/** * Question management page. */ public function action_index() { // Set page title $this->title(l('security_questions')); // Extract questions $questions = json_decode(settings('security_questions'), true); // Add an empty question if (!count($questions)) { $questions[] = array('question' => '', 'answers' => ''); } // Check if the form has been submitted $errors = array(); if (Request::method() == 'post') { // Process questions $updated_questions = array(); foreach (Request::$post['questions'] as $id => $question) { // Check fields foreach ($question as $field => $value) { if (empty($value)) { $errors[$id][$field] = true; } } // Add if no errors if (!isset($errors[$id])) { $updated_questions[] = $question; } } // Save and redirect if (!count($errors)) { $this->db->update('settings')->set(array('value' => json_encode($updated_questions)))->where('setting', 'security_questions')->exec(); Request::redirect(Request::requestUri()); } } View::set(compact('questions', 'errors')); }
/** * Edit tab. * * @param integer $id Tab ID */ public function action_edit($id) { $tab = CustomTab::find($id); // Check if the form has been submitted. if (Request::method() == 'post') { $tab->set(array('label' => Request::post('label', $tab->label), 'url' => Request::post('url', $tab->url), 'groups' => implode(',', Request::post('groups', explode(',', $tab->groups))), 'display_order' => Request::post('display_order', $tab->display_order), 'project_id' => Request::post('project_id', $tab->project_id))); // Save and redirect if ($tab->save()) { Request::redirectTo('/admin/custom_tabs'); } } View::set(compact('tab')); }
/** * Handles the permissions listing and saving... * * Nice sexy DRY code right here, eh? */ public function action_index($type) { // If the type of permissions is 'groups', set it to 'usergroups'. $type = $type == 'groups' ? 'usergroup' : 'role'; // Has the form been submitted? if (Request::method() == 'post') { $global_defaults = Permission::defaults(0, 0, $type); // Loop over group/role and get id and permissions foreach (Request::$post['perm'] as $type_id => $permissions) { // Loop over permissions for id and value foreach ($permissions as $permission_id => $value) { // Fetch permission $perm = Permission::find($permission_id); // Are we dealing with a default? if ($type_id == 0) { // Does it exist? if ($perm->project_id > 0) { // We we need to delete it? if ($global_defaults[$perm->action]->value == $value) { $perm->delete(); } elseif ($perm->value != $value) { $perm->set('value', $value); $perm->save(); } } else { // Should we create it? if ($perm->value != $value) { // Create the permission $perm = new Permission(array('project_id' => $this->project->id, 'type' => $type, 'type_id' => $type_id, 'action' => $perm->action, 'value' => $value)); $perm->save(); } } } elseif ($perm and $perm->type_id == $type_id and $value == -1 and $type_id > 0) { $perm->delete(); } elseif ($value == 0 or $value == 1) { // Update if ($perm and $perm->type_id == $type_id) { $perm->value = $value; $perm->save(); } else { $perm = new Permission(array('project_id' => $this->project->id, 'type' => $type, 'type_id' => $type_id, 'action' => $perm->action, 'value' => $value)); $perm->save(); } } } } Request::redirect(Request::requestUri()); } // Setup the page $this->permissions_for($type); }
/** * Edit ticket update * * @param integer $id */ public function action_edit($id) { // Get the ticket update $history = \traq\models\TicketHistory::find($id); // Has the form been submitted? if (Request::method() == 'post') { // Update the comment $history->set('comment', Request::$post['comment']); // Save and redirect if ($history->save()) { Request::redirectTo($history->ticket->href()); } } View::set('history', $history); }
/** * Edit field page. * * @param integer $id */ public function action_edit($id) { // Get field $field = CustomField::find($id); // Verify project if ($field->project_id != $this->project->id) { return $this->show_no_permission(); } // Check if the form has been submitted if (Request::method() == 'post') { $data = array(); // Loop over properties foreach (CustomField::properties() as $property) { // Check if it's set and not empty if (isset(Request::$post[$property])) { $data[$property] = Request::$post[$property]; } } if ($this->is_api) { $data['is_required'] = Request::post('is_required', $field->is_required); $data['multiple'] = Request::post('multiple', $field->multiple); } else { $data['is_required'] = Request::post('is_required', 0); $data['multiple'] = Request::post('multiple', 0); } // Set field properties $field->set($data); // Save and redirect if ($field->save()) { if ($this->is_api) { return \API::response(1, array('field' => $field)); } else { Request::redirectTo($this->project->href('settings/custom_fields')); } } } // Send field object to view View::set(compact('field')); }