public static function form(\Request $request, $command = null)
 {
     javascript('jquery');
     \Form::requiredScript();
     if (empty($command)) {
         $command = 'run_search';
     }
     $system_locations = \systemsinventory\Factory\SystemDevice::getSystemLocations();
     $location_options = '<option value="0">All</opton>';
     foreach ($system_locations as $val) {
         $location_options .= '<option value="' . $val['id'] . '">' . $val['display_name'] . '</option>';
     }
     $vars['locations'] = $location_options;
     $system_types = \systemsinventory\Factory\SystemDevice::getSystemTypes();
     $type_options = '<option value="0">All</opton>';
     foreach ($system_types as $val) {
         $type_options .= '<option value="' . $val['id'] . '">' . $val['description'] . '</option>';
     }
     $vars['system_types'] = $type_options;
     $system_dep = \systemsinventory\Factory\SystemDevice::getSystemDepartments();
     $dep_optons = '<option value="0">All</opton>';
     foreach ($system_dep as $val) {
         $dep_optons .= '<option value="' . $val['id'] . '">' . $val['display_name'] . '</option>';
     }
     $vars['departments'] = $dep_optons;
     $vars['form_action'] = "./systemsinventory/search/" . $command;
     $template = new \Template($vars);
     $template->setModuleTemplate('systemsinventory', 'Search_System.html');
     return $template->get();
 }
 /**
  * Format the search row by translating id's to names and formatting the date to human readable
  * 
  * @param array $row
  * @return array
  */
 public static function alterSearchRow($row)
 {
     $row['department_id'] = \systemsinventory\Factory\SystemDevice::getDepartmentByID($row['department_id']);
     $row['location_id'] = \systemsinventory\Factory\SystemDevice::getLocationByID($row['location_id']);
     $row['purchase_date'] = date('n/d/Y', $row['purchase_date']);
     return $row;
 }
 public static function deleteDevice($device_id, $specific_device_id, $device_type_id)
 {
     $systems_device = new Resource();
     $systems_device->setId($device_id);
     if (!parent::loadByID($systems_device)) {
         throw new \Exception('Cannot load resource. System id not found:' . $device_id);
     }
     switch ($device_type_id) {
         case '1':
         case '2':
             $specific_device = new PCResource();
             break;
         case '3':
             $specific_device = new IPADResource();
             break;
         case '4':
             $specific_device = new PrinterResource();
             break;
         case '5':
             $specific_device = new CameraResource();
             break;
         case '6':
             $specific_device = new DigitalSignResource();
             break;
     }
     $specific_device->setId($specific_device_id);
     if (!parent::loadByID($specific_device)) {
         throw new \Exception('Cannot load specific resource. System id not found:' . $specific_device_id);
     }
     if (!SystemDevice::deleteResource($specific_device)) {
         throw new \Exception('Cannot delete specific resource. Query failed');
     }
     if (!SystemDevice::deleteResource($systems_device)) {
         throw new \Exception('Cannot delete resource. Query failed');
     }
 }
 protected function getJsonView($data, \Request $request)
 {
     $vars = $request->getRequestVars();
     $command = '';
     if (!empty($data['command'])) {
         $command = $data['command'];
     }
     if ($command == 'getDetails' && \Current_User::allow('systemsinventory', 'view')) {
         $result = SDFactory::getSystemDetails($vars['device_id'], $vars['row_index']);
     } else {
         if (\Current_User::allow('systemsinventory', 'edit')) {
             $system_details = '';
             switch ($command) {
                 case 'searchUser':
                     $result = SDFactory::searchUserByUsername($vars['username']);
                     break;
                 case 'getUser':
                     $result = SDFactory::getUserByUsername($vars['username']);
                     break;
                 case 'getProfile':
                     $result = SDFactory::getProfile($vars['profile_id']);
                     break;
                 case 'searchPhysicalID':
                     $result = SDFactory::searchPhysicalID($vars['physical_id']);
                     break;
                 case 'delete':
                     $result = SDFactory::deleteDevice($vars['device_id'], $vars['specific_device_id'], $vars['device_type_id']);
                     break;
                 default:
                     throw new Exception("Invalid command received in system controller getJsonView. Command = {$command}");
             }
         } else {
             $result = array('Error');
         }
     }
     $view = new \View\JsonView($result);
     return $view;
 }
 public static function userPermissionsList($data, $request)
 {
     $users = Settings::getPHPWSUsers();
     $departments_result = SystemDevice::getSystemDepartments();
     // convert to associative array
     foreach ($departments_result as $dept) {
         $departments[$dept['id']] = $dept['display_name'];
     }
     $rows = array();
     $db = \Database::getDB();
     $tbl = $db->addTable('systems_permission');
     $tbl->addField('user_id');
     $tbl->addField('departments');
     $tbl->addField('id');
     foreach ($users as $user) {
         $permissions = '';
         $permitted_dept = array();
         $db->clearConditional();
         $user_id = $user['id'];
         $tbl->addFieldConditional('user_id', $user_id, '=');
         $result = $db->select();
         if (!empty($result)) {
             $permitted_dept = explode(':', $result['0']['departments']);
             foreach ($permitted_dept as $dept) {
                 if (!empty($permissions)) {
                     $permissions .= ', ';
                 }
                 $permissions .= $departments[$dept];
             }
         } else {
             $permissions = "All Departments!";
         }
         $action = '<a style="cursor:pointer" onclick="return confirm(\'Are you sure you want to delete this users permissions?\')" href="./systemsinventory/settings/editPermissions/?action=delete&user_id=' . $user_id . '")>
             <span class="glyphicon glyphicon-trash" title="Delete Restrictions"></span></a>';
         $rows[] = array('display_name' => $user['display_name'], 'username' => $user['username'], 'permissions' => $permissions, 'action' => $action);
     }
     $pager = new \Pager();
     $pager->setId('user-permission-list');
     $pager->setHeaders(array('display_name' => 'Name', 'username' => 'Username', 'permissions' => 'Current Permissions'));
     $pager->setRows($rows);
     $data = $pager->getJson();
     return $data;
 }