public function action_delete($id = null)
 {
     if ($customer = Model_Customer::find($id)) {
         $customer->delete();
         Session::set_flash('success', e('Deleted customer #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete customer #' . $id));
     }
     Response::redirect('admin/customers');
 }
 public function action_delete($id = null)
 {
     if ($customer = Model_Customer::find($id)) {
         if (!$customer->projects) {
             $customer->delete();
             Session::set_flash('success', e('Deleted customer #' . $id));
         } else {
             Fuel\Core\Session::set_flash('error', e('This customer has ' . count($customer->projects) . ' projects and cannot be deleted.'));
         }
     } else {
         Session::set_flash('error', e('Could not delete customer #' . $id));
     }
     Response::redirect('admin/customers');
 }
 public function action_index()
 {
     $pagination = \Fuel\Core\Pagination::forge('userprojects', array('pagination_url' => \Fuel\Core\Config::get('pagination.pagination_url', '') . 'user/projects/index/', 'total_items' => Model_Project::count(array('related' => array('customer', 'project_members'), 'where' => array(array('project_members.user_id', $this->current_user->id)))), 'per_page' => \Fuel\Core\Config::get('pagination.per_page', 10), 'num_links' => \Fuel\Core\Config::get('pagination.num_links', 10), 'uri_segment' => \Fuel\Core\Config::get('pagination.uri_segment', 4), 'show_first' => \Fuel\Core\Config::get('pagination.show_first', false), 'show_last' => \Fuel\Core\Config::get('pagination.show_last', false)));
     $view = Fuel\Core\View::forge('user/projects/index');
     $view->set_global('user_is_admin', false);
     $view->set_global('projects', Model_Project::find('all', array('related' => array('customer', 'project_members'), 'order_by' => array('customer.name' => 'asc', 'name' => 'asc'), 'where' => array(array('project_members.user_id', $this->current_user->id)), 'limit' => $pagination->per_page, 'offset' => $pagination->offset)));
     $view->set_global('customers', \Fuel\Core\Arr::assoc_to_keyval(Model_Customer::find('all', array('order_by' => array('name' => 'asc'))), 'id', 'name'));
     $view->set_global('project_statuses', Model_Projectstatus::find('all', array('order_by' => array(array('description', 'asc')))));
     $view->set_global('selected_status_id', \Fuel\Core\Config::get('projects.default_status_id', 0));
     $view->set_global('user_is_admin', $this->check_user_is_admin());
     $view->set_global('project_status_id', 0);
     $view->set_global('selected_status_id', 0);
     $view->set_global('pagination', $pagination, false);
     $view->set_global('admin', false);
     $this->template->title = 'My Projects';
     $this->template->content = $view;
 }
 public function action_filter()
 {
     $user_id = \Fuel\Core\Input::param('user_id', 0);
     $client_id = Fuel\Core\Input::param('client_id', 0);
     $project_id = \Fuel\Core\Input::param('project_id', 0);
     $month = Fuel\Core\Input::param('month', '00');
     $year = Fuel\Core\Input::param('year', date('Y'));
     $status = 0;
     $data['open_tasks'] = THelper::get_tasks($user_id, $client_id, $project_id, $month, $year, $status, array(\Fuel\Core\Input::param('sort', 'priority') => \Fuel\Core\Input::param('order', 0)));
     $view = \Fuel\Core\View::forge('admin/tasks/index');
     $view->set_global('clients', Model_Customer::find('all', array('order_by' => array('name' => 'asc'))));
     $view->set_global('users', Model_User::find('all', array('order_by' => array('username' => 'asc'))));
     $view->set_global('years', range(2015, date('Y')));
     $view->set_global('months', THelper::get_months_array());
     $view->set_global('open_tasks', $data['open_tasks']);
     $view->set_global('admin', true);
     $this->template->title = 'Open Tasks';
     $this->template->content = $view;
 }