Code

removed debug output
[gosa.git] / plugins / admin / systems / class_systemManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31   /* Definitions */
32   var $plHeadline     = "Systems";
33   var $plDescription  = "This does something";
34   var $departments    = array();
36   /* Dialog attributes */
37   var $systab   = NULL;
38   var $terminals= array();
39   var $ui       = NULL;
40   var $DivListSystem;
42   function systems ($config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= $config;
46     $this->ui= $ui;
48     /* Creat dialog object */
49     $this->DivListSystem = new divListSystem($this->config,$this);
50   }
52   function execute()
53   {
54     /* Call parent execute */
55     plugin::execute();
57     $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
59     /********************
60       Check for functional posts, edit|delete|add|... system devices 
61      ********************/
62     $s_action     = "";                       // Contains the action to proceed
63     $s_entry      = "";                       // The value for s_action
64     $base_back    = "";                       // The Link for Backbutton
65     $smarty       = get_smarty();
67     /* Test Posts */
68     foreach($_POST as $key => $val){
69       // Post for delete
70       if(preg_match("/user_del.*/",$key)){
71         $s_action = "del";
72         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
73         // Post for edit
74       }elseif(preg_match("/user_edit_.*/",$key)){
75         $s_action="edit";
76         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
77         // Post for new
78       }elseif(preg_match("/user_new.*/",$key)){
79         $s_action="new";
80       }elseif(preg_match("/user_tplnew.*/i",$key)){
81         $s_action="new_tpl";
82       }elseif(preg_match("/user_setpwd_.*/i",$key)){
83         $s_action="change_pw";
84         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
85       }elseif(preg_match("/newsystem_.*/i",$key)){
86         $s_action="newsystem";
87         $s_entry  = preg_replace("/newsystem_/i","",$key);
88       }
89     }
91     /* Incoming handling  
92      * If someone made a systemtype and ogroup selection 
93      * Display the new requested entry type ... servtab  in case of server and so on.
94      */
95     if(isset($_POST['SystemTypeChoosen'])){
96       $s_action = "SelectedSystemType";
97       $s_entry  = $_POST['SystemType'];
98       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
99       $this->systab = NULL;
100     }
102     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
103     $s_entry  = preg_replace("/_.$/","",$s_entry);
105     /* Edit was requested by pressing the name(link) of an item */
106     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
107       $s_action ="edit";
108       $s_entry  = $_GET['id'];
109     }
111     /* Check for exeeded sizelimit */
112     if (($message= check_sizelimit()) != ""){
113       return($message);
114     }
116     /* Try to get informations about what kind of system to create */
117     if ($s_action=="new") {
118       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
119     }
121     /********************
122       Create new system ...   
123      ********************/
124     /* Create new default terminal 
125      * Or create specified object of selected system type, from given incoming object  
126      */
127     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
129       /* If the current entry is an incoming object 
130        * $sw = System type as posted in new incoming handling dialog 
131        */ 
132       if($s_action == "SelectedSystemType") {
133         $sw         = $s_entry;
134       }else{
135         if(isset($_POST['system'])){
136           $sw = $_POST['system'];
137         }else{
138           $sw = $s_entry;
139         }
140         $this->dn= "new";
141       }
142       $tabs = array(
143           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
144           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
145           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
146           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
147           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
148           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
150       if(isset($tabs[$sw])){
151         $class    = $tabs[$sw]["CLASS"];
152         $tabname  = $tabs[$sw]["TABNAME"];
153         $tabclass = $tabs[$sw]["TABCLASS"];
154         $acl_cat  = $tabs[$sw]["ACL"];
155         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
156         $this->systab->set_acl_base($this->base);
157         $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
158         $this->systab->base = $this->DivListSystem->selectedBase;
159       }
160     }
162     /********************
163       Edit system ...   
164      ********************/
166     /* User wants to edit data? */
167     if (($s_action == "edit") && (!isset($this->systab->config))){
169       $this->dn= $this->terminals[$s_entry]['dn'];
171       /* Check locking, save current plugin in 'back_plugin', so
172          the dialog knows where to return. */
173       if (($user= get_lock($this->dn)) != ""){
174         return(gen_locked_message ($user, $this->dn));
175       }
177       /* Find out more about the object type */
178       $ldap= $this->config->get_ldap_link();
179       $ldap->cat($this->dn, array('objectClass'));
180       $attrs= $ldap->fetch();
181       $type= $this->get_system_type($attrs['objectClass']);
183       /* Lock the current entry, so everyone will get the
184          above dialog */
185       $tabs = array(
186           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
187           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
188           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
189           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
190           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
191           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
192           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
195       if($type == "NewDevice"){
196         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
197       }elseif(isset($tabs[$type])){
199         $class    = $tabs[$type]["CLASS"];
200         $acl_cat  = $tabs[$type]["ACL"];
201         $tabclass = $tabs[$type]["TABCLASS"];
203         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
204         $this->systab->set_acl_base($this->dn);
205         $_SESSION['objectinfo']= $this->dn;
206         add_lock ($this->dn, $this->ui->dn);
207       }else{ 
208         print_red (_("You can't edit this object type yet!"));
209         del_lock($this->dn);
210       }
211     }
214     /********************
215       Change password ...   
216      ********************/
218     /* Set terminals root password */
219     if ($s_action=="change_pw"){
220       $this->dn= $this->terminals[$s_entry]['dn'];
221       $_SESSION['objectinfo']= $this->dn;
222       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
223     }
226     /********************
227       Password cahnge finish, but check if entered data is ok 
228      ********************/
230     /* Correctly specified? */
231     if (isset($_POST['password_finish'])){
232       if ($_POST['new_password'] != $_POST['repeated_password']){
233         print_red (_("Passwords entered as new and repeated do not match!"));
234         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
235       }
236     }
238     /********************
239       Password change finish
240      ********************/
242     /* Change terminal password */
243     if (isset($_POST['password_finish']) && 
244         $_POST['new_password'] == $_POST['repeated_password']){
246       /* Check if user is allowed to set password */
247       $ui  = get_userinfo();
248       $acl = $ui -> get_category_permissions($this->dn,"terminal");
249       if(preg_match("/w/",$acl)){ 
250         print_red (_("You are not allowed to set this systems password!"));
251       } else {
252         $ldap= $this->config->get_ldap_link();
253         $ldap->cd($this->dn);
255         $attrs= array();
256         if ($_POST['new_password'] == ""){
257           $attrs['gotoRootPasswd']= array();
258         } else {
259           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
260               substr(session_id(),0,2));
261         }
262         $ldap->modify($attrs);
263         gosa_log ("Password for '".$this->dn."' has been changed");
264       }
265       unset($_SESSION['objectinfo']);
266     }
269     /********************
270       Delete system cancel
271      ********************/
273     /* Delete terminal canceled? */
274     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
275       del_lock ($this->dn);
276       unset($_SESSION['objectinfo']);
277     }
280     /********************
281       Delete system, confirm dialog
282      ********************/
284     /* Remove terminal was requested */
285     if ($s_action=="del"){
287       /* Get 'dn' from posted termlinst */
288       $this->dn= $this->terminals[$s_entry]['dn'];
290       /* Load permissions for selected 'dn' and check if
291          we're allowed to remove this 'dn' */
292       $ui  = get_userinfo();
293       $acl = $ui -> get_category_permissions($this->dn,"terminal");
294       if(preg_match("/w/",$acl)){ 
296         /* Check locking, save current plugin in 'back_plugin', so
297            the dialog knows where to return. */
298         if (($user= get_lock($this->dn)) != ""){
299           return(gen_locked_message ($user, $this->dn));
300         }
302         /* Lock the current entry, so nobody will edit it during deletion */
303         add_lock ($this->dn, $this->ui->dn);
304         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
305         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
306       } else {
308         /* Obviously the user isn't allowed to delete. Show message and
309            clean session. */
310         print_red (_("You are not allowed to delete this component!"));
311       }
312     }
315     /********************
316       Delete system, confirmed
317      ********************/
318     /* Confirmation for deletion has been passed. Terminal should be deleted. */
319     if (isset($_POST['delete_terminal_confirm'])){
321       /* Find out more about the object type */
322       $ldap= $this->config->get_ldap_link();
323       $ldap->cat($this->dn, array('objectClass'));
324       $attrs= $ldap->fetch();
325       $type= $this->get_system_type($attrs['objectClass']);
327       $ui = get_userinfo();
329       $tabs = array(
330           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
331           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
332           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
333           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
334           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
335           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
336           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
338         
339         /* get object type */
340         $tabtype  = "termtabs";
341         $tabobj   = "TERMTABS";
342         $tabacl   = "";
343         if(isset($tabs[$type])){
344           $tabtype = $tabs[$type]['TABCLASS'];
345           $tabobj  = $tabs[$type]['CLASS'];
346           $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
347         }
349       /* Check if we are allowed to remove this object */
350       if(preg_match("/d/",$tabacl)){
352         /* Delete request is permitted, perform LDAP action */
353         if($tabtype=="phonetabs"){
354           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$tabs[$type]['ACL']);
355           $this->systab->set_acl_base($this->dn);
356           $this->systab->by_object['phonegeneric']->remove_from_parent ();
357         }else{  
358           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$tabs[$type]['ACL']);
359           $this->systab->set_acl_base($this->dn);
360           $this->systab->delete();
361         }
362         unset ($this->systab);
363         gosa_log ("System object'".$this->dn."' has been removed");
364         $this->systab= NULL;
366         /* Terminal list has changed, reload it. */
367       } else {
369         /* Normally this shouldn't be reached, send some extra
370            logs to notify the administrator */
371         print_red (_("You are not allowed to delete this component!"));
372         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
373             "deletion.");
374       }
376       /* Remove lock file after successfull deletion */
377       del_lock ($this->dn);
378     }
381     /********************
382       Edit system type finished, check if everything went ok 
383      ********************/
384     /* Finish user edit is triggered by the tabulator dialog, so
385        the user wants to save edited data. Check and save at this
386        point. */
387     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
389       /* Check tabs, will feed message array */
390       $message= $this->systab->check();
392       /* Save, or display error message? */
393       if (count($message) == 0){
395         /* Save terminal data to ldap */
396         if(isset($_SESSION['SelectedSystemType']['ogroup'])){
397           foreach (array("workservice", "termservice") as $cls){
398             if (isset($this->systab->by_object[$cls])){
399               $this->systab->by_object[$cls]->gotoXMouseport= "";
400               $this->systab->by_object[$cls]->gotoXMouseType= "";
401               $this->systab->by_object[$cls]->gotoXResolution= "";
402               $this->systab->by_object[$cls]->gotoXColordepth= "";
403             }
404           }
405         }
406         $this->systab->save();
407         gosa_log ("System object'".$this->dn."' has been saved");
409         /* Incoming behavior; you can select a system type and an ogroup membership. 
410          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
411          * Check if we must add the new object to an object group.
412          * 
413          * If this is done, delete the old incoming entry... it is still there, because this is a new 
414          * entry and not an edited one, so we will delete it.
415          */
417         if(isset($_SESSION['SelectedSystemType'])){
418           $SelectedSystemType= $_SESSION['SelectedSystemType'];
419           unset($_SESSION['SelectedSystemType']);
420           if($SelectedSystemType['ogroup'] != "none"){
421             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
422             if($og){
423               $og->AddDelMembership($this->systab->dn);
424               $og->save();
425             }
426           }
427           if(!isset($ldap)){
428             $ldap = $this->config->get_ldap_link();
429           }
430           $ldap->cd ($this->dn);
431           $ldap->cat($this->dn, array('dn'));  
432           if(count($ldap->fetch())){
433             $ldap->cd($this->dn);
434             $ldap->rmDir($this->dn);
435           }
436           $ldap->cd($this->config->current['BASE']);
437         }
439         if (!isset($_POST['edit_apply'])){
440           /* Terminal has been saved successfully, remove lock from
441              LDAP. */
442           if ($this->dn != "new"){
443             del_lock ($this->dn);
444           }
446           unset ($this->systab);
447           $this->systab= NULL;
448           unset($_SESSION['objectinfo']);
449         }
450       } else {
451         /* Ok. There seem to be errors regarding to the tab data,
452            show message and continue as usual. */
453         show_errors($message);
454       }
455     }
457     /********************
458       Edit system was canceled 
459      ********************/
460     /* Cancel dialogs */
461     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
462       if (isset($this->systab)){
463         del_lock ($this->systab->dn);
464         unset ($this->systab);
465       }
466       $this->systab= NULL;
467       unset($_SESSION['objectinfo']);
469       /* Remove ogroup selection, which was set while editing a new incoming entry */
470       if(isset($_SESSION['SelectedSystemType'])){
471         unset($_SESSION['SelectedSystemType']);
472       }
473     }
475     /********************
476       Display edit dialog, or some other
477      ********************/
479     /* Show tab dialog if object is present */
480     if (isset($this->systab->config)){
481       $display= $this->systab->execute();
483       /* Don't show buttons if tab dialog requests this */
484       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
485         $display.= "<p style=\"text-align:right\">\n";
486         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
487         $display.= "&nbsp;\n";
488         if ($this->dn != "new"){
489           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
490           $display.= "&nbsp;\n";
491         }
492         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
493         $display.= "</p>";
494       }
495       return ($display);
496     }
498     /* Check if there is a snapshot dialog open */
499     $base = $this->DivListSystem->selectedBase;
500     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
501       return($str);
502     }
504     /* Display dialog with system list */
505     $this->DivListSystem->parent = $this;
506     $this->DivListSystem->execute();
508     /* Add departments if subsearch is disabled */
509     if(!$this->DivListSystem->SubSearch){
510       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
511     }
512     $this->reload();
513     $this->DivListSystem->setEntries($this->terminals);
514     return($this->DivListSystem->Draw());
515   }
518   /* Return departments, that will be included within snapshot detection */
519   function get_used_snapshot_bases()
520   {
521     $tmp = array();
522     foreach(array("phones","servers","printers","terminals","netdevices","workstations") as $ent){
523       $tmp[] = "ou=".$ent.",ou=systems,".$this->DivListSystem->selectedBase;
524     }
525     return($tmp); 
526   }
529   function remove_from_parent()
530   {
531     /* Optionally execute a command after we're done */
532     $this->postremove();
533   }
536   /* Save data to object */
537   function save_object()
538   {
539     $this->DivListSystem->save_object();
540   }
543   /* Check values */
544   function check()
545   {
546   }
549   /* Save to LDAP */
550   function save()
551   {
552   }
554   function adapt_from_template($dn)
555   {
556   }
558   function password_change_needed()
559   {
560   }
562   function reload()
563   {
564     /* some var init */
565     $ui = get_userinfo();
566     $res              = array();
567     $this->terminals  = array();
568     $userregex        = "";
570     /* Set base for all searches */
571     $base=  $this->DivListSystem->selectedBase;
573     /* Prepare samba class name */
574     $samba  ="";
575     if ($this->DivListSystem->ShowWinWorkstations){
576       if ($this->config->current['SAMBAVERSION'] == "3"){
577         $samba= "sambaSamAccount";
578       } else {
579         $samba= "sambaAccount";
580       }
581     }
583     /* This array represents the combination between checkboxes and search filters */
584     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
585         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
586         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
587         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
588         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
589         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
590         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
592     /* Include the 'Display Systems of user' attribute */ 
593     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
594       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
595     }
597     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
598     foreach($objs as $checkBox => $oc){
599       if($this->DivListSystem->$checkBox){
600         if($this->DivListSystem->SubSearch){
601           if($oc['CLASS'] != ""){
602             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
603             $res = array_merge($res,get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
604                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
605           }
606         }else{
607           /* User filter? */
608           if($oc['CLASS'] != ""){
609             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
610             $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
611                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
612           }
613         }
614       } 
615     }
617     /* Search for incoming objects */ 
618     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
619     $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
620           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
622     /* Get all gotoTerminal's */
623     foreach ($res as $value){
625       $tmp= $value['dn'];
626       $add= "";
628       /* Extract base */
629       foreach($objs as $obj){
630         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
631           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
632         }
633       }
635       /* check if current object is a new one */
636       if (preg_match ("/,ou=incoming,/i", $tmp)){
637         if (in_array_ics('gotoTerminal', $value['objectClass'])){
638           $add= "- "._("New terminal");
639         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
640           $add= "- "._("New workstation");
641         }elseif (in_array_ics('GOhard', $value['objectClass'])){
642           $add= "- "._("New Device");
643         }
644       } 
646       /* Detect type of object and create an entry for $this->terminals */
647       $terminal = array();
649       if (in_array_ics('gotoTerminal', $value["objectClass"])){
651         /* check acl */
652         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
653         if($add != "" || preg_match("/r/",$acl)) {
654           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
655             $terminal             = $value;
656             $terminal['type']     = "T";
657             $terminal['is_new']   = $add;
658           } else {
659             $terminal             = $value;
660             $terminal['type']     = "D";
661             $terminal['message']  = _("Terminal template for");
662             $terminal['location'] = array_search($tmp, $this->config->departments); 
663           }
664         }
665       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
667         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
668         if($add != "" || preg_match("/r/",$acl)) {
669           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
670             $terminal             = $value;
671             $terminal['type']     = "L";
672             $terminal['is_new']   = $add;
673           } else {
674             $terminal             = $value;
675             $terminal['type']     = "D";
676             $terminal['location'] = array_search($tmp, $this->config->departments);
677             $terminal['message']  = _("Workstation template for");
678           }
679           if (isset($value["FAIstate"][0])){
680             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
681           }
682         }
683       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
684        
685    
686         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
687         if($add != "" || preg_match("/r/",$acl)) {
689           $terminal             = $value;
690           $terminal['type']     = "P";
691         }
692       } elseif (in_array_ics('goServer', $value["objectClass"])){
694         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
695         if($add != "" || preg_match("/r/",$acl)) {
697           $terminal             = $value;
698           $terminal['type']     = "S";
699           if (isset($value["FAIstate"][0])){
700             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
701           }
702         }
703       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
705         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
706         if($add != "" || preg_match("/r/",$acl)) {
708           $terminal             = $value;
709           $terminal['type']     = "F";
710         }
711       }elseif (in_array_ics("GOhard",$value['objectClass'])){
713         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
714                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
715                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
716         if($add != "" || preg_match("/r/",$acl)) {
718           $terminal = $value;
719           $terminal['type']   = "Q";
720           $terminal['is_new'] = $add;
721         }
722       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
724         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
725         if($add != "" || preg_match("/r/",$acl)) {
727           $terminal             = $value;
728           $terminal['type']     = "C";
729         }
730       } else{
732         $name= preg_replace('/\$$/', '', $value['cn'][0]);
733         if (isset($value['sambaDomainName'])){
734           $domain= " [".$value['sambaDomainName'][0]."]";
735         } else {
736           $domain= "";
737         }
738         $terminal=$value;
739         $terminal['type']     ="W";
740         $terminal['domain']   = $name.$domain;
741       }
743       if(count($terminal)){
744         $this->terminals[]=$terminal;
745       }
746     }
748     $tmp=array();
749     foreach($this->terminals as $tkey => $val ){
750       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
751     }
752     ksort($tmp);
753     $this->terminals=array();
754     foreach($tmp as $val){
755       $this->terminals[]=$val;
756     }
757     reset ($this->terminals);
758   }
760   function remove_lock()
761   {
762     if (isset($this->systab->dn)){
763       del_lock ($this->systab->dn);
764     }
765   }
768   function get_system_type($classes)
769   {
770     $type= "";
771     if (in_array_ics('ieee802Device', $classes)){
772       $type= "component";
773     }elseif (in_array_ics('gotoTerminal', $classes)){
774       $type= "terminal";
775     }elseif (in_array_ics('gotoWorkstation', $classes)){
776       $type= "workstation";
777     }elseif (in_array_ics('gotoPrinter', $classes)){
778       $type= "printer";
779     }elseif (in_array_ics('goFonHardware', $classes)){
780       $type= "phone";
781     }elseif (in_array_ics('goServer', $classes)){
782       $type= "server";
783     }elseif (in_array_ics('GOhard', $classes)){
784       $type= "NewDevice";
785     }elseif (in_array_ics('sambaAccount', $classes) ||
786         in_array_ics('sambaSamAccount', $classes)){
787       $type= "winstation";
788     }
789     return ($type);
790   }
793   function convert_list($input)
794   {
795     $temp= "";
796     $conv= array(       
797         "NQ" => array("select_newsystem.png",_("New System from incoming")),
798         "D" => array("select_default.png",_("Template")),
799         "T" => array("select_terminal.png",_("Terminal")),
800         "L" => array("select_workstation.png",_("Workstation")),
801         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
802         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
803         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
804         "F" => array("select_phone.png",_("Phone")),
805         "S" => array("select_server.png",_("Server")),
806         "GS" => array("select_server_green.png",_("Server is installing")),
807         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
808         "RS" => array("select_server_red.png",_("Server installation failed")),
809         "W" => array("select_winstation.png",_("Winstation")),
810         "C" => array("select_component.png",_("Network Device")),
811         "NT"=> array("select_new_terminal.png",_("New Terminal")),
812         "NL"=> array("select_new_workstation.png",_("New Workstation")),
813         "P" => array("select_printer.png",_("Printer")));
815     if((isset($input['is_new']))&&(!empty($input['is_new']))){
816       $input['type']="N".$input['type'];
817     }
818     foreach ($conv  as $key => $value){
819       if($input['type']==$key){
820         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
821         $tmp['class']=$key;
822         return $tmp;
823       }
824     }
825   }
827   
828   function getState($type, $state)
829   {
830     switch (preg_replace('/:.*$/', '', $state)) {
831       case 'installing':
832                 $type= 'G'.$type;
833                 break;
834       case 'error':
835                 $type= 'R'.$type;
836                 break;
837       case 'install':
838                 $type= 'Y'.$type;
839                 break;
840       case 'sysinfo':
841                 $type= 'Y'.$type;
842                 break;
843       case 'softupdate':
844                 $type= 'Y'.$type;
845                 break;
846     }
849     return ($type);
850   }
854 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
855 ?>