public function templateSites() { $whitelist = array('site_name', 'site_challcount', 'regat_score', 'site_score', 'regat_solved', 'regat_lastdate', 'regat_onsitename'); $form_link = $this->getFormLink(); $form_all = $this->getFormAll(); $by = Common::getGet('by', 'site_name'); $dir = Common::getGet('dir', 'ASC'); $by = GDO::getWhitelistedByS($by, $whitelist, 'site_name'); $dir = GDO::getWhitelistedDirS($dir, 'ASC'); $orderby = "{$by} {$dir}"; $tVars = array('form_link' => $form_link === false ? '' : $form_link->templateX($this->module->lang('ft_link_site')), 'action' => GWF_WEB_ROOT . 'linked_sites', 'linked' => $this->getLinkedSites(GWF_Session::getUserID(), $orderby), 'form_update_all' => $form_all->templateX(), 'can_link' => count($this->not_linked) > 0, 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=WeChall&me=LinkedSites&by=%BY%&dir=%DIR%'); return $this->module->templatePHP('linked_sites.php', $tVars); }
public function templateChalls(GWF_User $user) { $whitelist = array('chall_score', 'chall_title', 'chall_creator_name', 'chall_solvecount', 'chall_date', 'chall_dif', 'chall_edu', 'chall_fun', 'csolve_date', 'csolve_time_taken'); require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php'; $challs = GDO::table('WC_Challenge'); $db = gdo_db(); $uid = $user->getVar('user_id'); $challs = GWF_TABLE_PREFIX . 'wc_chall'; $solved = GWF_TABLE_PREFIX . 'wc_chall_solved'; $by = GDO::getWhitelistedByS(Common::getGet('pcby'), $whitelist, self::DEFAULT_BY); $dir = GDO::getWhitelistedDirS(Common::getGet('pcdir'), self::DEFAULT_DIR); $orderby = "ORDER BY {$by} {$dir}"; $query = "SELECT c.*, s.* FROM {$challs} c LEFT JOIN {$solved} s ON c.chall_id=s.csolve_cid AND s.csolve_uid={$uid} {$orderby}"; $tVars = array('data' => $db->queryAll($query), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Profile&me=Profile&username='******'user_name') . '&pcby=%BY%&pcdir=%DIR%#wc_profile_challenges', 'table_title' => $this->module->lang('tt_challs_for', array('', $user->display('user_name')))); return $this->module->templatePHP('challs_profile.php', $tVars); }
private function templateRanking() { $whitelist = array('countryname', 'totalscore', 'users', 'avg', 'top3', 'topuser', 'spc'); $by = GDO::getWhitelistedByS(Common::getGet('by', 'avg'), $whitelist, 'avg'); $dir = GDO::getWhitelistedDirS(Common::getGet('dir', 'DESC'), 'DESC'); $users = GWF_TABLE_PREFIX . 'user'; $countries = GWF_TABLE_PREFIX . 'country'; $hide_ranking = 'user_options&0x10000000=0'; // $deleted = GWF_User::DELETED; $desc = "ORDER BY `user_level` DESC"; $not_deleted = "`user_options`&2=0"; $country_condition = "{$not_deleted} AND `user_countryid` = `country_id` AND {$hide_ranking}"; $ranked_condition = "{$country_condition} {$desc}"; $query = "SELECT " . "`c`.`country_id`, " . "`c`.`country_name` AS `countryname`, " . "COUNT(`u`.`user_id`) AS `users`, " . "SUM(`user_level`) AS `totalscore`, " . "MAX(`u`.`user_level`) AS `topscore`, " . "(SELECT `u`.`user_name` {$desc} LIMIT 1,1) as `topuser`, " . "AVG(`u`.`user_level`) AS `avg`, " . "SUM(`u`.`user_level`) AS `totalscore`, " . "(SELECT SUM(`u`.`user_level`) {$desc} LIMIT 3) as `top3`, " . 'ROUND(SUM(`u`.`user_level`) / `c`.`country_pop` * 1000, 2) AS `spc` ' . "FROM `{$countries}` AS `c` " . "LEFT JOIN `{$users}` AS `u` ON {$country_condition} " . "WHERE `c`.`country_id` > 0 " . "AND `user_level` > 0 " . "GROUP BY `c`.`country_id` " . "ORDER BY {$by} {$dir}"; $db = gdo_db(); if (false === ($result = $db->queryAll($query))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $tVars = array('highlight_country' => $this->getHighlightCountry(), 'data' => $result, 'sort_url' => GWF_WEB_ROOT . 'country_ranking/by/%BY%/%DIR%/page-1'); return $this->module->templatePHP('ranking_countries.php', $tVars); }
private function templateSolutions(WC_Challenge $chall, GWF_User $user, $length, $token) { $tt = $this->module->lang('pt_wmc_sol', array($chall->display('chall_title'), $length)); GWF_Website::setPageTitle($tt); $ipp = 50; $cid = $chall->getID(); $length = (int) $length; $whitelist = array('user_name', 'wmc_date', 'wmc_length', 'wmc_solution'); $by = GDO::getWhitelistedByS(Common::getGetString('by'), $whitelist, self::DEFAULT_BY); $dir = GDO::getWhitelistedDirS(Common::getGetString('dir'), self::DEFAULT_DIR); $wmc = GWF_TABLE_PREFIX . 'wc_math_chall'; $users = GWF_TABLE_PREFIX . 'user'; $where = "wmc_cid={$cid} AND wmc_length>={$length}"; $db = gdo_db(); $result = $db->queryFirst("SELECT COUNT(*) c FROM {$wmc} WHERE {$where}"); $nRows = (int) $result['c']; $nPages = GWF_PageMenu::getPagecount($ipp, $nRows); $page = Common::clamp(Common::getGetInt('page', 1), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $limit = GDO::getLimit($ipp, $from); $query = "SELECT user_name, wmc_date, wmc_length, wmc_solution FROM {$wmc} LEFT JOIN {$users} ON user_id=wmc_uid WHERE {$where} ORDER BY {$by} {$dir} {$limit}"; $tVars = array('sort_url' => GWF_WEB_ROOT . "index.php?mo=WeChall&me=MathSolutions&cid={$cid}&length={$length}&token={$token}&by=%BY%&dir=%DIR%", 'data' => $db->queryAll($query), 'page_menu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . sprintf('index.php?mo=WeChall&me=MathSolutions&cid=%d&length=%d&token=%s&by=%s&dir=%s&page=%%PAGE%%', $cid, $length, $token, urlencode($by), urlencode($dir))), 'table_title' => $tt, 'chall' => $chall); return $this->module->templatePHP('math_solutions.php', $tVars); }
private function onSearchB() { $whitelist = array('user_name', 'user_countryid', 'prof_icq', 'prof_msn', 'prof_jabber', 'prof_skype', 'prof_yahoo', 'prof_aim'); $ipp = 50; $db = gdo_db(); if ('' === ($where = $this->getWhereQuery())) { $where = "'1'='0'"; } $deleted = GWF_User::DELETED; $where .= " AND user_options&{$deleted}=0"; $users = GWF_TABLE_PREFIX . 'user'; $profiles = GWF_TABLE_PREFIX . 'profile'; $query = "SELECT COUNT(*) AS c FROM {$users} LEFT JOIN {$profiles} ON prof_uid=user_id WHERE {$where}"; if (false === ($result = $db->queryFirst($query, false))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $nRows = (int) $result['c']; $nPages = GWF_PageMenu::getPagecount($ipp, $nRows); $page = Common::clamp(Common::getGetInt('page', 1), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $limit = GDO::getLimit($ipp, $from); $by = GDO::getWhitelistedByS(Common::getGetString('by'), $whitelist, 'user_name'); $dir = GDO::getWhitelistedDirS(Common::getGetString('dir'), 'ASC'); $_GET['search'] = 'yes'; $query = "SELECT u.*, p.* FROM {$users} u LEFT JOIN {$profiles} p ON prof_uid=user_id WHERE {$where} ORDER BY {$by} {$dir} {$limit}"; $form = $this->formSearch(); $tVars = array('result' => $db->queryAll($query, true), 'form' => $form->templateY($this->module->lang('ft_search_adv'), $this->module->getMethodURL('SearchAdv')), 'pagemenu' => GWF_PageMenu::display($page, $nPages, $this->getPageMenuHREF()), 'sort_url' => $this->getSortHREF()); return $this->module->templatePHP('search_adv.php', $tVars); }