Code

Replace stream_get_contents() which is not php4 compatible
[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("/gen_cd_.*/i",$key)){
87         $s_action="gen_cd";
88         $s_entry  = preg_replace("/gen_cd_/i","",$key);
89       }elseif(preg_match("/newsystem_.*/i",$key)){
90         $s_action="newsystem";
91         $s_entry  = preg_replace("/newsystem_/i","",$key);
92       }
93     }
95     /* Incoming handling  
96      * If someone made a systemtype and ogroup selection 
97      * Display the new requested entry type ... servtab  in case of server and so on.
98      */
99     if(isset($_POST['SystemTypeChoosen'])){
100       $s_action = "SelectedSystemType";
101       $s_entry  = $_POST['SystemType'];
102       $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
103       $this->systab = NULL;
104     }
106     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
107     $s_entry  = preg_replace("/_.$/","",$s_entry);
109     /* Edit was requested by pressing the name(link) of an item */
110     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
111       $s_action ="edit";
112       $s_entry  = $_GET['id'];
113     }
115     /* Check for exeeded sizelimit */
116     if (($message= check_sizelimit()) != ""){
117       return($message);
118     }
120     /* Try to get informations about what kind of system to create */
121     if ($s_action=="new") {
122       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
123     }
125     /********************
126       Create new system ...   
127      ********************/
128     /* Create new default terminal 
129      * Or create specified object of selected system type, from given incoming object  
130      */
132     $save_object_directly = false;
133     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
134       $save_object_directly = true;
135     }
136     
137     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
139       /* If the current entry is an incoming object 
140        * $sw = System type as posted in new incoming handling dialog 
141        */ 
142       if($s_action == "SelectedSystemType") {
143         $sw         = $s_entry;
144       }else{
145         if(isset($_POST['system'])){
146           $sw = $_POST['system'];
147         }else{
148           $sw = $s_entry;
149         }
150         $this->dn= "new";
151       }
152       $this->acl= array(":all");
153       $tabs = array(
154           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs"),
155           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs"),
156           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs"),
157           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs"),
158           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phonegeneric",    "TABCLASS" =>"phonetabs"),
159           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs"));
161       if(isset($tabs[$sw])){
162         $class    = $tabs[$sw]["CLASS"];
163         $tabname  = $tabs[$sw]["TABNAME"];
164         $tabclass = $tabs[$sw]["TABCLASS"];
165         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
166         $this->systab->set_acl ($this->acl);
167         $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
168         $this->systab->base = $this->DivListSystem->selectedBase;
169       }
170     }
172     /********************
173       Edit system ...   
174      ********************/
176     /* User wants to edit data? */
177     if (($s_action == "edit") && (!isset($this->systab->config))){
179       $this->dn= $this->terminals[$s_entry]['dn'];
181       /* Check locking, save current plugin in 'back_plugin', so
182          the dialog knows where to return. */
183       if (($user= get_lock($this->dn)) != ""){
184         return(gen_locked_message ($user, $this->dn));
185       }
187       /* Set up the users ACL's for this 'dn' */
188       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
190       /* Find out more about the object type */
191       $ldap= $this->config->get_ldap_link();
192       $ldap->cat($this->dn, array('objectClass'));
193       $attrs= $ldap->fetch();
194       $type= $this->get_system_type($attrs['objectClass']);
196       /* Lock the current entry, so everyone will get the
197          above dialog */
198       $tabs = array(
199           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
200           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
201           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
202           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
203           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
204           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
205           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
208       if($type == "NewDevice"){
209         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
210       }elseif(isset($tabs[$type])){
212         $class    = $tabs[$type]["CLASS"];
213         $tabclass = $tabs[$type]["TABCLASS"];
215         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn);
216         $this->systab->set_acl($acl);
217         $_SESSION['objectinfo']= $this->dn;
218         add_lock ($this->dn, $this->ui->dn);
219       }else{ 
220         print_red (_("You can't edit this object type yet!"));
221         del_lock($this->dn);
222       }
223     }
225     /********************
226       Create FAI CD ...   
227      ********************/
228     if ($s_action=="gen_cd"){
229       $this->dn= $this->terminals[$s_entry]['dn'];
230       $_SESSION['objectinfo']= $this->dn;
231       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
232     }
234     /* Start CD-Creation */
235     if (isset($_POST["cd_create"])){
236       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
237       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
238     }
239   
240     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
242       $return_button   = "<form type='get' action='main.php' target='_parent'>
243                             <input type='submit' value='"._("Back")."'>
244                             <input type='hidden' name='plug' value='".$_GET['plug']."'/>
245                           </form>";
247       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
249       /* Get and check command */
250       $command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
251       if (check_command($command)){
252         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
254         /* Print out html introduction */
255         echo '<!-- headers.tpl--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
256                 "http://www.w3.org/TR/html4/transitional.dtd">
257                 <html><head><title></title><style type="text/css">@import url("themes/default/style.css");</style>';
258         echo "<script language=\"javascript\" src=\"include/focus.js\" type=\"text/javascript\"></script>";
259         echo "</head>";
260         echo "<body style='background: none;'>
261                 <script language=\"javascript\" type=\"text/javascript\">
262                   document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
263                 </script>
264               <pre>";
266         /* Open process handle and check if it is a valid process */
267         $process= proc_open($command, $dsc, $pipes);
268         if (is_resource($process)) {
269           fclose($pipes[0]);
271           /* Print out returned lines && write JS to scroll down each line */
272           while (!feof($pipes[1])){
273             $cur_dat = fgets($pipes[1], 1024);
274             echo $cur_dat;
275             echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
276             flush();
277           }
278         }
279     
280         /* Get error string && close streams */
281         $buffer = "";
282         while (!feof($pipes[2])){
283           $buffer .= fgets($pipes[2],256);
284         }
285       
286         fclose($pipes[1]);
287         fclose($pipes[2]);
288         echo "</pre>";
289       
290         /* Check return code */ 
291         $ret= proc_close($process);
292         if ($ret != 0){
293           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
294           echo "<pre style='color:red'>$buffer</pre>";
295         }
297         echo $return_button."<br>";
299       } else {
300         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
301         echo $tmp;
302       }
304       /* Scroll down completly */
305       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
306       echo "</body></html>";
307       flush();
308       exit;
309     }
312     /********************
313       Change password ...   
314      ********************/
316     /* Set terminals root password */
317     if ($s_action=="change_pw"){
318       $this->dn= $this->terminals[$s_entry]['dn'];
319       $_SESSION['objectinfo']= $this->dn;
320       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
321     }
324     /********************
325       Password cahnge finish, but check if entered data is ok 
326      ********************/
328     /* Correctly specified? */
329     if (isset($_POST['password_finish'])){
330       if ($_POST['new_password'] != $_POST['repeated_password']){
331         print_red (_("Passwords entered as new and repeated do not match!"));
332         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
333       }
334     }
336     /********************
337       Password change finish
338      ********************/
340     /* Change terminal password */
341     if (isset($_POST['password_finish']) && 
342         $_POST['new_password'] == $_POST['repeated_password']){
344       /* Check if user is allowed to set password */
345       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
346       $acl= get_module_permission($acl, "terminal", $this->dn);
347       if (chkacl($acl, "password") != ""){
348         print_red (_("You are not allowed to set this systems password!"));
349       } else {
350         $ldap= $this->config->get_ldap_link();
351         $ldap->cd($this->dn);
353         $attrs= array();
354         if ($_POST['new_password'] == ""){
355           $attrs['gotoRootPasswd']= array();
356         } else {
357           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
358               substr(session_id(),0,2));
359         }
360         $ldap->modify($attrs);
361         gosa_log ("Password for '".$this->dn."' has been changed");
362       }
363       unset($_SESSION['objectinfo']);
364     }
367     /********************
368       Delete system cancel
369      ********************/
371     /* Delete terminal canceled? */
372     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
373       del_lock ($this->dn);
374       unset($_SESSION['objectinfo']);
375     }
378     /********************
379       Delete system, confirm dialog
380      ********************/
382     /* Remove terminal was requested */
383     if ($s_action=="del"){
385       /* Get 'dn' from posted termlinst */
386       $this->dn= $this->terminals[$s_entry]['dn'];
388       /* Load permissions for selected 'dn' and check if
389          we're allowed to remove this 'dn' */
390       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
391       $this->acl= get_module_permission($acl, "terminal", $this->dn);
392       if (chkacl($this->acl, "delete") == ""){
394         /* Check locking, save current plugin in 'back_plugin', so
395            the dialog knows where to return. */
396         if (($user= get_lock($this->dn)) != ""){
397           return(gen_locked_message ($user, $this->dn));
398         }
400         /* Lock the current entry, so nobody will edit it during deletion */
401         add_lock ($this->dn, $this->ui->dn);
402         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
403         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
404       } else {
406         /* Obviously the user isn't allowed to delete. Show message and
407            clean session. */
408         print_red (_("You are not allowed to delete this component!"));
409       }
410     }
413     /********************
414       Delete system, confirmed
415      ********************/
416     /* Confirmation for deletion has been passed. Terminal should be deleted. */
417     if (isset($_POST['delete_terminal_confirm'])){
419       /* Some nice guy may send this as POST, so we've to check
420          for the permissions again. */
421       if (chkacl($this->acl, "delete") == ""){
423         /* Find out more about the object type */
424         $ldap= $this->config->get_ldap_link();
425         $ldap->cat($this->dn, array('objectClass'));
426         $attrs= $ldap->fetch();
427         $type= $this->get_system_type($attrs['objectClass']);
429         $tabs = array(
430             "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
431             "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
432             "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
433             "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
434             "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
435             "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
436             "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
438         /* get object type */
439         $tabtype  = "termtabs";
440         $tabobj   = "TERMTABS";
441         if(isset($tabs[$type])){
442           $tabtype = $tabs[$type]['TABCLASS'];
443           $tabobj  = $tabs[$type]['CLASS'];
444         }
446         /* Delete request is permitted, perform LDAP action */
447         if($tabtype=="phonetabs"){
448           $this->systab= new $tabtype($this->config,
449               $this->config->data['TABS'][$tabobj], $this->dn);
450           $this->systab->set_acl(array($this->acl));
451           $this->systab->by_object['phonegeneric']->remove_from_parent ();
452         }else{  
453           $this->systab= new $tabtype($this->config,
454               $this->config->data['TABS'][$tabobj], $this->dn);
455           $this->systab->set_acl(array($this->acl));
456           $this->systab->delete();
457 #$this->systab->by_object['termgeneric']->remove_from_parent ();
458         }
459         unset ($this->systab);
460         gosa_log ("System object'".$this->dn."' has been removed");
461         $this->systab= NULL;
463         /* Terminal list has changed, reload it. */
464       } else {
466         /* Normally this shouldn't be reached, send some extra
467            logs to notify the administrator */
468         print_red (_("You are not allowed to delete this component!"));
469         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
470             "deletion.");
471       }
473       /* Remove lock file after successfull deletion */
474       del_lock ($this->dn);
475     }
478     /********************
479       Edit system type finished, check if everything went ok 
480      ********************/
481     /* Finish user edit is triggered by the tabulator dialog, so
482        the user wants to save edited data. Check and save at this
483        point. */
484     if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
486       /* Check tabs, will feed message array */
487       $message = array();
488       if(!$save_object_directly){
489         $message = $this->systab->check();
490       }else{
491         $found = false;
492   
493         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
494         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
495           if(isset($this->systab->by_object[$tab]->gotoMode)) {
496             $found = true;
497             $this->systab->by_object[$tab]->gotoMode = $value;
498           }
499         }   
500         if(!$found){
501           print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
502         }
504       }
505       /* Save, or display error message? */
506       if (count($message) == 0){
508         /* Save terminal data to ldap */
509         if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
510           foreach (array("workservice", "termservice") as $cls){
511             if (isset($this->systab->by_object[$cls])){
512               $this->systab->by_object[$cls]->gotoXMouseport= "";
513               $this->systab->by_object[$cls]->gotoXMouseType= "";
514               $this->systab->by_object[$cls]->gotoXResolution= "";
515               $this->systab->by_object[$cls]->gotoXColordepth= "";
516             }
517           }
518         }
520         $this->systab->save();
521         gosa_log ("System object'".$this->dn."' has been saved");
523         /* Incoming behavior; you can select a system type and an ogroup membership. 
524          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
525          * Check if we must add the new object to an object group.
526          * 
527          * If this is done, delete the old incoming entry... it is still there, because this is a new 
528          * entry and not an edited one, so we will delete it.
529          */
531         if(isset($_SESSION['SelectedSystemType'])){
532           $SelectedSystemType= $_SESSION['SelectedSystemType'];
533           unset($_SESSION['SelectedSystemType']);
534           if($SelectedSystemType['ogroup'] != "none"){
535             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
536             if($og){
537               $og->AddDelMembership($this->systab->dn);
538               $og->save();
539             }
540           }
541           if(!isset($ldap)){
542             $ldap = $this->config->get_ldap_link();
543           }
544           $ldap->cd ($this->dn);
545           $ldap->cat($this->dn, array('dn'));  
546           if(count($ldap->fetch())){
547             $ldap->cd($this->dn);
548             $ldap->rmDir($this->dn);
549           }
550           $ldap->cd($this->config->current['BASE']);
551         }
553         /* Terminal has been saved successfully, remove lock from
554            LDAP. */
555         if ($this->dn != "new"){
556           del_lock ($this->dn);
557         }
559         unset ($this->systab);
560         $this->systab= NULL;
561         unset($_SESSION['objectinfo']);
562       } else {
563         /* Ok. There seem to be errors regarding to the tab data,
564            show message and continue as usual. */
565         show_errors($message);
566       }
567     }
569     /********************
570       Edit system was canceled 
571      ********************/
572     /* Cancel dialogs */
573     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
574       if (isset($this->systab)){
575         del_lock ($this->systab->dn);
576         unset ($this->systab);
577       }
578       $this->systab= NULL;
579       unset($_SESSION['objectinfo']);
581       /* Remove ogroup selection, which was set while editing a new incoming entry */
582       if(isset($_SESSION['SelectedSystemType'])){
583         unset($_SESSION['SelectedSystemType']);
584       }
585     }
587     /********************
588       Display edit dialog, or some other
589      ********************/
591     /* Show tab dialog if object is present */
592     if (isset($this->systab->config)){
593       $display= $this->systab->execute();
595       /* Don't show buttons if tab dialog requests this */
596       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
597         $display.= "<p style=\"text-align:right\">\n";
598         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
599         $display.= "&nbsp;\n";
600         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
601         $display.= "</p>";
602       }
603       return ($display);
604     }
606     /* Display dialog with system list */
607     $this->DivListSystem->parent = $this;
608     $this->DivListSystem->execute();
610     /* Add departments if subsearch is disabled */
611     if(!$this->DivListSystem->SubSearch){
612       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
613     }
614     $this->reload();
615     $this->DivListSystem->setEntries($this->terminals);
616     return($this->DivListSystem->Draw());
617   }
621   function remove_from_parent()
622   {
623     /* Optionally execute a command after we're done */
624     $this->postremove();
625   }
628   /* Save data to object */
629   function save_object()
630   {
631     $this->DivListSystem->save_object();
632   }
635   /* Check values */
636   function check()
637   {
638   }
641   /* Save to LDAP */
642   function save()
643   {
644   }
646   function adapt_from_template($dn)
647   {
648   }
650   function password_change_needed()
651   {
652   }
654   function reload()
655   {
656     /* Load terminal shortcuts */
657     $responsible= array();
658     foreach ($this->config->departments as $key => $value){
659       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
660             "terminal", $value) == "#all#"){
661         $responsible[$key]= $value;
662       }
663     }
665     /* some var init */
666     $res              = array();
667     $this->terminals  = array();
668     $userregex        = "";
670     /* Set base for all searches */
671     $base=  $this->DivListSystem->selectedBase;
673     /* Prepare samba class name */
674     $samba  ="";
675     if ($this->DivListSystem->ShowWinWorkstations){
676       if ($this->config->current['SAMBAVERSION'] == "3"){
677         $samba= "sambaSamAccount";
678       } else {
679         $samba= "sambaAccount";
680       }
681     }
683     /* This array represents the combination between checkboxes and search filters */
684     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
685         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
686         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
687         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
688         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
689         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
690         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
692     /* Include the 'Display Systems of user' attribute */ 
693     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
694       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
695     }
697     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
698     foreach($objs as $checkBox => $oc){
699       if($this->DivListSystem->$checkBox){
700         if($this->DivListSystem->SubSearch){
701           if($oc['CLASS'] != ""){
702             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
703             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
704                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
705           }
706         }else{
707           /* User filter? */
708           if($oc['CLASS'] != ""){
709             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
710             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
711                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
712           }
713         }
714       } 
715     }
717     /* Search for incoming objects */ 
718     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
719     $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
720           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
722     /* Get all gotoTerminal's */
723     foreach ($res as $value){
725       $tmp= $value['dn'];
726       $add= "";
728       /* Extract base */
729       foreach($objs as $obj){
730         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
731           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
732         }
733       }
735       /* check if current object is a new one */
736       if (preg_match ("/,ou=incoming,/i", $tmp)){
737         if (in_array_ics('gotoTerminal', $value['objectClass'])){
738           $add= "- "._("New terminal");
739         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
740           $add= "- "._("New workstation");
741         }elseif (in_array_ics('GOhard', $value['objectClass'])){
742           $add= "- "._("New Device");
743         }
744       } 
746       /* Create a string containing the last part of the department. */
747       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
748       if(empty($dn_name)){
749         $dn_name = "/";
750       }
751       
752       /* Detect type of object and create an entry for $this->terminals */
753       $terminal = array();
754       if ((in_array ($tmp, $responsible)) || ($add != "")){
755         if (in_array_ics('gotoTerminal', $value["objectClass"])){
756           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
757             $terminal             = $value;
758             $terminal['type']     = "T";
759             $terminal['is_new']   = $add;
760           } else {
761             $terminal             = $value;
762             $terminal['type']     = "D";
763             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
764             $terminal['location'] = array_search($tmp, $this->config->departments); 
765           }
766         } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
767           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
768             $terminal             = $value;
769             $terminal['type']     = "L";
770             $terminal['is_new']   = $add;
771           } else {
772             $terminal             = $value;
773             $terminal['type']     = "D";
774             $terminal['location'] = array_search($tmp, $this->config->departments);
775             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
776           }
777           if (isset($value["FAIstate"][0])){
778             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
779           }
780         } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
781           $terminal             = $value;
782           $terminal['type']     = "P";
783         } elseif (in_array_ics('goServer', $value["objectClass"])){
784           $terminal             = $value;
785           $terminal['type']     = "S";
786           if (isset($value["FAIstate"][0])){
787             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
788           }
789         } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
790           $terminal             = $value;
791           $terminal['type']     = "F";
792         }elseif (in_array_ics("GOhard",$value['objectClass'])){
793           $terminal = $value;
794           $terminal['type']   = "Q";
795           $terminal['is_new'] = $add;
796         } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
797           $terminal             = $value;
798           $terminal['type']     = "C";
799         } else{
800           $name= preg_replace('/\$$/', '', $value['cn'][0]);
801           if (isset($value['sambaDomainName'])){
802             $domain= " [".$value['sambaDomainName'][0]."]";
803           } else {
804             $domain= "";
805           }
806           $terminal=$value;
807           $terminal['type']     ="W";
808           $terminal['domain']   = $name.$domain;
809         }
810         $this->terminals[]=$terminal;
811       }
812     }
814     $tmp=array();
815     foreach($this->terminals as $tkey => $val ){
816       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
817     }
818     ksort($tmp);
819     $this->terminals=array();
820     foreach($tmp as $val){
821       $this->terminals[]=$val;
822     }
823     reset ($this->terminals);
824   }
826   function remove_lock()
827   {
828     if (isset($this->systab->dn)){
829       del_lock ($this->systab->dn);
830     }
831   }
834   function get_system_type($classes)
835   {
836     $type= "";
837     if (in_array_ics('ieee802Device', $classes)){
838       $type= "component";
839     }elseif (in_array_ics('gotoTerminal', $classes)){
840       $type= "terminal";
841     }elseif (in_array_ics('gotoWorkstation', $classes)){
842       $type= "workstation";
843     }elseif (in_array_ics('gotoPrinter', $classes)){
844       $type= "printer";
845     }elseif (in_array_ics('goFonHardware', $classes)){
846       $type= "phone";
847     }elseif (in_array_ics('goServer', $classes)){
848       $type= "server";
849     }elseif (in_array_ics('GOhard', $classes)){
850       $type= "NewDevice";
851     }elseif (in_array_ics('sambaAccount', $classes) ||
852         in_array_ics('sambaSamAccount', $classes)){
853       $type= "winstation";
854     }
855     return ($type);
856   }
859   function convert_list($input)
860   {
861     $temp= "";
862     $conv= array(       
863         "NQ" => array("select_newsystem.png",_("New System from incoming")),
864         "D" => array("select_default.png",_("Template")),
865         "T" => array("select_terminal.png",_("Terminal")),
866         "L" => array("select_workstation.png",_("Workstation")),
867         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
868         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
869         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
870         "F" => array("select_phone.png",_("Phone")),
871         "S" => array("select_server.png",_("Server")),
872         "GS" => array("select_server_green.png",_("Server is installing")),
873         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
874         "RS" => array("select_server_red.png",_("Server installation failed")),
875         "W" => array("select_winstation.png",_("Winstation")),
876         "C" => array("select_component.png",_("Network Device")),
877         "NT"=> array("select_new_terminal.png",_("New Terminal")),
878         "NL"=> array("select_new_workstation.png",_("New Workstation")),
879         "P" => array("select_printer.png",_("Printer")));
881     if((isset($input['is_new']))&&(!empty($input['is_new']))){
882       $input['type']="N".$input['type'];
883     }
884     foreach ($conv  as $key => $value){
885       if($input['type']==$key){
886         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
887         $tmp['class']=$key;
888         return $tmp;
889       }
890     }
891   }
893   
894   function getState($type, $state)
895   {
896     switch (preg_replace('/:.*$/', '', $state)) {
897       case 'installing':
898                 $type= 'G'.$type;
899                 break;
900       case 'error':
901                 $type= 'R'.$type;
902                 break;
903       case 'install':
904                 $type= 'Y'.$type;
905                 break;
906       case 'sysinfo':
907                 $type= 'Y'.$type;
908                 break;
909       case 'softupdate':
910                 $type= 'Y'.$type;
911                 break;
912     }
915     return ($type);
916   }
920 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
921 ?>