Example #1
0
 /**
  * Returns a list of the field names and values for a given userlevel
  *
  * @param int $id incident id
  * @param int $user_level the user's role level
  * @return Result
  */
 public static function view_everything($id, $user_level)
 {
     $db = new Database();
     $db->select('form_response.form_response', 'form_field.field_name');
     $db->from('form_response');
     $db->join('form_field', 'form_response.form_field_id', 'form_field.id');
     $db->where(array('form_response.incident_id' => $id, 'form_field.field_ispublic_visible <=' => $user_level));
     $db->orderby('form_field.field_position');
     return $db->get();
 }
Example #2
0
 public function get_objects_of_this_kind_created_by(User_model $author, $object_names, $mode = Workshop_Core::AS_MIXED_ARRAY)
 {
     $database = new Database();
     $database->select('object_name, object_id');
     $database->from('workshop_data');
     $database->where(array('user_id' => $author->id));
     if ($object_names != null) {
         if (!is_array($object_names)) {
             $database->where('object_name', $object_names);
         } else {
             $database->in('object_name', $object_names);
         }
     }
     $database->orderby(array('object_name' => 'ASC', 'object_id' => 'ASC'));
     $results = $database->get();
     $array_of_objects = array();
     switch ($mode) {
         case Workshop_Core::AS_MIXED_ARRAY:
             foreach ($results as $row) {
                 $array_of_objects[] = ORM::factory($row->object_name, $row->object_id);
             }
             break;
         case Workshop_Core::AS_HIERARCHICAL_ARRAY:
             foreach ($results as $row) {
                 $array_of_objects[$row->object_name][] = ORM::factory($row->object_name, $row->object_id);
             }
             break;
         default:
             break;
     }
     return $array_of_objects;
 }
Example #3
0
 /**
  * Lists the reports.
  * @param int $page
  */
 function index($page = 1)
 {
     $this->template->content = new View('admin/mhi');
     $this->template->content->title = Kohana::lang('ui_admin.multiple_hosted_instances');
     $this->template->content->domain_name = $_SERVER['HTTP_HOST'];
     // check, has the form been submitted?
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('action', 'required', 'alpha', 'length[1,1]');
         $post->add_rules('instance_id.*', 'required', 'numeric');
         if ($post->validate()) {
             if ($post->action == 'a') {
                 // Approve Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '1';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.approved'));
             } elseif ($post->action == 'u') {
                 // Unapprove Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '0';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
             } elseif ($post->action == 'd') {
                 // Delete Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->delete();
                     }
                 }
                 $form_action = Kohana::lang('ui_admin.deleted');
             }
             $form_saved = TRUE;
         } else {
             $form_error = TRUE;
         }
     }
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     // Status is the "Show All/Pending/Approved tabs'
     if (!empty($_GET['status'])) {
         $status = strtolower($_GET['status']);
         if ($status == 'a') {
             $filter = 'site_active = 1';
         } elseif ($status == 'p') {
             $filter = 'site_active = 0';
         }
     } else {
         $status = '0';
         $filter = '1=1';
         // Using 1=1 is a way to preserve the "where" statement to reduce code complexity
     }
     $this->template->content->status = $status;
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('mhi_site')->where($filter)->count_all()));
     $this->template->content->pagination = $pagination;
     $db = new Database();
     $db->select('mhi_site.*, mhi_users.email, mhi_users.firstname, mhi_users.lastname');
     $db->from('mhi_site');
     $db->join('mhi_users', 'mhi_users.id', 'mhi_site.user_id');
     $db->where($filter);
     $db->orderby('mhi_site.site_dateadd', 'desc');
     $db->limit((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $instances = $db->get();
     $this->template->content->instances = $instances;
     $this->template->content->total_items = $pagination->total_items;
     // Javascript Header
     $this->template->js = new View('admin/mhi_js');
 }
 /**
  * This is still not enough! We need things like custom column orders
  * (so we can order plugins in their columns)
  *
  * @param array $settings Settings to be passed to the WHERE clause. Currently only separated by AND
  * @return unknown
  */
 function getPluginsBySetting($settings)
 {
     $out = array();
     $db = new Database();
     #$res = $db->query("SELECT * FROM plugin_instances LEFT JOIN container_plugin_settings ON plugin_instances.id = container_plugin_settings.id WHERE container_plugins.container_id='{$this->container_id}' ORDER BY container_plugins.id");
     $res = $db->from('plugin_instances')->where('container_id', $this->container_id);
     foreach ($settings as $column => $value) {
         $db->where($column, $value);
     }
     $res = $db->orderby('order', 'ASC')->get();
     foreach ($res->result(false) as $row) {
         $out[$row['plugin_name']]['column'] = $row['column'];
         $out[$row['plugin_name']]['order'] = $row['order'];
         $out[$row['plugin_name']]['template'] = $row['template'];
     }
     return $out;
 }