function check_version() { global $db; // check to see that all tables are present install_db(); // load version number from db $config = $db->Execute('select db_version from ' . DB_PREFIX . 'zh_config'); $db_version = $config->fields['db_version']; $config_file = file(DOC_REL_PATH . '/' . VERSION_FILENAME); if (is_array($config_file)) { foreach ($config_file as $line) { if (substr(trim($line), 0, 7) == 'version') { $file_version = trim(substr($line, strpos($line, '=') + 1, strpos($line, ';') - strpos($line, '=') - 1)); break; } } } else { die(TEXT_NO_VERSION . VERSION_FILENAME . '<br />' . TEXT_CHECK_CONFIG); } //echo 'db_version='.$db_version.' and file_version='.$file_version.'<br />'; if ($db_version != $file_version) { synchronize($file_version); } return; }
/** * synchronize number of posts credited to user * * @param int $uid uid of user row * @param string $type type of processing, 'user' for one user, 'all users' for all * * @return void */ function synchronize($uid, $type) { $xoops = Xoops::getInstance(); $db = $xoops->db(); switch ($type) { case 'user': $total_posts = 0; /* @var $plugin SystemPluginInterface */ $plugins = \Xoops\Module\Plugin::getPlugins(); foreach ($plugins as $plugin) { if ($res = $plugin->userPosts($uid)) { $total_posts += $res; } } $query = $db->createXoopsQueryBuilder()->updatePrefix('system_user')->set('posts', ':posts')->where('uid = :uid')->setParameter(':posts', $total_posts)->setParameter(':uid', $uid); $result = $query->execute(); //if (!$result) { // $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_NOT_UPDATED); //} break; case 'all users': $sql = $db->createXoopsQueryBuilder()->select('uid')->fromPrefix('system_user', 'u'); $result = $sql->execute(); if (!$result) { $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_ID_NOT_FETCHED); } $rows = $result->fetchAll(); foreach ($rows as $row) { synchronize($row['uid'], "user"); } break; } }
/** * @param $uid * @param $type */ function synchronize($uid, $type) { global $xoopsDB; include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; include_once XOOPS_ROOT_PATH . '/kernel/module.php'; $tables = array(); // Count comments (approved only: com_status == XOOPS_COMMENT_ACTIVE) $tables[] = array('table_name' => 'xoopscomments', 'uid_column' => 'com_uid', 'criteria' => new Criteria('com_status', XOOPS_COMMENT_ACTIVE)); // Count Content posts if (XoopsModule::getByDirname('fmcontent')) { $tables[] = array('table_name' => 'fmcontent_content', 'uid_column' => 'content_uid'); } // Count forum posts if (XoopsModule::getByDirname('newbb')) { $tables[] = array('table_name' => 'bb_posts', 'uid_column' => 'uid'); } switch ($type) { case 'user': $total_posts = 0; foreach ($tables as $table) { $criteria = new CriteriaCompo(); $criteria->add(new Criteria($table['uid_column'], $uid)); if (!empty($table['criteria'])) { $criteria->add($table['criteria']); } $sql = 'SELECT COUNT(*) AS total FROM ' . $xoopsDB->prefix($table['table_name']) . ' ' . $criteria->renderWhere(); if ($result = $xoopsDB->query($sql)) { if ($row = $xoopsDB->fetchArray($result)) { $total_posts += $row['total']; } } } $sql = 'UPDATE ' . $xoopsDB->prefix('users') . " SET posts = '" . $total_posts . "' WHERE uid = '" . $uid . "'"; if (!($result = $xoopsDB->queryF($sql))) { redirect_header('admin.php?fct=users', 1, _AM_SYSTEM_USERS_CNUUSER); } break; case 'all users': $sql = 'SELECT uid FROM ' . $xoopsDB->prefix('users') . ''; if (!($result = $xoopsDB->query($sql))) { redirect_header('admin.php?fct=users', 1, sprintf(_AM_SYSTEM_USERS_CNGUSERID, $uid)); } while ($data = $xoopsDB->fetchArray($result)) { synchronize($data['uid'], 'user'); } break; } // exit(); }
//print_r($obj); } $obj->setVar("level", 1); if ($member_handler->insertUser($obj, true)) { redirect_header("admin.php?fct=users", 1, _AM_SYSTEM_DBUPDATED); } echo $obj->getHtmlErrors(); break; // Synchronize // Synchronize case 'users_synchronize': if (isset($_REQUEST['status']) && $_REQUEST['status'] == 1) { synchronize(${$uid}, 'user'); } else { if (isset($_REQUEST['status']) && $_REQUEST['status'] == 2) { synchronize('', 'all users'); } } redirect_header("admin.php?fct=users", 1, _AM_SYSTEM_DBUPDATED); break; default: // Search and Display // Define scripts $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js'); //table sorting does not work with select boxes //$xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js'); $xoTheme->addScript('browse.php?modules/system/js/admin.js'); //Recherche approfondie if (isset($_REQUEST['complet_search'])) { // Assign Breadcrumb menu
// | | // | This program is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // +-----------------------------------------------------------------+ // Path: /modules/phreehelp/pages/main/pre_process.php // $security_level = validate_user(0, true); /************** include page specific files *********************/ require_once DIR_FS_WORKING . 'defaults.php'; require_once DIR_FS_WORKING . 'functions/phreehelp.php'; /************** page specific initialization *************************/ if (PHREEHELP_FORCE_RELOAD == '1') { // load/reload db tables if forced to synchronize(); write_configure('PHREEHELP_FORCE_RELOAD', '0'); } $frame_id = isset($_GET['fID']) ? $_GET['fID'] : 'main'; $context_ref = isset($_GET['idx']) ? $_GET['idx'] : ''; $result = false; $start_page = DOC_ROOT_URL; if ($context_ref) { $result = $db->Execute("select doc_url from " . TABLE_PHREEHELP . " where doc_pos = '" . $context_ref . "'"); if ($result->RecordCount() > 0) { $start_page = $result->fields['doc_url']; } } $frame_url = 'index.php?module=phreehelp&page=main'; /*************** hook for custom actions ***************************/ $custom_path = DIR_FS_WORKING . 'custom/pages/main/extra_actions.php';
$adduser_errormsg = _AM_CNRNU; } else { if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newuser->getVar('uid'))) { $adduser_errormsg = _AM_CNRNU2; } else { redirect_header("admin.php?fct=users", 1, _AM_DBUPDATED); exit; } } } } xoops_cp_header(); xoops_error($adduser_errormsg); xoops_cp_footer(); break; case "synchronize": synchronize($id, $type); break; case "reactivate": $result = $xoopsDB->query("UPDATE " . $xoopsDB->prefix("users") . " SET level=1 WHERE uid=" . $uid); if (!$result) { exit; } redirect_header("admin.php?fct=users&op=modifyUser&uid=" . $uid, 1, _AM_DBUPDATED); break; case "mod_users": default: include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; displayUsers(); break; }
} } redirect_header("admin.php?fct=users", 1, _AM_DBUPDATED); exit; } } } xoops_cp_header(); xoops_error($adduser_errormsg); xoops_cp_footer(); break; case "synchronize": if (!XoopsMultiTokenHandler::quickValidate('users_synchronize')) { system_users_error("Ticket Error"); } synchronize($_POST['id'], $_POST['type']); break; case "reactivate": if (!xoops_confirm_validate()) { system_users_error("Ticket Error"); } $uid = !empty($_POST['uid']) ? intval($_POST['uid']) : 0; if ($uid > 0) { $result = $xoopsDB->query("UPDATE " . $xoopsDB->prefix("users") . " SET level=1 WHERE uid=" . $uid); } redirect_header("admin.php?fct=users&op=modifyUser&uid=" . $uid, 1, _AM_DBUPDATED); break; case "mod_users": default: include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; displayUsers();
function synchronize($id, $type) { global $xoopsDB; switch ($type) { case 'user': $id = intval($id); // Array of tables from which to count 'posts' $tables = array(); // Count comments (approved only: com_status == XOOPS_COMMENT_ACTIVE) include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $tables[] = array('table_name' => 'xoopscomments', 'uid_column' => 'com_uid', 'criteria' => new Criteria('com_status', XOOPS_COMMENT_ACTIVE)); // Count forum posts $tables[] = array('table_name' => 'bb_posts', 'uid_column' => 'uid'); $total_posts = 0; foreach ($tables as $table) { $criteria = new CriteriaCompo(); $criteria->add(new Criteria($table['uid_column'], $id)); if (!empty($table['criteria'])) { $criteria->add($table['criteria']); } $sql = "SELECT COUNT(*) AS total FROM " . $xoopsDB->prefix($table['table_name']) . ' ' . $criteria->renderWhere(); if ($result = $xoopsDB->query($sql)) { if ($row = $xoopsDB->fetchArray($result)) { $total_posts = $total_posts + $row['total']; } } } $sql = "UPDATE " . $xoopsDB->prefix("users") . " SET posts = {$total_posts} WHERE uid = {$id}"; if (!($result = $xoopsDB->query($sql))) { exit(sprintf(_AM_CNUUSER % s, $id)); } break; case 'all users': $sql = "SELECT uid FROM " . $xoopsDB->prefix("users") . ""; if (!($result = $xoopsDB->query($sql))) { exit(_AM_CNGUSERID); } while ($row = $xoopsDB->fetchArray($result)) { $id = $row['uid']; synchronize($id, "user"); } break; default: break; } redirect_header("admin.php?fct=users&op=modifyUser&uid=" . $id, 1, _AM_DBUPDATED); exit; }