Code

Added uid to post events.
[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)
78   {
79     plugin::plugin ($config, $dn);
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     foreach($tmp as $key => $value){
612       $img = "";
613    
614       /* Check if entry starts with an ! */
615       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
617         /* If we are currently editing groups environment, skip those ! entries */ 
618         if($this->is_group) continue;
619     
620         /* Create pwd reset images */
621         if($this->gotoShares[$key]['PwdHash'] != ""){
622           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
623             title='"._("Reset password hash")."'>";
624         }
625         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
626         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
627       }else{
629         /* Create pwd reset img && delete image */
630         if($this->gotoShares[$key]['PwdHash'] != ""){
631           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
632             title='"._("Reset password hash")."'>";
633           $img.= "&nbsp;";
634         }
635         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
636           title='"._("Delete share entry")."'>";
637         $field1 = array("string" => $value);
638         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
639       }
640       $divlistShares->AddEntry(array($field1,$field2));
641     }
642     $smarty->assign("divlistShares",$divlistShares->DrawList());
644     /* Hotplug devices will be handled here 
645      * There are 3 possible methods for this feature
646      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
647      * Delete will erase an entry, the entry must be selcted in the ListBox first
648      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
649      */
651     /* If there is a new entry wanted, open a new entry by initilising the dialog */
652     if(isset($_POST['gotoHotplugDeviceNew'])){
653       $this->dialog = new hotplugDialog($this->config,$this->dn);
654       $this->is_dialog = true;
655     }
657     /* We have to delete the selected hotplug from the list*/
658     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
659       foreach($_POST['gotoHotplugDevice'] as $name){
660         unset($this->gotoHotplugDevices[$name]);
661       }
662     }
664     /* There are already defined hotplugs from other users we could use */
665     if(isset($_POST['gotoHotplugDeviceUse'])){
666       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
667       $this->is_dialog = true;
668     }
670     /* Dialog Aborted */
671     if(isset($_POST['HotPlugCancel'])){
672       unset($this->dialog);
673       $this->dialog= NULL;
674       $this->is_dialog = false;
675     }
676  
677     /* Dialod saved */
678     if(isset($_POST['HotPlugSave'])){
679       $this->dialog->save_object();
680       if(count($this->dialog->check())!=0){
681         foreach($this->dialog->check() as $msg){
682           print_red($msg);
683         }
684       }else{
685         $this->dialog->save_object();
686         $a_tmp = $this->dialog->save();
687        
688         if(is_array($a_tmp)){
689           foreach($a_tmp as $name => $hotplug){
690             $this->gotoHotplugDevices[$name]= $hotplug; 
691           }
692         }
693         unset($this->dialog);
694         $this->dialog= NULL;
695         $this->is_dialog = false;
696       }
697     }
698     
699     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
700     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
701   
702     /* Printer Assignment will managed below 
703      * A printer can be assigned in two different ways and two different types
704      * There are 2 types of users assigned to a printer : user and admin
705      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
706      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
707      */ 
708     
709     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
710     if(isset($_POST['gotoPrinterAdd'])){
711       $this->is_dialog=true;
712       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
713     }
715     if(isset($_POST['PrinterCancel'])){
716         $this->is_dialog=false;
717         unset($this->dialog);
718         $this->dialog=NULL;
719     }
721     if(isset($_POST['PrinterSave'])){
722       if(count($this->dialog->check())!=0){
723         $tmp = $this->dialog->check();
724         foreach($tmp as $msg){
725           print_red($msg);
726         } 
727       }else{
728         $this->dialog->save_object();
729         $tmp = $this->dialog->save();
730         $tmp2= $this->dialog->getPrinter(true);
731   
732         foreach($tmp as $pname){
733           $this->gotoPrinter[$pname]=$tmp2[$pname];
734           $this->gotoPrinter[$pname]['mode']="user";
735         }
736   
737         $this->is_dialog=false;
738         unset($this->dialog);
739         $this->dialog   =NULL;
740       }
741     }
742   
743     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
744       $printer = $_POST['gotoPrinterSel'];
745       foreach($printer as $pname){
746         unset($this->gotoPrinter[$pname]);
747       }
748     }
750     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
753       $printers = $_POST['gotoPrinterSel'];
755       foreach($printers as $printer){
756         if($this->gotoPrinter[$printer]['mode']=="user"){
757           $this->gotoPrinter[$printer]['mode']="admin";
758         }else{
759           $this->gotoPrinter[$printer]['mode']="user";
760         }
761       }
762     }
764     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
765       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
766         $this->gosaDefaultPrinter= "";
767       } else {
768         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
769       }
770     }
772     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
773     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
774  
775     /* General behavior */
776     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
777       $this->dialog->save_object();
778       $disp =$this->dialog->execute();
780       $tmp = new kioskManagementDialog($this->config,$this->dn);
781       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
782       $list['none']=_("None");
783       $list = array_reverse($list);
784       if(!isset($list[$this->gotoKioskProfile])){
785         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
786         $this->gotoKioskProfile = 'none';
787       }
788       return($disp);
789     }
790     if($this->acl != "#none#"){
791       $smarty->assign("useProfileACL","");
792     }else{
793       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
794       $smarty->assign("gotoProfileServerACL"," disabled ");
795       $smarty->assign("gotoProfileQuotaACL"," disabled ");
796     }
798     if(!$this->useProfile){
799       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
800       $smarty->assign("gotoProfileServerACL"," disabled ");
801       $smarty->assign("gotoProfileQuotaACL"," disabled ");
802     }
804     /* Als smarty vars are set. Get smarty template and generate output */
805     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
806     return($display);
807   }
809   function remove_from_parent()
810   {
811     /* only if it was an account*/
812     if (!$this->initially_was_account){
813       return;
814     }
816     /* include global link_info */
817     $ldap= $this->config->get_ldap_link();
819     /* Remove and write to LDAP */
820     plugin::remove_from_parent();
822     /* Don't save our template variables */
823     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
825     /* Skip all these attributes */
826     foreach($skip as $del){
827       unset($this->attrs[$del]);
828     }
830     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
832     $ldap->cd($this->dn);
833     $this->cleanup();
834     $ldap->modify ($this->attrs);
836     show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
838     /* Optionally execute a command after we're done */
839     $this->handle_post_events("remove",array("uid" => $this->uid));
840   }
843   /* Save data to object */
844   function save_object()
845   {
846     /* Get all Posted vars 
847      * Setup checkboxes 
848      */
849  
850     if(isset($_POST['iamposted'])){
851       if(isset($_POST['useProfile'])){
852         $this->useProfile = true;
853       }else{
854         $this->useProfile = false;
855       }
856       if(isset($_POST['gotoProfileFlag_C'])){
857         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
858       }else{
859         $this->gotoProfileFlag_C = false;
860       }
861       if(isset($_POST['gotoProfileFlag_L'])){
862         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
863       }else{
864         $this->gotoProfileFlag_L = false;
865       }
867       $tmp= $this->gosaDefaultPrinter;
868       plugin::save_object();
869       foreach($this->attributes as $s_attr){
870         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
871         if(isset($_POST[$s_attr])){
872           $this->$s_attr = $_POST[$s_attr];
873         }else{
874           $this->$s_attr = false;
875         }
876       }
877       $this->gosaDefaultPrinter= $tmp;
878     }
879   }
882   /* Check supplied data */
883   function check()
884   {
885     /* Call common method to give check the hook */
886     $this->detect_grouptype();
887     $message= plugin::check();
888   
889     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
890       $message[]=_("Please set a valid profile quota size.");
891     } 
892     if(!isset($this->attrs['objectClass'])){
893       $this->attrs['objectClass']=array();
894     } 
895     if(!$this->is_group){
896       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
897         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
898       }
899     }
900     return ($message);
901   }
904   /* Save to LDAP */
905   function save()
906   {
907     /* If group was renamed, all printer settings get lost
908      */ 
909     /* only save changed variables ....*/
910     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
911     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
912       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
913         $method="https://";
914       }else{
915         $method="http://";
916       }
918       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
919       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
920     }else{
921       $this->gotoKioskProfile= array();
922     }
923     
924     plugin::save();
925     $ldap= $this->config->get_ldap_link();
927     $realyUsedAttrs= array();
929     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
930     /* Creating Kiosk Profiles */
931     foreach($this->newKioskProfiles as $file){
932       $contents = $file['contents'];
933       $fp = @fopen($path."/".$file['name'],"w");
934       if(!$fp){
935         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
936       }else{
937         fwrite($fp,$contents,strlen($contents));
938       }
939       @unlink($file['tmp_name']);
940     }
941  
942     /* Save already used objectClasses */
943     $ocs        = $this->attrs['objectClass'];
944     unset($ocs['count']);
945     $this->attrs = array();
946     $this->attrs['objectClass']= $ocs;
947     foreach($this->objectclasses as $objc){
948       if(!in_array($objc,$this->attrs['objectClass'])){
949         $this->attrs['objectClass'][]=$objc;
950       }
951     }
954     /* Save usersettings to Printer */
955     $skip_printer_changes = false;
956     if(chkacl($this->acl,"gotoPrinter")!=""){
957       $this->gotoPrinter    = array();
958       $skip_printer_changes = true;
959     }  
960     
961     if(!$skip_printer_changes){
962       /* 1. Search all printers that have our uid/cn as member
963        * 2. Delete this uid/cn from every single entry and save it again.
964        * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
965        * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
966        */
967       $types = array( "gotoUserPrinter"       => "AddUser",
968           "gotoGroupPrinter"      => "AddGroup",
969           "gotoUserAdminPrinter"  => "AddAdminUser",
970           "gotoGroupAdminPrinter" => "AddAdminGroup");
972       /* Detect type of edited object, sometimes this wasn't set correctly ... */
973       $this->detect_grouptype();
975       if($this->is_group){
976         $s_suffix = "Group";
977         $useVar   = "cn";
978       }else{
979         $useVar   = "uid";
980         $s_suffix = "User";
981       }
983       /* Remove old entries */
984       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
985       while($attr = $ldap->fetch()){
986         $printerObj = NULL;
987         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
988         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
989         $printerObj->by_object['printgeneric']->save();
990       }
992       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
993       while($attr = $ldap->fetch()){
994         $printerObj = NULL;
995         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
996         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
997         $printerObj->by_object['printgeneric']->save();
998       }
1000       foreach($this->gotoPrinter as $printer){
1001         $printerObj = NULL;
1002         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1004         if($printer['mode'] == "admin") {
1005           $attribute = "goto".$s_suffix."AdminPrinter";
1006         }else{
1007           $attribute = "goto".$s_suffix."Printer";
1008         }
1010         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1011         $printerObj->by_object['printgeneric']->save();
1012       }
1013     }
1015     /* Prepare HotPlug devices */
1016     $this->attrs['gotoHotplugDevice'] = array();
1017     foreach($this->gotoHotplugDevices as $name => $device){
1018       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
1019     }
1021     /* Prepare LogonScripts */
1022     $this->attrs['gotoLogonScript'] = array();
1023     foreach($this->gotoLogonScripts as $name => $script){
1024       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1025                                             $script['LogonOverload'].$script['LogonLast']."|".
1026                                             $script['LogonPriority']."|".
1027                                             base64_encode($script['LogonData'])."|".
1028                                             $script['LogonDescription'];
1029     }
1031     /* Prepare Shares */
1032     $this->attrs['gotoShare']=array();
1033     foreach($this->gotoShares as $name => $share){
1034       $mntp= $share['mountPoint'];
1035       if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1036         $mntp= base64_encode($mntp);
1037       }
1038       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1039     }
1042     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1043     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1044      
1045     foreach($saveThis as $tosave){
1046       if(!empty($this->$tosave)){
1047         $this->attrs[$tosave]=$this->$tosave;
1048       }else{
1049         $this->attrs[$tosave]=array();
1050       }
1051     }
1052  
1053     /* Prepare Flags */
1054     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1055     if(empty($this->attrs['gotoProfileFlags'][0])){
1056       $this->attrs['gotoProfileFlags']=array();
1057       }
1059     if($this->useProfile == false){
1060       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1061       $this->attrs['gotoProfileServer']= array(); 
1062     }
1064     foreach($this->attributes as $s_attr){
1065       if(chkacl($this->acl,$s_attr)!="") {
1066         if(isset($this->attrs[$s_attr])){
1067           unset($this->attrs[$s_attr]);
1068         }
1069       }
1070     }
1072     $ldap->cat ($this->dn, array('dn'));
1073     if ($ldap->fetch()){
1074       $mode= "modify";
1075     } else {
1076       $mode= "add";
1077       $ldap->cd($this->config->current['BASE']);
1078       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1079     }
1081     $ldap->cd($this->dn);
1082     $this->cleanup();
1083     $ldap->$mode($this->attrs);
1084     show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1085     $this->handle_post_events($mode,array("uid"=>$this->uid));
1086   }
1088 /* Generate ListBox frindly output for the defined shares 
1089  * Possibly Add or remove an attribute here, 
1090  */
1091   function printOutAssignedShares()
1092   {
1093     $a_return = array();
1094     if(is_array($this->gotoShares)){
1095       foreach($this->gotoShares as $share){
1096         if(preg_match("/^!/",$share['server'])){
1097           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1098         }else{
1099           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1100         }
1101       }
1102     }
1103     return($a_return);
1104   }
1106 /* Generate ListBox frindly output for the definedhotplugs 
1107  * Possibly Add or remove an attribute here,
1108  */
1109 function printOutHotPlugDevices()
1110   {
1111     $a_return= array();
1112     if(is_array($this->gotoHotplugDevices)){
1113       foreach($this->gotoHotplugDevices as $key=>$device){
1114         $a_return[$key] = $device['name']." - ".$device['id'];
1115       }
1116     }
1117     return($a_return);
1118   }
1120   /* Generates ListBox frienly output of used printer devices 
1121    * Append ' - admin' if printer is used in admin mode
1122    */
1123   function printOutPrinterDevices()
1124   {
1125     $a_return = array();
1126     if(is_array($this->gotoPrinter)){
1127       foreach($this->gotoPrinter as $printer){
1128         if($printer['mode'] == "admin"){
1129           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1130         }else{
1131           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1132         }
1133         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1134           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1135         }
1136       }
1137     }
1138     return($a_return);
1139   }
1141   /* Generates ListBox frienly output of used logonscripts 
1142    */
1143   function printOutLogonScripts()
1144   {
1145     $a_return = array();
1146     if(is_array($this->gotoLogonScripts)){
1147       foreach($this->gotoLogonScripts as $script){
1148         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1149       }
1150     }
1151     return($a_return);
1152   }
1158 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1159 ?>