Code

Fixed missing description error
[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->by_object['termgeneric']->remove_from_parent ();
466         }
467         unset ($this->systab);
468         gosa_log ("System object'".$this->dn."' has been removed");
469         $this->systab= NULL;
471         /* Terminal list has changed, reload it. */
472         $this->reload ();
473       } else {
475         /* Normally this shouldn't be reached, send some extra
476            logs to notify the administrator */
477         print_red (_("You are not allowed to delete this component!"));
478         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
479             "deletion.");
480       }
482       /* Remove lock file after successfull deletion */
483       del_lock ($this->dn);
484     }
486     /* Finish user edit is triggered by the tabulator dialog, so
487        the user wants to save edited data. Check and save at this
488        point. */
489     if (isset($_POST['edit_finish'])){
491       /* Check tabs, will feed message array */
492       $message= $this->systab->check();
494       /* Save, or display error message? */
495       if (count($message) == 0){
497         /* Save terminal data to ldap */
498         gosa_log ("System object'".$this->dn."' has been saved");
499         $this->systab->save();
501         /* Terminal has been saved successfully, remove lock from
502            LDAP. */
503         if ($this->dn != "new"){
504           del_lock ($this->dn);
505         }
507         /* There's no page reload so we have to read new terminals at
508            this point. */
509         $this->reload ();
510         unset ($this->systab);
511         $this->systab= NULL;
512         unset($_SESSION['objectinfo']);
514       } else {
515         /* Ok. There seem to be errors regarding to the tab data,
516            show message and continue as usual. */
517         show_errors($message);
518       }
520     }
522     /* Cancel dialogs */
523     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
524       if (isset($this->systab)){
525         del_lock ($this->systab->dn);
526         unset ($this->systab);
527       }
528       $this->systab= NULL;
529       unset($_SESSION['objectinfo']);
530     }
532     /* Show tab dialog if object is present */
533     if ($this->systab){
534       $display= $this->systab->execute();
536       /* Don't show buttons if tab dialog requests this */
537       if (!$this->systab->by_object[$this->systab->current]->dialog){
538         $display.= "<p style=\"text-align:right\">\n";
539         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
540         $display.= "&nbsp;\n";
541         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
542         $display.= "</p>";
543       }
544       return ($display);
545     }
552     /* Prepare departments */
553     $options= "";
554     foreach ($this->config->idepartments as $key => $value){
555             if ($terminalfilter['depselect'] == $key){
556                     $options.= "<option selected value='$key'>$value</option>";
557             } else {
558                     $options.= "<option value='$key'>$value</option>";
559             }
560     }
563   /* NEW LIST MANAGMENT */
564     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
565     " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
566     " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
567     " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
568     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
569     " <input class='center' type='image' align='middle' src='images/select_new_terminal.png'   name='newsystem_terminal'    alt='"._("New Terminal template")."' title='"._("New Terminal")."'>".
570     " <input class='center' type='image' align='middle' src='images/select_new_workstation.png' name='newsystem_workstation' alt='"._("New Workstation template")."' title='"._("New Workstation")."'>".
571     " <input class='center' type='image' align='middle' src='images/select_new_server.png'     name='newsystem_server'      alt='"._("New Server")."' title='"._("New Server")."'>".
572     " <input class='center' type='image' align='middle' src='images/select_new_printer.png'    name='newsystem_printer'     alt='"._("New Printer")."' title='"._("New Printer")."'>".
573     " <input class='center' type='image' align='middle' src='images/select_new_phone.png'      name='newsystem_phone'       alt='"._("New Phone")."' title='"._("New Phone")."'>".
574     " <input class='center' type='image' align='middle' src='images/select_new_component.png'  name='newsystem_component'   alt='"._("New Component")."' title='"._("New Component")."'>".
575     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
576     _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
577     " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
578     "</div>";
582     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit system")."'>";
583     $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete system")."'>";
586     $divlist = new divlist("systemstab");
587     $divlist->SetHeader(array(
588           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
589           array("string" => _("System")." / "._("Department"), "attach" => "style=''"),
590           array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
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'>", "attach" => "style='text-align:center;width:20px;'");
613       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
614       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
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='text-align:center;width:20px;'");
672       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
673       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
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(isset($value["description"][0])){
890         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
891       }else{
892         $this->departments[$value['dn']]=convert_department_dn2($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 ?>