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']))){
45 $this->parent->handle->removeEnterprise($_POST['manufacturer']);
46 }
48 /* Add new Manufactuer : Open dialog with empty fields */
49 if(isset($_POST['add_manu'])){
50 $this->editMode = true;
51 $this->Edit_Add = "add";
52 foreach($this->attributes as $atr){
53 $this->$atr = "";
54 }
55 }
57 /* Edit existing manuatctuerer data */
58 if((isset($_POST['edit_manu']))&&(isset($_POST['manufacturer']))){
59 $this->editMode = true;
60 $this->Edit_Add = "edit";
61 $tmp = $this->parent->handle->getEnterprise($_POST['manufacturer']);
62 $tmp = $tmp[0];
63 foreach($this->attributes as $atr){
64 $this->$atr = "";
65 }
66 foreach($this->attributes as $atr){
67 if(isset($tmp[$atr])){
68 $this->$atr = $tmp[$atr];
69 }
70 }
71 $this->ID = $_POST['manufacturer'];
72 }
74 /* close Dialog without saving */
75 if(isset($_POST['close_manufacturer'])){
76 $this->editMode=false;
77 }
79 /* close dialog an save all changes / adds */
80 if(isset($_POST['save_manufacturer'])){
81 $tmp = array();
82 foreach($this->attributes as $attrs){
83 $tmp[$attrs]=$this->$attrs;
84 }
86 $allok = true;
87 if(empty($tmp['name'])){
88 print_red(_("Please specify a name."));
89 $allok = false;
90 }
92 /* all checks are ok , so save changes */
93 if($allok){
94 if($this->Edit_Add == "add"){
95 $this->parent->handle->addEnterprise($tmp);
96 $this->editMode=false;
97 }else{
98 $this->parent->handle->updateEnterprise($tmp,$this->ID);
99 $this->editMode=false;
100 }
101 }
102 }
104 /* As long as this war is true, we have to display the edit dialog */
105 if($this->editMode == true){
106 $this->save_object();
107 foreach($this->attributes as $attrs){
108 $smarty->assign($attrs,$this->$attrs);
109 }
111 $display.= $smarty->fetch(get_template_path('glpiManufacturerAdd.tpl', TRUE));
112 return($display);
113 }
116 $smarty->assign("Manus", $this->parent->handle->getEnterprises());
117 $smarty->assign("ManuKeys", array_flip($this->parent->handle->getEnterprises()));
118 $display.= $smarty->fetch(get_template_path('glpiManufacturer.tpl', TRUE));
119 return($display);
120 }
122 /* Save to LDAP */
123 function save()
124 {
125 }
127 function save_object()
128 {
129 foreach($this->attributes as $attr){
130 if(isset($_POST[$attr])){
131 $this->$attr = $_POST[$attr];
132 }
133 }
134 }
136 }
138 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
139 ?>