Code

e18dc1a5de908c0480ae8b1c1b7e9393dec9b8cc
[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 //      $command = "/bin/sh /home/hickert/gen_stuff.sh";
252       if (check_command($command)){
253         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
255         /* Print out html introduction */
256         echo '<!-- headers.tpl--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
257                 "http://www.w3.org/TR/html4/transitional.dtd">
258                 <html><head><title></title><style type="text/css">@import url("themes/default/style.css");</style>';
259         echo "<script language=\"javascript\" src=\"include/focus.js\" type=\"text/javascript\"></script>";
260         echo "</head>";
261         echo "<body style='background: none;'>
262                 <script language=\"javascript\" type=\"text/javascript\">
263                   document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
264                 </script>
265               <pre>";
267         /* Open process handle and check if it is a valid process */
268         $process= proc_open($command, $dsc, $pipes, '/tmp');
269         if (is_resource($process)) {
270           fclose($pipes[0]);
272           /* Print out returned lines && write JS to scroll down each line */
273           while (!feof($pipes[1])){
274             $cur_dat = fgets($pipes[1], 1024);
275             echo $cur_dat;
276             echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
277             flush();
278           }
279         }
280     
281         /* Get error string && close streams */
282         $buffer= stream_get_contents($pipes[2]);
283         fclose($pipes[1]);
284         fclose($pipes[2]);
285         echo "</pre>";
286       
287         /* Check return code */ 
288         $ret= proc_close($process);
289         if ($ret != 0){
290           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
291           echo "<pre style='color:red'>$buffer</pre>";
292         }
294         echo $return_button."<br>";
296       } else {
297         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
298         echo $tmp;
299       }
301       /* Scroll down completly */
302       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
303       echo "</body></html>";
304       flush();
305       exit;
306     }
309     /********************
310       Change password ...   
311      ********************/
313     /* Set terminals root password */
314     if ($s_action=="change_pw"){
315       $this->dn= $this->terminals[$s_entry]['dn'];
316       $_SESSION['objectinfo']= $this->dn;
317       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
318     }
321     /********************
322       Password cahnge finish, but check if entered data is ok 
323      ********************/
325     /* Correctly specified? */
326     if (isset($_POST['password_finish'])){
327       if ($_POST['new_password'] != $_POST['repeated_password']){
328         print_red (_("Passwords entered as new and repeated do not match!"));
329         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
330       }
331     }
333     /********************
334       Password change finish
335      ********************/
337     /* Change terminal password */
338     if (isset($_POST['password_finish']) && 
339         $_POST['new_password'] == $_POST['repeated_password']){
341       /* Check if user is allowed to set password */
342       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
343       $acl= get_module_permission($acl, "terminal", $this->dn);
344       if (chkacl($acl, "password") != ""){
345         print_red (_("You are not allowed to set this systems password!"));
346       } else {
347         $ldap= $this->config->get_ldap_link();
348         $ldap->cd($this->dn);
350         $attrs= array();
351         if ($_POST['new_password'] == ""){
352           $attrs['gotoRootPasswd']= array();
353         } else {
354           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
355               substr(session_id(),0,2));
356         }
357         $ldap->modify($attrs);
358         gosa_log ("Password for '".$this->dn."' has been changed");
359       }
360       unset($_SESSION['objectinfo']);
361     }
364     /********************
365       Delete system cancel
366      ********************/
368     /* Delete terminal canceled? */
369     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
370       del_lock ($this->dn);
371       unset($_SESSION['objectinfo']);
372     }
375     /********************
376       Delete system, confirm dialog
377      ********************/
379     /* Remove terminal was requested */
380     if ($s_action=="del"){
382       /* Get 'dn' from posted termlinst */
383       $this->dn= $this->terminals[$s_entry]['dn'];
385       /* Load permissions for selected 'dn' and check if
386          we're allowed to remove this 'dn' */
387       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
388       $this->acl= get_module_permission($acl, "terminal", $this->dn);
389       if (chkacl($this->acl, "delete") == ""){
391         /* Check locking, save current plugin in 'back_plugin', so
392            the dialog knows where to return. */
393         if (($user= get_lock($this->dn)) != ""){
394           return(gen_locked_message ($user, $this->dn));
395         }
397         /* Lock the current entry, so nobody will edit it during deletion */
398         add_lock ($this->dn, $this->ui->dn);
399         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
400         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
401       } else {
403         /* Obviously the user isn't allowed to delete. Show message and
404            clean session. */
405         print_red (_("You are not allowed to delete this component!"));
406       }
407     }
410     /********************
411       Delete system, confirmed
412      ********************/
413     /* Confirmation for deletion has been passed. Terminal should be deleted. */
414     if (isset($_POST['delete_terminal_confirm'])){
416       /* Some nice guy may send this as POST, so we've to check
417          for the permissions again. */
418       if (chkacl($this->acl, "delete") == ""){
420         /* Find out more about the object type */
421         $ldap= $this->config->get_ldap_link();
422         $ldap->cat($this->dn, array('objectClass'));
423         $attrs= $ldap->fetch();
424         $type= $this->get_system_type($attrs['objectClass']);
426         $tabs = array(
427             "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs"),
428             "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs"),
429             "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs"),
430             "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs"),
431             "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs"),
432             "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs"),
433             "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs"));
435         /* get object type */
436         $tabtype  = "termtabs";
437         $tabobj   = "TERMTABS";
438         if(isset($tabs[$type])){
439           $tabtype = $tabs[$type]['TABCLASS'];
440           $tabobj  = $tabs[$type]['CLASS'];
441         }
443         /* Delete request is permitted, perform LDAP action */
444         if($tabtype=="phonetabs"){
445           $this->systab= new $tabtype($this->config,
446               $this->config->data['TABS'][$tabobj], $this->dn);
447           $this->systab->set_acl(array($this->acl));
448           $this->systab->by_object['phonegeneric']->remove_from_parent ();
449         }else{  
450           $this->systab= new $tabtype($this->config,
451               $this->config->data['TABS'][$tabobj], $this->dn);
452           $this->systab->set_acl(array($this->acl));
453           $this->systab->delete();
454 #$this->systab->by_object['termgeneric']->remove_from_parent ();
455         }
456         unset ($this->systab);
457         gosa_log ("System object'".$this->dn."' has been removed");
458         $this->systab= NULL;
460         /* Terminal list has changed, reload it. */
461       } else {
463         /* Normally this shouldn't be reached, send some extra
464            logs to notify the administrator */
465         print_red (_("You are not allowed to delete this component!"));
466         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
467             "deletion.");
468       }
470       /* Remove lock file after successfull deletion */
471       del_lock ($this->dn);
472     }
475     /********************
476       Edit system type finished, check if everything went ok 
477      ********************/
478     /* Finish user edit is triggered by the tabulator dialog, so
479        the user wants to save edited data. Check and save at this
480        point. */
481     if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
483       /* Check tabs, will feed message array */
484       $message = array();
485       if(!$save_object_directly){
486         $message = $this->systab->check();
487       }else{
488         $found = false;
489   
490         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
491         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
492           if(isset($this->systab->by_object[$tab]->gotoMode)) {
493             $found = true;
494             $this->systab->by_object[$tab]->gotoMode = $value;
495           }
496         }   
497         if(!$found){
498           print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
499         }
501       }
502       /* Save, or display error message? */
503       if (count($message) == 0){
505         /* Save terminal data to ldap */
506         if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
507           foreach (array("workservice", "termservice") as $cls){
508             if (isset($this->systab->by_object[$cls])){
509               $this->systab->by_object[$cls]->gotoXMouseport= "";
510               $this->systab->by_object[$cls]->gotoXMouseType= "";
511               $this->systab->by_object[$cls]->gotoXResolution= "";
512               $this->systab->by_object[$cls]->gotoXColordepth= "";
513             }
514           }
515         }
517         $this->systab->save();
518         gosa_log ("System object'".$this->dn."' has been saved");
520         /* Incoming behavior; you can select a system type and an ogroup membership. 
521          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
522          * Check if we must add the new object to an object group.
523          * 
524          * If this is done, delete the old incoming entry... it is still there, because this is a new 
525          * entry and not an edited one, so we will delete it.
526          */
528         if(isset($_SESSION['SelectedSystemType'])){
529           $SelectedSystemType= $_SESSION['SelectedSystemType'];
530           unset($_SESSION['SelectedSystemType']);
531           if($SelectedSystemType['ogroup'] != "none"){
532             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
533             if($og){
534               $og->AddDelMembership($this->systab->dn);
535               $og->save();
536             }
537           }
538           if(!isset($ldap)){
539             $ldap = $this->config->get_ldap_link();
540           }
541           $ldap->cd ($this->dn);
542           $ldap->cat($this->dn, array('dn'));  
543           if(count($ldap->fetch())){
544             $ldap->cd($this->dn);
545             $ldap->rmDir($this->dn);
546           }
547           $ldap->cd($this->config->current['BASE']);
548         }
550         /* Terminal has been saved successfully, remove lock from
551            LDAP. */
552         if ($this->dn != "new"){
553           del_lock ($this->dn);
554         }
556         unset ($this->systab);
557         $this->systab= NULL;
558         unset($_SESSION['objectinfo']);
559       } else {
560         /* Ok. There seem to be errors regarding to the tab data,
561            show message and continue as usual. */
562         show_errors($message);
563       }
564     }
566     /********************
567       Edit system was canceled 
568      ********************/
569     /* Cancel dialogs */
570     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
571       if (isset($this->systab)){
572         del_lock ($this->systab->dn);
573         unset ($this->systab);
574       }
575       $this->systab= NULL;
576       unset($_SESSION['objectinfo']);
578       /* Remove ogroup selection, which was set while editing a new incoming entry */
579       if(isset($_SESSION['SelectedSystemType'])){
580         unset($_SESSION['SelectedSystemType']);
581       }
582     }
584     /********************
585       Display edit dialog, or some other
586      ********************/
588     /* Show tab dialog if object is present */
589     if (isset($this->systab->config)){
590       $display= $this->systab->execute();
592       /* Don't show buttons if tab dialog requests this */
593       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
594         $display.= "<p style=\"text-align:right\">\n";
595         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
596         $display.= "&nbsp;\n";
597         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
598         $display.= "</p>";
599       }
600       return ($display);
601     }
603     /* Display dialog with system list */
604     $this->DivListSystem->parent = $this;
605     $this->DivListSystem->execute();
607     /* Add departments if subsearch is disabled */
608     if(!$this->DivListSystem->SubSearch){
609       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
610     }
611     $this->reload();
612     $this->DivListSystem->setEntries($this->terminals);
613     return($this->DivListSystem->Draw());
614   }
618   function remove_from_parent()
619   {
620     /* Optionally execute a command after we're done */
621     $this->postremove();
622   }
625   /* Save data to object */
626   function save_object()
627   {
628     $this->DivListSystem->save_object();
629   }
632   /* Check values */
633   function check()
634   {
635   }
638   /* Save to LDAP */
639   function save()
640   {
641   }
643   function adapt_from_template($dn)
644   {
645   }
647   function password_change_needed()
648   {
649   }
651   function reload()
652   {
653     /* Load terminal shortcuts */
654     $responsible= array();
655     foreach ($this->config->departments as $key => $value){
656       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
657             "terminal", $value) == "#all#"){
658         $responsible[$key]= $value;
659       }
660     }
662     /* some var init */
663     $res              = array();
664     $this->terminals  = array();
665     $userregex        = "";
667     /* Set base for all searches */
668     $base=  $this->DivListSystem->selectedBase;
670     /* Prepare samba class name */
671     $samba  ="";
672     if ($this->DivListSystem->ShowWinWorkstations){
673       if ($this->config->current['SAMBAVERSION'] == "3"){
674         $samba= "sambaSamAccount";
675       } else {
676         $samba= "sambaAccount";
677       }
678     }
680     /* This array represents the combination between checkboxes and search filters */
681     $objs = array( "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => "ou=servers,ou=systems," ),
682         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => "ou=terminals,ou=systems,"), 
683         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => "ou=printers,ou=systems," ),
684         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => "ou=netdevices,ou=systems," ),
685         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => "ou=phones,ou=systems," ),
686         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
687         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
689     /* Include the 'Display Systems of user' attribute */ 
690     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
691       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
692     }
694     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
695     foreach($objs as $checkBox => $oc){
696       if($this->DivListSystem->$checkBox){
697         if($this->DivListSystem->SubSearch){
698           if($oc['CLASS'] != ""){
699             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
700             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $base,
701                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT));
702           }
703         }else{
704           /* User filter? */
705           if($oc['CLASS'] != ""){
706             $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
707             $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, $oc['TREE'].$base,
708                   array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
709           }
710         }
711       } 
712     }
714     /* Search for incoming objects */ 
715     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
716     $res = array_merge($res,get_list($filter,$this->ui->subtreeACL, "ou=incoming,".$base,
717           array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
719     /* Get all gotoTerminal's */
720     foreach ($res as $value){
722       $tmp= $value['dn'];
723       $add= "";
725       /* Extract base */
726       foreach($objs as $obj){
727         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
728           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
729         }
730       }
732       /* check if current object is a new one */
733       if (preg_match ("/,ou=incoming,/i", $tmp)){
734         if (in_array_ics('gotoTerminal', $value['objectClass'])){
735           $add= "- "._("New terminal");
736         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
737           $add= "- "._("New workstation");
738         }elseif (in_array_ics('GOhard', $value['objectClass'])){
739           $add= "- "._("New Device");
740         }
741       } 
743       /* Create a string containing the last part of the department. */
744       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
745       if(empty($dn_name)){
746         $dn_name = "/";
747       }
748       
749       /* Detect type of object and create an entry for $this->terminals */
750       $terminal = array();
751       if ((in_array ($tmp, $responsible)) || ($add != "")){
752         if (in_array_ics('gotoTerminal', $value["objectClass"])){
753           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
754             $terminal             = $value;
755             $terminal['type']     = "T";
756             $terminal['is_new']   = $add;
757           } else {
758             $terminal             = $value;
759             $terminal['type']     = "D";
760             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
761             $terminal['location'] = array_search($tmp, $this->config->departments); 
762           }
763         } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
764           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
765             $terminal             = $value;
766             $terminal['type']     = "L";
767             $terminal['is_new']   = $add;
768           } else {
769             $terminal             = $value;
770             $terminal['type']     = "D";
771             $terminal['location'] = array_search($tmp, $this->config->departments);
772             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
773           }
774           if (isset($value["FAIstate"][0])){
775             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
776           }
777         } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
778           $terminal             = $value;
779           $terminal['type']     = "P";
780         } elseif (in_array_ics('goServer', $value["objectClass"])){
781           $terminal             = $value;
782           $terminal['type']     = "S";
783           if (isset($value["FAIstate"][0])){
784             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
785           }
786         } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
787           $terminal             = $value;
788           $terminal['type']     = "F";
789         }elseif (in_array_ics("GOhard",$value['objectClass'])){
790           $terminal = $value;
791           $terminal['type']   = "Q";
792           $terminal['is_new'] = $add;
793         } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
794           $terminal             = $value;
795           $terminal['type']     = "C";
796         } else{
797           $name= preg_replace('/\$$/', '', $value['cn'][0]);
798           if (isset($value['sambaDomainName'])){
799             $domain= " [".$value['sambaDomainName'][0]."]";
800           } else {
801             $domain= "";
802           }
803           $terminal=$value;
804           $terminal['type']     ="W";
805           $terminal['domain']   = $name.$domain;
806         }
807         $this->terminals[]=$terminal;
808       }
809     }
811     $tmp=array();
812     foreach($this->terminals as $tkey => $val ){
813       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
814     }
815     ksort($tmp);
816     $this->terminals=array();
817     foreach($tmp as $val){
818       $this->terminals[]=$val;
819     }
820     reset ($this->terminals);
821   }
823   function remove_lock()
824   {
825     if (isset($this->systab->dn)){
826       del_lock ($this->systab->dn);
827     }
828   }
831   function get_system_type($classes)
832   {
833     $type= "";
834     if (in_array_ics('ieee802Device', $classes)){
835       $type= "component";
836     }elseif (in_array_ics('gotoTerminal', $classes)){
837       $type= "terminal";
838     }elseif (in_array_ics('gotoWorkstation', $classes)){
839       $type= "workstation";
840     }elseif (in_array_ics('gotoPrinter', $classes)){
841       $type= "printer";
842     }elseif (in_array_ics('goFonHardware', $classes)){
843       $type= "phone";
844     }elseif (in_array_ics('goServer', $classes)){
845       $type= "server";
846     }elseif (in_array_ics('GOhard', $classes)){
847       $type= "NewDevice";
848     }elseif (in_array_ics('sambaAccount', $classes) ||
849         in_array_ics('sambaSamAccount', $classes)){
850       $type= "winstation";
851     }
852     return ($type);
853   }
856   function convert_list($input)
857   {
858     $temp= "";
859     $conv= array(       
860         "NQ" => array("select_newsystem.png",_("New System from incoming")),
861         "D" => array("select_default.png",_("Template")),
862         "T" => array("select_terminal.png",_("Terminal")),
863         "L" => array("select_workstation.png",_("Workstation")),
864         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
865         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
866         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
867         "F" => array("select_phone.png",_("Phone")),
868         "S" => array("select_server.png",_("Server")),
869         "GS" => array("select_server_green.png",_("Server is installing")),
870         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
871         "RS" => array("select_server_red.png",_("Server installation failed")),
872         "W" => array("select_winstation.png",_("Winstation")),
873         "C" => array("select_component.png",_("Network Device")),
874         "NT"=> array("select_new_terminal.png",_("New Terminal")),
875         "NL"=> array("select_new_workstation.png",_("New Workstation")),
876         "P" => array("select_printer.png",_("Printer")));
878     if((isset($input['is_new']))&&(!empty($input['is_new']))){
879       $input['type']="N".$input['type'];
880     }
881     foreach ($conv  as $key => $value){
882       if($input['type']==$key){
883         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
884         $tmp['class']=$key;
885         return $tmp;
886       }
887     }
888   }
890   
891   function getState($type, $state)
892   {
893     switch (preg_replace('/:.*$/', '', $state)) {
894       case 'installing':
895                 $type= 'G'.$type;
896                 break;
897       case 'error':
898                 $type= 'R'.$type;
899                 break;
900       case 'install':
901                 $type= 'Y'.$type;
902                 break;
903       case 'sysinfo':
904                 $type= 'Y'.$type;
905                 break;
906       case 'softupdate':
907                 $type= 'Y'.$type;
908                 break;
909     }
912     return ($type);
913   }
917 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
918 ?>