Code

Fixed headpage
[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     /* Save data */
72     $terminalfilter= get_global("terminalfilter");
73     foreach( array("depselect", "user", "regex") as $type){
74       if (isset($_POST[$type])){
75         $terminalfilter[$type]= $_POST[$type];
76       }
77     }
78     if (isset($_POST['depselect'])){
79       foreach( array("workstations", "thins", "winstations", "printers", "phones", "servers", "netdev") as $type){
81         if (isset($_POST[$type])) {
82           $terminalfilter[$type]= "checked";
83         } else {
84           $terminalfilter[$type]= "";
85         }
86       }
87     }
88     if (isset($_GET['search'])){
89       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
90       if ($s == "**"){
91         $s= "*";
92       }
93       $terminalfilter['regex']= $s;
94     }
96     $s_action     = "";                       // Contains the action to proceed
97     $s_entry      = "";                       // The value for s_action
98     $base_back    = "";                       // The Link for Backbutton
99     $smarty       = get_smarty();
101     /* Start for New List Managment */
102     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
103             $s_action="open";
104             $s_entry = base64_decode($_GET['dep_id']);
105             $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
106             $this->reload();
107     }
109     /* Test Posts */
110     foreach($_POST as $key => $val){
111       // Post for delete
112       if(preg_match("/user_del.*/",$key)){
113         $s_action = "del";
114         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
115         // Post for edit
116       }elseif(preg_match("/user_edit_.*/",$key)){
117         $s_action="edit";
118         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
119         // Post for new
120       }elseif(preg_match("/dep_back.*/i",$key)){
121         $s_action="back";
122       }elseif(preg_match("/user_new.*/",$key)){
123         $s_action="new";
124       }elseif(preg_match("/dep_home.*/i",$key)){
125         $s_action="home";
126       }elseif(preg_match("/user_tplnew.*/i",$key)){
127         $s_action="new_tpl";
128       }elseif(preg_match("/user_setpwd_.*/i",$key)){
129         $s_action="change_pw";
130         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
131       }elseif(preg_match("/dep_root.*/i",$key)){
132         $s_action="root";
133       }elseif(preg_match("/newsystem_.*/i",$key)){
134         $s_action="newsystem";
135         $s_entry  = preg_replace("/newsystem_/i","",$key);
136       }
137     }
139      if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
140       $s_action ="edit";
141       $s_entry  = $_GET['id'];
142     }
144     $s_entry  = preg_replace("/_.$/","",$s_entry);
146     /* Department changed? */
147     if(isset($_POST['depselect']) && $_POST['depselect']){
148       $terminalfilter['depselect']= $_POST['depselect'];
149     }
151     /* Homebutton is posted */
152     if($s_action=="home"){
153       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
154       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
155     }
157     if($s_action=="root"){
158       $terminalfilter['depselect']=($this->config->current['BASE']);
159     }
162     /* If Backbutton is Posted */
163     if($s_action=="back"){
164       $base_back          = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
165       $base_back          = convert_department_dn($base_back);
167       if(isset($this->config->departments[trim($base_back)])){
168         $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
169       }else{
170         $terminalfilter['depselect']= $this->config->departments["/"];
171       }
172     }
174     register_global("terminalfilter", $terminalfilter);
175     $this->reload();
177     /* Check for exeeded sizelimit */
178     if (($message= check_sizelimit()) != ""){
179       return($message);
180     }
182     /* Try to get informations about what kind of system to create */
183     if ($s_action=="new") {
184       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
185     }
187     /* Create new default terminal */
188     if (isset($_POST['create_system'])||$s_action=="newsystem") {
189       $this->dn= "new";
190       $this->acl= array(":all");
192       if(isset($_POST['system'])){
193         $sw = $_POST['system'];
194       }else{
195         $sw = $s_entry;
196       }
198       switch ($sw){
199         case 'terminal':
200           $this->systab= new termtabs($this->config,
201               $this->config->data['TABS']['TERMTABS'], $this->dn);
202           $this->systab->set_acl ($this->acl);
203           $this->systab->by_object['termgeneric']->cn= "default";
204           $this->systab->by_object['termservice']->cn= "default";
205           $this->systab->by_object['termgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
206           break;
208         case 'workstation':
209           $this->systab= new worktabs($this->config,
210               $this->config->data['TABS']['WORKTABS'], $this->dn);
211           $this->systab->set_acl ($this->acl);
212           $this->systab->by_object['workgeneric']->cn= "wdefault";
213           $this->systab->by_object['workservice']->cn= "default";
214           $this->systab->by_object['workgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
215           break;
217         case 'server':
218           $this->systab= new servtabs($this->config,
219               $this->config->data['TABS']['SERVTABS'], $this->dn);
220           $this->systab->set_acl ($this->acl);
221           $this->systab->by_object['servgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
222           break;
224         case 'printer':
225           $this->systab= new printtabs($this->config,
226               $this->config->data['TABS']['PRINTTABS'], $this->dn);
227           $this->systab->set_acl ($this->acl);
228           $this->systab->by_object['printgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
229           break;
231         case 'phone':
232           $this->systab= new phonetabs($this->config,
233               $this->config->data['TABS']['PHONETABS'], $this->dn);
234           $this->systab->set_acl ($this->acl);
235           $this->systab->by_object['phonegeneric']->base = $_SESSION['terminalfilter']['depselect'];  
236           break;
238         case 'component':
239           $this->systab= new componenttabs($this->config,
240               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
241           $this->systab->set_acl ($this->acl);
242           $this->systab->by_object['componentgeneric']->base = $_SESSION['terminalfilter']['depselect'];  
243           break;
244       }
245        
246       $this->systab->base = $_SESSION['terminalfilter']['depselect'];  
247     }
250     /* User wants to edit data? */
251     if ($s_action == "edit"){
253       /* Get 'dn' from posted 'cn', must be unique */
254       $this->dn= $this->terminals[$s_entry]['dn'];
256       /* Check locking, save current plugin in 'back_plugin', so
257          the dialog knows where to return. */
258       if (($user= get_lock($this->dn)) != ""){
259         return(gen_locked_message ($user, $this->dn));
260       }
262       /* Set up the users ACL's for this 'dn' */
263       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
265       /* Find out more about the object type */
266       $ldap= $this->config->get_ldap_link();
267       $ldap->cat($this->dn);
268       $attrs= $ldap->fetch();
269       $type= $this->get_system_type($attrs['objectClass']);
271       /* Lock the current entry, so everyone will get the
272          above dialog */
273       add_lock ($this->dn, $this->ui->dn);
275       switch ($type){
276         case "terminal":
277           /* Register systab to trigger edit dialog */
278           $this->systab= new termtabs($this->config,
279               $this->config->data['TABS']['TERMTABS'], $this->dn);
280           $this->systab->set_acl($acl);
281           $_SESSION['objectinfo']= $this->dn;
282           break;
284         case "server":
285           /* Register systab to trigger edit dialog */
286           $this->systab= new servtabs($this->config,
287               $this->config->data['TABS']['SERVTABS'], $this->dn);
288           $this->systab->set_acl($acl);
289           $_SESSION['objectinfo']= $this->dn;
290           break;
292         case "workstation":
293           /* Register systab to trigger edit dialog */
294           $this->systab= new worktabs($this->config,
295               $this->config->data['TABS']['WORKTABS'], $this->dn);
296           $this->systab->set_acl($acl);
297           $_SESSION['objectinfo']= $this->dn;
298           break;
300         case "printer":
301           /* Register systab to trigger edit dialog */
302           $this->systab= new printtabs($this->config,
303               $this->config->data['TABS']['PRINTTABS'], $this->dn);
304           $this->systab->set_acl($acl);
305           $_SESSION['objectinfo']= $this->dn;
306           break;
308         case "phone":
309           /* Register systab to trigger edit dialog */
310           $this->systab= new phonetabs($this->config,
311               $this->config->data['TABS']['PHONETABS'], $this->dn);
312           $this->systab->set_acl($acl);
313           $_SESSION['objectinfo']= $this->dn;
314           break;
316         case "component":
317           /* Register systab to trigger edit dialog */
318           $this->systab= new componenttabs($this->config,
319               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
320           $this->systab->set_acl($acl);
321           $_SESSION['objectinfo']= $this->dn;
322           break;
323        
324         case "winstation":
325           /* Register systab to trigger edit dialog */
326           $this->systab= new wintabs($this->config,
327               $this->config->data['TABS']['WINTABS'], $this->dn);
328           $this->systab->set_acl($acl);
329           $_SESSION['objectinfo']= $this->dn;
330           break;
333         default:
334           print_red (_("You can't edit this object type yet!"));
335           del_lock($this->dn);
336           break;
337       }
338     }
340     /* Set terminals root password */
341     if ($s_action=="change_pw"){
342       $this->dn= $this->terminals[$s_entry]['dn'];
343       $_SESSION['objectinfo']= $this->dn;
344       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
345     }
347     /* Correctly specified? */
348     if (isset($_POST['password_finish'])){
349       if ($_POST['new_password'] != $_POST['repeated_password']){
350         print_red (_("Passwords entered as new and repeated do not match!"));
351         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
352       }
353     }
355     /* Change terminal password */
356     if (isset($_POST['password_finish']) && 
357         $_POST['new_password'] == $_POST['repeated_password']){
359       /* Check if user is allowed to set password */
360       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
361       $acl= get_module_permission($acl, "terminal", $this->dn);
362       if (chkacl($acl, "password") != ""){
363         print_red (_("You are not allowed to set this systems password!"));
364       } else {
365         $ldap= $this->config->get_ldap_link();
366         $ldap->cd($this->dn);
368         $attrs= array();
369         if ($_POST['new_password'] == ""){
370           $attrs['gotoRootPasswd']= array();
371         } else {
372           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
373               substr(session_id(),0,2));
374         }
375         $ldap->modify($attrs);
376         gosa_log ("Password for '".$this->dn."' has been changed");
377       }
378       unset($_SESSION['objectinfo']);
379     }
381     /* Delete terminal canceled? */
382     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
383       del_lock ($this->dn);
384       unset($_SESSION['objectinfo']);
385     }
387     /* Remove terminal was requested */
388     if ($s_action=="del"){
390       /* Get 'dn' from posted termlinst */
391       $this->dn= $this->terminals[$s_entry]['dn'];
393       /* Load permissions for selected 'dn' and check if
394          we're allowed to remove this 'dn' */
395       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
396       $this->acl= get_module_permission($acl, "terminal", $this->dn);
397       if (chkacl($this->acl, "delete") == ""){
399         /* Check locking, save current plugin in 'back_plugin', so
400            the dialog knows where to return. */
401         if (($user= get_lock($this->dn)) != ""){
402           return(gen_locked_message ($user, $this->dn));
403         }
405         /* Lock the current entry, so nobody will edit it during deletion */
406         add_lock ($this->dn, $this->ui->dn);
407         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
408         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
409       } else {
411         /* Obviously the user isn't allowed to delete. Show message and
412            clean session. */
413         print_red (_("You are not allowed to delete this component!"));
414       }
415     }
417     /* Confirmation for deletion has been passed. Terminal should be deleted. */
418     if (isset($_POST['delete_terminal_confirm'])){
420       /* Some nice guy may send this as POST, so we've to check
421          for the permissions again. */
422       if (chkacl($this->acl, "delete") == ""){
424         /* Find out more about the object type */
425         $ldap= $this->config->get_ldap_link();
426         $ldap->cat($this->dn);
427         $attrs= $ldap->fetch();
428         $type= $this->get_system_type($attrs['objectClass']);
430         switch ($type){
431           case "terminal":
432             $tabtype= "termtabs";
433           break;
435           case "workstation":
436             $tabtype= "worktabs";
437           break;
438           
439           case "phone":
440             $tabtype= "phonetabs";
441           break;
443           case "server":
444             $tabtype= "servtabs";
445           break;
447           default:
448 #print_red (_("You can't remove this object type yet!"));
449 #del_lock($this->dn);
450 #return;
451           $tabtype= "termtabs";
452           break;
453         }
455         /* Delete request is permitted, perform LDAP action */
456         if($tabtype=="phonetabs"){
457           $this->systab= new $tabtype($this->config,
458              $this->config->data['TABS']['PHONETABS'], $this->dn);
459           $this->systab->set_acl(array($this->acl));
460           $this->systab->by_object['phonegeneric']->remove_from_parent ();
461         }else{  
462           $this->systab= new $tabtype($this->config,
463              $this->config->data['TABS']['TERMTABS'], $this->dn);
464           $this->systab->set_acl(array($this->acl));
465           $this->systab->delete();
466           #$this->systab->by_object['termgeneric']->remove_from_parent ();
467         }
468         unset ($this->systab);
469         gosa_log ("System object'".$this->dn."' has been removed");
470         $this->systab= NULL;
472         /* Terminal list has changed, reload it. */
473         $this->reload ();
474       } else {
476         /* Normally this shouldn't be reached, send some extra
477            logs to notify the administrator */
478         print_red (_("You are not allowed to delete this component!"));
479         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
480             "deletion.");
481       }
483       /* Remove lock file after successfull deletion */
484       del_lock ($this->dn);
485     }
487     /* Finish user edit is triggered by the tabulator dialog, so
488        the user wants to save edited data. Check and save at this
489        point. */
490     if (isset($_POST['edit_finish'])){
492       /* Check tabs, will feed message array */
493       $message= $this->systab->check();
495       /* Save, or display error message? */
496       if (count($message) == 0){
498         /* Save terminal data to ldap */
499         gosa_log ("System object'".$this->dn."' has been saved");
500         $this->systab->save();
502         /* Terminal has been saved successfully, remove lock from
503            LDAP. */
504         if ($this->dn != "new"){
505           del_lock ($this->dn);
506         }
508         /* There's no page reload so we have to read new terminals at
509            this point. */
510         $this->reload ();
511         unset ($this->systab);
512         $this->systab= NULL;
513         unset($_SESSION['objectinfo']);
515       } else {
516         /* Ok. There seem to be errors regarding to the tab data,
517            show message and continue as usual. */
518         show_errors($message);
519       }
521     }
523     /* Cancel dialogs */
524     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
525       if (isset($this->systab)){
526         del_lock ($this->systab->dn);
527         unset ($this->systab);
528       }
529       $this->systab= NULL;
530       unset($_SESSION['objectinfo']);
531     }
533     /* Show tab dialog if object is present */
534     if ($this->systab){
535       $display= $this->systab->execute();
537       /* Don't show buttons if tab dialog requests this */
538       if (!$this->systab->by_object[$this->systab->current]->dialog){
539         $display.= "<p style=\"text-align:right\">\n";
540         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
541         $display.= "&nbsp;\n";
542         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
543         $display.= "</p>";
544       }
545       return ($display);
546     }
553     /* Prepare departments */
554     $options= "";
555     foreach ($this->config->idepartments as $key => $value){
556             if ($terminalfilter['depselect'] == $key){
557                     $options.= "<option selected='selected' value='$key'>$value</option>";
558             } else {
559                     $options.= "<option value='$key'>$value</option>";
560             }
561     }
564   /* NEW LIST MANAGMENT */
565     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
566     " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
567     " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
568     " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
569     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
570     " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'   name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
571     " <input class='center' type='image' align='middle' src='images/select_new_workstation.png' name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
572     " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."' title='"._("New Server")."'>".
573     " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."' title='"._("New Printer")."'>".
574     " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."' title='"._("New Phone")."'>".
575     " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."' title='"._("New Component")."'>".
576     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
577     _("Base")."&nbsp;<select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
578     " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
579     "</div>";
581     $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
582     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
584     $divlist = new divlist("systemstab");
585     $divlist->SetHeader(array(
586           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
587           array("string" => _("System")." / "._("Department"), "attach" => "style=''"),
588           array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
590     $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
591     $divlist->SetEntriesPerPage(0);
593     // Defining Links
594     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
596     foreach($this->departments as $key=> $val){
598       if(!isset($this->config->departments[trim($key)])){
599         $this->config->departments[trim($key)]="";
600       }
602       $non_empty="";
603       $keys= str_replace("/","\/",$key);
604       foreach($this->config->departments as $keyd=>$vald ){
605         if(preg_match("/".$keys."\/.*/",$keyd)){
606           $non_empty="full";
607         }
608       }
610       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
611       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
612       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
613       $divlist->AddEntry(array($field1,$field2,$field3));
614     }
616     // Space
617     $empty    ="&nbsp;";
619     // User and Template  Images
620     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
622     // Pictures for Extensions
623     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
624     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
625     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
626     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
627     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
628     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
629     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
630     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
631     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
632     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
634     // Test Every Entry and generate divlist Array
635     foreach($this->terminals as $key => $val){
636       // Specify Pics for Extensions
637       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
638       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
639       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
640       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
641       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
642       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
643       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
644       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
645       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
646       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
647   
648       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
649       $pics = "";
650     
651       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
653       // Generate Array to Add
654       if((isset($val['is_new']))&&(!empty($val['is_new']))){
655         $display= "".$val["cn"][0]." ".$val['is_new'];
656       }else{
657         $display= "".$val["cn"][0]."";
658       }
660       if((in_array("gotoTerminal",$val['objectClass']))||(in_array("gotoWorkstation",$val['objectClass']))){
661         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
662       }else{
663         $action2 = "";
664       }
666       if(isset($val['message'])){
667         $display.= "  (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."'  )";
668       }
670       $img=$this->convert_list($val);
672       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
673       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
674       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
675       $divlist->AddEntry( array($field1,$field2,$field3));
676     }
678     /* Show main page */
679     $smarty->assign("terminalshead", $listhead);
680     $smarty->assign("terminals", $divlist->DrawList());
681     $smarty->assign("search_image", get_template_path('images/search.png'));
682     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
683     $smarty->assign("tree_image", get_template_path('images/tree.png'));
684     $smarty->assign("infoimage", get_template_path('images/info.png'));
685     $smarty->assign("launchimage", get_template_path('images/launch.png'));
686     foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
687           "winstations", "printers", "phones", "netdev") as $type){
689       $smarty->assign("$type", $terminalfilter[$type]);
690     }
691     $smarty->assign("deplist", $this->config->idepartments);
693     /* Extend if we are not using javascript */
694     $smarty->assign("apply", apply_filter());
695     $smarty->assign("alphabet", generate_alphabet());
696     $smarty->assign("hint", print_sizelimit_warning());
698     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
699   }
702   function convert_list($input)
703   {
704     $temp= "";
705     $conv= array(       
706         "D" => array("select_default.png",_("Template")),
707         "T" => array("select_terminal.png",_("Terminal")),
708         "L" => array("select_workstation.png",_("Workstation")),
709         "F" => array("select_phone.png",_("Phone")),
710         "S" => array("select_server.png",_("Server")),
711         "NT"=> array("select_new_terminal.png",_("New Terminal")),
712         "NL"=> array("select_new_workstation.png",_("New Workstation")),
713         "W" => array("select_winstation.png",_("Winstation")),
714         "C" => array("select_component.png",_("Network Device")),
715         "P" => array("select_printer.png",_("Printer")));
717    if((isset($input['is_new']))&&(!empty($input['is_new']))){
718      $input['type']="N".$input['type'];
719    }
720    foreach ($conv  as $key => $value){
721       if($input['type']==$key){
722         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
723         $tmp['class']=$key;
724         return $tmp;
725       }
726     }
727   }
729   function remove_from_parent()
730   {
731     /* Optionally execute a command after we're done */
732     $this->postremove();
733   }
736   /* Save data to object */
737   function save_object()
738   {
739   }
742   /* Check values */
743   function check()
744   {
745   }
748   /* Save to LDAP */
749   function save()
750   {
751   }
753   function adapt_from_template($dn)
754   {
755   }
757   function password_change_needed()
758   {
759   }
761   function show_header($button_text, $text, $disabled= FALSE)
762   {
763   }
765   function reload()
766   {
767     /* Load terminal shortcuts */
768     $responsible= array();
769     foreach ($this->config->departments as $key => $value){
770       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
771             "terminal", $value) == "#all#"){
772         $responsible[$key]= $value;
773       }
774     }
776     /* Get config */
777     $terminalfilter= get_global('terminalfilter');
778     $filter= "";
780     /* Set base for all searches */
781     $base= $terminalfilter['depselect'];
783     /* Regex filter? */
784     if ($terminalfilter['regex'] != ""){
785       $regex= $terminalfilter['regex'];
786     } else {
787       $regex= "*";
788     }
790     /* Get list of terminals to be shown */
791     if ($terminalfilter['thins'] == "checked"){
792       $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
793     } else {
794       $termfilter= "";
795     }
796     if ($terminalfilter['workstations'] == "checked"){
797       $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
798     } else {
799       $workfilter= "";
800     }
801     if ($terminalfilter['winstations'] == "checked"){
802       if ($this->config->current['SAMBAVERSION'] == "3"){
803         $samba= "sambaSamAccount";
804       } else {
805         $samba= "sambaAccount";
806       }
807       $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
808     } else {
809       $winfilter= "";
810     }
811     if ($terminalfilter['printers'] == "checked"){
812       $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
813     } else {
814       $printfilter= "";
815     }
816     if ($terminalfilter['phones'] == "checked"){
817       $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
818     } else {
819       $phonefilter= "";
820     }
821     if ($terminalfilter['netdev'] == "checked"){
822       $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
823     } else {
824       $netfilter= "";
825     }
826     if ($terminalfilter['servers'] == "checked"){
827       $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
828     } else {
829       $serverfilter= "";
830     }
832     /* User filter? */
833     if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
834       $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
835     }
837     /* Get all gotoTerminal's */
838     $this->terminals= array();
840     $res= get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=terminals,ou=systems,".$base, 
841         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE);
843     $res= array_merge($res,get_list($this->ui->subtreeACL, "(|$termfilter)", FALSE, "ou=incoming,".$base, 
844         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
846     $res= array_merge($res,
847           get_list($this->ui->subtreeACL, "(|$serverfilter)", FALSE, "ou=servers,ou=systems,".$base, 
848         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
850     $res= array_merge($res,
851           get_list($this->ui->subtreeACL, "(|$phonefilter)", FALSE, "ou=phones,ou=systems,".$base, 
852         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
854     $res= array_merge($res,
855           get_list($this->ui->subtreeACL, "(|$netfilter)", FALSE, "ou=netdevices,ou=systems,".$base, 
856         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
858     $res= array_merge($res,
859           get_list($this->ui->subtreeACL, "(|$printfilter)", FALSE, "ou=printers,ou=systems,".$base, 
860         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
862     $res= array_merge($res,
863           get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=workstations,ou=systems,".$base, 
864         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
866     $res= array_merge($res,
867           get_list($this->ui->subtreeACL, "(|$workfilter)", FALSE, "ou=incoming,".$base, 
868         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
870     $res= array_merge($res,
871           get_list($this->ui->subtreeACL, "(|$winfilter)", FALSE, "ou=winstations,ou=systems,".$base, 
872         array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), FALSE));
874 /* NEW LIST MANAGMENT
875      * We also need to search for the departments
876      * So we are able to navigate like in konquerer
877      */
879     $peopleOU = get_people_ou();
881     if(empty($peopleOU)){
882       $base2 = $base;
883     }else{
884       $base2 = preg_replace("/".$peopleOU."/i","",$base);
885     }
888     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
889                               TRUE, $base2, array("ou", "description"), TRUE);
891     $this->departments= array();
892     $tmp = array();
893     foreach ($res3 as $value){
894       $tmp[strtolower($value['dn']).$value['dn']]=$value;
895     }
896     ksort($tmp);
897     foreach($tmp as $value){
898       if(isset($value["description"][0])){
899         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
900       }else{
901         $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
902       }
903     }
905     /* END NEW LIST MANAGMENT
906      */
909     foreach ($res as $value){
911       /* Look for new terminals and mark them with '+' */
912       $tmp= "";
913       if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
914         $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
915       }
916       if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
917         $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
918       }
919       if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
920         $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
921       }
922       if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
923         $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
924       }
925       if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
926         $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
927       }
928       if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
929         $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
930       }
931       if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
932         $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
933       }
934       if ($tmp == ""){
935         $tmp= $value["dn"];
936       }
937       if (preg_match ("/,ou=incoming,/i", $tmp)){
938         if (in_array('gotoTerminal', $value['objectClass'])){
939           $add= "- "._("New terminal");
940         }
941         if (in_array('gotoWorkstation', $value['objectClass'])){
942           $add= "- "._("New workstation");
943         }
944       } else {
945         $add= "";
946       }
948       $terminal = array();
949   
950       if (in_array ($tmp, $responsible) || $add != ""){
951         if (in_array('gotoTerminal', $value["objectClass"])){
952           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
953             $terminal             = $value;
954             $terminal['type']     = "T";
955             $terminal['is_new']   = $add;
956           } else {
957             $terminal             = $value;
958             $terminal['type']     = "D";
959             $terminal['message']  = _("Terminal template for");
960             $terminal['location'] = array_search($tmp, $this->config->departments); 
961           }
962         } elseif (in_array('gotoWorkstation', $value["objectClass"])){
963           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
964             $terminal             = $value;
965             $terminal['type']     = "L";
966             $terminal['is_new']   = $add;
967           } else {
968             $terminal             = $value;
969             $terminal['type']     = "D";
970             $terminal['location'] = array_search($tmp, $this->config->departments);
971             $terminal['message']  = _("Workstation template for");
972           }
973         } elseif (in_array('gotoPrinter', $value["objectClass"])){
974             $terminal             = $value;
975             $terminal['type']     = "P";
976         } elseif (in_array('goServer', $value["objectClass"])){
977             $terminal             = $value;
978             $terminal['type']     = "S";
979         } elseif (in_array('goFonHardware', $value["objectClass"])){
980             $terminal             = $value;
981             $terminal['type']     = "F";
982         } elseif (in_array('ieee802Device', $value["objectClass"])){
983             $terminal             = $value;
984             $terminal['type']     = "C";
985         } else{
986           $name= preg_replace('/\$$/', '', $value['cn'][0]);
987           if (isset($value['sambaDomainName'])){
988             $domain= " [".$value['sambaDomainName'][0]."]";
989           } else {
990             $domain= "";
991           }
992           $terminal=$value;
993           $terminal['type']     ="W";
994           $terminal['domain']   = $name.$domain;
995         }
996         $this->terminals[]=$terminal;
997       }
998     }
1000     $tmp=array();
1001     foreach($this->terminals as $tkey => $val ){
1002       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1003     }
1004     ksort($tmp);
1005     $this->terminals=array();
1006     foreach($tmp as $val){
1007       $this->terminals[]=$val;
1008     }
1009     reset ($this->terminals);
1010   }
1012   function remove_lock()
1013   {
1014     if (isset($this->systab->dn)){
1015       del_lock ($this->systab->dn);
1016     }
1017   }
1020   function get_system_type($classes)
1021   {
1022     $type= "";
1024     if (in_array('ieee802Device', $classes)){
1025       $type= "component";
1026     }
1027     if (in_array('gotoTerminal', $classes)){
1028       $type= "terminal";
1029     }
1030     if (in_array('gotoWorkstation', $classes)){
1031       $type= "workstation";
1032     }
1033     if (in_array('gotoPrinter', $classes)){
1034       $type= "printer";
1035     }
1036     if (in_array('goFonHardware', $classes)){
1037       $type= "phone";
1038     }
1039     if (in_array('goServer', $classes)){
1040       $type= "server";
1041     }
1042     if (in_array('sambaAccount', $classes) ||
1043         in_array('sambaSamAccount', $classes)){
1044       $type= "winstation";
1045     }
1047     return ($type);
1048   }
1052 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1053 ?>