Exemplo n.º 1
0
 /**
  * @throws SampleIDMissingException
  * @throws SampleSecurityAccessDeniedException
  */
 public static function move()
 {
     global $user, $sample_security;
     if ($_GET['sample_id']) {
         if ($sample_security->is_access(2, false)) {
             $sample_id = $_GET['sample_id'];
             $sample = new Sample($sample_id);
             if ($_GET['nextpage'] == 1) {
                 if (is_numeric($_POST['location'])) {
                     $page_1_passed = true;
                 } else {
                     $page_1_passed = false;
                     $error = "You must select a location.";
                 }
             } elseif ($_GET['nextpage'] > 1) {
                 $page_1_passed = true;
             } else {
                 $page_1_passed = false;
                 $error = "";
             }
             if ($page_1_passed == false) {
                 $template = new HTMLTemplate("sample/move.html");
                 $paramquery = $_GET;
                 $paramquery['nextpage'] = "1";
                 $params = http_build_query($paramquery, '', '&');
                 $template->set_var("params", $params);
                 $template->set_var("error", $error);
                 $result = array();
                 $counter = 0;
                 $sample_location_array = Location::list_entries();
                 if (is_array($sample_location_array) and count($sample_location_array) >= 1) {
                     foreach ($sample_location_array as $key => $value) {
                         $sample_location_obj = new Location($value);
                         $result[$counter]['value'] = $value;
                         $result[$counter]['content'] = $sample_location_obj->get_name(true);
                         $counter++;
                     }
                 } else {
                     $result[$counter]['value'] = "0";
                     $result[$counter]['content'] = "NO LOCATIONS FOUND!";
                 }
                 $template->set_var("option", $result);
                 $template->output();
             } else {
                 $paramquery = $_GET;
                 unset($paramquery['nextpage']);
                 $paramquery['run'] = "detail";
                 $params = http_build_query($paramquery);
                 if ($sample->add_location($_POST['location'])) {
                     Common_IO::step_proceed($params, "Move Sample", "Operation Successful", null);
                 } else {
                     Common_IO::step_proceed($params, "Move Sample", "Operation Failed", null);
                 }
             }
         } else {
             throw new SampleSecurityAccessDeniedException();
         }
     } else {
         throw new SampleIDMissingException();
     }
 }