Code

3afa261c03a695b232107c57d312b47a1add7faf
[gosa.git] / gosa-plugins / glpi / admin / systems / services / glpi / class_glpiManufacturer.inc
1 <?php
3 class glpiManufacturer extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes= array("name","type","address","website","phonenumber","comments","deleted","fax","email");
8   var $objectclasses= array("whatever");
10   var $ui;
12   var $editMode = false;
13   var $Edit_Add = "edit";
15   var $name       ="";
16   var $type       ="";
17   var $address    ="";
18   var $website    ="";
19   var $phonenumber="";
20   var $comments   ="";
21   var $deleted    ="";
22   var $fax        ="";
23   var $email      ="";
24   var $ID         =-1;
26   function glpiManufacturer(&$config, $dn= NULL, $parent= NULL)
27   {
28     plugin::plugin ($config, $dn, $parent);
29     $this->ui = get_userinfo();  
30   }
32   function execute()
33   {
34     plugin::execute();
35     $smarty  = get_smarty();
36     $display = "";
38     /* Remove enterprise from db */
39     if((isset($_POST['remove_manu']))&&(isset($_POST['manufacturer']))){
41       $tmp = $this->parent->handle->is_manufacturerUsed($_POST['manufacturer']);
42       if(count($tmp)){
44         $names = "";
45         foreach($tmp as $name){
46           $names .= ", ".$name;
47         }
48         $names = preg_replace("/^, /","",$names);
49         $names = trim($names);
50         if(count($tmp) == 3){
51           $names .= " ...";
52         }
53         print_red(sprintf(_("You can't delete this manufacturer, it is still in use by these system(s) '%s'"),$names));
54       }else{
55         $this->parent->handle->removeEnterprise($_POST['manufacturer']);
56       }
57     }
59     /* Add new Manufactuer : Open dialog with empty fields */
60     if(isset($_POST['add_manu'])){
61       $this->editMode = true;
62       $this->Edit_Add = "add";
63       foreach($this->attributes as $atr){
64         $this->$atr = "";
65       }
66     }
68     /* Edit existing manuatctuerer data */
69     if((isset($_POST['edit_manu']))&&(isset($_POST['manufacturer']))){
70       $this->editMode = true;
71       $this->Edit_Add = "edit";
72       $tmp = $this->parent->handle->getEnterprise($_POST['manufacturer']);
73       $tmp = $tmp[0];
74       foreach($this->attributes as $atr){
75         $this->$atr = "";
76       }
77       foreach($this->attributes as $atr){
78         if(isset($tmp[$atr])){
79           $this->$atr = $tmp[$atr];
80         }
81       }
82       $this->ID = $_POST['manufacturer'];
83     }
85     /* close Dialog without saving */
86     if(isset($_POST['close_manufacturer'])){
87       $this->editMode=false;
88     }
90     /* close dialog an save all changes / adds */
91     if(isset($_POST['save_manufacturer'])){
92       $tmp = array();
93       foreach($this->attributes as $attrs){
94         $tmp[$attrs]=$this->$attrs;
95       }
97       $allok = true;
98       if(empty($tmp['name'])){
99         print_red(_("Please specify a name."));
100         $allok = false;
101       }
103       $attr = $this->parent->handle->getEnterprises();
105       if($this->ID == -1 ){
106         if(in_array($tmp['name'],$attr)){
107           $allok = false;
108           print_red(_("Specified name is already in use, please choose another one."));
109         }
110       }else{
111         unset($attr[$this->ID]);
112         if(in_array($tmp['name'],$attr)){
113           $allok = false;
114           print_red(_("Specified name is already in use, please choose another one."));
115         }
116       }
118       /* all checks are ok , so save changes */
119       if($allok){
120         if($this->Edit_Add == "add"){
121           $this->parent->handle->addEnterprise($tmp);
122           $this->editMode=false;
123         }else{
124           $this->parent->handle->updateEnterprise($tmp,$this->ID);
125           $this->editMode=false;
126         }
127       }
128     }
130     /* As long as this war is true, we have to display the edit dialog */
131     if($this->editMode == true){
132       $this->save_object();
133       foreach($this->attributes as $attrs){
134         $smarty->assign($attrs,$this->$attrs);
135       }
137       $display.= $smarty->fetch(get_template_path('glpiManufacturerAdd.tpl',TRUE,dirname(__FILE__)));
138       return($display);
139     }
142     $smarty->assign("Manus",    $this->parent->handle->getEnterprises());
143     $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprises()));
144     $display.= $smarty->fetch(get_template_path('glpiManufacturer.tpl',TRUE,dirname(__FILE__)));
145     return($display);
146   }
148   /* Save to LDAP */
149   function save()
150   {
151   }
153   function save_object()
154   {
155     foreach($this->attributes as $attr){
156       if(isset($_POST[$attr])){
157         $this->$attr = stripslashes($_POST[$attr]);
158       }
159     }
160   }
164 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
165 ?>