Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
1 <?php
3 class glpiAccount 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("ID","name","contact",
13                          "tech_num","comments","date_mod","os","location","domain","network",
14                          "model","type","is_template","FK_glpi_enterprise","deleted");
16   var $ID                 ;
17   var $name               ="";
18   var $contact            ="";
20   var $tech_num           ="";
21   var $comments           ="";
23   var $date_mod           ="";
24   var $os                 =0;
25   var $location           =0;
26   var $domain             =0;
27   var $network            =0; 
29   var $model              =0;
30   var $type               =0;
31   var $is_template        =0;
32   var $FK_glpi_enterprise =0;
33   var $deleted            ="N";
35   var $objectclasses= array("whatever");
37   var $initialy_was_account = false;
39   var $edit_type    =false;
40   var $edit_os    =false;
42   var $data;
43   var $handle = NULL;
45   var $cur_dialog = NULL;
47   var $orig_dn;
48   var $ui;
50   /* Contructor 
51      Sets default values and checks if we already have an existing glpi account
52   */
53   function glpiAccount ($config, $dn= NULL)
54   {
55     plugin::plugin ($config, $dn);
56     $this->ui= get_userinfo();
58     if(!isset($this->config->data['SERVERS']['GLPI'])){
59       return;
60     }
61     
62     $this->data = $this->config->data['SERVERS']['GLPI'];
63     
64     if(!is_callable("mysql_connect")){
65       return;
66     }
67     
68     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
69     
70     if(!$this->handle->is_connected){
71       return;
72     } 
74     if($this->handle->is_account($this->dn)){
75       $this->is_account = true;
76       $tmp = ($this->handle->getComputerInformations($this->dn));
78       foreach(array("tech_num","os","FK_glpi_enterprise","type","comments") as $attr){
79         $this->$attr = $tmp[0][$attr];
80       }
82     }else{
83       $this->is_account = false;
84     }
86     $this->name = $this->dn;
87     $this->orig_dn = $this->dn;
88     $this->initialy_was_account = $this->is_account;
89   }
91   function execute()
92   {
93         /* Call parent execute */
94           plugin::execute();
96     /* Fill templating stuff */
97     $smarty= get_smarty();
98     $display= "";
100     // #fixme
101     // Check if mysql a.s.o. is available.
102     
104     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
105     $users = ($this->handle->getUsers());
107     $ldap= $this->config->get_ldap_link();
110   /* System type management
111    */
112   if(isset($_POST['edit_type'])){
113     $this->dialog = true;
114     $this->edit_type=true;
115   }
117   if(isset($_POST['close_edit_type'])){
118     $this->edit_type=false;
119     $this->dialog = false;
120   }
122   if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
123     $this->handle->addSystemType($_POST['type_string']);  
124   }
126   if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
127     $this->handle->removeSystemType_byID($_POST['select_type']);  
128   }
130   if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
131     $this->handle->updateSystemType($_POST['type_string'],$_POST['select_type']);
132   }
134   if($this->edit_type){
135     $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
136     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
138     $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
139     return($display);
140   }
142   /*  ENDE, Systemtype management.
143    */
144   
145   /* System os management
146    */
147   if(isset($_POST['edit_os'])){
148     $this->dialog = true;
149     $this->edit_os=true;
150   }
152   if(isset($_POST['close_edit_os'])){
153     $this->edit_os=false;
154     $this->dialog = false;
155   }
157   if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){
158     $this->handle->addOS($_POST['is_string']);  
159   }
161   if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))){
162     $this->handle->removeOS_byID($_POST['select_os']);  
163   }
165   if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){
166     $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
167   }
169   if($this->edit_os){
170     $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
171     $smarty->assign("OSs",                    $this->handle->getOSTypes());
173     $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
174     return($display);
175   }
177   /*  ENDE, os management.
178    */
179   
180   if(isset($_POST['edit_manufacturer'])){
181     $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
182     $this->cur_dialog->parent = &$this;
183   }
185   if(isset($_POST['close_edit_manufacturer'])){
186     $this->cur_dialog = false;
187   }
190     if(isset($_POST['SelectTechPerson'])){
191       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
192     }
194     /* Technical responsible person selected*/
195     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
197       /* Get posted id */
198       $id = base64_decode($_GET['id']);
200       /* Check if user is already created in glpi database */
201       if(!in_array($id,$users)){
203         /* If this user doesn't exists in glpi db, we must create him */
204         $atr = $ldap->fetch($ldap->cat($id));
205         $tmp = array();
206         $use = array( "cn"              =>"name",
207                       "mail"            =>"email",
208                       "telephoneNumber" =>"phone");
210         /* Create array */
211         foreach($use as $gosa => $glpi){
212           if(isset($atr[$gosa])){
213             $tmp[$glpi]= $atr[$gosa][0];
214           }
215         }
216       
217         /* Add this user */
218         $this->handle->addUser($tmp,$id);
219       }
220       
221       /* Re-read users */
222       $users = ($this->handle->getUsers());
224       /* Get user */
225       $tmp = array_flip($users);
226       $id=$tmp[$id];
227     
228       /* Use user id, close dialog */
229       $this->tech_num = $id;
230       $this->cur_dialog   = false;
231       $this->dialog= false;
232     }
234     if($this->cur_dialog){
235       $this->cur_dialog->save_object();
236       $this->dialog=true;
237       return($this->cur_dialog->execute());
238     }
240     /* Assign smarty defaults */ 
241     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
242       $smarty->assign($attr,array());
243       $smarty->assign($attr."ACL"," disabled ");
244     }
246     foreach(array("type","FK_glpi_enterprise","os","tech_num") as $attr){
247       $smarty->assign($attr,"");
248       $smarty->assign($attr."ACL"," disabled ");
249     }
251     /* Perform some checks
252      *  arround the database
253      */ 
254     if(!isset($this->config->data['SERVERS']['GLPI'])){
255       print_red(_("There is no valid configuration for glpi database available."));
256       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
257     }
258     $this->data = $this->config->data['SERVERS']['GLPI'];
260     if(!is_callable("mysql_connect")){
261       print_red(_("The php mysql extension is missing. Can't perform any queries."));
262       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
263     }
265     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
267     if(!$this->handle->is_connected){
268       print_red(_("Can't connect to specified database."));
269       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
270     }
272     /* If we reach this this 
273      * the database connection seams to ok
274      */
276     /* Do we need to flip is_account state? */
277     if (isset($_POST['modify_state'])){
278       $this->is_account= !$this->is_account;
279     }
281     /* Show tab dialog headers */
282     if ($this->is_account){
283       $display= $this->show_header(_("Remove DNS service"),
284           _("This server has inventory features enabled. You can disable them by clicking below."));
285     } else {
286       $display= $this->show_header(_("Add DNS service"),
287           _("This server has inventory features disabled. You can enable them by clicking below."));
288       return ($display);
289     }
292     foreach($this->attributes as $attr){
293       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
294     }
296     
297     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
298     $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
299     $smarty->assign("type",                   $this->type);
301     $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
302     $smarty->assign("OSs",                    $this->handle->getOSTypes());
303     $smarty->assign("os",                     $this->os);
305     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprisesTypes()));
306     $smarty->assign("Manufacturers",          $this->handle->getEnterprisesTypes());
307     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
309     if(isset($users[$this->tech_num])){
310       $tr = $ldap->fetch($ldap->cat($users[$this->tech_num]));
311       $str = "";
312       if(isset($tr['givenName'][0])){
313         $str .= $tr['givenName'][0]." ";
314       }
316       if(isset($tr['sn'][0])){
317         $str .= $tr['sn'][0]." ";
318       }
319   
320       if(isset($tr['uid'][0])){
321         $str .= "[".$tr['uid'][0]."]";
322       }
325       $smarty->assign("tech_num",               $str);
326     }else{
327       $smarty->assign("tech_num",               _("N/A"));
328     }
329     $smarty->assign("comments",               $this->comments);
331     $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
332     return($display);
333   }
335   function remove_from_parent()
336   {
337   }
340   /* Save data to object */
341   function save_object()
342   {
343     plugin::save_object();
344     foreach($this->attributes as $attrs){
345       if(isset($_POST[$attrs])){
346         $this->$attrs = $_POST[$attrs];
347       }
348     }
349   }
352   /* Check supplied data */
353   function check()
354   {
355     $message= array();
357 //    if($this->TechnicalResponsible == ""){
358 //      $message[] = _("Please select a technical responsible person for this entry.");
359 //    }
361     return ($message);
362   }
364   /* Save to LDAP */
365   function save()
366   {
367     $attrs = array();
368     $this->date_mod = date("Y-m-d H:i:s");
369     foreach($this->attributes as $attr){
370       $attrs[$attr] = $this->$attr;
371     }
372     $attrs['name'] = $this->dn;
373     unset($attrs['ID']);
374     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
375     if($this->initialy_was_account&&$this->is_account){
376       $this->handle->updateComputerInformations($attrs,$this->dn);
377     }elseif($this->is_account){
378       $this->handle->addComputerInformations($attrs,$this->dn);
379     }
380   }
384 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
385 ?>