Ejemplo n.º 1
0
 /**
  * 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'));
 }
Ejemplo n.º 2
0
 /**
  * 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'));
 }
Ejemplo n.º 3
0
 /**
  * Delete ticket update
  *
  * @param integer $id
  */
 public function action_delete($id)
 {
     // Get the ticket update
     $history = \traq\models\TicketHistory::find($id);
     // Delete the update
     $history->delete();
     // Is this an ajax request?
     if (Request::isAjax()) {
         // Render the view
         View::set('history', $history);
     } else {
         // Just redirect back to the ticket
         Request::redirectTo($history->ticket->href());
     }
 }
Ejemplo n.º 4
0
 public static function init()
 {
     // Register namespace
     Autoloader::registerNamespace('CustomTabs', __DIR__);
     // Add routes
     Router::add('/admin/custom_tabs', 'CustomTabs::controllers::admin::CustomTabs.index');
     Router::add('/admin/custom_tabs/new', 'CustomTabs::controllers::admin::CustomTabs.new');
     Router::add('/admin/custom_tabs/([0-9]+)/(edit|delete)', 'CustomTabs::controllers::admin::CustomTabs.$2/$1');
     // Hook into the admin navbar
     FishHook::add('template:layouts/admin/main_nav', array(get_called_class(), 'admin_nav'));
     // Get tabs
     static::$tabs = CustomTab::fetch_all();
     View::set('custom_tabs', static::$tabs);
     // Hook into navbar
     FishHook::add('template:layouts/default/main_nav', array(get_called_class(), 'display_tabs'));
 }
Ejemplo n.º 5
0
 /**
  * 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'));
 }
Ejemplo n.º 6
0
 /**
  * Fetches all the data for the permission listing page.
  */
 private function permissions_for($type)
 {
     // Fetch groups, set permissions and actions arrays
     if ($type == 'usergroup') {
         $groups = Group::select()->where('is_admin', 1, '!=')->exec()->fetch_all();
         $groups = array_merge(array(new Group(array('id' => 0, 'name' => l('defaults')))), $groups);
     } elseif ($type == 'role') {
         $groups = ProjectRole::select()->custom_sql("WHERE project_id = 0 OR project_id = {$this->project->id}")->exec()->fetch_all();
         $groups = array_merge(array(new ProjectRole(array('id' => 0, 'name' => l('defaults'), 'project_id' => 0))), $groups);
     }
     $permissions = array();
     // Loop over the groups
     foreach ($groups as $group) {
         // Set the group array in the permissions array
         if (!isset($permissions[$group->id])) {
             $permissions[$group->id] = array();
         }
         // Loop over the permissions for the group
         foreach (Permission::get_permissions($this->project->id, $group->id, $type) as $action => $perm) {
             // Add the permission object to the permissions array
             $permissions[$group->id][$action] = $perm;
         }
     }
     // Send it all the to view.
     View::set('groups', $groups);
     View::set('permissions', $permissions);
     View::set('actions', permission_actions());
 }