Code

Updated Enviroment->Printer settings
[gosa.git] / gosa-plugins / goto / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account       = FALSE;
7   var $plHeadline           = "Environment";
8   var $plDescription        = "This does something";
9   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
10   
11   var $in_dialog            = false;
12   var $uid                  = "";
14   var $is_group             = false;
15   var $view_logged = FALSE;
16   
17   /* Attribute definition
18    */
20   /* profile management */
21   var $useProfile         = false;  // Specifies if we want to use a Server 
22   var $gotoProfileServer  = "";     // Specifies the selected profile server
23   var $gotoProfileServers = array();// Specifies all available and selectable servers
24   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
25   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
26   
27   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
28   var $gotoXResolutions   = array();// Contains all available resolutions for this account
29   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
30   var $gotoProfileQuota   = "";     // User Quota Settings
32   /* Logon script section*/
33   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
34   var $gotoLogonScript    = "";     // The selected Logon Script
36   /* Printer */
37   var $gotoPrinter        = array();// All available Printer, with their configurations
38   var $gotoPrinterSel     = "";     //  The selected Printer
39   var $gosaDefaultPrinter = "";     // Default printer
41   /* Share */
42   var $gotoShares         = array();// Current Share Options
43   var $gotoShare          = "";     // currently selected Share Option
44   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45   var $gotoAvailableShares= array();// Available Shares for this account
47   /* Kiosk profile */
48   var $kiosk_enabled      = FALSE;
49   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
50   var $gotoKioskProfile_Server    = "";     // The selected Kiosk Profile
51   var $gotoKioskProfile_Profile   = "";     // The selected Kiosk Profile
52   var $gotoKioskProfiles  = array();// All available Kiosk profiles
54   /* Hotplug Devices */
55   var $gotoHotplugDevice  = array();     // Selected hotplug
56   var $gotoHotplugDevices = array();// Already configured hotplug devices 
57   var $gotoHotplugDeviceDN= array();
59   var $NewAddedPrinters   = array();
60   var $NewDeletedPrinters = array();
62   /* general settings */
63   // Sets the attributes which will kept on page reload, which will be saved, ...
65   var $CopyPasteVars      = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
67   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
68       "gotoXResolution","gotoProfileQuota",
69       "gotoLogonScripts","gotoLogonScript",
70       "gotoPrinter", "gosaDefaultPrinter",
71       "gotoShares","gotoShare",
72       "gotoKioskProfile");
73   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
74   var $cn;
75   var $OrigCn;
76   var $add_del_printer_member_was_called = false;
78   var $multiple_support =TRUE;
80   var $use_gotoPrinter;
82   function environment (&$config, $dn= NULL)
83   {
84     plugin::plugin ($config, $dn);
86     /* Setting uid to default */
87     if(isset($this->attrs['uid'][0])){
88       $this->uid = $this->attrs['uid'][0];
89     }
91     /* Check : Are we currently editing a group or user dialog */
92     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
93       $suffix="Group";
94       $this->uid          = $this->attrs['cn'][0];
95       $this->attrs['uid'] = $this->attrs['cn'][0];
96       $this->OrigCn = $this->attrs['cn'][0];
97     }else{
98       $suffix="User";
99     }
101     /* Get all Printer assignments */
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cd($this->config->current['BASE']);
104     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
105     while($printer = $ldap->fetch()){
106       $this->gotoPrinter[$printer['cn'][0]]=$printer;
107       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
108     }
109     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
110     while($printer = $ldap->fetch()){
111       $this->gotoPrinter[$printer['cn'][0]]=$printer;
112       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
113     }
116     /* Prepare hotplugs */
117     if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
118       $ldap = $this->config->get_ldap_link();
119       $ldap->cd($this->config->current['BASE']);
120       for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
121         $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
122         if($ldap->count()){
123           $attrs = $ldap->fetch(); 
125           if(isset($attrs['gotoHotplugDevice'][0])){
126             $tmp      = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
127             $tmp2     = array();
128             $tmp2['name']         = $attrs['cn'][0];
129             $tmp2['description']  = $tmp[0];
130             $tmp2['id']           = $tmp[1];
131             $tmp2['produkt']      = $tmp[2];
132             $tmp2['vendor']       = $tmp[3];
133             $tmp2['dn']           = $attrs['dn'];
134             $this->gotoHotplugDevices[] = $tmp2; 
135           }
136         }else{
137           msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
138         }
139       }
140     }
142  
143     /* prepare LogonScripts */
144     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
145       unset($this->attrs['gotoLogonScript']['count']);
146       foreach($this->attrs['gotoLogonScript'] as $device){
147         $tmp = $tmp2 = array();
148         $tmp = split("\|",$device);
149         $tmp2['LogonName']        = $tmp[0]; 
150         $tmp2['LogonPriority']    = $tmp[2]; 
151         if(preg_match("/O/i",$tmp[1])){
152           $tmp2['LogonOverload'] = "O";
153         }else{
154           $tmp2['LogonOverload'] = "";
155         }
156         if(preg_match("/L/i",$tmp[1])){
157           $tmp2['LogonLast'] = "L";
158         }else{
159           $tmp2['LogonLast'] = "";
160         }
161         $tmp2['LogonData']        = base64_decode($tmp[3]); 
162         $tmp2['LogonDescription'] = $tmp[4];
163         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
164       }
165     }
167     /* Prepare Shares */
168     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
169       unset($this->attrs['gotoShare']['count']);
170       foreach($this->attrs['gotoShare'] as $share){
171         $tmp = $tmp2 = array();
172         $tmp = split("\|",$share);
173         $tmp2['server']      =$tmp[0];
174         $tmp2['name']        =$tmp[1];
176         /* Decode base64 if needed */
177         if (!preg_match('%/%', $tmp[2])){
178           $tmp2['mountPoint']  =base64_decode($tmp[2]);
179         } else {
180           $tmp2['mountPoint']  =$tmp[2];
181         }
183         if(isset($tmp[3])){
184           $tmp2['PwdHash']  =$tmp[3];
185         }else{
186           $tmp2['PwdHash']  ="";
187         }
188         if(isset($tmp[4])){
189           $tmp2['Username']  =$tmp[4];
190         }else{
191           $tmp2['Username']  ="";
192         }
193         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
194       }
195     }
197     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
198       $chr = $this->gotoProfileFlags[$i];
199       $name = "gotoProfileFlag".$chr;
200       $this->$name=$chr;
201     }
203     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
204       $this->useProfile = true;
205     }else{
206       $this->useProfile = false;
207     }
209     /* Set resolutions */
210     $this->gotoXResolutions = array("auto"=>_("auto"),
211                                     "640x480"   =>  "640x480",
212                                     "800x600"   =>  "800x600",
213                                     "1024x768"  =>  "1024x768",
214                                     "1152x864"  =>  "1152x864",
215                                     "1280x768"  =>  "1280x768",
216                                     "1280x1024" =>  "1280x1024");
218     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
219       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
221       if(is_readable($file)){
222         $str = file_get_contents($file);
223         $lines = split("\n",$str);
224         foreach($lines as $line){
225           $line = trim($line);
226           if(!empty($line)){
227             $this->gotoXResolutions[$line]=$line;
228           }
229         }
230         //natcasesort($this->gotoXResolutions);
231       }else{
232         msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
233       }
234     }
236     $this->gotoProfileServers= $config->getShareServerList() ;
237     $this->gotoShareSelections= $config->getShareList(true);
238     $this->gotoAvailableShares= $config->getShareList(false);  
240     $this->update_kiosk_profiles();
241   }
244   function update_kiosk_profiles()
245   { 
246     $tmp1  = array("none" => array(_("disabled")));
247     $tmp2  = array("none" => _("disabled"));
248     $tmp3  = array();
249     $ldap = $this->config->get_ldap_link();
250     $ldap->cd($this->config->current['BASE']);
251     $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
252     $cnt = 0;
253     while($attrs = $ldap->fetch()){
254       for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
255         $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
256         $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
257         $tmp1[$attrs['cn'][0]][] = $name;
258         $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
259       }
260       $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
261       $cnt ++;
262     }
264     if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
265       $this->kiosk_enabled = TRUE;
266     }
268     $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
269     $this->gotoKioskProfiles['SERVERS']   = $tmp2;
270     $this->gotoKioskProfiles['MAP']       = $tmp3;
271   
272     $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
273     $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
275     $error = false;
276     if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
277       $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
278       $error = true;
279     }
280   
281     if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
282       $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
283       $error = true;
284     }
285     if($error && !empty($this->gotoKioskProfile)){
286       $this->gotoKioskProfile_Server ="none";
287       $this->gotoKioskProfile_Profile="";
288       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);
289     }
290   }
293   /* Detect type of edited object (user|group)*/
294   function detect_grouptype()
295   {
296     if((!isset($this->parent))&&(!$this->is_account)){
297       $this->is_group     = false;
298     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
299       $this->is_group     = true;
300     }else{
301       $this->is_group     = false;
302     }
303   }
306   function execute()
307   {
309     /* Call parent execute */
310     plugin::execute();
311     /* Log view */
312     if($this->is_account && !$this->view_logged){
313       $this->view_logged = TRUE;
314       if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
315         new log("view","users/".get_class($this),$this->dn);
316       }else{
317         new log("view","groups/".get_class($this),$this->dn);
318       }
319     }
321     /* Are we editing from MyAccount and not editing a user */
322     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
324     /* Check profile server */
325     if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
326       if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
327         if(count($this->gotoProfileServers)){
329           /* Get First Profile */
330           $new = key($this->gotoProfileServers);
332           /* Another profile server found */
333           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
334         }else{
336           /* No other profile servers found */
337           msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
338           $this->gotoProfileServer = "none";
339         }
340       }
341     }    
343     $this->detect_grouptype();
345     /* Fill templating stuff */
346     $smarty= get_smarty();
347     $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
348     $display= "";
350     $smarty->assign("is_group",$this->is_group);
352     /* Prepare all variables for smarty */
353     foreach($this->attributes as $s_attr){
354       /* Set value*/
355       $smarty->assign($s_attr,$this->$s_attr);
357       /* Set checkbox state*/
358       if(empty($this->$s_attr)){
359         $smarty->assign($s_attr."CHK","");
360       }else{
361         $smarty->assign($s_attr."CHK"," checked ");
362       }
364       /* Prepare ACL settings*/
365       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
366     }
368     /* Is accout enabled | are we editing from usermenu or admin menu 
369        All these tab management is done here
370      */
373     /* Working from Usermenu an the Account is currently disbled
374      * this->parent :  is only set if we are working in a list of tabs
375      * is_account   :  is only true if the needed objectClass is given
376      */
377     if((!isset($this->parent))&&(!$this->is_account)){
378       /* We are currently editing this tab from usermenu, but this account is not enabled */
379       $smarty->assign("is_account",$this->is_account);
380       /* Load template */
381       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
382       /* Avoid the "You are currently editing ...." message when you leave this tab */
383       $display .= back_to_main(); 
384       /* Display our message to the user */
385       return $display;
388       /* We are currently editing from group tabs, because 
389        * $this->parent is set
390        * posixAccount is not set, so we are not in usertabs.
391        */
392     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
393       $smarty->assign("is_account","true");
394       $this->uid          = $this->cn;
395       $this->attrs['uid'] = $this->cn;
397       /* Change state if needed */
398       if (isset($_POST['modify_state'])){
399         if(($this->acl_is_createable() && !$this->is_account) || 
400             ($this->acl_is_removeable() &&  $this->is_account)){
401           $this->is_account= !$this->is_account;
402         }
403       }
404       /* Group Dialog with enabled environment options */
405       if ($this->is_account){
406         $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
407             msgPool::featuresEnabled(_("Environment")));
408       } else {
410         /* Environment is disabled 
411            If theres is no posixAccount enabled, you won't be able to enable 
412            environment extensions
413          */
414         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
415           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
416               msgPool::featuresDisabled(_("Environment")));
417           return $display;
418         }elseif((isset($this->parent->by_object['ogroup']))){
419           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
420               msgPool::featuresDisabled(_("Environment")));
421           return $display;
422         }else{
423           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
424               msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
425           return $display;
426         }
427       }
428     }else{
429       /* Editing from Usermenu 
430        *  Tell smarty that this accoutn is enabled 
431        */
432       $smarty->assign("is_account","true");
434       /* Change state if needed */
435       if (isset($_POST['modify_state'])){
436         if(($this->acl_is_createable() && !$this->is_account) || 
437             ($this->acl_is_removeable() &&  $this->is_account)){
438           $this->is_account= !$this->is_account;
439         }
440       }
442       if(isset($this->parent)){
444         // 3. Account enabled . Editing from adminmenu
445         if ($this->is_account){
446           $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
447               msgPool::featuresEnabled(_("Environment")));
448         } else {
450           if($this->parent->by_object['posixAccount']->is_account==true){
451             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
452                 msgPool::featuresDisabled(_("Environment")));
453             return $display;
454           }else{
455             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
456                 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
457             return $display;
458           }
459         }
460       }
461     }
462   
463     /* Reset header toggle */
464     if($this->multiple_support_active){
465       $display = "";
466     }
468     /* Account is Account : is_accounbt=true.
469      * Else we won't reach this. 
470      */
472     /* Prepare all variables for smarty */
473     foreach($this->attributes as $s_attr){
474       /* Set value*/
475       $smarty->assign($s_attr,$this->$s_attr);
477       /* Set checkbox state*/
478       if(empty($this->$s_attr)){
479         $smarty->assign($s_attr."CHK","");
480       }else{
481         $smarty->assign($s_attr."CHK"," checked ");
482       }
484       /* Prepare ACL settings*/
485       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
486     }
488     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
489       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
490     }
492     if($WriteOnly) {
493       $smarty->assign("gotoPrinterACL","r");
494     }else{
495       $smarty->assign("gotoPrinterACL","rw");
496     }
499     $smarty->assign("useProfile",$this->useProfile);
500     if(empty($this->useProfile) && !$this->multiple_support_active){
501       $smarty->assign("useProfileCHK","");
502       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
503       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
504       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
505     }else{
506       $smarty->assign("useProfileCHK"," checked ");
507     }
508     
509     $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
510     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
512     /* HANDLE Profile Settings here 
513      * Assign available Quota and resolution settings
514      * Get all available profile server
515      * Get cache checkbox
516      * Assign this all to Smarty 
517      */
519     if(empty($this->gotoProfileFlagL)){
520       $smarty->assign("gotoProfileFlagLCHK"," ");
521     }else{
522       $smarty->assign("gotoProfileFlagLCHK"," checked ");
523     }
525     if(empty($this->gotoProfileFlagC)){
526       $smarty->assign("gotoProfileFlagCCHK"," ");
527     }else{
528       $smarty->assign("gotoProfileFlagCCHK"," checked ");
529     }
532     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
533     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
535     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
536     if(!is_array($this->gotoProfileServers)){
537       $this->gotoProfileServers =array();
538     }
539     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
541     /* Handle kiosk profiles*/
542     $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
543     $smarty->assign("kiosk_server" ,  $this->gotoKioskProfile_Server);
544     $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
545     $smarty->assign("kiosk_profile" ,  $this->gotoKioskProfile_Profile);
546   
548     /* Logonscript Management
549      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
550      * Perform add Delete edit Posts 
551      */
553     /* Dialog Save */
554     if(isset($_POST['LogonSave'])){
556       if(!$this->acl_is_writeable("gotoLogonScript")){
557         msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
558         unset($this->dialog);
559         $this->dialog=FALSE;
560         $this->is_dialog=false;
561       }else{
562         $this->dialog->save_object();
563         if(count($this->dialog->check())!=0){
564           foreach($this->dialog->check() as $msg){
565             msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
566           }
567         }else{
568           $tmp = $this->dialog->save();
569           unset($this->dialog);
570           $this->dialog=FALSE;
571           $this->is_dialog=false;
573           if($this->multiple_support_active){
574             $tmp['UsedByAllUsers'] = TRUE;
575           }
576           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
577         }
578       }
579     }
580     
582     /* Dialog Quit without saving */
583     if(isset($_POST['LogonCancel'])){
584       $this->is_dialog= false;
585       unset($this->dialog);
586       $this->dialog= FALSE;
587     }
589     /* Check Edit Del New Posts for a selected LogonScript */ 
590     if($this->acl_is_writeable("gotoLogonScript") && 
591         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
593       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
594        * In this case we create a new Logon Script.
595        */
596       if(isset($_POST['gotoLogonScriptNew'])){
597         $this->is_dialog = true;
598         $this->dialog = new logonManagementDialog($this->config,$this->dn);
599       }
601       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
602        * We only can delete if there is an entry selected.
603        */
604       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
605         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
606       }
608       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
609        * There must be an entry selected to perform edit request.
610        */
611       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
612         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
613         $this->is_dialog = true;
614         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
615       }
616     }
618     /* Append List to smarty*/
619     if($this->multiple_support_active){
620       $smarty->assign("gotoLogonScripts",  $this->gotoLogonScripts);
621       $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
622     }else{
623       $ls = $this->printOutLogonScripts();
624       $smarty->assign("gotoLogonScripts",  $ls);
625       $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
626       $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
627     }
629     /* In this section server shares will be defined 
630      * A user can select one of the given shares and a mount point
631      *  and attach this combination to his setup.
632      */
634     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
635     if(!is_array($this->gotoShareSelections)){
636       $this->gotoShareSelections = array();
637     }
638     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
640     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
641      * This entry will be, a combination of mountPoint and sharedefinitions 
642      */
643     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
645       /* We assign a share to this user, if we don't know where to mount the share */
646       if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
647         msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
648       }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
649         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
650       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
651         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
652       }elseif(!(
653             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
654             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
655             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
656             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
657             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
658             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
659             preg_match("/^%/",$_POST['gotoShareMountPoint'])
660             )
661           ){
662         msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
663       }else{
664         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
665         $s_mount = $_POST['gotoShareMountPoint'];
666         $s_user  = $_POST['ShareUser'];
667         /* Preparing the new assignment */ 
668         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
669         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
670         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
671         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
673         if($this->multiple_support_active){
674           $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
675         }
676       }
677     }  
679     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
680      * If there is no defined share selected, we will abort the deletion without any message 
681      */
682     $once = true;
683     if($this->acl_is_writeable("gotoShare")){
684       foreach($_POST as $name => $value){
685         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
686           $once = false;  
687           $key  = preg_replace("/^gotoShareDel_/","",$name);
688           $key  = preg_replace("/_+[xy]$/","",$key);
689           $key  = base64_decode($key);
690           if(isset($this->gotoShares[$key])) {
691             unset($this->gotoShares[$key]);
692           }
694           /* Remove corresponding password entry, too. This is a workaround
695              to get rid of old-style entries. */
696           $key= preg_replace("/\|/", "|!", $key);
697           if(isset($this->gotoShares[$key])) {
698             unset($this->gotoShares[$key]);
699           }
700         }
701         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
702           $once = false;
703           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
704           $key  = preg_replace("/_+[xy]$/","",$key);
705           $key  = base64_decode($key);
706           $this->gotoShares[$key]['PwdHash'] = "";
707           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
708             unset($this->gotoShares[$key]);
709           }
710         }
711       }
712     }
713     $divlistShares = new divSelectBox("gotoShares");
714     $divlistShares->SetHeight(100);
717     $tmp = array();
718     if($this->acl_is_readable("gotoShares")){
719       $tmp = $this->printOutAssignedShares();
720     }
722     
723     foreach($tmp as $key => $value){
724       $img = "";
726       /* Skip apssword only entries */
727       if( empty($this->gotoShares[$key]['server']) && 
728           empty($this->gotoShares[$key]['name']) &&
729           empty($this->gotoShares[$key]['mountPoint']) &&
730           empty($this->gotoShares[$key]['Username'])){
731         continue;
732       } 
734       $color = "";
735       if($this->multiple_support_active){
736         if($this->gotoShares[$key]['UsedByAllUsers']){
737           $value .= "&nbsp;(<b>"._("Used by all users")."</b>)";
738         }else{
739           $color = "color: #999999;";
740           $value .= "&nbsp;(<b>"._("Used by some users")."</b>)";
741         }
742       }
744       /* Check if entry starts with an ! */
745       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
747         /* If we are currently editing groups environment, skip those ! entries */ 
748         if($this->is_group) continue;
750         /* Create pwd reset images */
751         if($this->gotoShares[$key]['PwdHash'] != ""){
752           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
753             title='"._("Reset password hash")."'>";
754         }
755         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
756         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
757       }else{
759         /* Create pwd reset img && delete image */
760         if($this->gotoShares[$key]['PwdHash'] != ""){
761           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
762             title='"._("Reset password hash")."'>";
763           $img.= "&nbsp;";
764         }
765         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/lists/trash.png' alt='".msgPool::delButton()."' 
766           title='"._("Delete share entry")."'>";
767         $field1 = array("string" => $value , "attach" => "style='".$color."'");
768         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
769       }
770       $divlistShares->AddEntry(array($field1,$field2));
771     }
772     $smarty->assign("divlistShares",$divlistShares->DrawList());
774     /* Hotplug devices will be handled here 
775      * There are 3 possible methods for this feature
776      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
777      * Delete will erase an entry, the entry must be selcted in the ListBox first
778      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
779      */
781     /* We have to delete the selected hotplug from the list*/
782     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
783       if($this->acl_is_writeable("gotoHotplugDevice")){
784         foreach($_POST['gotoHotplugDevice_post'] as $name){
785           unset($this->gotoHotplugDevices[$name]);
786         }
787       }
788     }
790     /* There are already defined hotplugs from other users we could use */
791     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
792       $tmp  =array();
793       foreach($this->gotoHotplugDevices as $plugs){
794         $tmp[] = $plugs['name'];
795       }
796       $this->dialog = new hotplugDialog($this->config,$tmp);
797       $this->is_dialog = true;
798     }
800     /* Dialog Aborted */
801     if(isset($_POST['HotPlugCancel'])){
802       unset($this->dialog);
803       $this->dialog= FALSE;
804       $this->is_dialog = false;
805     }
807     /* Dialod saved */
808     if(isset($_POST['HotPlugSave'])){
810       $this->dialog->save_object();
811       if(count($this->dialog->check())!=0){
812         foreach($this->dialog->check() as $msg){
813           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
814         }
815       }else{
816         $this->dialog->save_object();
817         $a_tmp = $this->dialog->save();
819         if(is_array($a_tmp)){
820           foreach($a_tmp as $name => $hotplug){
821             if($this->multiple_support_active){
822               $hotplug['UsedByAllUsers'] = TRUE;
823             }
824             $this->gotoHotplugDevices[$name]= $hotplug; 
825           }
826         }
827         unset($this->dialog);
828         $this->dialog= FALSE;
829         $this->is_dialog = false;
830       }
831     }
833     if($this->multiple_support_active){
834       $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
835     }else{
836       $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
837       $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
838     }
840     /* Printer Assignment will managed below 
841      * A printer can be assigned in two different ways and two different types
842      * There are 2 types of users assigned to a printer : user and admin
843      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
844      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
845      */ 
847     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
848     if(isset($_POST['gotoPrinterAdd'])){
850       $this->is_dialog=true;
851       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
852     }
854     if(isset($_POST['PrinterCancel'])){
855       $this->is_dialog=false;
856       unset($this->dialog);
857       $this->dialog=FALSE;
858     }
860     if(isset($_POST['PrinterSave'])){
861       if(count($this->dialog->check())!=0){
862         $tmp = $this->dialog->check();
863         foreach($tmp as $msg){
864           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
865         } 
866       }else{
867         $this->dialog->save_object();
868         $tmp = $this->dialog->save();
869         $tmp2= $this->dialog->getPrinter(true);
871         foreach($tmp as $pname){
872           $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
873           $printerObj->set_acl_base($tmp2[$pname]['dn']);
875           $type = false;
877           if($this->is_group){
878             if($this->dn == "new"){  
879               $type = "AddGroup";
880             }elseif(isset($this->NewDeletedPrinters[$pname])){
881               $type = "AddGroup";
882             }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
883               $type = "AddGroup";
884             }
885           }else{
886             if($this->multiple_support_active){
887               $type = "AddUser";
888             }elseif(isset($this->NewDeletedPrinters[$pname])){
889               $type = "AddUser";
890             }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
891               $type = "AddUser";
892             }
893           }
895           if($type){
896             $this->gotoPrinter[$pname]=$tmp2[$pname];
897             $this->gotoPrinter[$pname]['mode']="user";
898             $this->add_del_printer_member_was_called = true;
900             $this->NewAddedPrinters[$pname] = $pname;
901             if(isset($this->NewDeletedPrinters[$pname])){
902               unset($this->NewDeletedPrinters[$pname]);
903             }
904           }
905         }
907         $this->is_dialog=false;
908         unset($this->dialog);
909         $this->dialog   =FALSE;
910       }
911     }
913     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
914       $printer = $_POST['gotoPrinterSel'];
915       foreach($printer as $pname){
917         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
918         $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
920         $type = false;
921         if($this->is_group){
922           if(isset($this->NewAddedPrinters[$pname])){
923             $type = "Group";
924           }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
925             $type = "Group";
926           }
927         }else{
928           if(isset($this->NewAddedPrinters[$pname])){
929             $type = "User";
930           }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
931             $type = "User";
932           }
933         }
934         if($type){
935           $this->add_del_printer_member_was_called = true;
936           unset($this->gotoPrinter[$pname]);
938           $this->NewDeletedPrinters[$pname] = $pname;
939           if(isset($this->NewAddedPrinters[$pname])){
940             UNSET($this->NewAddedPrinters[$pname]);
941           }
942         }
943       }
944     }
946     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
947       $printers = $_POST['gotoPrinterSel'];
948       $this->add_del_printer_member_was_called = true;
949       foreach($printers as $printer){
950         if($this->gotoPrinter[$printer]['mode']=="user"){
951           $this->gotoPrinter[$printer]['mode']="admin";
952         }else{
953           $this->gotoPrinter[$printer]['mode']="user";
954         }
955       }
956     }
958     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
959       if($this->is_group){
960         msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
961       }else{
962         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
963           $this->gosaDefaultPrinter= "";
964         } else {
965           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
966         }
967       }
968     }
970     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
971     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
973     /* General behavior */
974     if(is_object($this->dialog)){
975       $this->dialog->save_object();
976       $disp =$this->dialog->execute();
977       return($disp);
978     }
980     /* Assign used attributes for multiple edit */
981     foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
982                   "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
983       $ubox ="use_".$box;
984       if(in_array($box,$this->multi_boxes)){
985         $smarty->assign($ubox,TRUE);
986       }else{
987         $smarty->assign($ubox,FALSE);
988       }
989     }
991     /* Als smarty vars are set. Get smarty template and generate output */
992     $smarty->assign("multiple_support",$this->multiple_support_active);
993     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
994     return($display);
995   }
997   function remove_from_parent()
998   {
999     /* only if it was an account*/
1000     if (!$this->initially_was_account){
1001       return;
1002     }
1004     /* include global link_info */
1005     $ldap= $this->config->get_ldap_link();
1007     /* Remove and write to LDAP */
1008     plugin::remove_from_parent();
1010     /* Don't save our template variables */
1011     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1013     /* Skip all these attributes */
1014     foreach($skip as $del){
1015       unset($this->attrs[$del]);
1016     }
1018     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1020     $ldap->cd($this->dn);
1021     $this->cleanup();
1022     $ldap->modify ($this->attrs); 
1024     if($this->is_group){
1025       new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1026     }else{
1027       new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1028     }
1030     if (!$ldap->success()){
1031       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1032     }
1034     /* Optionally execute a command after we're done */
1035     $this->handle_post_events("remove",array("uid" => $this->uid));
1036   }
1039   /* Save data to object */
1040   function save_object()
1041   {
1042     /* Get all Posted vars 
1043      * Setup checkboxes 
1044      */
1045     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1046     if(isset($_POST['iamposted'])){
1048       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1050       if(isset($_POST['kiosk_server'])){
1051         $tmp = $_POST['kiosk_server'];
1052         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1053           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1054         }
1055       }
1056       if(isset($_POST['kiosk_profile'])){
1057         $tmp = $_POST['kiosk_profile'];
1058         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1059           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1060         }
1061       }
1063       if(preg_match("/w/",$PACL)){
1064         if(isset($_POST['useProfile'])){
1065           $this->useProfile = true;
1066         }else{
1067           $this->useProfile = false;
1068         }
1069       }
1071       if($this->acl_is_writeable("gotoProfileFlagC")){
1072         if(isset($_POST['gotoProfileFlagC'])){
1073           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1074         }else{
1075           $this->gotoProfileFlagC = false;
1076         }
1077       }
1079       if($this->acl_is_writeable("gotoProfileFlagL")){
1080         if(isset($_POST['gotoProfileFlagL'])){
1081           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1082         }else{
1083           $this->gotoProfileFlagL = false;
1084         }
1085       }
1087       plugin::save_object();
1088       foreach($this->attributes as $s_attr){
1089         if((!isset($_POST[$s_attr])) || 
1090             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1091         if(!$this->acl_is_writeable($s_attr)){
1092           continue;
1093         }else{ 
1094           if(isset($_POST[$s_attr])){
1095             $this->$s_attr = $_POST[$s_attr];
1096           }else{
1097             $this->$s_attr = false;
1098           }
1099         }
1100       }
1101     }
1102   }
1105   /* Check supplied data */
1106   function check()
1107   {
1108     /* Call common method to give check the hook */
1109     $message= plugin::check();
1111     $this->detect_grouptype();
1113     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1114       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1115     } 
1116     if(!isset($this->attrs['objectClass'])){
1117       $this->attrs['objectClass']=array();
1118     } 
1119     if(!$this->is_group){
1120       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1121         $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));  
1122       }
1123     }
1124     return ($message);
1125   }
1128   /* Save to LDAP */
1129   function save()
1130   {
1131     /* If group was renamed, all printer settings get lost
1132      */ 
1133     /* only save changed variables ....*/
1134     if ($this->gotoKioskProfile_Server != "none"){
1135       $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1136       $this->gotoKioskProfile= $method;
1137     }else{
1138       $this->gotoKioskProfile= array();
1139     }
1141     plugin::save();
1142     $ldap= $this->config->get_ldap_link();
1144     $realyUsedAttrs= array();
1146     /* Save already used objectClasses */
1147     $ocs        = $this->attrs['objectClass'];
1148     unset($ocs['count']);
1149     $this->attrs = array();
1150     $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1152     /* 1. Search all printers that have our uid/cn as member 
1153      * 2. Delete this uid/cn from every single entry and save it again.
1154      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1155      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1156      */
1157     
1158     $this->detect_grouptype();
1160     if($this->add_del_printer_member_was_called){
1162       $types = array( "gotoUserPrinter"       => "AddUser",
1163           "gotoGroupPrinter"      => "AddGroup",
1164           "gotoUserAdminPrinter"  => "AddAdminUser",
1165           "gotoGroupAdminPrinter" => "AddAdminGroup");
1167       if($this->is_group){
1168         $s_suffix = "Group";
1169         $useVar   = "cn";
1170       }else{
1171         $useVar   = "uid";
1172         $s_suffix = "User";
1173       }
1175       /* Remove old entries */
1176       $ldap->cd($this->config->current['BASE']);;
1177       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1178       while($attr = $ldap->fetch()){
1179         $printerObj = NULL;
1180         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1181         $printerObj->set_acl_base($attr['dn']);
1182         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1183         $printerObj->by_object['printgeneric']->save();
1184       }
1186       $ldap->cd($this->config->current['BASE']);;
1187       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1188       while($attr = $ldap->fetch()){
1189         $printerObj = NULL;
1190         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1191         $printerObj->set_acl_base($attr['dn']);
1192         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1193         $printerObj->by_object['printgeneric']->save();
1194       }
1196       foreach($this->gotoPrinter as $printer){
1197         $printerObj = NULL;
1198         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1199         $printerObj->set_acl_base($printer['dn']);
1202         if($printer['mode'] == "admin") {
1203           $attribute = "goto".$s_suffix."AdminPrinter";
1204         }else{
1205           $attribute = "goto".$s_suffix."Printer";
1206         }
1208         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1209         $printerObj->by_object['printgeneric']->save();
1210       }
1211     }    
1213     /* Prepare HotPlug devices */
1214     $this->attrs['gotoHotplugDeviceDN'] = array();
1215     foreach($this->gotoHotplugDevices as $name => $device){
1216       $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1217     }
1219     /* Prepare LogonScripts */
1220     $this->attrs['gotoLogonScript'] = array();
1221     foreach($this->gotoLogonScripts as $name => $script){
1222       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1223         $script['LogonOverload'].$script['LogonLast']."|".
1224         $script['LogonPriority']."|".
1225         base64_encode($script['LogonData'])."|".
1226         $script['LogonDescription'];
1227     }
1229     /* Prepare Shares */
1230     $this->attrs['gotoShare']=array();
1231     foreach($this->gotoShares as $name => $share){
1232       $mntp= $share['mountPoint'];
1233       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1234         $mntp= base64_encode($mntp);
1235       }
1236       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1237     }
1240     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1241     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1243     foreach($saveThis as $tosave){
1244       if(!empty($this->$tosave)){
1245         $this->attrs[$tosave]=$this->$tosave;
1246       }else{
1247         $this->attrs[$tosave]=array();
1248       }
1249     }
1251     /* Prepare Flags */
1252     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1253     if(empty($this->attrs['gotoProfileFlags'][0])){
1254       $this->attrs['gotoProfileFlags']=array();
1255     }
1257     if($this->useProfile == false){
1258       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1259       $this->attrs['gotoProfileServer']= array(); 
1260     }
1262     $ldap->cat ($this->dn, array('dn'));
1263     if ($ldap->fetch()){
1264       $mode= "modify";
1265     } else {
1266       $mode= "add";
1267       $ldap->cd($this->config->current['BASE']);
1268       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1269     }
1271     $ldap->cd($this->dn);
1272     $this->cleanup();
1273     $ldap->$mode($this->attrs);
1274   
1275     $cat = "users";
1276     if($this->is_group){
1277       $cat = "groups";
1278     }
1280     /* Log last action */ 
1281     if($this->initially_was_account){
1282       new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1283     }else{
1284       new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1285     }
1287     if (!$ldap->success()){
1288       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1289     }
1290     $this->handle_post_events($mode,array("uid"=>$this->uid));
1291   }
1293   /* Generate ListBox frindly output for the defined shares 
1294    * Possibly Add or remove an attribute here, 
1295    */
1296   function printOutAssignedShares()
1297   {
1298     $a_return = array();
1299     if(is_array($this->gotoShares)){
1300       foreach($this->gotoShares as $share){
1301         if(preg_match("/^!/",$share['server'])){
1302           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1303         }else{
1304           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1305         }
1306       }
1307       natcasesort($a_return);
1308     }
1309     return($a_return);
1310   }
1312   /* Generate ListBox frindly output for the definedhotplugs 
1313    * Possibly Add or remove an attribute here,
1314    */
1315   function printOutHotPlugDevices()
1316   {
1317     $a_return= array();
1318     if(is_array($this->gotoHotplugDevices)){
1319       foreach($this->gotoHotplugDevices as $key=>$device){
1320         $a_return[$key] = $device['name']." - ".$device['id'];
1321       }
1322     }
1323     return($a_return);
1324   }
1326   /* Generates ListBox frienly output of used printer devices 
1327    * Append ' - admin' if printer is used in admin mode
1328    */
1329   function printOutPrinterDevices()
1330   {
1331     $a_return = array();
1332     
1333     if($this->acl_is_readable("gotoPrinter")){
1335       if(is_array($this->gotoPrinter)){
1336         foreach($this->gotoPrinter as $printer){
1337           if($printer['mode'] == "admin"){
1338             $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1339           }else{
1340             $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1341           }
1342           if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1343             $a_return[$printer['cn'][0]].=" - "._("Default printer");
1344           }
1345         }
1346       }
1347     }
1348     return($a_return);
1349   }
1352   function PrepareForCopyPaste($source)
1353   {
1354     plugin::PrepareForCopyPaste($source);
1356     $class= get_class($this);
1357     $o_source = new $class($this->config,$source['dn']);
1358     foreach($this->CopyPasteVars as $attr){
1359       $this->$attr = $o_source->$attr;  
1360     }
1361   }
1364   function saveCopyDialog()
1365   {
1366     if(isset($_POST['cn'])){
1367       $this->cn = $_POST['cn'];
1368       $this->uid = $_POST['cn'];
1369     }
1370   }
1373   /* Generates ListBox frienly output of used logonscripts 
1374    */
1375   function printOutLogonScripts()
1376   {
1377     $a_return = array();
1378     if(is_array($this->gotoLogonScripts)){
1379       foreach($this->gotoLogonScripts as $script){
1380         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1381       }
1382     }
1383     return($a_return);
1384   }
1387   function multiple_execute()
1388   {
1389     /* Reset header toggle */
1390     $this->is_account = TRUE;
1391     return($this->execute());
1392   }
1395     /* Initialize plugin with given atribute arrays
1396    */
1397   function init_multiple_support($attrs,$all)
1398   {
1399     plugin::init_multiple_support($attrs,$all);
1401     /* Prepare Shares */
1402     if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1403       unset($this->multi_attrs_all['gotoShare']['count']);
1404       foreach($this->multi_attrs_all['gotoShare'] as $share){
1405         $tmp = $tmp2 = array();
1406         $tmp = split("\|",$share);
1407         $tmp2['server']      =$tmp[0];
1408         $tmp2['name']        =$tmp[1];
1410         /* Decode base64 if needed */
1411         if (!preg_match('%/%', $tmp[2])){
1412           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1413         } else {
1414           $tmp2['mountPoint']  =$tmp[2];
1415         }
1417         if(isset($tmp[3])){
1418           $tmp2['PwdHash']  =$tmp[3];
1419         }else{
1420           $tmp2['PwdHash']  ="";
1421         }
1422         if(isset($tmp[4])){
1423           $tmp2['Username']  =$tmp[4];
1424         }else{
1425           $tmp2['Username']  ="";
1426         }
1427         $tmp2['UsedByAllUsers'] = FALSE;
1428         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1429       }
1430     }
1432     /* Prepare Shares */
1433     if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1434       unset($this->multi_attrs['gotoShare']['count']);
1435       foreach($this->multi_attrs['gotoShare'] as $share){
1436         $tmp = $tmp2 = array();
1437         $tmp = split("\|",$share);
1438         $tmp2['server']      =$tmp[0];
1439         $tmp2['name']        =$tmp[1];
1441         /* Decode base64 if needed */
1442         if (!preg_match('%/%', $tmp[2])){
1443           $tmp2['mountPoint']  =base64_decode($tmp[2]);
1444         } else {
1445           $tmp2['mountPoint']  =$tmp[2];
1446         }
1448         if(isset($tmp[3])){
1449           $tmp2['PwdHash']  =$tmp[3];
1450         }else{
1451           $tmp2['PwdHash']  ="";
1452         }
1453         if(isset($tmp[4])){
1454           $tmp2['Username']  =$tmp[4];
1455         }else{
1456           $tmp2['Username']  ="";
1457         }
1458         $tmp2['UsedByAllUsers'] = TRUE;
1459         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1460       }
1461     }
1464     /* prepare LogonScripts */
1465     if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1466       unset($this->multi_attrs_all['gotoLogonScript']['count']);
1467       foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1468         $tmp = $tmp2 = array();
1469         $tmp = split("\|",$device);
1470         $tmp2['LogonName']        = $tmp[0];
1471         $tmp2['LogonPriority']    = $tmp[2];
1472         if(preg_match("/O/i",$tmp[1])){
1473           $tmp2['LogonOverload'] = "O";
1474         }else{
1475           $tmp2['LogonOverload'] = "";
1476         }
1477         if(preg_match("/L/i",$tmp[1])){
1478           $tmp2['LogonLast'] = "L";
1479         }else{
1480           $tmp2['LogonLast'] = "";
1481         }
1482         $tmp2['LogonData']        = base64_decode($tmp[3]);
1483         $tmp2['LogonDescription'] = $tmp[4];
1484         $tmp2['UsedByAllUsers'] = FALSE;
1485         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1486       }
1487     }
1489     /* prepare LogonScripts */
1490     if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1491       unset($this->multi_attrs['gotoLogonScript']['count']);
1492       foreach($this->multi_attrs['gotoLogonScript'] as $device){
1493         $tmp = $tmp2 = array();
1494         $tmp = split("\|",$device);
1495         $tmp2['LogonName']        = $tmp[0];
1496         $tmp2['LogonPriority']    = $tmp[2];
1497         if(preg_match("/O/i",$tmp[1])){
1498           $tmp2['LogonOverload'] = "O";
1499         }else{
1500           $tmp2['LogonOverload'] = "";
1501         }
1502         if(preg_match("/L/i",$tmp[1])){
1503           $tmp2['LogonLast'] = "L";
1504         }else{
1505           $tmp2['LogonLast'] = "";
1506         }
1507         $tmp2['LogonData']        = base64_decode($tmp[3]);
1508         $tmp2['LogonDescription'] = $tmp[4];
1509         $tmp2['UsedByAllUsers'] = TRUE;
1510         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1511       }
1512     }
1514     /* Prepare hotplugs */
1515     if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1516       $ldap = $this->config->get_ldap_link();
1517       $ldap->cd($this->config->current['BASE']);
1518       for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1519         $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1520         if($ldap->count()){
1521           $multi_attrs_all = $ldap->fetch();
1523           if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1524             $tmp      = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1525             $tmp2     = array();
1526             $tmp2['name']         = $multi_attrs_all['cn'][0];
1527             $tmp2['description']  = $tmp[0];
1528             $tmp2['id']           = $tmp[1];
1529             $tmp2['produkt']      = $tmp[2];
1530             $tmp2['vendor']       = $tmp[3];
1531             $tmp2['dn']           = $multi_attrs_all['dn'];
1532             $tmp2['UsedByAllUsers'] = FALSE;
1533             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1534           }
1535         }
1536       }
1537     }
1539     /* Prepare hotplugs */
1540     if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1541       $ldap = $this->config->get_ldap_link();
1542       $ldap->cd($this->config->current['BASE']);
1543       for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1544         $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1545         if($ldap->count()){
1546           $multi_attrs = $ldap->fetch();
1548           if(isset($multi_attrs['gotoHotplugDevice'][0])){
1549             $tmp      = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1550             $tmp2     = array();
1551             $tmp2['name']         = $multi_attrs['cn'][0];
1552             $tmp2['description']  = $tmp[0];
1553             $tmp2['id']           = $tmp[1];
1554             $tmp2['produkt']      = $tmp[2];
1555             $tmp2['vendor']       = $tmp[3];
1556             $tmp2['dn']           = $multi_attrs['dn'];
1557             $tmp2['UsedByAllUsers'] = TRUE;
1558             $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1559           }
1560         }
1561       }
1562     }
1563     $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1564     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1565       $chr = $this->gotoProfileFlags[$i];
1566       $name = "gotoProfileFlag".$chr;
1567       $this->$name=$chr;
1568     }
1569     $this->update_kiosk_profiles();
1570     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1572     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1573       $this->useProfile = true;
1574     }else{
1575       $this->useProfile = false;
1576     }
1578   }
1581   function set_multi_edit_values($attrs)
1582   {
1583     $shares = $this->gotoShares;
1584     $scripts= $this->gotoLogonScripts;
1585     $plugs= $this->gotoHotplugDevices;
1586     plugin::set_multi_edit_values($attrs);
1588     $this->gotoShares = $shares;
1589     $this->gotoLogonScripts = $scripts;
1590     $this->gotoHotplugDevices = $plugs;
1592     foreach($attrs['gotoShares'] as $name => $share){
1593       if($share['UsedByAllUsers'] == TRUE){
1594         $this->gotoShares[$name] = $share;
1595       }
1596     }
1597     foreach($this->gotoShares as $name => $share){
1598       if(!isset($attrs['gotoShares'][$name])){
1599         unset($this->gotoShares[$name]);
1600       }
1601     }
1602     foreach($attrs['gotoLogonScripts'] as $name => $script){
1603       if($script['UsedByAllUsers'] == TRUE){
1604         $this->gotoLogonScripts[$name] = $script;
1605       }
1606     }
1607     foreach($this->gotoLogonScripts as $name => $script){
1608       if(!isset($attrs['gotoLogonScripts'][$name])){
1609         unset($this->gotoLogonScripts[$name]);
1610       }
1611     }
1612     $tmp = array();
1613     foreach($this->gotoHotplugDevices as $entry){
1614       $tmp[$entry['dn']] = $entry;
1615     }
1616   
1617     foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1618       if($plug['UsedByAllUsers'] == TRUE){
1619         $tmp[$plug['dn']] = $plug;
1620       }
1621     }
1622     foreach($tmp as $name => $plug){
1623       $found = false;
1624       foreach($attrs['gotoHotplugDevices'] as $test){
1625         if($test['dn'] == $name){
1626           $found = true;
1627         }
1628       }
1629       if(!$found){
1630         unset($tmp[$name]);
1631       }
1632     }
1633   }
1636     /* Return selected values for multiple edit */
1637   function get_multi_edit_values()
1638   {
1639     $ret = plugin::get_multi_edit_values();
1640     $ret['gotoShares'] = $this->gotoShares;
1641     $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1642     $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1643   
1644     if(in_array("gotoPrinter",$this->multi_boxes)){
1645       $ret['gotoPrinter'] = $this->gotoPrinter;
1646       $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1647       $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1648   
1649       /* Force printer reset */
1650       $ret['add_del_printer_member_was_called'] = TRUE;
1651     }
1652   
1653     if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1654       $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1655     }
1657     if(in_array("useProfile",$this->multi_boxes)){
1658       $ret['useProfile']=$this->useProfile;
1659       if(in_array("gotoProfileServer",$this->multi_boxes)){
1660         $ret['gotoProfileServer']=$this->gotoProfileServer;
1661       }
1662       if(in_array("gotoProfileQuota",$this->multi_boxes)){
1663         $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1664       }
1665       if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1666         $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1667       }
1668     }
1669     if(in_array("gotoXResolution",$this->multi_boxes)){
1670       $ret['gotoXResolution'] = $this->gotoXResolution;
1671     }
1672     if(in_array("kiosk_server",$this->multi_boxes)){
1673       $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1674       $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1675     }
1676     return($ret);
1677   }
1680   function multiple_check() 
1681   {
1682     $message = plugin::multiple_check();
1683     $this->detect_grouptype();
1685     if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1686       $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1687     }
1688     return($message);
1689   }
1692   function multiple_save_object()
1693   {
1694     if(isset($_POST['environment_multiple_posted'])){
1695       plugin::multiple_save_object();
1696       
1697       if(isset($_POST['useProfile'])){
1698         $this->useProfile = true;
1699       }else{
1700         $this->useProfile = false;
1701       }
1702       if(isset($_POST['gotoProfileFlagC'])){
1703         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1704       }else{
1705         $this->gotoProfileFlagC = false;
1706       }
1708       if(isset($_POST['gotoProfileFlagL'])){
1709         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1710       }else{
1711         $this->gotoProfileFlagL = false;
1712       }
1714       foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1715                     "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1716         $uattr = "use_".$attr;
1717         if(isset($_POST[$uattr])){
1718           $this->multi_boxes[] = $attr;
1719         }
1720       }
1721       if(isset($_POST['kiosk_server'])){
1722         $tmp = $_POST['kiosk_server'];
1723         if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1724           $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1725         }
1726       }
1727       if(isset($_POST['kiosk_profile'])){
1728         $tmp = $_POST['kiosk_profile'];
1729         if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1730           $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1731         }
1732       }
1734     }
1735   }
1737   /* Return plugin informations for acl handling 
1738 #FIXME these ACLs should work for groups too */ 
1739   static function plInfo()
1740   {
1741     return (array("plShortName"     => _("Environment"),
1742           "plDescription"   => _("Environment settings"),         // Description
1743           "plSelfModify"    => TRUE,                              
1744           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1745           "plPriority"      => 3,                                 // Position in tabs 
1746           "plSection"     => array("personal" => _("My account")),
1747           "plCategory"    => array("users",
1748                                    "groups"),
1749           "plOptions"       => array("resolution_hook" => array("type" => "string",
1750               "description" => _("Command to extend the list of possible screen resolutions"))),
1752           "plProvidedAcls"  => array(
1754             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1755             "gotoProfileFlagC"    => _("Cache profile localy") ,
1757             "gotoProfileQuota"    => _("Profile quota") ,
1758             "gotoProfileServer"   => _("Profile server") ,
1760             "gotoXResolution"     => _("Resolution") ,
1761             "gotoKioskProfile"    => _("Kiosk profile") ,
1763             "gosaDefaultPrinter"  => _("Default printer") ,
1764             "gotoLogonScript"     => _("Logon script") ,
1765             "gotoHotplugDevice"   => _("Hotplug devices"),
1766             "gotoShare"           => _("Shares"))
1767             ));
1768   }
1771 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1772 ?>