Code

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