Exemplo n.º 1
0
 private function onEdit(WC_Challenge $chall)
 {
     $form = $this->getForm($chall);
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $msgs = '';
     $wc = WC_Site::getWeChall();
     # Solution
     $is_case_i = isset($_POST['case_i']);
     if ('' !== ($solution = Common::getPostString('solution', ''))) {
         if (false === $chall->saveVar('chall_solution', $chall->hashSolution($solution, $is_case_i))) {
             $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # CASE_I
     $case_i = WC_Challenge::CHALL_CASE_I;
     if ($chall->isOptionEnabled($case_i) !== $is_case_i) {
         if (false === $chall->saveOption($case_i, $is_case_i)) {
             $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # Save score
     $new_score = $form->getVar('score');
     $old_score = $chall->getVar('chall_score');
     if ($new_score !== $old_score) {
         if (!WC_Challenge::isValidScore($new_score)) {
             $msgs .= $this->module->error('err_chall_score', array($new_score, WC_Challenge::MIN_SCORE, WC_Challenge::MAX_SCORE));
         }
         if (false === $chall->saveVar('chall_score', $new_score)) {
             $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         if (false === $wc->saveVar('site_maxscore', WC_Challenge::getMaxScore())) {
             $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         $wc->recalcSite();
     }
     # URL+Title (dangerous)
     if (false === $chall->saveVars(array('chall_url' => $form->getVar('url'), 'chall_title' => $form->getVar('title')))) {
         $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Creator:
     if (false === $chall->updateCreators($form->getVar('creators'))) {
         $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Tags:
     if (false === $chall->saveVar('chall_tags', trim($form->getVar('tags'), ' ,'))) {
         $msgs .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     Module_WeChall::instance()->cacheChallTags();
     # Done
     return $msgs . $this->module->message('msg_chall_edited');
 }