Code

Updated environment/kiosk error
[gosa.git] / gosa-plugins / goto / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account       = FALSE;
7   var $plHeadline           = "Environment";
8   var $plDescription        = "This does something";
9   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
10   
11   var $in_dialog            = false;
12   var $uid                  = "";
14   var $is_group             = false;
15   var $view_logged = FALSE;
16   
17   /* Attribute definition
18    */
20   /* profile management */
21   var $useProfile         = false;  // Specifies if we want to use a Server 
22   var $gotoProfileServer  = "";     // Specifies the selected profile server
23   var $gotoProfileServers = array();// Specifies all available and selectable servers
24   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
25   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
26   
27   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
28   var $gotoXResolutions   = array();// Contains all available resolutions for this account
29   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
30   var $gotoProfileQuota   = "";     // User Quota Settings
32   /* Logon script section*/
33   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
34   var $gotoLogonScript    = "";     // The selected Logon Script
36   /* Printer */
37   var $gotoPrinter        = array();// All available Printer, with their configurations
38   var $gotoPrinterSel     = "";     //  The selected Printer
39   var $gosaDefaultPrinter = "";     // Default printer
41   /* Share */
42   var $gotoShares         = array();// Current Share Options
43   var $gotoShare          = "";     // currently selected Share Option
44   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45   var $gotoAvailableShares= array();// Available Shares for this account
47   /* Kiosk profile */
48   var $kiosk_enabled      = FALSE;
49   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
50   var $gotoKioskProfile_Server    = "";     // The selected Kiosk Profile
51   var $gotoKioskProfile_Profile   = "";     // The selected Kiosk Profile
52   var $gotoKioskProfiles  = array();// All available Kiosk profiles
54   /* Hotplug Devices */
55   var $gotoHotplugDevice  = array();     // Selected hotplug
56   var $gotoHotplugDevices = array();// Already configured hotplug devices 
57   var $gotoHotplugDeviceDN= array();
59   var $NewAddedPrinters   = array();
60   var $NewDeletedPrinters = array();
62   /* general settings */
63   // Sets the attributes which will kept on page reload, which will be saved, ...
65   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
67   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
68       "gotoXResolution","gotoProfileQuota",
69       "gotoLogonScripts","gotoLogonScript",
70       "gotoPrinter", "gosaDefaultPrinter",
71       "gotoShares","gotoShare",
72       "gotoKioskProfile");
73   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
74   var $cn;
75   var $OrigCn;
76   var $add_del_printer_member_was_called = false;
78   var $multiple_support =TRUE;
80   var $use_gotoPrinter;
82   function environment (&$config, $dn= NULL)
83   {
84     plugin::plugin ($config, $dn);
86     /* Setting uid to default */
87     if(isset($this->attrs['uid'][0])){
88       $this->uid = $this->attrs['uid'][0];
89     }
91     /* Check : Are we currently editing a group or user dialog */
92     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
93       $suffix="Group";
94       $this->uid          = $this->attrs['cn'][0];
95       $this->attrs['uid'] = $this->attrs['cn'][0];
96       $this->OrigCn = $this->attrs['cn'][0];
97     }else{
98       $suffix="User";
99     }
101     /* Get all Printer assignments */
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cd($this->config->current['BASE']);
104     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
105     while($printer = $ldap->fetch()){
106       $this->gotoPrinter[$printer['cn'][0]]=$printer;
107       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
108     }
109     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
110     while($printer = $ldap->fetch()){
111       $this->gotoPrinter[$printer['cn'][0]]=$printer;
112       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
113     }
116     /* Prepare hotplugs */
117     if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
118       $ldap = $this->config->get_ldap_link();
119       $ldap->cd($this->config->current['BASE']);
120       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
121         $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
122         if($ldap->count()){
123           $attrs = $ldap->fetch(); 
125           if(isset($attrs['gotoHotplugDevice'][0])){
126             $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
127             $tmp2     = array();
128             $tmp2['name']         = $attrs['cn'][0];
129             $tmp2['description']  = $tmp[0];
130             $tmp2['id']           = $tmp[1];
131             $tmp2['produkt']      = $tmp[2];
132             $tmp2['vendor']       = $tmp[3];
133             $tmp2['dn']           = $attrs['dn'];
134             $this->gotoHotplugDevices[] = $tmp2; 
135           }
136         }else{
137           msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
138         }
139       }
140     }
142  
143     /* prepare LogonScripts */
144     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
145       unset($this->attrs['gotoLogonScript']['count']);
146       foreach($this->attrs['gotoLogonScript'] as $device){
147         $tmp = $tmp2 = array();
148         $tmp = split("\|",$device);
149         $tmp2['LogonName']        = $tmp[0]; 
150         $tmp2['LogonPriority']    = $tmp[2]; 
151         if(preg_match("/O/i",$tmp[1])){
152           $tmp2['LogonOverload'] = "O";
153         }else{
154           $tmp2['LogonOverload'] = "";
155         }
156         if(preg_match("/L/i",$tmp[1])){
157           $tmp2['LogonLast'] = "L";
158         }else{
159           $tmp2['LogonLast'] = "";
160         }
161         $tmp2['LogonData']        = base64_decode($tmp[3]); 
162         $tmp2['LogonDescription'] = $tmp[4];
163         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
164       }
165     }
167     /* Prepare Shares */
168     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
169       unset($this->attrs['gotoShare']['count']);
170       foreach($this->attrs['gotoShare'] as $share){
171         $tmp = $tmp2 = array();
172         $tmp = split("\|",$share);
173         $tmp2['server']      =$tmp[0];
174         $tmp2['name']        =$tmp[1];
176         /* Decode base64 if needed */
177         if (!preg_match('%/%', $tmp[2])){
178           $tmp2['mountPoint']  =base64_decode($tmp[2]);
179         } else {
180           $tmp2['mountPoint']  =$tmp[2];
181         }
183         if(isset($tmp[3])){
184           $tmp2['PwdHash']  =$tmp[3];
185         }else{
186           $tmp2['PwdHash']  ="";
187         }
188         if(isset($tmp[4])){
189           $tmp2['Username']  =$tmp[4];
190         }else{
191           $tmp2['Username']  ="";
192         }
193         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
194       }
195     }
197     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
198       $chr = $this->gotoProfileFlags[$i];
199       $name = "gotoProfileFlag".$chr;
200       $this->$name=$chr;
201     }
203     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
204       $this->useProfile = true;
205     }else{
206       $this->useProfile = false;
207     }
209     /* Set resolutions */
210     $this->gotoXResolutions = array("auto"=>_("auto"),
211                                     "640x480"   =>  "640x480",
212                                     "800x600"   =>  "800x600",
213                                     "1024x768"  =>  "1024x768",
214                                     "1152x864"  =>  "1152x864",
215                                     "1280x768"  =>  "1280x768",
216                                     "1280x1024" =>  "1280x1024");
218     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
219       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
221       if(is_readable($file)){
222         $str = file_get_contents($file);
223         $lines = split("\n",$str);
224         foreach($lines as $line){
225           $line = trim($line);
226           if(!empty($line)){
227             $this->gotoXResolutions[$line]=$line;
228           }
229         }
230         //natcasesort($this->gotoXResolutions);
231       }else{
232         msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
233       }
234     }
236     $this->gotoProfileServers= $config->getShareServerList() ;
237     $this->gotoShareSelections= $config->getShareList(true);
238     $this->gotoAvailableShares= $config->getShareList(false);  
240     $this->update_kiosk_profiles();
241   }
244   function update_kiosk_profiles()
245   { 
246     $tmp1  = array("none" => array(_("disabled")));
247     $tmp2  = array("none" => _("disabled"));
248     $tmp3  = array();
249     $ldap = $this->config->get_ldap_link();
250     $ldap->cd($this->config->current['BASE']);
251     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
252     $cnt = 0;
253     while($attrs = $ldap->fetch()){
254       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
255         $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
256         $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
257         $tmp1[$attrs['cn'][0]][] = $name;
258         $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
259       }
260       $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
261       $cnt ++;
262     }
264     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
265       $this->kiosk_enabled = TRUE;
266     }
268     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
269     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
270     $this->gotoKioskProfiles['MAP']       = $tmp3;
271   
272     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
273     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
275     $error = false;
276     if(!isset($this->gotoKioskProfiles['SERVERS'][$this->gotoKioskProfile_Server])){
277       $error = true;
278     }elseif(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
279       $error = true;
280     }
281     if($error && !empty($this->gotoKioskProfile)){
282       msg_dialog::display(_("Warning"), sprintf(_("Kiosk profile '%s' located on server '%s' is not available anymore. Kiosk profile will be disabled!"), $this->gotoKioskProfile_Profile, $this->gotoKioskProfile_Server), WARNING_DIALOG);
283       $this->gotoKioskProfile_Server ="none";
284       $this->gotoKioskProfile_Profile="";
285     }elseif(empty($this->gotoKioskProfile)){
286       $this->gotoKioskProfile_Server ="none";
287       $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) && !session::is_set('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           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
333         }else{
335           /* No other profile servers found */
336           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
337           $this->gotoProfileServer = "none";
338         }
339       }
340     }    
342     $this->detect_grouptype();
344     /* Fill templating stuff */
345     $smarty= get_smarty();
346     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
347     $display= "";
349     $smarty->assign("is_group",$this->is_group);
351     /* Prepare all variables for smarty */
352     foreach($this->attributes as $s_attr){
353       /* Set value*/
354       $smarty->assign($s_attr,$this->$s_attr);
356       /* Set checkbox state*/
357       if(empty($this->$s_attr)){
358         $smarty->assign($s_attr."CHK","");
359       }else{
360         $smarty->assign($s_attr."CHK"," checked ");
361       }
363       /* Prepare ACL settings*/
364       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
365     }
367     /* Is accout enabled | are we editing from usermenu or admin menu 
368        All these tab management is done here
369      */
372     /* Working from Usermenu an the Account is currently disbled
373      * this->parent :  is only set if we are working in a list of tabs
374      * is_account   :  is only true if the needed objectClass is given
375      */
376     if((!isset($this->parent))&&(!$this->is_account)){
377       /* We are currently editing this tab from usermenu, but this account is not enabled */
378       $smarty->assign("is_account",$this->is_account);
379       /* Load template */
380       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
381       /* Avoid the "You are currently editing ...." message when you leave this tab */
382       $display .= back_to_main(); 
383       /* Display our message to the user */
384       return $display;
387       /* We are currently editing from group tabs, because 
388        * $this->parent is set
389        * posixAccount is not set, so we are not in usertabs.
390        */
391     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
392       $smarty->assign("is_account","true");
393       $this->uid          = $this->cn;
394       $this->attrs['uid'] = $this->cn;
396       /* Change state if needed */
397       if (isset($_POST['modify_state'])){
398         if(($this->acl_is_createable() && !$this->is_account) || 
399             ($this->acl_is_removeable() &&  $this->is_account)){
400           $this->is_account= !$this->is_account;
401         }
402       }
403       /* Group Dialog with enabled environment options */
404       if ($this->is_account){
405         $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
406             msgPool::featuresEnabled(_("Environment")));
407       } else {
409         /* Environment is disabled 
410            If theres is no posixAccount enabled, you won't be able to enable 
411            environment extensions
412          */
413         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
414           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
415               msgPool::featuresDisabled(_("Environment")));
416           return $display;
417         }elseif((isset($this->parent->by_object['ogroup']))){
418           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
419               msgPool::featuresDisabled(_("Environment")));
420           return $display;
421         }else{
422           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
423               msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
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_enable_header(msgPool::removeFeaturesButton(_("Environment")),
446               msgPool::featuresEnabled(_("Environment")));
447         } else {
449           if($this->parent->by_object['posixAccount']->is_account==true){
450             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
451                 msgPool::featuresDisabled(_("Environment")));
452             return $display;
453           }else{
454             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
455                 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
456             return $display;
457           }
458         }
459       }
460     }
461   
462     /* Reset header toggle */
463     if($this->multiple_support_active){
464       $display = "";
465     }
467     /* Account is Account : is_accounbt=true.
468      * Else we won't reach this. 
469      */
471     /* Prepare all variables for smarty */
472     foreach($this->attributes as $s_attr){
473       /* Set value*/
474       $smarty->assign($s_attr,$this->$s_attr);
476       /* Set checkbox state*/
477       if(empty($this->$s_attr)){
478         $smarty->assign($s_attr."CHK","");
479       }else{
480         $smarty->assign($s_attr."CHK"," checked ");
481       }
483       /* Prepare ACL settings*/
484       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
485     }
487     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
488       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
489     }
491     if($WriteOnly) {
492       $smarty->assign("gotoPrinterACL","r");
493     }else{
494       $smarty->assign("gotoPrinterACL","rw");
495     }
498     $smarty->assign("useProfile",$this->useProfile);
499     if(empty($this->useProfile) && !$this->multiple_support_active){
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         msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
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             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
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         msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
647       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
648         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
649       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
650         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
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         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
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/lists/trash.png' alt='".msgPool::delButton()."' 
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           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
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           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
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($this->multiple_support_active){
886               $type = "AddUser";
887             }elseif(isset($this->NewDeletedPrinters[$pname])){
888               $type = "AddUser";
889             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
890               $type = "AddUser";
891             }
892           }
894           if($type){
895             $this->gotoPrinter[$pname]=$tmp2[$pname];
896             $this->gotoPrinter[$pname]['mode']="user";
897             $this->add_del_printer_member_was_called = true;
899             $this->NewAddedPrinters[$pname] = $pname;
900             if(isset($this->NewDeletedPrinters[$pname])){
901               unset($this->NewDeletedPrinters[$pname]);
902             }
903           }
904         }
906         $this->is_dialog=false;
907         unset($this->dialog);
908         $this->dialog   =FALSE;
909       }
910     }
912     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
913       $printer = $_POST['gotoPrinterSel'];
914       foreach($printer as $pname){
916         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
917         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
919         $type = false;
920         if($this->is_group){
921           if(isset($this->NewAddedPrinters[$pname])){
922             $type = "Group";
923           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
924             $type = "Group";
925           }
926         }else{
927           if(isset($this->NewAddedPrinters[$pname])){
928             $type = "User";
929           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
930             $type = "User";
931           }
932         }
933         if($type){
934           $this->add_del_printer_member_was_called = true;
935           unset($this->gotoPrinter[$pname]);
937           $this->NewDeletedPrinters[$pname] = $pname;
938           if(isset($this->NewAddedPrinters[$pname])){
939             UNSET($this->NewAddedPrinters[$pname]);
940           }
941         }
942       }
943     }
945     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
946       $printers = $_POST['gotoPrinterSel'];
947       $this->add_del_printer_member_was_called = true;
948       foreach($printers as $printer){
949         if($this->gotoPrinter[$printer]['mode']=="user"){
950           $this->gotoPrinter[$printer]['mode']="admin";
951         }else{
952           $this->gotoPrinter[$printer]['mode']="user";
953         }
954       }
955     }
957     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
958       if($this->is_group){
959         msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
960       }else{
961         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
962           $this->gosaDefaultPrinter= "";
963         } else {
964           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
965         }
966       }
967     }
969     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
970     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
972     /* General behavior */
973     if(is_object($this->dialog)){
974       $this->dialog->save_object();
975       $disp =$this->dialog->execute();
976       return($disp);
977     }
979     /* Assign used attributes for multiple edit */
980     foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
981                   "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
982       $ubox ="use_".$box;
983       if(in_array($box,$this->multi_boxes)){
984         $smarty->assign($ubox,TRUE);
985       }else{
986         $smarty->assign($ubox,FALSE);
987       }
988     }
990     /* Als smarty vars are set. Get smarty template and generate output */
991     $smarty->assign("multiple_support",$this->multiple_support_active);
992     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
993     return($display);
994   }
996   function remove_from_parent()
997   {
998     /* only if it was an account*/
999     if (!$this->initially_was_account){
1000       return;
1001     }
1003     /* include global link_info */
1004     $ldap= $this->config->get_ldap_link();
1006     /* Remove and write to LDAP */
1007     plugin::remove_from_parent();
1009     /* Don't save our template variables */
1010     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1012     /* Skip all these attributes */
1013     foreach($skip as $del){
1014       unset($this->attrs[$del]);
1015     }
1017     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1019     $ldap->cd($this->dn);
1020     $this->cleanup();
1021     $ldap->modify ($this->attrs); 
1023     if($this->is_group){
1024       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1025     }else{
1026       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1027     }
1029     if (!$ldap->success()){
1030       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1031     }
1033     /* Optionally execute a command after we're done */
1034     $this->handle_post_events("remove",array("uid" => $this->uid));
1035   }
1038   /* Save data to object */
1039   function save_object()
1040   {
1041     /* Get all Posted vars 
1042      * Setup checkboxes 
1043      */
1044     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1045     if(isset($_POST['iamposted'])){
1047       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1049       if(isset($_POST['kiosk_server'])){
1050         $tmp = $_POST['kiosk_server'];
1051         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1052           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1053         }
1054       }
1055       if(isset($_POST['kiosk_profile'])){
1056         $tmp = $_POST['kiosk_profile'];
1057         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1058           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1059         }
1060       }
1062       if(preg_match("/w/",$PACL)){
1063         if(isset($_POST['useProfile'])){
1064           $this->useProfile = true;
1065         }else{
1066           $this->useProfile = false;
1067         }
1068       }
1070       if($this->acl_is_writeable("gotoProfileFlagC")){
1071         if(isset($_POST['gotoProfileFlagC'])){
1072           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1073         }else{
1074           $this->gotoProfileFlagC = false;
1075         }
1076       }
1078       if($this->acl_is_writeable("gotoProfileFlagL")){
1079         if(isset($_POST['gotoProfileFlagL'])){
1080           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1081         }else{
1082           $this->gotoProfileFlagL = false;
1083         }
1084       }
1086       plugin::save_object();
1087       foreach($this->attributes as $s_attr){
1088         if((!isset($_POST[$s_attr])) || 
1089             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1090         if(!$this->acl_is_writeable($s_attr)){
1091           continue;
1092         }else{ 
1093           if(isset($_POST[$s_attr])){
1094             $this->$s_attr = $_POST[$s_attr];
1095           }else{
1096             $this->$s_attr = false;
1097           }
1098         }
1099       }
1100     }
1101   }
1104   /* Check supplied data */
1105   function check()
1106   {
1107     /* Call common method to give check the hook */
1108     $message= plugin::check();
1110     $this->detect_grouptype();
1112     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1113       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1114     } 
1115     if(!isset($this->attrs['objectClass'])){
1116       $this->attrs['objectClass']=array();
1117     } 
1118     if(!$this->is_group){
1119       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1120         $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));  
1121       }
1122     }
1123     return ($message);
1124   }
1127   /* Save to LDAP */
1128   function save()
1129   {
1130     /* If group was renamed, all printer settings get lost
1131      */ 
1132     /* only save changed variables ....*/
1133     if ($this->gotoKioskProfile_Server != "none"){
1134       $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1135       $this->gotoKioskProfile= $method;
1136     }else{
1137       $this->gotoKioskProfile= array();
1138     }
1140     plugin::save();
1141     $ldap= $this->config->get_ldap_link();
1143     $realyUsedAttrs= array();
1145     /* Save already used objectClasses */
1146     $ocs        = $this->attrs['objectClass'];
1147     unset($ocs['count']);
1148     $this->attrs = array();
1149     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1151     /* 1. Search all printers that have our uid/cn as member 
1152      * 2. Delete this uid/cn from every single entry and save it again.
1153      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1154      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1155      */
1156     
1157     $this->detect_grouptype();
1159     if($this->add_del_printer_member_was_called){
1161       $types = array( "gotoUserPrinter"       => "AddUser",
1162           "gotoGroupPrinter"      => "AddGroup",
1163           "gotoUserAdminPrinter"  => "AddAdminUser",
1164           "gotoGroupAdminPrinter" => "AddAdminGroup");
1166       if($this->is_group){
1167         $s_suffix = "Group";
1168         $useVar   = "cn";
1169       }else{
1170         $useVar   = "uid";
1171         $s_suffix = "User";
1172       }
1174       /* Remove old entries */
1175       $ldap->cd($this->config->current['BASE']);;
1176       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1177       while($attr = $ldap->fetch()){
1178         $printerObj = NULL;
1179         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1180         $printerObj->set_acl_base($attr['dn']);
1181         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1182         $printerObj->by_object['printgeneric']->save();
1183       }
1185       $ldap->cd($this->config->current['BASE']);;
1186       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1187       while($attr = $ldap->fetch()){
1188         $printerObj = NULL;
1189         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1190         $printerObj->set_acl_base($attr['dn']);
1191         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1192         $printerObj->by_object['printgeneric']->save();
1193       }
1195       foreach($this->gotoPrinter as $printer){
1196         $printerObj = NULL;
1197         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1198         $printerObj->set_acl_base($printer['dn']);
1201         if($printer['mode'] == "admin") {
1202           $attribute = "goto".$s_suffix."AdminPrinter";
1203         }else{
1204           $attribute = "goto".$s_suffix."Printer";
1205         }
1207         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1208         $printerObj->by_object['printgeneric']->save();
1209       }
1210     }    
1212     /* Prepare HotPlug devices */
1213     $this->attrs['gotoHotplugDeviceDN'] = array();
1214     foreach($this->gotoHotplugDevices as $name => $device){
1215       $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1216     }
1218     /* Prepare LogonScripts */
1219     $this->attrs['gotoLogonScript'] = array();
1220     foreach($this->gotoLogonScripts as $name => $script){
1221       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1222         $script['LogonOverload'].$script['LogonLast']."|".
1223         $script['LogonPriority']."|".
1224         base64_encode($script['LogonData'])."|".
1225         $script['LogonDescription'];
1226     }
1228     /* Prepare Shares */
1229     $this->attrs['gotoShare']=array();
1230     foreach($this->gotoShares as $name => $share){
1231       $mntp= $share['mountPoint'];
1232       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1233         $mntp= base64_encode($mntp);
1234       }
1235       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1236     }
1239     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1240     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1242     foreach($saveThis as $tosave){
1243       if(!empty($this->$tosave)){
1244         $this->attrs[$tosave]=$this->$tosave;
1245       }else{
1246         $this->attrs[$tosave]=array();
1247       }
1248     }
1250     /* Prepare Flags */
1251     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1252     if(empty($this->attrs['gotoProfileFlags'][0])){
1253       $this->attrs['gotoProfileFlags']=array();
1254     }
1256     if($this->useProfile == false){
1257       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1258       $this->attrs['gotoProfileServer']= array(); 
1259     }
1261     $ldap->cat ($this->dn, array('dn'));
1262     if ($ldap->fetch()){
1263       $mode= "modify";
1264     } else {
1265       $mode= "add";
1266       $ldap->cd($this->config->current['BASE']);
1267       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1268     }
1270     $ldap->cd($this->dn);
1271     $this->cleanup();
1272     $ldap->$mode($this->attrs);
1273   
1274     $cat = "users";
1275     if($this->is_group){
1276       $cat = "groups";
1277     }
1279     /* Log last action */ 
1280     if($this->initially_was_account){
1281       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1282     }else{
1283       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1284     }
1286     if (!$ldap->success()){
1287       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1288     }
1289     $this->handle_post_events($mode,array("uid"=>$this->uid));
1290   }
1292   /* Generate ListBox frindly output for the defined shares 
1293    * Possibly Add or remove an attribute here, 
1294    */
1295   function printOutAssignedShares()
1296   {
1297     $a_return = array();
1298     if(is_array($this->gotoShares)){
1299       foreach($this->gotoShares as $share){
1300         if(preg_match("/^!/",$share['server'])){
1301           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1302         }else{
1303           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1304         }
1305       }
1306       natcasesort($a_return);
1307     }
1308     return($a_return);
1309   }
1311   /* Generate ListBox frindly output for the definedhotplugs 
1312    * Possibly Add or remove an attribute here,
1313    */
1314   function printOutHotPlugDevices()
1315   {
1316     $a_return= array();
1317     if(is_array($this->gotoHotplugDevices)){
1318       foreach($this->gotoHotplugDevices as $key=>$device){
1319         $a_return[$key] = $device['name']." - ".$device['id'];
1320       }
1321     }
1322     return($a_return);
1323   }
1325   /* Generates ListBox frienly output of used printer devices 
1326    * Append ' - admin' if printer is used in admin mode
1327    */
1328   function printOutPrinterDevices()
1329   {
1330     $a_return = array();
1331     
1332     if($this->acl_is_readable("gotoPrinter")){
1334       if(is_array($this->gotoPrinter)){
1335         foreach($this->gotoPrinter as $printer){
1336           if($printer['mode'] == "admin"){
1337             $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1338           }else{
1339             $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1340           }
1341           if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1342             $a_return[$printer['cn'][0]].=" - "._("Default printer");
1343           }
1344         }
1345       }
1346     }
1347     return($a_return);
1348   }
1351   function PrepareForCopyPaste($source)
1352   {
1353     plugin::PrepareForCopyPaste($source);
1355     $class= get_class($this);
1356     $o_source = new $class($this->config,$source['dn']);
1357     foreach($this->CopyPasteVars as $attr){
1358       $this->$attr = $o_source->$attr;  
1359     }
1360   }
1363   function saveCopyDialog()
1364   {
1365     if(isset($_POST['cn'])){
1366       $this->cn = $_POST['cn'];
1367       $this->uid = $_POST['cn'];
1368     }
1369   }
1372   /* Generates ListBox frienly output of used logonscripts 
1373    */
1374   function printOutLogonScripts()
1375   {
1376     $a_return = array();
1377     if(is_array($this->gotoLogonScripts)){
1378       foreach($this->gotoLogonScripts as $script){
1379         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1380       }
1381     }
1382     return($a_return);
1383   }
1386   function multiple_execute()
1387   {
1388     /* Reset header toggle */
1389     $this->is_account = TRUE;
1390     return($this->execute());
1391   }
1394     /* Initialize plugin with given atribute arrays
1395    */
1396   function init_multiple_support($attrs,$all)
1397   {
1398     plugin::init_multiple_support($attrs,$all);
1400     /* Prepare Shares */
1401     if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1402       unset($this->multi_attrs_all['gotoShare']['count']);
1403       foreach($this->multi_attrs_all['gotoShare'] as $share){
1404         $tmp = $tmp2 = array();
1405         $tmp = split("\|",$share);
1406         $tmp2['server']      =$tmp[0];
1407         $tmp2['name']        =$tmp[1];
1409         /* Decode base64 if needed */
1410         if (!preg_match('%/%', $tmp[2])){
1411           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1412         } else {
1413           $tmp2['mountPoint']  =$tmp[2];
1414         }
1416         if(isset($tmp[3])){
1417           $tmp2['PwdHash']  =$tmp[3];
1418         }else{
1419           $tmp2['PwdHash']  ="";
1420         }
1421         if(isset($tmp[4])){
1422           $tmp2['Username']  =$tmp[4];
1423         }else{
1424           $tmp2['Username']  ="";
1425         }
1426         $tmp2['UsedByAllUsers'] = FALSE;
1427         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1428       }
1429     }
1431     /* Prepare Shares */
1432     if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1433       unset($this->multi_attrs['gotoShare']['count']);
1434       foreach($this->multi_attrs['gotoShare'] as $share){
1435         $tmp = $tmp2 = array();
1436         $tmp = split("\|",$share);
1437         $tmp2['server']      =$tmp[0];
1438         $tmp2['name']        =$tmp[1];
1440         /* Decode base64 if needed */
1441         if (!preg_match('%/%', $tmp[2])){
1442           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1443         } else {
1444           $tmp2['mountPoint']  =$tmp[2];
1445         }
1447         if(isset($tmp[3])){
1448           $tmp2['PwdHash']  =$tmp[3];
1449         }else{
1450           $tmp2['PwdHash']  ="";
1451         }
1452         if(isset($tmp[4])){
1453           $tmp2['Username']  =$tmp[4];
1454         }else{
1455           $tmp2['Username']  ="";
1456         }
1457         $tmp2['UsedByAllUsers'] = TRUE;
1458         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1459       }
1460     }
1463     /* prepare LogonScripts */
1464     if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1465       unset($this->multi_attrs_all['gotoLogonScript']['count']);
1466       foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1467         $tmp = $tmp2 = array();
1468         $tmp = split("\|",$device);
1469         $tmp2['LogonName']        = $tmp[0];
1470         $tmp2['LogonPriority']    = $tmp[2];
1471         if(preg_match("/O/i",$tmp[1])){
1472           $tmp2['LogonOverload'] = "O";
1473         }else{
1474           $tmp2['LogonOverload'] = "";
1475         }
1476         if(preg_match("/L/i",$tmp[1])){
1477           $tmp2['LogonLast'] = "L";
1478         }else{
1479           $tmp2['LogonLast'] = "";
1480         }
1481         $tmp2['LogonData']        = base64_decode($tmp[3]);
1482         $tmp2['LogonDescription'] = $tmp[4];
1483         $tmp2['UsedByAllUsers'] = FALSE;
1484         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1485       }
1486     }
1488     /* prepare LogonScripts */
1489     if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1490       unset($this->multi_attrs['gotoLogonScript']['count']);
1491       foreach($this->multi_attrs['gotoLogonScript'] as $device){
1492         $tmp = $tmp2 = array();
1493         $tmp = split("\|",$device);
1494         $tmp2['LogonName']        = $tmp[0];
1495         $tmp2['LogonPriority']    = $tmp[2];
1496         if(preg_match("/O/i",$tmp[1])){
1497           $tmp2['LogonOverload'] = "O";
1498         }else{
1499           $tmp2['LogonOverload'] = "";
1500         }
1501         if(preg_match("/L/i",$tmp[1])){
1502           $tmp2['LogonLast'] = "L";
1503         }else{
1504           $tmp2['LogonLast'] = "";
1505         }
1506         $tmp2['LogonData']        = base64_decode($tmp[3]);
1507         $tmp2['LogonDescription'] = $tmp[4];
1508         $tmp2['UsedByAllUsers'] = TRUE;
1509         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1510       }
1511     }
1513     /* Prepare hotplugs */
1514     if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1515       $ldap = $this->config->get_ldap_link();
1516       $ldap->cd($this->config->current['BASE']);
1517       for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1518         $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1519         if($ldap->count()){
1520           $multi_attrs_all = $ldap->fetch();
1522           if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1523             $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1524             $tmp2     = array();
1525             $tmp2['name']         = $multi_attrs_all['cn'][0];
1526             $tmp2['description']  = $tmp[0];
1527             $tmp2['id']           = $tmp[1];
1528             $tmp2['produkt']      = $tmp[2];
1529             $tmp2['vendor']       = $tmp[3];
1530             $tmp2['dn']           = $multi_attrs_all['dn'];
1531             $tmp2['UsedByAllUsers'] = FALSE;
1532             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1533           }
1534         }
1535       }
1536     }
1538     /* Prepare hotplugs */
1539     if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1540       $ldap = $this->config->get_ldap_link();
1541       $ldap->cd($this->config->current['BASE']);
1542       for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1543         $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1544         if($ldap->count()){
1545           $multi_attrs = $ldap->fetch();
1547           if(isset($multi_attrs['gotoHotplugDevice'][0])){
1548             $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1549             $tmp2     = array();
1550             $tmp2['name']         = $multi_attrs['cn'][0];
1551             $tmp2['description']  = $tmp[0];
1552             $tmp2['id']           = $tmp[1];
1553             $tmp2['produkt']      = $tmp[2];
1554             $tmp2['vendor']       = $tmp[3];
1555             $tmp2['dn']           = $multi_attrs['dn'];
1556             $tmp2['UsedByAllUsers'] = TRUE;
1557             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1558           }
1559         }
1560       }
1561     }
1562     $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1563     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1564       $chr = $this->gotoProfileFlags[$i];
1565       $name = "gotoProfileFlag".$chr;
1566       $this->$name=$chr;
1567     }
1568     $this->update_kiosk_profiles();
1569     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1571     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1572       $this->useProfile = true;
1573     }else{
1574       $this->useProfile = false;
1575     }
1577   }
1580   function set_multi_edit_values($attrs)
1581   {
1582     $shares = $this->gotoShares;
1583     $scripts= $this->gotoLogonScripts;
1584     $plugs= $this->gotoHotplugDevices;
1585     plugin::set_multi_edit_values($attrs);
1587     $this->gotoShares = $shares;
1588     $this->gotoLogonScripts = $scripts;
1589     $this->gotoHotplugDevices = $plugs;
1591     foreach($attrs['gotoShares'] as $name => $share){
1592       if($share['UsedByAllUsers'] == TRUE){
1593         $this->gotoShares[$name] = $share;
1594       }
1595     }
1596     foreach($this->gotoShares as $name => $share){
1597       if(!isset($attrs['gotoShares'][$name])){
1598         unset($this->gotoShares[$name]);
1599       }
1600     }
1601     foreach($attrs['gotoLogonScripts'] as $name => $script){
1602       if($script['UsedByAllUsers'] == TRUE){
1603         $this->gotoLogonScripts[$name] = $script;
1604       }
1605     }
1606     foreach($this->gotoLogonScripts as $name => $script){
1607       if(!isset($attrs['gotoLogonScripts'][$name])){
1608         unset($this->gotoLogonScripts[$name]);
1609       }
1610     }
1611     $tmp = array();
1612     foreach($this->gotoHotplugDevices as $entry){
1613       $tmp[$entry['dn']] = $entry;
1614     }
1615   
1616     foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1617       if($plug['UsedByAllUsers'] == TRUE){
1618         $tmp[$plug['dn']] = $plug;
1619       }
1620     }
1621     foreach($tmp as $name => $plug){
1622       $found = false;
1623       foreach($attrs['gotoHotplugDevices'] as $test){
1624         if($test['dn'] == $name){
1625           $found = true;
1626         }
1627       }
1628       if(!$found){
1629         unset($tmp[$name]);
1630       }
1631     }
1632   }
1635     /* Return selected values for multiple edit */
1636   function get_multi_edit_values()
1637   {
1638     $ret = plugin::get_multi_edit_values();
1639     $ret['gotoShares'] = $this->gotoShares;
1640     $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1641     $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1642   
1643     if(in_array("gotoPrinter",$this->multi_boxes)){
1644       $ret['gotoPrinter'] = $this->gotoPrinter;
1645       $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1646       $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1647   
1648       /* Force printer reset */
1649       $ret['add_del_printer_member_was_called'] = TRUE;
1650     }
1651   
1652     if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1653       $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1654     }
1656     if(in_array("useProfile",$this->multi_boxes)){
1657       $ret['useProfile']=$this->useProfile;
1658       if(in_array("gotoProfileServer",$this->multi_boxes)){
1659         $ret['gotoProfileServer']=$this->gotoProfileServer;
1660       }
1661       if(in_array("gotoProfileQuota",$this->multi_boxes)){
1662         $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1663       }
1664       if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1665         $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1666       }
1667     }
1668     if(in_array("gotoXResolution",$this->multi_boxes)){
1669       $ret['gotoXResolution'] = $this->gotoXResolution;
1670     }
1671     if(in_array("kiosk_server",$this->multi_boxes)){
1672       $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1673       $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1674     }
1675     return($ret);
1676   }
1679   function multiple_check() 
1680   {
1681     $message = plugin::multiple_check();
1682     $this->detect_grouptype();
1684     if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1685       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1686     }
1687     return($message);
1688   }
1691   function multiple_save_object()
1692   {
1693     if(isset($_POST['environment_multiple_posted'])){
1694       plugin::multiple_save_object();
1695       
1696       if(isset($_POST['useProfile'])){
1697         $this->useProfile = true;
1698       }else{
1699         $this->useProfile = false;
1700       }
1701       if(isset($_POST['gotoProfileFlagC'])){
1702         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1703       }else{
1704         $this->gotoProfileFlagC = false;
1705       }
1707       if(isset($_POST['gotoProfileFlagL'])){
1708         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1709       }else{
1710         $this->gotoProfileFlagL = false;
1711       }
1713       foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1714                     "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1715         $uattr = "use_".$attr;
1716         if(isset($_POST[$uattr])){
1717           $this->multi_boxes[] = $attr;
1718         }
1719       }
1720       if(isset($_POST['kiosk_server'])){
1721         $tmp = $_POST['kiosk_server'];
1722         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1723           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1724         }
1725       }
1726       if(isset($_POST['kiosk_profile'])){
1727         $tmp = $_POST['kiosk_profile'];
1728         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1729           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1730         }
1731       }
1733     }
1734   }
1736   /* Return plugin informations for acl handling 
1737 #FIXME these ACLs should work for groups too */ 
1738   static function plInfo()
1739   {
1740     return (array("plShortName"     => _("Environment"),
1741           "plDescription"   => _("Environment settings"),         // Description
1742           "plSelfModify"    => TRUE,                              
1743           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1744           "plPriority"      => 3,                                 // Position in tabs 
1745           "plSection"     => array("personal" => _("My account")),
1746           "plCategory"    => array("users",
1747                                    "groups"),
1748           "plOptions"       => array("resolution_hook" => array("type" => "string",
1749               "description" => _("Command to extend the list of possible screen resolutions"))),
1751           "plProvidedAcls"  => array(
1753             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1754             "gotoProfileFlagC"    => _("Cache profile localy") ,
1756             "gotoProfileQuota"    => _("Profile quota") ,
1757             "gotoProfileServer"   => _("Profile server") ,
1759             "gotoXResolution"     => _("Resolution") ,
1760             "gotoKioskProfile"    => _("Kiosk profile") ,
1762             "gosaDefaultPrinter"  => _("Default printer") ,
1763             "gotoLogonScript"     => _("Logon script") ,
1764             "gotoHotplugDevice"   => _("Hotplug devices"),
1765             "gotoShare"           => _("Shares"))
1766             ));
1767   }
1770 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1771 ?>