public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $cm = new waContactCategoryModel(); $id = waRequest::post('id'); $name = waRequest::post('name', 'string'); if (!$id) { if (!$name && $name !== '0') { throw new waException('No id and no name given.'); } $id = $cm->add($name); $this->logAction('category_add', $id); } else { if ($name || $name === '0') { $cm->updateById($id, array('name' => $name)); } } $this->response['id'] = $id; }
public function execute() { $id = waRequest::request('id', 0, 'int'); $category = null; $ccm = new waContactCategoryModel(); if ($id) { $category = $ccm->getById($id); } if (waRequest::post()) { if ($id && waRequest::post('delete')) { $ccm->delete($id); exit; } $name = waRequest::request('name'); $icon = waRequest::request('icon'); if ($id && $category) { $category['name'] = $name; $category['icon'] = $icon; $ccm->updateById($id, array('name' => $name, 'icon' => $icon)); } else { $category = array('name' => $name, 'icon' => $icon, 'app_id' => 'shop'); $id = $ccm->insert($category); $category['id'] = $id; } echo "<script>window.location.hash = '#/category/{$id}';\$.customers.reloadSidebar();</script>"; exit; } if (!$category) { $category = array('id' => '', 'name' => '', 'icon' => '', 'app_id' => ''); } $icons = self::getIcons(); if (empty($category['icon'])) { $category['icon'] = reset($icons); } $this->view->assign('category', $category); $this->view->assign('icons', $icons); }