/**
  * @param integer $folder_id
  */
 function __construct($folder_id)
 {
     global $user;
     if (is_numeric($folder_id)) {
         parent::__construct($folder_id);
         $this->sample_folder = new SampleHasFolder_Access($folder_id);
         $this->sample_id = $this->sample_folder->get_sample_id();
         if ($this->sample_id) {
             $sample_security = new SampleSecurity($this->sample_id);
             if ($this->get_automatic == false) {
                 $permission_bin = decbin($this->get_permission());
                 $permission_bin = str_pad($permission_bin, 16, "0", STR_PAD_LEFT);
                 $permission_bin = strrev($permission_bin);
             }
             // Read-Access
             if ($this->get_automatic() == true) {
                 if ($sample_security->is_access(1, false)) {
                     $this->read_access = true;
                 } else {
                     $this->read_access = false;
                 }
             } else {
                 if ($permission_bin[8] == "1" and $sample_security->is_access(1, false)) {
                     $this->read_access = true;
                 } else {
                     $this->read_access = false;
                 }
             }
             // Write-Access
             if ($this->get_automatic() == true) {
                 if ($sample_security->is_access(2, false)) {
                     $this->write_access = true;
                 } else {
                     $this->write_access = false;
                 }
             } else {
                 if ($permission_bin[9] == "1" and $sample_security->is_access(2, false)) {
                     $this->write_access = true;
                 } else {
                     $this->write_access = false;
                 }
             }
             // Delete-Access
             if ($user->is_admin() == true) {
                 if ($sample_security->is_access(5, false)) {
                     $this->delete_access = true;
                 } else {
                     $this->delete_access = false;
                 }
             } else {
                 if ($permission_bin[10] == "1" and $user->is_admin() == true) {
                     $this->delete_access = true;
                 } else {
                     $this->delete_access = false;
                 }
             }
             // Control-Access
             if ($user->is_admin() == true) {
                 if ($sample_security->is_access(7, false)) {
                     $this->control_access = true;
                 } else {
                     $this->control_access = false;
                 }
             } else {
                 if ($permission_bin[11] == "1" and $user->is_admin() == true) {
                     $this->control_access = true;
                 } else {
                     $this->control_access = false;
                 }
             }
         }
     } else {
         parent::__construct(null);
         $this->sample_folder = null;
         $this->sample_id = null;
     }
 }
