Code

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