Exemple #1
0
 public function action_editfields()
 {
     $groupId = intval($this->request->param('id'));
     $paramName = $this->request->param('param');
     $group = new Model_Material('groups');
     if (isset($_POST['delete_fields'])) {
         $result = $group->deleteParams($_POST['pid']);
     }
     if (isset($_POST['sort_fields']) && isset($_POST['params'])) {
         $group->sortParams($_POST['params'], $groupId);
         Controller::redirect('/admin/materials/' . $groupId . '/fields');
     }
     if (isset($_POST['saveParam'])) {
         $group->updateParam($_POST, $paramName, $groupId);
         Controller::redirect('/admin/materials/' . $groupId . '/fields');
     }
     if (isset($_POST['saveExcelSettings'])) {
         $group->updateExcelSettings($_POST, $groupId);
     }
     $groupData = $group->getGroup($groupId);
     $this->data['groups'] = $group->getTree();
     $this->data['groupParams'] = $group->getParams($groupId);
     $base = new Model_Base();
     $options = $base->getOptions();
     if (!$paramName) {
         $params = View::factory('admin/admParams', array('data' => $this->data['groupParams'], 'user' => $this->user, 'group' => $groupData, 'options' => $options));
     } else {
         $param_data = $group->getField($paramName, $groupId);
         $params = View::factory('admin/admParam', array('data' => $param_data, 'user' => $this->user, 'group' => $groupData, 'options' => $options));
     }
     $this->template->content = View::factory('admin/admMaterials', array('data' => $this->data, 'user' => $this->user, 'params' => $params));
 }
Exemple #2
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $ordering = $previousPos + 1;
         $result = $group->addParam(array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering));
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $oldGroup = Arr::get($_POST, 'old_group', '0');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         $result = $group->changeGroup($oldGroup, $newGroup, $ids);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials));
             $pagination->current_page = $pageNum;
             if (isset($_GET['sort'])) {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'));
             $data['material'] = $group->getAdminMaterial($materialId);
             //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $folders = $this->getFolders();
     $pictures = $this->action_pictures($wpm['folder']);
     $comments['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     // $this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments, 'pictures' => $pictures, 'wpm' => $wpm, ));
 }