Exemple #2
0
 /**
  * @param string $get_array
  * @throws SampleIDMissingException
  */
 public static function get_sample_information($get_array)
 {
     global $user;
     if ($get_array) {
         $_GET = unserialize($get_array);
     }
     if ($_GET['sample_id']) {
         $sample_security = new SampleSecurity($_GET['sample_id']);
         if ($sample_security->is_access(1, false)) {
             $sample = new Sample($_GET['sample_id']);
             $owner = new User($sample->get_owner_id());
             $template = new HTMLTemplate("sample/ajax/detail_information.html");
             $template->set_var("id", $sample->get_formatted_id());
             $template->set_var("name", $sample->get_name());
             $template->set_var("owner", $owner->get_full_name(false));
             $template->set_var("template", $sample->get_template_name());
             $template->set_var("permissions", $sample_security->get_access_string());
             $datetime = new DatetimeHandler($sample->get_datetime());
             $template->set_var("datetime", $datetime->get_datetime());
             if ($sample->get_date_of_expiry()) {
                 $date_of_expiry = new DatetimeHandler($sample->get_date_of_expiry());
                 $template->set_var("date_of_expiry", $date_of_expiry->get_date());
             } else {
                 $template->set_var("date_of_expiry", false);
             }
             if ($sample->get_current_location_name()) {
                 $template->set_var("location", $sample->get_current_location_name());
             } else {
                 $template->set_var("location", false);
             }
             if ($sample->get_manufacturer_id()) {
                 $manufacturer = new Manufacturer($sample->get_manufacturer_id());
                 $template->set_var("manufacturer", $manufacturer->get_name());
             } else {
                 $template->set_var("manufacturer", false);
             }
             if ($sample->get_availability() == true) {
                 $template->set_var("status", "available");
             } else {
                 $template->set_var("status", "not available");
             }
             if ($sample->get_owner_id() == $user->get_user_id() or $user->is_admin() == true) {
                 $template->set_var("is_owner", true);
             } else {
                 $template->set_var("is_owner", false);
             }
             if ($user->is_admin() == true) {
                 $template->set_var("is_admin", true);
             } else {
                 $template->set_var("is_admin", false);
             }
             $owner_paramquery = array();
             $owner_paramquery['username'] = $_GET['username'];
             $owner_paramquery['session_id'] = $_GET['session_id'];
             $owner_paramquery['nav'] = "sample";
             $owner_paramquery['run'] = "common_dialog";
             $owner_paramquery['dialog'] = "user_detail";
             $owner_paramquery['id'] = $sample->get_owner_id();
             $owner_params = http_build_query($owner_paramquery, '', '&');
             $template->set_var("owner_params", $owner_params);
             $location_history_paramquery = $_GET;
             $location_history_paramquery['run'] = "location_history";
             $location_history_params = http_build_query($location_history_paramquery, '', '&');
             $template->set_var("location_history_params", $location_history_params);
             $template->output();
         }
     } else {
         throw new SampleIDMissingException();
     }
 }
 /**
  * @param string $json_column_array
  * @param string $json_argument_array
  * @param string $css_page_id
  * @param string $css_row_sort_id
  * @param string $entries_per_page
  * @param string $page
  * @param string $sortvalue
  * @param string $sortmethod
  * @return string
  * @throws BaseAjaxArgumentMissingException
  */
 public static function list_samples($json_column_array, $json_argument_array, $css_page_id, $css_row_sort_id, $entries_per_page, $page, $sortvalue, $sortmethod)
 {
     $argument_array = json_decode($json_argument_array);
     if (is_array($argument_array)) {
         $name = $argument_array[0][1];
         $organisation_unit_array = $argument_array[1][1];
         $template_array = $argument_array[2][1];
         $in_id = $argument_array[3][1];
         $in_name = $argument_array[4][1];
         $list_request = new ListRequest_IO();
         $list_request->set_column_array($json_column_array);
         if (!is_numeric($entries_per_page) or $entries_per_page < 1) {
             $entries_per_page = 20;
         }
         $list_array = Sample_Wrapper::list_sample_search($name, $organisation_unit_array, $template_array, $in_id, $in_name, $sortvalue, $sortmethod, $page * $entries_per_page - $entries_per_page, $page * $entries_per_page);
         if (is_array($list_array) and count($list_array) >= 1) {
             $today_end = new DatetimeHandler(date("Y-m-d") . " 23:59:59");
             foreach ($list_array as $key => $value) {
                 $datetime_handler = new DatetimeHandler($list_array[$key]['datetime']);
                 $list_array[$key]['datetime'] = $datetime_handler->get_datetime(false);
                 if ($list_array[$key]['av'] == "f") {
                     $list_array[$key]['av'] = "<img src='images/icons/grey_point.png' alt='' />";
                 } else {
                     if ($list_array[$key]['date_of_expiry'] and $list_array[$key]['expiry_warning']) {
                         $date_of_expiry = new DatetimeHandler($list_array[$key]['date_of_expiry'] . " 23:59:59");
                         $warning_day = clone $date_of_expiry;
                         $warning_day->sub_day($list_array[$key]['expiry_warning']);
                         if ($date_of_expiry->distance($today_end) > 0) {
                             $list_array[$key]['av'] = "<img src='images/icons/red_point.png' alt='' />";
                         } else {
                             if ($warning_day->distance($today_end) > 0) {
                                 $list_array[$key]['av'] = "<img src='images/icons/yellow_point.png' alt='' />";
                             } else {
                                 $list_array[$key]['av'] = "<img src='images/icons/green_point.png' alt='' />";
                             }
                         }
                     } else {
                         $list_array[$key]['av'] = "<img src='images/icons/green_point.png' alt='' />";
                     }
                 }
                 $sample_id = $list_array[$key]['id'];
                 $sample_security = new SampleSecurity($sample_id);
                 if ($sample_security->is_access(1, false)) {
                     $paramquery = array();
                     $paramquery['username'] = $_GET['username'];
                     $paramquery['session_id'] = $_GET['session_id'];
                     $paramquery['nav'] = "sample";
                     $paramquery['run'] = "detail";
                     $paramquery['sample_id'] = $sample_id;
                     $params = http_build_query($paramquery, '', '&#38;');
                     $list_array[$key]['symbol']['link'] = $params;
                     $list_array[$key]['symbol']['content'] = "<img src='images/icons/sample.png' alt='' style='border:0;' />";
                     unset($list_array[$key]['id']);
                     $list_array[$key]['id']['link'] = $params;
                     $list_array[$key]['id']['content'] = "S" . str_pad($sample_id, 8, '0', STR_PAD_LEFT);
                     $sample_name = $list_array[$key]['name'];
                     unset($list_array[$key]['name']);
                     $list_array[$key]['name']['link'] = $params;
                     $list_array[$key]['name']['content'] = $sample_name;
                 } else {
                     $list_array[$key]['symbol'] = "<img src='core/images/denied_overlay.php?image=images/icons/sample.png' alt='N' border='0' />";
                     $list_array[$key]['id'] = "S" . str_pad($sample_id, 8, '0', STR_PAD_LEFT);
                 }
             }
         } else {
             $list_request->empty_message("<span class='italic'>No results found!</span>");
         }
         $list_request->set_array($list_array);
         return $list_request->get_page($page);
     } else {
         throw new BaseAjaxArgumentMissingException();
     }
 }
