Exemplo n.º 1
0
 /**
  * @throws EquipmentTypeIDMissingException
  */
 public static function rename()
 {
     if ($_GET['id']) {
         $equipment_type = new EquipmentType($_GET['id']);
         if ($_GET['nextpage'] == 1) {
             $page_1_passed = true;
             if ($_POST['name'] or $_POST['manufacturer']) {
                 if ($_POST['name']) {
                     if (EquipmentType::exist_name($_POST['name']) == true and $equipment_type->get_name() != $_POST['name']) {
                         $page_1_passed = false;
                         $error = "This name already exists";
                     }
                 }
             } else {
                 $page_1_passed = false;
                 $error = "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/rename.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['manufacturer']) {
                 $template->set_var("manufacturer", $_POST['manufacturer']);
             } else {
                 if ($equipment_type->get_manufacturer()) {
                     $template->set_var("manufacturer", $equipment_type->get_manufacturer());
                 } else {
                     $template->set_var("manufacturer", "");
                 }
             }
             if ($_POST['name']) {
                 $template->set_var("name", $_POST['name']);
             } else {
                 if ($equipment_type->get_internal_name()) {
                     $template->set_var("name", $equipment_type->get_internal_name());
                 } else {
                     $template->set_var("name", "");
                 }
             }
             $template->output();
         } else {
             $paramquery = $_GET;
             unset($paramquery['nextpage']);
             $paramquery['action'] = "detail";
             $params = http_build_query($paramquery);
             if ($equipment_type->set_name($_POST['name']) and $equipment_type->set_manufacturer($_POST['manufacturer'])) {
                 Common_IO::step_proceed($params, "Rename Equipment Type", "Operation Successful", null);
             } else {
                 Common_IO::step_proceed($params, "Rename Equipment Type", "Operation Failed", null);
             }
         }
     } else {
         throw new EquipmentTypeIDMissingException();
     }
 }