[4169] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // +-----------------------------------------------------------------------+ |
---|
| 4 | // | Piwigo - a PHP based picture gallery | |
---|
| 5 | // +-----------------------------------------------------------------------+ |
---|
| 6 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
| 7 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 8 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 9 | // +-----------------------------------------------------------------------+ |
---|
| 10 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 11 | // | it under the terms of the GNU General Public License as published by | |
---|
| 12 | // | the Free Software Foundation | |
---|
| 13 | // | | |
---|
| 14 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 15 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 16 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 17 | // | General Public License for more details. | |
---|
| 18 | // | | |
---|
| 19 | // | You should have received a copy of the GNU General Public License | |
---|
| 20 | // | along with this program; if not, write to the Free Software | |
---|
| 21 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 22 | // | USA. | |
---|
| 23 | // +-----------------------------------------------------------------------+ |
---|
| 24 | |
---|
[4421] | 25 | // Look out, do sit before reading that : |
---|
| 26 | // keeps file coded in UTF-8 without BOM in Notepad++ : é |
---|
| 27 | // !!! |
---|
| 28 | |
---|
[4333] | 29 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 30 | |
---|
[4169] | 31 | // *************************************************************************** |
---|
| 32 | // ** evntcats_admin_funcs.php : Main functions (include) ** |
---|
| 33 | // ** for Piwigo plugin Event Cats ** |
---|
| 34 | // *************************************************************************** |
---|
| 35 | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | // | Header | |
---|
| 38 | // +-----------------------------------------------------------------------+ |
---|
| 39 | |
---|
| 40 | include_once(EVNTCATS_PATH.'include/ec_conf.inc.php'); |
---|
| 41 | |
---|
[4263] | 42 | if (!isset($ec_lists)) { |
---|
| 43 | $ec_lists = array(); |
---|
| 44 | $ec_lists['add_pages'] = array(); |
---|
| 45 | $ec_lists['categories'] = array(); |
---|
| 46 | $ec_lists['user_ids'] = array(); |
---|
| 47 | $ec_lists['ec_table'] = array(); |
---|
| 48 | } |
---|
| 49 | |
---|
[4169] | 50 | // +-----------------------------------------------------------------------+ |
---|
| 51 | // | Utilities functions | |
---|
| 52 | // +-----------------------------------------------------------------------+ |
---|
| 53 | |
---|
| 54 | /* |
---|
| 55 | * is_in($haystack, $needle) |
---|
| 56 | * returns true or false whether $needle is a string found in string $haystack |
---|
| 57 | * |
---|
| 58 | * @param |
---|
| 59 | * $haystack : the string in which to search |
---|
| 60 | * $needle : the string looked for |
---|
| 61 | * @return |
---|
| 62 | * true if $needle is found in $haystack ; false if not |
---|
| 63 | */ |
---|
| 64 | function is_in($haystack, $needle) { |
---|
| 65 | return (strpos($haystack, $needle) !== false); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * ec_image_exists($cat, $img) |
---|
| 70 | * returns true or false whether the image is associated with the category. |
---|
| 71 | * |
---|
| 72 | * @param |
---|
| 73 | * $cat : the category |
---|
| 74 | * $img : the image |
---|
| 75 | * @return |
---|
| 76 | * treu or false whether the image is associated with the category. |
---|
| 77 | */ |
---|
| 78 | function ec_image_exists($cat, $img) { |
---|
[8956] | 79 | return (mysql_fetch_row(pwg_query(" |
---|
[4218] | 80 | SELECT * |
---|
| 81 | FROM `".IMAGE_CATEGORY_TABLE."` |
---|
| 82 | WHERE `category_id` = ".$cat." |
---|
[4219] | 83 | AND `image_id` = ".$img |
---|
| 84 | )) !== false); |
---|
[4169] | 85 | } |
---|
| 86 | |
---|
| 87 | /* |
---|
| 88 | * str_from_var($var) |
---|
| 89 | * returns a string easing array var informations displaying in Piwigo : |
---|
[8956] | 90 | * _ the string return value starts with"<p align="left">" ; |
---|
[7663] | 91 | * _ all "TAB" characters (chr(10)) are replaced by "<br>" ; |
---|
[4169] | 92 | * _ all spaces are replaced by " ". |
---|
| 93 | * |
---|
| 94 | * @param |
---|
| 95 | * $var : variable to display |
---|
| 96 | * @return |
---|
| 97 | * string easy to display in Piwigo |
---|
| 98 | */ |
---|
| 99 | function str_from_var($var) { |
---|
[4218] | 100 | return |
---|
[8956] | 101 | '<p align="left">'. |
---|
[4218] | 102 | str_replace( |
---|
[7663] | 103 | chr(10),'<br>', |
---|
[4218] | 104 | str_replace(' ',' ', print_r /* var_dump */ ($var,true)) |
---|
| 105 | ). |
---|
| 106 | '</p>'; |
---|
[4169] | 107 | } |
---|
| 108 | |
---|
| 109 | /* |
---|
| 110 | * ec_inspect() |
---|
| 111 | * goes through ec_lists['ec_table'] to check errors on (multiple) entries |
---|
| 112 | * using the same code. Cannot really be used elsewhere than here in |
---|
| 113 | * build_ec_table() . |
---|
| 114 | * |
---|
| 115 | * @param |
---|
| 116 | * |
---|
| 117 | * @return |
---|
| 118 | * (no return value) |
---|
| 119 | */ |
---|
| 120 | function ec_inspect($checked_item, $new_action, $check_ec_nok = true) { |
---|
| 121 | global $ec_lists; |
---|
| 122 | $first = array(); |
---|
| 123 | $to_correct = array(); |
---|
| 124 | |
---|
[4239] | 125 | /* |
---|
[4169] | 126 | // $to_correct is needed cause following code would not work everywhere : |
---|
| 127 | foreach ($table as $value) { |
---|
| 128 | if ($value == $value_to_check and $value == $problem) { |
---|
| 129 | foreach ($table as &$value2) { // key index of $table can be reset |
---|
| 130 | if ($value2 == $value_to_check) { |
---|
| 131 | $value2 = $better_value; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | // It works with WinAmp Server, but not on Apache server of Free (french |
---|
| 137 | // Internet provider). |
---|
| 138 | */ |
---|
| 139 | |
---|
[4218] | 140 | foreach ($ec_lists['ec_table'] as $ec_entry) { |
---|
[4169] | 141 | $ec_current_code = $ec_entry['code']; |
---|
| 142 | if ( |
---|
| 143 | $ec_entry['action'] == 'ec_ok' or |
---|
| 144 | ($check_ec_nok and $ec_entry['action'] == 'ec_nok') |
---|
| 145 | ) { |
---|
| 146 | if (isset($first[$ec_current_code])) { |
---|
| 147 | // $first[$ec_current_code] is set <=> code has already been met. |
---|
| 148 | // Checked item MUST be equal to the first item (thus all items) for |
---|
| 149 | // this code. |
---|
| 150 | if ( |
---|
| 151 | $first[$ec_current_code] != $ec_entry[$checked_item] or |
---|
| 152 | ($new_action == '' and $ec_entry[$checked_item] == 'true') |
---|
[4218] | 153 | ) $to_correct[$ec_current_code] = true; // value not used in fact |
---|
| 154 | // but using $ec_current_code as a key makes a smaller table |
---|
[4169] | 155 | } // if the error comes back several times |
---|
[4218] | 156 | else $first[$ec_current_code] = $ec_entry[$checked_item]; |
---|
[4169] | 157 | } |
---|
| 158 | } |
---|
| 159 | foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here |
---|
| 160 | if (isset($to_correct[$ec_entry['code']])) { |
---|
| 161 | if ($new_action == '') { |
---|
[4218] | 162 | if (!pwg_query(" |
---|
[4282] | 163 | UPDATE `".EVNTCATS_TABLE."` |
---|
[4218] | 164 | SET `forced` = 'false' |
---|
| 165 | WHERE `id` = ".$ec_entry['id'] |
---|
[4169] | 166 | )) die('Could not fix a "_f_pb"'); |
---|
| 167 | $ec_entry['forced'] = 'false'; |
---|
| 168 | } |
---|
| 169 | else $ec_entry['action'] = $new_action; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
[10052] | 174 | // Compatibility to Piwigo 2.2 , where this function disappeared |
---|
| 175 | /** returns the argument_ids array with new sequenced keys based on related |
---|
| 176 | * names. Sequence is not case sensitive. |
---|
| 177 | * Warning: By definition, this function breaks original keys |
---|
| 178 | */ |
---|
| 179 | function ec_order_by_name($element_ids,$name) |
---|
| 180 | { |
---|
| 181 | $ordered_element_ids = array(); |
---|
| 182 | foreach ($element_ids as $k_id => $element_id) |
---|
| 183 | { |
---|
| 184 | $key = strtolower($name[$element_id]) .'-'. $name[$element_id] .'-'. $k_id; |
---|
| 185 | $ordered_element_ids[$key] = $element_id; |
---|
| 186 | } |
---|
| 187 | ksort($ordered_element_ids); |
---|
| 188 | return $ordered_element_ids; |
---|
| 189 | } |
---|
| 190 | |
---|
[4169] | 191 | // +-----------------------------------------------------------------------+ |
---|
| 192 | // | Tables building functions | |
---|
| 193 | // +-----------------------------------------------------------------------+ |
---|
| 194 | |
---|
| 195 | /* |
---|
[4263] | 196 | * build_ec_addp() |
---|
| 197 | * builds $ec_lists['add_pages']. |
---|
| 198 | * |
---|
| 199 | * @param |
---|
| 200 | * (no parameter) |
---|
| 201 | * @return |
---|
| 202 | * (no return value) |
---|
| 203 | */ |
---|
| 204 | function build_ec_addp() { |
---|
[4329] | 205 | global $ec_lists; |
---|
[4436] | 206 | $ec_lists['add_pages'] = array(); |
---|
[4342] | 207 | if (defined('ADD_PAGES_TABLE')) { |
---|
[4436] | 208 | $res = pwg_query("SELECT `id`, `title` FROM `".ADD_PAGES_TABLE."`;"); |
---|
[8956] | 209 | while ($r = mysql_fetch_array($res)) { |
---|
[4436] | 210 | $a = (is_in($r['title'], '/user_id=')) ? |
---|
| 211 | explode('/user_id=' , $r['title']) : array($r['title']); |
---|
| 212 | $b = (is_in($a[0], '/group_id=')) ? |
---|
| 213 | explode('/group_id=' , $a[0]) : $a; |
---|
| 214 | $ec_lists['add_pages'][$r['id']] = $b[0]; |
---|
[4263] | 215 | } |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /* |
---|
[4173] | 220 | * build_ec_categories($dsp) |
---|
| 221 | * builds $ec_lists['categories']. |
---|
| 222 | * |
---|
| 223 | * @param |
---|
| 224 | * whether $ec_lists['categories'] must be of type "cat / sub-cat" or |
---|
| 225 | * or "cat <CR LF> - sub-cat". |
---|
| 226 | * @return |
---|
| 227 | * (no return value) |
---|
| 228 | */ |
---|
| 229 | function build_ec_categories($dsp) { |
---|
| 230 | global $template, $ec_lists; |
---|
[4436] | 231 | $ec_lists['categories'] = array(); |
---|
[4173] | 232 | $c = array(); |
---|
[4218] | 233 | display_select_cat_wrapper(" |
---|
| 234 | SELECT `id`, `name`, `uppercats`, `global_rank` |
---|
| 235 | FROM `".CATEGORIES_TABLE."` |
---|
| 236 | ", $c, 'category_options', $dsp); |
---|
[4173] | 237 | $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options']; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /* |
---|
[4263] | 241 | * build_ec_userids() |
---|
| 242 | * builds $ec_lists['user_ids']. |
---|
| 243 | * |
---|
| 244 | * @param |
---|
| 245 | * (no parameter) |
---|
| 246 | * @return |
---|
| 247 | * (no return value) |
---|
| 248 | */ |
---|
| 249 | function build_ec_userids() { |
---|
| 250 | global $ec_lists, $conf; |
---|
[4436] | 251 | $ec_lists['user_ids'] = array(); |
---|
[4263] | 252 | $ec_lists['user_ids'] = simple_hash_from_query(" |
---|
| 253 | SELECT |
---|
| 254 | ".$conf['user_fields']['id']." AS id, |
---|
| 255 | ".$conf['user_fields']['username']." AS username |
---|
| 256 | FROM `".USERS_TABLE."` |
---|
| 257 | WHERE id > 2;", |
---|
| 258 | 'id', 'username' |
---|
| 259 | ); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | /* |
---|
[4169] | 263 | * build_ec_table() |
---|
| 264 | * builds a table showing the content of the <pwg>_event_cats database table, |
---|
| 265 | * and a table showing the eventual errors. |
---|
| 266 | * |
---|
| 267 | * @param |
---|
| 268 | * no parameters passed ; the main material on which works the function, is |
---|
| 269 | * the global array variable $ec_lists. |
---|
| 270 | * @return |
---|
| 271 | * (no return value) |
---|
| 272 | */ |
---|
| 273 | function build_ec_table() { |
---|
[4329] | 274 | global $ec_lists; |
---|
[4169] | 275 | |
---|
[4436] | 276 | $ec_lists['ec_table'] = array(); |
---|
[4218] | 277 | $q = pwg_query(" |
---|
[4436] | 278 | SELECT * |
---|
| 279 | FROM `".EVNTCATS_TABLE."` |
---|
[8956] | 280 | WHERE `code` IS NOT NULL |
---|
[4218] | 281 | ORDER BY `id` |
---|
| 282 | "); |
---|
[8956] | 283 | while ($r = mysql_fetch_assoc($q)) |
---|
[4218] | 284 | $ec_lists['ec_table'][intval($r['id'])] = $r; |
---|
[4169] | 285 | |
---|
| 286 | // Construction of behaviour |
---|
| 287 | |
---|
| 288 | // Multiple action params for a single code check |
---|
| 289 | ec_inspect('action', 'ec_nok_action_pb'); |
---|
| 290 | |
---|
| 291 | // Multiple user_ids for a single code check |
---|
| 292 | ec_inspect('user_id', 'ec_nok_userid_pb', false); |
---|
| 293 | |
---|
| 294 | // Multiple "forced" params for a single code check |
---|
| 295 | ec_inspect('forced', ''); |
---|
| 296 | |
---|
| 297 | // User id and associated page validities checks |
---|
| 298 | foreach ($ec_lists['ec_table'] as &$ec_entry) { |
---|
| 299 | |
---|
| 300 | // Check if associated user_id exists |
---|
| 301 | if ( |
---|
| 302 | is_in($ec_entry['action'], 'ec_ok') and |
---|
| 303 | !array_key_exists($ec_entry['user_id'], $ec_lists['user_ids']) |
---|
[4170] | 304 | ) $ec_entry['action'] = 'ec_nok_userid_miss'; |
---|
[4169] | 305 | |
---|
| 306 | // Check if associated displayed page exists |
---|
| 307 | $a = 0; |
---|
[4218] | 308 | if ( |
---|
| 309 | !empty($ec_entry['arg1']) and |
---|
| 310 | // (Only arg2 is significant if action is ec_nok[_xxx] .) |
---|
| 311 | is_in($ec_entry['action'], 'ec_ok') |
---|
| 312 | ) $a++; |
---|
[4169] | 313 | if (!empty($ec_entry['arg2'])) $a+= 2; |
---|
| 314 | switch ($a) { |
---|
| 315 | // case 0 : home, nothing to check |
---|
| 316 | |
---|
| 317 | case 2: // Additional Page |
---|
| 318 | if ( |
---|
[4342] | 319 | defined('ADD_PAGES_TABLE') and ( |
---|
[4169] | 320 | is_in($ec_entry['action'], 'ec_ok') or |
---|
| 321 | $ec_entry['action'] == 'ec_nok' |
---|
| 322 | ) and |
---|
| 323 | !array_key_exists($ec_entry['arg2'], $ec_lists['add_pages']) |
---|
[4179] | 324 | ) $ec_entry['action'].= '_ap_pb'; |
---|
[4169] | 325 | break; |
---|
| 326 | |
---|
| 327 | case 1: // Category |
---|
| 328 | case 3: // Image |
---|
| 329 | if (is_in($ec_entry['action'], 'ec_ok')) { |
---|
| 330 | if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) { |
---|
[4218] | 331 | if ($a == 3) // case 3: // Image |
---|
| 332 | if (!ec_image_exists($ec_entry['arg1'], $ec_entry['arg2'])) |
---|
| 333 | $ec_entry['action'].= '_img_pb'; |
---|
[4169] | 334 | } |
---|
[4179] | 335 | else $ec_entry['action'].= '_cat_pb'; |
---|
[4169] | 336 | } |
---|
| 337 | break; |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | /* |
---|
[4333] | 343 | * build_dup_groups() |
---|
| 344 | * builds the information telling who is allowed to duplicate |
---|
[4169] | 345 | * |
---|
| 346 | * @param |
---|
| 347 | * no parameter passed, the main material on which works the function, is |
---|
| 348 | * the global array variable $ec_lists. |
---|
| 349 | * @return |
---|
[8956] | 350 | * (no return value) |
---|
[4169] | 351 | */ |
---|
[4333] | 352 | function build_dup_groups() { |
---|
| 353 | global $ec_lists; |
---|
[4169] | 354 | |
---|
[4263] | 355 | if (count($ec_lists['user_ids']) == 0) build_ec_userids(); |
---|
| 356 | |
---|
[4333] | 357 | // Existing groups (needed later) |
---|
| 358 | $ec_lists['groups'] = simple_hash_from_query(" |
---|
[4263] | 359 | SELECT `id`, `name` |
---|
| 360 | FROM `".GROUPS_TABLE."` |
---|
| 361 | ORDER BY `name` ASC; |
---|
| 362 | ", |
---|
| 363 | 'id', 'name' |
---|
| 364 | ); |
---|
| 365 | |
---|
| 366 | // groups granted to duplication |
---|
[10052] | 367 | $ec_lists['groups_granted_ids'] = ec_order_by_name( |
---|
[4263] | 368 | array_from_query(" |
---|
[4282] | 369 | SELECT `arg2` |
---|
| 370 | FROM ".EVNTCATS_TABLE." |
---|
| 371 | WHERE `code` IS NULL |
---|
[4329] | 372 | AND `arg1` = 1 |
---|
[4282] | 373 | AND `arg2` IS NOT NULL |
---|
[4263] | 374 | ;", |
---|
[4282] | 375 | 'arg2' |
---|
[4263] | 376 | ), |
---|
[4333] | 377 | $ec_lists['groups'] |
---|
[4263] | 378 | ); |
---|
| 379 | |
---|
| 380 | // users directly granted to duplication |
---|
[10052] | 381 | $ec_lists['users_granted_direct_ids'] = ec_order_by_name( |
---|
[4263] | 382 | array_from_query(" |
---|
[4282] | 383 | SELECT `arg2` |
---|
[4329] | 384 | FROM `".EVNTCATS_TABLE."` |
---|
[4282] | 385 | WHERE `code` IS NULL |
---|
[4329] | 386 | AND `arg1` = 2 |
---|
[4282] | 387 | AND `arg2` IS NOT NULL |
---|
[4263] | 388 | ;", |
---|
[4282] | 389 | 'arg2' |
---|
[4263] | 390 | ), |
---|
| 391 | $ec_lists['user_ids'] |
---|
| 392 | ); |
---|
| 393 | |
---|
| 394 | // Calculate users granted to duplication thanks to belonging to a |
---|
| 395 | // certain group (in groups, level (friends, family, contacts), |
---|
| 396 | // or user status (generic)) |
---|
[8956] | 397 | $types_entry_exists = (($t = mysql_fetch_row(pwg_query(" |
---|
[4329] | 398 | SELECT `arg2` |
---|
| 399 | FROM `".EVNTCATS_TABLE."` |
---|
| 400 | WHERE `code` IS NULL |
---|
| 401 | AND `arg1` = 3 |
---|
| 402 | AND `arg2` IS NOT NULL |
---|
| 403 | LIMIT 1; |
---|
[4333] | 404 | "))) !== false); |
---|
| 405 | $ec_lists['types_granted'] = ($types_entry_exists) ? $t[0] : 0; |
---|
[4329] | 406 | |
---|
[4333] | 407 | return $types_entry_exists; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | /* |
---|
| 411 | * build_ec_lists() |
---|
| 412 | * builds the main array variable contaning all informations for the plugin |
---|
| 413 | * |
---|
| 414 | * @param |
---|
| 415 | * no parameter passed, the main material on which works the function, is |
---|
| 416 | * the global array variable $ec_lists. |
---|
| 417 | * @return |
---|
| 418 | * (no return value) |
---|
| 419 | */ |
---|
| 420 | function build_ec_lists() { |
---|
| 421 | |
---|
| 422 | // Construction of $ec_lists['add_pages'] array var |
---|
| 423 | build_ec_addp(); |
---|
| 424 | |
---|
| 425 | // Construction of $ec_lists['categories'] array var |
---|
| 426 | build_ec_categories(true); |
---|
| 427 | |
---|
| 428 | // Construction of $ec_lists['user_ids'] array var |
---|
| 429 | build_ec_userids(); |
---|
| 430 | |
---|
| 431 | // Construction of $ec_lists['ec_table'] array var |
---|
| 432 | build_ec_table(); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | // +-----------------------------------------------------------------------+ |
---|
| 436 | // | Duplication analysis functions | |
---|
| 437 | // +-----------------------------------------------------------------------+ |
---|
| 438 | |
---|
| 439 | /* |
---|
| 440 | * build_dup_arrays($append_tpl = false) |
---|
| 441 | * builds arrays telling which accounts are allowed to display a duplicate |
---|
| 442 | * account link. Returns an array of all the user ids allowed to duplicate. |
---|
| 443 | * |
---|
| 444 | * @param |
---|
| 445 | * $append_tpl : tells if $template must be appended with built arrays |
---|
| 446 | * @return |
---|
[4371] | 447 | * array of all the user ids allowed to duplicate |
---|
[4333] | 448 | */ |
---|
| 449 | function build_dup_arrays($append_tpl = false) { |
---|
| 450 | global $template, $ec_lists, $conf; |
---|
| 451 | |
---|
| 452 | // A lot of below code has simply been copied from file cat_perm.php . |
---|
| 453 | // Many thanks to people who wrote it ! |
---|
| 454 | |
---|
| 455 | build_dup_groups(); |
---|
| 456 | |
---|
| 457 | $users_granted_ids = array(); |
---|
| 458 | |
---|
[4263] | 459 | $users_granted_thks_gen_ids = array(); |
---|
[4333] | 460 | if ($ec_gen_granted = (($ec_lists['types_granted'] & 8) != 0)) { |
---|
[10052] | 461 | $users_granted_thks_gen_ids = ec_order_by_name( |
---|
[4263] | 462 | array_diff( |
---|
| 463 | array_from_query(" |
---|
| 464 | SELECT `user_id` |
---|
| 465 | FROM `".USER_INFOS_TABLE."` |
---|
[4486] | 466 | WHERE `status` = 'generic' |
---|
| 467 | AND `user_id` > 2;", |
---|
[4263] | 468 | 'user_id' |
---|
| 469 | ), |
---|
[4333] | 470 | $ec_lists['users_granted_direct_ids'] |
---|
[4263] | 471 | ), |
---|
| 472 | $ec_lists['user_ids'] |
---|
| 473 | ); |
---|
| 474 | foreach ($users_granted_thks_gen_ids as $user_id) |
---|
[4276] | 475 | $users_granted_ids[$user_id] = l10n('user_status_generic'); |
---|
| 476 | } |
---|
[4263] | 477 | |
---|
[4276] | 478 | $types = array( |
---|
| 479 | '1' => l10n('Level 1'), |
---|
| 480 | '2' => l10n('Level 2'), |
---|
| 481 | '4' => l10n('Level 4'), |
---|
| 482 | ); |
---|
| 483 | $types_granted_ids = array(); |
---|
[4263] | 484 | $users_granted_thks_types_ids = array(); |
---|
[4333] | 485 | if (($ec_lists['types_granted'] & 7) != 0) { |
---|
| 486 | if (($ec_lists['types_granted'] & 1) != 0) $types_granted_ids[] = '1'; |
---|
| 487 | if (($ec_lists['types_granted'] & 2) != 0) $types_granted_ids[] = '2'; |
---|
| 488 | if (($ec_lists['types_granted'] & 4) != 0) $types_granted_ids[] = '4'; |
---|
[4276] | 489 | if (count($types_granted_ids) > 0) { |
---|
[4263] | 490 | $user_granted_from_type = array(); |
---|
| 491 | $result = pwg_query(" |
---|
| 492 | SELECT `user_id`, `level` |
---|
| 493 | FROM `".USER_INFOS_TABLE."` |
---|
[4486] | 494 | WHERE `level` IN (".implode(',', $types_granted_ids).") |
---|
| 495 | AND `user_id` > 2; |
---|
[4263] | 496 | "); |
---|
[8956] | 497 | while ($row = mysql_fetch_array($result)) { |
---|
[4263] | 498 | if (!isset($user_granted_from_type[$row['level']])) { |
---|
| 499 | $user_granted_from_type[$row['level']] = array(); |
---|
| 500 | } |
---|
| 501 | $user_granted_from_type[$row['level']][] = $row['user_id']; |
---|
| 502 | } |
---|
| 503 | $user_granted_by_type_ids = array(); |
---|
| 504 | foreach ($user_granted_from_type as $type_users) |
---|
| 505 | $user_granted_by_type_ids = array_merge( |
---|
| 506 | $user_granted_by_type_ids, |
---|
| 507 | $type_users |
---|
| 508 | ); |
---|
[10052] | 509 | $users_granted_thks_types_ids = ec_order_by_name( |
---|
[4263] | 510 | array_diff( |
---|
| 511 | array_unique($user_granted_by_type_ids), |
---|
[4333] | 512 | $ec_lists['users_granted_direct_ids'] |
---|
[4263] | 513 | ), |
---|
| 514 | $ec_lists['user_ids'] |
---|
| 515 | ); |
---|
| 516 | foreach ($users_granted_thks_types_ids as $user_id) |
---|
| 517 | foreach ($user_granted_from_type as $type_id => $type_users) { |
---|
| 518 | if (in_array($user_id, $type_users)) { |
---|
[4276] | 519 | $users_granted_ids[$user_id]= $types[$type_id]; |
---|
[4263] | 520 | break; |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | } |
---|
[4276] | 524 | } |
---|
[4263] | 525 | |
---|
| 526 | $users_granted_thks_groups_ids = array(); |
---|
[4333] | 527 | if (count($ec_lists['groups_granted_ids']) > 0) { |
---|
[4263] | 528 | $granted_groups = array(); |
---|
| 529 | |
---|
| 530 | $result = pwg_query(" |
---|
| 531 | SELECT `user_id`, `group_id` |
---|
| 532 | FROM `".USER_GROUP_TABLE."` |
---|
[4486] | 533 | WHERE `group_id` IN (".implode(',', $ec_lists['groups_granted_ids']).") |
---|
| 534 | AND `user_id` > 2; |
---|
[4263] | 535 | "); |
---|
[8956] | 536 | while ($row = mysql_fetch_array($result)) { |
---|
[4263] | 537 | if (!isset($granted_groups[$row['group_id']])) { |
---|
| 538 | $granted_groups[$row['group_id']] = array(); |
---|
| 539 | } |
---|
| 540 | $granted_groups[$row['group_id']][] = $row['user_id']; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | $user_granted_by_group_ids = array(); |
---|
| 544 | |
---|
| 545 | foreach ($granted_groups as $group_users) |
---|
| 546 | $user_granted_by_group_ids = array_merge( |
---|
| 547 | $user_granted_by_group_ids, |
---|
| 548 | $group_users |
---|
| 549 | ); |
---|
[10052] | 550 | $users_granted_thks_groups_ids = ec_order_by_name( |
---|
[4263] | 551 | array_diff( |
---|
| 552 | array_unique($user_granted_by_group_ids), |
---|
[4333] | 553 | $ec_lists['users_granted_direct_ids'] |
---|
[4263] | 554 | ), |
---|
| 555 | $ec_lists['user_ids'] |
---|
| 556 | ); |
---|
| 557 | foreach ($users_granted_thks_groups_ids as $user_id) |
---|
| 558 | foreach ($granted_groups as $group_id => $group_users) |
---|
| 559 | if (in_array($user_id, $group_users)) { |
---|
[4333] | 560 | $users_granted_ids[$user_id]= $ec_lists['groups'][$group_id]; |
---|
[4263] | 561 | break; |
---|
| 562 | } |
---|
| 563 | |
---|
[4276] | 564 | } |
---|
[4263] | 565 | |
---|
| 566 | if ($append_tpl) { |
---|
[10052] | 567 | $users_denied_ids = ec_order_by_name( |
---|
[4263] | 568 | array_diff( |
---|
| 569 | array_keys($ec_lists['user_ids']), |
---|
| 570 | $users_granted_thks_gen_ids, |
---|
| 571 | $users_granted_thks_types_ids, |
---|
| 572 | $users_granted_thks_groups_ids, |
---|
[4333] | 573 | $ec_lists['users_granted_direct_ids'] |
---|
[4263] | 574 | ), |
---|
| 575 | $ec_lists['user_ids'] |
---|
| 576 | ); |
---|
| 577 | |
---|
[4276] | 578 | foreach ($users_granted_ids as $u => $g) $template->append( |
---|
[4263] | 579 | 'user_granted_indirects', |
---|
| 580 | array( |
---|
| 581 | 'USER' => $ec_lists['user_ids'][$u], |
---|
| 582 | 'GROUP' => $g |
---|
| 583 | ) |
---|
| 584 | ); |
---|
| 585 | |
---|
[4333] | 586 | $template->assign('all_groups', $ec_lists['groups']); |
---|
| 587 | $template->assign('groups_granted_ids', $ec_lists['groups_granted_ids']); |
---|
[10052] | 588 | $template->assign('groups_denied_ids', ec_order_by_name( |
---|
[4333] | 589 | array_diff( |
---|
| 590 | array_keys($ec_lists['groups']), |
---|
| 591 | $ec_lists['groups_granted_ids'] |
---|
| 592 | ), |
---|
| 593 | $ec_lists['groups'] |
---|
[4263] | 594 | )); |
---|
[4276] | 595 | $template->assign('ec_gen_granted', $ec_gen_granted); |
---|
| 596 | $template->assign('all_types', $types); |
---|
| 597 | $template->assign('types_granted_ids', $types_granted_ids); |
---|
[10052] | 598 | $template->assign('types_denied_ids', ec_order_by_name( |
---|
[4276] | 599 | array_diff(array_keys($types), $types_granted_ids), $types |
---|
| 600 | )); |
---|
[4263] | 601 | $template->assign('all_users', $ec_lists['user_ids']); |
---|
[4333] | 602 | $template->assign( |
---|
| 603 | 'users_granted_direct_ids', |
---|
| 604 | $ec_lists['users_granted_direct_ids'] |
---|
| 605 | ); |
---|
[4276] | 606 | $template->assign('users_denied_ids', $users_denied_ids); |
---|
[4263] | 607 | } |
---|
[4276] | 608 | $users_granted_ids = array_merge( |
---|
| 609 | array_keys($users_granted_ids), |
---|
[4333] | 610 | $ec_lists['users_granted_direct_ids'] |
---|
[4276] | 611 | ); |
---|
| 612 | |
---|
| 613 | // Returns an array which values are all the user_ids allowed to display a |
---|
| 614 | // "duplicate" link. The keys of this array are strange (for direct allowed |
---|
[4329] | 615 | // users, keys are usernames), but should not used |
---|
[4276] | 616 | return $users_granted_ids; |
---|
[4263] | 617 | } |
---|
| 618 | |
---|
| 619 | /* |
---|
| 620 | * dup_allowed($user_id) |
---|
| 621 | * returns true if the user_id is allowed to display a duplicate link |
---|
| 622 | * |
---|
| 623 | * @param |
---|
| 624 | * $user_id : the user_id |
---|
| 625 | * @return |
---|
| 626 | * true if the user_id is allowed to display a duplicate link |
---|
| 627 | */ |
---|
| 628 | function dup_allowed($user_id) { |
---|
[4329] | 629 | return in_array($user_id, build_dup_arrays()); |
---|
[4263] | 630 | } |
---|
| 631 | |
---|
[4169] | 632 | ?> |
---|