Exemple #4
0
 /**
  * @param string $role
  * @throws ItemParentIDMissingException
  * @throws ItemPositionIDMissingException
  * @throws BaseModuleDialogMethodNotFoundException
  * @throws BaseModuleDialogClassNotFoundException
  * @throws BaseModuleDialogFileNotFoundException
  * @throws BaseModuleDialogNotFoundException
  * @throws SampleSecurityAccessDeniedException
  * @throws BaseModuleDialogMissingException
  */
 public static function item_add_edit_handler($role = "add")
 {
     if ($_GET['dialog']) {
         if (!is_numeric($_GET['parent_id'])) {
             throw new ItemParentIDMissingException();
         }
         if (!is_numeric($_GET['key'])) {
             throw new ItemPositionIDMissingException();
         }
         $sample = new Sample($_GET['parent_id']);
         $sample_security = new SampleSecurity($_GET['parent_id']);
         if ($sample_security->is_access(2, false) == true) {
             if ($role == "add") {
                 $module_dialog = ModuleDialog::get_by_type_and_internal_name("item_add", $_GET['dialog']);
             } elseif ($role == "edit") {
                 $module_dialog = ModuleDialog::get_by_type_and_internal_name("item_edit", $_GET['dialog']);
             }
             if (is_array($module_dialog) and $module_dialog['class_path']) {
                 if (file_exists($module_dialog['class_path'])) {
                     require_once $module_dialog['class_path'];
                     if (class_exists($module_dialog['class'])) {
                         if (method_exists($module_dialog['class'], $module_dialog['method'])) {
                             $sample_item = new SampleItem($_GET['parent_id']);
                             $sample_item->set_gid($_GET['key']);
                             $current_requirements = $sample->get_requirements();
                             if ($role == "add") {
                                 $module_dialog['class']::$module_dialog['method']($current_requirements[$_GET['key']]['type_id'], $current_requirements[$_GET['key']]['category_id'], "Sample", $_GET['parent_id'], $_GET['key']);
                             } elseif ($role == "edit") {
                                 $module_dialog['class']::$module_dialog['method']($current_requirements[$_GET['key']]['fulfilled'][0]['item_id']);
                             }
                         } else {
                             throw new BaseModuleDialogMethodNotFoundException();
                         }
                     } else {
                         throw new BaseModuleDialogClassNotFoundException();
                     }
                 } else {
                     throw new BaseModuleDialogFileNotFoundException();
                 }
             } else {
                 throw new BaseModuleDialogNotFoundException();
             }
         } else {
             throw new SampleSecurityAccessDeniedException();
         }
     } else {
         throw new BaseModuleDialogMissingException();
     }
 }
Exemple #5
0
 /**
  * @see SampleInterface::get_organisation_unit_id()
  * @return integer
  */
 public function get_organisation_unit_id()
 {
     if ($this->sample_id) {
         $sample_security = new SampleSecurity($this->sample_id);
         $sample_security_array = $sample_security->list_organisation_units();
         if (is_array($sample_security_array) and count($sample_security_array) >= 1) {
             return $sample_security_array[0];
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Exemple #6
0
 /**
  * @throws SampleIDMissingException
  * @throws SampleSecurityAccessDeniedException
  * @throws SamplePermissionOrganisationUnitIDMissingException
  */
 public static function ou_permission_delete()
 {
     global $user;
     if ($_GET['sample_id']) {
         if ($_GET['id']) {
             $sample_id = $_GET['sample_id'];
             $sample = new Sample($sample_id);
             $sample_security = new SampleSecurity($sample_id);
             if ($sample->get_owner_id() == $user->get_user_id() or $user->is_admin() == true) {
                 if ($_GET['sure'] != "true") {
                     $template = new HTMLTemplate("sample/int_admin/ou_permission_delete.html");
                     $paramquery = $_GET;
                     $paramquery['sure'] = "true";
                     $params = http_build_query($paramquery);
                     $template->set_var("yes_params", $params);
                     $paramquery = $_GET;
                     unset($paramquery['nextpage']);
                     unset($paramquery['sure']);
                     $paramquery['nav'] = "sample";
                     $paramquery['run'] = "admin_permission_ou";
                     $params = http_build_query($paramquery);
                     $template->set_var("no_params", $params);
                     $template->output();
                 } else {
                     $paramquery = $_GET;
                     unset($paramquery['nextpage']);
                     unset($paramquery['sure']);
                     $paramquery['nav'] = "sample";
                     $paramquery['run'] = "admin_permission_ou";
                     $params = http_build_query($paramquery);
                     $entry_id = $sample_security->get_entry_by_organisation_unit_id($_GET['id']);
                     if ($sample_security->delete_organisation_unit($entry_id)) {
                         Common_IO::step_proceed($params, "Delete Sample", "Operation Successful", null);
                     } else {
                         Common_IO::step_proceed($params, "Delete Sample", "Operation Failed", null);
                     }
                 }
             } else {
                 throw new SampleSecurityAccessDeniedException();
             }
         } else {
             throw new SamplePermissionOrganisationUnitIDMissingException();
         }
     } else {
         throw new SampleIDMissingException();
     }
 }