Code

2f55230ef965415fd09cb6a0170ed40ae0180145
[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 $gotoProfileFlag_C  = "";     // 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 $gotoProfileFlag_L  = "";     // 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
50   
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","gotoProfileFlag_L","gotoXResolutions","gotoProfileFlag_C","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDevice",
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;
77   function environment ($config, $dn= NULL, $parent= NULL)
78   {
79     plugin::plugin ($config, $dn, $parent);
81     /* Check : Are we currently editing a group or user dialog */
82     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
83       $suffix="Group";
84       $this->uid          = $this->attrs['cn'][0];
85       $this->attrs['uid'] = $this->attrs['cn'][0];
86       $this->OrigCn = $this->attrs['cn'][0];
87     }else{
88       $suffix="User";
89     }
91     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
93     /* Get all Printer assignments */
94     $ldap = $this->config->get_ldap_link();
95     $ldap->cd($this->config->current['BASE']);
96     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
97     while($printer = $ldap->fetch()){
98       $this->gotoPrinter[$printer['cn'][0]]=$printer;
99       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
100     }
101     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
102     while($printer = $ldap->fetch()){
103       $this->gotoPrinter[$printer['cn'][0]]=$printer;
104       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
105     }
106   
107     /* prepare hotplugs */
108     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
109       unset($this->attrs['gotoHotplugDevice']['count']);
110       foreach($this->attrs['gotoHotplugDevice'] as $device){
111         $tmp = $tmp2 = array();
112         $tmp = split("\|",$device);
113         $tmp2['name']        = $tmp[0]; 
114         $tmp2['description'] = $tmp[1]; 
115         $tmp2['id']          = $tmp[2]; 
116         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
117       }
118     }
119     
120     /* prepare LogonScripts */
121     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
122       unset($this->attrs['gotoLogonScript']['count']);
123       foreach($this->attrs['gotoLogonScript'] as $device){
124         $tmp = $tmp2 = array();
125         $tmp = split("\|",$device);
126         $tmp2['LogonName']        = $tmp[0]; 
127         $tmp2['LogonPriority']    = $tmp[2]; 
128         if(preg_match("/O/i",$tmp[1])){
129           $tmp2['LogonOverload'] = "O";
130         }else{
131           $tmp2['LogonOverload'] = "";
132         }
133         if(preg_match("/L/i",$tmp[1])){
134           $tmp2['LogonLast'] = "L";
135         }else{
136           $tmp2['LogonLast'] = "";
137         }
138         $tmp2['LogonData']        = base64_decode($tmp[3]); 
139         $tmp2['LogonDescription'] = $tmp[4];
140         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
141       }
142     }
143     
144     /* Prepare Shares */
145     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
146       unset($this->attrs['gotoShare']['count']);
147       foreach($this->attrs['gotoShare'] as $share){
148         $tmp = $tmp2 = array();
149         $tmp = split("\|",$share);
150         $tmp2['server']      =$tmp[0];
151         $tmp2['name']        =$tmp[1];
152         
153         /* Decode base64 if needed */
154         if (!preg_match('%/%', $tmp[2])){
155           $tmp2['mountPoint']  =base64_decode($tmp[2]);
156         } else {
157           $tmp2['mountPoint']  =$tmp[2];
158         }
160         if(isset($tmp[3])){
161           $tmp2['PwdHash']  =$tmp[3];
162         }else{
163           $tmp2['PwdHash']  ="";
164         }
165         if(isset($tmp[4])){
166           $tmp2['Username']  =$tmp[4];
167         }else{
168           $tmp2['Username']  ="";
169         }
170         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
171       }
172     }
174     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
175       $chr = $this->gotoProfileFlags[$i];
176       $name = "gotoProfileFlag_".$chr;
177       $this->$name=$chr;
178     }
180     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
181       $this->useProfile = true;
182     }else{
183       $this->useProfile = false;
184     }
186     /* Set resolutions */
187     $this->gotoXResolutions = array("auto"=>_("auto"),
188                                     "640x480"   =>  "640x480",
189                                     "800x600"   =>  "800x600",
190                                     "1024x768"  =>  "1024x768",
191                                     "1152x864"  =>  "1152x864",
192                                     "1280x768"  =>  "1280x768",
193                                     "1280x1024" =>  "1280x1024");
195     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
196       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
197   
198       if(is_readable($file)){
199         $str = file_get_contents($file);
200         $lines = split("\n",$str);
201         foreach($lines as $line){
202           $line = trim($line);
203           if(!empty($line)){
204             $this->gotoXResolutions[$line]=$line;
205           }
206         }
207         //natcasesort($this->gotoXResolutions);
208       }else{
209         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
210       }
211     }
213  
214     $this->gotoProfileServers= $config->getShareServerList() ;
215     $this->gotoShareSelections= $config->getShareList(true);
216     $this->gotoAvailableShares= $config->getShareList(false);  
218   }
221   /* Detect type of edited object (user|group)*/
222   function detect_grouptype()
223   {
224     if((!isset($this->parent))&&(!$this->is_account)){
225       $this->is_group     = false;
226     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
227       $this->is_group     = true;
228     }else{
229       $this->is_group     = false;
230     }
231   }
234   function execute()
235   {
236         /* Call parent execute */
237         plugin::execute();
239   /* Fill templating stuff */
240   $smarty= get_smarty();
241   $display= "";
243   /* Prepare all variables for smarty */
244   foreach($this->attributes as $s_attr){
245     /* Set value*/
246     $smarty->assign($s_attr,$this->$s_attr);
248     /* Set checkbox state*/
249     if(empty($this->$s_attr)){
250       $smarty->assign($s_attr."CHK","");
251     }else{
252       $smarty->assign($s_attr."CHK"," checked ");
253     }
255     /* Prepare ACL settings*/
256     if(chkacl($this->acl,$s_attr)=="") {
257       $smarty->assign($s_attr."ACL","");
258     }else{
259       $smarty->assign($s_attr."ACL"," disabled ");
260     }
262   }
264   /* Is accout enabled | are we editing from usermenu or admin menu 
265      All these tab management is done here
266    */
268   $this->detect_grouptype();
270   /* Working from Usermenu an the Account is currently disbled
271      * this->parent :  is only set if we are working in a list of tabs
272      * is_account   :  is only true if the needed objectClass is given
273     */
274     if((!isset($this->parent))&&(!$this->is_account)){
275       /* We are currently editing this tab from usermenu, but this account is not enabled */
276       $smarty->assign("is_account",$this->is_account);
277       /* Load template */
278       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
279       /* Avoid the "You are currently editing ...." message when you leave this tab */
280       $display .= back_to_main(); 
281       /* Display our message to the user */
282       return $display;
283     
285     /* We are currently editing from group tabs, because 
286      * $this->parent is set
287      * posixAccount is not set, so we are not in usertabs.
288      */
289     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
290       $smarty->assign("is_account","true");
291       $this->uid          = $this->cn;
292       $this->attrs['uid'] = $this->cn;
294       /* Change state if needed */
295       if (isset($_POST['modify_state'])){
296         $this->is_account= !$this->is_account;
297       }
299       /* Group Dialog with enabled environment options */
300       if ($this->is_account){
301         $display= $this->show_header(_("Remove environment extension"),
302             _("Environment extension enabled. You can disable it by clicking below."));
303       } else {
304   
305       /* Environment is disabled 
306          If theres is no posixAccount enabled, you won't be able to enable 
307          environment extensions
308        */
309         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
310           // 4. There is a PosixAccount
311           $display= $this->show_header(_("Add environment extension"),
312               _("Environment extension disabled. You can enable it by clicking below."));
313           return $display;
314         }else{
315           // 4. There is no PosixAccount
316           $display= $this->show_header(_("Add environment extension"),
317               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
318           return $display;
319         }
320       }
321     }else{
322       /* Editing from Usermenu 
323        *  Tell smarty that this accoutn is enabled 
324        */
325       $smarty->assign("is_account","true");
328       /* Do we need to flip is_account state? */
329       if (isset($_POST['modify_state'])){
330         $this->is_account= !$this->is_account;
331       }
333       if(isset($this->parent)){
335         // 3. Account enabled . Editing from adminmenu
336         if ($this->is_account){
337           $display= $this->show_header(_("Remove environment extension"),
338               _("Environment extension enabled. You can disable it by clicking below."));
339         } else {
341           if($this->parent->by_object['posixAccount']->is_account==true){
342             // 4. There is a PosixAccount
343             $display= $this->show_header(_("Add environment extension"),
344                 _("Environment extension disabled. You can enable it by clicking below."));
345             return $display;
346           }else{
347             // 4. There is a PosixAccount
348             $display= $this->show_header(_("Add environment extension"),
349                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
350             return $display;
351           }
352         }
353       }
354     }
355     /* Account is Account : is_accounbt=true.
356      * Else we won't reach this. 
357      */
358    
359     /* Prepare all variables for smarty */
360     foreach($this->attributes as $s_attr){
361       /* Set value*/
362       $smarty->assign($s_attr,$this->$s_attr);
363      
364       /* Set checkbox state*/
365       if(empty($this->$s_attr)){
366         $smarty->assign($s_attr."CHK","");
367       }else{
368         $smarty->assign($s_attr."CHK"," checked ");
369       }
370     
371       /* Prepare ACL settings*/
372       if(chkacl($this->acl,$s_attr)=="") {
373         $smarty->assign($s_attr."ACL","");
374       }else{
375         $smarty->assign($s_attr."ACL"," disabled ");
376       }
377  
378     }
380     foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
381       if(chkacl($this->acl,$s_attr)=="") {
382         $smarty->assign($s_attr."ACL","");
383       }else{
384         $smarty->assign($s_attr."ACL"," disabled ");
385       }
386     }
388     if(empty($this->useProfile)){
389       $smarty->assign("gotoProfileACL","disabled");
390       $smarty->assign("useProfileCHK","");
391     }else{
392       $smarty->assign("gotoProfileACL","");
393       $smarty->assign("useProfileCHK"," checked ");
394     }
396  
397     $smarty->assign("useProfileACL","");
398     if($this->acl != "#none#"){
399       $smarty->assign("useProfileACL","");
400       $smarty->assign("gotoProfileFlag_CACL"," ");
401       $smarty->assign("gotoProfileQuotaACL"," ");
402     }else{
403       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
404       $smarty->assign("useProfileACL","disabled");
405       $smarty->assign("gotoProfileServer"," disabled ");
406       $smarty->assign("gotoProfileQuotaACL"," disabled ");
407     }
409     /* HANDLE Profile Settings here 
410      * Assign available Quota and resolution settings
411      * Get all available profile server
412      * Get cache checkbox
413      * Assign this all to Smarty 
414      */
416     if(empty($this->gotoProfileFlag_L)){
417       $smarty->assign("gotoProfileFlag_LCHK"," ");
418     }else{
419       $smarty->assign("gotoProfileFlag_LCHK"," checked ");
420     }
422     if(empty($this->gotoProfileFlag_C)){
423       $smarty->assign("gotoProfileFlag_CCHK"," ");
424     }else{
425       $smarty->assign("gotoProfileFlag_CCHK"," checked ");
426     }
429     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
430     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
432     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
433     if(!is_array($this->gotoProfileServers)){
434       $this->gotoProfileServers =array();
435     }
436     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
438     /* Handle kiosk profiles 
439      * Read available from filesystem
440      * Open management if post is transmitted
441      */
443     /* Save */
444     if(isset($_POST['KioskClose'])){
445       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
446   
447       unset($this->dialog);
448       $this->dialog=NULL;
449       $this->is_dialog = false;
450     }
452     /* Reassign help class */
453     $_SESSION['current_class_for_help'] = get_class($this);
454  
455     /* Open Management Dialog */
456     if(isset($_POST['KioskManagementDialog'])){
457       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
458       $this->dialog->parent= $this;
459       $this->dialog->acl = $this->acl;
460       $this->is_dialog = true;
461     }
462     $tmp = new kioskManagementDialog($this->config,$this->dn);
463     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
464     $list['none']=_("None");
465     $list = array_reverse($list);
466     $smarty->assign("gotoKioskProfiles",$list);
467     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
469     /* Logonscript Management
470      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
471      * Perform add Delete edit Posts 
472      */
474     /* Dialog Save */
475     if(isset($_POST['LogonSave'])){
476       $this->dialog->save_object();
477       if(count($this->dialog->check())!=0){
478         foreach($this->dialog->check() as $msg){
479           print_red($msg);
480         }
481       }else{
482         $tmp = $this->dialog->save();
483         unset($this->dialog);
484         $this->dialog=NULL;
485         $this->is_dialog=false;
486         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
487       }
488     }
489     
490     /* Dialog Quit without saving */
491     if(isset($_POST['LogonCancel'])){
492       $this->is_dialog= false;
493       unset($this->dialog);
494       $this->dialog= NULL;
495     }
496    
497     /* Check Edit Del New Posts for a selected LogonScript */ 
498     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
500       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
501        * In this case we create a new Logon Script.
502        */
503       if(isset($_POST['gotoLogonScriptNew'])){
504         $this->is_dialog = true;
505         $this->dialog = new logonManagementDialog($this->config,$this->dn);
506       }
508       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
509        * We only can delete if there is an entry selected.
510        */
511       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
512         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
513       }
514       
515       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
516        * There must be an entry selected to perform edit request.
517        */
518       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
519         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
520         $this->is_dialog = true;
521         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
522       }
523     }
524      
525     /* Append List to smarty*/
526     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
527     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
529     /* In this section server shares will be defined 
530      * A user can select one of the given shares and a mount point
531      *  and attach this combination to his setup.
532      */
533     
534     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
535     if(!is_array($this->gotoShareSelections)){
536       print $this->gotoShareSelections;
537       $this->gotoShareSelections = array();
538     }
539     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
541     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
542      * This entry will be, a combination of mountPoint and sharedefinitions 
543      */
544     if(isset($_POST['gotoShareAdd'])){
545       /* We assign a share to this user, if we don't know where to mount the share */
546       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
547         print_red(_("You must specify a valid mount point."));
548       }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
549         print_red(_("Spaces are not allowed in the mount path!"));
550       }elseif(!(
551         preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
552         preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
553         preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
554         preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
555         preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
556         preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
557         preg_match("/^%/",$_POST['gotoShareMountPoint'])
558         )
559       ){
560         print_red(_("You must specify a valid mount point.")); 
561       }else{
562         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
563         $s_mount = $_POST['gotoShareMountPoint'];
564         $s_user  = $_POST['ShareUser'];
565         /* Preparing the new assignment */ 
566         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
567         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
568         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
569         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
570       }
571     }  
573     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
574      * If there is no defined share selected, we will abort the deletion without any message 
575      */
576     $once = true;
577     foreach($_POST as $name => $value){
578       if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
579         $once = false;  
580         $key  = preg_replace("/^gotoShareDel_/","",$name);
581         $key  = preg_replace("/_+[xy]$/","",$key);
582         $key  = base64_decode($key);
583         if(isset($this->gotoShares[$key])) {
584           unset($this->gotoShares[$key]);
585         }
587         /* Remove corresponding password entry, too. This is a workaround
588            to get rid of old-style entries. */
589         $key= base64_decode($key);
590         if(isset($this->gotoShares[$key])) {
591           unset($this->gotoShares[$key]);
592         }
594       }
595       if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
596         $once = false;
597         $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
598         $key  = preg_replace("/_+[xy]$/","",$key);
599         $key  = base64_decode($key);
600         $this->gotoShares[$key]['PwdHash'] = "";
601         if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
602           unset($this->gotoShares[$key]);
603         }
604       }
605     }
607     $divlistShares = new divSelectBox("gotoShares");
608     $divlistShares->SetHeight(100);
609     $tmp = $this->printOutAssignedShares();
610     
611     
612     foreach($tmp as $key => $value){
613       $img = "";
614    
615       $hide       = false;    
616       $background = "";
617       if(chkacl($this->acl,"gotoShare") != ""){
618         $background = "background: #D0D0D0; ";
619         $hide = true;    
620       }
622       /* Check if entry starts with an ! */
623       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
625         /* If we are currently editing groups environment, skip those ! entries */ 
626         if($this->is_group) continue;
627     
628         /* Create pwd reset images */
629         if($this->gotoShares[$key]['PwdHash'] != "" && !$hide){
630           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
631             title='"._("Reset password hash")."'>";
632         }
633         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$background."'");
634         $field2 = array("string" => $img   , "attach" => "style='".$background."border-right:0px;'");
635       }else{
637         /* Create pwd reset img && delete image */
638         if($this->gotoShares[$key]['PwdHash'] != ""){
639           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
640             title='"._("Reset password hash")."'>";
641           $img.= "&nbsp;";
642         }
643         if(!$hide){
644         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
645           title='"._("Delete share entry")."'>";
646         }
647         $field1 = array("string" => $value , "attach" => "style='".$background."'");
648         $field2 = array("string" => $img   , "attach" => "style='".$background."border-right:0px;'");
649       }
650       $divlistShares->AddEntry(array($field1,$field2));
651     }
652     $smarty->assign("divlistShares",$divlistShares->DrawList());
654     /* Hotplug devices will be handled here 
655      * There are 3 possible methods for this feature
656      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
657      * Delete will erase an entry, the entry must be selcted in the ListBox first
658      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
659      */
661     /* If there is a new entry wanted, open a new entry by initilising the dialog */
662     if(isset($_POST['gotoHotplugDeviceNew'])){
663       $this->dialog = new hotplugDialog($this->config,$this->dn);
664       $this->is_dialog = true;
665     }
667     /* We have to delete the selected hotplug from the list*/
668     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
669       foreach($_POST['gotoHotplugDevice'] as $name){
670         unset($this->gotoHotplugDevices[$name]);
671       }
672     }
674     /* There are already defined hotplugs from other users we could use */
675     if(isset($_POST['gotoHotplugDeviceUse'])){
676       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
677       $this->is_dialog = true;
678     }
680     /* Dialog Aborted */
681     if(isset($_POST['HotPlugCancel'])){
682       unset($this->dialog);
683       $this->dialog= NULL;
684       $this->is_dialog = false;
685     }
686  
687     /* Dialod saved */
688     if(isset($_POST['HotPlugSave'])){
689       $this->dialog->save_object();
690       if(count($this->dialog->check())!=0){
691         foreach($this->dialog->check() as $msg){
692           print_red($msg);
693         }
694       }else{
695         $this->dialog->save_object();
696         $a_tmp = $this->dialog->save();
697        
698         if(is_array($a_tmp)){
699           foreach($a_tmp as $name => $hotplug){
700             $this->gotoHotplugDevices[$name]= $hotplug; 
701           }
702         }
703         unset($this->dialog);
704         $this->dialog= NULL;
705         $this->is_dialog = false;
706       }
707     }
708     
709     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
710     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
711   
712     /* Printer Assignment will managed below 
713      * A printer can be assigned in two different ways and two different types
714      * There are 2 types of users assigned to a printer : user and admin
715      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
716      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
717      */ 
718     
719     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
720     if(isset($_POST['gotoPrinterAdd'])){
721       $this->is_dialog=true;
722       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
723     }
725     if(isset($_POST['PrinterCancel'])){
726         $this->is_dialog=false;
727         unset($this->dialog);
728         $this->dialog=NULL;
729     }
731     if(isset($_POST['PrinterSave'])){
732       if(count($this->dialog->check())!=0){
733         $tmp = $this->dialog->check();
734         foreach($tmp as $msg){
735           print_red($msg);
736         } 
737       }else{
738         $this->dialog->save_object();
739         $tmp = $this->dialog->save();
740         $tmp2= $this->dialog->getPrinter(true);
741   
742         foreach($tmp as $pname){
743           $this->gotoPrinter[$pname]=$tmp2[$pname];
744           $this->gotoPrinter[$pname]['mode']="user";
745         }
746   
747         $this->is_dialog=false;
748         unset($this->dialog);
749         $this->dialog   =NULL;
750       }
751     }
752   
753     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
754       $printer = $_POST['gotoPrinterSel'];
755       foreach($printer as $pname){
756         unset($this->gotoPrinter[$pname]);
757       }
758     }
760     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
763       $printers = $_POST['gotoPrinterSel'];
765       foreach($printers as $printer){
766         if($this->gotoPrinter[$printer]['mode']=="user"){
767           $this->gotoPrinter[$printer]['mode']="admin";
768         }else{
769           $this->gotoPrinter[$printer]['mode']="user";
770         }
771       }
772     }
774     if(!$this->is_group){
775       if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
776         if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
777           $this->gosaDefaultPrinter= "";
778         } else {
779           $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
780         }
781       }
782     }  
784     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
785     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
786  
787     /* General behavior */
788     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
789       $this->dialog->save_object();
790       $disp =$this->dialog->execute();
792       $tmp = new kioskManagementDialog($this->config,$this->dn);
793       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
794       $list['none']=_("None");
795       $list = array_reverse($list);
796       if(!isset($list[$this->gotoKioskProfile])){
797         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
798         $this->gotoKioskProfile = 'none';
799       }
800       return($disp);
801     }
802     if($this->acl != "#none#"){
803       $smarty->assign("useProfileACL","");
804     }else{
805       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
806       $smarty->assign("gotoProfileServerACL"," disabled ");
807       $smarty->assign("gotoProfileQuotaACL"," disabled ");
808     }
810     if(!$this->useProfile){
811       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
812       $smarty->assign("gotoProfileServerACL"," disabled ");
813       $smarty->assign("gotoProfileQuotaACL"," disabled ");
814     }
816     $smarty->assign("is_group",$this->is_group);
818     /* Als smarty vars are set. Get smarty template and generate output */
819     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
820     return($display);
821   }
823   function remove_from_parent()
824   {
825     /* only if it was an account*/
826     if (!$this->initially_was_account){
827       return;
828     }
830     /* include global link_info */
831     $ldap= $this->config->get_ldap_link();
833     /* Remove and write to LDAP */
834     plugin::remove_from_parent();
836     /* Don't save our template variables */
837     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
839     /* Skip all these attributes */
840     foreach($skip as $del){
841       unset($this->attrs[$del]);
842     }
844     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
846     $ldap->cd($this->dn);
847     $this->cleanup();
848     $ldap->modify ($this->attrs);
850     show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
852     /* Optionally execute a command after we're done */
853     $this->handle_post_events("remove",array("uid" => $this->uid));
854   }
857   /* Save data to object */
858   function save_object()
859   {
860     /* Get all Posted vars 
861      * Setup checkboxes 
862      */
863  
864     if(isset($_POST['iamposted'])){
865       if(isset($_POST['useProfile'])){
866         $this->useProfile = true;
867       }else{
868         $this->useProfile = false;
869       }
870       if(isset($_POST['gotoProfileFlag_C'])){
871         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
872       }else{
873         $this->gotoProfileFlag_C = false;
874       }
875       if(isset($_POST['gotoProfileFlag_L'])){
876         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
877       }else{
878         $this->gotoProfileFlag_L = false;
879       }
881       $tmp= $this->gosaDefaultPrinter;
882       plugin::save_object();
883       foreach($this->attributes as $s_attr){
884         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
885         if(isset($_POST[$s_attr])){
886           $this->$s_attr = $_POST[$s_attr];
887         }else{
888           $this->$s_attr = false;
889         }
890       }
891       $this->gosaDefaultPrinter= $tmp;
892     }
893   }
896   /* Check supplied data */
897   function check()
898   {
899     /* Call common method to give check the hook */
900     $this->detect_grouptype();
901     $message= plugin::check();
902   
903     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
904       $message[]=_("Please set a valid profile quota size.");
905     } 
906     if(!isset($this->attrs['objectClass'])){
907       $this->attrs['objectClass']=array();
908     } 
909     if(!$this->is_group){
910       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
911         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
912       }
913     }
914     return ($message);
915   }
918   /* Save to LDAP */
919   function save()
920   {
921     /* If group was renamed, all printer settings get lost
922      */ 
923     /* only save changed variables ....*/
924     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
925     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
926       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
927         $method="https://";
928       }else{
929         $method="http://";
930       }
932       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
933       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
934     }else{
935       $this->gotoKioskProfile= array();
936     }
937     
938     plugin::save();
939     $ldap= $this->config->get_ldap_link();
941     $realyUsedAttrs= array();
943     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
944     /* Creating Kiosk Profiles */
945     foreach($this->newKioskProfiles as $file){
946       $contents = $file['contents'];
947       $fp = @fopen($path."/".$file['name'],"w");
948       if(!$fp){
949         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
950       }else{
951         fwrite($fp,$contents,strlen($contents));
952       }
953       @unlink($file['tmp_name']);
954     }
955  
956     /* Save already used objectClasses */
957     $ocs        = $this->attrs['objectClass'];
958     unset($ocs['count']);
959     $this->attrs = array();
960     $this->attrs['objectClass']= $ocs;
961     foreach($this->objectclasses as $objc){
962       if(!in_array($objc,$this->attrs['objectClass'])){
963         $this->attrs['objectClass'][]=$objc;
964       }
965     }
968     /* Save usersettings to Printer */
969     $skip_printer_changes = false;
970     if(chkacl($this->acl,"gotoPrinter")!=""){
971       $this->gotoPrinter    = array();
972       $skip_printer_changes = true;
973     }  
974     
975     if(!$skip_printer_changes){
976       /* 1. Search all printers that have our uid/cn as member
977        * 2. Delete this uid/cn from every single entry and save it again.
978        * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
979        * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
980        */
981       $types = array( "gotoUserPrinter"       => "AddUser",
982           "gotoGroupPrinter"      => "AddGroup",
983           "gotoUserAdminPrinter"  => "AddAdminUser",
984           "gotoGroupAdminPrinter" => "AddAdminGroup");
986       /* Detect type of edited object, sometimes this wasn't set correctly ... */
987       $this->detect_grouptype();
989       if($this->is_group){
990         $s_suffix = "Group";
991         $useVar   = "cn";
992       }else{
993         $useVar   = "uid";
994         $s_suffix = "User";
995       }
997       /* Remove old entries */
998       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
999       while($attr = $ldap->fetch()){
1000         $printerObj = NULL;
1001         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1002         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
1003         $printerObj->by_object['printgeneric']->save();
1004       }
1006       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
1007       while($attr = $ldap->fetch()){
1008         $printerObj = NULL;
1009         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1010         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
1011         $printerObj->by_object['printgeneric']->save();
1012       }
1014       foreach($this->gotoPrinter as $printer){
1015         $printerObj = NULL;
1016         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1018         if($printer['mode'] == "admin") {
1019           $attribute = "goto".$s_suffix."AdminPrinter";
1020         }else{
1021           $attribute = "goto".$s_suffix."Printer";
1022         }
1024         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1025         $printerObj->by_object['printgeneric']->save();
1026       }
1027     }
1029     /* Prepare HotPlug devices */
1030     $this->attrs['gotoHotplugDevice'] = array();
1031     foreach($this->gotoHotplugDevices as $name => $device){
1032       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
1033     }
1035     /* Prepare LogonScripts */
1036     $this->attrs['gotoLogonScript'] = array();
1037     foreach($this->gotoLogonScripts as $name => $script){
1038       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1039                                             $script['LogonOverload'].$script['LogonLast']."|".
1040                                             $script['LogonPriority']."|".
1041                                             base64_encode($script['LogonData'])."|".
1042                                             $script['LogonDescription'];
1043     }
1045     /* Prepare Shares */
1046     $this->attrs['gotoShare']=array();
1047     foreach($this->gotoShares as $name => $share){
1048       $mntp= $share['mountPoint'];
1049       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1050         $mntp= base64_encode($mntp);
1051       }
1052       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1053     }
1056     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1057     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1058      
1059     foreach($saveThis as $tosave){
1060       if(!empty($this->$tosave)){
1061         $this->attrs[$tosave]=$this->$tosave;
1062       }else{
1063         $this->attrs[$tosave]=array();
1064       }
1065     }
1066  
1067     /* Prepare Flags */
1068     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1069     if(empty($this->attrs['gotoProfileFlags'][0])){
1070       $this->attrs['gotoProfileFlags']=array();
1071       }
1073     if($this->useProfile == false){
1074       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1075       $this->attrs['gotoProfileServer']= array(); 
1076     }
1078     foreach($this->attributes as $s_attr){
1079       if(chkacl($this->acl,$s_attr)!="") {
1080         if(isset($this->attrs[$s_attr])){
1081           unset($this->attrs[$s_attr]);
1082         }
1083       }
1084     }
1086     $ldap->cat ($this->dn, array('dn'));
1087     if ($ldap->fetch()){
1088       $mode= "modify";
1089     } else {
1090       $mode= "add";
1091       $ldap->cd($this->config->current['BASE']);
1092       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1093     }
1095     $ldap->cd($this->dn);
1096     $this->cleanup();
1097     $ldap->$mode($this->attrs);
1098     show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1099     $this->handle_post_events($mode,array("uid"=>$this->uid));
1100   }
1102 /* Generate ListBox frindly output for the defined shares 
1103  * Possibly Add or remove an attribute here, 
1104  */
1105   function printOutAssignedShares()
1106   {
1107     $a_return = array();
1108     if(is_array($this->gotoShares)){
1109       foreach($this->gotoShares as $share){
1110         if(preg_match("/^!/",$share['server'])){
1111           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1112         }else{
1113           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1114         }
1115       }
1116     }
1117     return($a_return);
1118   }
1120 /* Generate ListBox frindly output for the definedhotplugs 
1121  * Possibly Add or remove an attribute here,
1122  */
1123 function printOutHotPlugDevices()
1124   {
1125     $a_return= array();
1126     if(is_array($this->gotoHotplugDevices)){
1127       foreach($this->gotoHotplugDevices as $key=>$device){
1128         $a_return[$key] = $device['name']." - ".$device['id'];
1129       }
1130     }
1131     return($a_return);
1132   }
1134   /* Generates ListBox frienly output of used printer devices 
1135    * Append ' - admin' if printer is used in admin mode
1136    */
1137   function printOutPrinterDevices()
1138   {
1139     $a_return = array();
1140     if(is_array($this->gotoPrinter)){
1141       foreach($this->gotoPrinter as $printer){
1142         if($printer['mode'] == "admin"){
1143           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1144         }else{
1145           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1146         }
1147         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1148           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1149         }
1150       }
1151     }
1152     return($a_return);
1153   }
1155   /* Generates ListBox frienly output of used logonscripts 
1156    */
1157   function printOutLogonScripts()
1158   {
1159     $a_return = array();
1160     if(is_array($this->gotoLogonScripts)){
1161       foreach($this->gotoLogonScripts as $script){
1162         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1163       }
1164     }
1165     return($a_return);
1166   }
1172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1173 ?>