Code

775cd3ed1040a39d90f72932d8247bcc9a202380
[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     $ldap = $this->config->get_ldap_link();
249     $ldap->cd($this->config->current['BASE']);
250     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
251     $cnt = 0;
252     while($attrs = $ldap->fetch()){
253       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
254         $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
255         $tmp1[$attrs['cn'][0]][] = $name;
256       }
257       $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
258       $cnt ++;
259     }
261     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
262       $this->kiosk_enabled = TRUE;
263     }
265     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
266     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
267   
268     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
269     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
271     $error = false;
272     if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
273       $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
274       $error = true;
275     }
276   
277     if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
278       $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
279       $error = true;
280     }
281     if($error && !empty($this->gotoKioskProfile)){
282       $this->gotoKioskProfile_Server ="none";
283       $this->gotoKioskProfile_Profile="";
284       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);
285     }
286   }
289   /* Detect type of edited object (user|group)*/
290   function detect_grouptype()
291   {
292     if((!isset($this->parent))&&(!$this->is_account)){
293       $this->is_group     = false;
294     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
295       $this->is_group     = true;
296     }else{
297       $this->is_group     = false;
298     }
299   }
302   function execute()
303   {
305     /* Call parent execute */
306     plugin::execute();
307     /* Log view */
308     if($this->is_account && !$this->view_logged){
309       $this->view_logged = TRUE;
310       if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
311         new log("view","users/".get_class($this),$this->dn);
312       }else{
313         new log("view","groups/".get_class($this),$this->dn);
314       }
315     }
317     /* Are we editing from MyAccount and not editing a user */
318     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
320     /* Check profile server */
321     if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
322       if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
323         if(count($this->gotoProfileServers)){
325           /* Get First Profile */
326           $new = key($this->gotoProfileServers);
328           /* Another profile server found */
329           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
330         }else{
332           /* No other profile servers found */
333           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
334           $this->gotoProfileServer = "none";
335         }
336       }
337     }    
339     $this->detect_grouptype();
341     /* Fill templating stuff */
342     $smarty= get_smarty();
343     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
344     $display= "";
346     $smarty->assign("is_group",$this->is_group);
348     /* Prepare all variables for smarty */
349     foreach($this->attributes as $s_attr){
350       /* Set value*/
351       $smarty->assign($s_attr,$this->$s_attr);
353       /* Set checkbox state*/
354       if(empty($this->$s_attr)){
355         $smarty->assign($s_attr."CHK","");
356       }else{
357         $smarty->assign($s_attr."CHK"," checked ");
358       }
360       /* Prepare ACL settings*/
361       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
362     }
364     /* Is accout enabled | are we editing from usermenu or admin menu 
365        All these tab management is done here
366      */
369     /* Working from Usermenu an the Account is currently disbled
370      * this->parent :  is only set if we are working in a list of tabs
371      * is_account   :  is only true if the needed objectClass is given
372      */
373     if((!isset($this->parent))&&(!$this->is_account)){
374       /* We are currently editing this tab from usermenu, but this account is not enabled */
375       $smarty->assign("is_account",$this->is_account);
376       /* Load template */
377       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
378       /* Avoid the "You are currently editing ...." message when you leave this tab */
379       $display .= back_to_main(); 
380       /* Display our message to the user */
381       return $display;
384       /* We are currently editing from group tabs, because 
385        * $this->parent is set
386        * posixAccount is not set, so we are not in usertabs.
387        */
388     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
389       $smarty->assign("is_account","true");
390       $this->uid          = $this->cn;
391       $this->attrs['uid'] = $this->cn;
393       /* Change state if needed */
394       if (isset($_POST['modify_state'])){
395         if(($this->acl_is_createable() && !$this->is_account) || 
396             ($this->acl_is_removeable() &&  $this->is_account)){
397           $this->is_account= !$this->is_account;
398         }
399       }
400       /* Group Dialog with enabled environment options */
401       if ($this->is_account){
402         $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
403             msgPool::featuresEnabled(_("Environment")));
404       } else {
406         /* Environment is disabled 
407            If theres is no posixAccount enabled, you won't be able to enable 
408            environment extensions
409          */
410         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
411           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
412               msgPool::featuresDisabled(_("Environment")));
413           return $display;
414         }else{
415           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
416               msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
417           return $display;
418         }
419       }
420     }else{
421       /* Editing from Usermenu 
422        *  Tell smarty that this accoutn is enabled 
423        */
424       $smarty->assign("is_account","true");
426       /* Change state if needed */
427       if (isset($_POST['modify_state'])){
428         if(($this->acl_is_createable() && !$this->is_account) || 
429             ($this->acl_is_removeable() &&  $this->is_account)){
430           $this->is_account= !$this->is_account;
431         }
432       }
434       if(isset($this->parent)){
436         // 3. Account enabled . Editing from adminmenu
437         if ($this->is_account){
438           $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
439               msgPool::featuresEnabled(_("Environment")));
440         } else {
442           if($this->parent->by_object['posixAccount']->is_account==true){
443             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
444                 msgPool::featuresDisabled(_("Environment")));
445             return $display;
446           }else{
447             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
448                 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
449             return $display;
450           }
451         }
452       }
453     }
454   
455     /* Reset header toggle */
456     if($this->multiple_support_active){
457       $display = "";
458     }
460     /* Account is Account : is_accounbt=true.
461      * Else we won't reach this. 
462      */
464     /* Prepare all variables for smarty */
465     foreach($this->attributes as $s_attr){
466       /* Set value*/
467       $smarty->assign($s_attr,$this->$s_attr);
469       /* Set checkbox state*/
470       if(empty($this->$s_attr)){
471         $smarty->assign($s_attr."CHK","");
472       }else{
473         $smarty->assign($s_attr."CHK"," checked ");
474       }
476       /* Prepare ACL settings*/
477       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
478     }
480     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
481       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
482     }
484     if($WriteOnly) {
485       $smarty->assign("gotoPrinterACL","r");
486     }else{
487       $smarty->assign("gotoPrinterACL","rw");
488     }
491     $smarty->assign("useProfile",$this->useProfile);
492     if(empty($this->useProfile) && !$this->multiple_support_active){
493       $smarty->assign("useProfileCHK","");
494       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
495       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
496       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
497     }else{
498       $smarty->assign("useProfileCHK"," checked ");
499     }
500     
501     $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
502     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
504     /* HANDLE Profile Settings here 
505      * Assign available Quota and resolution settings
506      * Get all available profile server
507      * Get cache checkbox
508      * Assign this all to Smarty 
509      */
511     if(empty($this->gotoProfileFlagL)){
512       $smarty->assign("gotoProfileFlagLCHK"," ");
513     }else{
514       $smarty->assign("gotoProfileFlagLCHK"," checked ");
515     }
517     if(empty($this->gotoProfileFlagC)){
518       $smarty->assign("gotoProfileFlagCCHK"," ");
519     }else{
520       $smarty->assign("gotoProfileFlagCCHK"," checked ");
521     }
524     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
525     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
527     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
528     if(!is_array($this->gotoProfileServers)){
529       $this->gotoProfileServers =array();
530     }
531     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
533     /* Handle kiosk profiles*/
534     $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
535     $smarty->assign("kiosk_server" ,  $this->gotoKioskProfile_Server);
536     $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
537     $smarty->assign("kiosk_profile" ,  $this->gotoKioskProfile_Profile);
538   
540     /* Logonscript Management
541      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
542      * Perform add Delete edit Posts 
543      */
545     /* Dialog Save */
546     if(isset($_POST['LogonSave'])){
548       if(!$this->acl_is_writeable("gotoLogonScript")){
549         msg_dialog::display(_("Permission error"), _("You have no permission to modify logon scripts!"), ERROR_DIALOG);
550         unset($this->dialog);
551         $this->dialog=FALSE;
552         $this->is_dialog=false;
553       }else{
554         $this->dialog->save_object();
555         if(count($this->dialog->check())!=0){
556           foreach($this->dialog->check() as $msg){
557             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
558           }
559         }else{
560           $tmp = $this->dialog->save();
561           unset($this->dialog);
562           $this->dialog=FALSE;
563           $this->is_dialog=false;
565           if($this->multiple_support_active){
566             $tmp['UsedByAllUsers'] = TRUE;
567           }
568           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
569         }
570       }
571     }
572     
574     /* Dialog Quit without saving */
575     if(isset($_POST['LogonCancel'])){
576       $this->is_dialog= false;
577       unset($this->dialog);
578       $this->dialog= FALSE;
579     }
581     /* Check Edit Del New Posts for a selected LogonScript */ 
582     if($this->acl_is_writeable("gotoLogonScript") && 
583         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
585       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
586        * In this case we create a new Logon Script.
587        */
588       if(isset($_POST['gotoLogonScriptNew'])){
589         $this->is_dialog = true;
590         $this->dialog = new logonManagementDialog($this->config,$this->dn);
591       }
593       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
594        * We only can delete if there is an entry selected.
595        */
596       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
597         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
598       }
600       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
601        * There must be an entry selected to perform edit request.
602        */
603       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
604         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
605         $this->is_dialog = true;
606         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
607       }
608     }
610     /* Append List to smarty*/
611     if($this->multiple_support_active){
612       $smarty->assign("gotoLogonScripts",  $this->gotoLogonScripts);
613       $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
614     }else{
615       $ls = $this->printOutLogonScripts();
616       $smarty->assign("gotoLogonScripts",  $ls);
617       $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
618       $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
619     }
621     /* In this section server shares will be defined 
622      * A user can select one of the given shares and a mount point
623      *  and attach this combination to his setup.
624      */
626     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
627     if(!is_array($this->gotoShareSelections)){
628       $this->gotoShareSelections = array();
629     }
630     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
632     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
633      * This entry will be, a combination of mountPoint and sharedefinitions 
634      */
635     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
637       /* We assign a share to this user, if we don't know where to mount the share */
638       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
639         msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
640       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
641         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
642       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
643         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
644       }elseif(!(
645             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
646             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
647             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
648             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
649             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
650             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
651             preg_match("/^%/",$_POST['gotoShareMountPoint'])
652             )
653           ){
654         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
655       }else{
656         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
657         $s_mount = $_POST['gotoShareMountPoint'];
658         $s_user  = $_POST['ShareUser'];
659         /* Preparing the new assignment */ 
660         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
661         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
662         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
663         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
665         if($this->multiple_support_active){
666           $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
667         }
668       }
669     }  
671     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
672      * If there is no defined share selected, we will abort the deletion without any message 
673      */
674     $once = true;
675     if($this->acl_is_writeable("gotoShare")){
676       foreach($_POST as $name => $value){
677         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
678           $once = false;  
679           $key  = preg_replace("/^gotoShareDel_/","",$name);
680           $key  = preg_replace("/_+[xy]$/","",$key);
681           $key  = base64_decode($key);
682           if(isset($this->gotoShares[$key])) {
683             unset($this->gotoShares[$key]);
684           }
686           /* Remove corresponding password entry, too. This is a workaround
687              to get rid of old-style entries. */
688           $key= preg_replace("/\|/", "|!", $key);
689           if(isset($this->gotoShares[$key])) {
690             unset($this->gotoShares[$key]);
691           }
692         }
693         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
694           $once = false;
695           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
696           $key  = preg_replace("/_+[xy]$/","",$key);
697           $key  = base64_decode($key);
698           $this->gotoShares[$key]['PwdHash'] = "";
699           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
700             unset($this->gotoShares[$key]);
701           }
702         }
703       }
704     }
705     $divlistShares = new divSelectBox("gotoShares");
706     $divlistShares->SetHeight(100);
709     $tmp = array();
710     if($this->acl_is_readable("gotoShares")){
711       $tmp = $this->printOutAssignedShares();
712     }
714     
715     foreach($tmp as $key => $value){
716       $img = "";
718       /* Skip apssword only entries */
719       if( empty($this->gotoShares[$key]['server']) && 
720           empty($this->gotoShares[$key]['name']) &&
721           empty($this->gotoShares[$key]['mountPoint']) &&
722           empty($this->gotoShares[$key]['Username'])){
723         continue;
724       } 
726       $color = "";
727       if($this->multiple_support_active){
728         if($this->gotoShares[$key]['UsedByAllUsers']){
729           $value .= "&nbsp;(<b>"._("Used by all users")."</b>)";
730         }else{
731           $color = "color: #999999;";
732           $value .= "&nbsp;(<b>"._("Used by some users")."</b>)";
733         }
734       }
736       /* Check if entry starts with an ! */
737       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
739         /* If we are currently editing groups environment, skip those ! entries */ 
740         if($this->is_group) continue;
742         /* Create pwd reset images */
743         if($this->gotoShares[$key]['PwdHash'] != ""){
744           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
745             title='"._("Reset password hash")."'>";
746         }
747         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
748         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
749       }else{
751         /* Create pwd reset img && delete image */
752         if($this->gotoShares[$key]['PwdHash'] != ""){
753           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
754             title='"._("Reset password hash")."'>";
755           $img.= "&nbsp;";
756         }
757         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='".msgPool::delButton()."' 
758           title='"._("Delete share entry")."'>";
759         $field1 = array("string" => $value , "attach" => "style='".$color."'");
760         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
761       }
762       $divlistShares->AddEntry(array($field1,$field2));
763     }
764     $smarty->assign("divlistShares",$divlistShares->DrawList());
766     /* Hotplug devices will be handled here 
767      * There are 3 possible methods for this feature
768      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
769      * Delete will erase an entry, the entry must be selcted in the ListBox first
770      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
771      */
773     /* We have to delete the selected hotplug from the list*/
774     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
775       if($this->acl_is_writeable("gotoHotplugDevice")){
776         foreach($_POST['gotoHotplugDevice_post'] as $name){
777           unset($this->gotoHotplugDevices[$name]);
778         }
779       }
780     }
782     /* There are already defined hotplugs from other users we could use */
783     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
784       $tmp  =array();
785       foreach($this->gotoHotplugDevices as $plugs){
786         $tmp[] = $plugs['name'];
787       }
788       $this->dialog = new hotplugDialog($this->config,$tmp);
789       $this->is_dialog = true;
790     }
792     /* Dialog Aborted */
793     if(isset($_POST['HotPlugCancel'])){
794       unset($this->dialog);
795       $this->dialog= FALSE;
796       $this->is_dialog = false;
797     }
799     /* Dialod saved */
800     if(isset($_POST['HotPlugSave'])){
802       $this->dialog->save_object();
803       if(count($this->dialog->check())!=0){
804         foreach($this->dialog->check() as $msg){
805           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
806         }
807       }else{
808         $this->dialog->save_object();
809         $a_tmp = $this->dialog->save();
811         if(is_array($a_tmp)){
812           foreach($a_tmp as $name => $hotplug){
813             if($this->multiple_support_active){
814               $hotplug['UsedByAllUsers'] = TRUE;
815             }
816             $this->gotoHotplugDevices[$name]= $hotplug; 
817           }
818         }
819         unset($this->dialog);
820         $this->dialog= FALSE;
821         $this->is_dialog = false;
822       }
823     }
825     if($this->multiple_support_active){
826       $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
827     }else{
828       $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
829       $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
830     }
832     /* Printer Assignment will managed below 
833      * A printer can be assigned in two different ways and two different types
834      * There are 2 types of users assigned to a printer : user and admin
835      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
836      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
837      */ 
839     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
840     if(isset($_POST['gotoPrinterAdd'])){
842       $this->is_dialog=true;
843       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
844     }
846     if(isset($_POST['PrinterCancel'])){
847       $this->is_dialog=false;
848       unset($this->dialog);
849       $this->dialog=FALSE;
850     }
852     if(isset($_POST['PrinterSave'])){
853       if(count($this->dialog->check())!=0){
854         $tmp = $this->dialog->check();
855         foreach($tmp as $msg){
856           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
857         } 
858       }else{
859         $this->dialog->save_object();
860         $tmp = $this->dialog->save();
861         $tmp2= $this->dialog->getPrinter(true);
863         foreach($tmp as $pname){
864           $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
865           $printerObj->set_acl_base($tmp2[$pname]['dn']);
867           $type = false;
869           if($this->is_group){
870             if($this->dn == "new"){  
871               $type = "AddGroup";
872             }elseif(isset($this->NewDeletedPrinters[$pname])){
873               $type = "AddGroup";
874             }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
875               $type = "AddGroup";
876             }
877           }else{
878             if($this->multiple_support_active){
879               $type = "AddUser";
880             }elseif(isset($this->NewDeletedPrinters[$pname])){
881               $type = "AddUser";
882             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
883               $type = "AddUser";
884             }
885           }
887           if($type){
888             $this->gotoPrinter[$pname]=$tmp2[$pname];
889             $this->gotoPrinter[$pname]['mode']="user";
890             $this->add_del_printer_member_was_called = true;
892             $this->NewAddedPrinters[$pname] = $pname;
893             if(isset($this->NewDeletedPrinters[$pname])){
894               unset($this->NewDeletedPrinters[$pname]);
895             }
896           }
897         }
899         $this->is_dialog=false;
900         unset($this->dialog);
901         $this->dialog   =FALSE;
902       }
903     }
905     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
906       $printer = $_POST['gotoPrinterSel'];
907       foreach($printer as $pname){
909         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
910         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
912         $type = false;
913         if($this->is_group){
914           if(isset($this->NewAddedPrinters[$pname])){
915             $type = "Group";
916           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
917             $type = "Group";
918           }
919         }else{
920           if(isset($this->NewAddedPrinters[$pname])){
921             $type = "User";
922           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
923             $type = "User";
924           }
925         }
926         if($type){
927           $this->add_del_printer_member_was_called = true;
928           unset($this->gotoPrinter[$pname]);
930           $this->NewDeletedPrinters[$pname] = $pname;
931           if(isset($this->NewAddedPrinters[$pname])){
932             UNSET($this->NewAddedPrinters[$pname]);
933           }
934         }
935       }
936     }
938     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
939       $printers = $_POST['gotoPrinterSel'];
940       $this->add_del_printer_member_was_called = true;
941       foreach($printers as $printer){
942         if($this->gotoPrinter[$printer]['mode']=="user"){
943           $this->gotoPrinter[$printer]['mode']="admin";
944         }else{
945           $this->gotoPrinter[$printer]['mode']="user";
946         }
947       }
948     }
950     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
951       if($this->is_group){
952         msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
953       }else{
954         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
955           $this->gosaDefaultPrinter= "";
956         } else {
957           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
958         }
959       }
960     }
962     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
963     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
965     /* General behavior */
966     if(is_object($this->dialog)){
967       $this->dialog->save_object();
968       $disp =$this->dialog->execute();
969       return($disp);
970     }
972     /* Assign used attributes for multiple edit */
973     foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
974                   "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
975       $ubox ="use_".$box;
976       if(in_array($box,$this->multi_boxes)){
977         $smarty->assign($ubox,TRUE);
978       }else{
979         $smarty->assign($ubox,FALSE);
980       }
981     }
983     /* Als smarty vars are set. Get smarty template and generate output */
984     $smarty->assign("multiple_support",$this->multiple_support_active);
985     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
986     return($display);
987   }
989   function remove_from_parent()
990   {
991     /* only if it was an account*/
992     if (!$this->initially_was_account){
993       return;
994     }
996     /* include global link_info */
997     $ldap= $this->config->get_ldap_link();
999     /* Remove and write to LDAP */
1000     plugin::remove_from_parent();
1002     /* Don't save our template variables */
1003     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1005     /* Skip all these attributes */
1006     foreach($skip as $del){
1007       unset($this->attrs[$del]);
1008     }
1010     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1012     $ldap->cd($this->dn);
1013     $this->cleanup();
1014     $ldap->modify ($this->attrs); 
1016     if($this->is_group){
1017       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1018     }else{
1019       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1020     }
1022     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
1024     /* Optionally execute a command after we're done */
1025     $this->handle_post_events("remove",array("uid" => $this->uid));
1026   }
1029   /* Save data to object */
1030   function save_object()
1031   {
1032     /* Get all Posted vars 
1033      * Setup checkboxes 
1034      */
1035     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1036     if(isset($_POST['iamposted'])){
1038       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1040       if(isset($_POST['kiosk_server'])){
1041         $tmp = $_POST['kiosk_server'];
1042         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1043           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1044         }
1045       }
1046       if(isset($_POST['kiosk_profile'])){
1047         $tmp = $_POST['kiosk_profile'];
1048         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1049           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1050         }
1051       }
1053       if(preg_match("/w/",$PACL)){
1054         if(isset($_POST['useProfile'])){
1055           $this->useProfile = true;
1056         }else{
1057           $this->useProfile = false;
1058         }
1059       }
1061       if($this->acl_is_writeable("gotoProfileFlagC")){
1062         if(isset($_POST['gotoProfileFlagC'])){
1063           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1064         }else{
1065           $this->gotoProfileFlagC = false;
1066         }
1067       }
1069       if($this->acl_is_writeable("gotoProfileFlagL")){
1070         if(isset($_POST['gotoProfileFlagL'])){
1071           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1072         }else{
1073           $this->gotoProfileFlagL = false;
1074         }
1075       }
1077       plugin::save_object();
1078       foreach($this->attributes as $s_attr){
1079         if((!isset($_POST[$s_attr])) || 
1080             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1081         if(!$this->acl_is_writeable($s_attr)){
1082           continue;
1083         }else{ 
1084           if(isset($_POST[$s_attr])){
1085             $this->$s_attr = $_POST[$s_attr];
1086           }else{
1087             $this->$s_attr = false;
1088           }
1089         }
1090       }
1091     }
1092   }
1095   /* Check supplied data */
1096   function check()
1097   {
1098     /* Call common method to give check the hook */
1099     $message= plugin::check();
1101     $this->detect_grouptype();
1103     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1104       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1105     } 
1106     if(!isset($this->attrs['objectClass'])){
1107       $this->attrs['objectClass']=array();
1108     } 
1109     if(!$this->is_group){
1110       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1111         $message[]=(_("You need to enable POSIX features in order to enable evironment features!"));  
1112       }
1113     }
1114     return ($message);
1115   }
1118   /* Save to LDAP */
1119   function save()
1120   {
1121     /* If group was renamed, all printer settings get lost
1122      */ 
1123     /* only save changed variables ....*/
1124     if ($this->gotoKioskProfile_Server != "none"){
1125       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1126         $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1127       }else{
1128         $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1129       }
1130       $this->gotoKioskProfile= $method;
1131     }else{
1132       $this->gotoKioskProfile= array();
1133     }
1135     plugin::save();
1136     $ldap= $this->config->get_ldap_link();
1138     $realyUsedAttrs= array();
1140     /* Save already used objectClasses */
1141     $ocs        = $this->attrs['objectClass'];
1142     unset($ocs['count']);
1143     $this->attrs = array();
1144     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1146     /* 1. Search all printers that have our uid/cn as member 
1147      * 2. Delete this uid/cn from every single entry and save it again.
1148      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1149      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1150      */
1151     
1152     $this->detect_grouptype();
1154     if($this->add_del_printer_member_was_called){
1156       $types = array( "gotoUserPrinter"       => "AddUser",
1157           "gotoGroupPrinter"      => "AddGroup",
1158           "gotoUserAdminPrinter"  => "AddAdminUser",
1159           "gotoGroupAdminPrinter" => "AddAdminGroup");
1161       if($this->is_group){
1162         $s_suffix = "Group";
1163         $useVar   = "cn";
1164       }else{
1165         $useVar   = "uid";
1166         $s_suffix = "User";
1167       }
1169       /* Remove old entries */
1170       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1171       while($attr = $ldap->fetch()){
1172         $printerObj = NULL;
1173         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1174         $printerObj->set_acl_base($attr['dn']);
1175         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1176         $printerObj->by_object['printgeneric']->save();
1177       }
1179       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1180       while($attr = $ldap->fetch()){
1181         $printerObj = NULL;
1182         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1183         $printerObj->set_acl_base($attr['dn']);
1184         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1185         $printerObj->by_object['printgeneric']->save();
1186       }
1188       foreach($this->gotoPrinter as $printer){
1189         $printerObj = NULL;
1190         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1191         $printerObj->set_acl_base($printer['dn']);
1194         if($printer['mode'] == "admin") {
1195           $attribute = "goto".$s_suffix."AdminPrinter";
1196         }else{
1197           $attribute = "goto".$s_suffix."Printer";
1198         }
1200         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1201         $printerObj->by_object['printgeneric']->save();
1202       }
1203     }    
1205     /* Prepare HotPlug devices */
1206     $this->attrs['gotoHotplugDeviceDN'] = array();
1207     foreach($this->gotoHotplugDevices as $name => $device){
1208       $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1209     }
1211     /* Prepare LogonScripts */
1212     $this->attrs['gotoLogonScript'] = array();
1213     foreach($this->gotoLogonScripts as $name => $script){
1214       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1215         $script['LogonOverload'].$script['LogonLast']."|".
1216         $script['LogonPriority']."|".
1217         base64_encode($script['LogonData'])."|".
1218         $script['LogonDescription'];
1219     }
1221     /* Prepare Shares */
1222     $this->attrs['gotoShare']=array();
1223     foreach($this->gotoShares as $name => $share){
1224       $mntp= $share['mountPoint'];
1225       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1226         $mntp= base64_encode($mntp);
1227       }
1228       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1229     }
1232     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1233     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1235     foreach($saveThis as $tosave){
1236       if(!empty($this->$tosave)){
1237         $this->attrs[$tosave]=$this->$tosave;
1238       }else{
1239         $this->attrs[$tosave]=array();
1240       }
1241     }
1243     /* Prepare Flags */
1244     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1245     if(empty($this->attrs['gotoProfileFlags'][0])){
1246       $this->attrs['gotoProfileFlags']=array();
1247     }
1249     if($this->useProfile == false){
1250       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1251       $this->attrs['gotoProfileServer']= array(); 
1252     }
1254     $ldap->cat ($this->dn, array('dn'));
1255     if ($ldap->fetch()){
1256       $mode= "modify";
1257     } else {
1258       $mode= "add";
1259       $ldap->cd($this->config->current['BASE']);
1260       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1261     }
1263     $ldap->cd($this->dn);
1264     $this->cleanup();
1265     $ldap->$mode($this->attrs);
1266   
1267     $cat = "users";
1268     if($this->is_group){
1269       $cat = "groups";
1270     }
1272     /* Log last action */ 
1273     if($this->initially_was_account){
1274       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1275     }else{
1276       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1277     }
1279     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1280     $this->handle_post_events($mode,array("uid"=>$this->uid));
1281   }
1283   /* Generate ListBox frindly output for the defined shares 
1284    * Possibly Add or remove an attribute here, 
1285    */
1286   function printOutAssignedShares()
1287   {
1288     $a_return = array();
1289     if(is_array($this->gotoShares)){
1290       foreach($this->gotoShares as $share){
1291         if(preg_match("/^!/",$share['server'])){
1292           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1293         }else{
1294           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1295         }
1296       }
1297       natcasesort($a_return);
1298     }
1299     return($a_return);
1300   }
1302   /* Generate ListBox frindly output for the definedhotplugs 
1303    * Possibly Add or remove an attribute here,
1304    */
1305   function printOutHotPlugDevices()
1306   {
1307     $a_return= array();
1308     if(is_array($this->gotoHotplugDevices)){
1309       foreach($this->gotoHotplugDevices as $key=>$device){
1310         $a_return[$key] = $device['name']." - ".$device['id'];
1311       }
1312     }
1313     return($a_return);
1314   }
1316   /* Generates ListBox frienly output of used printer devices 
1317    * Append ' - admin' if printer is used in admin mode
1318    */
1319   function printOutPrinterDevices()
1320   {
1321     $a_return = array();
1322     
1323     if($this->acl_is_readable("gotoPrinter")){
1325       if(is_array($this->gotoPrinter)){
1326         foreach($this->gotoPrinter as $printer){
1327           if($printer['mode'] == "admin"){
1328             $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1329           }else{
1330             $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1331           }
1332           if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1333             $a_return[$printer['cn'][0]].=" - "._("Default printer");
1334           }
1335         }
1336       }
1337     }
1338     return($a_return);
1339   }
1342   function PrepareForCopyPaste($source)
1343   {
1344     plugin::PrepareForCopyPaste($source);
1346     $class= get_class($this);
1347     $o_source = new $class($this->config,$source['dn']);
1348     foreach($this->CopyPasteVars as $attr){
1349       $this->$attr = $o_source->$attr;  
1350     }
1351   }
1354   function saveCopyDialog()
1355   {
1356     if(isset($_POST['cn'])){
1357       $this->cn = $_POST['cn'];
1358       $this->uid = $_POST['cn'];
1359     }
1360   }
1363   /* Generates ListBox frienly output of used logonscripts 
1364    */
1365   function printOutLogonScripts()
1366   {
1367     $a_return = array();
1368     if(is_array($this->gotoLogonScripts)){
1369       foreach($this->gotoLogonScripts as $script){
1370         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1371       }
1372     }
1373     return($a_return);
1374   }
1377   function multiple_execute()
1378   {
1379     /* Reset header toggle */
1380     $this->is_account = TRUE;
1381     return($this->execute());
1382   }
1385     /* Initialize plugin with given atribute arrays
1386    */
1387   function init_multiple_support($attrs,$all)
1388   {
1389     plugin::init_multiple_support($attrs,$all);
1391     /* Prepare Shares */
1392     if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1393       unset($this->multi_attrs_all['gotoShare']['count']);
1394       foreach($this->multi_attrs_all['gotoShare'] as $share){
1395         $tmp = $tmp2 = array();
1396         $tmp = split("\|",$share);
1397         $tmp2['server']      =$tmp[0];
1398         $tmp2['name']        =$tmp[1];
1400         /* Decode base64 if needed */
1401         if (!preg_match('%/%', $tmp[2])){
1402           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1403         } else {
1404           $tmp2['mountPoint']  =$tmp[2];
1405         }
1407         if(isset($tmp[3])){
1408           $tmp2['PwdHash']  =$tmp[3];
1409         }else{
1410           $tmp2['PwdHash']  ="";
1411         }
1412         if(isset($tmp[4])){
1413           $tmp2['Username']  =$tmp[4];
1414         }else{
1415           $tmp2['Username']  ="";
1416         }
1417         $tmp2['UsedByAllUsers'] = FALSE;
1418         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1419       }
1420     }
1422     /* Prepare Shares */
1423     if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1424       unset($this->multi_attrs['gotoShare']['count']);
1425       foreach($this->multi_attrs['gotoShare'] as $share){
1426         $tmp = $tmp2 = array();
1427         $tmp = split("\|",$share);
1428         $tmp2['server']      =$tmp[0];
1429         $tmp2['name']        =$tmp[1];
1431         /* Decode base64 if needed */
1432         if (!preg_match('%/%', $tmp[2])){
1433           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1434         } else {
1435           $tmp2['mountPoint']  =$tmp[2];
1436         }
1438         if(isset($tmp[3])){
1439           $tmp2['PwdHash']  =$tmp[3];
1440         }else{
1441           $tmp2['PwdHash']  ="";
1442         }
1443         if(isset($tmp[4])){
1444           $tmp2['Username']  =$tmp[4];
1445         }else{
1446           $tmp2['Username']  ="";
1447         }
1448         $tmp2['UsedByAllUsers'] = TRUE;
1449         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1450       }
1451     }
1454     /* prepare LogonScripts */
1455     if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1456       unset($this->multi_attrs_all['gotoLogonScript']['count']);
1457       foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1458         $tmp = $tmp2 = array();
1459         $tmp = split("\|",$device);
1460         $tmp2['LogonName']        = $tmp[0];
1461         $tmp2['LogonPriority']    = $tmp[2];
1462         if(preg_match("/O/i",$tmp[1])){
1463           $tmp2['LogonOverload'] = "O";
1464         }else{
1465           $tmp2['LogonOverload'] = "";
1466         }
1467         if(preg_match("/L/i",$tmp[1])){
1468           $tmp2['LogonLast'] = "L";
1469         }else{
1470           $tmp2['LogonLast'] = "";
1471         }
1472         $tmp2['LogonData']        = base64_decode($tmp[3]);
1473         $tmp2['LogonDescription'] = $tmp[4];
1474         $tmp2['UsedByAllUsers'] = FALSE;
1475         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1476       }
1477     }
1479     /* prepare LogonScripts */
1480     if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1481       unset($this->multi_attrs['gotoLogonScript']['count']);
1482       foreach($this->multi_attrs['gotoLogonScript'] as $device){
1483         $tmp = $tmp2 = array();
1484         $tmp = split("\|",$device);
1485         $tmp2['LogonName']        = $tmp[0];
1486         $tmp2['LogonPriority']    = $tmp[2];
1487         if(preg_match("/O/i",$tmp[1])){
1488           $tmp2['LogonOverload'] = "O";
1489         }else{
1490           $tmp2['LogonOverload'] = "";
1491         }
1492         if(preg_match("/L/i",$tmp[1])){
1493           $tmp2['LogonLast'] = "L";
1494         }else{
1495           $tmp2['LogonLast'] = "";
1496         }
1497         $tmp2['LogonData']        = base64_decode($tmp[3]);
1498         $tmp2['LogonDescription'] = $tmp[4];
1499         $tmp2['UsedByAllUsers'] = TRUE;
1500         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1501       }
1502     }
1504     /* Prepare hotplugs */
1505     if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1506       $ldap = $this->config->get_ldap_link();
1507       $ldap->cd($this->config->current['BASE']);
1508       for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1509         $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1510         if($ldap->count()){
1511           $multi_attrs_all = $ldap->fetch();
1513           if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1514             $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1515             $tmp2     = array();
1516             $tmp2['name']         = $multi_attrs_all['cn'][0];
1517             $tmp2['description']  = $tmp[0];
1518             $tmp2['id']           = $tmp[1];
1519             $tmp2['produkt']      = $tmp[2];
1520             $tmp2['vendor']       = $tmp[3];
1521             $tmp2['dn']           = $multi_attrs_all['dn'];
1522             $tmp2['UsedByAllUsers'] = FALSE;
1523             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1524           }
1525         }
1526       }
1527     }
1529     /* Prepare hotplugs */
1530     if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1531       $ldap = $this->config->get_ldap_link();
1532       $ldap->cd($this->config->current['BASE']);
1533       for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1534         $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1535         if($ldap->count()){
1536           $multi_attrs = $ldap->fetch();
1538           if(isset($multi_attrs['gotoHotplugDevice'][0])){
1539             $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1540             $tmp2     = array();
1541             $tmp2['name']         = $multi_attrs['cn'][0];
1542             $tmp2['description']  = $tmp[0];
1543             $tmp2['id']           = $tmp[1];
1544             $tmp2['produkt']      = $tmp[2];
1545             $tmp2['vendor']       = $tmp[3];
1546             $tmp2['dn']           = $multi_attrs['dn'];
1547             $tmp2['UsedByAllUsers'] = TRUE;
1548             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1549           }
1550         }
1551       }
1552     }
1553     $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1554     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1555       $chr = $this->gotoProfileFlags[$i];
1556       $name = "gotoProfileFlag".$chr;
1557       $this->$name=$chr;
1558     }
1559     $this->update_kiosk_profiles();
1560     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1562     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1563       $this->useProfile = true;
1564     }else{
1565       $this->useProfile = false;
1566     }
1568   }
1571   function set_multi_edit_values($attrs)
1572   {
1573     $shares = $this->gotoShares;
1574     $scripts= $this->gotoLogonScripts;
1575     $plugs= $this->gotoHotplugDevices;
1576     plugin::set_multi_edit_values($attrs);
1578     $this->gotoShares = $shares;
1579     $this->gotoLogonScripts = $scripts;
1580     $this->gotoHotplugDevices = $plugs;
1582     foreach($attrs['gotoShares'] as $name => $share){
1583       if($share['UsedByAllUsers'] == TRUE){
1584         $this->gotoShares[$name] = $share;
1585       }
1586     }
1587     foreach($this->gotoShares as $name => $share){
1588       if(!isset($attrs['gotoShares'][$name])){
1589         unset($this->gotoShares[$name]);
1590       }
1591     }
1592     foreach($attrs['gotoLogonScripts'] as $name => $script){
1593       if($script['UsedByAllUsers'] == TRUE){
1594         $this->gotoLogonScripts[$name] = $script;
1595       }
1596     }
1597     foreach($this->gotoLogonScripts as $name => $script){
1598       if(!isset($attrs['gotoLogonScripts'][$name])){
1599         unset($this->gotoLogonScripts[$name]);
1600       }
1601     }
1602     $tmp = array();
1603     foreach($this->gotoHotplugDevices as $entry){
1604       $tmp[$entry['dn']] = $entry;
1605     }
1606   
1607     foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1608       if($plug['UsedByAllUsers'] == TRUE){
1609         $tmp[$plug['dn']] = $plug;
1610       }
1611     }
1612     foreach($tmp as $name => $plug){
1613       $found = false;
1614       foreach($attrs['gotoHotplugDevices'] as $test){
1615         if($test['dn'] == $name){
1616           $found = true;
1617         }
1618       }
1619       if(!$found){
1620         unset($tmp[$name]);
1621       }
1622     }
1623   }
1626     /* Return selected values for multiple edit */
1627   function get_multi_edit_values()
1628   {
1629     $ret = plugin::get_multi_edit_values();
1630     $ret['gotoShares'] = $this->gotoShares;
1631     $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1632     $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1633   
1634     if(in_array("gotoPrinter",$this->multi_boxes)){
1635       $ret['gotoPrinter'] = $this->gotoPrinter;
1636       $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1637       $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1638   
1639       /* Force printer reset */
1640       $ret['add_del_printer_member_was_called'] = TRUE;
1641     }
1642   
1643     if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1644       $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1645     }
1647     if(in_array("useProfile",$this->multi_boxes)){
1648       $ret['useProfile']=$this->useProfile;
1649       if(in_array("gotoProfileServer",$this->multi_boxes)){
1650         $ret['gotoProfileServer']=$this->gotoProfileServer;
1651       }
1652       if(in_array("gotoProfileQuota",$this->multi_boxes)){
1653         $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1654       }
1655       if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1656         $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1657       }
1658     }
1659     if(in_array("gotoXResolution",$this->multi_boxes)){
1660       $ret['gotoXResolution'] = $this->gotoXResolution;
1661     }
1662     if(in_array("kiosk_server",$this->multi_boxes)){
1663       $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1664       $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1665     }
1666     return($ret);
1667   }
1670   function multiple_check() 
1671   {
1672     $message = plugin::multiple_check();
1673     $this->detect_grouptype();
1675     if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1676       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1677     }
1678     return($message);
1679   }
1682   function multiple_save_object()
1683   {
1684     if(isset($_POST['environment_multiple_posted'])){
1685       plugin::multiple_save_object();
1686       
1687       if(isset($_POST['useProfile'])){
1688         $this->useProfile = true;
1689       }else{
1690         $this->useProfile = false;
1691       }
1692       if(isset($_POST['gotoProfileFlagC'])){
1693         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1694       }else{
1695         $this->gotoProfileFlagC = false;
1696       }
1698       if(isset($_POST['gotoProfileFlagL'])){
1699         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1700       }else{
1701         $this->gotoProfileFlagL = false;
1702       }
1704       foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1705                     "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1706         $uattr = "use_".$attr;
1707         if(isset($_POST[$uattr])){
1708           $this->multi_boxes[] = $attr;
1709         }
1710       }
1711       if(isset($_POST['kiosk_server'])){
1712         $tmp = $_POST['kiosk_server'];
1713         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1714           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1715         }
1716       }
1717       if(isset($_POST['kiosk_profile'])){
1718         $tmp = $_POST['kiosk_profile'];
1719         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1720           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1721         }
1722       }
1724     }
1725   }
1727   /* Return plugin informations for acl handling 
1728 #FIXME these ACLs should work for groups too */ 
1729   static function plInfo()
1730   {
1731     return (array("plShortName"     => _("Environment"),
1732           "plDescription"   => _("Environment settings"),         // Description
1733           "plSelfModify"    => TRUE,                              
1734           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1735           "plPriority"      => 3,                                 // Position in tabs 
1736           "plSection"     => array("personal" => _("My account")),
1737           "plCategory"    => array("users",
1738                                    "groups"),
1739           "plOptions"       => array("resolution_hook" => array("type" => "string",
1740               "description" => _("Command to extend the list of possible screen resolutions"))),
1742           "plProvidedAcls"  => array(
1744             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1745             "gotoProfileFlagC"    => _("Cache profile localy") ,
1747             "gotoProfileQuota"    => _("Profile quota") ,
1748             "gotoProfileServer"   => _("Profile server") ,
1750             "gotoXResolution"     => _("Resolution") ,
1751             "gotoKioskProfile"    => _("Kiosk profile") ,
1753             "gosaDefaultPrinter"  => _("Default printer") ,
1754             "gotoLogonScript"     => _("Logon script") ,
1755             "gotoHotplugDevice"   => _("Hotplug devices"),
1756             "gotoShare"           => _("Shares"))
1757             ));
1758   }
1761 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1762 ?>