Code

e553b92065aa615220ecb6208b40457432cb26ec
[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     /* Save data */
69     $terminalfilter= get_global("terminalfilter");
70     foreach( array("depselect", "user", "regex") as $type){
71       if (isset($_POST[$type])){
72         $terminalfilter[$type]= $_POST[$type];
73       }
74     }
75     if (isset($_POST['depselect'])){
76       foreach( array("workstations", "thins", "winstations", "printers", "phones", "servers", "netdev") as $type){
78         if (isset($_POST[$type])) {
79           $terminalfilter[$type]= "checked";
80         } else {
81           $terminalfilter[$type]= "";
82         }
83       }
84     }
85     if (isset($_GET['search'])){
86       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
87       if ($s == "**"){
88         $s= "*";
89       }
90       $terminalfilter['regex']= $s;
91     }
93     $terminalfilter   = get_global("terminalfilter"); // contains Filter Settings
94     $s_action     = "";                       // Contains the action to proceed
95     $s_entry      = "";                       // The value for s_action
96     $base_back    = "";                       // The Link for Backbutton
97     $smarty       = get_smarty();
99     /* Start for New List Managment */
100     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
101             $s_action="open";
102             $s_entry = base64_decode($_GET['dep_id']);
103             $terminalfilter['depselect']= "".$this->config->departments[trim($s_entry)];
104             $this->reload();
105     }
107     /* Test Posts */
108     foreach($_POST as $key => $val){
109       // Post for delete
110       if(preg_match("/user_del.*/",$key)){
111         $s_action = "del";
112         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
113         // Post for edit
114       }elseif(preg_match("/user_edit_.*/",$key)){
115         $s_action="edit";
116         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
117         // Post for new
118       }elseif(preg_match("/dep_back.*/i",$key)){
119         $s_action="back";
120       }elseif(preg_match("/user_new.*/",$key)){
121         $s_action="new";
122       }elseif(preg_match("/dep_home.*/i",$key)){
123         $s_action="home";
124       }elseif(preg_match("/user_tplnew.*/i",$key)){
125         $s_action="new_tpl";
126       }elseif(preg_match("/user_setpwd_.*/i",$key)){
127         $s_action="change_pw";
128         $s_entry  = preg_replace("/user_setpwd_/i","",$key);
129       }elseif(preg_match("/dep_root.*/i",$key)){
130         $s_action="root";
131       }
132     }
134      if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
135       $s_action ="edit";
136       $s_entry  = $_GET['id'];
137     }
139     $s_entry  = preg_replace("/_.$/","",$s_entry);
141     /* Department changed? */
142     if(isset($_POST['depselect']) && $_POST['depselect']){
143       $terminalfilter['depselect']= $_POST['depselect'];
144     }
146     /* Homebutton is posted */
147     if($s_action=="home"){
148       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
149       $terminalfilter['depselect']=(preg_replace("/^[^,]+,/","",$terminalfilter['depselect']));
150     }
152     if($s_action=="root"){
153       $terminalfilter['depselect']=($this->config->current['BASE']);
154     }
157     /* If Backbutton is Posted */
158     if($s_action=="back"){
159       $base_back          = preg_replace("/^[^,]+,/","",$terminalfilter['depselect']);
160       $base_back          = convert_department_dn($base_back);
162       if(isset($this->config->departments[trim($base_back)])){
163         $terminalfilter['depselect']= $this->config->departments[trim($base_back)];
164       }else{
165         $terminalfilter['depselect']= $this->config->departments["/"];
166       }
167     }
169     register_global("terminalfilter", $terminalfilter);
170     $this->reload();
172     /* Check for exeeded sizelimit */
173     if (($message= check_sizelimit()) != ""){
174       return($message);
175     }
177     /* Try to get informations about what kind of system to create */
178     if ($s_action=="new") {
179       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
180     }
182     /* Create new default terminal */
183     if (isset($_POST['create_system'])) {
184       $this->dn= "new";
185       $this->acl= array(":all");
187       switch ($_POST['system']){
188         case 'terminal':
189           $this->systab= new termtabs($this->config,
190               $this->config->data['TABS']['TERMTABS'], $this->dn);
191           $this->systab->set_acl ($this->acl);
192           $this->systab->by_object['termgeneric']->cn= "default";
193           $this->systab->by_object['termservice']->cn= "default";
194           break;
196         case 'workstation':
197           $this->systab= new worktabs($this->config,
198               $this->config->data['TABS']['WORKTABS'], $this->dn);
199           $this->systab->set_acl ($this->acl);
200           $this->systab->by_object['workgeneric']->cn= "wdefault";
201           $this->systab->by_object['termservice']->cn= "default";
202           break;
204         case 'server':
205           $this->systab= new servtabs($this->config,
206               $this->config->data['TABS']['SERVTABS'], $this->dn);
207           $this->systab->set_acl ($this->acl);
208           break;
210         case 'printer':
211           $this->systab= new printtabs($this->config,
212               $this->config->data['TABS']['PRINTTABS'], $this->dn);
213           $this->systab->set_acl ($this->acl);
214           break;
216         case 'phone':
217           $this->systab= new phonetabs($this->config,
218               $this->config->data['TABS']['PHONETABS'], $this->dn);
219           $this->systab->set_acl ($this->acl);
220           break;
222         case 'component':
223           $this->systab= new componenttabs($this->config,
224               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
225           $this->systab->set_acl ($this->acl);
226           break;
227       }
228     }
230     /* User wants to edit data? */
231     if ($s_action == "edit"){
233       /* Get 'dn' from posted 'cn', must be unique */
234       $this->dn= $this->terminals[$s_entry]['dn'];
236       /* Check locking, save current plugin in 'back_plugin', so
237          the dialog knows where to return. */
238       if (($user= get_lock($this->dn)) != ""){
239         return(gen_locked_message ($user, $this->dn));
240       }
242       /* Set up the users ACL's for this 'dn' */
243       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
245       /* Find out more about the object type */
246       $ldap= $this->config->get_ldap_link();
247       $ldap->cat($this->dn);
248       $attrs= $ldap->fetch();
249       $type= $this->get_system_type($attrs['objectClass']);
251       /* Lock the current entry, so everyone will get the
252          above dialog */
253       add_lock ($this->dn, $this->ui->dn);
255       switch ($type){
256         case "terminal":
257           /* Register systab to trigger edit dialog */
258           $this->systab= new termtabs($this->config,
259               $this->config->data['TABS']['TERMTABS'], $this->dn);
260           $this->systab->set_acl($acl);
261           $_SESSION['objectinfo']= $this->dn;
262           break;
264         case "server":
265           /* Register systab to trigger edit dialog */
266           $this->systab= new servtabs($this->config,
267               $this->config->data['TABS']['SERVTABS'], $this->dn);
268           $this->systab->set_acl($acl);
269           $_SESSION['objectinfo']= $this->dn;
270           break;
272         case "workstation":
273           /* Register systab to trigger edit dialog */
274           $this->systab= new worktabs($this->config,
275               $this->config->data['TABS']['WORKTABS'], $this->dn);
276           $this->systab->set_acl($acl);
277           $_SESSION['objectinfo']= $this->dn;
278           break;
280         case "printer":
281           /* Register systab to trigger edit dialog */
282           $this->systab= new printtabs($this->config,
283               $this->config->data['TABS']['PRINTTABS'], $this->dn);
284           $this->systab->set_acl($acl);
285           $_SESSION['objectinfo']= $this->dn;
286           break;
288         case "phone":
289           /* Register systab to trigger edit dialog */
290           $this->systab= new phonetabs($this->config,
291               $this->config->data['TABS']['PHONETABS'], $this->dn);
292           $this->systab->set_acl($acl);
293           $_SESSION['objectinfo']= $this->dn;
294           break;
296         case "component":
297           /* Register systab to trigger edit dialog */
298           $this->systab= new componenttabs($this->config,
299               $this->config->data['TABS']['COMPONENTTABS'], $this->dn);
300           $this->systab->set_acl($acl);
301           $_SESSION['objectinfo']= $this->dn;
302           break;
303        
304         case "winstation":
305           /* Register systab to trigger edit dialog */
306           $this->systab= new wintabs($this->config,
307               $this->config->data['TABS']['WINTABS'], $this->dn);
308           $this->systab->set_acl($acl);
309           $_SESSION['objectinfo']= $this->dn;
310           break;
313         default:
314           print_red (_("You can't edit this object type yet!"));
315           del_lock($this->dn);
316           break;
317       }
318     }
320     /* Set terminals root password */
321     if ($s_action=="change_pw"){
322       $this->dn= $this->terminals[$s_entry]['dn'];
323       $_SESSION['objectinfo']= $this->dn;
324       return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
325     }
327     /* Correctly specified? */
328     if (isset($_POST['password_finish'])){
329       if ($_POST['new_password'] != $_POST['repeated_password']){
330         print_red (_("Passwords entered as new and repeated do not match!"));
331         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
332       }
333     }
335     /* Change terminal password */
336     if (isset($_POST['password_finish']) && 
337         $_POST['new_password'] == $_POST['repeated_password']){
339       /* Check if user is allowed to set password */
340       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
341       $acl= get_module_permission($acl, "terminal", $this->dn);
342       if (chkacl($acl, "password") != ""){
343         print_red (_("You are not allowed to set this systems password!"));
344       } else {
345         $ldap= $this->config->get_ldap_link();
346         $ldap->cd($this->dn);
348         $attrs= array();
349         if ($_POST['new_password'] == ""){
350           $attrs['gotoRootPasswd']= array();
351         } else {
352           $attrs['gotoRootPasswd']= crypt($_POST['new_password'],
353               substr(session_id(),0,2));
354         }
355         $ldap->modify($attrs);
356         gosa_log ("Password for '".$this->dn."' has been changed");
357       }
358       unset($_SESSION['objectinfo']);
359     }
361     /* Delete terminal canceled? */
362     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
363       del_lock ($this->dn);
364       unset($_SESSION['objectinfo']);
365     }
367     /* Remove terminal was requested */
368     if ($s_action=="del"){
370       /* Get 'dn' from posted termlinst */
371       $this->dn= $this->terminals[$s_entry]['dn'];
373       /* Load permissions for selected 'dn' and check if
374          we're allowed to remove this 'dn' */
375       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
376       $this->acl= get_module_permission($acl, "terminal", $this->dn);
377       if (chkacl($this->acl, "delete") == ""){
379         /* Check locking, save current plugin in 'back_plugin', so
380            the dialog knows where to return. */
381         if (($user= get_lock($this->dn)) != ""){
382           return(gen_locked_message ($user, $this->dn));
383         }
385         /* Lock the current entry, so nobody will edit it during deletion */
386         add_lock ($this->dn, $this->ui->dn);
387         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), $this->dn));
388         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
389       } else {
391         /* Obviously the user isn't allowed to delete. Show message and
392            clean session. */
393         print_red (_("You are not allowed to delete this component!"));
394       }
395     }
397     /* Confirmation for deletion has been passed. Terminal should be deleted. */
398     if (isset($_POST['delete_terminal_confirm'])){
400       /* Some nice guy may send this as POST, so we've to check
401          for the permissions again. */
402       if (chkacl($this->acl, "delete") == ""){
404         /* Find out more about the object type */
405         $ldap= $this->config->get_ldap_link();
406         $ldap->cat($this->dn);
407         $attrs= $ldap->fetch();
408         $type= $this->get_system_type($attrs['objectClass']);
410         switch ($type){
411           case "terminal":
412             $tabtype= "termtabs";
413           break;
415           case "workstation":
416             $tabtype= "worktabs";
417           break;
419           case "server":
420             $tabtype= "servtabs";
421           break;
423           default:
424 #print_red (_("You can't remove this object type yet!"));
425 #del_lock($this->dn);
426 #return;
427           $tabtype= "termtabs";
428           break;
429         }
431         /* Delete request is permitted, perform LDAP action */
432         $this->systab= new $tabtype($this->config,
433             $this->config->data['TABS']['TERMTABS'], $this->dn);
434         $this->systab->set_acl(array($this->acl));
435         $this->systab->by_object['termgeneric']->remove_from_parent ();
436         unset ($this->systab);
437         gosa_log ("System object'".$this->dn."' has been removed");
438         $this->systab= NULL;
440         /* Terminal list has changed, reload it. */
441         $this->reload ();
442       } else {
444         /* Normally this shouldn't be reached, send some extra
445            logs to notify the administrator */
446         print_red (_("You are not allowed to delete this component!"));
447         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
448             "deletion.");
449       }
451       /* Remove lock file after successfull deletion */
452       del_lock ($this->dn);
453     }
455     /* Finish user edit is triggered by the tabulator dialog, so
456        the user wants to save edited data. Check and save at this
457        point. */
458     if (isset($_POST['edit_finish'])){
460       /* Check tabs, will feed message array */
461       $message= $this->systab->check();
463       /* Save, or display error message? */
464       if (count($message) == 0){
466         /* Save terminal data to ldap */
467         gosa_log ("System object'".$this->dn."' has been saved");
468         $this->systab->save();
470         /* Terminal has been saved successfully, remove lock from
471            LDAP. */
472         if ($this->dn != "new"){
473           del_lock ($this->dn);
474         }
476         /* There's no page reload so we have to read new terminals at
477            this point. */
478         $this->reload ();
479         unset ($this->systab);
480         $this->systab= NULL;
481         unset($_SESSION['objectinfo']);
483       } else {
484         /* Ok. There seem to be errors regarding to the tab data,
485            show message and continue as usual. */
486         show_errors($message);
487       }
489     }
491     /* Cancel dialogs */
492     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
493       if (isset($this->systab)){
494         del_lock ($this->systab->dn);
495         unset ($this->systab);
496       }
497       $this->systab= NULL;
498       unset($_SESSION['objectinfo']);
499     }
501     /* Show tab dialog if object is present */
502     if ($this->systab){
503       $display= $this->systab->execute();
505       /* Don't show buttons if tab dialog requests this */
506       if (!$this->systab->by_object[$this->systab->current]->dialog){
507         $display.= "<p style=\"text-align:right\">\n";
508         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
509         $display.= "&nbsp;\n";
510         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
511         $display.= "</p>";
512       }
513       return ($display);
514     }
521     /* Prepare departments */
522     $options= "";
523     foreach ($this->config->idepartments as $key => $value){
524             if ($terminalfilter['depselect'] == $key){
525                     $options.= "<option selected value='$key'>$value</option>";
526             } else {
527                     $options.= "<option value='$key'>$value</option>";
528             }
529     }
532   /* NEW LIST MANAGMENT */
533     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
534     " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
535     " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
536     " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."'                     name='dep_home'>&nbsp;".
537     " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
538     " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."'                    name='user_new'>&nbsp;".
539     " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
540     _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
541     " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;".
542     "</div>";
546     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
547     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
550     $divlist = new divlist();
551     $divlist->SetHeader(array(
552           array("string" => "&nbsp;"),
553           array("string" => _("System")." / "._("Department")),
554           array("string" => _("Actions"), "attach" => "style='border:none'" )));
557     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
558     $divlist->SetEntriesPerPage(20);
560     // Defining Links
561     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
563     foreach($this->departments as $key=> $val){
564       $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
565       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
566       $field3 = array("string" => "&nbsp;", "attach" => "style='border:none'");
567       $divlist->AddEntry(array($field1,$field2,$field3));
568     }
570     // Space
571     $empty    ="";//= "<img src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
573     // User and Template  Images
574     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
576     // Pictures for Extensions
577     $img1  = "<img src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
578     $img2  = "<img src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
579     $img3  = "<img src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
580     $img4  = "<img src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
581     $img5  = "<img src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
582     $img6  = "<img src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
583     $img7  = "<img src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
584     $img8  = "<img src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
585     $img9  = "<img src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
586     $img10 = "<img src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
588     // Test Every Entry and generate divlist Array
589     foreach($this->terminals as $key => $val){
590       // Specify Pics for Extensions
591       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
592       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
593       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
594       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
595       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
596       if(in_array("goNfsServer"     ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
597       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
598       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
599       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
600       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
601   
602       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
603       $pics = "";
604       // Generate Array to Add
605       if((isset($val['is_new']))&&(!empty($val['is_new']))){
606         $display= "".$val["cn"][0]." ".$val['is_new'];
607       }else{
608         $display= "".$val["cn"][0]."";
609       }
611       if(in_array("gotoTerminal",$val['objectClass'])){
612         $action2 = "<input type='image' src='images/certs.png' alt='"._("Password")."'   name='user_setpwd_%KEY%' title='"._("Set root password")."'>";
613       }else{
614         $action2 = "";
615       }
618       if(isset($val['message'])){
619         $display.= "  (".$val['message']." '".$this->config->idepartments[$terminalfilter['depselect']]."'  )";
620       }
622       $img=$this->convert_list($val);
624       $field1 = array("string" => sprintf($img['img'],$val['dn']),"attach"=>"style='width:20px;align:middle;'");
625       $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
626       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),"attach" => "style='border:none; text-align:right;width:48px'");
627       $divlist->AddEntry( array($field1,$field2,$field3));
628     }
634     /* Show main page */
635     $smarty->assign("terminalshead", $listhead);
636     $smarty->assign("terminals", $divlist->DrawList());
637     $smarty->assign("search_image", get_template_path('images/search.png'));
638     $smarty->assign("tree_image", get_template_path('images/tree.png'));
639     $smarty->assign("infoimage", get_template_path('images/info.png'));
640     $smarty->assign("launchimage", get_template_path('images/launch.png'));
641     foreach( array("depselect", "user", "regex", "workstations", "thins", "servers",
642           "winstations", "printers", "phones", "netdev") as $type){
644       $smarty->assign("$type", $terminalfilter[$type]);
645     }
646     $smarty->assign("deplist", $this->config->idepartments);
648     /* Extend if we are not using javascript */
649     $smarty->assign("apply", apply_filter());
650     $smarty->assign("alphabet", generate_alphabet());
651     $smarty->assign("hint", print_sizelimit_warning());
653     return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
654   }
657   function convert_list($input)
658   {
659     $temp= "";
660     $conv= array(       "D" => "select_default.png",
661         
663   "T" => "select_terminal.png",
664         "L" => "select_workstation.png",
665         "F" => "select_phone.png",
666         "S" => "select_server.png",
667         "NT" => "select_new_terminal.png",
668         "NL" => "select_new_workstation.png",
669         "W" => "select_winstation.png",
670         "C" => "select_component.png",
671         "P" => "select_printer.png");
673    if((isset($input['is_new']))&&(!empty($input['is_new']))){
674      $input['type']="N".$input['type'];
675    }
676    foreach ($conv  as $key => $value){
677       if($input['type']==$key){
678         $tmp['img'] ="<img src='images/".$value."' alt='".$key."' title='%s'>";
679         $tmp['class']=$key;
680         return $tmp;
681       }
682     }
683   }
685   function remove_from_parent()
686   {
687     /* Optionally execute a command after we're done */
688     $this->postremove();
689   }
692   /* Save data to object */
693   function save_object()
694   {
695   }
698   /* Check values */
699   function check()
700   {
701   }
704   /* Save to LDAP */
705   function save()
706   {
707   }
709   function adapt_from_template($dn)
710   {
711   }
713   function password_change_needed()
714   {
715   }
717   function show_header($button_text, $text, $disabled= FALSE)
718   {
719   }
721   function reload()
722   {
723     /* Load terminal shortcuts */
724     $responsible= array();
725     foreach ($this->config->departments as $key => $value){
726       if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
727             "terminal", $value) == "#all#"){
728         $responsible[$key]= $value;
729       }
730     }
732     /* Get config */
733     $terminalfilter= get_global('terminalfilter');
734     $filter= "";
736     /* Set base for all searches */
737     $base= $terminalfilter['depselect'];
739     /* Regex filter? */
740     if ($terminalfilter['regex'] != ""){
741       $regex= $terminalfilter['regex'];
742     } else {
743       $regex= "*";
744     }
746     /* Get list of terminals to be shown */
747     if ($terminalfilter['thins'] == "checked"){
748       $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
749     } else {
750       $termfilter= "";
751     }
752     if ($terminalfilter['workstations'] == "checked"){
753       $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
754     } else {
755       $workfilter= "";
756     }
757     if ($terminalfilter['winstations'] == "checked"){
758       if ($this->config->current['SAMBAVERSION'] == "3"){
759         $samba= "sambaSamAccount";
760       } else {
761         $samba= "sambaAccount";
762       }
763       $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
764     } else {
765       $winfilter= "";
766     }
767     if ($terminalfilter['printers'] == "checked"){
768       $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
769     } else {
770       $printfilter= "";
771     }
772     if ($terminalfilter['phones'] == "checked"){
773       $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
774     } else {
775       $phonefilter= "";
776     }
777     if ($terminalfilter['netdev'] == "checked"){
778       $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
779     } else {
780       $netfilter= "";
781     }
782     if ($terminalfilter['servers'] == "checked"){
783       $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
784     } else {
785       $serverfilter= "";
786     }
788     /* User filter? */
789     if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
790       $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
791     }
793     /* Get all gotoTerminal's */
794     $this->terminals= array();
796     $res= get_list($this->ui->subtreeACL, "(|$termfilter$workfilter$winfilter$printfilter$phonefilter$serverfilter$netfilter)", TRUE, $base, array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), TRUE);
798       
799     /* NEW LIST MANAGMENT
800      * We also need to search for the departments
801      * So we are able to navigate like in konquerer
802      */
803     $base2 = preg_replace("/ou=people,/i","",$base);
805     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
806                               TRUE, $base2, array("ou", "description"), TRUE);
808     $this->departments= array();
809     $tmp = array();
810     foreach ($res3 as $value){
811       $tmp[strtolower($value['dn']).$value['dn']]=$value;
812     }
813     ksort($tmp);
814     foreach($tmp as $value){
815       if($value["description"][0]!=".."){
816         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
817       }else{
818         $this->departments[$value['dn']]=$value["description"][0];
819       }
820     }
822     /* END NEW LIST MANAGMENT
823      */
826     foreach ($res as $value){
828       /* Look for new terminals and mark them with '+' */
829       $tmp= "";
830       if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
831         $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
832       }
833       if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
834         $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
835       }
836       if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
837         $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
838       }
839       if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
840         $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
841       }
842       if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
843         $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
844       }
845       if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
846         $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
847       }
848       if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
849         $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
850       }
851       if ($tmp == ""){
852         $tmp= $value["dn"];
853       }
854       if (preg_match ("/,ou=incoming,/i", $tmp)){
855         if (in_array('gotoTerminal', $value['objectClass'])){
856           $add= "+ "._("New terminal");
857         }
858         if (in_array('gotoWorkstation', $value['objectClass'])){
859           $add= "+ "._("New workstation");
860         }
861       } else {
862         $add= "";
863       }
865       $terminal = array();
866   
867       if (in_array ($tmp, $responsible) || $add != ""){
868         if (in_array('gotoTerminal', $value["objectClass"])){
869           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
870             $terminal             = $value;
871             $terminal['type']     = "T";
872             $terminal['is_new']   = $add;
873           } else {
874             $terminal             = $value;
875             $terminal['type']     = "D";
876             $terminal['message']  = _("Terminal template for");
877             $terminal['location'] = array_search($tmp, $this->config->departments); 
878           }
879         } elseif (in_array('gotoWorkstation', $value["objectClass"])){
880           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
881             $terminal             = $value;
882             $terminal['type']     = "L";
883           } else {
884             $terminal             = $value;
885             $terminal['type']     = "D";
886             $terminal['location'] = array_search($tmp, $this->config->departments);
887             $terminal['message']  = _("Workstation template for");
888           }
889         } elseif (in_array('gotoPrinter', $value["objectClass"])){
890             $terminal             = $value;
891             $terminal['type']     = "P";
892         } elseif (in_array('goServer', $value["objectClass"])){
893             $terminal             = $value;
894             $terminal['type']     = "S";
895         } elseif (in_array('goFonHardware', $value["objectClass"])){
896             $terminal             = $value;
897             $terminal['type']     = "F";
898         } elseif (in_array('ieee802Device', $value["objectClass"])){
899             $terminal             = $value;
900             $terminal['type']     = "C";
901         } else{
902           $name= preg_replace('/\$$/', '', $value['cn'][0]);
903           if (isset($value['sambaDomainName'])){
904             $domain= " [".$value['sambaDomainName'][0]."]";
905           } else {
906             $domain= "";
907           }
908             $terminal=$value;
909             $terminal['type']     ="W";
910             $terminal['domain']   = $name.$domain;
911         }
912       $this->terminals[]=$terminal;
913       }
914     }
916     $tmp=array();
917     foreach($this->terminals as $tkey => $val ){
918       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
919     }
920     ksort($tmp);
921     $this->terminals=array();
922     foreach($tmp as $val){
923       $this->terminals[]=$val;
924     }
925     reset ($this->terminals);
926   }
928   function remove_lock()
929   {
930     if (isset($this->systab->dn)){
931       del_lock ($this->systab->dn);
932     }
933   }
936   function get_system_type($classes)
937   {
938     $type= "";
940     if (in_array('ieee802Device', $classes)){
941       $type= "component";
942     }
943     if (in_array('gotoTerminal', $classes)){
944       $type= "terminal";
945     }
946     if (in_array('gotoWorkstation', $classes)){
947       $type= "workstation";
948     }
949     if (in_array('gotoPrinter', $classes)){
950       $type= "printer";
951     }
952     if (in_array('goFonHardware', $classes)){
953       $type= "phone";
954     }
955     if (in_array('goServer', $classes)){
956       $type= "server";
957     }
958     if (in_array('sambaAccount', $classes) ||
959         in_array('sambaSamAccount', $classes)){
960       $type= "winstation";
961     }
963     return ($type);
964   }
968 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
969 ?>