Code

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