function editAction() { $request = new RivetyCore_Request($this->getRequest()); if ($request->has('role_id')) { $nav_id = $request->nav_id; $role_id = $request->role_id; $nav_table = new Navigation($role_id, $this->locale_code); $roles_table = new Roles(); $role = $roles_table->fetchRow("id = " . $role_id); if (!is_null($role)) { $role = $role->toArray(); $this->view->role = $role; } else { die("Invalid role."); } if ($this->getRequest()->isPost()) { $parent_id = $request->parent_id; $short_name = $request->short_name; $link_text = $request->link_text; $url = $request->url; $data = array( 'parent_id' => $parent_id, 'short_name' => $short_name, 'link_text' => $link_text, 'url' => $url, ); if ($nav_id == 0) { // INSERT $data['role_id'] = $role_id; // make sure it's the last item $data['sort_order'] = '99999999999'; $params = array($role_id,$this->locale_code); $nav_table->insert($data); // now get rid of all those nines RivetyCore_Sort::reNumber('Navigation', "parent_id = " . $parent_id . " and role_id = " . $role_id, 'id', 'sort_order', 10, $params); } else { // UPDATE $nav_table->update($data, 'id = ' . $nav_id); } RivetyCore_Cache::removeByTags(array('navigation')); $this->_redirect('/default/navigation/editrole/id/' . $role_id); } else { $nav_s = new Navigation($role_id,$this->locale_code); $new_nav = $nav_s->getNavTree(); $this->view->parent_choices = $new_nav; $this->view->role_id = $role_id; if ($nav_id == 0) { // CREATE $this->view->pagetitle = 'Create Nav Link for ' . $role['shortname'] . ' Role'; $this->view->nav_id = '0'; $this->view->parent_id = '0'; $this->view->short_name = ''; $this->view->link_text = ''; $this->view->url = ''; } else { // EDIT $nav_item_temp = $nav_table->fetchRow("id = " . $nav_id); if (!is_null($nav_item_temp)) { $this->view->pagetitle = "Edit Nav Link for " . $role["shortname"] . " Role"; $this->view->nav_id = $nav_id; $this->view->parent_id = $nav_item_temp->parent_id; $this->view->short_name = $nav_item_temp->short_name; $this->view->link_text = $nav_item_temp->link_text; $this->view->url = $nav_item_temp->url; } else { $this->_forward('default', 'auth', 'missing'); return; } } } } else { $this->_forward('default', 'auth', 'missing'); return; } }
header('WWW-Authenticate: Basic realm="Navigation"'); header('HTTP/1.0 401 Unauthorized'); echo json_encode($res); return; } $error = false; $out = null; $nav = new Navigation(); switch ($this->params[0]) { case 'update': $tree = $_POST['tree']; if (empty($tree)) { $tree = array(); } require_once 'apps/navigation/lib/Functions.php'; if ($nav->update($tree) && $nav->save()) { $out = array('msg' => sprintf('Nav json has been updated')); } else { $error = $nav->error; } break; default: $error = 'Unknown method'; break; } if (!$error) { require_once 'apps/navigation/lib/Functions.php'; navigation_clear_cache(); } $res = new StdClass(); if ($error) {