function getCategory()
 {
     $session = Session::singletone();
     $db = Database::singletone()->db();
     $cid = Utils::pg("cid", 0);
     $fn_sep = Utils::pg('sub-separator', ' / ');
     $this->_query->appendChild($this->_dom->createElement("category-id", $cid));
     if ($cid <= 0) {
         $this->error("bad-arguments");
         return;
     }
     $category = new Category($cid);
     $parents = $category->getParentsObjs();
     $parents[] = $category;
     $parents_n = array();
     foreach ($parents as $p) {
         $parents_n[] = $p->dbdata('category_name');
     }
     $this->_response->appendChild($this->_dom->createElement('category-id', $category->dbdata('category_id')));
     $this->_response->appendChild($this->_dom->createElement('category-name', $category->dbdata('category_name')));
     $this->_response->appendChild($this->_dom->createElement('category-full-name', implode($fn_sep, $parents_n)));
     $this->_response->appendChild($this->_dom->createElement('category-description', $category->dbdata('category_description')));
     $this->_response->appendChild($this->_dom->createElement('category-parent', $category->dbdata('category_parent')));
     $this->_response->appendChild($this->_dom->createElement('category-order', $category->dbdata('category_order')));
     $this->_response->appendChild($this->_dom->createElement('category-created', Utils::formatTime($category->dbdata('category_created'), Config::getUser($session->uid(), 'datetime-format'))));
     $this->_response->appendChild($category->creator()->xml($this->_dom, 'creator'));
     $this->_response->appendChild($this->_dom->createElement('photos-count', $category->photosCount(false)));
     $this->_response->appendChild($this->_dom->createElement('total-photos-count', $category->photosCount(true)));
     $this->_response->appendChild($this->_dom->createElement('subcategories-count', $category->subCategoriesCount()));
     $pids = $category->photosPIDs(false);
     $tpids = $category->photosPIDs(true);
     $photos = $this->_dom->createElement('photos');
     foreach ($pids as $pid) {
         $photos->appendChild($this->_dom->createElement('photo-id', $pid));
     }
     $this->_response->appendChild($photos);
     $photos = $this->_dom->createElement('all-photos');
     foreach ($tpids as $pid) {
         $photos->appendChild($this->_dom->createElement('photo-id', $pid));
     }
     $this->_response->appendChild($photos);
     $this->success();
 }
Example #2
0
 protected function _edit_category()
 {
     $category_id = Utils::pg('cid', 0);
     if (!empty($category_id)) {
         if (!$this->session()->checkPerm('edit-categories')) {
             $this->denyAccess();
         }
     } else {
         if (!$this->session()->checkPerm('create-categories')) {
             $this->denyAccess();
         }
     }
     $this->addScript("js/functions.js");
     $this->addScript("js/behaviour.js");
     $this->addScript("js/advajax.js");
     $this->addScript("js/ajax.js");
     $this->addScript("js/admin/ctree.js");
     $this->addScript("js/admin/edit-category.js");
     $this->addCSS('css/admin/ctree.css');
     $category = new Category($category_id);
     $category_name = Utils::p("category_name", $category->dbdata('category_name'));
     $category_description = Utils::p("category_description", $category->dbdata('category_description'));
     $category_parent = Utils::p("category_parent", $category->dbdata('category_parent', null));
     $this->setTemplateVar('category_id', $category_id);
     $this->setTemplateVar('frm_category_name', $category_name);
     $this->setTemplateVar('frm_category_description', $category_description);
     $this->setTemplateVar('frm_category_parent', $category_parent);
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $category->setDBData('category_name', $category_name);
         $category->setDBData('category_description', $category_description);
         $category->setDBData('category_parent', $category_parent);
         $category->save();
         $category_id = $category->cid();
         $this->setTemplateVar('category_id', $category_id);
         $this->finishAction(_T("Kategoria zostaƂa zapisana."));
     }
 }