Code

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