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;
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.= " \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'> ".
535 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
536 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
537 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
538 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new system")."' alt='"._("New user")."' name='user_new'> ".
539 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
540 _("Current base")." <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")."'> ".
542 "</div>";
546 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit system")."'>";
547 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete system")."'>";
550 $divlist = new divlist();
551 $divlist->SetHeader(array(
552 array("string" => " "),
553 array("string" => _("System")." / "._("Department")),
554 array("string" => _("Actions"), "attach" => "style='border:none'" )));
557 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
558 $divlist->SetEntriesPerPage(20);
560 // Defining Links
561 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&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" => " ", "attach" => "style='border:none'");
567 $divlist->AddEntry(array($field1,$field2,$field3));
568 }
570 // Space
571 $empty =" ";
573 // User and Template Images
574 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&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;
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(
661 "D" => array("select_default.png",_("Template")),
662 "T" => array("select_terminal.png",_("Terminal")),
663 "L" => array("select_workstation.png",_("Workstation")),
664 "F" => array("select_phone.png",_("Phone")),
665 "S" => array("select_server.png",_("Server")),
666 "NT"=> array("select_new_terminal.png",_("New Terminal")),
667 "NL"=> array("select_new_workstation.png",_("New Workstation")),
668 "W" => array("select_winstation.png",_("Winstation")),
669 "C" => array("select_component.png",_("Network Device")),
670 "P" => array("select_printer.png",_("Printer")));
672 if((isset($input['is_new']))&&(!empty($input['is_new']))){
673 $input['type']="N".$input['type'];
674 }
675 foreach ($conv as $key => $value){
676 if($input['type']==$key){
677 $tmp['img'] ="<img src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
678 $tmp['class']=$key;
679 return $tmp;
680 }
681 }
682 }
684 function remove_from_parent()
685 {
686 /* Optionally execute a command after we're done */
687 $this->postremove();
688 }
691 /* Save data to object */
692 function save_object()
693 {
694 }
697 /* Check values */
698 function check()
699 {
700 }
703 /* Save to LDAP */
704 function save()
705 {
706 }
708 function adapt_from_template($dn)
709 {
710 }
712 function password_change_needed()
713 {
714 }
716 function show_header($button_text, $text, $disabled= FALSE)
717 {
718 }
720 function reload()
721 {
722 /* Load terminal shortcuts */
723 $responsible= array();
724 foreach ($this->config->departments as $key => $value){
725 if (get_module_permission(get_permissions ($value, $this->ui->subtreeACL),
726 "terminal", $value) == "#all#"){
727 $responsible[$key]= $value;
728 }
729 }
731 /* Get config */
732 $terminalfilter= get_global('terminalfilter');
733 $filter= "";
735 /* Set base for all searches */
736 $base= $terminalfilter['depselect'];
738 /* Regex filter? */
739 if ($terminalfilter['regex'] != ""){
740 $regex= $terminalfilter['regex'];
741 } else {
742 $regex= "*";
743 }
745 /* Get list of terminals to be shown */
746 if ($terminalfilter['thins'] == "checked"){
747 $termfilter= "(&(objectClass=gotoTerminal)(cn=$regex))";
748 } else {
749 $termfilter= "";
750 }
751 if ($terminalfilter['workstations'] == "checked"){
752 $workfilter= "(&(objectClass=gotoWorkstation)(cn=$regex))";
753 } else {
754 $workfilter= "";
755 }
756 if ($terminalfilter['winstations'] == "checked"){
757 if ($this->config->current['SAMBAVERSION'] == "3"){
758 $samba= "sambaSamAccount";
759 } else {
760 $samba= "sambaAccount";
761 }
762 $winfilter= "(&(objectClass=$samba)(cn=$regex\$))";
763 } else {
764 $winfilter= "";
765 }
766 if ($terminalfilter['printers'] == "checked"){
767 $printfilter= "(&(objectClass=gotoPrinter)(cn=$regex))";
768 } else {
769 $printfilter= "";
770 }
771 if ($terminalfilter['phones'] == "checked"){
772 $phonefilter= "(&(objectClass=goFonHardware)(cn=$regex))";
773 } else {
774 $phonefilter= "";
775 }
776 if ($terminalfilter['netdev'] == "checked"){
777 $netfilter= "(&(objectClass=ieee802Device)(cn=$regex))";
778 } else {
779 $netfilter= "";
780 }
781 if ($terminalfilter['servers'] == "checked"){
782 $serverfilter= "(&(objectClass=goServer)(cn=$regex))";
783 } else {
784 $serverfilter= "";
785 }
787 /* User filter? */
788 if ($terminalfilter['user'] != "" && $terminalfilter['user'] != "*"){
789 $filter.= "(gotoLastUser=".$terminalfilter['user'].")";
790 }
792 /* Get all gotoTerminal's */
793 $this->terminals= array();
795 $res= get_list($this->ui->subtreeACL, "(|$termfilter$workfilter$winfilter$printfilter$phonefilter$serverfilter$netfilter)", TRUE, $base, array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), TRUE);
798 /* NEW LIST MANAGMENT
799 * We also need to search for the departments
800 * So we are able to navigate like in konquerer
801 */
802 $base2 = preg_replace("/ou=people,/i","",$base);
804 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
805 TRUE, $base2, array("ou", "description"), TRUE);
807 $this->departments= array();
808 $tmp = array();
809 foreach ($res3 as $value){
810 $tmp[strtolower($value['dn']).$value['dn']]=$value;
811 }
812 ksort($tmp);
813 foreach($tmp as $value){
814 if($value["description"][0]!=".."){
815 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
816 }else{
817 $this->departments[$value['dn']]=$value["description"][0];
818 }
819 }
821 /* END NEW LIST MANAGMENT
822 */
825 foreach ($res as $value){
827 /* Look for new terminals and mark them with '+' */
828 $tmp= "";
829 if (preg_match('/,ou=terminals,ou=systems,/i', $value["dn"])){
830 $tmp= preg_replace("/^[^,]+,[^o]*ou=terminals,ou=systems,/i", "", $value["dn"]);
831 }
832 if (preg_match('/,ou=workstations,ou=systems,/i', $value["dn"])){
833 $tmp= preg_replace("/^[^,]+,[^o]*ou=workstations,ou=systems,/i", "", $value["dn"]);
834 }
835 if (preg_match('/,ou=servers,ou=systems,/i', $value["dn"])){
836 $tmp= preg_replace("/^[^,]+,[^o]*ou=servers,ou=systems,/i", "", $value["dn"]);
837 }
838 if (preg_match('/,'.get_winstations_ou().'/i', $value["dn"])){
839 $tmp= preg_replace("/^[^,]+,[^o]*".get_winstations_ou()."/i", "", $value["dn"]);
840 }
841 if (preg_match('/,ou=printers,ou=systems,/i', $value["dn"])){
842 $tmp= preg_replace("/^[^,]+,[^o]*ou=printers,ou=systems,/i", "", $value["dn"]);
843 }
844 if (preg_match('/,ou=phones,ou=systems,/i', $value["dn"])){
845 $tmp= preg_replace("/^[^,]+,[^o]*ou=phones,ou=systems,/i", "", $value["dn"]);
846 }
847 if (preg_match('/,ou=netdevices,ou=systems,/i', $value["dn"])){
848 $tmp= preg_replace("/^[^,]+,[^o]*ou=netdevices,ou=systems,/i", "", $value["dn"]);
849 }
850 if ($tmp == ""){
851 $tmp= $value["dn"];
852 }
853 if (preg_match ("/,ou=incoming,/i", $tmp)){
854 if (in_array('gotoTerminal', $value['objectClass'])){
855 $add= "+ "._("New terminal");
856 }
857 if (in_array('gotoWorkstation', $value['objectClass'])){
858 $add= "+ "._("New workstation");
859 }
860 } else {
861 $add= "";
862 }
864 $terminal = array();
866 if (in_array ($tmp, $responsible) || $add != ""){
867 if (in_array('gotoTerminal', $value["objectClass"])){
868 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
869 $terminal = $value;
870 $terminal['type'] = "T";
871 $terminal['is_new'] = $add;
872 } else {
873 $terminal = $value;
874 $terminal['type'] = "D";
875 $terminal['message'] = _("Terminal template for");
876 $terminal['location'] = array_search($tmp, $this->config->departments);
877 }
878 } elseif (in_array('gotoWorkstation', $value["objectClass"])){
879 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
880 $terminal = $value;
881 $terminal['type'] = "L";
882 } else {
883 $terminal = $value;
884 $terminal['type'] = "D";
885 $terminal['location'] = array_search($tmp, $this->config->departments);
886 $terminal['message'] = _("Workstation template for");
887 }
888 } elseif (in_array('gotoPrinter', $value["objectClass"])){
889 $terminal = $value;
890 $terminal['type'] = "P";
891 } elseif (in_array('goServer', $value["objectClass"])){
892 $terminal = $value;
893 $terminal['type'] = "S";
894 } elseif (in_array('goFonHardware', $value["objectClass"])){
895 $terminal = $value;
896 $terminal['type'] = "F";
897 } elseif (in_array('ieee802Device', $value["objectClass"])){
898 $terminal = $value;
899 $terminal['type'] = "C";
900 } else{
901 $name= preg_replace('/\$$/', '', $value['cn'][0]);
902 if (isset($value['sambaDomainName'])){
903 $domain= " [".$value['sambaDomainName'][0]."]";
904 } else {
905 $domain= "";
906 }
907 $terminal=$value;
908 $terminal['type'] ="W";
909 $terminal['domain'] = $name.$domain;
910 }
911 $this->terminals[]=$terminal;
912 }
913 }
915 $tmp=array();
916 foreach($this->terminals as $tkey => $val ){
917 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
918 }
919 ksort($tmp);
920 $this->terminals=array();
921 foreach($tmp as $val){
922 $this->terminals[]=$val;
923 }
924 reset ($this->terminals);
925 }
927 function remove_lock()
928 {
929 if (isset($this->systab->dn)){
930 del_lock ($this->systab->dn);
931 }
932 }
935 function get_system_type($classes)
936 {
937 $type= "";
939 if (in_array('ieee802Device', $classes)){
940 $type= "component";
941 }
942 if (in_array('gotoTerminal', $classes)){
943 $type= "terminal";
944 }
945 if (in_array('gotoWorkstation', $classes)){
946 $type= "workstation";
947 }
948 if (in_array('gotoPrinter', $classes)){
949 $type= "printer";
950 }
951 if (in_array('goFonHardware', $classes)){
952 $type= "phone";
953 }
954 if (in_array('goServer', $classes)){
955 $type= "server";
956 }
957 if (in_array('sambaAccount', $classes) ||
958 in_array('sambaSamAccount', $classes)){
959 $type= "winstation";
960 }
962 return ($type);
963 }
965 }
967 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
968 ?>