Code

b5cb920631d070859799237f6b500b4f08f58cf8
[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 $acl= "";
41   var $DivListSystem;
43   function systems ($config, $ui)
44   {
45     /* Save configuration for internal use */
46     $this->config= $config;
47     $this->ui= $ui;
49     /* Creat dialog object */
50     $this->DivListSystem = new divListSystem($this->config,$this);
51   }
53   function execute()
54   {
55     /* Call parent execute */
56     plugin::execute();
58     $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
60     /********************
61       Check for functional posts, edit|delete|add|... system devices 
62      ********************/
63     $s_action     = "";                       // Contains the action to proceed
64     $s_entry      = "";                       // The value for s_action
65     $base_back    = "";                       // The Link for Backbutton
66     $smarty       = get_smarty();
68     /* Test Posts */
69     foreach($_POST as $key => $val){
70       // Post for delete
71       if(preg_match("/user_del.*/",$key)){
72         $s_action = "del";
73         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
74         // Post for edit
75       }elseif(preg_match("/user_edit_.*/",$key)){
76         $s_action="edit";
77         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
78         // Post for new
79       }elseif(preg_match("/user_new.*/",$key)){
80         $s_action="new";
81       }elseif(preg_match("/user_tplnew.*/i",$key)){
82         $s_action="new_tpl";
83       }elseif(preg_match("/user_setpwd_.*/i",$key)){
84         $s_action="change_pw";
85         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
86       }elseif(preg_match("/newsystem_.*/i",$key)){
87         $s_action="newsystem";
88         $s_entry  = preg_replace("/newsystem_/i","",$key);
89       }
90     }
92     /* Incoming handling  
93      * If someone made a systemtype and ogroup selection 
94      * Display the new requested entry type ... servtab  in case of server and so on.
95      */
96     if(isset($_POST['SystemTypeChoosen'])){
97       $s_action = "SelectedSystemType";
98       $s_entry  = $_POST['SystemType'];
99       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
100       $this->systab = NULL;
101     }
103     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
104     $s_entry  = preg_replace("/_.$/","",$s_entry);
106     /* Edit was requested by pressing the name(link) of an item */
107     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
108       $s_action ="edit";
109       $s_entry  = $_GET['id'];
110     }
112     /* Check for exeeded sizelimit */
113     if (($message= check_sizelimit()) != ""){
114       return($message);
115     }
117     /* Try to get informations about what kind of system to create */
118     if ($s_action=="new") {
119       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
120     }
122     /********************
123       Create new system ...   
124      ********************/
125     /* Create new default terminal 
126      * Or create specified object of selected system type, from given incoming object  
127      */
128     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
130       /* If the current entry is an incoming object 
131        * $sw = System type as posted in new incoming handling dialog 
132        */ 
133       if($s_action == "SelectedSystemType") {
134         $sw         = $s_entry;
135       }else{
136         if(isset($_POST['system'])){
137           $sw = $_POST['system'];
138         }else{
139           $sw = $s_entry;
140         }
141         $this->dn= "new";
142       }
143       $this->acl= array(":all");
144       $tabs = array(
145           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs"),
146           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs"),
147           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs"),
148           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs"),
149           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs"),
150           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
152       if(isset($tabs[$sw])){
153         $class    = $tabs[$sw]["CLASS"];
154         $tabname  = $tabs[$sw]["TABNAME"];
155         $tabclass = $tabs[$sw]["TABCLASS"];
156         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
157         $this->systab->set_acl ($this->acl);
158         $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
159         $this->systab->base = $this->DivListSystem->selectedBase;
160       }
161     }
163     /********************
164       Edit system ...   
165      ********************/
167     /* User wants to edit data? */
168     if (($s_action == "edit") && (!isset($this->systab->config))){
170       $this->dn= $this->terminals[$s_entry]['dn'];
172       /* Check locking, save current plugin in 'back_plugin', so
173          the dialog knows where to return. */
174       if (($user= get_lock($this->dn)) != ""){
175         return(gen_locked_message ($user, $this->dn));
176       }
178       /* Set up the users ACL's for this 'dn' */
179       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
181       /* Find out more about the object type */
182       $ldap= $this->config->get_ldap_link();
183       $ldap->cat($this->dn, array('objectClass'));
184       $attrs= $ldap->fetch();
185       $type= $this->get_system_type($attrs['objectClass']);
187       /* Lock the current entry, so everyone will get the
188          above dialog */
189       $tabs = array(
190           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
191           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
192           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
193           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
194           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
195           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
196           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
199       if($type == "NewDevice"){
200         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
201       }elseif(isset($tabs[$type])){
203         $class    = $tabs[$type]["CLASS"];
204         $tabclass = $tabs[$type]["TABCLASS"];
206         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
207         $this->systab->set_acl($acl);
208         $_SESSION['objectinfo']= $this->dn;
209         add_lock ($this->dn, $this->ui->dn);
210       }else{ 
211         print_red (_("You can't edit this object type yet!"));
212         del_lock($this->dn);
213       }
214     }
217     /********************
218       Change password ...   
219      ********************/
221     /* Set terminals root password */
222     if ($s_action=="change_pw"){
223       $this->dn= $this->terminals[$s_entry]['dn'];
224       $_SESSION['objectinfo']= $this->dn;
225       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
226     }
229     /********************
230       Password cahnge finish, but check if entered data is ok 
231      ********************/
233     /* Correctly specified? */
234     if (isset($_POST['password_finish'])){
235       if ($_POST['new_password'] != $_POST['repeated_password']){
236         print_red (_("Passwords entered as new and repeated do not match!"));
237         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
238       }
239     }
241     /********************
242       Password change finish
243      ********************/
245     /* Change terminal password */
246     if (isset($_POST['password_finish']) && 
247         $_POST['new_password'] == $_POST['repeated_password']){
249       /* Check if user is allowed to set password */
250       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
251       $acl= get_module_permission($acl, "terminal", $this->dn);
252       if (chkacl($acl, "password") != ""){
253         print_red (_("You are not allowed to set this systems password!"));
254       } else {
255         $ldap= $this->config->get_ldap_link();
256         $ldap->cd($this->dn);
258         $attrs= array();
259         if ($_POST['new_password'] == ""){
260           $attrs['gotoRootPasswd']= array();
261         } else {
262           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
263               substr(session_id(),0,2));
264         }
265         $ldap->modify($attrs);
266         gosa_log ("Password for '".$this->dn."' has been changed");
267       }
268       unset($_SESSION['objectinfo']);
269     }
272     /********************
273       Delete system cancel
274      ********************/
276     /* Delete terminal canceled? */
277     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
278       del_lock ($this->dn);
279       unset($_SESSION['objectinfo']);
280     }
283     /********************
284       Delete system, confirm dialog
285      ********************/
287     /* Remove terminal was requested */
288     if ($s_action=="del"){
290       /* Get 'dn' from posted termlinst */
291       $this->dn= $this->terminals[$s_entry]['dn'];
293       /* Load permissions for selected 'dn' and check if
294          we're allowed to remove this 'dn' */
295       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
296       $this->acl= get_module_permission($acl, "terminal", $this->dn);
297       if (chkacl($this->acl, "delete") == ""){
299         /* Check locking, save current plugin in 'back_plugin', so
300            the dialog knows where to return. */
301         if (($user= get_lock($this->dn)) != ""){
302           return(gen_locked_message ($user, $this->dn));
303         }
305         /* Lock the current entry, so nobody will edit it during deletion */
306         add_lock ($this->dn, $this->ui->dn);
307         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), LDAP::fix($this->dn)));
308         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
309       } else {
311         /* Obviously the user isn't allowed to delete. Show message and
312            clean session. */
313         print_red (_("You are not allowed to delete this component!"));
314       }
315     }
318     /********************
319       Delete system, confirmed
320      ********************/
321     /* Confirmation for deletion has been passed. Terminal should be deleted. */
322     if (isset($_POST['delete_terminal_confirm'])){
324       /* Some nice guy may send this as POST, so we've to check
325          for the permissions again. */
326       if (chkacl($this->acl, "delete") == ""){
328         /* Find out more about the object type */
329         $ldap= $this->config->get_ldap_link();
330         $ldap->cat($this->dn, array('objectClass'));
331         $attrs= $ldap->fetch();
332         $type= $this->get_system_type($attrs['objectClass']);
334         $tabs = array(
335             "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
336             "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
337             "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
338             "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
339             "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
340             "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
341             "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
343         /* get object type */
344         $tabtype  = "termtabs";
345         $tabobj   = "TERMTABS";
346         if(isset($tabs[$type])){
347           $tabtype = $tabs[$type]['TABCLASS'];
348           $tabobj  = $tabs[$type]['CLASS'];
349         }
351         /* Delete request is permitted, perform LDAP action */
352         if($tabtype=="phonetabs"){
353           $this->systab= new $tabtype($this->config,
354               $this->config->data['TABS'][$tabobj], $this->dn);
355           $this->systab->set_acl(array($this->acl));
356           $this->systab->by_object['phonegeneric']->remove_from_parent ();
357         }else{  
358           $this->systab= new $tabtype($this->config,
359               $this->config->data['TABS'][$tabobj], $this->dn);
360           $this->systab->set_acl(array($this->acl));
361           $this->systab->delete();
362 #$this->systab->by_object['termgeneric']->remove_from_parent ();
363         }
364         unset ($this->systab);
365         gosa_log ("System object'".$this->dn."' has been removed");
366         $this->systab= NULL;
368         /* Terminal list has changed, reload it. */
369       } else {
371         /* Normally this shouldn't be reached, send some extra
372            logs to notify the administrator */
373         print_red (_("You are not allowed to delete this component!"));
374         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
375             "deletion.");
376       }
378       /* Remove lock file after successfull deletion */
379       del_lock ($this->dn);
380     }
383     /********************
384       Edit system type finished, check if everything went ok 
385      ********************/
386     /* Finish user edit is triggered by the tabulator dialog, so
387        the user wants to save edited data. Check and save at this
388        point. */
389     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
391       /* Check tabs, will feed message array */
392       $message= $this->systab->check();
394       /* Save, or display error message? */
395       if (count($message) == 0){
397         /* Save terminal data to ldap */
398         gosa_log ("System object'".$this->dn."' has been saved");
399         $this->systab->save();
401         /* Incoming behavior; you can select a system type and an ogroup membership. 
402          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
403          * Check if we must add the new object to an object group.
404          * 
405          * If this is done, delete the old incoming entry... it is still there, because this is a new 
406          * entry and not an edited one, so we will delete it.
407          */
409         if(isset($_SESSION['SelectedSystemType'])){
410           $SelectedSystemType= $_SESSION['SelectedSystemType'];
411           unset($_SESSION['SelectedSystemType']);
412           if($SelectedSystemType['ogroup'] != "none"){
413             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
414             if($og){
415               $og->AddDelMembership($this->systab->dn);
416               $og->save();
417             }
418           }
419           if(!isset($ldap)){
420             $ldap = $this->config->get_ldap_link();
421           }
422           $ldap->cd ($this->dn);
423           $ldap->cat($this->dn, array('dn'));  
424           if(count($ldap->fetch())){
425             $ldap->cd($this->dn);
426             $ldap->rmDir($this->dn);
427           }
428           $ldap->cd($this->config->current['BASE']);
429         }
431         if (!isset($_POST['edit_apply'])){
432           /* Terminal has been saved successfully, remove lock from
433              LDAP. */
434           if ($this->dn != "new"){
435             del_lock ($this->dn);
436           }
438           unset ($this->systab);
439           $this->systab= NULL;
440           unset($_SESSION['objectinfo']);
441         }
442       } else {
443         /* Ok. There seem to be errors regarding to the tab data,
444            show message and continue as usual. */
445         show_errors($message);
446       }
447     }
449     /********************
450       Edit system was canceled 
451      ********************/
452     /* Cancel dialogs */
453     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
454       if (isset($this->systab)){
455         del_lock ($this->systab->dn);
456         unset ($this->systab);
457       }
458       $this->systab= NULL;
459       unset($_SESSION['objectinfo']);
461       /* Remove ogroup selection, which was set while editing a new incoming entry */
462       if(isset($_SESSION['SelectedSystemType'])){
463         unset($_SESSION['SelectedSystemType']);
464       }
465     }
467     /********************
468       Display edit dialog, or some other
469      ********************/
471     /* Show tab dialog if object is present */
472     if (isset($this->systab->config)){
473       $display= $this->systab->execute();
475       /* Don't show buttons if tab dialog requests this */
476       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
477         $display.= "<p style=\"text-align:right\">\n";
478         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
479         $display.= "&nbsp;\n";
480         if ($this->dn != "new"){
481           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
482           $display.= "&nbsp;\n";
483         }
484         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
485         $display.= "</p>";
486       }
487       return ($display);
488     }
490     /* Display dialog with system list */
491     $this->DivListSystem->parent = $this;
492     $this->DivListSystem->execute();
494     /* Add departments if subsearch is disabled */
495     if(!$this->DivListSystem->SubSearch){
496       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
497     }
498     $this->reload();
499     $this->DivListSystem->setEntries($this->terminals);
500     return($this->DivListSystem->Draw());
501   }
505   function remove_from_parent()
506   {
507     /* Optionally execute a command after we're done */
508     $this->postremove();
509   }
512   /* Save data to object */
513   function save_object()
514   {
515     $this->DivListSystem->save_object();
516     /* check for posts */
517     $once = true;
518     foreach($_POST as $name => $value){
520       /* Create a new snapshot, display a dialog */
521       if(preg_match("/^CreateSnapShot_/",$name) && $once){
522         $once = false;
523         $entry = preg_replace("/^CreateSnapShot_/","",$name);
524         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
525         $this->systab = new SnapShotDialog($this->config,$entry,$this); 
526       }
528       /* Restore a snapshot, display a dialog with all snapshots of the current object */
529       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
530         $once = false;
531         $entry = preg_replace("/^RestoreSnapShot_/","",$name);
532         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
533         $this->systab = new SnapShotDialog($this->config,$entry,$this); 
534         $this->systab->Restore = true;
535       }
537       /* Restore one of the already deleted objects */
538       if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
539         $once = false;
540         $entry = "ou=systems,".$this->selectedBase;  
541         $this->systab = new SnapShotDialog($this->config,$entry,$this); 
542         $this->systab->Restore      = true;
543         $this->systab->DeletedOnes  = true;
544       }
545     }
547     /* Create a new snapshot requested, check 
548        the given attributes and create the snapshot*/
549     if(isset($_POST['CreateSnapshot'])){
550       $this->systab->save_object();
551       $msgs = $this->systab->check();
552       if(count($msgs)){
553         foreach($msgs as $msg){
554           print_red($msg);
555         }
556       }else{
557         $this->dn =  $this->parent->systab->dn;
558         $this->create_snapshot("snapshot",$this->parent->systab->CurrentDescription);
559         $this->systab = NULL;
560       }
561     }
563     /* Restore is requested, restore the object with the posted dn .*/ 
564     if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
565       $entry =trim($_POST['SnapShot']);
566       if(!empty($entry)){
567         $entry = base64_decode($entry);
568         $this->parent->restore_snapshot($entry);
569         $this->parent->systab = NULL;
570       }
571     }
572   }
575   /* Check values */
576   function check()
577   {
578   }
581   /* Save to LDAP */
582   function save()
583   {
584   }
586   function adapt_from_template($dn)
587   {
588   }
590   function password_change_needed()
591   {
592   }
594   function reload()
595   {
596     /* Load terminal shortcuts */
597     $responsible= array();
598     foreach ($this->config->departments as $key => $value){
599       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
600             "terminal", $value) == "#all#"){
601         $responsible[$key]= $value;
602       }
603     }
605     /* some var init */
606     $res              = array();
607     $this->terminals  = array();
608     $userregex        = "";
610     /* Set base for all searches */
611     $base=  $this->DivListSystem->selectedBase;
613     /* Prepare samba class name */
614     $samba  ="";
615     if ($this->DivListSystem->ShowWinWorkstations){
616       if ($this->config->current['SAMBAVERSION'] == "3"){
617         $samba= "sambaSamAccount";
618       } else {
619         $samba= "sambaAccount";
620       }
621     }
623     /* This array represents the combination between checkboxes and search filters */
624     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
625         "ShowTerminals"      => array("CLASS" => "goHard"          ,"TREE" => "ou=terminals,ou=systems,"), 
626         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
627         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
628         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
629         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
630         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
632     /* Include the 'Display Systems of user' attribute */ 
633     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
634       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
635     }
637     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
638     foreach($objs as $checkBox => $oc){
639       if($this->DivListSystem->$checkBox){
640         if($this->DivListSystem->SubSearch){
641           if($oc['CLASS'] != ""){
642             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
643             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
644                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
645           }
646         }else{
647           /* User filter? */
648           if($oc['CLASS'] != ""){
649             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
650             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
651                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
652           }
653         }
654       } 
655     }
657     /* Search for incoming objects */ 
658     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
659     $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
660           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
662     /* Get all gotoTerminal's */
663     foreach ($res as $value){
665       $tmp= $value['dn'];
666       $add= "";
668       /* Extract base */
669       foreach($objs as $obj){
670         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
671           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
672         }
673       }
675       /* check if current object is a new one */
676       if (preg_match ("/,ou=incoming,/i", $tmp)){
677         if (in_array_ics('gotoTerminal', $value['objectClass'])){
678           $add= "- "._("New terminal");
679         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
680           $add= "- "._("New workstation");
681         }elseif (in_array_ics('GOhard', $value['objectClass'])){
682           $add= "- "._("New Device");
683         }
684       } 
686       /* Detect type of object and create an entry for $this->terminals */
687       $terminal = array();
688       if ((in_array ($tmp, $responsible)) || ($add != "")){
689         if (in_array_ics('gotoTerminal', $value["objectClass"])){
690           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
691             $terminal             = $value;
692             $terminal['type']     = "T";
693             $terminal['is_new']   = $add;
694           } else {
695             $terminal             = $value;
696             $terminal['type']     = "D";
697             $terminal['message']  = _("Terminal template for");
698             $terminal['location'] = array_search($tmp, $this->config->departments); 
699           }
700         } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
701           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
702             $terminal             = $value;
703             $terminal['type']     = "L";
704             $terminal['is_new']   = $add;
705           } else {
706             $terminal             = $value;
707             $terminal['type']     = "D";
708             $terminal['location'] = array_search($tmp, $this->config->departments);
709             $terminal['message']  = _("Workstation template for");
710           }
711           if (isset($value["FAIstate"][0])){
712             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
713           }
714         } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
715           $terminal             = $value;
716           $terminal['type']     = "P";
717         } elseif (in_array_ics('goServer', $value["objectClass"])){
718           $terminal             = $value;
719           $terminal['type']     = "S";
720           if (isset($value["FAIstate"][0])){
721             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
722           }
723         } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
724           $terminal             = $value;
725           $terminal['type']     = "F";
726         }elseif (in_array_ics("GOhard",$value['objectClass'])){
727           $terminal = $value;
728           $terminal['type']   = "Q";
729           $terminal['is_new'] = $add;
730         } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
731           $terminal             = $value;
732           $terminal['type']     = "C";
733         } else{
734           $name= preg_replace('/\$$/', '', $value['cn'][0]);
735           if (isset($value['sambaDomainName'])){
736             $domain= " [".$value['sambaDomainName'][0]."]";
737           } else {
738             $domain= "";
739           }
740           $terminal=$value;
741           $terminal['type']     ="W";
742           $terminal['domain']   = $name.$domain;
743         }
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 ?>