예제 #1
0
 /**
  * @see EquipmentTypeInterface::get_cat_name()
  * @return string
  */
 public function get_cat_name()
 {
     if ($this->equipment_type_id and $this->equipment_type) {
         $equipment_cat = new EquipmentCat($this->equipment_type->get_cat_id());
         return $equipment_cat->get_name();
     } else {
         return null;
     }
 }
예제 #2
0
 /**
  * @throws EquipmentTypeIDMissingException
  */
 public static function create()
 {
     if ($_GET['action'] == "add_child" and $_GET['id'] or $_GET['action'] == "add") {
         if ($_GET['nextpage'] == 1) {
             $page_1_passed = true;
             if ($_POST['name'] or $_POST['manufacturer']) {
                 if ($_POST['name']) {
                     if (EquipmentType::exist_name($_POST['name']) == true) {
                         $page_1_passed = false;
                         $error = "This name already exists";
                     }
                 }
             } else {
                 $page_1_passed = false;
                 $error2 = "You must enter a name or a manufacturer";
             }
         } else {
             $page_1_passed = false;
             $error = "";
         }
         if ($page_1_passed == false) {
             $template = new HTMLTemplate("equipment/admin/equipment_type/add.html");
             $paramquery = $_GET;
             $paramquery['nextpage'] = "1";
             $params = http_build_query($paramquery, '', '&');
             $template->set_var("params", $params);
             if ($error1) {
                 $template->set_var("error1", $error1);
             } else {
                 $template->set_var("error1", "");
             }
             if ($error2) {
                 $template->set_var("error2", $error2);
             } else {
                 $template->set_var("error2", "");
             }
             if ($_POST['manufacturer']) {
                 $template->set_var("manufacturer", $_POST['manufacturer']);
             } else {
                 $template->set_var("manufacturer", "");
             }
             if ($_POST['name']) {
                 $template->set_var("name", $_POST['name']);
             } else {
                 $template->set_var("name", "");
             }
             if ($_POST['description']) {
                 $template->set_var("description", $_POST['description']);
             } else {
                 $template->set_var("description", "");
             }
             $cat_array = EquipmentCat::list_entries();
             $result = array();
             $counter = 0;
             foreach ($cat_array as $key => $value) {
                 $equipment_cat = new EquipmentCat($value);
                 $result[$counter]['value'] = $value;
                 $result[$counter]['content'] = $equipment_cat->get_name();
                 if ($_POST['cat_id'] == $value) {
                     $result[$counter]['selected'] = "selected='selected'";
                 } else {
                     $result[$counter]['selected'] = "";
                 }
                 $counter++;
             }
             $template->set_var("category", $result);
             $location_array = Location::list_entries();
             $result = array();
             $counter = 1;
             $result[0]['value'] = 0;
             $result[0]['content'] = "none";
             foreach ($location_array as $key => $value) {
                 $location = new Location($value);
                 $result[$counter]['value'] = $value;
                 $result[$counter]['content'] = $location->get_name(true);
                 $counter++;
             }
             $template->set_var("location", $result);
             $template->output();
         } else {
             $equipment_type = new EquipmentType(null);
             if ($_GET['action'] == "add_child" and is_numeric($_GET['id'])) {
                 $toid = $_GET['id'];
             } else {
                 $toid = null;
             }
             $paramquery = $_GET;
             unset($paramquery['action']);
             unset($paramquery['nextpage']);
             $params = http_build_query($paramquery, '', '&');
             if ($equipment_type->create($toid, $_POST['name'], $_POST['cat_id'], $_POST['location_id'], $_POST['description'], $_POST['manufacturer'])) {
                 Common_IO::step_proceed($params, "Add Equipment Type", "Operation Successful", null);
             } else {
                 Common_IO::step_proceed($params, "Add Equipment Type", "Operation Failed", null);
             }
         }
     } else {
         throw new EquipmentTypeIDMissingException();
     }
 }
예제 #3
0
 /**
  * @throws EquipmentCategoryIDMissingException
  */
 public static function edit()
 {
     if ($_GET['id']) {
         $equipment_cat = new EquipmentCat($_GET['id']);
         if ($_GET['nextpage'] == 1) {
             $page_1_passed = true;
             if ($_POST['name']) {
                 if (EquipmentCat::exist_name($_POST['name']) == true and $equipment_cat->get_name() != $_POST['name']) {
                     $page_1_passed = false;
                     $error = "This name already exists";
                 }
             } else {
                 $page_1_passed = false;
                 $error = "You must enter a name";
             }
         } else {
             $page_1_passed = false;
             $error = "";
         }
         if ($page_1_passed == false) {
             $template = new HTMLTemplate("equipment/admin/equipment_cat/edit.html");
             $paramquery = $_GET;
             $paramquery['nextpage'] = "1";
             $params = http_build_query($paramquery, '', '&');
             $template->set_var("params", $params);
             if ($error) {
                 $template->set_var("error", $error);
             } else {
                 $template->set_var("error", "");
             }
             if ($_POST['name']) {
                 $template->set_var("name", $_POST['name']);
             } else {
                 $template->set_var("name", $equipment_cat->get_name());
             }
             $template->output();
         } else {
             $paramquery = $_GET;
             unset($paramquery['nextpage']);
             unset($paramquery['action']);
             $params = http_build_query($paramquery);
             if ($equipment_cat->set_name($_POST['name'])) {
                 Common_IO::step_proceed($params, "Edit Equipment Category", "Operation Successful", null);
             } else {
                 Common_IO::step_proceed($params, "Edit Equipment Category", "Operation Failed", null);
             }
         }
     } else {
         throw new EquipmentCategoryIDMissingException();
     }
 }