private function onUnFreeze($data) { if (false !== ($err = GWF_Form::validateCSRF_WeakS())) { return GWF_HTML::error('WeChall', $err); } if (!is_array($data)) { return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } foreach ($data as $key => $value) { break; } $data = explode(',', $key); if (count($data) !== 2) { return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } $userid = intval($data[0]); $siteid = intval($data[1]); if (false === ($user = GWF_User::getByID($userid))) { return GWF_HTML::err('ERR_UNKNOWN_USER'); } if (false === ($site = WC_Site::getByID($siteid))) { return $this->module->error('err_site'); } if (WC_Freeze::isUserFrozenOnSite($userid, $siteid)) { # Unfreeze if (false === WC_Freeze::unfreezeUser($userid, $siteid)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # Insert event. $rank = WC_RegAt::calcExactRank($user); WC_HistoryUser2::insertEntry($user, $site, 'unban'); } # Done return $this->module->message('msg_unfrozen', array($user->displayUsername(), $site->displayName())); }
private function onHardlink() { $form = $this->formHardlink(); if (false !== ($error = $form->validate($this->module))) { return $error; } $onsitename = Common::getPost('onsitename'); $site = $this->site; $user = $this->user; require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php'; require_once GWF_CORE_PATH . 'module/WeChall/WC_Freeze.php'; if (false !== WC_RegAt::getRegatRow($user->getID(), $site->getID())) { return $this->module->error('err_already_linked', array($site->displayName())); } if (WC_Freeze::isUserFrozenOnSite($user->getID(), $site->getID())) { return $this->module->error('err_site_ban', array($site->displayName())); } if (false !== ($regat = WC_RegAt::getByOnsitename($site->getID(), $onsitename))) { if (false === ($user = $regat->getUser())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } else { return $this->module->error('err_onsitename_taken', array(htmlspecialchars($onsitename), $site->displayName(), $user->displayUsername())); } } $entry = new WC_RegAt(array('regat_uid' => $user->getID(), 'regat_sid' => $site->getID(), 'regat_onsitename' => $onsitename, 'regat_onsitescore' => 0, 'regat_challcount' => 0, 'regat_options' => 0, 'regat_lastdate' => '', 'regat_linkdate' => GWF_Time::getDate(GWF_Date::LEN_DAY), 'regat_solved' => 0.0, 'regat_score' => 0, 'regat_langid' => 0, 'regat_tagbits' => 0, 'regat_onsiterank' => 0, 'regat_challsolved' => 0)); if (false === $entry->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (0 < ($percent = $form->getVar('percent'))) { $new_score = round($site->getOnsiteScore() * $percent / 100); $site->onUpdateUserB($user, $entry, $new_score, true, true); } return $this->module->message('msg_hardlinked', array($user->displayUsername(), $site->displayName(), GWF_HTML::display($onsitename))); }
private function onUnLinkSite($array) { if (false !== ($error = GWF_Form::validateCSRF_WeakS())) { return GWF_HTML::error('WeChall', $error); } if (!is_array($array)) { return ''; } // TODO: Replace with appropiate PHP function foreach ($array as $siteid => $stub) { break; } if (false === ($site = WC_Site::getByID($siteid))) { return $this->module->error('err_site'); } $user = GWF_Session::getUser(); $userid = GWF_Session::getUserID(); $old_totalscore = $user->getVar('user_level'); if (WC_Freeze::isUserFrozen($userid)) { return $this->module->error('err_frozen'); } if (false === ($regat = WC_RegAt::getRegatRow($userid, $site->getID()))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === WC_RegAt::unlink($userid, $site->getID())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $site->increase('site_linkcount', -1); WC_RegAt::calcTotalscores(); # (GWF_Session::getUser()); $user = GWF_User::getByID($userid); $new_totalscore = $user->getVar('user_level'); require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php'; WC_HistoryUser2::insertEntry($user, $site, 'unlink', 0, $regat->getOnsiteScore(), $new_totalscore - $old_totalscore); return $this->module->message('msg_site_unlinked', array($site->displayName())); }