Code

Just use the -n option from dh_installinit and the world is fine again.
[gosa.git] / 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= "";
42   function systems ($config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= $config;
46     $this->ui= $ui;
48     /* Get global filter config */
49     if (!is_global("terminalfilter")){
50       $ui   = get_userinfo();
51       $base = get_base_from_people($ui->dn);
52       $terminalfilter= array("workstations" => "checked",
53           "thins" => "checked",
54           "winstations" => "checked",
55           "servers" => "checked",
56           "printers" => "checked",
57           "phones" => "checked",
58           "netdev" => "checked",
59           "user" => "*",
60           "depselect" => $base,
61           "regex" => "*");
62       register_global("terminalfilter", $terminalfilter);
63     }
64   }
66   function execute()
67   {
68     /* Call parent execute */
69     plugin::execute();
71     /********************
72       Filter handling, check posted filter options and store them in our Session obejct
73      ********************/
74   
75     /* Save posted filter data */
76     $terminalfilter= get_global("terminalfilter");
77     foreach( array("depselect", "user", "regex") as $type){
78       if (isset($_POST[$type])){
79         $terminalfilter[$type]= $_POST[$type];
80       }
81     }
83     /* Check if filter checkboxes are selected */
84     if (isset($_POST['depselect'])){
85       foreach( array("workstations", "thins", "winstations", "printers", "phones", "servers", "netdev") as $type){
86         if (isset($_POST[$type])) {
87           $terminalfilter[$type]= "checked";
88         } else {
89           $terminalfilter[$type]= "";
90         }
91       }
92     }
94     /* Check for search post */
95     if (isset($_GET['search'])){
96       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
97       if ($s == "**"){
98         $s= "*";
99       }
100       $terminalfilter['regex']= $s;
101     }
104     /********************
105       Check for functional posts, edit|delete|add|... system devices 
106      ********************/
107     $s_action     = "";                       // Contains the action to proceed
108     $s_entry      = "";                       // The value for s_action
109     $base_back    = "";                       // The Link for Backbutton
110     $smarty       = get_smarty();
112     /* check if base was changed */
113     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
114             $s_action="open";
115             $s_entry = base64_decode($_GET['dep_id']);
116             $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
117             $this->reload();
118     }
120     /* Test Posts */
121     foreach($_POST as $key => $val){
122       // Post for delete
123       if(preg_match("/user_del.*/",$key)){
124         $s_action = "del";
125         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
126         // Post for edit
127       }elseif(preg_match("/user_edit_.*/",$key)){
128         $s_action="edit";
129         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
130         // Post for new
131       }elseif(preg_match("/dep_back.*/i",$key)){
132         $s_action="back";
133       }elseif(preg_match("/user_new.*/",$key)){
134         $s_action="new";
135       }elseif(preg_match("/dep_home.*/i",$key)){
136         $s_action="home";
137       }elseif(preg_match("/user_tplnew.*/i",$key)){
138         $s_action="new_tpl";
139       }elseif(preg_match("/user_setpwd_.*/i",$key)){
140         $s_action="change_pw";
141         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
142       }elseif(preg_match("/dep_root.*/i",$key)){
143         $s_action="root";
144       }elseif(preg_match("/newsystem_.*/i",$key)){
145         $s_action="newsystem";
146         $s_entry  = preg_replace("/newsystem_/i","",$key);
147       }
148     }
150     /* 09.02.2006 : New incoming handling ; hickert
151      * If someone made a systemtype and ogroup selection 
152      * Display the new requested entry type ... servtab  in case of server and so on.
153      */
154     if(isset($_POST['SystemTypeChoosen'])){
155       $s_action = "SelectedSystemType";
156       $s_entry  = $_POST['SystemType'];
157       $this->systab = NULL;
158     }
160     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
161     $s_entry  = preg_replace("/_.$/","",$s_entry);
163     /* Edit was requested by pressing the name(link) of an item */
164     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
165       $s_action ="edit";
166       $s_entry  = $_GET['id'];
167     }
169     /* Department changed? */
170     if(isset($_POST['depselect']) && $_POST['depselect']){
171       $terminalfilter['depselect']= $_POST['depselect'];
172     }
174     /* Homebutton is posted */
175     if($s_action=="home"){
176       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
177       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
178     }
180     /* back to the roots ^^ */
181     if($s_action=="root"){
182       $terminalfilter['depselect']=($this->config->current['BASE']);
183     }
185     /* If Backbutton is Posted */
186     if($s_action=="back"){
187       $base_back          = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
188       $base_back          = convert_department_dn($base_back);
190       if(isset($this->config->departments[trim($base_back)])){
191         $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
192       }else{
193         $terminalfilter['depselect']= $this->config->departments["/"];
194       }
195     }
197     /* Save Termfilter .... */
198     register_global("terminalfilter", $terminalfilter);
199     $this->reload();
200     
201     /* Check for exeeded sizelimit */
202     if (($message= check_sizelimit()) != ""){
203       return($message);
204     }
206     /* Try to get informations about what kind of system to create */
207     if ($s_action=="new") {
208       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
209     }
211     /********************
212      Create new system ...   
213      ********************/
214     /* Create new default terminal 
215      *
216      * 09.02.2006 ; New incoming handling ; hickert
217      * Or create specified object of selected system type, from given incoming object  
218      */
219     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
221       /* If the current entry is an incoming object 
222        * $sw = System type as posted in new incoming handling dialog 
223        */ 
224       if($s_action == "SelectedSystemType") {
225         $sw         = $s_entry;
226         $dn_backup  = $this->dn;
227       }else{
228         if(isset($_POST['system'])){
229           $sw = $_POST['system'];
230         }else{
231           $sw = $s_entry;
232         }
233       }
235       $this->dn= "new";
236       $this->acl= array(":all");
238       switch ($sw){
239         case 'terminal':
240           $this->systab= new termtabs($this->config,
241               $this->config->data['TABS']['TERMTABS'], $this->dn);
242           $this->systab->set_acl ($this->acl);
243           $this->systab->by_object['termgeneric']->cn= "default";
244           $this->systab->by_object['termservice']->cn= "default";
245           $this->systab->by_object['termgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
246           break;
248         case 'workstation':
249           $this->systab= new worktabs($this->config,
250               $this->config->data['TABS']['WORKTABS'], $this->dn);
251           $this->systab->set_acl ($this->acl);
252           $this->systab->by_object['workgeneric']->cn= "wdefault";
253           $this->systab->by_object['workservice']->cn= "default";
254           $this->systab->by_object['workgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
255           break;
257         case 'server':
258           $this->systab= new servtabs($this->config,
259               $this->config->data['TABS']['SERVTABS'], $this->dn);
260           $this->systab->set_acl ($this->acl);
261           $this->systab->by_object['servgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
262           break;
264         case 'printer':
265           $this->systab= new printtabs($this->config,
266               $this->config->data['TABS']['PRINTTABS'], $this->dn);
267           $this->systab->set_acl ($this->acl);
268           $this->systab->by_object['printgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
269           break;
271         case 'phone':
272           $this->systab= new phonetabs($this->config,
273               $this->config->data['TABS']['PHONETABS'], $this->dn);
274           $this->systab->set_acl ($this->acl);
275           $this->systab->by_object['phonegeneric']->base = $_SESSION['terminalfilter']['depselect'];  
276           break;
278         case 'component':
279           $this->systab= new componenttabs($this->config,
280               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
281           $this->systab->set_acl ($this->acl);
282           $this->systab->by_object['componentgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
283           break;
284       }
285      
286       /* 09.02.2006 ; New incoming handling ; hickert.
287        * We must create a NEW object of given system type (Posted from SelectDeviceType).
288        * But we have to use the same attributes as used in incoming object, thats
289        * what we do here. 
290        */ 
291       if($s_action == "SelectedSystemType"){
292     
293         /* Store some informations, to be able to add this object to 
294          * To specified objectgroup and delete incoming object
295          */
296         $_SESSION['SelectedSystemType']['dn']     = $this->dn;
297         $_SESSION['SelectedSystemType']['server'] = $s_entry;
298         $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
299         
300         /* restore dn */
301         $this->dn = $dn_backup;
303         /* Get properties from incoming object */
304         $ldap = $this->config->get_ldap_link();
305         $ldap->cd($this->dn);
306         $ldap->cat($this->dn);
307         $res = $ldap->fetch();
308       
309         /* Unset not needed attributes */
310         unset($res['dn']);
311         unset($res['objectClass']);
312     
313         /* Walk through all tabs and set attributes if available */
314         foreach($this->systab->by_object as $name => $value){
315           foreach($this->systab->by_object[$name]->attributes as $atr){
316             if((isset($value))&&(isset($res[$atr]))){
317               $this->systab->by_object[$name]->$atr = $res[$atr][0];
318             }
319           }
320         }
321       }
322   
323       /* set base ... of current divlist position */
324       $this->systab->base = $_SESSION['terminalfilter']['depselect'];  
325     }
328     /********************
329      Edit system ...   
330      ********************/
332     /* User wants to edit data? */
333     if ($s_action == "edit"){
335       $this->dn= $this->terminals[$s_entry]['dn'];
337       /* Check locking, save current plugin in 'back_plugin', so
338          the dialog knows where to return. */
339       if (($user= get_lock($this->dn)) != ""){
340         return(gen_locked_message ($user, $this->dn));
341       }
343       /* Set up the users ACL's for this 'dn' */
344       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
346       /* Find out more about the object type */
347       $ldap= $this->config->get_ldap_link();
348       $ldap->cat($this->dn);
349       $attrs= $ldap->fetch();
350       $type= $this->get_system_type($attrs['objectClass']);
352       /* Lock the current entry, so everyone will get the
353          above dialog */
355       switch ($type){
356         case "NewDevice" :
357           $this->systab = new SelectDeviceType($this->config,$this->dn) ;
358         break;
359         case "terminal":
360           /* Register systab to trigger edit dialog */
361           $this->systab= new termtabs($this->config,
362               $this->config->data['TABS']['TERMTABS'], $this->dn);
363         $this->systab->set_acl($acl);
364         $_SESSION['objectinfo']= $this->dn;
365         add_lock ($this->dn, $this->ui->dn);
366         break;
368         case "server":
370           /* Register systab to trigger edit dialog */
371           $this->systab= new servtabs($this->config,$this->config->data['TABS']['SERVTABS'], $this->dn);
372         $this->systab->set_acl($acl);
373         $_SESSION['objectinfo']= $this->dn;
374         add_lock ($this->dn, $this->ui->dn);
375         break;
377         case "workstation":
378           /* Register systab to trigger edit dialog */
379           $this->systab= new worktabs($this->config,
380               $this->config->data['TABS']['WORKTABS'], $this->dn);
381         $this->systab->set_acl($acl);
382         $_SESSION['objectinfo']= $this->dn;
383         add_lock ($this->dn, $this->ui->dn);
384         break;
386         case "printer":
387           /* Register systab to trigger edit dialog */
388           $this->systab= new printtabs($this->config,
389               $this->config->data['TABS']['PRINTTABS'], $this->dn);
390         $this->systab->set_acl($acl);
391         $_SESSION['objectinfo']= $this->dn;
392         add_lock ($this->dn, $this->ui->dn);
393         break;
395         case "phone":
396           /* Register systab to trigger edit dialog */
397           $this->systab= new phonetabs($this->config,
398               $this->config->data['TABS']['PHONETABS'], $this->dn);
399         $this->systab->set_acl($acl);
400         $_SESSION['objectinfo']= $this->dn;
401         add_lock ($this->dn, $this->ui->dn);
402         break;
404         case "component":
405           /* Register systab to trigger edit dialog */
406           $this->systab= new componenttabs($this->config,
407               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
408         $this->systab->set_acl($acl);
409         $_SESSION['objectinfo']= $this->dn;
410         add_lock ($this->dn, $this->ui->dn);
411         break;
413         case "winstation":
414           /* Register systab to trigger edit dialog */
415           $this->systab= new wintabs($this->config,
416               $this->config->data['TABS']['WINTABS'], $this->dn);
417         $this->systab->set_acl($acl);
418         $_SESSION['objectinfo']= $this->dn;
419         add_lock ($this->dn, $this->ui->dn);
420         break;
423         default:
424         print_red (_("You can't edit this object type yet!"));
425         del_lock($this->dn);
426         break;
427       }
428     }
429     
431     /********************
432      Change password ...   
433      ********************/
435     /* Set terminals root password */
436     if ($s_action=="change_pw"){
437       $this->dn= $this->terminals[$s_entry]['dn'];
438       $_SESSION['objectinfo']= $this->dn;
439       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
440     }
443     /********************
444       Password cahnge finish, but check if entered data is ok 
445      ********************/
447     /* Correctly specified? */
448     if (isset($_POST['password_finish'])){
449       if ($_POST['new_password'] != $_POST['repeated_password']){
450         print_red (_("Passwords entered as new and repeated do not match!"));
451         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
452       }
453     }
455     /********************
456       Password change finish
457      ********************/
459     /* Change terminal password */
460     if (isset($_POST['password_finish']) && 
461         $_POST['new_password'] == $_POST['repeated_password']){
463       /* Check if user is allowed to set password */
464       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
465       $acl= get_module_permission($acl, "terminal", $this->dn);
466       if (chkacl($acl, "password") != ""){
467         print_red (_("You are not allowed to set this systems password!"));
468       } else {
469         $ldap= $this->config->get_ldap_link();
470         $ldap->cd($this->dn);
472         $attrs= array();
473         if ($_POST['new_password'] == ""){
474           $attrs['gotoRootPasswd']= array();
475         } else {
476           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
477               substr(session_id(),0,2));
478         }
479         $ldap->modify($attrs);
480         gosa_log ("Password for '".$this->dn."' has been changed");
481       }
482       unset($_SESSION['objectinfo']);
483     }
486     /********************
487       Delete system cancel
488      ********************/
490     /* Delete terminal canceled? */
491     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
492       del_lock ($this->dn);
493       unset($_SESSION['objectinfo']);
494     }
497     /********************
498       Delete system, confirm dialog
499      ********************/
501     /* Remove terminal was requested */
502     if ($s_action=="del"){
504       /* Get 'dn' from posted termlinst */
505       $this->dn= $this->terminals[$s_entry]['dn'];
507       /* Load permissions for selected 'dn' and check if
508          we're allowed to remove this 'dn' */
509       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
510       $this->acl= get_module_permission($acl, "terminal", $this->dn);
511       if (chkacl($this->acl, "delete") == ""){
513         /* Check locking, save current plugin in 'back_plugin', so
514            the dialog knows where to return. */
515         if (($user= get_lock($this->dn)) != ""){
516           return(gen_locked_message ($user, $this->dn));
517         }
519         /* Lock the current entry, so nobody will edit it during deletion */
520         add_lock ($this->dn, $this->ui->dn);
521         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), LDAP::fix($this->dn)));
522         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
523       } else {
525         /* Obviously the user isn't allowed to delete. Show message and
526            clean session. */
527         print_red (_("You are not allowed to delete this component!"));
528       }
529     }
531   
532     /********************
533       Delete system, confirmed
534      ********************/
535     /* Confirmation for deletion has been passed. Terminal should be deleted. */
536     if (isset($_POST['delete_terminal_confirm'])){
538       /* Some nice guy may send this as POST, so we've to check
539          for the permissions again. */
540       if (chkacl($this->acl, "delete") == ""){
542         /* Find out more about the object type */
543         $ldap= $this->config->get_ldap_link();
544         $ldap->cat($this->dn);
545         $attrs= $ldap->fetch();
546         $type= $this->get_system_type($attrs['objectClass']);
548         switch ($type){
549           case "terminal":
550             $tabtype  = "termtabs";
551             $tabobj   = "TERMTABS";
552           break;
554           case "workstation":
555             $tabtype  = "worktabs";
556             $tabobj   = "WORKTABS";
557           break;
559           case "phone":
560             $tabtype  = "phonetabs";
561             $tabobj   = "PHONETABS";
562           break;
564           case "server":
565             $tabtype  = "servtabs";
566             $tabobj   = "SERVTABS";
567           break;
569           default:
570             $tabtype  = "termtabs";
571             $tabobj   = "TERMTABS";
572           break;
573         }
575         /* Delete request is permitted, perform LDAP action */
576         if($tabtype=="phonetabs"){
577           $this->systab= new $tabtype($this->config,
578              $this->config->data['TABS'][$tabobj], $this->dn);
579           $this->systab->set_acl(array($this->acl));
580           $this->systab->by_object['phonegeneric']->remove_from_parent ();
581         }else{  
582           $this->systab= new $tabtype($this->config,
583              $this->config->data['TABS'][$tabobj], $this->dn);
584           $this->systab->set_acl(array($this->acl));
585           $this->systab->delete();
586           #$this->systab->by_object['termgeneric']->remove_from_parent ();
587         }
588         unset ($this->systab);
589         gosa_log ("System object'".$this->dn."' has been removed");
590         $this->systab= NULL;
592         /* Terminal list has changed, reload it. */
593         $this->reload ();
594       } else {
596         /* Normally this shouldn't be reached, send some extra
597            logs to notify the administrator */
598         print_red (_("You are not allowed to delete this component!"));
599         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
600             "deletion.");
601       }
603       /* Remove lock file after successfull deletion */
604       del_lock ($this->dn);
605     }
608     /********************
609       Edit system type finished, check if everything went ok 
610      ********************/
611     /* Finish user edit is triggered by the tabulator dialog, so
612        the user wants to save edited data. Check and save at this
613        point. */
614     if (isset($_POST['edit_finish'])){
616       /* Check tabs, will feed message array */
617       $message= $this->systab->check();
619       /* Save, or display error message? */
620       if (count($message) == 0){
622         /* Save terminal data to ldap */
623         gosa_log ("System object'".$this->dn."' has been saved");
624         $this->systab->save();
626         /* Terminal has been saved successfully, remove lock from
627            LDAP. */
629         /* 09.02.2006 Hickert 
630          * New System incoming behavior; you can select a system type and an ogroup membership. 
631          * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
632          * Check if we must add the new object to an object group.
633          * !! Don't forget to unset the $_SESSION['SelectedSystemType']... else all edited objects 
634          * !! will be added to  the object group.
635          * 
636          * If this is done, delete the old incoming entry... it is still there, because this is a new 
637          * entry and not an edited one.
638          */
639         if(isset($_SESSION['SelectedSystemType'])){
640           $SelectedSystemType= $_SESSION['SelectedSystemType'];
641           unset($_SESSION['SelectedSystemType']);
642           if($SelectedSystemType['ogroup'] != "none"){
643             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
644             if($og){
645               $og->AddDelMembership($this->systab->dn);
646             }
647             $og->save();
648           }
649           if(!isset($ldap)){
650             $ldap = $this->config->get_ldap_link();
651           }
652           $ldap->cd ($this->dn);
653           $ldap->cat($this->dn);  
654           if(count($ldap->fetch())){
655             $ldap->cd($this->dn);
656             $ldap->rmDir($this->dn);
657           }
658           $ldap->cd($this->config->current['BASE']);
659         }
661         if ($this->dn != "new"){
662           del_lock ($this->dn);
663         }
665         /* There's no page reload so we have to read new terminals at
666            this point. */
667         $this->reload ();
668         unset ($this->systab);
669         $this->systab= NULL;
670         unset($_SESSION['objectinfo']);
672       } else {
673         /* Ok. There seem to be errors regarding to the tab data,
674            show message and continue as usual. */
675         show_errors($message);
676       }
678     }
681     /********************
682       Edit system was canceled 
683      ********************/
684     /* Cancel dialogs */
685     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
686       if (isset($this->systab)){
687         del_lock ($this->systab->dn);
688         unset ($this->systab);
689       }
690       $this->systab= NULL;
691       unset($_SESSION['objectinfo']);
693       /* 09.02.2006 ; New incoming handling ; hickert 
694        * remove session object which stores our ogroup selection 
695        * for the new incoming handling
696        */
697       if(isset($_SESSION['SelectedSystemType'])){
698         unset($_SESSION['SelectedSystemType']);
699       }
700     }
703     /********************
704       Display edit dialog, or some other  
705      ********************/
707     /* Show tab dialog if object is present */
708     if ($this->systab){
709       $display= $this->systab->execute();
711       
712       /* Don't show buttons if tab dialog requests this */
713       if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
714         $display.= "<p style=\"text-align:right\">\n";
715         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
716         $display.= "&nbsp;\n";
717         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
718         $display.= "</p>";
719       }
720       return ($display);
721     }
724     /********************
725       Entry handling finished (edit delete ... )
726       Now the list generation is the next part of this script.
727      ********************/
728     
729     /* Prepare departments, 
730        which are shown in the listbox on top of the listbox 
731      */
732     $options= "";
733     foreach ($this->config->idepartments as $key => $value){
734       if ($terminalfilter['depselect'] == $key){
735         $options.= "<option selected='selected' value='$key'>$value</option>";
736       } else {
737         $options.= "<option value='$key'>$value</option>";
738       }
739     }
742     /* NEW LIST MANAGMENT */
744     /* Create list header
745      */
746     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
747     " <input class='center' type='image' align='middle' src='images/list_back.png' 
748         title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
749     " <input class='center' type='image' src='images/list_root.png' align='middle' 
750         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
751     " <input class='center' type='image' align='middle' src='images/list_home.png' 
752         title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
753     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
754     " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'   
755         name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
756     " <input class='center' type='image' align='middle' src='images/select_new_workstation.png' 
757         name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
758     " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."' 
759         title='"._("New Server")."'>".
760     " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."' 
761         title='"._("New Printer")."'>".
762     " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."' 
763         title='"._("New Phone")."'>".
764     " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."' 
765         title='"._("New Component")."'>".
766     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;".
767     " <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
768     " <input class='center' type='image' src='images/list_submit.png' align='middle' 
769         title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
770     "</div>";
773     /* Edit delete link for system types 
774      */
775     $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
776     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
777     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
779     /* Create new divlist, and add the header elements 
780      */
781     $divlist = new divlist("systemstab");
782     $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
783     $divlist->SetEntriesPerPage(0);
784     $divlist->SetHeader(array(
785           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
786           array("string" => _("System")." / "._("Department"), "attach" => "style=''"),
787           array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
790     /* Add departments, to be able to switch into them
791      */
792     foreach($this->departments as $key=> $val){
793       
794       /* Add missing entries ... */
795       if(!isset($this->config->departments[trim($key)])){
796         $this->config->departments[trim($key)]="";
797       }
799       /* check if this department contains sub-departments 
800          Display different image in this case 
801        */ 
802       $non_empty="";
803       $keys= str_replace("/","\/",$key);
804       foreach($this->config->departments as $keyd=>$vald ){
805         if(preg_match("/".$keys."\/.*/",$keyd)){
806           $non_empty="full";
807         }
808       }
810       /* Add to divlist */
811       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
812       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
813       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
814       $divlist->AddEntry(array($field1,$field2,$field3));
815     }
817     // Iamge spacer 
818     $empty    ="&nbsp;";
820     // User and Template  Images
821     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
823     // Pictures for Extensions
824     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
825     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
826     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
827     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
828     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
829     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
830     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
831     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
832     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
833     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
835     // Test Every Entry and generate divlist Array
836     foreach($this->terminals as $key => $val){
837       // Specify Pics for Extensions
838       if(in_array("goLdapServer"    ,$val['objectClass'])){
839         
840       }
842       /* Generate picture list, which is currently disabled */     
843       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
844       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
845       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
846       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
847       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
848       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
849       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
850       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
851       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
852       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
853       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
854       $pics = "";
855     
856       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
858       // Generate Array to Add
859       if((isset($val['is_new']))&&(!empty($val['is_new']))){
860         $display= "".$val["cn"][0]." ".$val['is_new'];
861       }else{
862         $display= "".$val["cn"][0]."";
863       }
865       if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
866         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
867       }else{
868         $action2 = "";
869       }
871       if(isset($val['message'])){
872         $display.= "  (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."'  )";
873       }
875       $img=$this->convert_list($val);
877       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
878       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
879       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
880       $divlist->AddEntry( array($field1,$field2,$field3));
881     }
883     /* Show main page */
884     $smarty->assign("terminalshead", $listhead);
885     $smarty->assign("terminals", $divlist->DrawList());
886     $smarty->assign("search_image", get_template_path('images/search.png'));
887     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
888     $smarty->assign("tree_image", get_template_path('images/tree.png'));
889     $smarty->assign("infoimage", get_template_path('images/info.png'));
890     $smarty->assign("launchimage", get_template_path('images/launch.png'));
891     foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
892           "winstations", "printers", "phones", "netdev") as $type){
894       $smarty->assign("$type", $terminalfilter[$type]);
895     }
896     $smarty->assign("deplist", $this->config->idepartments);
898     /* Extend if we are not using javascript */
899     $smarty->assign("apply", apply_filter());
900     $smarty->assign("alphabet", generate_alphabet());
901     $smarty->assign("hint", print_sizelimit_warning());
903     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
904   }
907   function convert_list($input)
908   {
909     $temp= "";
910     $conv= array(       
911         "NQ" => array("select_newsystem.png",_("New System from incoming")),
912         "D" => array("select_default.png",_("Template")),
913         "T" => array("select_terminal.png",_("Terminal")),
914         "L" => array("select_workstation.png",_("Workstation")),
915         "F" => array("select_phone.png",_("Phone")),
916         "S" => array("select_server.png",_("Server")),
917         "W" => array("select_winstation.png",_("Winstation")),
918         "C" => array("select_component.png",_("Network Device")),
919         "NT"=> array("select_new_terminal.png",_("New Terminal")),
920         "NL"=> array("select_new_workstation.png",_("New Workstation")),
921         "P" => array("select_printer.png",_("Printer")));
923    if((isset($input['is_new']))&&(!empty($input['is_new']))){
924      $input['type']="N".$input['type'];
925    }
926    foreach ($conv  as $key => $value){
927       if($input['type']==$key){
928         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
929         $tmp['class']=$key;
930         return $tmp;
931       }
932     }
933   }
935   function remove_from_parent()
936   {
937     /* Optionally execute a command after we're done */
938     $this->postremove();
939   }
942   /* Save data to object */
943   function save_object()
944   {
945   }
948   /* Check values */
949   function check()
950   {
951   }
954   /* Save to LDAP */
955   function save()
956   {
957   }
959   function adapt_from_template($dn)
960   {
961   }
963   function password_change_needed()
964   {
965   }
967   function show_header($button_text, $text, $disabled= FALSE)
968   {
969   }
971   function reload()
972   {
973     /* Load terminal shortcuts */
974     $responsible= array();
975     foreach ($this->config->departments as $key => $value){
976       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
977             "terminal", $value) == "#all#"){
978         $responsible[$key]= $value;
979       }
980     }
982     /* Get config */
983     $terminalfilter= get_global('terminalfilter');
984     $filter= "";
986     /* Set base for all searches */
987     $base= $terminalfilter['depselect'];
989     /* Regex filter? */
990     if ($terminalfilter['regex'] != ""){
991       $regex= $terminalfilter['regex'];
992     } else {
993       $regex= "*";
994     }
996     /* Get list of terminals to be shown */
997     if ($terminalfilter['thins'] == "checked"){
998       $termfilter= "(&(objectClass=goHard)(cn=$regex))";
999     } else {
1000       $termfilter= "";
1001     }
1002     if ($terminalfilter['workstations'] == "checked"){
1003       $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
1004     } else {
1005       $workfilter= "";
1006     }
1007     if ($terminalfilter['winstations'] == "checked"){
1008       if ($this->config->current['SAMBAVERSION'] == "3"){
1009         $samba= "sambaSamAccount";
1010       } else {
1011         $samba= "sambaAccount";
1012       }
1013       $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
1014     } else {
1015       $winfilter= "";
1016     }
1017     if ($terminalfilter['printers'] == "checked"){
1018       $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
1019     } else {
1020       $printfilter= "";
1021     }
1022     if ($terminalfilter['phones'] == "checked"){
1023       $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
1024     } else {
1025       $phonefilter= "";
1026     }
1027     if ($terminalfilter['netdev'] == "checked"){
1028       $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
1029     } else {
1030       $netfilter= "";
1031     }
1032     if ($terminalfilter['servers'] == "checked"){
1033       $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
1034     } else {
1035       $serverfilter= "";
1036     }
1038     /* User filter? */
1039     if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
1040       $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
1041     }
1043     /* Get all gotoTerminal's */
1044     $this->terminals= array();
1046     $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base, 
1047         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
1049     $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base, 
1050         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1052     $res= array_merge($res,
1053           get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base, 
1054         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1056     $res= array_merge($res,
1057           get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base, 
1058         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1060     $res= array_merge($res,
1061           get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base, 
1062         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1064     $res= array_merge($res,
1065           get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base, 
1066         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1068     $res= array_merge($res,
1069           get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,ou=systems,".$base, 
1070         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1072     $res= array_merge($res,
1073           get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base, 
1074         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1076 /* NEW LIST MANAGMENT
1077      * We also need to search for the departments
1078      * So we are able to navigate like in konquerer
1079      */
1081     $peopleOU = get_people_ou();
1083     if(empty($peopleOU)){
1084       $base2 = $base;
1085     }else{
1086       $base2 = preg_replace("/".$peopleOU."/i","",$base);
1087     }
1090     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1091                               TRUE, $base2, array("ou", "description"), TRUE);
1093     $this->departments= array();
1094     $tmp = array();
1095     foreach ($res3 as $value){
1096       $tmp[strtolower($value['dn']).$value['dn']]=$value;
1097     }
1098     ksort($tmp);
1099     foreach($tmp as $value){
1100       if(isset($value["description"][0])){
1101         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1102       }else{
1103         $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
1104       }
1105     }
1107     /* END NEW LIST MANAGMENT
1108      */
1111     foreach ($res as $value){
1113       /* Look for new terminals and mark them with '+' */
1114       $tmp= "";
1115       if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
1116         $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
1117       }
1118       if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
1119         $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
1120       }
1121       if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
1122         $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
1123       }
1124       if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
1125         $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
1126       }
1127       if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
1128         $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
1129       }
1130       if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
1131         $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
1132       }
1133       if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
1134         $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
1135       }
1136       if ($tmp == ""){
1137         $tmp= $value["dn"];
1138       }
1139       if (preg_match ("/,ou=incoming,/i", $tmp)){
1140          if (in_array('gotoTerminal', $value['objectClass'])){
1141           $add= "- "._("New terminal");
1142         }elseif (in_array('gotoWorkstation', $value['objectClass'])){
1143           $add= "- "._("New workstation");
1144         }elseif (in_array('GOhard', $value['objectClass'])){
1145           $add= "- "._("New Device");
1146         }
1147       } else {
1148         $add= "";
1149       }
1151       $terminal = array();
1152   
1153       if (in_array ($tmp, $responsible) || $add != ""){
1154         if (in_array('gotoTerminal', $value["objectClass"])){
1155           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1156             $terminal             = $value;
1157             $terminal['type']     = "T";
1158             $terminal['is_new']   = $add;
1159           } else {
1160             $terminal             = $value;
1161             $terminal['type']     = "D";
1162             $terminal['message']  = _("Terminal template for");
1163             $terminal['location'] = array_search($tmp, $this->config->departments); 
1164           }
1165         } elseif (in_array('gotoWorkstation', $value["objectClass"])){
1166           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1167             $terminal             = $value;
1168             $terminal['type']     = "L";
1169             $terminal['is_new']   = $add;
1170           } else {
1171             $terminal             = $value;
1172             $terminal['type']     = "D";
1173             $terminal['location'] = array_search($tmp, $this->config->departments);
1174             $terminal['message']  = _("Workstation template for");
1175           }
1176         }elseif (in_array("GOhard",$value['objectClass'])){
1177           $terminal = $value;
1178           $terminal['type']   = "Q";
1179           $terminal['is_new'] = $add;
1180         } elseif (in_array('gotoPrinter', $value["objectClass"])){
1181             $terminal             = $value;
1182             $terminal['type']     = "P";
1183         } elseif (in_array('goServer', $value["objectClass"])){
1184             $terminal             = $value;
1185             $terminal['type']     = "S";
1186         } elseif (in_array('goFonHardware', $value["objectClass"])){
1187             $terminal             = $value;
1188             $terminal['type']     = "F";
1189         } elseif (in_array('ieee802Device', $value["objectClass"])){
1190             $terminal             = $value;
1191             $terminal['type']     = "C";
1192         } else{
1193           $name= preg_replace('/\$$/', '', $value['cn'][0]);
1194           if (isset($value['sambaDomainName'])){
1195             $domain= " [".$value['sambaDomainName'][0]."]";
1196           } else {
1197             $domain= "";
1198           }
1199           $terminal=$value;
1200           $terminal['type']     ="W";
1201           $terminal['domain']   = $name.$domain;
1202         }
1203         $this->terminals[]=$terminal;
1204       }
1205     }
1207     $tmp=array();
1208     foreach($this->terminals as $tkey => $val ){
1209       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1210     }
1211     ksort($tmp);
1212     $this->terminals=array();
1213     foreach($tmp as $val){
1214       $this->terminals[]=$val;
1215     }
1216     reset ($this->terminals);
1217   }
1219   function remove_lock()
1220   {
1221     if (isset($this->systab->dn)){
1222       del_lock ($this->systab->dn);
1223     }
1224   }
1227   function get_system_type($classes)
1228   {
1229     $type= "";
1231     if (in_array('ieee802Device', $classes)){
1232       $type= "component";
1233     }else
1234     if (in_array('gotoTerminal', $classes)){
1235       $type= "terminal";
1236     }else
1237     if (in_array('gotoWorkstation', $classes)){
1238       $type= "workstation";
1239     }else
1240     if (in_array('gotoPrinter', $classes)){
1241       $type= "printer";
1242     }else
1243     if (in_array('goFonHardware', $classes)){
1244       $type= "phone";
1245     }else
1246     if (in_array('goServer', $classes)){
1247       $type= "server";
1248     }else
1249     if (in_array('GOhard', $classes)){
1250       $type= "NewDevice";
1251     }else
1252     if (in_array('sambaAccount', $classes) ||
1253         in_array('sambaSamAccount', $classes)){
1254       $type= "winstation";
1255     }
1257     return ($type);
1258   }
1262 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1263 ?>