コード例 #1
0
ファイル: questions.php プロジェクト: dasklney/traq
 /**
  * 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'));
 }
コード例 #2
0
ファイル: permissions.php プロジェクト: dasklney/traq
 /**
  * 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);
 }
コード例 #3
0
ファイル: Ticketlist.php プロジェクト: dasklney/traq
 /**
  * Returns the URL for sorting the provided ticket column.
  *
  * @param string $column
  *
  * @return string
  */
 public static function sortUrlFor($column)
 {
     // Get current order
     if (isset(Request::$request['order_by'])) {
         $order = explode('.', Request::$request['order_by']);
     } else {
         return Request::requestUri() . (strlen($_SERVER['QUERY_STRING']) ? '&' : '?') . "order_by={$column}.asc";
     }
     // Are we flipping the current sort?
     if ($order[0] == $column) {
         $query = "{$column}." . (strtolower($order[1]) == 'asc' ? 'desc' : 'asc');
     } else {
         $query = "{$column}.{$order[1]}";
     }
     return str_replace("order_by=" . implode('.', $order), "order_by={$query}", Request::requestUri());
 }