X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_glpiManufacturer.inc;h=120818a5ddc7839b1b52c753c21d7da1ec59d8de;hb=e646d1b091e3d40c67039125dae867faa6fdd402;hp=8463743a2ccae2684c5030105e2068cd9a80f40a;hpb=22f3e06448dd3c990c5997af704c3505a3563031;p=gosa.git diff --git a/plugins/admin/systems/class_glpiManufacturer.inc b/plugins/admin/systems/class_glpiManufacturer.inc index 8463743a2..120818a5d 100644 --- a/plugins/admin/systems/class_glpiManufacturer.inc +++ b/plugins/admin/systems/class_glpiManufacturer.inc @@ -36,13 +36,32 @@ class glpiManufacturer extends plugin function execute() { + plugin::execute(); $smarty = get_smarty(); $display = ""; + /* Remove enterprise from db */ if((isset($_POST['remove_manu']))&&(isset($_POST['manufacturer']))){ - $this->parent->handle->removeEnterprisesType($_POST['manufacturer']); + + $tmp = $this->parent->handle->is_manufacturerUsed($_POST['manufacturer']); + if(count($tmp)){ + + $names = ""; + foreach($tmp as $name){ + $names .= ", ".$name; + } + $names = preg_replace("/^, /","",$names); + $names = trim($names); + if(count($tmp) == 3){ + $names .= " ..."; + } + print_red(sprintf(_("You can't delete this manufacturer, it is still in use by these system(s) '%s'"),$names)); + }else{ + $this->parent->handle->removeEnterprise($_POST['manufacturer']); + } } + /* Add new Manufactuer : Open dialog with empty fields */ if(isset($_POST['add_manu'])){ $this->editMode = true; $this->Edit_Add = "add"; @@ -51,6 +70,7 @@ class glpiManufacturer extends plugin } } + /* Edit existing manuatctuerer data */ if((isset($_POST['edit_manu']))&&(isset($_POST['manufacturer']))){ $this->editMode = true; $this->Edit_Add = "edit"; @@ -67,26 +87,52 @@ class glpiManufacturer extends plugin $this->ID = $_POST['manufacturer']; } + /* close Dialog without saving */ if(isset($_POST['close_manufacturer'])){ $this->editMode=false; } + /* close dialog an save all changes / adds */ if(isset($_POST['save_manufacturer'])){ - $tmp = array(); foreach($this->attributes as $attrs){ $tmp[$attrs]=$this->$attrs; } - if($this->Edit_Add == "add"){ - $this->parent->handle->addEnterprisesType($tmp); + $allok = true; + if(empty($tmp['name'])){ + print_red(_("Please specify a name.")); + $allok = false; + } + + $attr = $this->parent->handle->getEnterprises(); + + if($this->ID == -1 ){ + if(in_array($tmp['name'],$attr)){ + $allok = false; + print_red(_("Specified name is already in use, please choose another one.")); + } }else{ - $this->parent->handle->updateEnterprisesType($tmp,$this->ID); + unset($attr[$this->ID]); + if(in_array($tmp['name'],$attr)){ + $allok = false; + print_red(_("Specified name is already in use, please choose another one.")); + } } - $this->editMode=false; + /* all checks are ok , so save changes */ + if($allok){ + if($this->Edit_Add == "add"){ + $this->parent->handle->addEnterprise($tmp); + $this->editMode=false; + }else{ + $this->parent->handle->updateEnterprise($tmp,$this->ID); + $this->editMode=false; + } + } } + /* As long as this war is true, we have to display the edit dialog */ if($this->editMode == true){ $this->save_object(); foreach($this->attributes as $attrs){ @@ -98,8 +144,8 @@ class glpiManufacturer extends plugin } - $smarty->assign("Manus", $this->parent->handle->getEnterprisesTypes()); - $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprisesTypes())); + $smarty->assign("Manus", $this->parent->handle->getEnterprises()); + $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprises())); $display.= $smarty->fetch(get_template_path('glpiManufacturer.tpl', TRUE)); return($display); } @@ -113,7 +159,7 @@ class glpiManufacturer extends plugin { foreach($this->attributes as $attr){ if(isset($_POST[$attr])){ - $this->$attr = $_POST[$attr]; + $this->$attr = stripslashes($_POST[$attr]); } } }