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 $attr = $this->parent->handle->getEnterprises();
110 if($this->ID == -1 ){
111 if(in_array($tmp['name'],$attr)){
112 $allok = false;
113 print_red(_("Specified name is already in use, please choose another one."));
114 }
115 }else{
116 unset($attr[$this->ID]);
117 if(in_array($tmp['name'],$attr)){
118 $allok = false;
119 print_red(_("Specified name is already in use, please choose another one."));
120 }
121 }
123 /* all checks are ok , so save changes */
124 if($allok){
125 if($this->Edit_Add == "add"){
126 $this->parent->handle->addEnterprise($tmp);
127 $this->editMode=false;
128 }else{
129 $this->parent->handle->updateEnterprise($tmp,$this->ID);
130 $this->editMode=false;
131 }
132 }
133 }
135 /* As long as this war is true, we have to display the edit dialog */
136 if($this->editMode == true){
137 $this->save_object();
138 foreach($this->attributes as $attrs){
139 $smarty->assign($attrs,$this->$attrs);
140 }
142 $display.= $smarty->fetch(get_template_path('glpiManufacturerAdd.tpl', TRUE));
143 return($display);
144 }
147 $smarty->assign("Manus", $this->parent->handle->getEnterprises());
148 $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprises()));
149 $display.= $smarty->fetch(get_template_path('glpiManufacturer.tpl', TRUE));
150 return($display);
151 }
153 /* Save to LDAP */
154 function save()
155 {
156 }
158 function save_object()
159 {
160 foreach($this->attributes as $attr){
161 if(isset($_POST[$attr])){
162 $this->$attr = stripslashes($_POST[$attr]);
163 }
164 }
165 }
167 }
169 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
170 ?>