Code

Fixes error
[gosa.git] / plugins / personal / environment / class_environment.inc
1 <?php
3 class environment extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account       = FALSE;
12   var $plHeadline           = "Environment";
13   var $plDescription        = "This does something";
14   var $dialog               = false;    // Indicates that we are currently editing in an seperate dialog
15   
16   var $in_dialog            = false;
17   var $uid                  = "";
19   var $is_group             = false;
20   
21   /* Attribute definition
22    */
24   /* profile management */
25   var $useProfile         = false;  // Specifies if we want to use a Server 
26   var $gotoProfileServer  = "";     // Specifies the selected profile server
27   var $gotoProfileServers = array();// Specifies all available and selectable servers
28   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
29   var $gotoProfileFlagC  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
30   
31   var $gotoXResolution    = "auto";     // The selected resolution eg: 1024x768
32   var $gotoXResolutions   = array();// Contains all available resolutions for this account
33   var $gotoProfileFlagL  = "";     // Flag is set to L to enable runtime resolution change 
34   var $gotoProfileQuota   = "";     // User Quota Settings
36   /* Logon script section*/
37   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
38   var $gotoLogonScript    = "";     // The selected Logon Script
40   /* Printer */
41   var $gotoPrinter        = array();// All available Printer, with their configurations
42   var $gotoPrinterSel     = "";     //  The selected Printer
43   var $gosaDefaultPrinter = "";     // Default printer
45   /* Share */
46   var $gotoShares         = array();// Current Share Options
47   var $gotoShare          = "";     // currently selected Share Option
48   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
49   var $gotoAvailableShares= array();// Available Shares for this account
51   /* Kiosk profile */
52   var $gotoKioskProfile   = "none";     // The selected Kiosk Profile
53   var $gotoKioskProfiles  = array();// All available Kiosk profiles
54   var $newKioskProfiles   = array();
56   /* Hotplug Devices */
57   var $gotoHotplugDevice  = array();     // Selected hotplug
58   var $gotoHotplugDevices = array();// Already configured hotplug devices 
61   /* general settings */
62   // Sets the attributes which will kept on page reload, which will be saved, ...
64   var $CopyPasteVars      = array("gotoHotplugDevices","newKioskProfiles","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags",
67       "gotoXResolution","gotoProfileQuota",
68       "gotoLogonScripts","gotoLogonScript",
69       "gotoPrinter", "gosaDefaultPrinter",
70       "gotoShares","gotoShare",
71       "gotoKioskProfile","gotoKioskProfiles"
72       );
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   function environment ($config, $dn= NULL)
79   {
80     plugin::plugin ($config, $dn);
82     /* Check : Are we currently editing a group or user dialog */
83     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
84       $suffix="Group";
85       $this->uid          = $this->attrs['cn'][0];
86       $this->attrs['uid'] = $this->attrs['cn'][0];
87       $this->OrigCn = $this->attrs['cn'][0];
88     }else{
89       $suffix="User";
90     }
92     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
94     /* Get all Printer assignments */
95     $ldap = $this->config->get_ldap_link();
96     $ldap->cd($this->config->current['BASE']);
97     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
98     while($printer = $ldap->fetch()){
99       $this->gotoPrinter[$printer['cn'][0]]=$printer;
100       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
101     }
102     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
103     while($printer = $ldap->fetch()){
104       $this->gotoPrinter[$printer['cn'][0]]=$printer;
105       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
106     }
108     /* prepare hotplugs */
109     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
110       unset($this->attrs['gotoHotplugDevice']['count']);
111       foreach($this->attrs['gotoHotplugDevice'] as $device){
112         $tmp = $tmp2 = array();
113         $tmp = split("\|",$device);
114         $tmp2['name']        = $tmp[0]; 
115         $tmp2['description'] = $tmp[1]; 
116         $tmp2['id']          = $tmp[2]; 
118         /* Produkt ID */
119         if(!isset($tmp[3])){
120           $tmp[3] = "";
121         }
122         /* Vendor ID */
123         if(!isset($tmp[4])){
124           $tmp[4] = "";
125         }
127         $tmp2['produkt']     = $tmp[3]; 
128         $tmp2['vendor']      = $tmp[4];
130         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
131       }
132     }
134     /* prepare LogonScripts */
135     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
136       unset($this->attrs['gotoLogonScript']['count']);
137       foreach($this->attrs['gotoLogonScript'] as $device){
138         $tmp = $tmp2 = array();
139         $tmp = split("\|",$device);
140         $tmp2['LogonName']        = $tmp[0]; 
141         $tmp2['LogonPriority']    = $tmp[2]; 
142         if(preg_match("/O/i",$tmp[1])){
143           $tmp2['LogonOverload'] = "O";
144         }else{
145           $tmp2['LogonOverload'] = "";
146         }
147         if(preg_match("/L/i",$tmp[1])){
148           $tmp2['LogonLast'] = "L";
149         }else{
150           $tmp2['LogonLast'] = "";
151         }
152         $tmp2['LogonData']        = base64_decode($tmp[3]); 
153         $tmp2['LogonDescription'] = $tmp[4];
154         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
155       }
156     }
158     /* Prepare Shares */
159     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
160       unset($this->attrs['gotoShare']['count']);
161       foreach($this->attrs['gotoShare'] as $share){
162         $tmp = $tmp2 = array();
163         $tmp = split("\|",$share);
164         $tmp2['server']      =$tmp[0];
165         $tmp2['name']        =$tmp[1];
167         /* Decode base64 if needed */
168         if (!preg_match('%/%', $tmp[2])){
169           $tmp2['mountPoint']  =base64_decode($tmp[2]);
170         } else {
171           $tmp2['mountPoint']  =$tmp[2];
172         }
174         if(isset($tmp[3])){
175           $tmp2['PwdHash']  =$tmp[3];
176         }else{
177           $tmp2['PwdHash']  ="";
178         }
179         if(isset($tmp[4])){
180           $tmp2['Username']  =$tmp[4];
181         }else{
182           $tmp2['Username']  ="";
183         }
184         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
185       }
186     }
188     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
189       $chr = $this->gotoProfileFlags[$i];
190       $name = "gotoProfileFlag".$chr;
191       $this->$name=$chr;
192     }
194     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
195       $this->useProfile = true;
196     }else{
197       $this->useProfile = false;
198     }
200     /* Set resolutions */
201     $this->gotoXResolutions = array("auto"=>_("auto"),
202                                     "640x480"   =>  "640x480",
203                                     "800x600"   =>  "800x600",
204                                     "1024x768"  =>  "1024x768",
205                                     "1152x864"  =>  "1152x864",
206                                     "1280x768"  =>  "1280x768",
207                                     "1280x1024" =>  "1280x1024");
209     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
210       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
212       if(is_readable($file)){
213         $str = file_get_contents($file);
214         $lines = split("\n",$str);
215         foreach($lines as $line){
216           $line = trim($line);
217           if(!empty($line)){
218             $this->gotoXResolutions[$line]=$line;
219           }
220         }
221         //natcasesort($this->gotoXResolutions);
222       }else{
223         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
224       }
225     }
227     $this->gotoProfileServers= $config->getShareServerList() ;
228     $this->gotoShareSelections= $config->getShareList(true);
229     $this->gotoAvailableShares= $config->getShareList(false);  
231   }
234   /* Detect type of edited object (user|group)*/
235   function detect_grouptype()
236   {
237     if((!isset($this->parent))&&(!$this->is_account)){
238       $this->is_group     = false;
239     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
240       $this->is_group     = true;
241     }else{
242       $this->is_group     = false;
243     }
244   }
247   function execute()
248   {
249     /* Call parent execute */
250     plugin::execute();
252     $this->detect_grouptype();
254     /* Fill templating stuff */
255     $smarty= get_smarty();
256     $display= "";
258     /* Are we editing from MyAccount and not editing a user */
259     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
261     /* Prepare all variables for smarty */
262     foreach($this->attributes as $s_attr){
263       /* Set value*/
264       $smarty->assign($s_attr,$this->$s_attr);
266       /* Set checkbox state*/
267       if(empty($this->$s_attr)){
268         $smarty->assign($s_attr."CHK","");
269       }else{
270         $smarty->assign($s_attr."CHK"," checked ");
271       }
273       /* Prepare ACL settings*/
274       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
275     }
277     /* Is accout enabled | are we editing from usermenu or admin menu 
278        All these tab management is done here
279      */
282     /* Working from Usermenu an the Account is currently disbled
283      * this->parent :  is only set if we are working in a list of tabs
284      * is_account   :  is only true if the needed objectClass is given
285      */
286     if((!isset($this->parent))&&(!$this->is_account)){
287       /* We are currently editing this tab from usermenu, but this account is not enabled */
288       $smarty->assign("is_account",$this->is_account);
289       /* Load template */
290       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
291       /* Avoid the "You are currently editing ...." message when you leave this tab */
292       $display .= back_to_main(); 
293       /* Display our message to the user */
294       return $display;
297       /* We are currently editing from group tabs, because 
298        * $this->parent is set
299        * posixAccount is not set, so we are not in usertabs.
300        */
301     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
302       $smarty->assign("is_account","true");
303       $this->uid          = $this->cn;
304       $this->attrs['uid'] = $this->cn;
306       /* Change state if needed */
307       if (isset($_POST['modify_state'])){
308         if(($this->acl_is_createable() && !$this->is_account) || 
309             ($this->acl_is_removeable() &&  $this->is_account)){
310           $this->is_account= !$this->is_account;
311         }
312       }
313       /* Group Dialog with enabled environment options */
314       if ($this->is_account){
315         $display= $this->show_enable_header(_("Remove environment extension"),
316             _("Environment extension enabled. You can disable it by clicking below."));
317       } else {
319         /* Environment is disabled 
320            If theres is no posixAccount enabled, you won't be able to enable 
321            environment extensions
322          */
323         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
324           // 4. There is a PosixAccount
325           $display= $this->show_enable_header(_("Add environment extension"),
326               _("Environment extension disabled. You can enable it by clicking below."));
327           return $display;
328         }else{
329           // 4. There is no PosixAccount
330           $display= $this->show_enable_header(_("Add environment extension"),
331               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
332           return $display;
333         }
334       }
335     }else{
336       /* Editing from Usermenu 
337        *  Tell smarty that this accoutn is enabled 
338        */
339       $smarty->assign("is_account","true");
341       /* Change state if needed */
342       if (isset($_POST['modify_state'])){
343         if(($this->acl_is_createable() && !$this->is_account) || 
344             ($this->acl_is_removeable() &&  $this->is_account)){
345           $this->is_account= !$this->is_account;
346         }
347       }
349       if(isset($this->parent)){
351         // 3. Account enabled . Editing from adminmenu
352         if ($this->is_account){
353           $display= $this->show_disable_header(_("Remove environment extension"),
354               _("Environment extension enabled. You can disable it by clicking below."));
355         } else {
357           if($this->parent->by_object['posixAccount']->is_account==true){
358             // 4. There is a PosixAccount
359             $display= $this->show_disable_header(_("Add environment extension"),
360                 _("Environment extension disabled. You can enable it by clicking below."));
361             return $display;
362           }else{
363             // 4. There is a PosixAccount
364             $display= $this->show_disable_header(_("Add environment extension"),
365                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
366             return $display;
367           }
368         }
369       }
370     }
371     /* Account is Account : is_accounbt=true.
372      * Else we won't reach this. 
373      */
375     /* Prepare all variables for smarty */
376     foreach($this->attributes as $s_attr){
377       /* Set value*/
378       $smarty->assign($s_attr,$this->$s_attr);
380       /* Set checkbox state*/
381       if(empty($this->$s_attr)){
382         $smarty->assign($s_attr."CHK","");
383       }else{
384         $smarty->assign($s_attr."CHK"," checked ");
385       }
387       /* Prepare ACL settings*/
388       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
389     }
391     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
392       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
393     }
395     if($WriteOnly) {
396       $smarty->assign("gotoPrinterACL","r");
397     }else{
398       $smarty->assign("gotoPrinterACL","rw");
399     }
401     if(empty($this->useProfile)){
402       $smarty->assign("useProfileCHK","");
403       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
404       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
405       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
406     }else{
407       $smarty->assign("useProfileCHK"," checked ");
408     }
411     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
413     /* HANDLE Profile Settings here 
414      * Assign available Quota and resolution settings
415      * Get all available profile server
416      * Get cache checkbox
417      * Assign this all to Smarty 
418      */
420     if(empty($this->gotoProfileFlagL)){
421       $smarty->assign("gotoProfileFlagLCHK"," ");
422     }else{
423       $smarty->assign("gotoProfileFlagLCHK"," checked ");
424     }
426     if(empty($this->gotoProfileFlagC)){
427       $smarty->assign("gotoProfileFlagCCHK"," ");
428     }else{
429       $smarty->assign("gotoProfileFlagCCHK"," checked ");
430     }
433     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
434     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
436     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
437     if(!is_array($this->gotoProfileServers)){
438       $this->gotoProfileServers =array();
439     }
440     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
442     /* Handle kiosk profiles 
443      * Read available from filesystem
444      * Open management if post is transmitted
445      */
447     /* Save */
448     if(isset($_POST['KioskClose'])){
449       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
451       unset($this->dialog);
452       $this->dialog=NULL;
453       $this->is_dialog = false;
454     }
456     /* Reassign help class */
457     $_SESSION['current_class_for_help'] = get_class($this);
459     /* Open Management Dialog */
460     if(isset($_POST['KioskManagementDialog'])){
461       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
462       $this->dialog->parent= $this;
463       $this->dialog->acl = $this->acl;
464       $this->is_dialog = true;
465     }
466     $tmp = new kioskManagementDialog($this->config,$this->dn);
467     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
468     $list['none']=_("None");
469     $list = array_reverse($list);
470     $smarty->assign("gotoKioskProfiles",$list);
471     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
473     /* Logonscript Management
474      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
475      * Perform add Delete edit Posts 
476      */
478     /* Dialog Save */
479     if(isset($_POST['LogonSave'])){
481       if(!$this->acl_is_writeable("gotoLogonScript")){
482         print_red(_("You are not allowed to write Logon scripts."));
483         unset($this->dialog);
484         $this->dialog=NULL;
485         $this->is_dialog=false;
486       }else{
487         $this->dialog->save_object();
488         if(count($this->dialog->check())!=0){
489           foreach($this->dialog->check() as $msg){
490             print_red($msg);
491           }
492         }else{
493           $tmp = $this->dialog->save();
494           unset($this->dialog);
495           $this->dialog=NULL;
496           $this->is_dialog=false;
497           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
498         }
499       }
500     }
501     
503     /* Dialog Quit without saving */
504     if(isset($_POST['LogonCancel'])){
505       $this->is_dialog= false;
506       unset($this->dialog);
507       $this->dialog= NULL;
508     }
510     /* Check Edit Del New Posts for a selected LogonScript */ 
511     if($this->acl_is_writeable("gotoLogonScript") && 
512         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
514       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
515        * In this case we create a new Logon Script.
516        */
517       if(isset($_POST['gotoLogonScriptNew'])){
518         $this->is_dialog = true;
519         $this->dialog = new logonManagementDialog($this->config,$this->dn);
520       }
522       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
523        * We only can delete if there is an entry selected.
524        */
525       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
526         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
527       }
529       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
530        * There must be an entry selected to perform edit request.
531        */
532       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
533         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
534         $this->is_dialog = true;
535         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
536       }
537     }
539     /* Append List to smarty*/
540     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
541     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
543     /* In this section server shares will be defined 
544      * A user can select one of the given shares and a mount point
545      *  and attach this combination to his setup.
546      */
548     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
549     if(!is_array($this->gotoShareSelections)){
550       print $this->gotoShareSelections;
551       $this->gotoShareSelections = array();
552     }
553     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
555     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
556      * This entry will be, a combination of mountPoint and sharedefinitions 
557      */
558     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
559       /* We assign a share to this user, if we don't know where to mount the share */
560       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
561         print_red(_("You must specify a valid mount point."));
562       }elseif(!(
563             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
564             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
565             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
566             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
567             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
568             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
569             preg_match("/^%/",$_POST['gotoShareMountPoint'])
570             )
571           ){
572         print_red(_("You must specify a valid mount point.")); 
573       }else{
574         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
575         $s_mount = $_POST['gotoShareMountPoint'];
576         $s_user  = $_POST['ShareUser'];
577         /* Preparing the new assignment */ 
578         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
579         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
580         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
581         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
582       }
583     }  
585     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
586      * If there is no defined share selected, we will abort the deletion without any message 
587      */
588     $once = true;
589     if($this->acl_is_writeable("gotoShare")){
590       foreach($_POST as $name => $value){
591         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
592           $once = false;  
593           $key  = preg_replace("/^gotoShareDel_/","",$name);
594           $key  = preg_replace("/_+[xy]$/","",$key);
595           $key  = base64_decode($key);
596           if(isset($this->gotoShares[$key])) {
597             unset($this->gotoShares[$key]);
598           }
600           /* Remove corresponding password entry, too. This is a workaround
601              to get rid of old-style entries. */
602           $key= preg_replace("/\|/", "|!", $key);
603           if(isset($this->gotoShares[$key])) {
604             unset($this->gotoShares[$key]);
605           }
606         }
607         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
608           $once = false;
609           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
610           $key  = preg_replace("/_+[xy]$/","",$key);
611           $key  = base64_decode($key);
612           $this->gotoShares[$key]['PwdHash'] = "";
613           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
614             unset($this->gotoShares[$key]);
615           }
616         }
617       }
618     }
619     $divlistShares = new divSelectBox("gotoShares");
620     $divlistShares->SetHeight(100);
621     $tmp = $this->printOutAssignedShares();
623     foreach($tmp as $key => $value){
624       $img = "";
626       /* Check if entry starts with an ! */
627       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
629         /* If we are currently editing groups environment, skip those ! entries */ 
630         if($this->is_group) continue;
632         /* Create pwd reset images */
633         if($this->gotoShares[$key]['PwdHash'] != ""){
634           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
635             title='"._("Reset password hash")."'>";
636         }
637         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
638         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
639       }else{
641         /* Create pwd reset img && delete image */
642         if($this->gotoShares[$key]['PwdHash'] != ""){
643           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
644             title='"._("Reset password hash")."'>";
645           $img.= "&nbsp;";
646         }
647         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
648           title='"._("Delete share entry")."'>";
649         $field1 = array("string" => $value);
650         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
651       }
652       $divlistShares->AddEntry(array($field1,$field2));
653     }
654     $smarty->assign("divlistShares",$divlistShares->DrawList());
656     /* Hotplug devices will be handled here 
657      * There are 3 possible methods for this feature
658      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
659      * Delete will erase an entry, the entry must be selcted in the ListBox first
660      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
661      */
663     /* If there is a new entry wanted, open a new entry by initilising the dialog */
664     if((isset($_POST['gotoHotplugDeviceNew'])) && ($this->acl_is_writeable("gotoHotplugDevice"))){
665       $this->dialog = new hotplugDialog($this->config,$this->dn);
666       $this->is_dialog = true;
667     }
669     /* We have to delete the selected hotplug from the list*/
670     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice'])) && $this->acl_is_writeable("gotoHotplugDevice")){
671       if($this->acl_is_writeable("gotoHotplugDevice")){
672         foreach($_POST['gotoHotplugDevice'] as $name){
673           unset($this->gotoHotplugDevices[$name]);
674         }
675       }
676     }
678     /* There are already defined hotplugs from other users we could use */
679     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
680       $tmp  =array();
681       foreach($this->gotoHotplugDevices as $plugs){
682         $tmp[] = $plugs['name'];
683       }
684       $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
685       $this->is_dialog = true;
686     }
688     /* Dialog Aborted */
689     if(isset($_POST['HotPlugCancel'])){
690       unset($this->dialog);
691       $this->dialog= NULL;
692       $this->is_dialog = false;
693     }
695     /* Dialod saved */
696     if(isset($_POST['HotPlugSave'])){
698       $this->dialog->save_object();
699       if(count($this->dialog->check())!=0){
700         foreach($this->dialog->check() as $msg){
701           print_red($msg);
702         }
703       }else{
704         $this->dialog->save_object();
705         $a_tmp = $this->dialog->save();
707         if(is_array($a_tmp)){
708           foreach($a_tmp as $name => $hotplug){
709             $this->gotoHotplugDevices[$name]= $hotplug; 
710           }
711         }
712         unset($this->dialog);
713         $this->dialog= NULL;
714         $this->is_dialog = false;
715       }
716     }
717     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
718     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
720     /* Printer Assignment will managed below 
721      * A printer can be assigned in two different ways and two different types
722      * There are 2 types of users assigned to a printer : user and admin
723      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
724      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
725      */ 
727     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
728     if(isset($_POST['gotoPrinterAdd'])){
730       $this->is_dialog=true;
731       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
732     }
734     if(isset($_POST['PrinterCancel'])){
735       $this->is_dialog=false;
736       unset($this->dialog);
737       $this->dialog=NULL;
738     }
740     if(isset($_POST['PrinterSave'])){
741       if(count($this->dialog->check())!=0){
742         $tmp = $this->dialog->check();
743         foreach($tmp as $msg){
744           print_red($msg);
745         } 
746       }else{
747         $this->dialog->save_object();
748         $tmp = $this->dialog->save();
749         $tmp2= $this->dialog->getPrinter(true);
751         foreach($tmp as $pname){
752         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn']);
753           if($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
754             $this->gotoPrinter[$pname]=$tmp2[$pname];
755             $this->gotoPrinter[$pname]['mode']="user";
756             $this->add_del_printer_member_was_called = true;
757           }
758         }
760         $this->is_dialog=false;
761         unset($this->dialog);
762         $this->dialog   =NULL;
763       }
764     }
766     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
767       $printer = $_POST['gotoPrinterSel'];
768       foreach($printer as $pname){
770         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn']);
771         if($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->dn)){
772           unset($this->gotoPrinter[$pname]);
773           $this->add_del_printer_member_was_called = true;
774         }
775       }
776     }
778     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
781       $printers = $_POST['gotoPrinterSel'];
783       foreach($printers as $printer){
784         if($this->gotoPrinter[$printer]['mode']=="user"){
785           $this->gotoPrinter[$printer]['mode']="admin";
786         }else{
787           $this->gotoPrinter[$printer]['mode']="user";
788         }
789       }
790     }
792     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
793       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
794         $this->gosaDefaultPrinter= "";
795       } else {
796         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
797       }
798     }
800     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
801     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
803     /* General behavior */
804     if($this->acl_is_writeable("gotoKioskProfile")){
805     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
806       $this->dialog->save_object();
807       $disp =$this->dialog->execute();
809       $tmp = new kioskManagementDialog($this->config,$this->dn);
810       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
811       $list['none']=_("None");
812       $list = array_reverse($list);
813       if(!isset($list[$this->gotoKioskProfile])){
814         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
815         $this->gotoKioskProfile = 'none';
816       }
817       return($disp);
818       }
819     }
821     /* Als smarty vars are set. Get smarty template and generate output */
822     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
823     return($display);
824   }
826   function remove_from_parent()
827   {
828     /* only if it was an account*/
829     if (!$this->initially_was_account){
830       return;
831     }
833     /* include global link_info */
834     $ldap= $this->config->get_ldap_link();
836     /* Remove and write to LDAP */
837     plugin::remove_from_parent();
839     /* Don't save our template variables */
840     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
842     /* Skip all these attributes */
843     foreach($skip as $del){
844       unset($this->attrs[$del]);
845     }
847     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
849     $ldap->cd($this->dn);
850     $this->cleanup();
851     $ldap->modify ($this->attrs); 
853     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
855     /* Optionally execute a command after we're done */
856     $this->handle_post_events("remove");
857   }
860   /* Save data to object */
861   function save_object()
862   {
863     /* Get all Posted vars 
864      * Setup checkboxes 
865      */
866     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
867     if(isset($_POST['iamposted'])){
869       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
871       if(preg_match("/w/",$PACL)){
872         if(isset($_POST['useProfile'])){
873           $this->useProfile = true;
874         }else{
875           $this->useProfile = false;
876         }
877       }
879       if($this->acl_is_writeable("gotoProfileFlagC")){
880         if(isset($_POST['gotoProfileFlagC'])){
881           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
882         }else{
883           $this->gotoProfileFlagC = false;
884         }
885       }
887       if($this->acl_is_writeable("gotoProfileFlagL")){
888         if(isset($_POST['gotoProfileFlagL'])){
889           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
890         }else{
891           $this->gotoProfileFlagL = false;
892         }
893       }
895       plugin::save_object();
896       foreach($this->attributes as $s_attr){
897         if((!isset($_POST[$s_attr])) || 
898             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
899         if(!$this->acl_is_writeable($s_attr)){
900           continue;
901         }else{ 
902           if(isset($_POST[$s_attr])){
903             $this->$s_attr = $_POST[$s_attr];
904           }else{
905             $this->$s_attr = false;
906           }
907         }
908       }
909     }
910   }
913   /* Check supplied data */
914   function check()
915   {
916     /* Call common method to give check the hook */
917     $message= plugin::check();
919     $this->detect_grouptype();
921     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
922       $message[]=_("Please set a valid profile quota size.");
923     } 
924     if(!isset($this->attrs['objectClass'])){
925       $this->attrs['objectClass']=array();
926     } 
927     if(!$this->is_group){
928       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
929         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
930       }
931     }
932     return ($message);
933   }
936   /* Save to LDAP */
937   function save()
938   {
939     /* If group was renamed, all printer settings get lost
940      */ 
941     /* only save changed variables ....*/
942     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
943     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
944       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
945         $method="https://";
946       }else{
947         $method="http://";
948       }
950       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
951       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
952     }else{
953       $this->gotoKioskProfile= array();
954     }
956     plugin::save();
957     $ldap= $this->config->get_ldap_link();
959     $realyUsedAttrs= array();
961     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
962     /* Creating Kiosk Profiles */
963     foreach($this->newKioskProfiles as $file){
964       $contents = $file['contents'];
965       $fp = @fopen($path."/".$file['name'],"w");
966       if(!$fp){
967         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
968       }else{
969         fwrite($fp,$contents,strlen($contents));
970       }
971       @unlink($file['tmp_name']);
972     }
974     /* Save already used objectClasses */
975     $ocs        = $this->attrs['objectClass'];
976     unset($ocs['count']);
977     $this->attrs = array();
978     $this->attrs['objectClass']= $ocs;
979     foreach($this->objectclasses as $objc){
980       if(!in_array($objc,$this->attrs['objectClass'])){
981         $this->attrs['objectClass'][]=$objc;
982       }
983     }
985     /* 1. Search all printers that have our uid/cn as member 
986      * 2. Delete this uid/cn from every single entry and save it again.
987      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
988      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
989      */
990     
991     $this->detect_grouptype();
993     if($this->add_del_printer_member_was_called){
995       $types = array( "gotoUserPrinter"       => "AddUser",
996           "gotoGroupPrinter"      => "AddGroup",
997           "gotoUserAdminPrinter"  => "AddAdminUser",
998           "gotoGroupAdminPrinter" => "AddAdminGroup");
1000       if($this->is_group){
1001         $s_suffix = "Group";
1002         $useVar   = "cn";
1003       }else{
1004         $useVar   = "uid";
1005         $s_suffix = "User";
1006       }
1008       /* Remove old entries */
1009       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
1010       while($attr = $ldap->fetch()){
1011         $printerObj = NULL;
1012         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1013         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
1014         $printerObj->by_object['printgeneric']->save();
1015       }
1017       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
1018       while($attr = $ldap->fetch()){
1019         $printerObj = NULL;
1020         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1021         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
1022         $printerObj->by_object['printgeneric']->save();
1023       }
1025       foreach($this->gotoPrinter as $printer){
1026         $printerObj = NULL;
1027         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1029         if($printer['mode'] == "admin") {
1030           $attribute = "goto".$s_suffix."AdminPrinter";
1031         }else{
1032           $attribute = "goto".$s_suffix."Printer";
1033         }
1035         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1036         $printerObj->by_object['printgeneric']->save();
1037       }
1038     }    
1040     /* Prepare HotPlug devices */
1041     $this->attrs['gotoHotplugDevice'] = array();
1042     foreach($this->gotoHotplugDevices as $name => $device){
1043       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1044         "|".$device['produkt']."|".$device['vendor'];
1045     }
1047     /* Prepare LogonScripts */
1048     $this->attrs['gotoLogonScript'] = array();
1049     foreach($this->gotoLogonScripts as $name => $script){
1050       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1051         $script['LogonOverload'].$script['LogonLast']."|".
1052         $script['LogonPriority']."|".
1053         base64_encode($script['LogonData'])."|".
1054         $script['LogonDescription'];
1055     }
1057     /* Prepare Shares */
1058     $this->attrs['gotoShare']=array();
1059     foreach($this->gotoShares as $name => $share){
1060       $mntp= $share['mountPoint'];
1061       if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1062         $mntp= base64_encode($mntp);
1063       }
1064       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1065     }
1068     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1069     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1071     foreach($saveThis as $tosave){
1072       if(!empty($this->$tosave)){
1073         $this->attrs[$tosave]=$this->$tosave;
1074       }else{
1075         $this->attrs[$tosave]=array();
1076       }
1077     }
1079     /* Prepare Flags */
1080     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1081     if(empty($this->attrs['gotoProfileFlags'][0])){
1082       $this->attrs['gotoProfileFlags']=array();
1083     }
1085     if($this->useProfile == false){
1086       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1087       $this->attrs['gotoProfileServer']= array(); 
1088     }
1090     $ldap->cat ($this->dn, array('dn'));
1091     if ($ldap->fetch()){
1092       $mode= "modify";
1093     } else {
1094       $mode= "add";
1095       $ldap->cd($this->config->current['BASE']);
1096       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1097     }
1099     $ldap->cd($this->dn);
1100     $this->cleanup();
1101     $ldap->$mode($this->attrs);
1102     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1103     $this->handle_post_events($mode);
1104   }
1106   /* Generate ListBox frindly output for the defined shares 
1107    * Possibly Add or remove an attribute here, 
1108    */
1109   function printOutAssignedShares()
1110   {
1111     $a_return = array();
1112     if(is_array($this->gotoShares)){
1113       foreach($this->gotoShares as $share){
1114         if(preg_match("/^!/",$share['server'])){
1115           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1116         }else{
1117           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1118         }
1119       }
1120       natcasesort($a_return);
1121     }
1122     return($a_return);
1123   }
1125   /* Generate ListBox frindly output for the definedhotplugs 
1126    * Possibly Add or remove an attribute here,
1127    */
1128   function printOutHotPlugDevices()
1129   {
1130     $a_return= array();
1131     if(is_array($this->gotoHotplugDevices)){
1132       foreach($this->gotoHotplugDevices as $key=>$device){
1133         $a_return[$key] = $device['name']." - ".$device['id'];
1134       }
1135     }
1136     return($a_return);
1137   }
1139   /* Generates ListBox frienly output of used printer devices 
1140    * Append ' - admin' if printer is used in admin mode
1141    */
1142   function printOutPrinterDevices()
1143   {
1144     $a_return = array();
1145     if(is_array($this->gotoPrinter)){
1146       foreach($this->gotoPrinter as $printer){
1147         if($printer['mode'] == "admin"){
1148           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1149         }else{
1150           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1151         }
1152         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1153           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1154         }
1155       }
1156     }
1157     return($a_return);
1158   }
1160   /* Generates ListBox frienly output of used logonscripts 
1161    */
1162   function printOutLogonScripts()
1163   {
1164     $a_return = array();
1165     if(is_array($this->gotoLogonScripts)){
1166       foreach($this->gotoLogonScripts as $script){
1167         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1168       }
1169     }
1170     return($a_return);
1171   }
1174   /* Return plugin informations for acl handling 
1175 #FIXME these ACLs should work for groups too */ 
1176   function plInfo()
1177   {
1178     return (array("plShortName"     => _("Environment"),
1179           "plDescription"   => _("Environment settings"),         // Description
1180           "plSelfModify"    => TRUE,                              
1181           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1182           "plPriority"      => 2,                                 // Position in tabs 
1183           "plSection"       => "personal",                        // This belongs to personal
1184           "plCategory"      => array("users", "groups"),          // Add to following categories 
1185           "plOptions"       => array("resolution_hook" => array("type" => "string",
1186               "description" => _("Command to extend the list of possible screen resolutions"))),
1188           "plProvidedAcls"  => array(
1190             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1191             "gotoProfileFlagC"    => _("Cache profile localy") ,
1193             "gotoProfileQuota"    => _("Profile quota") ,
1194             "gotoProfileServer"   => _("Profile server") ,
1196             "gotoXResolution"     => _("Resolution") ,
1197             "gotoKioskProfile"    => _("Kiosk profile") ,
1199             "gosaDefaultPrinter"  => _("Default printer") ,
1200             "gotoLogonScript"     => _("Logon script") ,
1201             "gotoHotplugDevice"   => _("Hotplug devices"),
1202             "gotoShare"           => _("Shares"))
1203             ));
1204   }
1207 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1208 ?>