[9530] | 1 | <?php |
---|
| 2 | |
---|
| 3 | function plugin_install() |
---|
| 4 | { |
---|
| 5 | global $conf; |
---|
| 6 | |
---|
| 7 | ////////////créer groupe//////////// |
---|
| 8 | $query = ' |
---|
| 9 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 10 | (name) |
---|
| 11 | VALUES |
---|
| 12 | (\'+18\') |
---|
| 13 | ;'; |
---|
| 14 | pwg_query($query); |
---|
| 15 | $query = ' |
---|
| 16 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 17 | (name) |
---|
| 18 | VALUES |
---|
| 19 | (\'16-17\') |
---|
| 20 | ;'; |
---|
| 21 | pwg_query($query); |
---|
| 22 | $query = ' |
---|
| 23 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 24 | (name) |
---|
| 25 | VALUES |
---|
| 26 | (\'nothing\') |
---|
| 27 | ;'; |
---|
| 28 | pwg_query($query); |
---|
| 29 | ////////////créer user//////////// |
---|
| 30 | include_once(PHPWG_ROOT_PATH.'include/functions_user.inc.php'); |
---|
| 31 | register_user('18', 'adult_content', ''); |
---|
| 32 | register_user('16', 'adult_content', ''); |
---|
| 33 | |
---|
| 34 | ////////////placer dans group 16//////////// |
---|
| 35 | $result = pwg_query('SELECT id FROM '.GROUPS_TABLE.' WHERE name IN (\'16-17\') ;'); |
---|
| 36 | $data_group = mysql_fetch_array($result); |
---|
| 37 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('16').'\', \''.$data_group['id'].'\' )' ); |
---|
| 38 | |
---|
| 39 | ////////////placer dans group 18//////////// |
---|
| 40 | $result = pwg_query('SELECT id FROM '.GROUPS_TABLE.' WHERE name IN (\'+18\') ;'); |
---|
| 41 | $data_group = mysql_fetch_array($result); |
---|
| 42 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('18').'\', \''.$data_group['id'].'\' )' ); |
---|
| 43 | |
---|
| 44 | /////////////Config plugin |
---|
| 45 | $q = ' |
---|
| 46 | INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) |
---|
| 47 | VALUES |
---|
[12621] | 48 | ("ad_c_plugin" , "true,false,both" , "Plugin adult_content : menublock_for_guest, block_on_index, manage_what");'; |
---|
[9530] | 49 | pwg_query($q); |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | function plugin_activate() |
---|
| 56 | { |
---|
[9557] | 57 | ///user exist ?/// |
---|
| 58 | $query = ' |
---|
| 59 | SELECT COUNT(*) AS result FROM '.USERS_TABLE.' |
---|
| 60 | WHERE username IN (\'18\') |
---|
| 61 | ;'; |
---|
| 62 | $data_user = mysql_fetch_array(pwg_query($query)); |
---|
| 63 | $exist = $data_user['result']; |
---|
| 64 | if ( $exist == 0 ) |
---|
| 65 | { |
---|
| 66 | register_user('18', 'adult_content', ''); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | $query = ' |
---|
| 70 | SELECT COUNT(*) AS result FROM '.USERS_TABLE.' |
---|
| 71 | WHERE username IN (\'16\') |
---|
| 72 | ;'; |
---|
| 73 | $data_user = mysql_fetch_array(pwg_query($query)); |
---|
| 74 | $exist = $data_user['result']; |
---|
| 75 | if ( $exist == 0 ) |
---|
| 76 | { |
---|
| 77 | register_user('16', 'adult_content', ''); |
---|
| 78 | } |
---|
| 79 | ///group exist ?/// |
---|
| 80 | $query = ' |
---|
| 81 | SELECT COUNT(*) AS result FROM '.GROUPS_TABLE.' |
---|
| 82 | WHERE name IN (\'+18\') |
---|
| 83 | ;'; |
---|
| 84 | $data_user = mysql_fetch_array(pwg_query($query)); |
---|
| 85 | $exist = $data_user['result']; |
---|
| 86 | if ( $exist == 0 ) |
---|
| 87 | { |
---|
| 88 | $query = 'INSERT INTO '.GROUPS_TABLE.' |
---|
| 89 | (name) |
---|
| 90 | VALUES |
---|
| 91 | (\'+18\') |
---|
| 92 | ;'; |
---|
| 93 | pwg_query($query); |
---|
| 94 | ////////////placer dans group 18//////////// |
---|
| 95 | $result = pwg_query('SELECT id FROM '.GROUPS_TABLE.' WHERE name IN (\'+18\') ;'); |
---|
| 96 | $data_group = mysql_fetch_array($result); |
---|
| 97 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('18').'\', \''.$data_group['id'].'\' )' ); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | $query = ' |
---|
| 101 | SELECT COUNT(*) AS result FROM '.GROUPS_TABLE.' |
---|
| 102 | WHERE name IN (\'16-17\') |
---|
| 103 | ;'; |
---|
| 104 | $data_user = mysql_fetch_array(pwg_query($query)); |
---|
| 105 | $exist = $data_user['result']; |
---|
| 106 | if ( $exist == 0 ) |
---|
| 107 | { |
---|
| 108 | $query = ' |
---|
| 109 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 110 | (name) |
---|
| 111 | VALUES |
---|
| 112 | (\'16-17\') |
---|
| 113 | ;'; |
---|
| 114 | pwg_query($query); |
---|
[9530] | 115 | ////////////placer dans group 16//////////// |
---|
[9557] | 116 | $result = pwg_query('SELECT id FROM '.GROUPS_TABLE.' WHERE name IN (\'16-17\') ;'); |
---|
| 117 | $data_group = mysql_fetch_array($result); |
---|
| 118 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('16').'\', \''.$data_group['id'].'\' )' ); |
---|
| 119 | |
---|
[9530] | 120 | } |
---|
[9557] | 121 | //grp nothing |
---|
[9530] | 122 | $query = ' |
---|
[9557] | 123 | SELECT COUNT(*) AS result FROM '.GROUPS_TABLE.' |
---|
| 124 | WHERE name IN (\'nothing\') |
---|
| 125 | ;'; |
---|
| 126 | $data_user = mysql_fetch_array(pwg_query($query)); |
---|
| 127 | $exist = $data_user['result']; |
---|
| 128 | if ( $exist == 0 ) |
---|
| 129 | { |
---|
| 130 | $query = ' |
---|
| 131 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 132 | (name) |
---|
| 133 | VALUES |
---|
| 134 | (\'nothing\') |
---|
| 135 | ;'; |
---|
| 136 | pwg_query($query); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | ///assoc user/group exist ?/// |
---|
| 140 | |
---|
| 141 | $n_query = ' |
---|
| 142 | SELECT id FROM '.GROUPS_TABLE.' |
---|
| 143 | WHERE name IN (\'16-17\') |
---|
| 144 | ;'; |
---|
| 145 | $data_group = mysql_fetch_array(pwg_query($n_query)); |
---|
| 146 | $query = ' |
---|
| 147 | SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.' |
---|
| 148 | WHERE group_id IN (\''.$data_group['id'].'\') AND user_id IN (\''.get_userid('16').'\') |
---|
| 149 | ;'; |
---|
| 150 | $data_user_group = mysql_fetch_array(pwg_query($query)); |
---|
| 151 | $exist = $data_user_group['result']; |
---|
| 152 | if ( $exist == 0 ) |
---|
| 153 | { |
---|
| 154 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('16').'\', \''.$data_group['id'].'\' )' ); |
---|
| 155 | } |
---|
| 156 | $n_query = ' |
---|
| 157 | SELECT id FROM '.GROUPS_TABLE.' |
---|
| 158 | WHERE name IN (\'+18\') |
---|
| 159 | ;'; |
---|
| 160 | $data_group = mysql_fetch_array(pwg_query($n_query)); |
---|
| 161 | $query = ' |
---|
| 162 | SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.' |
---|
| 163 | WHERE group_id IN (\''.$data_group['id'].'\') AND user_id IN (\''.get_userid('18').'\') |
---|
| 164 | ;'; |
---|
| 165 | $data_user_group = mysql_fetch_array(pwg_query($query)); |
---|
| 166 | $exist = $data_user_group['result']; |
---|
| 167 | if ( $exist == 0 ) |
---|
| 168 | { |
---|
| 169 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES(\''.get_userid('18').'\', \''.$data_group['id'].'\' )' ); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | ////////////mis en generic//////////// |
---|
| 173 | $query = ' |
---|
| 174 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 175 | SET status=\'generic\' |
---|
| 176 | WHERE user_id IN (\''.get_userid('16').'\') |
---|
| 177 | ;'; |
---|
[9530] | 178 | pwg_query($query); |
---|
| 179 | |
---|
| 180 | $query = ' |
---|
[9557] | 181 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 182 | SET status=\'generic\' |
---|
| 183 | WHERE user_id IN (\''.get_userid('18').'\') |
---|
| 184 | ;'; |
---|
[9530] | 185 | pwg_query($query); |
---|
[9557] | 186 | |
---|
| 187 | //////////// Check Config |
---|
| 188 | $query = ' |
---|
| 189 | SELECT COUNT(*) AS result FROM '.CONFIG_TABLE.' |
---|
| 190 | WHERE param IN (\'ad_c_plugin\') |
---|
| 191 | ;'; |
---|
| 192 | $data_table = mysql_fetch_array(pwg_query($query)); |
---|
| 193 | $exist = $data_table['result']; |
---|
| 194 | if ( $exist == 0 ) |
---|
| 195 | { |
---|
| 196 | $q = ' |
---|
| 197 | INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) |
---|
[9530] | 198 | VALUES |
---|
[12622] | 199 | ("ad_c_plugin" , "true,false,both" , "Plugin adult_content : menublock_for_guest, block_on_index, manage_what");'; |
---|
[9557] | 200 | pwg_query($q); |
---|
| 201 | } |
---|
| 202 | else { |
---|
| 203 | $query = ' |
---|
| 204 | SELECT value FROM '.CONFIG_TABLE.' |
---|
| 205 | WHERE param IN (\'ad_c_plugin\') |
---|
| 206 | ;'; |
---|
| 207 | $data_conf = mysql_fetch_array(pwg_query($query)); |
---|
| 208 | $conf=explode(',', $data_conf['value']); |
---|
| 209 | $nbr=count($conf); |
---|
| 210 | |
---|
[12621] | 211 | if ($nbr!=3) |
---|
[9557] | 212 | { |
---|
| 213 | pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param IN (\'ad_c_plugin\')'); |
---|
| 214 | $q = ' |
---|
| 215 | INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) |
---|
| 216 | VALUES |
---|
[12621] | 217 | ("ad_c_plugin" , "true,false,both" , "Plugin adult_content : menublock_for_guest, block_on_index, manage_what");'; |
---|
[9557] | 218 | pwg_query($q); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
[9530] | 222 | }//fin active |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | function plugin_uninstall() |
---|
| 228 | { |
---|
| 229 | include_once(PHPWG_ROOT_PATH.'include/functions_user.inc.php'); |
---|
| 230 | ////////////suppr user//////////// |
---|
| 231 | delete_user(get_userid('18')); |
---|
| 232 | delete_user(get_userid('16')); |
---|
| 233 | |
---|
| 234 | ////////////suppr assoc user all /groupe 16//////////// |
---|
| 235 | $query = ' |
---|
| 236 | SELECT id FROM '.GROUPS_TABLE.' |
---|
| 237 | WHERE name IN (\'16-17\') |
---|
| 238 | ;'; |
---|
| 239 | $data_group = mysql_fetch_array(pwg_query($query)); |
---|
| 240 | pwg_query('DELETE FROM '.USER_GROUP_TABLE.' WHERE group_id IN (\''.$data_group['id'].'\')' ); |
---|
| 241 | |
---|
| 242 | ////////////suppr assoc user all /groupe 18//////////// |
---|
| 243 | $query = ' |
---|
| 244 | SELECT id FROM '.GROUPS_TABLE.' |
---|
| 245 | WHERE name IN (\'+18\') |
---|
| 246 | ;'; |
---|
| 247 | $data_group = mysql_fetch_array(pwg_query($query)); |
---|
| 248 | pwg_query('DELETE FROM '.USER_GROUP_TABLE.' WHERE group_id IN (\''.$data_group['id'].'\')' ); |
---|
| 249 | |
---|
| 250 | ////////////suppr assoc user all /groupe nothing//////////// |
---|
| 251 | $query = ' |
---|
| 252 | SELECT id FROM '.GROUPS_TABLE.' |
---|
| 253 | WHERE name IN (\'nothing\') |
---|
| 254 | ;'; |
---|
| 255 | $data_group = mysql_fetch_array(pwg_query($query)); |
---|
| 256 | pwg_query('DELETE FROM '.USER_GROUP_TABLE.' WHERE group_id IN (\''.$data_group['id'].'\')' ); |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | ////////////suppr groupe//////////// |
---|
| 260 | $query = ' |
---|
| 261 | DELETE FROM '.GROUPS_TABLE.' |
---|
| 262 | WHERE name IN (\'+18\') |
---|
| 263 | ;'; |
---|
| 264 | pwg_query($query); |
---|
| 265 | |
---|
| 266 | $query = ' |
---|
| 267 | DELETE FROM '.GROUPS_TABLE.' |
---|
| 268 | WHERE name IN (\'16-17\') |
---|
| 269 | ;'; |
---|
| 270 | pwg_query($query); |
---|
| 271 | $query = ' |
---|
| 272 | DELETE FROM '.GROUPS_TABLE.' |
---|
| 273 | WHERE name IN (\'nothing\') |
---|
| 274 | ;'; |
---|
| 275 | pwg_query($query); |
---|
| 276 | |
---|
| 277 | //////////////// Delete config |
---|
| 278 | pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param IN (\'ad_c_plugin\')'); |
---|
| 279 | }//fin uninstall |
---|
| 280 | |
---|
| 281 | |
---|
[3331] | 282 | ?> |
---|