Code

Added copy & paste for ogroups
[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' align='middle' src='images/list_back.png' 
753         title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
754     " <input class='center' type='image' src='images/list_root.png' align='middle' 
755         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&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     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
759     " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'   
760         name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
761     " <input class='center' type='image' align='middle' src='images/select_new_workstation.png' 
762         name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
763     " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."' 
764         title='"._("New Server")."'>".
765     " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."' 
766         title='"._("New Printer")."'>".
767     " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."' 
768         title='"._("New Phone")."'>".
769     " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."' 
770         title='"._("New Component")."'>".
771     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;".
772     " <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
773     " <input class='center' type='image' src='images/list_submit.png' align='middle' 
774         title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
775     "</div>";
778     /* Edit delete link for system types 
779      */
780     $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
781     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
782     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
784     /* Create new divlist, and add the header elements 
785      */
786     $divlist = new divlist("systemstab");
787     $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
788     $divlist->SetEntriesPerPage(0);
789     $divlist->SetHeader(array(
790           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
791           array("string" => _("System")." / "._("Department"), "attach" => "style=''"),
792           array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
795     /* Add departments, to be able to switch into them
796      */
797     foreach($this->departments as $key=> $val){
798       
799       /* Add missing entries ... */
800       if(!isset($this->config->departments[trim($key)])){
801         $this->config->departments[trim($key)]="";
802       }
804       /* check if this department contains sub-departments 
805          Display different image in this case 
806        */ 
807       $non_empty="";
808       $keys= str_replace("/","\/",$key);
809       foreach($this->config->departments as $keyd=>$vald ){
810         if(preg_match("/".$keys."\/.*/",$keyd)){
811           $non_empty="full";
812         }
813       }
815       /* Add to divlist */
816       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
817       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
818       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
819       $divlist->AddEntry(array($field1,$field2,$field3));
820     }
822     // Iamge spacer 
823     $empty    ="&nbsp;";
825     // User and Template  Images
826     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
828     // Pictures for Extensions
829     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
830     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
831     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
832     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
833     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
834     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
835     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
836     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
837     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
838     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
840     // Test Every Entry and generate divlist Array
841     foreach($this->terminals as $key => $val){
842       // Specify Pics for Extensions
843       if(in_array("goLdapServer"    ,$val['objectClass'])){
844         
845       }
847       /* Generate picture list, which is currently disabled */     
848       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
849       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
850       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
851       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
852       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
853       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
854       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
855       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
856       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
857       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
858       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
859       $pics = "";
860     
861       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
863       // Generate Array to Add
864       if((isset($val['is_new']))&&(!empty($val['is_new']))){
865         $display= "".$val["cn"][0]." ".$val['is_new'];
866       }else{
867         $display= "".$val["cn"][0]."";
868       }
870       if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
871         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
872       }else{
873         $action2 = "";
874       }
876       if(isset($val['message'])){
877         $display.= "  (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."'  )";
878       }
880       $img=$this->convert_list($val);
882       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
883       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
884       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
885       $divlist->AddEntry( array($field1,$field2,$field3));
886     }
888     /* Show main page */
889     $smarty->assign("terminalshead", $listhead);
890     $smarty->assign("terminals", $divlist->DrawList());
891     $smarty->assign("search_image", get_template_path('images/search.png'));
892     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
893     $smarty->assign("tree_image", get_template_path('images/tree.png'));
894     $smarty->assign("infoimage", get_template_path('images/info.png'));
895     $smarty->assign("launchimage", get_template_path('images/launch.png'));
896     foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
897           "winstations", "printers", "phones", "netdev") as $type){
899       $smarty->assign("$type", $terminalfilter[$type]);
900     }
901     $smarty->assign("deplist", $this->config->idepartments);
903     /* Extend if we are not using javascript */
904     $smarty->assign("apply", apply_filter());
905     $smarty->assign("alphabet", generate_alphabet());
906     $smarty->assign("hint", print_sizelimit_warning());
908     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
909   }
912   function convert_list($input)
913   {
914     $temp= "";
915     $conv= array(       
916         "NQ" => array("select_newsystem.png",_("New System from incoming")),
917         "D" => array("select_default.png",_("Template")),
918         "T" => array("select_terminal.png",_("Terminal")),
919         "L" => array("select_workstation.png",_("Workstation")),
920         "F" => array("select_phone.png",_("Phone")),
921         "S" => array("select_server.png",_("Server")),
922         "W" => array("select_winstation.png",_("Winstation")),
923         "C" => array("select_component.png",_("Network Device")),
924         "NT"=> array("select_new_terminal.png",_("New Terminal")),
925         "NL"=> array("select_new_workstation.png",_("New Workstation")),
926         "P" => array("select_printer.png",_("Printer")));
928    if((isset($input['is_new']))&&(!empty($input['is_new']))){
929      $input['type']="N".$input['type'];
930    }
931    foreach ($conv  as $key => $value){
932       if($input['type']==$key){
933         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
934         $tmp['class']=$key;
935         return $tmp;
936       }
937     }
938   }
940   function remove_from_parent()
941   {
942     /* Optionally execute a command after we're done */
943     $this->postremove();
944   }
947   /* Save data to object */
948   function save_object()
949   {
950   }
953   /* Check values */
954   function check()
955   {
956   }
959   /* Save to LDAP */
960   function save()
961   {
962   }
964   function adapt_from_template($dn)
965   {
966   }
968   function password_change_needed()
969   {
970   }
972   function show_header($button_text, $text, $disabled= FALSE)
973   {
974   }
976   function reload()
977   {
978     /* Load terminal shortcuts */
979     $responsible= array();
980     foreach ($this->config->departments as $key => $value){
981       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
982             "terminal", $value) == "#all#"){
983         $responsible[$key]= $value;
984       }
985     }
987     /* Get config */
988     $terminalfilter= get_global('terminalfilter');
989     $filter= "";
991     /* Set base for all searches */
992     $base= $terminalfilter['depselect'];
994     /* Regex filter? */
995     if ($terminalfilter['regex'] != ""){
996       $regex= $terminalfilter['regex'];
997     } else {
998       $regex= "*";
999     }
1001     /* Get list of terminals to be shown */
1002     if ($terminalfilter['thins'] == "checked"){
1003       $termfilter= "(&(objectClass=goHard)(cn=$regex))";
1004     } else {
1005       $termfilter= "";
1006     }
1007     if ($terminalfilter['workstations'] == "checked"){
1008       $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
1009     } else {
1010       $workfilter= "";
1011     }
1012     if ($terminalfilter['winstations'] == "checked"){
1013       if ($this->config->current['SAMBAVERSION'] == "3"){
1014         $samba= "sambaSamAccount";
1015       } else {
1016         $samba= "sambaAccount";
1017       }
1018       $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
1019     } else {
1020       $winfilter= "";
1021     }
1022     if ($terminalfilter['printers'] == "checked"){
1023       $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
1024     } else {
1025       $printfilter= "";
1026     }
1027     if ($terminalfilter['phones'] == "checked"){
1028       $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
1029     } else {
1030       $phonefilter= "";
1031     }
1032     if ($terminalfilter['netdev'] == "checked"){
1033       $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
1034     } else {
1035       $netfilter= "";
1036     }
1037     if ($terminalfilter['servers'] == "checked"){
1038       $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
1039     } else {
1040       $serverfilter= "";
1041     }
1043     /* User filter? */
1044     if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
1045       $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
1046     }
1048     /* Get all gotoTerminal's */
1049     $this->terminals= array();
1051     $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base, 
1052         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
1054     $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base, 
1055         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1057     $res= array_merge($res,
1058           get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base, 
1059         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1061     $res= array_merge($res,
1062           get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base, 
1063         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1065     $res= array_merge($res,
1066           get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base, 
1067         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1069     $res= array_merge($res,
1070           get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base, 
1071         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1073     $res= array_merge($res,
1074           get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,ou=systems,".$base, 
1075         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1077     $res= array_merge($res,
1078           get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base, 
1079         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
1081 /* NEW LIST MANAGMENT
1082      * We also need to search for the departments
1083      * So we are able to navigate like in konquerer
1084      */
1086     $peopleOU = get_people_ou();
1088     if(empty($peopleOU)){
1089       $base2 = $base;
1090     }else{
1091       $base2 = preg_replace("/".$peopleOU."/i","",$base);
1092     }
1095     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1096                               TRUE, $base2, array("ou", "description"), TRUE);
1098     $this->departments= array();
1099     $tmp = array();
1100     foreach ($res3 as $value){
1101       $tmp[strtolower($value['dn']).$value['dn']]=$value;
1102     }
1103     ksort($tmp);
1104     foreach($tmp as $value){
1105       if(isset($value["description"][0])){
1106         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1107       }else{
1108         $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
1109       }
1110     }
1112     /* END NEW LIST MANAGMENT
1113      */
1116     foreach ($res as $value){
1118       /* Look for new terminals and mark them with '+' */
1119       $tmp= "";
1120       if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
1121         $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
1122       }
1123       if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
1124         $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
1125       }
1126       if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
1127         $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
1128       }
1129       if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
1130         $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
1131       }
1132       if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
1133         $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
1134       }
1135       if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
1136         $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
1137       }
1138       if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
1139         $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
1140       }
1141       if ($tmp == ""){
1142         $tmp= $value["dn"];
1143       }
1144       if (preg_match ("/,ou=incoming,/i", $tmp)){
1145          if (in_array('gotoTerminal', $value['objectClass'])){
1146           $add= "- "._("New terminal");
1147         }elseif (in_array('gotoWorkstation', $value['objectClass'])){
1148           $add= "- "._("New workstation");
1149         }elseif (in_array('GOhard', $value['objectClass'])){
1150           $add= "- "._("New Device");
1151         }
1152       } else {
1153         $add= "";
1154       }
1156       $terminal = array();
1157   
1158       if (in_array ($tmp, $responsible) || $add != ""){
1159         if (in_array('gotoTerminal', $value["objectClass"])){
1160           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1161             $terminal             = $value;
1162             $terminal['type']     = "T";
1163             $terminal['is_new']   = $add;
1164           } else {
1165             $terminal             = $value;
1166             $terminal['type']     = "D";
1167             $terminal['message']  = _("Terminal template for");
1168             $terminal['location'] = array_search($tmp, $this->config->departments); 
1169           }
1170         } elseif (in_array('gotoWorkstation', $value["objectClass"])){
1171           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1172             $terminal             = $value;
1173             $terminal['type']     = "L";
1174             $terminal['is_new']   = $add;
1175           } else {
1176             $terminal             = $value;
1177             $terminal['type']     = "D";
1178             $terminal['location'] = array_search($tmp, $this->config->departments);
1179             $terminal['message']  = _("Workstation template for");
1180           }
1181         } elseif (in_array('gotoPrinter', $value["objectClass"])){
1182             $terminal             = $value;
1183             $terminal['type']     = "P";
1184         } elseif (in_array('goServer', $value["objectClass"])){
1185             $terminal             = $value;
1186             $terminal['type']     = "S";
1187         } elseif (in_array('goFonHardware', $value["objectClass"])){
1188             $terminal             = $value;
1189             $terminal['type']     = "F";
1190         }elseif (in_array("GOhard",$value['objectClass'])){
1191           $terminal = $value;
1192           $terminal['type']   = "Q";
1193           $terminal['is_new'] = $add;
1194         } elseif (in_array('ieee802Device', $value["objectClass"])){
1195             $terminal             = $value;
1196             $terminal['type']     = "C";
1197         } else{
1198           $name= preg_replace('/\$$/', '', $value['cn'][0]);
1199           if (isset($value['sambaDomainName'])){
1200             $domain= " [".$value['sambaDomainName'][0]."]";
1201           } else {
1202             $domain= "";
1203           }
1204           $terminal=$value;
1205           $terminal['type']     ="W";
1206           $terminal['domain']   = $name.$domain;
1207         }
1208         $this->terminals[]=$terminal;
1209       }
1210     }
1212     $tmp=array();
1213     foreach($this->terminals as $tkey => $val ){
1214       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1215     }
1216     ksort($tmp);
1217     $this->terminals=array();
1218     foreach($tmp as $val){
1219       $this->terminals[]=$val;
1220     }
1221     reset ($this->terminals);
1222   }
1224   function remove_lock()
1225   {
1226     if (isset($this->systab->dn)){
1227       del_lock ($this->systab->dn);
1228     }
1229   }
1232   function get_system_type($classes)
1233   {
1234     $type= "";
1236     if (in_array('ieee802Device', $classes)){
1237       $type= "component";
1238     }else
1239     if (in_array('gotoTerminal', $classes)){
1240       $type= "terminal";
1241     }else
1242     if (in_array('gotoWorkstation', $classes)){
1243       $type= "workstation";
1244     }else
1245     if (in_array('gotoPrinter', $classes)){
1246       $type= "printer";
1247     }else
1248     if (in_array('goFonHardware', $classes)){
1249       $type= "phone";
1250     }else
1251     if (in_array('goServer', $classes)){
1252       $type= "server";
1253     }else
1254     if (in_array('GOhard', $classes)){
1255       $type= "NewDevice";
1256     }else
1257     if (in_array('sambaAccount', $classes) ||
1258         in_array('sambaSamAccount', $classes)){
1259       $type= "winstation";
1260     }
1262     return ($type);
1263   }
1267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1268 ?>