Code

Fixed two small typos.
[gosa.git] / gosa-plugins / systems / 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  */
21 class systems extends plugin
22 {
23   /* Definitions */
24   var $plHeadline     = "Systems";
25   var $plDescription  = "This does something";
26   var $departments    = array();
28   /* Dialog attributes */
29   var $systab   = NULL;
30   var $terminals= array();
31   var $ui       = NULL;
32   var $DivListSystem;
33   var $start_pasting_copied_objects = FALSE;
34   var $CopyPasteHandler   = NULL;
36   /* Arp hanlding activated */
37   var $arp_handling_active = FALSE;
39   function systems (&$config, $ui)
40   {
41     /* Save configuration for internal use */
42     $this->config= $config;
43     $this->ui= $ui;
45     /* Creat dialog object */
46     $this->DivListSystem = new divListSystem($this->config,$this);
48     /* Copy & Paste enabled ?*/
49     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
50       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
51     }
53     /* Check whether the arp handling active or not */
54     if($this->config->search("ArpNewDevice","CLASS",array('tabs')) != ""){
55       $this->arp_handling_active = TRUE;
56     }
58   }
61   function execute()
62   {
63     /* Call parent execute */
64     plugin::execute();
66     session::set('LOCK_VARS_TO_USE',array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/"));
68     /********************
69       Check for functional posts, edit|delete|add|... system devices 
70      ********************/
71     $s_action     = "";                       // Contains the action to proceed
72     $s_entry      = "";                       // The value for s_action
73     $base_back    = "";                       // The Link for Backbutton
74     $smarty       = get_smarty();
76     /* Test Posts */
77     foreach($_POST as $key => $val){
78       // Post for delete
79       if(preg_match("/system_del.*/",$key)){
80         $s_action = "del";
81         $s_entry  = preg_replace("/system_del_/i","",$key);
82         // Post for edit
83       }elseif(preg_match("/system_edit_.*/",$key)){
84         $s_action="edit";
85         $s_entry  = preg_replace("/system_edit_/i","",$key);
86         // Post for new
87       }elseif(preg_match("/system_new.*/",$key)){
88         $s_action="new";
89       }elseif(preg_match("/system_tplnew.*/i",$key)){
90         $s_action="new_tpl";
91       }elseif(preg_match("/system_setpwd_.*/i",$key)){
92         $s_action="change_pw";
93         $s_entry  = preg_replace("/system_setpwd_/i","",$key);
94       }elseif(preg_match("/gen_cd_.*/i",$key)){
95         $s_action="gen_cd";
96         $s_entry  = preg_replace("/gen_cd_/i","",$key);
97       }elseif(preg_match("/^copy_.*/",$key)){
98         $s_action="copy";
99         $s_entry  = preg_replace("/^copy_/i","",$key);
100       }elseif(preg_match("/^cut_.*/",$key)){
101         $s_action="cut";
102         $s_entry  = preg_replace("/^cut_/i","",$key);
103       }
104     }
105    
106     /* Incoming handling  
107      * If someone made a systemtype and ogroup selection 
108      * Display the new requested entry type ... servtab  in case of server and so on.
109      */
110     if(isset($_POST['SystemTypeChoosen'])){
111       $SelectedSystemType = session::get('SelectedSystemType');
112       $s_action = "SelectedSystemType";
113       $s_entry  = $_POST['SystemType'];
114       $SelectedSystemType['ogroup'] = $_POST['ObjectGroup'];
115       $this->systab = NULL;
116       session::set('SelectedSystemType',$SelectedSystemType);
117     }
119     /* remove image tags from posted entry  (posts looks like this 'name_x')*/
120     $s_entry  = preg_replace("/_.$/","",$s_entry);
122     /* Edit was requested by pressing the name(link) of an item */
123     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
124       $s_action ="edit";
125       $s_entry  = $_GET['id'];
126     }
127     /* Create options */
128     if(isset($_POST['menu_action']) && preg_match("/^newsystem_/",$_POST['menu_action'])){
129       $s_action = "newsystem";
130       $s_entry  = preg_replace("/^newsystem_/","",$_POST['menu_action']);
131     }
133     /* handle C&P from layers menu */
134     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
135       $s_action = "copy_multiple";
136     }
137     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
138       $s_action = "cut_multiple";
139     }
140     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
141       $s_action = "editPaste";
142     }
144     /* handle remove from layers menu */
145     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
146       $s_action = "del_multiple";
147     }
148     
150     /* Check for exeeded sizelimit */
151     if (($message= check_sizelimit()) != ""){
152       return($message);
153     }
155     /* Try to get informations about what kind of system to create */
156     if ($s_action=="new") {
157       return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
158     }
161     /********************
162       Copy & Paste Handling  ...
163      ********************/
165     /* Display the copy & paste dialog, if it is currently open */
166     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
167     if($ret){
168       return($ret);
169     }
170   
172     /********************
173       Create FAI CD ...   
174      ********************/
175     if ($s_action=="gen_cd"){
176       $this->dn= $this->terminals[$s_entry]['dn'];
177       session::set('objectinfo',$this->dn);
178       return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
179     }
182     /* Start CD-Creation */
183     if ((isset($_POST["cd_create"])) && !empty($this->dn)){
184       $smarty->assign("src", "?plug=".$_GET['plug']."&amp;PerformIsoCreation");
185       return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
186     }
189     if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
191       $return_button   = "<form method='get' action='main.php' target='_parent'>
192         <input type='submit' value='"._("Back")."'>
193         <input type='hidden' name='plug' value='".$_GET['plug']."'/>
194         </form>";
196       $dsc             = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
198       /* Get and check command */
199       $command= $this->config->search("workgeneric", "ISOCMD",array('tabs'));
200       
201       if (check_command($command)){
202         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
204         /* Print out html introduction */
205         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
206           <html>
207           <head>
208           <title></title>
209           <style type="text/css">@import url("themes/default/style.css");</style>
210           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
211           </head>
212           <body style="background: none; margin:4px;" id="body" >
213           <pre>';
215         /* Open process handle and check if it is a valid process */
216         $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
217         if (is_resource($process)) {
218           fclose($pipes[0]);
220           /* Print out returned lines && write JS to scroll down each line */
221           while (!feof($pipes[1])){
222             $cur_dat = fgets($pipes[1], 1024);
223             echo $cur_dat;
224             echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
225             flush();
226           }
227         }
229         /* Get error string && close streams */
230         $buffer= stream_get_contents($pipes[2]);
232         fclose($pipes[1]);
233         fclose($pipes[2]);
234         echo "</pre>";
236         /* Check return code */
237         $ret= proc_close($process);
238         if ($ret != 0){
239           echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
240           echo "<pre style='color:red'>$buffer</pre>";
241         }
245         echo $return_button."<br>";
247       } else {
248         $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
249         echo $tmp;
250       }
252       /* Scroll down completly */
253       echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
254       echo '</body></html>';
255       flush();
256       exit;
257     }
260     /********************
261       Create new system ...   
262      ********************/
263     /* Create new default terminal 
264      * Or create specified object of selected system type, from given incoming object  
265      */
267     $save_object_directly = false;
268     if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
269       $save_object_directly = true;
270     }
272     if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
274       /* If the current entry is an incoming object 
275        * $sw = System type as posted in new incoming handling dialog 
276        */ 
277       if($s_action == "SelectedSystemType") {
278         $sw         = $s_entry;
279       }else{
280         if(isset($_POST['system'])){
281           $sw = $_POST['system'];
282         }else{
283           $sw = $s_entry;
284         }
285         $this->dn= "new";
286       }
288       $tabs = array(
289           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
290           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
291           "server"      => array("CLASS"=>"SERVTABS",     "TABNAME"=>"servgeneric",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
292           "printer"     => array("CLASS"=>"PRINTTABS",    "TABNAME"=>"printgeneric",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
293           "phone"       => array("CLASS"=>"PHONETABS",    "TABNAME"=>"phoneGeneric",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
294           "component"   => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentGeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
296       if(isset($tabs[$sw])){
297         $class    = $tabs[$sw]["CLASS"];
298         $tabname  = $tabs[$sw]["TABNAME"];
299         $tabclass = $tabs[$sw]["TABCLASS"];
300         $acl_cat  = $tabs[$sw]["ACL"];
302         /* Load permissions for selected 'dn' and check if
303            we're allowed to remove this 'dn' */
304         $ui       = get_userinfo();
305         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
306         if(preg_match("/c/",$tabacl)){
307           $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
308           $this->systab->set_acl_base($this->DivListSystem->selectedBase);
309           $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
310           $this->systab->base = $this->DivListSystem->selectedBase;
311         }else{
312           print_red(_("You are not allowed to create a new object of this type."));
313         }
314       }
315     }
317     /********************
318       Edit system ...   
319      ********************/
321     /* User wants to edit data? */
322     if (($s_action == "edit") && (!isset($this->systab->config))){
324       $this->dn= $this->terminals[$s_entry]['dn'];
326       /* Check locking, save current plugin in 'back_plugin', so
327          the dialog knows where to return. */
328       if (($user= get_lock($this->dn)) != ""){
329         return(gen_locked_message ($user, $this->dn));
330       }
332       /* Find out more about the object type */
333       $ldap= $this->config->get_ldap_link();
334       $ldap->cat($this->dn, array('objectClass','gotoMode'));
335       $attrs= $ldap->fetch();
336       $type= $this->get_system_type($attrs);
338       /* Lock the current entry, so everyone will get the
339          above dialog */
340       $tabs = array(
341           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
342           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"),
343           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server"),
344           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer"),
345           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone"),
346           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation"),
347           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
350       if($type == "ArpNewDevice"){
351         $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn);
352       }elseif($type == "NewDevice"){
353         $this->systab = new SelectDeviceType($this->config,$this->dn) ;
354       }elseif(isset($tabs[$type])){
356         $class    = $tabs[$type]["CLASS"];
357         $acl_cat  = $tabs[$type]["ACL"];
358         $tabclass = $tabs[$type]["TABCLASS"];
360         $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
361         $this->systab->set_acl_base($this->dn);
362         session::set('objectinfo',$this->dn);
363         add_lock ($this->dn, $this->ui->dn);
364       }else{ 
365         print_red (_("You can't edit this object type yet!"));
366         del_lock($this->dn);
367       }
368     }
371     /********************
372       Change password ...   
373      ********************/
375     /* Set terminals root password */
376     if ($s_action=="change_pw"){
377       $tabs = array(
378           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
379           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
381       $type = $this->get_system_type($this->terminals[$s_entry]);
382       $class    = $tabs[$type]["CLASS"];
383       $tabname  = $tabs[$type]["TABNAME"];
384       $acl_cat  = $tabs[$type]["ACL"];
385       $tabclass = $tabs[$type]["TABCLASS"];
386       $ui       = get_userinfo();
387       $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
388       if(preg_match("/w/",$tabacl)){
389         $this->dn= $this->terminals[$s_entry]['dn'];
390         session::set('objectinfo',$this->dn);
391         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
392       }else{
393         print_red(_("You are not allowed to change the password for this object."));
394       }
395     }
398     /********************
399       Password change finish, but check if entered data is ok 
400      ********************/
402     /* Correctly specified? */
403     if (isset($_POST['password_finish'])){
404       if ($_POST['new_password'] != $_POST['repeated_password']){
405         print_red (_("Passwords entered as new and repeated do not match!"));
406         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
407       }
408     }
410     /********************
411       Password change finish
412      ********************/
414     /* Change terminal password */
415     if (isset($_POST['password_finish']) && 
416         $_POST['new_password'] == $_POST['repeated_password']){
418       /* Check if user is allowed to set password */
419       $tabs = array(
420           "terminal"    => array("CLASS"=>"TERMTABS",     "TABNAME"=>"termgeneric",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal"),
421           "workstation" => array("CLASS"=>"WORKTABS",     "TABNAME"=>"workgeneric",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation"));
423       /* Detect object type */
424       $type = "";
425       foreach($this->terminals as $terminal){
426         if($terminal['dn'] == $this->dn){
427           $type = $this->get_system_type($terminal);
428           break;
429         } 
430       }
432       /* Type detected */
433       if(!empty($type)){
435         /* Get infos */
436         $class    = $tabs[$type]["CLASS"];
437         $tabname  = $tabs[$type]["TABNAME"];
438         $acl_cat  = $tabs[$type]["ACL"];
439         $tabclass = $tabs[$type]["TABCLASS"];
440     
441         /* Get acls */
442         $ui       = get_userinfo();
443         $tabacl   = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
445         /* Check acls */
446         if(preg_match("/w/",$tabacl)){
447           $ldap = $this->config->get_ldap_link();
448           $ldap->cd($this->dn);
450           $attrs= array();
451           if ($_POST['new_password'] == ""){
452             $attrs['gotoRootPasswd']= array();
453           } else {
454             $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
455           }
456           $ldap->modify($attrs);
457           new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
458         }else{
459           print_red(_("You are not allowed to change the password for this object."));
460         }
461       }else{
462         print_red(_("Can't detect object to change password."));
463       }
464       session::un_set('objectinfo');
465     }
468     /********************
469       Delete system cancel
470      ********************/
472     /* Delete terminal canceled? */
473     if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
474       del_lock ($this->dn);
475       session::un_set('objectinfo');
476     }
479     /********************
480       Delete MULTIPLE entries requested, display confirm dialog
481      ********************/
483     if ($s_action=="del_multiple"){
484       $this->dns = array();
485       $ids = $this->list_get_selected_items();
487       if(count($ids)){
489         foreach($ids as $id){
490           $dn = $this->terminals[$id]['dn'];
491           if (($user= get_lock($dn)) != ""){
492             return(gen_locked_message ($user, $dn));
493           }
494           $this->dns[$id] = $dn;
495         }
497         $dns_names = "<br><pre>";
498         foreach($this->dns as $dn){
499           add_lock ($dn, $this->ui->dn);
500           $dns_names .= $dn."\n";
501         }
502         $dns_names .="</pre>";
504         /* Lock the current entry, so nobody will edit it during deletion */
505         if (count($this->dns) == 1){
506           $smarty->assign("warning",     sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
507         } else {
508           $smarty->assign("warning",     sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
509         }
510         $smarty->assign("multiple", true);
511         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
512       }
513     }
516     /********************
517       Delete MULTIPLE entries confirmed
518      ********************/
520     /* Confirmation for deletion has been passed. Users should be deleted. */
521     if (isset($_POST['delete_multiple_system_confirm'])){
523       $ui = get_userinfo();
524       $tabs = array(
525           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
526           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
527           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
528           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
529           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
530           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
531           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
532           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
533           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
536       /* Remove user by user and check acls before removeing them */
537       foreach($this->dns as $key => $dn){
539         /* Get 'dn' from posted termlinst */
540         $attrs    = $this->terminals[$key];
541         $type= $this->get_system_type($attrs);
543         /* get object type */
544         $tabtype  = "termtabs";
545         $tabobj   = "TERMTABS";
546         $tabacl   = "";
547         if(isset($tabs[$type])){
548           $tabtype = $tabs[$type]['TABCLASS'];
549           $tabobj  = $tabs[$type]['CLASS'];
550           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
552           /* Load permissions for selected 'dn' and check if
553              we're allowed to remove this 'dn' */
554           if(preg_match("/d/",$tabacl)){ 
556             /* Delete request is permitted, perform LDAP action */
557             if($tabtype=="phonetabs"){
558               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
559               $this->systab->set_acl_base($dn);
560               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
561             }else{
562               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
563               $this->systab->set_acl_base($dn);
564               $this->systab->delete();
565             }
566             unset ($this->systab);
567             $this->systab= NULL;
569           } else {
570             /* Normally this shouldn't be reached, send some extra
571                logs to notify the administrator */
572             print_red (_("You are not allowed to delete this component!"));
573             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
574           }
575           /* Remove lock file after successfull deletion */
576           del_lock ($dn);
577           unset($this->dns[$key]);
578         }
579       }
580     }
582     /********************
583       Delete MULTIPLE entries Canceled
584      ********************/
586     /* Remove lock */
587    if(isset($_POST['delete_multiple_system_cancel'])){
588       foreach($this->dns as $key => $dn){
589         del_lock ($dn);
590         unset($this->dns[$key]);
591       }
592     }
595     /********************
596       Delete system, confirm dialog
597      ********************/
599     /* Remove terminal was requested */
600     if ($s_action=="del"){
602       /* Get 'dn' from posted termlinst */
603       $this->dn = $this->terminals[$s_entry]['dn'];
604       $attrs    = $this->terminals[$s_entry];
606   
608       $type= $this->get_system_type($attrs);
609       $ui = get_userinfo();
610       $tabs = array(
611           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
612           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
613           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
614           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
615           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
616           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
617           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
618           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
619           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
621       /* get object type */
622       $tabtype  = "termtabs";
623       $tabobj   = "TERMTABS";
624       $tabacl   = "";
625       if(isset($tabs[$type])){
626         $tabtype = $tabs[$type]['TABCLASS'];
627         $tabobj  = $tabs[$type]['CLASS'];
628         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
629       }
631       /* Load permissions for selected 'dn' and check if
632          we're allowed to remove this 'dn' */
633       if(preg_match("/d/",$tabacl)){ 
635         /* Check locking, save current plugin in 'back_plugin', so
636            the dialog knows where to return. */
637         if (($user= get_lock($this->dn)) != ""){
638           return(gen_locked_message ($user, $this->dn));
639         }
641         /* Lock the current entry, so nobody will edit it during deletion */
642         add_lock ($this->dn, $this->ui->dn);
643         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
644         $smarty->assign("multiple", false);
645         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
646       } else {
648         /* Obviously the user isn't allowed to delete. Show message and
649            clean session. */
650         print_red (_("You are not allowed to delete this component!"));
651       }
652     }
655     /********************
656       Delete system, confirmed
657      ********************/
658     /* Confirmation for deletion has been passed. Terminal should be deleted. */
659     if (isset($_POST['delete_terminal_confirm'])){
661       /* Find out more about the object type */
662       $ldap= $this->config->get_ldap_link();
663       $ldap->cat($this->dn, array('objectClass'));
664       $attrs= $ldap->fetch();
665       $type= $this->get_system_type($attrs);
667       $ui = get_userinfo();
669       $tabs = array(
670           "ArpNewDevice"=> array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
671           "NewDevice"   => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "incoming/systems"),
672           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
673           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
674           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
675           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
676           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
677           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
678           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
680       /* get object type */
681       $tabtype  = "termtabs";
682       $tabobj   = "TERMTABS";
683       $tabacl   = "";
684       if(isset($tabs[$type])){
685         $tabtype = $tabs[$type]['TABCLASS'];
686         $tabobj  = $tabs[$type]['CLASS'];
687         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
688       }
690       /* Check if we are allowed to remove this object */
691       if(preg_match("/d/",$tabacl)){
693         /* Delete request is permitted, perform LDAP action */
694         if($tabtype=="phonetabs"){
695           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
696           $this->systab->set_acl_base($this->dn);
697           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
698         }else{  
699           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
700           $this->systab->set_acl_base($this->dn);
701           $this->systab->delete();
702         }
703         unset ($this->systab);
704         $this->systab= NULL;
706         /* Terminal list has changed, reload it. */
707       } else {
709         /* Normally this shouldn't be reached, send some extra
710            logs to notify the administrator */
711         print_red (_("You are not allowed to delete this component!"));
712         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
713       }
715       /* Remove lock file after successfull deletion */
716       del_lock ($this->dn);
717     }
727    /********************
728       Edit system type finished, check if everything went ok
729      ********************/
730     /* Finish user edit is triggered by the tabulator dialog, so
731        the user wants to save edited data. Check and save at this
732        point. */
733     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
735       /* Check tabs, will feed message array */
736       $message = array();
737       if(!$save_object_directly){
738         $message = $this->systab->check();
739       }else{
740         $found = false;
742         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
743         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
744           if(isset($this->systab->by_object[$tab]->gotoMode)) {
745             $found = true;
746             $this->systab->by_object[$tab]->gotoMode = $value;
747           }
748         }
749         if(!$found){
750           print_red(sprintf(_("Can't set gotoMode to status 'active', the current object couldn't be identified.")));
751         }
753       }
754       /* Save, or display error message? */
755       if (count($message) == 0){
757         /* Incoming behavior; you can select a system type and an ogroup membership.
758          * If this object is an Incoming object, session::get('SelectedSystemType') isset.
759          * Check if we must add the new object to an object group.
760          *
761          * If this is done, delete the old incoming entry... it is still there, because this is a new
762          * entry and not an edited one, so we will delete it.
763          *
764          */
766         if(session::is_set('SelectedSystemType')){
767           $SelectedSystemType = session::get('SelectedSystemType');
768           if($SelectedSystemType['ogroup'] != "none"){
769             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
770             if($og){
771               $og->AddDelMembership($this->systab->dn);
772               $og->save();
773             }
774           }
775         }
777         /* Save terminal data to ldap */
778         $SelectedSystemType = session::get('SelectedSystemType');
779         if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
780           foreach (array("workservice", "termservice") as $cls){
781             if (isset($this->systab->by_object[$cls])){
782               $this->systab->by_object[$cls]->gotoXMouseport= "";
783               $this->systab->by_object[$cls]->gotoXMouseType= "";
784               $this->systab->by_object[$cls]->gotoXResolution= "";
785               $this->systab->by_object[$cls]->gotoXColordepth= "";
786             }
787           }
788         }
790         $this->systab->save();
792         if(session::is_set('SelectedSystemType')){
793           session::un_set('SelectedSystemType');
794           if(!isset($ldap)){
795             $ldap = $this->config->get_ldap_link();
796           }
797           $ldap->cd ($this->dn);
798           $ldap->cat($this->dn, array('dn'));
799           if(count($ldap->fetch())){
800             $ldap->cd($this->dn);
801             $ldap->rmDir($this->dn);
802           }
803           $ldap->cd($this->config->current['BASE']);
804         }
806         /* Terminal has been saved successfully, remove lock from LDAP. */
807         if (!isset($_POST['edit_apply'])){
808           if ($this->dn != "new"){
809             del_lock ($this->dn);
810           }
812           unset ($this->systab);
813           $this->systab= NULL;
814           session::un_set('objectinfo');
815         }
816       } else {
817         /* Ok. There seem to be errors regarding to the tab data,
818            show message and continue as usual. */
819         show_errors($message);
820       }
821     }
824     /********************
825       Edit system was canceled 
826      ********************/
827     /* Cancel dialogs */
828     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
829       if (isset($this->systab)){
830         del_lock ($this->systab->dn);
831         unset ($this->systab);
832       }
833       $this->systab= NULL;
834       session::un_set('objectinfo');
836       /* Remove ogroup selection, which was set while editing a new incoming entry */
837       if(session::is_set('SelectedSystemType')){
838         session::un_set('SelectedSystemType');
839       }
840     }
842     /********************
843       Display edit dialog, or some other
844      ********************/
846     /* Show tab dialog if object is present */
847     if (isset($this->systab->config)){
848       $display= $this->systab->execute();
850       /* Don't show buttons if tab dialog requests this */
852       $dialog     = FALSE;
853       $hide_apply = $this->dn == "new";
854       if(is_object($this->systab) && !isset($this->systab->by_object)){
855         $dialog = TRUE;
856         $hide_apply = TRUE;
857       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
858         $dia = $this->systab->by_object[$this->systab->current]->dialog;
859         if($dia === TRUE || is_object($dia)){
860           $dialog = TRUE;
861         }  
862       }
863       if(isset($this->systab->current) && isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
864         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
865         $dialog = TRUE;
866       }
868       if (!$dialog){
869         $display.= "<p style=\"text-align:right\">\n";
870         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
871         $display.= "&nbsp;\n";
872         if (!$hide_apply){
873           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
874           $display.= "&nbsp;\n";
875         }
876         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
877         $display.= "</p>";
878       }
879       return ($display);
880     }
882     /* Check if there is a snapshot dialog open */
883     $base = $this->DivListSystem->selectedBase;
884     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
885       return($str);
886     }
888     /* Display dialog with system list */
889     $this->DivListSystem->parent = $this;
890     $this->DivListSystem->execute();
892     /* Add departments if subsearch is disabled */
893     if(!$this->DivListSystem->SubSearch){
894       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
895     }
896     $this->reload();
897     $this->DivListSystem->setEntries($this->terminals);
898     return($this->DivListSystem->Draw());
899   }
902   /* Return departments, that will be included within snapshot detection */
903   function get_used_snapshot_bases()
904   {
905     $tmp = array();
907     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
909     $tabs = array(
910         "terminal"        => get_ou('terminalou'),
911         "workstation"     => get_ou('workstationou'),
912         "incoming"        => get_ou('incomingou'),
913         "server"          => get_ou('serverou'),
914         "printer"         => get_ou('printerou'),
915         "phone"           => get_ou('phoneou'),
916         "winworkstation"  => get_winstations_ou(),
917         "component"       => get_ou('componentou')
918         ); 
920     foreach($tabs as $acl_cat => $dn){
922       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
923       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
924         $tmp[] = $dn.$this->DivListSystem->selectedBase;
925       }
926     }
927     return($tmp); 
928   }
931   function remove_from_parent()
932   {
933     /* Optionally execute a command after we're done */
934     $this->postremove();
935   }
938   /* Save data to object */
939   function save_object()
940   {
941     $this->DivListSystem->save_object();
942   }
945   /* Check values */
946   function check()
947   {
948   }
951   /* Save to LDAP */
952   function save()
953   {
954   }
956   function adapt_from_template($dn)
957   {
958   }
960   function password_change_needed()
961   {
962   }
964   function reload()
965   {
966     /* some var init */
967     $ui = get_userinfo();
968     $res              = array();
969     $this->terminals  = array();
970     $userregex        = "";
972     /* Set base for all searches */
973     $base=  $this->DivListSystem->selectedBase;
975     /* Prepare samba class name */
976     $samba  ="";
977     if ($this->DivListSystem->ShowWinWorkstations){
978       if ($this->config->current['SAMBAVERSION'] == "3"){
979         $samba= "sambaSamAccount";
980       } else {
981         $samba= "sambaAccount";
982       }
983     }
985     /* This array represents the combination between checkboxes and search filters */
986     $objs = array( 
987         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
988         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
989         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
990         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
991         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
992         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
993         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
995     /* Include the 'Display Systems of user' attribute */ 
996     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
997       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
998     }
1000     /* Attributes to fetch */
1001     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
1002     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer","incoming");
1004     /* Add FAIstate to attributes if FAI is activated */
1005     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1006     if(!empty($tmp)){
1007       $sys_attrs[] = "FAIstate";
1008     }    
1010     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1011     foreach($objs as $checkBox => $oc){
1012       if($this->DivListSystem->$checkBox){
1013         if($this->DivListSystem->SubSearch){
1014           if($oc['CLASS'] != ""){
1015             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1016             $new_res = get_sub_list($filter, $sys_categories ,preg_replace("/,.*$/","",$base), $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
1017       
1018             /* Remove all objects that are not in the expected sub department */
1019             foreach($new_res as $key => $obj){
1020               if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
1021                 $res[$obj['dn']] = $obj;
1022               }
1023             }
1024           }
1025         }else{
1026           /* User filter? */
1027           if($oc['CLASS'] != ""){
1028             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1029             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
1030           }
1031         }
1032       } 
1033     }
1035     /* Search for incoming objects */ 
1036     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1037     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou').$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
1039     /* Get all gotoTerminal's */
1040     foreach ($res as $value){
1042       $tmp= $value['dn'];
1043       $add= "";
1045       /* Extract base */
1046       foreach($objs as $obj){
1047         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1048           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1049         }
1050       }
1052       /* Create a string containing the last part of the department. */
1053       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1054       if(empty($dn_name)){
1055         $dn_name = "/";
1056       }
1058       /* check if current object is a new one */
1059       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1060         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1061           $add= "- "._("New terminal");
1062         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1063           $add= "- "._("New workstation");
1064         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1065           $add= "- "._("Unknown device");
1066         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1067           $add= "- "._("New Device");
1068         }
1069       } 
1071       /* Detect type of object and create an entry for $this->terminals */
1072       $terminal = array();
1073       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1075         /* check acl */
1076         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1077         if($add != "" || preg_match("/r/",$acl)) {
1078           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1079             $terminal             = $value;
1080             $terminal['type']     = "T";
1081             $terminal['is_new']   = $add;
1082           } else {
1083             $terminal             = $value;
1084             $terminal['type']     = "D";
1085             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1086             $terminal['location'] = array_search($tmp, $this->config->departments); 
1087           }
1088         }
1089       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1091         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1092         if($add != "" || preg_match("/r/",$acl)) {
1093           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1094             $terminal             = $value;
1095             $terminal['type']     = "L";
1096             $terminal['is_new']   = $add;
1097           } else {
1098             $terminal             = $value;
1099             $terminal['type']     = "D";
1100             $terminal['location'] = array_search($tmp, $this->config->departments);
1101             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1102           }
1103           if (isset($value["FAIstate"][0])){
1104             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1105           }
1106         }
1107       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1108        
1109    
1110         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1111         if($add != "" || preg_match("/r/",$acl)) {
1113           $terminal             = $value;
1114           $terminal['type']     = "P";
1115         }
1116       } elseif (in_array_ics('goServer', $value["objectClass"])){
1118         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1119         if($add != "" || preg_match("/r/",$acl)) {
1121           $terminal             = $value;
1122           $terminal['type']     = "S";
1123           if (isset($value["FAIstate"][0])){
1124             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1125           }
1126         }
1127       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1129         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1130         if($add != "" || preg_match("/r/",$acl)) {
1132           $terminal             = $value;
1133           $terminal['type']     = "F";
1134         }
1135       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1137         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1138                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1139                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1140         if($add != "" || preg_match("/r/",$acl)) {
1142           $terminal = $value;
1143           $terminal['type']   = "Q";
1144           $terminal['is_new'] = $add;
1145         }
1146       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1148         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1149         if($add != "" || preg_match("/r/",$acl)) {
1151           $terminal             = $value;
1152           $terminal['type']     = "C";
1153         }
1154       } else{
1156         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1157         if (isset($value['sambaDomainName'])){
1158           $domain= " [".$value['sambaDomainName'][0]."]";
1159         } else {
1160           $domain= "";
1161         }
1162         $terminal=$value;
1163         $terminal['type']     ="W";
1164         $terminal['domain']   = $name.$domain;
1165       }
1167       if(count($terminal)){
1168         $this->terminals[]=$terminal;
1169       }
1170     }
1172     $tmp  =array();
1173     $tmp2 =array();
1174     foreach($this->terminals as $tkey => $val ){
1175       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1176       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1177     }
1178     natcasesort($tmp2);
1179     $this->terminals=array();
1180     foreach($tmp2 as $val){
1181       $this->terminals[]=$tmp[$val];
1182     }
1183     reset ($this->terminals);
1184   }
1186   function remove_lock()
1187   {
1188     if (isset($this->systab->dn)){
1189       del_lock ($this->systab->dn);
1190     }
1191   }
1194   function copyPasteHandling_from_queue($s_action,$s_entry)
1195   {
1196     /* Check if Copy & Paste is disabled */
1197     if(!is_object($this->CopyPasteHandler)){
1198       return("");
1199     }
1202     $tabs = array(
1203         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1204           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1205         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1206           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1207         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1208           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1209         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1210           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1211         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1212           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1213         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1214           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1216     /* Add a single entry to queue */
1217     if($s_action == "cut" || $s_action == "copy"){
1219       /* Cleanup object queue */
1220       $this->CopyPasteHandler->cleanup_queue();
1221       $dn     = $this->terminals[$s_entry]['dn'];
1222       $oc     = $this->terminals[$s_entry]['objectClass'];
1223       $type   = $this->get_system_type($this->terminals[$s_entry]);
1225       $tab_o  = $tabs[$type]['CLASS'];
1226       $tab_c  = $tabs[$type]['TABCLASS'];
1227       $acl    = $tabs[$type]['ACL'];
1229       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1230     }
1232     /* Add entries to queue */
1233     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1235       /* Cleanup object queue */
1236       $this->CopyPasteHandler->cleanup_queue();
1238       /* Add new entries to CP queue */
1239       foreach($this->list_get_selected_items() as $id){
1240         $dn = $this->terminals[$id]['dn'];
1241         $oc = $this->terminals[$id]['objectClass']; 
1242         $type = $this->get_system_type($this->terminals[$id]);
1244         if(isset($tabs[$type])){
1245           $tab_o  = $tabs[$type]['CLASS'];
1246           $tab_c  = $tabs[$type]['TABCLASS'];
1247           $acl    = $tabs[$type]['ACL'];
1249           if($s_action == "copy_multiple"){
1250             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1251           }
1252           if($s_action == "cut_multiple"){
1253             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1254           }
1255         }
1256       }
1257     }
1259     /* Start pasting entries */
1260     if($s_action == "editPaste"){
1261       $this->start_pasting_copied_objects = TRUE;
1262     }
1263   
1264     /* Return C&P dialog */
1265     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1266     
1267       /* Load entry from queue and set base */
1268       $this->CopyPasteHandler->load_entry_from_queue();
1269       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1271       /* Get dialog */
1272       $data = $this->CopyPasteHandler->execute();
1274       /* Return dialog data */
1275       if(!empty($data)){
1276         return($data);
1277       }
1278     }
1280     /* Automatically disable status for pasting */
1281     if(!$this->CopyPasteHandler->entries_queued()){
1282       $this->start_pasting_copied_objects = FALSE;
1283     }
1284     return("");
1285   }
1288   function get_system_type($attrs)
1289   {
1290     $classes = $attrs['objectClass'];
1292     $type= "";
1293     if (in_array_ics('ieee802Device', $classes)){
1294       $type= "component";
1295     }elseif (in_array_ics('gotoTerminal', $classes)){
1296       $type= "terminal";
1297     }elseif (in_array_ics('gotoWorkstation', $classes)){
1298       $type= "workstation";
1299     }elseif (in_array_ics('gotoPrinter', $classes)){
1300       $type= "printer";
1301     }elseif (in_array_ics('goFonHardware', $classes)){
1302       $type= "phone";
1303     }elseif (in_array_ics('goServer', $classes)){
1304       $type= "server";
1305     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1306       $type= "ArpNewDevice";
1307     }elseif (in_array_ics('GOhard', $classes)){
1308       $type= "NewDevice";
1309     }elseif (in_array_ics('sambaAccount', $classes) ||
1310         in_array_ics('sambaSamAccount', $classes)){
1311       $type= "winstation";
1312     }
1313     return ($type);
1314   }
1317   function convert_list($input)
1318   {
1319     $temp= "";
1320     $conv= array(       
1321         "NQ" => array("select_newsystem.png",_("New System from incoming")),
1322         "D" => array("select_default.png",_("Template")),
1323         "T" => array("select_terminal.png",_("Terminal")),
1324         "L" => array("select_workstation.png",_("Workstation")),
1325         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1326         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1327         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1328         "F" => array("select_phone.png",_("Phone")),
1329         "S" => array("select_server.png",_("Server")),
1330         "GS" => array("select_server_green.png",_("Server is installing")),
1331         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1332         "RS" => array("select_server_red.png",_("Server installation failed")),
1333         "W" => array("select_winstation.png",_("Winstation")),
1334         "C" => array("select_component.png",_("Network Device")),
1335         "NT"=> array("select_new_terminal.png",_("New Terminal")),
1336         "NL"=> array("select_new_workstation.png",_("New Workstation")),
1337         "P" => array("select_printer.png",_("Printer")));
1339     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1340       $input['type']="N".$input['type'];
1341     }
1342     foreach ($conv  as $key => $value){
1343       if($input['type']==$key){
1344         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1345         $tmp['class']=$key;
1346         return $tmp;
1347       }
1348     }
1349   }
1351   
1352   function getState($type, $state)
1353   {
1354     switch (preg_replace('/:.*$/', '', $state)) {
1355       case 'installing':
1356                 $type= 'G'.$type;
1357                 break;
1358       case 'error':
1359                 $type= 'R'.$type;
1360                 break;
1361       case 'install':
1362       case 'sysinfo':
1363       case 'softupdate':
1364       case 'scheduledupdate':
1365                 $type= 'Y'.$type;
1366                 break;
1367     }
1370     return ($type);
1371   }
1374   function list_get_selected_items()
1375   {
1376     $ids = array();
1377     foreach($_POST as $name => $value){
1378       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1379         $id   = preg_replace("/^item_selected_/","",$name);
1380         $ids[$id] = $id;
1381       }
1382     }
1383     return($ids);
1384   }
1387   /* !! Incoming dummy acls, required to defined acls for incoming objects
1388    */
1389   static function plInfo()
1390   {
1391     return (array(
1392           "plShortName"   => _("Incoming objects"),
1393           "plDescription" => _("Incoming objects"),
1394           "plSelfModify"  => FALSE,
1395           "plDepends"     => array(),
1396           "plPriority"    => 99,
1397           "plSection"     => array("administration"),
1398           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1399                                                           "objectClass"  => "")),
1400           "plProvidedAcls"=> array()
1401             
1402           ));
1403   }
1406   
1410 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1411 ?>