public function change_doc_part_name_desc() { $project_id = $this->post('projectID'); $domain_handle = $this->post('itemDomain'); $volume_handle = $this->post('itemVolume'); $part_handle = $this->post('itemPart'); $item_type = $this->post('itemType'); $item_value = $this->post('itemValue'); $json = Loader::helper('json'); $pas = new PageActionStatus(); $pas->action = t('Change Volume/Part Name/Desc'); $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 (!in_array($domain_handle, $this->mDomainList)) { $pas->status = "error"; $pas->message = "Invalid doc domain: {$domain_handle}!"; echo $json->encode($pas); exit(0); } if (!preg_match("/^[a-z0-9_\\-]{4,64}\$/", $project_id)) { $pas->status = "error"; $pas->message = "Invalid given project ID: {$project_id}!"; echo $json->encode($pas); exit(0); } $project_home_page = ProjectInfo::getProjectPage($project_id, 'home'); if ($project_home_page == false) { $pas->status = "error"; $pas->message = "No such project: {$project_id}!"; echo $json->encode($pas); exit(0); } if ($item_type == 'name') { if (!preg_match("/^.{1,64}\$/", $item_value)) { $pas->status = "error"; $pas->message = "Bad volume/part name: {$item_value}!"; echo $json->encode($pas); exit(0); } $page_property = 'cName'; } else { if ($item_type == 'desc') { if (!preg_match("/^.{2,255}\$/", $item_value)) { $pas->status = "error"; $pas->message = "Bad volume/part desc: {$item_value}!"; echo $json->encode($pas); exit(0); } $page_property = 'cDescription'; } else { $pas->status = "error"; $pas->message = "Bad item type: {$item_type}!"; echo $json->encode($pas); exit(0); } } $project_info = ProjectInfo::getBasicInfo($project_id); if ($project_info['fse_id'] != $_SESSION['FSEInfo']['fse_id']) { $pas->status = "error"; $pas->message = "You are not the owner of {$project_id}!"; echo $json->encode($pas); exit(0); } $db = Loader::db(); if (preg_match("/^[a-z0-9\\-]{3,16}\$/", $part_handle)) { $res = $db->Execute("UPDATE fsen_project_doc_volume_parts SET part_{$item_type}=?\n\tWHERE project_id=? AND domain_handle=? AND volume_handle=? AND part_handle=?", array($item_value, $project_id, $domain_handle, $volume_handle, $part_handle)); ProjectInfo::onUpdateProjectPartInfo($project_id, $domain_handle, $volume_handle, $part_handle); } else { $res = $db->Execute("UPDATE fsen_project_doc_volumes SET volume_{$item_type}=?\n\tWHERE project_id=? AND domain_handle=? AND volume_handle=?", array($item_value, $project_id, $domain_handle, $volume_handle)); ProjectInfo::onUpdateProjectVolumeInfo($project_id, $domain_handle, $volume_handle); } if ($db->Affected_Rows() == 0) { $pas->status = "error"; $pas->message = "Nothing changed!"; echo $json->encode($pas); exit(0); } $cache = PageCache::getLibrary(); /* update page attributes and refresh block caches */ if (preg_match("/^[a-z0-9\\-]{3,16}\$/", $part_handle)) { $page = ProjectInfo::getProjectPage($project_id, $domain_handle, $volume_handle, $part_handle); if ($page != false) { $page->update(array($page_property => $item_value)); $cache->purge($page); } } else { $page = ProjectInfo::getProjectPage($project_id, $domain_handle, $volume_handle); if ($page != false) { $page->update(array($page_property => $item_value)); $cache->purge($page); } $cache->purge($project_home_page); } $pas->status = "success"; $pas->message = "Item changed!"; echo $json->encode($pas); exit(0); }