Exemplo n.º 1
0
 public function change_item()
 {
     $project_id = $this->post('projectID');
     $item_name = $this->post('itemName');
     $item_value = $this->post('itemValue');
     $json = Loader::helper('json');
     $pas = new PageActionStatus();
     $pas->action = t('Change Project Item');
     $pas->status = t('Unkown error');
     $pas->time = time();
     if (!fse_try_to_login()) {
         $pas->message = t('You do not sign in or session expired.');
         echo $json->encode($pas);
         exit(0);
     }
     if (!preg_match("/^[a-z0-9_\\-]{4,64}\$/", $project_id)) {
         $pas->message = t('Invalid project identifier!');
         echo $json->encode($pas);
         exit(0);
     }
     $page = ProjectInfo::getProjectPage($project_id, 'home');
     if ($page == false) {
         $pas->message = t('No such project!');
         echo $json->encode($pas);
         exit(0);
     }
     if (!in_array($item_name, $this->mItemList)) {
         $pas->message = t('Invalid item name!');
         echo $json->encode($pas);
         exit(0);
     }
     if (strlen($item_value) < 2) {
         $pas->message = t('Too short item value!');
         echo $json->encode($pas);
         exit(0);
     }
     $project_info = ProjectInfo::getBasicInfo($project_id);
     if ($project_info['fse_id'] != $_SESSION['FSEInfo']['fse_id']) {
         $pas->message = t('You are not the owner of the project!');
         return;
     }
     $db = Loader::db();
     $res = $db->Execute("UPDATE fsen_projects SET {$item_name}=? WHERE project_id=?", array($item_value, $project_id));
     if ($db->Affected_Rows() == 0) {
         $pas->message = t('Nothing changed!');
         echo $json->encode($pas);
         exit(0);
     }
     /* update page attributes */
     if ($item_name == "name") {
         $page->update(array("cName" => $item_value));
     } else {
         if ($item_name == "short_desc") {
             $page->update(array("cDescription" => $item_value));
         }
     }
     ProjectInfo::onUpdateProjectBasicInfo($project_id);
     /* refresh related blocks */
     $blocks = $page->getBlocks('Banner');
     foreach ($blocks as $block) {
         $block->refreshBlockOutputCache();
     }
     $cache = PageCache::getLibrary();
     $cache->purge($page);
     $pas->status = 'success';
     $pas->message = t('Item changed!');
     echo $json->encode($pas);
     exit(0);
 }