Example #1
0
 public function addNew()
 {
     if (in_array(Auth::getCapability(), array(CAPABILITY_ADMINISTRATOR, CAPABILITY_AUTHOR, CAPABILITY_CONTRIBUTOR, CAPABILITY_EDITOR))) {
         Model::autoloadModel('tag');
         $model = new TagModel($this->db);
         $this->para = new stdClass();
         if (isset($_POST['action']) && $_POST['action'] == "addNew") {
             $this->para->action = $_POST['action'];
             if (isset($_POST['name'])) {
                 $this->para->name = $_POST['name'];
             }
             if (isset($_POST['slug'])) {
                 $this->para->slug = $_POST['slug'];
             }
             if (isset($_POST['description'])) {
                 $this->para->description = $_POST['description'];
             }
             if (isset($_POST['parent'])) {
                 $this->para->parent = $_POST['parent'];
             }
             $result = $model->addToDatabase($this->para);
             if (!$result) {
                 $this->view->para = $this->para;
             }
         }
         $this->view->parentList = new SplDoublyLinkedList();
         $model->getAllSorted($this->view->parentList, $model->buildTree($model->getAll("tag")), -1);
         if (isset($_POST['ajax']) && !is_null($_POST['ajax'])) {
             $this->view->renderAdmin(RENDER_VIEW_TAG_ADD_NEW, TRUE);
         } else {
             $this->view->renderAdmin(RENDER_VIEW_TAG_ADD_NEW);
         }
     } else {
         $this->login();
     }
 }