Code

Added hotplug devices to multiple edit
[gosa.git] / gosa-core / plugins / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account       = FALSE;
12   var $plHeadline           = "Environment";
13   var $plDescription        = "This does something";
14   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
15   
16   var $in_dialog            = false;
17   var $uid                  = "";
19   var $is_group             = false;
20   var $view_logged = FALSE;
21   
22   /* Attribute definition
23    */
25   /* profile management */
26   var $useProfile         = false;  // Specifies if we want to use a Server 
27   var $gotoProfileServer  = "";     // Specifies the selected profile server
28   var $gotoProfileServers = array();// Specifies all available and selectable servers
29   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
30   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
31   
32   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
33   var $gotoXResolutions   = array();// Contains all available resolutions for this account
34   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
35   var $gotoProfileQuota   = "";     // User Quota Settings
37   /* Logon script section*/
38   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
39   var $gotoLogonScript    = "";     // The selected Logon Script
41   /* Printer */
42   var $gotoPrinter        = array();// All available Printer, with their configurations
43   var $gotoPrinterSel     = "";     //  The selected Printer
44   var $gosaDefaultPrinter = "";     // Default printer
46   /* Share */
47   var $gotoShares         = array();// Current Share Options
48   var $gotoShare          = "";     // currently selected Share Option
49   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
50   var $gotoAvailableShares= array();// Available Shares for this account
52   /* Kiosk profile */
53   var $kiosk_enabled      = FALSE;
54   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
55   var $gotoKioskProfile_Server    = "";     // The selected Kiosk Profile
56   var $gotoKioskProfile_Profile   = "";     // The selected Kiosk Profile
57   var $gotoKioskProfiles  = array();// All available Kiosk profiles
59   /* Hotplug Devices */
60   var $gotoHotplugDevice  = array();     // Selected hotplug
61   var $gotoHotplugDevices = array();// Already configured hotplug devices 
62   var $gotoHotplugDeviceDN= array();
64   var $NewAddedPrinters   = array();
65   var $NewDeletedPrinters = array();
67   /* general settings */
68   // Sets the attributes which will kept on page reload, which will be saved, ...
70   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
72   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
73       "gotoXResolution","gotoProfileQuota",
74       "gotoLogonScripts","gotoLogonScript",
75       "gotoPrinter", "gosaDefaultPrinter",
76       "gotoShares","gotoShare",
77       "gotoKioskProfile");
78   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
79   var $cn;
80   var $OrigCn;
81   var $add_del_printer_member_was_called = false;
83   var $multiple_support =TRUE;
85   function environment (&$config, $dn= NULL)
86   {
87     plugin::plugin ($config, $dn);
89     /* Setting uid to default */
90     if(isset($this->attrs['uid'][0])){
91       $this->uid = $this->attrs['uid'][0];
92     }
94     /* Check : Are we currently editing a group or user dialog */
95     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
96       $suffix="Group";
97       $this->uid          = $this->attrs['cn'][0];
98       $this->attrs['uid'] = $this->attrs['cn'][0];
99       $this->OrigCn = $this->attrs['cn'][0];
100     }else{
101       $suffix="User";
102     }
104     /* Get all Printer assignments */
105     $ldap = $this->config->get_ldap_link();
106     $ldap->cd($this->config->current['BASE']);
107     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
108     while($printer = $ldap->fetch()){
109       $this->gotoPrinter[$printer['cn'][0]]=$printer;
110       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
111     }
112     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
113     while($printer = $ldap->fetch()){
114       $this->gotoPrinter[$printer['cn'][0]]=$printer;
115       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
116     }
119     /* Prepare hotplugs */
120     if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
121       $ldap = $this->config->get_ldap_link();
122       $ldap->cd($this->config->current['BASE']);
123       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
124         $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
125         if($ldap->count()){
126           $attrs = $ldap->fetch(); 
128           if(isset($attrs['gotoHotplugDevice'][0])){
129             $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
130             $tmp2     = array();
131             $tmp2['name']         = $attrs['cn'][0];
132             $tmp2['description']  = $tmp[0];
133             $tmp2['id']           = $tmp[1];
134             $tmp2['produkt']      = $tmp[2];
135             $tmp2['vendor']       = $tmp[3];
136             $tmp2['dn']           = $attrs['dn'];
137             $this->gotoHotplugDevices[] = $tmp2; 
138           }
139         }else{
140           print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
141         }
142       }
143     }
145  
146     /* prepare LogonScripts */
147     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
148       unset($this->attrs['gotoLogonScript']['count']);
149       foreach($this->attrs['gotoLogonScript'] as $device){
150         $tmp = $tmp2 = array();
151         $tmp = split("\|",$device);
152         $tmp2['LogonName']        = $tmp[0]; 
153         $tmp2['LogonPriority']    = $tmp[2]; 
154         if(preg_match("/O/i",$tmp[1])){
155           $tmp2['LogonOverload'] = "O";
156         }else{
157           $tmp2['LogonOverload'] = "";
158         }
159         if(preg_match("/L/i",$tmp[1])){
160           $tmp2['LogonLast'] = "L";
161         }else{
162           $tmp2['LogonLast'] = "";
163         }
164         $tmp2['LogonData']        = base64_decode($tmp[3]); 
165         $tmp2['LogonDescription'] = $tmp[4];
166         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
167       }
168     }
170     /* Prepare Shares */
171     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
172       unset($this->attrs['gotoShare']['count']);
173       foreach($this->attrs['gotoShare'] as $share){
174         $tmp = $tmp2 = array();
175         $tmp = split("\|",$share);
176         $tmp2['server']      =$tmp[0];
177         $tmp2['name']        =$tmp[1];
179         /* Decode base64 if needed */
180         if (!preg_match('%/%', $tmp[2])){
181           $tmp2['mountPoint']  =base64_decode($tmp[2]);
182         } else {
183           $tmp2['mountPoint']  =$tmp[2];
184         }
186         if(isset($tmp[3])){
187           $tmp2['PwdHash']  =$tmp[3];
188         }else{
189           $tmp2['PwdHash']  ="";
190         }
191         if(isset($tmp[4])){
192           $tmp2['Username']  =$tmp[4];
193         }else{
194           $tmp2['Username']  ="";
195         }
196         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
197       }
198     }
200     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
201       $chr = $this->gotoProfileFlags[$i];
202       $name = "gotoProfileFlag".$chr;
203       $this->$name=$chr;
204     }
206     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
207       $this->useProfile = true;
208     }else{
209       $this->useProfile = false;
210     }
212     /* Set resolutions */
213     $this->gotoXResolutions = array("auto"=>_("auto"),
214                                     "640x480"   =>  "640x480",
215                                     "800x600"   =>  "800x600",
216                                     "1024x768"  =>  "1024x768",
217                                     "1152x864"  =>  "1152x864",
218                                     "1280x768"  =>  "1280x768",
219                                     "1280x1024" =>  "1280x1024");
221     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
222       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
224       if(is_readable($file)){
225         $str = file_get_contents($file);
226         $lines = split("\n",$str);
227         foreach($lines as $line){
228           $line = trim($line);
229           if(!empty($line)){
230             $this->gotoXResolutions[$line]=$line;
231           }
232         }
233         //natcasesort($this->gotoXResolutions);
234       }else{
235         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
236       }
237     }
239     $this->gotoProfileServers= $config->getShareServerList() ;
240     $this->gotoShareSelections= $config->getShareList(true);
241     $this->gotoAvailableShares= $config->getShareList(false);  
243     $this->update_kiosk_profiles();
244   
245     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
246   }
249   function update_kiosk_profiles()
250   { 
251     $tmp1  = array("none" => array(_("disabled")));
252     $tmp2  = array("none" => _("disabled"));
253     $ldap = $this->config->get_ldap_link();
254     $ldap->cd($this->config->current['BASE']);
255     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
256     $cnt = 0;
257     while($attrs = $ldap->fetch()){
258       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
259         $name = preg_replace("/^.*kiosk\//","",$attrs['gotoKioskProfile'][$i]);
260         $tmp1[$attrs['cn'][0]][] = $name;
261       }
262       $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
263       $cnt ++;
264     }
266     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
267       $this->kiosk_enabled = TRUE;
268     }
270     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
271     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
272   
273     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
274     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
276     $error = false;
277     if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
278       $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
279       $error = true;
280     }
281     if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
282       $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
283       $error = true;
284     }
285     if($error && !empty($this->gotoKioskProfile)){
286       print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
287             $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
288     }
289   }
292   /* Detect type of edited object (user|group)*/
293   function detect_grouptype()
294   {
295     if((!isset($this->parent))&&(!$this->is_account)){
296       $this->is_group     = false;
297     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
298       $this->is_group     = true;
299     }else{
300       $this->is_group     = false;
301     }
302   }
305   function execute()
306   {
308     /* Call parent execute */
309     plugin::execute();
310     /* Log view */
311     if($this->is_account && !$this->view_logged){
312       $this->view_logged = TRUE;
313       if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
314         new log("view","users/".get_class($this),$this->dn);
315       }else{
316         new log("view","groups/".get_class($this),$this->dn);
317       }
318     }
320     /* Are we editing from MyAccount and not editing a user */
321     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
323     /* Check profile server */
324     if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
325       if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
326         if(count($this->gotoProfileServers)){
328           /* Get First Profile */
329           $new = key($this->gotoProfileServers);
331           /* Another profile server found */
332           print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
333                 $this->gotoProfileServer,$new));
334         }else{
336           /* No other profile servers found */
337           print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
338                 $this->gotoProfileServer));
339           $this->gotoProfileServer = "";
340         }
341       }
342     }    
344     $this->detect_grouptype();
346     /* Fill templating stuff */
347     $smarty= get_smarty();
348     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
349     $display= "";
351     $smarty->assign("is_group",$this->is_group);
353     /* Prepare all variables for smarty */
354     foreach($this->attributes as $s_attr){
355       /* Set value*/
356       $smarty->assign($s_attr,$this->$s_attr);
358       /* Set checkbox state*/
359       if(empty($this->$s_attr)){
360         $smarty->assign($s_attr."CHK","");
361       }else{
362         $smarty->assign($s_attr."CHK"," checked ");
363       }
365       /* Prepare ACL settings*/
366       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
367     }
369     /* Is accout enabled | are we editing from usermenu or admin menu 
370        All these tab management is done here
371      */
374     /* Working from Usermenu an the Account is currently disbled
375      * this->parent :  is only set if we are working in a list of tabs
376      * is_account   :  is only true if the needed objectClass is given
377      */
378     if((!isset($this->parent))&&(!$this->is_account)){
379       /* We are currently editing this tab from usermenu, but this account is not enabled */
380       $smarty->assign("is_account",$this->is_account);
381       /* Load template */
382       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
383       /* Avoid the "You are currently editing ...." message when you leave this tab */
384       $display .= back_to_main(); 
385       /* Display our message to the user */
386       return $display;
389       /* We are currently editing from group tabs, because 
390        * $this->parent is set
391        * posixAccount is not set, so we are not in usertabs.
392        */
393     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
394       $smarty->assign("is_account","true");
395       $this->uid          = $this->cn;
396       $this->attrs['uid'] = $this->cn;
398       /* Change state if needed */
399       if (isset($_POST['modify_state'])){
400         if(($this->acl_is_createable() && !$this->is_account) || 
401             ($this->acl_is_removeable() &&  $this->is_account)){
402           $this->is_account= !$this->is_account;
403         }
404       }
405       /* Group Dialog with enabled environment options */
406       if ($this->is_account){
407         $display= $this->show_enable_header(_("Remove environment extension"),
408             _("Environment extension enabled. You can disable it by clicking below."));
409       } else {
411         /* Environment is disabled 
412            If theres is no posixAccount enabled, you won't be able to enable 
413            environment extensions
414          */
415         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
416           // 4. There is a PosixAccount
417           $display= $this->show_enable_header(_("Add environment extension"),
418               _("Environment extension disabled. You can enable it by clicking below."));
419           return $display;
420         }else{
421           // 4. There is no PosixAccount
422           $display= $this->show_enable_header(_("Add environment extension"),
423               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
424           return $display;
425         }
426       }
427     }else{
428       /* Editing from Usermenu 
429        *  Tell smarty that this accoutn is enabled 
430        */
431       $smarty->assign("is_account","true");
433       /* Change state if needed */
434       if (isset($_POST['modify_state'])){
435         if(($this->acl_is_createable() && !$this->is_account) || 
436             ($this->acl_is_removeable() &&  $this->is_account)){
437           $this->is_account= !$this->is_account;
438         }
439       }
441       if(isset($this->parent)){
443         // 3. Account enabled . Editing from adminmenu
444         if ($this->is_account){
445           $display= $this->show_disable_header(_("Remove environment extension"),
446               _("Environment extension enabled. You can disable it by clicking below."));
447         } else {
449           if($this->parent->by_object['posixAccount']->is_account==true){
450             // 4. There is a PosixAccount
451             $display= $this->show_disable_header(_("Add environment extension"),
452                 _("Environment extension disabled. You can enable it by clicking below."));
453             return $display;
454           }else{
455             // 4. There is a PosixAccount
456             $display= $this->show_disable_header(_("Add environment extension"),
457                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
458             return $display;
459           }
460         }
461       }
462     }
463   
464     /* Reset header toggle */
465     if($this->multiple_support_active){
466       $display = "";
467     }
469     /* Account is Account : is_accounbt=true.
470      * Else we won't reach this. 
471      */
473     /* Prepare all variables for smarty */
474     foreach($this->attributes as $s_attr){
475       /* Set value*/
476       $smarty->assign($s_attr,$this->$s_attr);
478       /* Set checkbox state*/
479       if(empty($this->$s_attr)){
480         $smarty->assign($s_attr."CHK","");
481       }else{
482         $smarty->assign($s_attr."CHK"," checked ");
483       }
485       /* Prepare ACL settings*/
486       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
487     }
489     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
490       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
491     }
493     if($WriteOnly) {
494       $smarty->assign("gotoPrinterACL","r");
495     }else{
496       $smarty->assign("gotoPrinterACL","rw");
497     }
499     if(empty($this->useProfile)){
500       $smarty->assign("useProfileCHK","");
501       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
502       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
503       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
504     }else{
505       $smarty->assign("useProfileCHK"," checked ");
506     }
507     
508     $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
509     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
511     /* HANDLE Profile Settings here 
512      * Assign available Quota and resolution settings
513      * Get all available profile server
514      * Get cache checkbox
515      * Assign this all to Smarty 
516      */
518     if(empty($this->gotoProfileFlagL)){
519       $smarty->assign("gotoProfileFlagLCHK"," ");
520     }else{
521       $smarty->assign("gotoProfileFlagLCHK"," checked ");
522     }
524     if(empty($this->gotoProfileFlagC)){
525       $smarty->assign("gotoProfileFlagCCHK"," ");
526     }else{
527       $smarty->assign("gotoProfileFlagCCHK"," checked ");
528     }
531     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
532     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
534     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
535     if(!is_array($this->gotoProfileServers)){
536       $this->gotoProfileServers =array();
537     }
538     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
540     /* Handle kiosk profiles*/
541     $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
542     $smarty->assign("kiosk_server" ,  $this->gotoKioskProfile_Server);
543     $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
544     $smarty->assign("kiosk_profile" ,  $this->gotoKioskProfile_Profile);
545   
547     /* Logonscript Management
548      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
549      * Perform add Delete edit Posts 
550      */
552     /* Dialog Save */
553     if(isset($_POST['LogonSave'])){
555       if(!$this->acl_is_writeable("gotoLogonScript")){
556         print_red(_("You are not allowed to write Logon scripts."));
557         unset($this->dialog);
558         $this->dialog=FALSE;
559         $this->is_dialog=false;
560       }else{
561         $this->dialog->save_object();
562         if(count($this->dialog->check())!=0){
563           foreach($this->dialog->check() as $msg){
564             print_red($msg);
565           }
566         }else{
567           $tmp = $this->dialog->save();
568           unset($this->dialog);
569           $this->dialog=FALSE;
570           $this->is_dialog=false;
572           if($this->multiple_support_active){
573             $tmp['UsedByAllUsers'] = TRUE;
574           }
575           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
576         }
577       }
578     }
579     
581     /* Dialog Quit without saving */
582     if(isset($_POST['LogonCancel'])){
583       $this->is_dialog= false;
584       unset($this->dialog);
585       $this->dialog= FALSE;
586     }
588     /* Check Edit Del New Posts for a selected LogonScript */ 
589     if($this->acl_is_writeable("gotoLogonScript") && 
590         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
592       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
593        * In this case we create a new Logon Script.
594        */
595       if(isset($_POST['gotoLogonScriptNew'])){
596         $this->is_dialog = true;
597         $this->dialog = new logonManagementDialog($this->config,$this->dn);
598       }
600       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
601        * We only can delete if there is an entry selected.
602        */
603       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
604         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
605       }
607       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
608        * There must be an entry selected to perform edit request.
609        */
610       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
611         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
612         $this->is_dialog = true;
613         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
614       }
615     }
617     /* Append List to smarty*/
618     if($this->multiple_support_active){
619       $smarty->assign("gotoLogonScripts",  $this->gotoLogonScripts);
620       $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
621     }else{
622       $ls = $this->printOutLogonScripts();
623       $smarty->assign("gotoLogonScripts",  $ls);
624       $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
625       $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
626     }
628     /* In this section server shares will be defined 
629      * A user can select one of the given shares and a mount point
630      *  and attach this combination to his setup.
631      */
633     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
634     if(!is_array($this->gotoShareSelections)){
635       $this->gotoShareSelections = array();
636     }
637     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
639     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
640      * This entry will be, a combination of mountPoint and sharedefinitions 
641      */
642     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
644       /* We assign a share to this user, if we don't know where to mount the share */
645       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
646         print_red(_("You must select a valid share."));
647       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
648         print_red(_("You must specify a valid mount point."));
649       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
650         print_red(_("Spaces are not allowed in the mount path!"));
651       }elseif(!(
652             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
653             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
654             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
655             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
656             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
657             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
658             preg_match("/^%/",$_POST['gotoShareMountPoint'])
659             )
660           ){
661         print_red(_("You must specify a valid mount point.")); 
662       }else{
663         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
664         $s_mount = $_POST['gotoShareMountPoint'];
665         $s_user  = $_POST['ShareUser'];
666         /* Preparing the new assignment */ 
667         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
668         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
669         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
670         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
672         if($this->multiple_support_active){
673           $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
674         }
675       }
676     }  
678     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
679      * If there is no defined share selected, we will abort the deletion without any message 
680      */
681     $once = true;
682     if($this->acl_is_writeable("gotoShare")){
683       foreach($_POST as $name => $value){
684         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
685           $once = false;  
686           $key  = preg_replace("/^gotoShareDel_/","",$name);
687           $key  = preg_replace("/_+[xy]$/","",$key);
688           $key  = base64_decode($key);
689           if(isset($this->gotoShares[$key])) {
690             unset($this->gotoShares[$key]);
691           }
693           /* Remove corresponding password entry, too. This is a workaround
694              to get rid of old-style entries. */
695           $key= preg_replace("/\|/", "|!", $key);
696           if(isset($this->gotoShares[$key])) {
697             unset($this->gotoShares[$key]);
698           }
699         }
700         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
701           $once = false;
702           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
703           $key  = preg_replace("/_+[xy]$/","",$key);
704           $key  = base64_decode($key);
705           $this->gotoShares[$key]['PwdHash'] = "";
706           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
707             unset($this->gotoShares[$key]);
708           }
709         }
710       }
711     }
712     $divlistShares = new divSelectBox("gotoShares");
713     $divlistShares->SetHeight(100);
716     $tmp = array();
717     if($this->acl_is_readable("gotoShares")){
718       $tmp = $this->printOutAssignedShares();
719     }
721     
722     foreach($tmp as $key => $value){
723       $img = "";
725       /* Skip apssword only entries */
726       if( empty($this->gotoShares[$key]['server']) && 
727           empty($this->gotoShares[$key]['name']) &&
728           empty($this->gotoShares[$key]['mountPoint']) &&
729           empty($this->gotoShares[$key]['Username'])){
730         continue;
731       } 
733       $color = "";
734       if($this->multiple_support_active){
735         if($this->gotoShares[$key]['UsedByAllUsers']){
736           $value .= "&nbsp;(<b>"._("Used by all users")."</b>)";
737         }else{
738           $color = "color: #999999;";
739           $value .= "&nbsp;(<b>"._("Used by some users")."</b>)";
740         }
741       }
743       /* Check if entry starts with an ! */
744       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
746         /* If we are currently editing groups environment, skip those ! entries */ 
747         if($this->is_group) continue;
749         /* Create pwd reset images */
750         if($this->gotoShares[$key]['PwdHash'] != ""){
751           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
752             title='"._("Reset password hash")."'>";
753         }
754         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
755         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
756       }else{
758         /* Create pwd reset img && delete image */
759         if($this->gotoShares[$key]['PwdHash'] != ""){
760           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
761             title='"._("Reset password hash")."'>";
762           $img.= "&nbsp;";
763         }
764         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
765           title='"._("Delete share entry")."'>";
766         $field1 = array("string" => $value , "attach" => "style='".$color."'");
767         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
768       }
769       $divlistShares->AddEntry(array($field1,$field2));
770     }
771     $smarty->assign("divlistShares",$divlistShares->DrawList());
773     /* Hotplug devices will be handled here 
774      * There are 3 possible methods for this feature
775      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
776      * Delete will erase an entry, the entry must be selcted in the ListBox first
777      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
778      */
780     /* We have to delete the selected hotplug from the list*/
781     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
782       if($this->acl_is_writeable("gotoHotplugDevice")){
783         foreach($_POST['gotoHotplugDevice_post'] as $name){
784           unset($this->gotoHotplugDevices[$name]);
785         }
786       }
787     }
789     /* There are already defined hotplugs from other users we could use */
790     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
791       $tmp  =array();
792       foreach($this->gotoHotplugDevices as $plugs){
793         $tmp[] = $plugs['name'];
794       }
795       $this->dialog = new hotplugDialog($this->config,$tmp);
796       $this->is_dialog = true;
797     }
799     /* Dialog Aborted */
800     if(isset($_POST['HotPlugCancel'])){
801       unset($this->dialog);
802       $this->dialog= FALSE;
803       $this->is_dialog = false;
804     }
806     /* Dialod saved */
807     if(isset($_POST['HotPlugSave'])){
809       $this->dialog->save_object();
810       if(count($this->dialog->check())!=0){
811         foreach($this->dialog->check() as $msg){
812           print_red($msg);
813         }
814       }else{
815         $this->dialog->save_object();
816         $a_tmp = $this->dialog->save();
818         if(is_array($a_tmp)){
819           foreach($a_tmp as $name => $hotplug){
820             if($this->multiple_support_active){
821               $hotplug['UsedByAllUsers'] = TRUE;
822             }
823             $this->gotoHotplugDevices[$name]= $hotplug; 
824           }
825         }
826         unset($this->dialog);
827         $this->dialog= FALSE;
828         $this->is_dialog = false;
829       }
830     }
832     if($this->multiple_support_active){
833       $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
834     }else{
835       $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
836       $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
837     }
839     /* Printer Assignment will managed below 
840      * A printer can be assigned in two different ways and two different types
841      * There are 2 types of users assigned to a printer : user and admin
842      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
843      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
844      */ 
846     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
847     if(isset($_POST['gotoPrinterAdd'])){
849       $this->is_dialog=true;
850       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
851     }
853     if(isset($_POST['PrinterCancel'])){
854       $this->is_dialog=false;
855       unset($this->dialog);
856       $this->dialog=FALSE;
857     }
859     if(isset($_POST['PrinterSave'])){
860       if(count($this->dialog->check())!=0){
861         $tmp = $this->dialog->check();
862         foreach($tmp as $msg){
863           print_red($msg);
864         } 
865       }else{
866         $this->dialog->save_object();
867         $tmp = $this->dialog->save();
868         $tmp2= $this->dialog->getPrinter(true);
870         foreach($tmp as $pname){
871           $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
872           $printerObj->set_acl_base($tmp2[$pname]['dn']);
874           $type = false;
876           if($this->is_group){
877             if($this->dn == "new"){  
878               $type = "AddGroup";
879             }elseif(isset($this->NewDeletedPrinters[$pname])){
880               $type = "AddGroup";
881             }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
882               $type = "AddGroup";
883             }
884           }else{
885             if(isset($this->NewDeletedPrinters[$pname])){
886               $type = "AddUser";
887             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
888               $type = "AddUser";
889             }
890           }
892           if($type){
893             $this->gotoPrinter[$pname]=$tmp2[$pname];
894             $this->gotoPrinter[$pname]['mode']="user";
895             $this->add_del_printer_member_was_called = true;
897             $this->NewAddedPrinters[$pname] = $pname;
898             if(isset($this->NewDeletedPrinters[$pname])){
899               unset($this->NewDeletedPrinters[$pname]);
900             }
901           }
902         }
904         $this->is_dialog=false;
905         unset($this->dialog);
906         $this->dialog   =FALSE;
907       }
908     }
910     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
911       $printer = $_POST['gotoPrinterSel'];
912       foreach($printer as $pname){
914         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
915         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
917         $type = false;
918         if($this->is_group){
919           if(isset($this->NewAddedPrinters[$pname])){
920             $type = "Group";
921           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
922             $type = "Group";
923           }
924         }else{
925           if(isset($this->NewAddedPrinters[$pname])){
926             $type = "User";
927           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
928             $type = "User";
929           }
930         }
931         if($type){
932           $this->add_del_printer_member_was_called = true;
933           unset($this->gotoPrinter[$pname]);
935           $this->NewDeletedPrinters[$pname] = $pname;
936           if(isset($this->NewAddedPrinters[$pname])){
937             UNSET($this->NewAddedPrinters[$pname]);
938           }
939         }
940       }
941     }
943     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
944       $printers = $_POST['gotoPrinterSel'];
945       $this->add_del_printer_member_was_called = true;
946       foreach($printers as $printer){
947         if($this->gotoPrinter[$printer]['mode']=="user"){
948           $this->gotoPrinter[$printer]['mode']="admin";
949         }else{
950           $this->gotoPrinter[$printer]['mode']="user";
951         }
952       }
953     }
955     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
956       if($this->is_group){
957         print_red(_("GOsa default printer flag is not allowed within groups."));
958       }else{
959         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
960           $this->gosaDefaultPrinter= "";
961         } else {
962           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
963         }
964       }
965     }
967     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
968     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
970     /* General behavior */
971     if(is_object($this->dialog)){
972       $this->dialog->save_object();
973       $disp =$this->dialog->execute();
974       return($disp);
975     }
977     /* Als smarty vars are set. Get smarty template and generate output */
978     $smarty->assign("multiple_support",$this->multiple_support_active);
979     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
980     return($display);
981   }
983   function remove_from_parent()
984   {
985     /* only if it was an account*/
986     if (!$this->initially_was_account){
987       return;
988     }
990     /* include global link_info */
991     $ldap= $this->config->get_ldap_link();
993     /* Remove and write to LDAP */
994     plugin::remove_from_parent();
996     /* Don't save our template variables */
997     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
999     /* Skip all these attributes */
1000     foreach($skip as $del){
1001       unset($this->attrs[$del]);
1002     }
1004     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1006     $ldap->cd($this->dn);
1007     $this->cleanup();
1008     $ldap->modify ($this->attrs); 
1010     if($this->is_group){
1011       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1012     }else{
1013       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1014     }
1016     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
1018     /* Optionally execute a command after we're done */
1019     $this->handle_post_events("remove",array("uid" => $this->uid));
1020   }
1023   /* Save data to object */
1024   function save_object()
1025   {
1026     /* Get all Posted vars 
1027      * Setup checkboxes 
1028      */
1029     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
1030     if(isset($_POST['iamposted'])){
1032       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1034       if(isset($_POST['kiosk_server'])){
1035         $tmp = $_POST['kiosk_server'];
1036         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1037           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1038         }
1039       }
1040       if(isset($_POST['kiosk_profile'])){
1041         $tmp = $_POST['kiosk_profile'];
1042         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1043           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1044         }
1045       }
1047       if(preg_match("/w/",$PACL)){
1048         if(isset($_POST['useProfile'])){
1049           $this->useProfile = true;
1050         }else{
1051           $this->useProfile = false;
1052         }
1053       }
1055       if($this->acl_is_writeable("gotoProfileFlagC")){
1056         if(isset($_POST['gotoProfileFlagC'])){
1057           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1058         }else{
1059           $this->gotoProfileFlagC = false;
1060         }
1061       }
1063       if($this->acl_is_writeable("gotoProfileFlagL")){
1064         if(isset($_POST['gotoProfileFlagL'])){
1065           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1066         }else{
1067           $this->gotoProfileFlagL = false;
1068         }
1069       }
1071       plugin::save_object();
1072       foreach($this->attributes as $s_attr){
1073         if((!isset($_POST[$s_attr])) || 
1074             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1075         if(!$this->acl_is_writeable($s_attr)){
1076           continue;
1077         }else{ 
1078           if(isset($_POST[$s_attr])){
1079             $this->$s_attr = $_POST[$s_attr];
1080           }else{
1081             $this->$s_attr = false;
1082           }
1083         }
1084       }
1085     }
1086   }
1089   /* Check supplied data */
1090   function check()
1091   {
1092     /* Call common method to give check the hook */
1093     $message= plugin::check();
1095     $this->detect_grouptype();
1097     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1098       $message[]=_("Please set a valid profile quota size.");
1099     } 
1100     if(!isset($this->attrs['objectClass'])){
1101       $this->attrs['objectClass']=array();
1102     } 
1103     if(!$this->is_group){
1104       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1105         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
1106       }
1107     }
1108     return ($message);
1109   }
1112   /* Save to LDAP */
1113   function save()
1114   {
1115     /* If group was renamed, all printer settings get lost
1116      */ 
1117     /* only save changed variables ....*/
1118     if ($this->gotoKioskProfile_Server != "none"){
1119       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1120         $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1121       }else{
1122         $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1123       }
1124       $this->gotoKioskProfile= $method;
1125     }else{
1126       $this->gotoKioskProfile= array();
1127     }
1129     plugin::save();
1130     $ldap= $this->config->get_ldap_link();
1132     $realyUsedAttrs= array();
1134     /* Save already used objectClasses */
1135     $ocs        = $this->attrs['objectClass'];
1136     unset($ocs['count']);
1137     $this->attrs = array();
1138     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1140     /* 1. Search all printers that have our uid/cn as member 
1141      * 2. Delete this uid/cn from every single entry and save it again.
1142      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1143      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1144      */
1145     
1146     $this->detect_grouptype();
1148     if($this->add_del_printer_member_was_called){
1150       $types = array( "gotoUserPrinter"       => "AddUser",
1151           "gotoGroupPrinter"      => "AddGroup",
1152           "gotoUserAdminPrinter"  => "AddAdminUser",
1153           "gotoGroupAdminPrinter" => "AddAdminGroup");
1155       if($this->is_group){
1156         $s_suffix = "Group";
1157         $useVar   = "cn";
1158       }else{
1159         $useVar   = "uid";
1160         $s_suffix = "User";
1161       }
1163       /* Remove old entries */
1164       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1165       while($attr = $ldap->fetch()){
1166         $printerObj = NULL;
1167         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1168         $printerObj->set_acl_base($attr['dn']);
1169         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1170         $printerObj->by_object['printgeneric']->save();
1171       }
1173       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1174       while($attr = $ldap->fetch()){
1175         $printerObj = NULL;
1176         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1177         $printerObj->set_acl_base($attr['dn']);
1178         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1179         $printerObj->by_object['printgeneric']->save();
1180       }
1182       foreach($this->gotoPrinter as $printer){
1183         $printerObj = NULL;
1184         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1185         $printerObj->set_acl_base($printer['dn']);
1188         if($printer['mode'] == "admin") {
1189           $attribute = "goto".$s_suffix."AdminPrinter";
1190         }else{
1191           $attribute = "goto".$s_suffix."Printer";
1192         }
1194         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1195         $printerObj->by_object['printgeneric']->save();
1196       }
1197     }    
1199     /* Prepare HotPlug devices */
1200     $this->attrs['gotoHotplugDeviceDN'] = array();
1201     foreach($this->gotoHotplugDevices as $name => $device){
1202       $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1203     }
1205     /* Prepare LogonScripts */
1206     $this->attrs['gotoLogonScript'] = array();
1207     foreach($this->gotoLogonScripts as $name => $script){
1208       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1209         $script['LogonOverload'].$script['LogonLast']."|".
1210         $script['LogonPriority']."|".
1211         base64_encode($script['LogonData'])."|".
1212         $script['LogonDescription'];
1213     }
1215     /* Prepare Shares */
1216     $this->attrs['gotoShare']=array();
1217     foreach($this->gotoShares as $name => $share){
1218       $mntp= $share['mountPoint'];
1219       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1220         $mntp= base64_encode($mntp);
1221       }
1222       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1223     }
1226     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1227     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1229     foreach($saveThis as $tosave){
1230       if(!empty($this->$tosave)){
1231         $this->attrs[$tosave]=$this->$tosave;
1232       }else{
1233         $this->attrs[$tosave]=array();
1234       }
1235     }
1237     /* Prepare Flags */
1238     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1239     if(empty($this->attrs['gotoProfileFlags'][0])){
1240       $this->attrs['gotoProfileFlags']=array();
1241     }
1243     if($this->useProfile == false){
1244       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1245       $this->attrs['gotoProfileServer']= array(); 
1246     }
1248     $ldap->cat ($this->dn, array('dn'));
1249     if ($ldap->fetch()){
1250       $mode= "modify";
1251     } else {
1252       $mode= "add";
1253       $ldap->cd($this->config->current['BASE']);
1254       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1255     }
1257     $ldap->cd($this->dn);
1258     $this->cleanup();
1259     $ldap->$mode($this->attrs);
1260   
1261     $cat = "users";
1262     if($this->is_group){
1263       $cat = "groups";
1264     }
1266     /* Log last action */ 
1267     if($this->initially_was_account){
1268       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1269     }else{
1270       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1271     }
1273     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1274     $this->handle_post_events($mode,array("uid"=>$this->uid));
1275   }
1277   /* Generate ListBox frindly output for the defined shares 
1278    * Possibly Add or remove an attribute here, 
1279    */
1280   function printOutAssignedShares()
1281   {
1282     $a_return = array();
1283     if(is_array($this->gotoShares)){
1284       foreach($this->gotoShares as $share){
1285         if(preg_match("/^!/",$share['server'])){
1286           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1287         }else{
1288           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1289         }
1290       }
1291       natcasesort($a_return);
1292     }
1293     return($a_return);
1294   }
1296   /* Generate ListBox frindly output for the definedhotplugs 
1297    * Possibly Add or remove an attribute here,
1298    */
1299   function printOutHotPlugDevices()
1300   {
1301     $a_return= array();
1302     if(is_array($this->gotoHotplugDevices)){
1303       foreach($this->gotoHotplugDevices as $key=>$device){
1304         $a_return[$key] = $device['name']." - ".$device['id'];
1305       }
1306     }
1307     return($a_return);
1308   }
1310   /* Generates ListBox frienly output of used printer devices 
1311    * Append ' - admin' if printer is used in admin mode
1312    */
1313   function printOutPrinterDevices()
1314   {
1315     $a_return = array();
1316     
1317     if($this->acl_is_readable("gotoPrinter")){
1319       if(is_array($this->gotoPrinter)){
1320         foreach($this->gotoPrinter as $printer){
1321           if($printer['mode'] == "admin"){
1322             $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1323           }else{
1324             $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1325           }
1326           if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1327             $a_return[$printer['cn'][0]].=" - "._("Default printer");
1328           }
1329         }
1330       }
1331     }
1332     return($a_return);
1333   }
1336   function PrepareForCopyPaste($source)
1337   {
1338     plugin::PrepareForCopyPaste($source);
1340     $class= get_class($this);
1341     $o_source = new $class($this->config,$source['dn']);
1342     foreach($this->CopyPasteVars as $attr){
1343       $this->$attr = $o_source->$attr;  
1344     }
1345   }
1348   function saveCopyDialog()
1349   {
1350     if(isset($_POST['cn'])){
1351       $this->cn = $_POST['cn'];
1352       $this->uid = $_POST['cn'];
1353     }
1354   }
1357   /* Generates ListBox frienly output of used logonscripts 
1358    */
1359   function printOutLogonScripts()
1360   {
1361     $a_return = array();
1362     if(is_array($this->gotoLogonScripts)){
1363       foreach($this->gotoLogonScripts as $script){
1364         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1365       }
1366     }
1367     return($a_return);
1368   }
1371   function multiple_execute()
1372   {
1373     /* Reset header toggle */
1374     $this->is_account = TRUE;
1375     return($this->execute());
1376   }
1379     /* Initialize plugin with given atribute arrays
1380    */
1381   function init_multiple_support($attrs,$all)
1382   {
1383     plugin::init_multiple_support($attrs,$all);
1385     /* Prepare Shares */
1386     if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1387       unset($this->multi_attrs_all['gotoShare']['count']);
1388       foreach($this->multi_attrs_all['gotoShare'] as $share){
1389         $tmp = $tmp2 = array();
1390         $tmp = split("\|",$share);
1391         $tmp2['server']      =$tmp[0];
1392         $tmp2['name']        =$tmp[1];
1394         /* Decode base64 if needed */
1395         if (!preg_match('%/%', $tmp[2])){
1396           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1397         } else {
1398           $tmp2['mountPoint']  =$tmp[2];
1399         }
1401         if(isset($tmp[3])){
1402           $tmp2['PwdHash']  =$tmp[3];
1403         }else{
1404           $tmp2['PwdHash']  ="";
1405         }
1406         if(isset($tmp[4])){
1407           $tmp2['Username']  =$tmp[4];
1408         }else{
1409           $tmp2['Username']  ="";
1410         }
1411         $tmp2['UsedByAllUsers'] = FALSE;
1412         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1413       }
1414     }
1416     /* Prepare Shares */
1417     if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1418       unset($this->multi_attrs['gotoShare']['count']);
1419       foreach($this->multi_attrs['gotoShare'] as $share){
1420         $tmp = $tmp2 = array();
1421         $tmp = split("\|",$share);
1422         $tmp2['server']      =$tmp[0];
1423         $tmp2['name']        =$tmp[1];
1425         /* Decode base64 if needed */
1426         if (!preg_match('%/%', $tmp[2])){
1427           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1428         } else {
1429           $tmp2['mountPoint']  =$tmp[2];
1430         }
1432         if(isset($tmp[3])){
1433           $tmp2['PwdHash']  =$tmp[3];
1434         }else{
1435           $tmp2['PwdHash']  ="";
1436         }
1437         if(isset($tmp[4])){
1438           $tmp2['Username']  =$tmp[4];
1439         }else{
1440           $tmp2['Username']  ="";
1441         }
1442         $tmp2['UsedByAllUsers'] = TRUE;
1443         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1444       }
1445     }
1448     /* prepare LogonScripts */
1449     if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1450       unset($this->multi_attrs_all['gotoLogonScript']['count']);
1451       foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1452         $tmp = $tmp2 = array();
1453         $tmp = split("\|",$device);
1454         $tmp2['LogonName']        = $tmp[0];
1455         $tmp2['LogonPriority']    = $tmp[2];
1456         if(preg_match("/O/i",$tmp[1])){
1457           $tmp2['LogonOverload'] = "O";
1458         }else{
1459           $tmp2['LogonOverload'] = "";
1460         }
1461         if(preg_match("/L/i",$tmp[1])){
1462           $tmp2['LogonLast'] = "L";
1463         }else{
1464           $tmp2['LogonLast'] = "";
1465         }
1466         $tmp2['LogonData']        = base64_decode($tmp[3]);
1467         $tmp2['LogonDescription'] = $tmp[4];
1468         $tmp2['UsedByAllUsers'] = FALSE;
1469         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1470       }
1471     }
1473     /* prepare LogonScripts */
1474     if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1475       unset($this->multi_attrs['gotoLogonScript']['count']);
1476       foreach($this->multi_attrs['gotoLogonScript'] as $device){
1477         $tmp = $tmp2 = array();
1478         $tmp = split("\|",$device);
1479         $tmp2['LogonName']        = $tmp[0];
1480         $tmp2['LogonPriority']    = $tmp[2];
1481         if(preg_match("/O/i",$tmp[1])){
1482           $tmp2['LogonOverload'] = "O";
1483         }else{
1484           $tmp2['LogonOverload'] = "";
1485         }
1486         if(preg_match("/L/i",$tmp[1])){
1487           $tmp2['LogonLast'] = "L";
1488         }else{
1489           $tmp2['LogonLast'] = "";
1490         }
1491         $tmp2['LogonData']        = base64_decode($tmp[3]);
1492         $tmp2['LogonDescription'] = $tmp[4];
1493         $tmp2['UsedByAllUsers'] = TRUE;
1494         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1495       }
1496     }
1498     /* Prepare hotplugs */
1499     if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1500       $ldap = $this->config->get_ldap_link();
1501       $ldap->cd($this->config->current['BASE']);
1502       for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1503         $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1504         if($ldap->count()){
1505           $multi_attrs_all = $ldap->fetch();
1507           if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1508             $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1509             $tmp2     = array();
1510             $tmp2['name']         = $multi_attrs_all['cn'][0];
1511             $tmp2['description']  = $tmp[0];
1512             $tmp2['id']           = $tmp[1];
1513             $tmp2['produkt']      = $tmp[2];
1514             $tmp2['vendor']       = $tmp[3];
1515             $tmp2['dn']           = $multi_attrs_all['dn'];
1516             $tmp2['UsedByAllUsers'] = FALSE;
1517             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1518           }
1519         }
1520       }
1521     }
1523     /* Prepare hotplugs */
1524     if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1525       $ldap = $this->config->get_ldap_link();
1526       $ldap->cd($this->config->current['BASE']);
1527       for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1528         $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1529         if($ldap->count()){
1530           $multi_attrs = $ldap->fetch();
1532           if(isset($multi_attrs['gotoHotplugDevice'][0])){
1533             $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1534             $tmp2     = array();
1535             $tmp2['name']         = $multi_attrs['cn'][0];
1536             $tmp2['description']  = $tmp[0];
1537             $tmp2['id']           = $tmp[1];
1538             $tmp2['produkt']      = $tmp[2];
1539             $tmp2['vendor']       = $tmp[3];
1540             $tmp2['dn']           = $multi_attrs['dn'];
1541             $tmp2['UsedByAllUsers'] = TRUE;
1542             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1543           }
1544         }
1545       }
1546     }
1547    $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1548   }
1551   function set_multi_edit_values($attrs)
1552   {
1553     $shares = $this->gotoShares;
1554     $scripts= $this->gotoLogonScripts;
1555     $plugs= $this->gotoHotplugDevices;
1556     plugin::set_multi_edit_values($attrs);
1558     $this->gotoShares = $shares;
1559     $this->gotoLogonScripts = $scripts;
1560     $this->gotoHotplugDevices = $plugs;
1562     foreach($attrs['gotoShares'] as $name => $share){
1563       if($share['UsedByAllUsers'] == TRUE){
1564         $this->gotoShares[$name] = $share;
1565       }
1566     }
1567     foreach($this->gotoShares as $name => $share){
1568       if(!isset($attrs['gotoShares'][$name])){
1569         unset($this->gotoShares[$name]);
1570       }
1571     }
1572     foreach($attrs['gotoLogonScripts'] as $name => $script){
1573       if($script['UsedByAllUsers'] == TRUE){
1574         $this->gotoLogonScripts[$name] = $script;
1575       }
1576     }
1577     foreach($this->gotoLogonScripts as $name => $script){
1578       if(!isset($attrs['gotoLogonScripts'][$name])){
1579         unset($this->gotoLogonScripts[$name]);
1580       }
1581     }
1582     $tmp = array();
1583     foreach($this->gotoHotplugDevices as $entry){
1584       $tmp[$entry['dn']] = $entry;
1585     }
1586   
1587     foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1588       if($plug['UsedByAllUsers'] == TRUE){
1589         $tmp[$plug['dn']] = $plug;
1590       }
1591     }
1592     foreach($tmp as $name => $plug){
1593       $found = false;
1594       foreach($attrs['gotoHotplugDevices'] as $test){
1595         if($test['dn'] == $name){
1596           $found = true;
1597         }
1598       }
1599       if(!$found){
1600         unset($tmp[$name]);
1601       }
1602     }
1603     $this->gotoHotplugDevices = array_values($tmp);
1604   }
1607     /* Return selected values for multiple edit */
1608   function get_multi_edit_values()
1609   {
1610     $ret = plugin::get_multi_edit_values();
1611     $ret['gotoShares'] = $this->gotoShares;
1612     $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1613     $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1614     return($ret);
1615   }
1618   /* Return plugin informations for acl handling 
1619 #FIXME these ACLs should work for groups too */ 
1620   static function plInfo()
1621   {
1622     return (array("plShortName"     => _("Environment"),
1623           "plDescription"   => _("Environment settings"),         // Description
1624           "plSelfModify"    => TRUE,                              
1625           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1626           "plPriority"      => 3,                                 // Position in tabs 
1627           "plSection"     => array("personal" => _("My account")),
1628           "plCategory"    => array("users",
1629                                    "groups"),
1630           "plOptions"       => array("resolution_hook" => array("type" => "string",
1631               "description" => _("Command to extend the list of possible screen resolutions"))),
1633           "plProvidedAcls"  => array(
1635             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1636             "gotoProfileFlagC"    => _("Cache profile localy") ,
1638             "gotoProfileQuota"    => _("Profile quota") ,
1639             "gotoProfileServer"   => _("Profile server") ,
1641             "gotoXResolution"     => _("Resolution") ,
1642             "gotoKioskProfile"    => _("Kiosk profile") ,
1644             "gosaDefaultPrinter"  => _("Default printer") ,
1645             "gotoLogonScript"     => _("Logon script") ,
1646             "gotoHotplugDevice"   => _("Hotplug devices"),
1647             "gotoShare"           => _("Shares"))
1648             ));
1649   }
1652 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1653 ?>