Пример #1
0
 /**
  * @throws SampleIDMissingException
  * @throws SampleSecurityAccessDeniedException
  */
 public static function ou_permission_add()
 {
     global $user;
     if ($_GET['sample_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['nextpage'] == 1) {
                 if (is_numeric($_POST['ou'])) {
                     if ($sample_security->is_organisation_unit($_POST['ou']) == true) {
                         $page_1_passed = false;
                         $error = "This organisation unit was already added.";
                     } else {
                         $page_1_passed = true;
                     }
                 } else {
                     $page_1_passed = false;
                     $error = "You must select an organisation unit.";
                 }
             } elseif ($_GET['nextpage'] > 1) {
                 $page_1_passed = true;
             } else {
                 $page_1_passed = false;
                 $error = "";
             }
             if ($page_1_passed == false) {
                 $template = new HTMLTemplate("sample/int_admin/ou_permission_add.html");
                 $paramquery = $_GET;
                 $paramquery['nextpage'] = "1";
                 $params = http_build_query($paramquery, '', '&');
                 $template->set_var("params", $params);
                 $template->set_var("error", $error);
                 $organisation_unit_array = OrganisationUnit::list_entries();
                 $result = array();
                 $counter = 0;
                 foreach ($organisation_unit_array as $key => $value) {
                     $organisation_unit = new OrganisationUnit($value);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['content'] = $organisation_unit->get_name();
                     $counter++;
                 }
                 $template->set_var("option", $result);
                 $template->output();
             } else {
                 $paramquery = $_GET;
                 unset($paramquery['nextpage']);
                 unset($paramquery['sure']);
                 $paramquery['nav'] = "sample";
                 $paramquery['run'] = "admin_permission_ou";
                 $params = http_build_query($paramquery);
                 if ($sample_security->create_organisation_unit($_POST['ou'])) {
                     Common_IO::step_proceed($params, "Add Permission", "Operation Successful", null);
                 } else {
                     Common_IO::step_proceed($params, "Add Permission", "Operation Failed", null);
                 }
             }
         } else {
             throw new SampleSecurityAccessDeniedException();
         }
     } else {
         throw new SampleIDMissingException();
     }
 }