_event_cats database table, * and a table showing the eventual errors. * * @param * no parameters passed ; the main material on which works the function, is * the global array variable $ec_lists. * @return * (no return value) */ function build_ec_table() { global $ec_lists, $conf, $ec_ap_ok; $ec_lists['ec_table'] = array(); // $ec_lists['ec_codes'] = array(); // Useful ? if (isset($conf['auto_log'])) { // For tests purpose : table not in MySQL, but in $conf['xxx'] vars in // config_local.inc.php foreach ($conf['auto_log'] as $ec_current_code => $ec_entry) { $ec_current_entry = array_push($ec_lists['ec_table'], array( 'code' => $ec_current_code, 'user_id' => get_userid($ec_entry[$ec_current_code]), 'action' => 'ec_ok', 'arg1' => NULL, 'arg2' => NULL, 'forced' => 'false', )) - 1; // key($ec_lists['ec_table']) does not work as expected $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry; /* $ec_lists['ec_codes'][$ec_current_code] = array( 'count' => 1, 'id' => $ec_current_entry ); */ if (isset($conf['prior_page'])) { if (array_key_exists($ec_current_code, $conf['prior_page'])) { $ec_lists['ec_table'][$ec_current_entry]['arg2'] = $conf['prior_page'][$ec_current_code]; $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true'; } } if (isset($conf['outdated_page'])) { if (array_key_exists($ec_current_code, $conf['outdated_page'])) { $ec_lists['ec_table'][$ec_current_entry]['action'] = 'ec_nok'; $ec_lists['ec_table'][$ec_current_entry]['arg2'] = $conf['outdated_page'][$ec_current_code]; $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true'; } } } // Inspection of $conf['outdated_page'] if (isset($conf['outdated_page'])) { foreach ($conf['outdated_page'] as $ec_current_code => $ec_current_AP) { if (!array_key_exists($ec_current_code, $conf['auto_log'])) { $ec_current_entry = array_push($ec_lists['ec_table'], array( 'code' => $ec_current_code, 'user_id' => '', 'action' => 'ec_nok', 'arg1' => NULL, 'arg2' => $ec_current_AP, 'forced' => 'true', )) - 1; // key($ec_lists['ec_table']) problem $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry; /* $ec_lists['ec_codes'][$ec_current_code] = array( 'id' => $ec_current_entry, 'count' => 1 ); */ } } } } else { // in "normal" use ($conf['auto_log'] NOT set), $ec_lists['ec_table'] // is built thanks to below code only. A little bit more simple... $q = pwg_query(' SELECT * FROM `'.EVNTCATS_TABLE.'` WHERE `code` IS NOT NULL ORDER BY `id` '); while ($r = mysql_fetch_assoc($q)) { $ec_lists['ec_table'][intval($r['id'])] = $r; /* $ec_current_entry = intval($r['id']); $ec_current_code = $r['code']; if (array_key_exists($ec_current_code, $ec_lists['ec_codes'])) { $ec_lists[$ec_current_code]['count']++; } else { $ec_lists['ec_codes'][$ec_current_code] = array( 'id' => $ec_current_entry, 'count' => 1 ); */ } } // Construction of behaviour /* * ec_inpect() * goes through ec_lists['ec_table'] to check errors on (multiple) entries * using the same code. Cannot be used elsewhere than here in * build_ec_table() . * * @param * * @return * (no return value) */ function ec_inpect($checked_item, $new_action, $check_ec_nok = false, $check_forced = false) { global $ec_lists; $first = array(); $to_correct = array(); // $to_correct is needed because following code would not work anywhere : /* foreach ($table as $value) { if ($value == $value_to_check and $value == $problem) { foreach ($table as &$value2) { // key index of $table can be reset if ($value2 == $value_to_check) { $value2 = $better_value; } } } } // It works with WinAmp Server, but not on Apache server of Free (french // Internet provider). */ foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is not really needed $ec_current_code = $ec_entry['code']; if ( $ec_entry['action'] == 'ec_ok' or ($check_ec_nok and $ec_entry['action'] == 'ec_nok') ) { if (isset($first[$ec_current_code])) { // $first[$ec_current_code] is set <=> code has already been met. // Checked item MUST be equal to the first item (thus all items) for // this code. if ( $first[$ec_current_code] != $ec_entry[$checked_item] or ($check_forced and $ec_entry[$checked_item] == 'true') ) { $to_correct[$ec_current_code] = true; // value not used in fact } // but using $ec_current_code as a key makes a smaller table } // if the error comes back several times else { $first[$ec_current_code] = $ec_entry[$checked_item]; } } } foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here if (isset($to_correct[$ec_entry['code']])) { $ec_entry['action'] = $new_action; } } } // Multiple action params for a single code check ec_inpect('action', 'ec_nok_action_pb', true); // Multiple user_ids for a single code check ec_inpect('user_id', 'ec_nok_userid_pb'); // Multiple "forced" params for a single code check ec_inpect('forced', 'ec_ok_forced_pb', true, true); // User id and associated page validities checks foreach ($ec_lists['ec_table'] as &$ec_entry) { // Check if associated user_id exists if ( $ec_entry['action'] == 'ec_ok' and !array_key_exists($ec_entry['user_id'], $ec_lists['user_ids']) ) { $ec_entry['action'] = 'ec_nok_userid_miss'; } // Check if associated displayed page exists $a = 0; if (!empty($ec_entry['arg1']) and (strpos($ec_entry['action'], 'ec_ok') !== false)) $a++; // Only arg2 // is significant if action is ec_nok[_xxx] . if (!empty($ec_entry['arg2'])) $a+= 2; switch ($a) { // case 0 : home, nothing to check case 2: // Additional Page if ( $ec_ap_ok and ( $ec_entry['action'] == 'ec_ok' or $ec_entry['action'] == 'ec_nok' ) and !array_key_exists($ec_entry['arg2'], $ec_lists['add_pages']) ) { $ec_entry['action'].= '_ap_pb'; } break; case 1: // Category case 3: // Image if ($ec_entry['action'] == 'ec_ok') { if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) { if ($a == 3) { // case 3: // Image if (!mysql_fetch_row(pwg_query(' SELECT * FROM `'.IMAGE_CATEGORY_TABLE.'` WHERE `category_id` = '.$ec_entry['arg1'].' AND `image_id` = '.$ec_entry['arg2'] ))) { $ec_entry['action'].= '_img_pb'; } } } else { $ec_entry['action'].= '_cat_pb'; } } break; } } } /* * build_ec_lists() * builds the main array variable contaning all informations for the plugin * * @param * no parameter passed, the main material on which works the function, is * the global array variable $ec_lists. * @return * (no return value) */ function build_ec_lists() { global $ec_ap_ok, $template, $ec_lists; $ec_lists = array(); // Construction of $ec_lists['add_pages'] array var $ec_lists['add_pages'] = array(); if ($ec_ap_ok) { $res = pwg_query('SELECT id,title FROM '.ADD_PAGES_TABLE); while ($r = mysql_fetch_assoc($res)) { $c = (strpos($r['title'], '/user_id=')) ? '/user_id=' : '/group_id='; $a = explode($c ,$r['title']); $ec_lists['add_pages'][$r['id']] = $a[0]; } } // Construction of $ec_lists['categories'] array var $c = array(); display_select_cat_wrapper(' SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE, $c, 'category_options', true); $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options']; // Construction of $ec_lists['user_ids'] array var $ec_lists['user_ids'] = array(); $q = pwg_query('SELECT id,username FROM '.USERS_TABLE. ' WHERE id > 3'); while ($r = mysql_fetch_assoc($q)) { $ec_lists['user_ids'][$r['id']] = $r['username']; } // Construction of $ec_lists['ec_table'] array var build_ec_table(); } /* * str_from_var($var) * returns a string easing array var informations displaying in Piwigo : * _ the string return value starts with"

" ; * _ all "TAB" characters (chr(10)) are replaced by "
" ; * _ all spaces are replaced by " ". * * @param * $var : variable to display * @return * string easy to display in Piwigo */ function str_from_var($var) { return '

'.str_replace(chr(10),'
',str_replace(' ',' ', print_r /* var_dump */ ($var,true))).'

'; } ?>