Code

e7a9b65cb7a1a4bdb7cf227d2ebcde095f8a18a3
[gosa.git] / plugins / admin / systems / class_glpiManufacturer.inc
1 <?php
3 class glpiManufacturer extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account= TRUE;
12   var $attributes= array("name","type","address","website","phonenumber","comments","deleted","fax","email");
13   var $objectclasses= array("whatever");
15   var $ui;
17   var $editMode = false;
18   var $Edit_Add = "edit";
20   var $name       ="";
21   var $type       ="";
22   var $address    ="";
23   var $website    ="";
24   var $phonenumber="";
25   var $comments   ="";
26   var $deleted    ="";
27   var $fax        ="";
28   var $email      ="";
29   var $ID         =-1;
31   function glpiManufacturer($config, $dn= NULL)
32   {
33     plugin::plugin ($config, $dn);
34     $this->ui = get_userinfo();  
35   }
37   function execute()
38   {
39     plugin::execute();
40     $smarty  = get_smarty();
41     $display = "";
43     /* Remove enterprise from db */
44     if((isset($_POST['remove_manu']))&&(isset($_POST['manufacturer']))){
46       $tmp = $this->parent->handle->is_manufacturerUsed($_POST['manufacturer']);
47       if(count($tmp)){
49         $names = "";
50         foreach($tmp as $name){
51           $names .= ", ".$name;
52         }
53         $names = preg_replace("/^, /","",$names);
54         $names = trim($names);
55         if(count($tmp) == 3){
56           $names .= " ...";
57         }
58         print_red(sprintf(_("You can't delete this manufacturer, it is still in use by these system(s) '%s'"),$names));
59       }else{
60         //$this->parent->handle->removeEnterprise($_POST['manufacturer']);
61       }
62     }
64     /* Add new Manufactuer : Open dialog with empty fields */
65     if(isset($_POST['add_manu'])){
66       $this->editMode = true;
67       $this->Edit_Add = "add";
68       foreach($this->attributes as $atr){
69         $this->$atr = "";
70       }
71     }
73     /* Edit existing manuatctuerer data */
74     if((isset($_POST['edit_manu']))&&(isset($_POST['manufacturer']))){
75       $this->editMode = true;
76       $this->Edit_Add = "edit";
77       $tmp = $this->parent->handle->getEnterprise($_POST['manufacturer']);
78       $tmp = $tmp[0];
79       foreach($this->attributes as $atr){
80         $this->$atr = "";
81       }
82       foreach($this->attributes as $atr){
83         if(isset($tmp[$atr])){
84           $this->$atr = $tmp[$atr];
85         }
86       }
87       $this->ID = $_POST['manufacturer'];
88     }
90     /* close Dialog without saving */
91     if(isset($_POST['close_manufacturer'])){
92       $this->editMode=false;
93     }
95     /* close dialog an save all changes / adds */
96     if(isset($_POST['save_manufacturer'])){
97       $tmp = array();
98       foreach($this->attributes as $attrs){
99         $tmp[$attrs]=$this->$attrs;
100       }
102       $allok = true;
103       if(empty($tmp['name'])){
104         print_red(_("Please specify a name."));
105         $allok = false;
106       }
108       /* all checks are ok , so save changes */
109       if($allok){
110         if($this->Edit_Add == "add"){
111           $this->parent->handle->addEnterprise($tmp);
112           $this->editMode=false;
113         }else{
114           $this->parent->handle->updateEnterprise($tmp,$this->ID);
115           $this->editMode=false;
116         }
117       }
118     }
120     /* As long as this war is true, we have to display the edit dialog */
121     if($this->editMode == true){
122       $this->save_object();
123       foreach($this->attributes as $attrs){
124         $smarty->assign($attrs,$this->$attrs);
125       }
127       $display.= $smarty->fetch(get_template_path('glpiManufacturerAdd.tpl', TRUE));
128       return($display);
129     }
132     $smarty->assign("Manus",    $this->parent->handle->getEnterprises());
133     $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprises()));
134     $display.= $smarty->fetch(get_template_path('glpiManufacturer.tpl', TRUE));
135     return($display);
136   }
138   /* Save to LDAP */
139   function save()
140   {
141   }
143   function save_object()
144   {
145     foreach($this->attributes as $attr){
146       if(isset($_POST[$attr])){
147         $this->$attr = $_POST[$attr];
148       }
149     }
150   }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>