Code

Updated check for boolean config values
[gosa.git] / gosa-plugins / goto / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   var $plIcon = "plugins/goto/images/plugin.png";
7   /* attribute list for save action */
8   var $ignore_account       = FALSE;
9   var $plHeadline           = "Desktop";
10   var $plDescription        = "This does something";
11   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
12   
13   var $in_dialog            = false;
14   var $uid                  = "";
16   var $is_group             = false;
17   var $view_logged = FALSE;
19   /* Attribute definition
20    */
22   /* profile management */
23   var $useProfile         = false;  // Specifies if we want to use a Server 
24   var $gotoProfileServer  = "";     // Specifies the selected profile server
25   var $gotoProfileServers = array();// Specifies all available and selectable servers
26   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
27   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
28   
29   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
30   var $gotoXResolutions   = array();// Contains all available resolutions for this account
31   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
32   var $gotoProfileQuota   = "";     // User Quota Settings
34   /* Logon script section*/
35   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
36   var $gotoLogonScript    = "";     // The selected Logon Script
38   /* Printer */
39   var $gotoPrinter        = array();// All available Printer, with their configurations
40   var $gotoPrinterSel     = "";     //  The selected Printer
41   var $gosaDefaultPrinter = "";     // Default printer
43   /* Share */
44   var $gotoShares         = array();// Current Share Options
45   var $gotoShare          = "";     // currently selected Share Option
46   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
47   var $gotoAvailableShares= array();// Available Shares for this account
49   /* Kiosk profile */
50   var $kiosk_enabled      = FALSE;
51   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
52   var $gotoKioskProfile_Server    = "";     // The selected Kiosk Profile
53   var $gotoKioskProfile_Profile   = "";     // The selected Kiosk Profile
54   var $gotoKioskProfiles  = array();// All available Kiosk profiles
56   /* Hotplug Devices */
57   var $gotoHotplugDevice  = array();     // Selected hotplug
58   var $gotoHotplugDevices = array();// Already configured hotplug devices 
59   var $gotoHotplugDeviceDN= array();
61   var $NewAddedPrinters   = array();
62   var $NewDeletedPrinters = array();
64   /* general settings */
65   // Sets the attributes which will kept on page reload, which will be saved, ...
67   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile", "gotoLogonScripts","gotoLogonScript","gotoShare","gotoShares");
69   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
70       "gotoXResolution","gotoProfileQuota",
71       "gotoLogonScript","gotoLogonScripts","gotoHotplugDevices",
72       "gotoPrinter", "gosaDefaultPrinter",
73       "gotoShare",
74       "gotoKioskProfile");
75   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
76   var $cn;
77   var $OrigCn;
78   var $add_del_printer_member_was_called = false;
80   var $multiple_support =TRUE;
82   var $use_gotoPrinter;
83   var $shareList = NULL;
86   function environment (&$config, $dn= NULL)
87   {
88     plugin::plugin ($config, $dn);
90     /* Setting uid to default */
91     if(isset($this->attrs['uid'][0])){
92       $this->uid = $this->attrs['uid'][0];
93     }
95     /* Check : Are we currently editing a group or user dialog */
96     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
97       $suffix="Group";
98       $this->uid          = $this->attrs['cn'][0];
99       $this->attrs['uid'] = $this->attrs['cn'][0];
100       $this->OrigCn = $this->attrs['cn'][0];
101     }else{
102       $suffix="User";
103     }
105     /* Get all Printer assignments */
106     $ldap = $this->config->get_ldap_link();
107     $ldap->cd($this->config->current['BASE']);
108     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
109     while($printer = $ldap->fetch()){
110       $this->gotoPrinter[$printer['cn'][0]]=$printer;
111       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
112     }
113     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
114     while($printer = $ldap->fetch()){
115       $this->gotoPrinter[$printer['cn'][0]]=$printer;
116       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
117     }
120     /* Prepare hotplugs */
121     if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
122       $ldap = $this->config->get_ldap_link();
123       $ldap->cd($this->config->current['BASE']);
124       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
125         $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
126         if($ldap->count()){
127           $attrs = $ldap->fetch(); 
129           if(isset($attrs['gotoHotplugDevice'][0])){
130             $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
131             $tmp2     = array();
132             $tmp2['name']         = $attrs['cn'][0];
133             $tmp2['description']  = $tmp[0];
134             $tmp2['id']           = $tmp[1];
135             $tmp2['produkt']      = $tmp[2];
136             $tmp2['vendor']       = $tmp[3];
137             $tmp2['dn']           = $attrs['dn'];
138             $this->gotoHotplugDevices[] = $tmp2; 
139           }
140         }else{
141           msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
142         }
143       }
144     }
146  
147     /* prepare LogonScripts */
148     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
149       unset($this->attrs['gotoLogonScript']['count']);
150       foreach($this->attrs['gotoLogonScript'] as $device){
151         $tmp = $tmp2 = array();
152         $tmp = explode("|",$device);
153         $tmp2['LogonName']        = $tmp[0]; 
154         $tmp2['LogonPriority']    = $tmp[2]; 
155         if(preg_match("/O/i",$tmp[1])){
156           $tmp2['LogonOverload'] = "O";
157         }else{
158           $tmp2['LogonOverload'] = "";
159         }
160         if(preg_match("/L/i",$tmp[1])){
161           $tmp2['LogonLast'] = "L";
162         }else{
163           $tmp2['LogonLast'] = "";
164         }
165         $tmp2['LogonData']        = base64_decode($tmp[3]); 
166         $tmp2['LogonDescription'] = $tmp[4];
167         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
168       }
169     }
171     /* Prepare Shares */
172     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
173       unset($this->attrs['gotoShare']['count']);
174       foreach($this->attrs['gotoShare'] as $share){
175         $tmp = $tmp2 = array();
176         $tmp = explode("|",$share);
177         $tmp2['server']      =$tmp[0];
178         $tmp2['name']        =$tmp[1];
180         /* Decode base64 if needed */
181         if (!preg_match('%/%', $tmp[2])){
182           $tmp2['mountPoint']  =base64_decode($tmp[2]);
183         } else {
184           $tmp2['mountPoint']  =$tmp[2];
185         }
187         if(isset($tmp[3])){
188           $tmp2['PwdHash']  =$tmp[3];
189         }else{
190           $tmp2['PwdHash']  ="";
191         }
192         if(isset($tmp[4])){
193           $tmp2['Username']  =$tmp[4];
194         }else{
195           $tmp2['Username']  ="";
196         }
197         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
198       }
199     }
201     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
202       $chr = $this->gotoProfileFlags[$i];
203       $name = "gotoProfileFlag".$chr;
204       $this->$name=$chr;
205     }
207     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
208       $this->useProfile = true;
209     }else{
210       $this->useProfile = false;
211     }
213     /* Set resolutions */
214     $this->gotoXResolutions = array("auto"=>_("auto"),
215                                     "640x480"   =>  "640x480",
216                                     "800x600"   =>  "800x600",
217                                     "1024x768"  =>  "1024x768",
218                                     "1152x864"  =>  "1152x864",
219                                     "1280x768"  =>  "1280x768",
220                                     "1280x1024" =>  "1280x1024");
222     if($this->config->get_cfg_value("core","resolutions") != ""){
223       $file = $this->config->get_cfg_value("core","resolutions");
225       if(is_readable($file)){
226         $str = file_get_contents($file);
227         $lines = preg_split("/\n/",$str);
228         foreach($lines as $line){
229           $line = trim($line);
230           if(!empty($line)){
231             $this->gotoXResolutions[$line]=$line;
232           }
233         }
234         //natcasesort($this->gotoXResolutions);
235       }else{
236         msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
237       }
238     }
240     $this->gotoProfileServers= $config->getShareServerList() ;
241     $this->gotoShareSelections= $config->getShareList(true);
242     $this->gotoAvailableShares= $config->getShareList(false);  
243   
244     /* Ensure that a currently selected server will stay selected, even if the list of profile servers
245         is empty due to insufficient permissions.
246      */
247     if(count($this->gotoProfileServers) && !empty($this->gotoProfileServer)){
249       /* The currently selected profile server is outdated/no longer available */
250       if(!isset($this->gotoProfileServers[$this->gotoProfileServer])){
252       }else{
253         $c = $this->gotoProfileServers[$this->gotoProfileServer];
254         if(!preg_match("/r/",$c['ACL'])){
256           /* We are not allowed to read to currently selected server.
257              But to ensure that the selection will be kept after saving the account, we 
258               override the current ACL tag.
259            */          
260           $this->gotoProfileServers[$this->gotoProfileServer]['ACL'] .= "r";
261         }
262       }
263     }
264     $this->update_kiosk_profiles();
266     // Prepare lists
267     $this->shareList = new sortableListing();
268     $this->shareList->setDeleteable(false);
269     $this->shareList->setEditable(false);
270     $this->shareList->setWidth("100%");
271     $this->shareList->setHeight("120px");
272     $this->shareList->setHeader(array(_("Server"),_("Share name"),_("Mount point"), 
273             _("User"), _("Type"), _("Action")));
274     $this->shareList->setDefaultSortColumn(1);
275   }
278   function update_kiosk_profiles()
279   { 
280     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
281     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
283     $tmp1  = array("none" => array(_("disabled")));
284     $tmp2  = array("none" => _("disabled"));
285     $tmp3  = array();
286     $ldap = $this->config->get_ldap_link();
287     $ldap->cd($this->config->current['BASE']);
288     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
289     $cnt = 0;
290     $ui = get_userinfo();
291     while($attrs = $ldap->fetch()){
292       $acl = $ui->get_permissions($attrs['dn'],"server/goKioskService","");
293       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
294         if(preg_match("/r/",$acl) || $this->gotoKioskProfile_Server == $attrs['cn'][0]){
295           $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
296           $tmp1[$attrs['cn'][0]][] = $name;
297           $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
298           $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
299           $cnt ++;
300         }
301       }
302     }
304     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
305       $this->kiosk_enabled = TRUE;
306     }
308     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
309     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
310     $this->gotoKioskProfiles['MAP']       = $tmp3;
311   
312     $error = false;
313     if(!isset($this->gotoKioskProfiles['SERVERS'][$this->gotoKioskProfile_Server])){
314       $error = true;
315     }elseif(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
316       $error = true;
317     }
318     if($error && !empty($this->gotoKioskProfile)){
319       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);
320       $this->gotoKioskProfile_Server ="none";
321       $this->gotoKioskProfile_Profile="";
322     }elseif(empty($this->gotoKioskProfile)){
323       $this->gotoKioskProfile_Server ="none";
324       $this->gotoKioskProfile_Profile="";
325     }
326   }
329   /* Detect type of edited object (user|group)*/
330   function detect_grouptype()
331   {
332     if((!isset($this->parent))&&(!$this->is_account)){
333       $this->is_group     = false;
334     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
335       $this->is_group     = true;
336     }else{
337       $this->is_group     = false;
338     }
339   }
342   function execute()
343   {
345     /* Call parent execute */
346     plugin::execute();
347     /* Log view */
348     if($this->is_account && !$this->view_logged){
349       $this->view_logged = TRUE;
350       if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
351         new log("view","users/".get_class($this),$this->dn);
352       }else{
353         new log("view","groups/".get_class($this),$this->dn);
354       }
355     }
357     /* Check profile server */
358     if($this->acl_is_writeable("gotoProfileServer")){
360       if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
363         if(count($this->gotoProfileServers)){
365           /* Get First Profile */
366           $new = key($this->gotoProfileServers);
368           /* Another profile server found */
369           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
370         }else{
372           /* No other profile servers found */
373           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
374           $this->gotoProfileServer = "none";
375         }
376       }
377     }    
379     $this->detect_grouptype();
381     /* Fill templating stuff */
382     $smarty= get_smarty();
383     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
384     $display= "";
386     $smarty->assign("is_group",$this->is_group);
388     /* Prepare all variables for smarty */
389     foreach($this->attributes as $s_attr){
390       /* Set value*/
391       $smarty->assign($s_attr,$this->$s_attr);
393       /* Set checkbox state*/
394       if(empty($this->$s_attr)){
395         $smarty->assign($s_attr."CHK","");
396       }else{
397         $smarty->assign($s_attr."CHK"," checked ");
398       }
399     }
401     $tmp = $this->plInfo();
402     foreach($tmp['plProvidedAcls'] as $val => $desc){
403       $smarty->assign("$val"."ACL", $this->getacl($val));
404     }
406     /* Is accout enabled | are we editing from usermenu or admin menu 
407        All these tab management is done here
408      */
411     /* Working from Usermenu an the Account is currently disbled
412      * this->parent :  is only set if we are working in a list of tabs
413      * is_account   :  is only true if the needed objectClass is given
414      */
415     if((!isset($this->parent))&&(!$this->is_account)){
416       /* We are currently editing this tab from usermenu, but this account is not enabled */
417       $smarty->assign("is_account",$this->is_account);
418       /* Load template */
419       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
420       /* Avoid the "You are currently editing ...." message when you leave this tab */
421       $display .= back_to_main(); 
422       /* Display our message to the user */
423       return $display;
426       /* We are currently editing from group tabs, because 
427        * $this->parent is set
428        * posixAccount is not set, so we are not in usertabs.
429        */
430     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
431       $smarty->assign("is_account","true");
432       $this->uid          = $this->cn;
433       $this->attrs['uid'] = $this->cn;
435       /* Change state if needed */
436       if (isset($_POST['modify_state'])){
437         if(($this->acl_is_createable() && !$this->is_account) || 
438             ($this->acl_is_removeable() &&  $this->is_account)){
439           $this->is_account= !$this->is_account;
440         }
441       }
442       /* Group Dialog with enabled environment options */
443       if ($this->is_account){
444         $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Desktop")),
445             msgPool::featuresEnabled(_("Desktop")));
446       } else {
448         /* Environment is disabled 
449            If theres is no posixAccount enabled, you won't be able to enable 
450            environment extensions
451          */
452         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
453           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
454               msgPool::featuresDisabled(_("Desktop")));
455           return $display;
456         }elseif((isset($this->parent->by_object['ogroup']))){
457           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
458               msgPool::featuresDisabled(_("Desktop")));
459           return $display;
460         }else{
461           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
462               msgPool::featuresDisabled(_("Desktop"), _("POSIX")), TRUE);
463           return $display;
464         }
465       }
466     }else{
467       /* Editing from Usermenu 
468        *  Tell smarty that this accoutn is enabled 
469        */
470       $smarty->assign("is_account","true");
472       /* Change state if needed */
473       if (isset($_POST['modify_state'])){
474         if(($this->acl_is_createable() && !$this->is_account) || 
475             ($this->acl_is_removeable() &&  $this->is_account)){
476           $this->is_account= !$this->is_account;
477         }
478       }
480       if(isset($this->parent)){
482         // 3. Account enabled . Editing from adminmenu
483         if ($this->is_account){
484           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Desktop")),
485               msgPool::featuresEnabled(_("Desktop")));
486         } else {
488           if($this->parent->by_object['posixAccount']->is_account==true){
489             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
490                 msgPool::featuresDisabled(_("Desktop")));
491             return $display;
492           }else{
493             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
494                 msgPool::featuresDisabled(_("Desktop"), _("POSIX")), TRUE);
495             return $display;
496           }
497         }
498       }
499     }
500   
501     /* Reset header toggle */
502     if($this->multiple_support_active){
503       $display = "";
504     }
506     /* Account is Account : is_accounbt=true.
507      * Else we won't reach this. 
508      */
510     /* Prepare all variables for smarty */
511     foreach($this->attributes as $s_attr){
512       /* Set value*/
513       $smarty->assign($s_attr,$this->$s_attr);
515       /* Set checkbox state*/
516       if(empty($this->$s_attr)){
517         $smarty->assign($s_attr."CHK","");
518       }else{
519         $smarty->assign($s_attr."CHK"," checked ");
520       }
521     }
523     $tmp = $this->plInfo();
524     foreach($tmp['plProvidedAcls'] as $val => $desc){
525       $smarty->assign("$val"."ACL", $this->getacl($val));
526     }
528     foreach(array("gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
529       $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
530     }
532     if($this->read_only) {
533       $smarty->assign("gotoPrinterACL","r");
534     }else{
535       $smarty->assign("gotoPrinterACL","rw");
536     }
539     $smarty->assign("useProfile",$this->useProfile);
540     if(empty($this->useProfile) && !$this->multiple_support_active){
541       $smarty->assign("useProfileCHK","");
542       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer")));
543       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota")));
544       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC")));
545     }else{
546       $smarty->assign("useProfileCHK"," checked ");
547     }
548     
549     $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer"));
550     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota"));
552     /* HANDLE Profile Settings here 
553      * Assign available Quota and resolution settings
554      * Get all available profile server
555      * Get cache checkbox
556      * Assign this all to Smarty 
557      */
559     if(empty($this->gotoProfileFlagL)){
560       $smarty->assign("gotoProfileFlagLCHK"," ");
561     }else{
562       $smarty->assign("gotoProfileFlagLCHK"," checked ");
563     }
565     if(empty($this->gotoProfileFlagC)){
566       $smarty->assign("gotoProfileFlagCCHK"," ");
567     }else{
568       $smarty->assign("gotoProfileFlagCCHK"," checked ");
569     }
572     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
573     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
575     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
576     if(!is_array($this->gotoProfileServers)){
577       $this->gotoProfileServers =array();
578     }
580     /* Handle kiosk profiles*/
581     $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
582     $smarty->assign("kiosk_server" ,  $this->gotoKioskProfile_Server);
583     $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
584     $smarty->assign("kiosk_profile" ,  $this->gotoKioskProfile_Profile);
585   
587     /* Logonscript Management
588      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
589      * Perform add Delete edit Posts 
590      */
592     /* Dialog Save */
593     if(isset($_POST['LogonSave'])){
595       if(!$this->acl_is_writeable("gotoLogonScript")){
596         msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
597         unset($this->dialog);
598         $this->dialog=FALSE;
599         $this->is_dialog=false;
600       }else{
601         $this->dialog->save_object();
602         if(count($this->dialog->check())!=0){
603           foreach($this->dialog->check() as $msg){
604             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
605           }
606         }else{
607           $tmp = $this->dialog->save();
608           unset($this->dialog);
609           $this->dialog=FALSE;
610           $this->is_dialog=false;
612           if($this->multiple_support_active){
613             $tmp['UsedByAllUsers'] = TRUE;
614           }
615           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
616         }
617       }
618     }
619     
621     /* Dialog Quit without saving */
622     if(isset($_POST['LogonCancel'])){
623       $this->is_dialog= false;
624       unset($this->dialog);
625       $this->dialog= FALSE;
626     }
628     /* Check Edit Del New Posts for a selected LogonScript */ 
629     if($this->acl_is_writeable("gotoLogonScript") && 
630         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
632       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
633        * In this case we create a new Logon Script.
634        */
635       if(isset($_POST['gotoLogonScriptNew'])){
636         $this->is_dialog = true;
637         $this->dialog = new logonManagementDialog($this->config,$this->dn);
638       }
640       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
641        * We only can delete if there is an entry selected.
642        */
643       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
644         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
645       }
647       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
648        * There must be an entry selected to perform edit request.
649        */
650       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
651         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
652         $this->is_dialog = true;
653         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
654       }
655     }
657     /* Append List to smarty*/
658     if($this->multiple_support_active){
659       $smarty->assign("gotoLogonScripts",  $this->gotoLogonScripts);
660       $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
661     }else{
662       $ls = $this->printOutLogonScripts();
663       $smarty->assign("gotoLogonScripts",  $ls);
664       $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
665       $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
666     }
668     /* In this section server shares will be defined 
669      * A user can select one of the given shares and a mount point
670      *  and attach this combination to his setup.
671      */
673     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
674     if(!is_array($this->gotoShareSelections)){
675       $this->gotoShareSelections = array();
676     }
677     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
679     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
680      * This entry will be, a combination of mountPoint and sharedefinitions 
681      */
682     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
684       /* We assign a share to this user, if we don't know where to mount the share */
685       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
686         msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
687       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
688         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
689       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
690         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
691       }elseif(!(
692             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
693             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
694             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
695             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
696             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
697             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
698             preg_match("/^%/",$_POST['gotoShareMountPoint'])
699             )
700           ){
701         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
702       }else{
703         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
704         $s_mount = $_POST['gotoShareMountPoint'];
705         $s_user  = $_POST['ShareUser'];
706         /* Preparing the new assignment */ 
707         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
708         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
709         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
710         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
712         if($this->multiple_support_active){
713           $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
714         }
715       }
716     }  
718     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
719      * If there is no defined share selected, we will abort the deletion without any message 
720      */
721     $once = true;
722     if($this->acl_is_writeable("gotoShare")){
723       foreach($_POST as $name => $value){
724         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
725           $once = false;  
726           $key  = preg_replace("/^gotoShareDel_/","",$name);
727           $key  = postDecode($key);
728           if(isset($this->gotoShares[$key])) {
729             unset($this->gotoShares[$key]);
730           }
732           /* Remove corresponding password entry, too. This is a workaround
733              to get rid of old-style entries. */
734           $key= preg_replace("/\|/", "|!", $key);
735           if(isset($this->gotoShares[$key])) {
736             unset($this->gotoShares[$key]);
737           }
738         }
739         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
740           $once = false;
741           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
742           $key  = postDecode($key);
743           $this->gotoShares[$key]['PwdHash'] = "";
744           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
745             unset($this->gotoShares[$key]);
746           }
747         }
748       }
749     }
751     // Build up share list
752     $data = $lData = array(); 
753     foreach($this->gotoShares as $key => $entry){
754       $img = "";
756       // Skip password only entries
757       if( empty($entry['server']) && empty($entry['name']) &&
758           empty($entry['mountPoint']) && empty($entry['Username'])){
759         continue;
760       } 
762       // While editing mutlipe users at once we've to seperate 
763       //  entries used by all users and those used by only some.
764       $color = "";
765       if($this->multiple_support_active){
766         if($entry['UsedByAllUsers']){
767           $value .= "&nbsp;(<b>"._("Used by all users")."</b>)";
768         }else{
769           $color = "color: #999999;";
770           $value .= "&nbsp;(<b>"._("Used by some users")."</b>)";
771         }
772       }
774       // Create password reset image button 
775       if($entry['PwdHash'] != ""){
776           $img.= 
777               image('plugins/goto/images/list_reset_password.png',
778                       'gotoShareResetPwd_'.postEncode($key),
779                       _("Reset password hash"));
780       }
782       // Build up list entries - Handle entries starting with '!' here.
783       $data[$key]=$key;
784       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
786         // If we are currently editing groups environment, skip those ! entries */ 
787         if($this->is_group) continue;
789         $lData[$key] = array('data' => array(
790                     $entry['server']."://",
791                     $entry['name'], 
792                     "",
793                     "",
794                     image("plugins/groups/images/select_group.png","",_("Group share")),
795                     $img));
796       }else{
798         $img.= image('images/lists/trash.png',"gotoShareDel_".postEncode($key),msgPool::delButton());
799         $lData[$key] = array('data' => array(
800                     $entry['server']."://",
801                     $entry['name'], 
802                     $entry['mountPoint'], 
803                     $entry['Username'], 
804                     image("plugins/users/images/select_user.png","",_("User share")),
805                     $img));
806       }
807     }
808     $this->shareList->setListData($data,$lData);
809     $this->shareList->update();
810     $this->shareList->setAcl($this->getacl("gotoShare"));
811     $smarty->assign("shareList",$this->shareList->render());
813     /* Hotplug devices will be handled here 
814      * There are 3 possible methods for this feature
815      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
816      * Delete will erase an entry, the entry must be selcted in the ListBox first
817      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
818      */
820     /* We have to delete the selected hotplug from the list*/
821     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDeviceDN")){
822       if($this->acl_is_writeable("gotoHotplugDeviceDN")){
823         foreach($_POST['gotoHotplugDevice_post'] as $name){
824           unset($this->gotoHotplugDevices[$name]);
825         }
826       }
827     }
829     /* There are already defined hotplugs from other users we could use */
830     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDeviceDN")){
831       $tmp  =array();
832       foreach($this->gotoHotplugDevices as $plugs){
833         $tmp[] = $plugs['name'];
834       }
835       $this->dialog = new hotplugSelect($this->config, get_userinfo());
836       $this->is_dialog = true;
837     }
839     /* Dialog Aborted */
840     if(isset($_POST['hotplugSelect_cancel'])){
841       $this->dialog= FALSE;
842       $this->is_dialog = false;
843     }
845     /* Dialod saved */
846     if(isset($_POST['hotplugSelect_save'])){
848       $res = $this->dialog->save();
849       foreach($res as $hotplug){
850         $name = $hotplug['cn'][0];
851         $entry['dn'] = $hotplug['dn'];
853         /* Set class values */
854         $tmp = preg_split("/\|/",$hotplug['gotoHotplugDevice'][0]);
855         $entry['name']          = $hotplug['cn'][0];
856         $entry['description'] = $tmp[0];
857         $entry['id']       = $tmp[1];
858         $entry['produkt']      = $tmp[2];
859         $entry['vendor']     = $tmp[3];
860         if($this->multiple_support_active){
861           $entry['UsedByAllUsers'] = TRUE;
862         }
863         $this->gotoHotplugDevices[$name]= $entry; 
864       }
865       $this->dialog= FALSE;
866       $this->is_dialog = false;
867     }
869     if($this->dialog instanceOf hotplugSelect){
870     
871       // Build up blocklist
872       session::set('filterBlacklist', array('cn' => array_keys($this->gotoHotplugDevices)));
873       return($this->dialog->execute());
874     }
876     if($this->multiple_support_active){
877       $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
878     }else{
879       $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
880       $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
881     }
883     /* Printer Assignment will managed below 
884      * A printer can be assigned in two different ways and two different types
885      * There are 2 types of users assigned to a printer : user and admin
886      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
887      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
888      */ 
890     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
891     if(isset($_POST['gotoPrinterAdd'])){
892       $this->dialog = new printerSelect($this->config,get_userinfo());
893       $this->is_dialog=true;
894     }
896     if(isset($_POST['printerSelect_cancel']) && $this->dialog instanceOf printerSelect){
897       $this->is_dialog=false;
898       $this->dialog=FALSE;
899     }
901     if(isset($_POST['printerSelect_save'])  && $this->dialog instanceOf printerSelect){
903       $res = $this->dialog->save();
904         foreach($res as $printer){
906           $pname = $printer['cn'][0];
907           $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'], $printer['dn'],"printer");
908           $printerObj->set_acl_base($printer['dn']);
910           $type = false;
912           
913           if($this->is_group){
914             if($this->dn == "new"){  
915               $type = "AddGroup";
916             }elseif(isset($this->NewDeletedPrinters[$pname])){
917               $type = "AddGroup";
918             }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
919               $type = "AddGroup";
920             }
921           }else{
922             if($this->multiple_support_active){
923               $type = "AddUser";
924             }elseif(isset($this->NewDeletedPrinters[$pname])){
925               $type = "AddUser";
926             }elseif($this->dn == "new"){  
927               $type = "AddUser";
928             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
929               $type = "AddUser";
930             }
931           }
933           if($type){
934             $this->gotoPrinter[$pname]=$printer;
935             $this->gotoPrinter[$pname]['mode']="user";
936             $this->add_del_printer_member_was_called = true;
938             $this->NewAddedPrinters[$pname] = $pname;
939             if(isset($this->NewDeletedPrinters[$pname])){
940               unset($this->NewDeletedPrinters[$pname]);
941             }
942           }
943         }
945         $this->is_dialog=false;
946         unset($this->dialog);
947         $this->dialog   =FALSE;
948     }
950     // Display printer selection dialog 
951     if($this->dialog instanceOf printerSelect){
953       // Build up blocklist
954       session::set('filterBlacklist',array('cn' => array_keys($this->gotoPrinter)));
955       return($this->dialog->execute());
956     }
959     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
960       $printer = $_POST['gotoPrinterSel'];
961       foreach($printer as $pname){
963         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
964         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
966         $type = false;
967         if($this->is_group){
968           if(isset($this->NewAddedPrinters[$pname])){
969             $type = "Group";
970           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
971             $type = "Group";
972           }
973         }else{
974           if(isset($this->NewAddedPrinters[$pname])){
975             $type = "User";
976           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
977             $type = "User";
978           }
979         }
980         if($type){
981           $this->add_del_printer_member_was_called = true;
982           unset($this->gotoPrinter[$pname]);
984           $this->NewDeletedPrinters[$pname] = $pname;
985           if(isset($this->NewAddedPrinters[$pname])){
986             UNSET($this->NewAddedPrinters[$pname]);
987           }
988         }
989       }
990     }
992     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
993       $printers = $_POST['gotoPrinterSel'];
994       $this->add_del_printer_member_was_called = true;
995       foreach($printers as $printer){
996         if($this->gotoPrinter[$printer]['mode']=="user"){
997           $this->gotoPrinter[$printer]['mode']="admin";
998         }else{
999           $this->gotoPrinter[$printer]['mode']="user";
1000         }
1001       }
1002     }
1004     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
1005       if($this->is_group){
1006         msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
1007       }else{
1008         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
1009           $this->gosaDefaultPrinter= "";
1010         } else {
1011           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
1012         }
1013       }
1014     }
1016     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
1018     /* General behavior */
1019     if(is_object($this->dialog)){
1020       $this->dialog->save_object();
1021       $disp =$this->dialog->execute();
1022       return($disp);
1023     }
1025     /* Assign used attributes for multiple edit */
1026     foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
1027                   "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
1028       $ubox ="use_".$box;
1029       if(in_array($box,$this->multi_boxes)){
1030         $smarty->assign($ubox,TRUE);
1031       }else{
1032         $smarty->assign($ubox,FALSE);
1033       }
1034     }
1036     /* Als smarty vars are set. Get smarty template and generate output */
1037     $smarty->assign("multiple_support",$this->multiple_support_active);
1038     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
1039     return($display);
1040   }
1042   function remove_from_parent()
1043   {
1044     /* only if it was an account*/
1045     if (!$this->initially_was_account){
1046       return;
1047     }
1049     /* include global link_info */
1050     $ldap= $this->config->get_ldap_link();
1052     /* Remove and write to LDAP */
1053     plugin::remove_from_parent();
1055     /* Don't save our template variables */
1056     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1058     /* Skip all these attributes */
1059     foreach($skip as $del){
1060       unset($this->attrs[$del]);
1061     }
1063     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1065     $ldap->cd($this->dn);
1066     $this->cleanup();
1067     $ldap->modify ($this->attrs); 
1069     if($this->is_group){
1070       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1071     }else{
1072       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1073     }
1075     if (!$ldap->success()){
1076       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1077     }
1079     /* Optionally execute a command after we're done */
1080     $this->handle_post_events("remove",array("uid" => $this->uid));
1081   }
1084   /* Save data to object */
1085   function save_object()
1086   {
1087     /* Get all Posted vars 
1088      * Setup checkboxes 
1089      */
1090     if(isset($_POST['iamposted'])){
1092       $PACL =  $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota");
1094       if(isset($_POST['kiosk_server'])){
1095         $tmp = $_POST['kiosk_server'];
1096         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1097           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1098         }
1099       }
1100       if(isset($_POST['kiosk_profile'])){
1101         $tmp = $_POST['kiosk_profile'];
1102         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1103           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1104         }
1105       }
1107       if(preg_match("/w/",$PACL)){
1108         if(isset($_POST['useProfile'])){
1109           $this->useProfile = true;
1110         }else{
1111           $this->useProfile = false;
1112         }
1113       }
1115       if($this->acl_is_writeable("gotoProfileFlagC")){
1116         if(isset($_POST['gotoProfileFlagC'])){
1117           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1118         }else{
1119           $this->gotoProfileFlagC = false;
1120         }
1121       }
1123       if($this->acl_is_writeable("gotoProfileFlagL")){
1124         if(isset($_POST['gotoProfileFlagL'])){
1125           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1126         }else{
1127           $this->gotoProfileFlagL = false;
1128         }
1129       }
1131       plugin::save_object();
1132       foreach($this->attributes as $s_attr){
1133         if((!isset($_POST[$s_attr])) || 
1134             in_array($s_attr,array("gosaDefaultPrinter","gotoShare","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1135         if(!$this->acl_is_writeable($s_attr)){
1136           continue;
1137         }else{ 
1138           if(isset($_POST[$s_attr])){
1139             $this->$s_attr = $_POST[$s_attr];
1140           }else{
1141             $this->$s_attr = false;
1142           }
1143         }
1144       }
1145     }
1146   }
1149   /* Check supplied data */
1150   function check()
1151   {
1152     /* Call common method to give check the hook */
1153     $message= plugin::check();
1155     $this->detect_grouptype();
1157     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1158       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1159     } 
1160     if(!isset($this->attrs['objectClass'])){
1161       $this->attrs['objectClass']=array();
1162     } 
1163     if(!$this->is_group){
1164       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1165         $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));  
1166       }
1167     }
1168     return ($message);
1169   }
1172   /* Save to LDAP */
1173   function save()
1174   {
1175     /* If group was renamed, all printer settings get lost
1176      */ 
1177     /* only save changed variables ....*/
1178     if ($this->gotoKioskProfile_Server != "none"){
1179       $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1180       $this->gotoKioskProfile= $method;
1181     }else{
1182       $this->gotoKioskProfile= array();
1183     }
1185     plugin::save();
1186     $ldap= $this->config->get_ldap_link();
1188     $realyUsedAttrs= array();
1190     /* Save already used objectClasses */
1191     $ocs        = $this->attrs['objectClass'];
1192     unset($ocs['count']);
1193     $this->attrs = array();
1194     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1196     /* 1. Search all printers that have our uid/cn as member 
1197      * 2. Delete this uid/cn from every single entry and save it again.
1198      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1199      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1200      */
1201     
1202     $this->detect_grouptype();
1204     if($this->add_del_printer_member_was_called){
1206       $types = array( "gotoUserPrinter"       => "AddUser",
1207           "gotoGroupPrinter"      => "AddGroup",
1208           "gotoUserAdminPrinter"  => "AddAdminUser",
1209           "gotoGroupAdminPrinter" => "AddAdminGroup");
1211       if($this->is_group){
1212         $s_suffix = "Group";
1213         $useVar   = "cn";
1214       }else{
1215         $useVar   = "uid";
1216         $s_suffix = "User";
1217       }
1219       /* Remove old entries */
1220       $ldap->cd($this->config->current['BASE']);;
1221       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1222       while($attr = $ldap->fetch()){
1223         $printerObj = NULL;
1224         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1225         $printerObj->set_acl_base($attr['dn']);
1226         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1227         $printerObj->by_object['printgeneric']->save();
1228       }
1230       $ldap->cd($this->config->current['BASE']);;
1231       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1232       while($attr = $ldap->fetch()){
1233         $printerObj = NULL;
1234         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1235         $printerObj->set_acl_base($attr['dn']);
1236         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1237         $printerObj->by_object['printgeneric']->save();
1238       }
1240       foreach($this->gotoPrinter as $printer){
1241         $printerObj = NULL;
1242         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1243         $printerObj->set_acl_base($printer['dn']);
1246         if($printer['mode'] == "admin") {
1247           $attribute = "goto".$s_suffix."AdminPrinter";
1248         }else{
1249           $attribute = "goto".$s_suffix."Printer";
1250         }
1252         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1253         $printerObj->by_object['printgeneric']->save();
1254       }
1255     }    
1257     /* Prepare HotPlug devices */
1258     $this->attrs['gotoHotplugDeviceDN'] = array();
1259     foreach($this->gotoHotplugDevices as $name => $device){
1260       $this->attrs['gotoHotplugDeviceDN'][]= LDAP::fix($device['dn']);
1261     }
1263     /* Prepare LogonScripts */
1264     $this->attrs['gotoLogonScript'] = array();
1265     foreach($this->gotoLogonScripts as $name => $script){
1266       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1267         $script['LogonOverload'].$script['LogonLast']."|".
1268         $script['LogonPriority']."|".
1269         base64_encode($script['LogonData'])."|".
1270         $script['LogonDescription'];
1271     }
1273     /* Prepare Shares */
1274     $this->attrs['gotoShare']=array();
1275     foreach($this->gotoShares as $name => $share){
1276       $mntp= $share['mountPoint'];
1277       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1278         $mntp= base64_encode($mntp);
1279       }
1280       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1281     }
1284     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1285     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1287     foreach($saveThis as $tosave){
1288       if(!empty($this->$tosave)){
1289         $this->attrs[$tosave]=$this->$tosave;
1290       }else{
1291         $this->attrs[$tosave]=array();
1292       }
1293     }
1295     /* Prepare Flags */
1296     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1297     if(empty($this->attrs['gotoProfileFlags'][0])){
1298       $this->attrs['gotoProfileFlags']=array();
1299     }
1301     if($this->useProfile == false){
1302       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1303       $this->attrs['gotoProfileServer']= array(); 
1304     }
1306     $ldap->cat ($this->dn, array('dn'));
1307     if ($ldap->fetch()){
1308       $mode= "modify";
1309     } else {
1310       $mode= "add";
1311       $ldap->cd($this->config->current['BASE']);
1312       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1313     }
1315     $ldap->cd($this->dn);
1316     $this->cleanup();
1317     $ldap->$mode($this->attrs);
1318   
1319     $cat = "users";
1320     if($this->is_group){
1321       $cat = "groups";
1322     }
1324     /* Log last action */ 
1325     if($this->initially_was_account){
1326       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1327     }else{
1328       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1329     }
1331     if (!$ldap->success()){
1332       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1333     }
1334     $this->handle_post_events($mode,array("uid"=>$this->uid));
1335   }
1338   /* Generate ListBox frindly output for the definedhotplugs 
1339    * Possibly Add or remove an attribute here,
1340    */
1341   function printOutHotPlugDevices()
1342   {
1343     $a_return= array();
1344     if(is_array($this->gotoHotplugDevices)){
1345       foreach($this->gotoHotplugDevices as $key=>$device){
1346         $a_return[$key] = $device['name']." - ".$device['id'];
1347       }
1348     }
1349     return($a_return);
1350   }
1352   /* Generates ListBox frienly output of used printer devices 
1353    * Append ' - admin' if printer is used in admin mode
1354    */
1355   function printOutPrinterDevices()
1356   {
1357     $a_return = array();
1359     if(is_array($this->gotoPrinter)){
1360       foreach($this->gotoPrinter as $printer){
1361         if($printer['mode'] == 'admin'){
1362           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1363         }else{
1364           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1365         }
1366         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1367           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1368         }
1369       }
1370     }
1371                 asort($a_return);
1372     return($a_return);
1373   }
1376   function PrepareForCopyPaste($source)
1377   {
1378     plugin::PrepareForCopyPaste($source);
1380     $class= get_class($this);
1381     $o_source = new $class($this->config,$source['dn']);
1382     foreach($this->CopyPasteVars as $attr){
1383       $this->$attr = $o_source->$attr;  
1384     }
1385   }
1388   function saveCopyDialog()
1389   {
1390     if(isset($_POST['cn'])){
1391       $this->cn = $_POST['cn'];
1392       $this->uid = $_POST['cn'];
1393     }
1394   }
1397   /* Generates ListBox frienly output of used logonscripts 
1398    */
1399   function printOutLogonScripts()
1400   {
1401     $a_return = array();
1402     if(is_array($this->gotoLogonScripts)){
1403       foreach($this->gotoLogonScripts as $script){
1404         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1405       }
1406     }
1407     return($a_return);
1408   }
1411   function multiple_execute()
1412   {
1413     /* Reset header toggle */
1414     $this->is_account = TRUE;
1415     return($this->execute());
1416   }
1419     /* Initialize plugin with given atribute arrays
1420    */
1421   function init_multiple_support($attrs,$all)
1422   {
1423     plugin::init_multiple_support($attrs,$all);
1425     /* Prepare Shares */
1426     if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1427       unset($this->multi_attrs_all['gotoShare']['count']);
1428       foreach($this->multi_attrs_all['gotoShare'] as $share){
1429         $tmp = $tmp2 = array();
1430         $tmp = explode("|",$share);
1431         $tmp2['server']      =$tmp[0];
1432         $tmp2['name']        =$tmp[1];
1434         /* Decode base64 if needed */
1435         if (!preg_match('%/%', $tmp[2])){
1436           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1437         } else {
1438           $tmp2['mountPoint']  =$tmp[2];
1439         }
1441         if(isset($tmp[3])){
1442           $tmp2['PwdHash']  =$tmp[3];
1443         }else{
1444           $tmp2['PwdHash']  ="";
1445         }
1446         if(isset($tmp[4])){
1447           $tmp2['Username']  =$tmp[4];
1448         }else{
1449           $tmp2['Username']  ="";
1450         }
1451         $tmp2['UsedByAllUsers'] = FALSE;
1452         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1453       }
1454     }
1456     /* Prepare Shares */
1457     if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1458       unset($this->multi_attrs['gotoShare']['count']);
1459       foreach($this->multi_attrs['gotoShare'] as $share){
1460         $tmp = $tmp2 = array();
1461         $tmp = explode("|",$share);
1462         $tmp2['server']      =$tmp[0];
1463         $tmp2['name']        =$tmp[1];
1465         /* Decode base64 if needed */
1466         if (!preg_match('%/%', $tmp[2])){
1467           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1468         } else {
1469           $tmp2['mountPoint']  =$tmp[2];
1470         }
1472         if(isset($tmp[3])){
1473           $tmp2['PwdHash']  =$tmp[3];
1474         }else{
1475           $tmp2['PwdHash']  ="";
1476         }
1477         if(isset($tmp[4])){
1478           $tmp2['Username']  =$tmp[4];
1479         }else{
1480           $tmp2['Username']  ="";
1481         }
1482         $tmp2['UsedByAllUsers'] = TRUE;
1483         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1484       }
1485     }
1488     /* prepare LogonScripts */
1489     if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1490       unset($this->multi_attrs_all['gotoLogonScript']['count']);
1491       foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1492         $tmp = $tmp2 = array();
1493         $tmp = explode("|",$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'] = FALSE;
1509         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1510       }
1511     }
1513     /* prepare LogonScripts */
1514     if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1515       unset($this->multi_attrs['gotoLogonScript']['count']);
1516       foreach($this->multi_attrs['gotoLogonScript'] as $device){
1517         $tmp = $tmp2 = array();
1518         $tmp = explode("|",$device);
1519         $tmp2['LogonName']        = $tmp[0];
1520         $tmp2['LogonPriority']    = $tmp[2];
1521         if(preg_match("/O/i",$tmp[1])){
1522           $tmp2['LogonOverload'] = "O";
1523         }else{
1524           $tmp2['LogonOverload'] = "";
1525         }
1526         if(preg_match("/L/i",$tmp[1])){
1527           $tmp2['LogonLast'] = "L";
1528         }else{
1529           $tmp2['LogonLast'] = "";
1530         }
1531         $tmp2['LogonData']        = base64_decode($tmp[3]);
1532         $tmp2['LogonDescription'] = $tmp[4];
1533         $tmp2['UsedByAllUsers'] = TRUE;
1534         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1535       }
1536     }
1538     /* Prepare hotplugs */
1539     if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1540       $ldap = $this->config->get_ldap_link();
1541       $ldap->cd($this->config->current['BASE']);
1542       for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1543         $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1544         if($ldap->count()){
1545           $multi_attrs_all = $ldap->fetch();
1547           if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1548             $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1549             $tmp2     = array();
1550             $tmp2['name']         = $multi_attrs_all['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_all['dn'];
1556             $tmp2['UsedByAllUsers'] = FALSE;
1557             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1558           }
1559         }
1560       }
1561     }
1563     /* Prepare hotplugs */
1564     if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1565       $ldap = $this->config->get_ldap_link();
1566       $ldap->cd($this->config->current['BASE']);
1567       for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1568         $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1569         if($ldap->count()){
1570           $multi_attrs = $ldap->fetch();
1572           if(isset($multi_attrs['gotoHotplugDevice'][0])){
1573             $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1574             $tmp2     = array();
1575             $tmp2['name']         = $multi_attrs['cn'][0];
1576             $tmp2['description']  = $tmp[0];
1577             $tmp2['id']           = $tmp[1];
1578             $tmp2['produkt']      = $tmp[2];
1579             $tmp2['vendor']       = $tmp[3];
1580             $tmp2['dn']           = $multi_attrs['dn'];
1581             $tmp2['UsedByAllUsers'] = TRUE;
1582             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1583           }
1584         }
1585       }
1586     }
1587     $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1588     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1589       $chr = $this->gotoProfileFlags[$i];
1590       $name = "gotoProfileFlag".$chr;
1591       $this->$name=$chr;
1592     }
1593     $this->update_kiosk_profiles();
1594     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1596     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1597       $this->useProfile = true;
1598     }else{
1599       $this->useProfile = false;
1600     }
1602   }
1605   function set_multi_edit_values($attrs)
1606   {
1607     $shares = $this->gotoShares;
1608     $scripts= $this->gotoLogonScripts;
1609     $plugs= $this->gotoHotplugDevices;
1610     plugin::set_multi_edit_values($attrs);
1612     $this->gotoShares = $shares;
1613     $this->gotoLogonScripts = $scripts;
1614     $this->gotoHotplugDevices = $plugs;
1616     foreach($attrs['gotoShares'] as $name => $share){
1617       if($share['UsedByAllUsers'] == TRUE){
1618         $this->gotoShares[$name] = $share;
1619       }
1620     }
1621     foreach($this->gotoShares as $name => $share){
1622       if(!isset($attrs['gotoShares'][$name])){
1623         unset($this->gotoShares[$name]);
1624       }
1625     }
1626     foreach($attrs['gotoLogonScripts'] as $name => $script){
1627       if($script['UsedByAllUsers'] == TRUE){
1628         $this->gotoLogonScripts[$name] = $script;
1629       }
1630     }
1631     foreach($this->gotoLogonScripts as $name => $script){
1632       if(!isset($attrs['gotoLogonScripts'][$name])){
1633         unset($this->gotoLogonScripts[$name]);
1634       }
1635     }
1636     $tmp = array();
1637     foreach($this->gotoHotplugDevices as $entry){
1638       $tmp[$entry['dn']] = $entry;
1639     }
1640   
1641     foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1642       if($plug['UsedByAllUsers'] == TRUE){
1643         $tmp[$plug['dn']] = $plug;
1644       }
1645     }
1646     foreach($tmp as $name => $plug){
1647       $found = false;
1648       foreach($attrs['gotoHotplugDevices'] as $test){
1649         if($test['dn'] == $name){
1650           $found = true;
1651         }
1652       }
1653       if(!$found){
1654         unset($tmp[$name]);
1655       }
1656     }
1657   }
1660     /* Return selected values for multiple edit */
1661   function get_multi_edit_values()
1662   {
1663     $ret = plugin::get_multi_edit_values();
1664     $ret['gotoShares'] = $this->gotoShares;
1665     $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1666     $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1667   
1668     if(in_array("gotoPrinter",$this->multi_boxes)){
1669       $ret['gotoPrinter'] = $this->gotoPrinter;
1670       $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1671       $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1672   
1673       /* Force printer reset */
1674       $ret['add_del_printer_member_was_called'] = TRUE;
1675     }
1676   
1677     if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1678       $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1679     }
1681     if(in_array("useProfile",$this->multi_boxes)){
1682       $ret['useProfile']=$this->useProfile;
1683       if(in_array("gotoProfileServer",$this->multi_boxes)){
1684         $ret['gotoProfileServer']=$this->gotoProfileServer;
1685       }
1686       if(in_array("gotoProfileQuota",$this->multi_boxes)){
1687         $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1688       }
1689       if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1690         $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1691       }
1692     }
1693     if(in_array("gotoXResolution",$this->multi_boxes)){
1694       $ret['gotoXResolution'] = $this->gotoXResolution;
1695     }
1696     if(in_array("kiosk_server",$this->multi_boxes)){
1697       $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1698       $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1699     }
1700     return($ret);
1701   }
1704   function multiple_check() 
1705   {
1706     $message = plugin::multiple_check();
1707     $this->detect_grouptype();
1709     if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1710       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1711     }
1712     return($message);
1713   }
1716   function multiple_save_object()
1717   {
1718     if(isset($_POST['environment_multiple_posted'])){
1719       plugin::multiple_save_object();
1720       
1721       if(isset($_POST['useProfile'])){
1722         $this->useProfile = true;
1723       }else{
1724         $this->useProfile = false;
1725       }
1726       if(isset($_POST['gotoProfileFlagC'])){
1727         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1728       }else{
1729         $this->gotoProfileFlagC = false;
1730       }
1732       if(isset($_POST['gotoProfileFlagL'])){
1733         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1734       }else{
1735         $this->gotoProfileFlagL = false;
1736       }
1738       foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1739                     "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1740         $uattr = "use_".$attr;
1741         if(isset($_POST[$uattr])){
1742           $this->multi_boxes[] = $attr;
1743         }
1744       }
1745       if(isset($_POST['kiosk_server'])){
1746         $tmp = $_POST['kiosk_server'];
1747         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1748           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1749         }
1750       }
1751       if(isset($_POST['kiosk_profile'])){
1752         $tmp = $_POST['kiosk_profile'];
1753         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1754           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1755         }
1756       }
1758     }
1759   }
1761   /* Return plugin informations for acl handling 
1762 #FIXME these ACLs should work for groups too */ 
1763   static function plInfo()
1764   {
1765     return (array("plShortName"     => _("Desktop"),
1766           "plDescription"   => _("Desktop settings"),         // Description
1767           "plSelfModify"    => TRUE,                              
1768           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1769           "plPriority"      => 3,                                 // Position in tabs 
1770           "plSection"     => array("personal" => _("My account")),
1771           "plCategory"    => array("users",
1772                                    "groups"),
1773           "plOptions"       => array("resolution_hook" => array("type" => "string",
1774               "description" => _("Command to extend the list of possible screen resolutions"))),
1776           "plProvidedAcls"  => array(
1778             "gotoPrinter"         => _("Printer") ,
1779             "gotoProfileServer"   => _("Profile server") ,
1780             "gosaDefaultPrinter"  => _("Default printer"),
1781             "gotoProfileQuota"    => _("Profile quota") ,
1782             "gotoProfileFlagC"    => _("Cache profile localy") ,
1783             "gotoShare"          => _("Shares"),
1784             "gotoHotplugDeviceDN" => _("Hotplug devices"),
1785             "gotoKioskProfile"    => _("Kiosk profile") ,
1786             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1787             "gotoXResolution"     => _("Resolution") ,
1788             "gotoLogonScript"     => _("Logon script"))
1789             ));
1790   }
1793 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1794 ?>