Code

75ac762c35d8375a477913f572e22f36c3aa4bcb
[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           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
526           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
527           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
528           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
529           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
530           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
531           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
534       /* Remove user by user and check acls before removeing them */
535       foreach($this->dns as $key => $dn){
537         /* Get 'dn' from posted termlinst */
538         $attrs    = $this->terminals[$key];
539         $type= $this->get_system_type($attrs);
541         /* get object type */
542         $tabtype  = "termtabs";
543         $tabobj   = "TERMTABS";
544         $tabacl   = "";
545         if(isset($tabs[$type])){
546           $tabtype = $tabs[$type]['TABCLASS'];
547           $tabobj  = $tabs[$type]['CLASS'];
548           $tabacl  = $ui->get_permissions($dn,$tabs[$type]['ACL']);
550           /* Load permissions for selected 'dn' and check if
551              we're allowed to remove this 'dn' */
552           if(preg_match("/d/",$tabacl)){ 
554             /* Delete request is permitted, perform LDAP action */
555             if($tabtype=="phonetabs"){
556               $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
557               $this->systab->set_acl_base($dn);
558               $this->systab->by_object['phoneGeneric']->remove_from_parent ();
559             }else{
560               $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type);
561               $this->systab->set_acl_base($dn);
562               $this->systab->delete();
563             }
564             unset ($this->systab);
565             $this->systab= NULL;
567           } else {
568             /* Normally this shouldn't be reached, send some extra
569                logs to notify the administrator */
570             print_red (_("You are not allowed to delete this component!"));
571             new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
572           }
573           /* Remove lock file after successfull deletion */
574           del_lock ($dn);
575           unset($this->dns[$key]);
576         }
577       }
578     }
580     /********************
581       Delete MULTIPLE entries Canceled
582      ********************/
584     /* Remove lock */
585    if(isset($_POST['delete_multiple_system_cancel'])){
586       foreach($this->dns as $key => $dn){
587         del_lock ($dn);
588         unset($this->dns[$key]);
589       }
590     }
593     /********************
594       Delete system, confirm dialog
595      ********************/
597     /* Remove terminal was requested */
598     if ($s_action=="del"){
600       /* Get 'dn' from posted termlinst */
601       $this->dn = $this->terminals[$s_entry]['dn'];
602       $attrs    = $this->terminals[$s_entry];
604       $type= $this->get_system_type($attrs);
605       $ui = get_userinfo();
606       $tabs = array(
607           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
608           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
609           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
610           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
611           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
612           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
613           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
616       /* get object type */
617       $tabtype  = "termtabs";
618       $tabobj   = "TERMTABS";
619       $tabacl   = "";
620       if(isset($tabs[$type])){
621         $tabtype = $tabs[$type]['TABCLASS'];
622         $tabobj  = $tabs[$type]['CLASS'];
623         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
624       }
626       /* Load permissions for selected 'dn' and check if
627          we're allowed to remove this 'dn' */
628       if(preg_match("/d/",$tabacl)){ 
630         /* Check locking, save current plugin in 'back_plugin', so
631            the dialog knows where to return. */
632         if (($user= get_lock($this->dn)) != ""){
633           return(gen_locked_message ($user, $this->dn));
634         }
636         /* Lock the current entry, so nobody will edit it during deletion */
637         add_lock ($this->dn, $this->ui->dn);
638         $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
639         $smarty->assign("multiple", false);
640         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
641       } else {
643         /* Obviously the user isn't allowed to delete. Show message and
644            clean session. */
645         print_red (_("You are not allowed to delete this component!"));
646       }
647     }
650     /********************
651       Delete system, confirmed
652      ********************/
653     /* Confirmation for deletion has been passed. Terminal should be deleted. */
654     if (isset($_POST['delete_terminal_confirm'])){
656       /* Find out more about the object type */
657       $ldap= $this->config->get_ldap_link();
658       $ldap->cat($this->dn, array('objectClass'));
659       $attrs= $ldap->fetch();
660       $type= $this->get_system_type($attrs);
662       $ui = get_userinfo();
664       $tabs = array(
665           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
666           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
667           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
668           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
669           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
670           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
671           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
673       /* get object type */
674       $tabtype  = "termtabs";
675       $tabobj   = "TERMTABS";
676       $tabacl   = "";
677       if(isset($tabs[$type])){
678         $tabtype = $tabs[$type]['TABCLASS'];
679         $tabobj  = $tabs[$type]['CLASS'];
680         $tabacl  = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
681       }
683       /* Check if we are allowed to remove this object */
684       if(preg_match("/d/",$tabacl)){
686         /* Delete request is permitted, perform LDAP action */
687         if($tabtype=="phonetabs"){
688           $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
689           $this->systab->set_acl_base($this->dn);
690           $this->systab->by_object['phoneGeneric']->remove_from_parent ();
691         }else{  
692           $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
693           $this->systab->set_acl_base($this->dn);
694           $this->systab->delete();
695         }
696         unset ($this->systab);
697         $this->systab= NULL;
699         /* Terminal list has changed, reload it. */
700       } else {
702         /* Normally this shouldn't be reached, send some extra
703            logs to notify the administrator */
704         print_red (_("You are not allowed to delete this component!"));
705         new log("security","systems/".get_class($this),$dn,array(),"Tried to trick deletion.");
706       }
708       /* Remove lock file after successfull deletion */
709       del_lock ($this->dn);
710     }
720    /********************
721       Edit system type finished, check if everything went ok
722      ********************/
723     /* Finish user edit is triggered by the tabulator dialog, so
724        the user wants to save edited data. Check and save at this
725        point. */
726     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config)) || $save_object_directly){
728       /* Check tabs, will feed message array */
729       $message = array();
730       if(!$save_object_directly){
731         $message = $this->systab->check();
732       }else{
733         $found = false;
735         /* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
736         foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
737           if(isset($this->systab->by_object[$tab]->gotoMode)) {
738             $found = true;
739             $this->systab->by_object[$tab]->gotoMode = $value;
740           }
741         }
742         if(!$found){
743           print_red(sprintf(_("Can't set gotoMode to status 'active', the current object couldn't be identified.")));
744         }
746       }
747       /* Save, or display error message? */
748       if (count($message) == 0){
750         /* Incoming behavior; you can select a system type and an ogroup membership.
751          * If this object is an Incoming object, session::get('SelectedSystemType') isset.
752          * Check if we must add the new object to an object group.
753          *
754          * If this is done, delete the old incoming entry... it is still there, because this is a new
755          * entry and not an edited one, so we will delete it.
756          *
757          */
759         if(session::is_set('SelectedSystemType')){
760           $SelectedSystemType = session::get('SelectedSystemType');
761           if($SelectedSystemType['ogroup'] != "none"){
762             $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
763             if($og){
764               $og->AddDelMembership($this->systab->dn);
765               $og->save();
766             }
767           }
768         }
770         /* Save terminal data to ldap */
771         $SelectedSystemType = session::get('SelectedSystemType');
772         if(isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
773           foreach (array("workservice", "termservice") as $cls){
774             if (isset($this->systab->by_object[$cls])){
775               $this->systab->by_object[$cls]->gotoXMouseport= "";
776               $this->systab->by_object[$cls]->gotoXMouseType= "";
777               $this->systab->by_object[$cls]->gotoXResolution= "";
778               $this->systab->by_object[$cls]->gotoXColordepth= "";
779             }
780           }
781         }
783         $this->systab->save();
785         if(session::is_set('SelectedSystemType')){
786           session::un_set('SelectedSystemType');
787           if(!isset($ldap)){
788             $ldap = $this->config->get_ldap_link();
789           }
790           $ldap->cd ($this->dn);
791           $ldap->cat($this->dn, array('dn'));
792           if(count($ldap->fetch())){
793             $ldap->cd($this->dn);
794             $ldap->rmDir($this->dn);
795           }
796           $ldap->cd($this->config->current['BASE']);
797         }
799         /* Terminal has been saved successfully, remove lock from LDAP. */
800         if (!isset($_POST['edit_apply'])){
801           if ($this->dn != "new"){
802             del_lock ($this->dn);
803           }
805           unset ($this->systab);
806           $this->systab= NULL;
807           session::un_set('objectinfo');
808         }
809       } else {
810         /* Ok. There seem to be errors regarding to the tab data,
811            show message and continue as usual. */
812         show_errors($message);
813       }
814     }
817     /********************
818       Edit system was canceled 
819      ********************/
820     /* Cancel dialogs */
821     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
822       if (isset($this->systab)){
823         del_lock ($this->systab->dn);
824         unset ($this->systab);
825       }
826       $this->systab= NULL;
827       session::un_set('objectinfo');
829       /* Remove ogroup selection, which was set while editing a new incoming entry */
830       if(session::is_set('SelectedSystemType')){
831         session::un_set('SelectedSystemType');
832       }
833     }
835     /********************
836       Display edit dialog, or some other
837      ********************/
839     /* Show tab dialog if object is present */
840     if (isset($this->systab->config)){
841       $display= $this->systab->execute();
843       /* Don't show buttons if tab dialog requests this */
845       $dialog     = FALSE;
846       $hide_apply = $this->dn == "new";
847       if(is_object($this->systab) && !isset($this->systab->by_object)){
848         $dialog = TRUE;
849         $hide_apply = TRUE;
850       }elseif(isset($this->systab->by_object[$this->systab->current]->dialog)){
851         $dia = $this->systab->by_object[$this->systab->current]->dialog;
852         if($dia === TRUE || is_object($dia)){
853           $dialog = TRUE;
854         }  
855       }
856       if(isset($this->systab->by_object[$this->systab->current]->netConfigDNS) && 
857         $this->systab->by_object[$this->systab->current]->netConfigDNS->dialog){
858         $dialog = TRUE;
859       }
861       if (!$dialog){
862         $display.= "<p style=\"text-align:right\">\n";
863         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
864         $display.= "&nbsp;\n";
865         if (!$hide_apply){
866           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
867           $display.= "&nbsp;\n";
868         }
869         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
870         $display.= "</p>";
871       }
872       return ($display);
873     }
875     /* Check if there is a snapshot dialog open */
876     $base = $this->DivListSystem->selectedBase;
877     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
878       return($str);
879     }
881     /* Display dialog with system list */
882     $this->DivListSystem->parent = $this;
883     $this->DivListSystem->execute();
885     /* Add departments if subsearch is disabled */
886     if(!$this->DivListSystem->SubSearch){
887       $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1);
888     }
889     $this->reload();
890     $this->DivListSystem->setEntries($this->terminals);
891     return($this->DivListSystem->Draw());
892   }
895   /* Return departments, that will be included within snapshot detection */
896   function get_used_snapshot_bases()
897   {
898     $tmp = array();
900     /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
902     $tabs = array(
903         "terminal"        => get_ou('terminalou'),
904         "workstation"     => get_ou('workstationou'),
905         "incoming"        => get_ou('incomingou'),
906         "server"          => get_ou('serverou'),
907         "printer"         => get_ou('printerou'),
908         "phone"           => get_ou('phoneou'),
909         "winworkstation"  => get_winstations_ou(),
910         "component"       => get_ou('componentou')
911         ); 
913     foreach($tabs as $acl_cat => $dn){
915       $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
916       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
917         $tmp[] = $dn.$this->DivListSystem->selectedBase;
918       }
919     }
920     return($tmp); 
921   }
924   function remove_from_parent()
925   {
926     /* Optionally execute a command after we're done */
927     $this->postremove();
928   }
931   /* Save data to object */
932   function save_object()
933   {
934     $this->DivListSystem->save_object();
935   }
938   /* Check values */
939   function check()
940   {
941   }
944   /* Save to LDAP */
945   function save()
946   {
947   }
949   function adapt_from_template($dn)
950   {
951   }
953   function password_change_needed()
954   {
955   }
957   function reload()
958   {
959     /* some var init */
960     $ui = get_userinfo();
961     $res              = array();
962     $this->terminals  = array();
963     $userregex        = "";
965     /* Set base for all searches */
966     $base=  $this->DivListSystem->selectedBase;
968     /* Prepare samba class name */
969     $samba  ="";
970     if ($this->DivListSystem->ShowWinWorkstations){
971       if ($this->config->current['SAMBAVERSION'] == "3"){
972         $samba= "sambaSamAccount";
973       } else {
974         $samba= "sambaAccount";
975       }
976     }
978     /* This array represents the combination between checkboxes and search filters */
979     $objs = array( 
980         "ShowServers"        => array("CLASS" => "goServer"        ,"TREE" => get_ou('serverou')),
981         "ShowTerminals"      => array("CLASS" => "gotoTerminal"    ,"TREE" => get_ou('terminalou')),
982         "ShowPrinters"       => array("CLASS" => "gotoPrinter"     ,"TREE" => get_ou('printerou')),
983         "ShowDevices"        => array("CLASS" => "ieee802Device"   ,"TREE" => get_ou('componentou')),
984         "ShowPhones"         => array("CLASS" => "goFonHardware"   ,"TREE" => get_ou('phoneou')),
985         "ShowWorkstations"   => array("CLASS" => "gotoWorkstation" ,"TREE" => get_ou('workstationou')),
986         "ShowWinWorkstations"=> array("CLASS" => $samba            ,"TREE" => get_winstations_ou() ));
988     /* Include the 'Display Systems of user' attribute */ 
989     if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
990       $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
991     }
993     /* Attributes to fetch */
994     $sys_attrs        = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode");
995     $sys_categories   = array("terminal", "workstation", "server", "phone" ,"printer");
997     /* Add FAIstate to attributes if FAI is activated */
998     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
999     if(!empty($tmp)){
1000       $sys_attrs[] = "FAIstate";
1001     }    
1003     /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled  */
1004     foreach($objs as $checkBox => $oc){
1005       if($this->DivListSystem->$checkBox){
1006         if($this->DivListSystem->SubSearch){
1007           if($oc['CLASS'] != ""){
1008             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1009             $new_res = get_sub_list($filter, $sys_categories ,preg_replace("/,.*$/","",$base), $base,$sys_attrs, GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
1010       
1011             /* Remove all objects that are not in the expected sub department */
1012             foreach($new_res as $key => $obj){
1013               if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
1014                 $res[$obj['dn']] = $obj;
1015               }
1016             }
1017           }
1018         }else{
1019           /* User filter? */
1020           if($oc['CLASS'] != ""){
1021             $filter = "(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex."))";
1022             $res = array_merge($res,get_list($filter,$sys_categories,$oc['TREE'].$base, $sys_attrs, GL_NONE | GL_SIZELIMIT));
1023           }
1024         }
1025       } 
1026     }
1028     /* Search for incoming objects */ 
1029     $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
1030     $res = array_merge($res,get_list($filter,$sys_categories, get_ou('incomingou'),get_ou('incomingou').$base,$sys_attrs, GL_NONE | GL_SIZELIMIT));
1032     /* Get all gotoTerminal's */
1033     foreach ($res as $value){
1035       $tmp= $value['dn'];
1036       $add= "";
1038       /* Extract base */
1039       foreach($objs as $obj){
1040         if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
1041           $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
1042         }
1043       }
1045       /* Create a string containing the last part of the department. */
1046       $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
1047       if(empty($dn_name)){
1048         $dn_name = "/";
1049       }
1051       /* check if current object is a new one */
1052       if (preg_match ("/,".get_ou('incomingou')."/i", $tmp)){
1053         if (in_array_ics('gotoTerminal', $value['objectClass'])){
1054           $add= "- "._("New terminal");
1055         }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
1056           $add= "- "._("New workstation");
1057         }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){
1058           $add= "- "._("Unknown device");
1059         }elseif (in_array_ics('GOhard', $value['objectClass'])){
1060           $add= "- "._("New Device");
1061         }
1062       } 
1064       /* Detect type of object and create an entry for $this->terminals */
1065       $terminal = array();
1067       if (in_array_ics('gotoTerminal', $value["objectClass"])){
1069         /* check acl */
1070         $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
1071         if($add != "" || preg_match("/r/",$acl)) {
1072           if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
1073             $terminal             = $value;
1074             $terminal['type']     = "T";
1075             $terminal['is_new']   = $add;
1076           } else {
1077             $terminal             = $value;
1078             $terminal['type']     = "D";
1079             $terminal['message']  = _("Terminal template for")."&nbsp;'".$dn_name."'&nbsp;";
1080             $terminal['location'] = array_search($tmp, $this->config->departments); 
1081           }
1082         }
1083       } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
1085         $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
1086         if($add != "" || preg_match("/r/",$acl)) {
1087           if (isset($value["macAddress"][0]) &&  $value["macAddress"][0] != "-"){
1088             $terminal             = $value;
1089             $terminal['type']     = "L";
1090             $terminal['is_new']   = $add;
1091           } else {
1092             $terminal             = $value;
1093             $terminal['type']     = "D";
1094             $terminal['location'] = array_search($tmp, $this->config->departments);
1095             $terminal['message']  = _("Workstation template for")."&nbsp;'".$dn_name."'&nbsp;";
1096           }
1097           if (isset($value["FAIstate"][0])){
1098             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1099           }
1100         }
1101       } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
1102        
1103    
1104         $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
1105         if($add != "" || preg_match("/r/",$acl)) {
1107           $terminal             = $value;
1108           $terminal['type']     = "P";
1109         }
1110       } elseif (in_array_ics('goServer', $value["objectClass"])){
1112         $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
1113         if($add != "" || preg_match("/r/",$acl)) {
1115           $terminal             = $value;
1116           $terminal['type']     = "S";
1117           if (isset($value["FAIstate"][0])){
1118             $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
1119           }
1120         }
1121       } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
1123         $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
1124         if($add != "" || preg_match("/r/",$acl)) {
1126           $terminal             = $value;
1127           $terminal['type']     = "F";
1128         }
1129       }elseif (in_array_ics("GOhard",$value['objectClass'])){
1131         $acl =  $ui->get_permissions($value['dn'],"server/servgeneric"). 
1132                 $ui->get_permissions($value['dn'],"terminal/termgeneric").
1133                 $ui->get_permissions($value['dn'],"workstation/workgeneric");
1134         if($add != "" || preg_match("/r/",$acl)) {
1136           $terminal = $value;
1137           $terminal['type']   = "Q";
1138           $terminal['is_new'] = $add;
1139         }
1140       } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
1142         $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
1143         if($add != "" || preg_match("/r/",$acl)) {
1145           $terminal             = $value;
1146           $terminal['type']     = "C";
1147         }
1148       } else{
1150         $name= preg_replace('/\$$/', '', $value['cn'][0]);
1151         if (isset($value['sambaDomainName'])){
1152           $domain= " [".$value['sambaDomainName'][0]."]";
1153         } else {
1154           $domain= "";
1155         }
1156         $terminal=$value;
1157         $terminal['type']     ="W";
1158         $terminal['domain']   = $name.$domain;
1159       }
1161       if(count($terminal)){
1162         $this->terminals[]=$terminal;
1163       }
1164     }
1166     $tmp  =array();
1167     $tmp2 =array();
1168     foreach($this->terminals as $tkey => $val ){
1169       $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
1170       $tmp2[strtolower($val['cn'][0]).$val['dn']] = strtolower($val['cn'][0]).$val['dn'];
1171     }
1172     natcasesort($tmp2);
1173     $this->terminals=array();
1174     foreach($tmp2 as $val){
1175       $this->terminals[]=$tmp[$val];
1176     }
1177     reset ($this->terminals);
1178   }
1180   function remove_lock()
1181   {
1182     if (isset($this->systab->dn)){
1183       del_lock ($this->systab->dn);
1184     }
1185   }
1188   function copyPasteHandling_from_queue($s_action,$s_entry)
1189   {
1190     /* Check if Copy & Paste is disabled */
1191     if(!is_object($this->CopyPasteHandler)){
1192       return("");
1193     }
1196     $tabs = array(
1197         "terminal"    => array( "CLASS"     =>"TERMTABS",     "TABNAME" =>"termgeneric",     
1198           "TABCLASS"  =>"termtabs",     "ACL"     =>"terminal"),
1199         "workstation" => array( "CLASS"     =>"WORKTABS",     "TABNAME" =>"workgeneric",     
1200           "TABCLASS"  =>"worktabs",     "ACL"     =>"workstation"),
1201         "server"      => array( "CLASS"     =>"SERVTABS",     "TABNAME" =>"servgeneric",     
1202           "TABCLASS"  =>"servtabs",     "ACL"     =>"server"),
1203         "printer"     => array( "CLASS"     =>"PRINTTABS",    "TABNAME" =>"printgeneric",    
1204           "TABCLASS"  =>"printtabs",    "ACL"     =>"printer"),
1205         "phone"       => array( "CLASS"     =>"PHONETABS",    "TABNAME" =>"phoneGeneric",    
1206           "TABCLASS"  =>"phonetabs",    "ACL"     =>"phone"),
1207         "component"   => array( "CLASS"     =>"COMPONENTTABS","TABNAME" =>"componentGeneric",
1208           "TABCLASS"  =>"componenttabs","ACL"     =>"component"));
1210     /* Add a single entry to queue */
1211     if($s_action == "cut" || $s_action == "copy"){
1213       /* Cleanup object queue */
1214       $this->CopyPasteHandler->cleanup_queue();
1215       $dn     = $this->terminals[$s_entry]['dn'];
1216       $oc     = $this->terminals[$s_entry]['objectClass'];
1217       $type   = $this->get_system_type($this->terminals[$s_entry]);
1219       $tab_o  = $tabs[$type]['CLASS'];
1220       $tab_c  = $tabs[$type]['TABCLASS'];
1221       $acl    = $tabs[$type]['ACL'];
1223       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$tab_c,$tab_o,$acl);
1224     }
1226     /* Add entries to queue */
1227     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1229       /* Cleanup object queue */
1230       $this->CopyPasteHandler->cleanup_queue();
1232       /* Add new entries to CP queue */
1233       foreach($this->list_get_selected_items() as $id){
1234         $dn = $this->terminals[$id]['dn'];
1235         $oc = $this->terminals[$id]['objectClass']; 
1236         $type = $this->get_system_type($this->terminals[$id]);
1238         if(isset($tabs[$type])){
1239           $tab_o  = $tabs[$type]['CLASS'];
1240           $tab_c  = $tabs[$type]['TABCLASS'];
1241           $acl    = $tabs[$type]['ACL'];
1243           if($s_action == "copy_multiple"){
1244             $this->CopyPasteHandler->add_to_queue($dn,"copy",$tab_c,$tab_o,$acl);
1245           }
1246           if($s_action == "cut_multiple"){
1247             $this->CopyPasteHandler->add_to_queue($dn,"cut",$tab_c,$tab_o,$acl);
1248           }
1249         }
1250       }
1251     }
1253     /* Start pasting entries */
1254     if($s_action == "editPaste"){
1255       $this->start_pasting_copied_objects = TRUE;
1256     }
1257   
1258     /* Return C&P dialog */
1259     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1260     
1261       /* Load entry from queue and set base */
1262       $this->CopyPasteHandler->load_entry_from_queue();
1263       $this->CopyPasteHandler->SetVar("base",$this->DivListSystem->selectedBase);
1265       /* Get dialog */
1266       $data = $this->CopyPasteHandler->execute();
1268       /* Return dialog data */
1269       if(!empty($data)){
1270         return($data);
1271       }
1272     }
1274     /* Automatically disable status for pasting */
1275     if(!$this->CopyPasteHandler->entries_queued()){
1276       $this->start_pasting_copied_objects = FALSE;
1277     }
1278     return("");
1279   }
1282   function get_system_type($attrs)
1283   {
1284     $classes = $attrs['objectClass'];
1286     $type= "";
1287     if (in_array_ics('ieee802Device', $classes)){
1288       $type= "component";
1289     }elseif (in_array_ics('gotoTerminal', $classes)){
1290       $type= "terminal";
1291     }elseif (in_array_ics('gotoWorkstation', $classes)){
1292       $type= "workstation";
1293     }elseif (in_array_ics('gotoPrinter', $classes)){
1294       $type= "printer";
1295     }elseif (in_array_ics('goFonHardware', $classes)){
1296       $type= "phone";
1297     }elseif (in_array_ics('goServer', $classes)){
1298       $type= "server";
1299     }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $this->arp_handling_active){
1300       $type= "ArpNewDevice";
1301     }elseif (in_array_ics('GOhard', $classes)){
1302       $type= "NewDevice";
1303     }elseif (in_array_ics('sambaAccount', $classes) ||
1304         in_array_ics('sambaSamAccount', $classes)){
1305       $type= "winstation";
1306     }
1307     return ($type);
1308   }
1311   function convert_list($input)
1312   {
1313     $temp= "";
1314     $conv= array(       
1315         "NQ" => array("select_newsystem.png",_("New System from incoming")),
1316         "D" => array("select_default.png",_("Template")),
1317         "T" => array("select_terminal.png",_("Terminal")),
1318         "L" => array("select_workstation.png",_("Workstation")),
1319         "GL" => array("select_workstation_green.png",_("Workstation is installing")),
1320         "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
1321         "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
1322         "F" => array("select_phone.png",_("Phone")),
1323         "S" => array("select_server.png",_("Server")),
1324         "GS" => array("select_server_green.png",_("Server is installing")),
1325         "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
1326         "RS" => array("select_server_red.png",_("Server installation failed")),
1327         "W" => array("select_winstation.png",_("Winstation")),
1328         "C" => array("select_component.png",_("Network Device")),
1329         "NT"=> array("select_new_terminal.png",_("New Terminal")),
1330         "NL"=> array("select_new_workstation.png",_("New Workstation")),
1331         "P" => array("select_printer.png",_("Printer")));
1333     if((isset($input['is_new']))&&(!empty($input['is_new']))){
1334       $input['type']="N".$input['type'];
1335     }
1336     foreach ($conv  as $key => $value){
1337       if($input['type']==$key){
1338         $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
1339         $tmp['class']=$key;
1340         return $tmp;
1341       }
1342     }
1343   }
1345   
1346   function getState($type, $state)
1347   {
1348     switch (preg_replace('/:.*$/', '', $state)) {
1349       case 'installing':
1350                 $type= 'G'.$type;
1351                 break;
1352       case 'error':
1353                 $type= 'R'.$type;
1354                 break;
1355       case 'install':
1356       case 'sysinfo':
1357       case 'softupdate':
1358       case 'scheduledupdate':
1359                 $type= 'Y'.$type;
1360                 break;
1361     }
1364     return ($type);
1365   }
1368   function list_get_selected_items()
1369   {
1370     $ids = array();
1371     foreach($_POST as $name => $value){
1372       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1373         $id   = preg_replace("/^item_selected_/","",$name);
1374         $ids[$id] = $id;
1375       }
1376     }
1377     return($ids);
1378   }
1381   /* !! Incoming dummy acls, required to defined acls for incoming objects
1382    */
1383   static function plInfo()
1384   {
1385     return (array(
1386           "plShortName"   => _("Incoming objects"),
1387           "plDescription" => _("Incoming objects"),
1388           "plSelfModify"  => FALSE,
1389           "plDepends"     => array(),
1390           "plPriority"    => 99,
1391           "plSection"     => array("administration"),
1392           "plCategory"    => array("incoming"   => array( "description"  => _("Incoming"),
1393                                                           "objectClass"  => "")),
1394           "plProvidedAcls"=> array()
1395             
1396           ));
1397   }
1400   
1404 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1405 ?>