Code

gotoKioskProfile wasn't saved
[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    = "1024x768";     // 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
44   /* Share */
45   var $gotoShares         = array();// Current Share Options
46   var $gotoShare          = "";     // currently selected Share Option
47   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
48   var $gotoAvailableShares= array();// Available Shares for this account
49   
50   /* Kiosk profile */
51   var $gotoKioskProfile   = "none";     // The selected Kiosk Profile
52   var $gotoKioskProfiles  = array();// All available Kiosk profiles
53   VAR $newKioskProfiles   = array();
55   /* Hotplug Devices */
56   var $gotoHotplugDevice  = "";     // Selected hotplug
57   var $gotoHotplugDevices = array();// Already configured hotplug devices 
60   /* general settings */
61   // Sets the attributes which will kept on page reload, which will be saved, ...
62   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags",
63                                     "gotoXResolution","gotoProfileQuota",
64                                     "gotoLogonScripts","gotoLogonScript",
65                                     "gotoPrinter",
66                                     "gotoShares","gotoShare",
67                                     "gotoKioskProfile","gotoKioskProfiles",
68                                     "gotoHotplugDevice");
69   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
70   var $cn;
72   function environment ($config, $dn= NULL)
73   {
74     plugin::plugin ($config, $dn);
76    
77     /* Check : Are we currently editing a group or user dialog */
78     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
79       $suffix="Group";
80       $this->uid          = $this->attrs['cn'][0];
81       $this->attrs['uid'] = $this->attrs['cn'][0];
82     }else{
83       $suffix="User";
84     }
86     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
88     /* Get all Printer assignments */
89     $ldap = $this->config->get_ldap_link();
90     $ldap->cd($this->config->current['BASE']);
91     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
92     while($printer = $ldap->fetch()){
93       $this->gotoPrinter[$printer['cn'][0]]=$printer;
94       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
95     }
96     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
97     while($printer = $ldap->fetch()){
98       $this->gotoPrinter[$printer['cn'][0]]=$printer;
99       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
100     }
101   
102     /* prepare hotplugs */
103     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
104       unset($this->attrs['gotoHotplugDevice']['count']);
105       foreach($this->attrs['gotoHotplugDevice'] as $device){
106         $tmp = $tmp2 = array();
107         $tmp = split("\|",$device);
108         $tmp2['name']        = $tmp[0]; 
109         $tmp2['description'] = $tmp[1]; 
110         $tmp2['id']          = $tmp[2]; 
111         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
112       }
113     }
114     
115     /* prepare LogonScripts */
116     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
117       unset($this->attrs['gotoLogonScript']['count']);
118       foreach($this->attrs['gotoLogonScript'] as $device){
119         $tmp = $tmp2 = array();
120         $tmp = split("\|",$device);
121         $tmp2['LogonName']        = $tmp[0]; 
122         $tmp2['LogonPriority']    = $tmp[2]; 
123         if(preg_match("/O/i",$tmp[1])){
124           $tmp2['LogonOverload'] = "O";
125         }else{
126           $tmp2['LogonOverload'] = "";
127         }
128         if(preg_match("/L/i",$tmp[1])){
129           $tmp2['LogonLast'] = "L";
130         }else{
131           $tmp2['LogonLast'] = "";
132         }
133         $tmp2['LogonData']        = base64_decode($tmp[3]); 
134         $tmp2['LogonDescription'] = $tmp[4];
135         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
136       }
137     }
138     
139     /* Prepare Shares */
140     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
141       unset($this->attrs['gotoShare']['count']);
142       foreach($this->attrs['gotoShare'] as $share){
143         $tmp = $tmp2 = array();
144         $tmp = split("\|",$share);
145         $tmp2['server']      =$tmp[0];
146         $tmp2['name']        =$tmp[1];
147         $tmp2['mountPoint']  =$tmp[2];
148         if(isset($tmp[3])){
149           $tmp2['OtherStuff']  =$tmp[3];
150         }else{
151           $tmp2['OtherStuff']  ="";
152         }
153         if(isset($tmp[4])){
154           $tmp2['Username']  =$tmp[4];
155         }else{
156           $tmp2['Username']  ="";
157         }
158         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
159       }
160     }
162     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
163       $chr = $this->gotoProfileFlags[$i];
164       $name = "gotoProfileFlag_".$chr;
165       $this->$name=$chr;
166     }
168     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
169       $this->useProfile = true;
170     }else{
171       $this->useProfile = false;
172     }
174     /* Set to group environment if we editing a group */
175     if(!isset($this->parent)){
176       $this->is_group = true;
177     }
179     $this->gotoProfileServers= $config->getShareServerList() ;
180     $this->gotoShareSelections= $config->getShareList(true);
181     $this->gotoAvailableShares= $config->getShareList(false);  
183   }
185   function execute()
186   {
187         /* Call parent execute */
188         plugin::execute();
190   /* Fill templating stuff */
191   $smarty= get_smarty();
192   $display= "";
194   /* Prepare all variables for smarty */
195   foreach($this->attributes as $s_attr){
196     /* Set value*/
197     $smarty->assign($s_attr,$this->$s_attr);
199     /* Set checkbox state*/
200     if(empty($this->$s_attr)){
201       $smarty->assign($s_attr."CHK","");
202     }else{
203       $smarty->assign($s_attr."CHK"," checked ");
204     }
206     /* Prepare ACL settings*/
207     if(chkacl($this->acl,$s_attr)=="") {
208       $smarty->assign($s_attr."ACL","");
209     }else{
210       $smarty->assign($s_attr."ACL"," disabled ");
211     }
213   }
215   /* Is accout enabled | are we editing from usermenu or admin menu 
216      All these tab management is done here
217    */
219   /* Working from Usermenu an the Account is currently disbled
220      * this->parent :  is only set if we are working in a list of tabs
221      * is_account   :  is only true if the needed objectClass is given
222     */
223     if((!isset($this->parent))&&(!$this->is_account)){
224       /* We are currently editing this tab from usermenu, but this account is not enabled */
225       $smarty->assign("is_account",$this->is_account);
226       /* Load template */
227       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
228       /* Avoid the "You are currently editing ...." message when you leave this tab */
229       $display .= back_to_main(); 
230       /* Display our message to the user */
231       return $display;
232     
234     /* We are currently editing from group tabs, because 
235      * $this->parent is set
236      * posixAccount is not set, so we are not in usertabs.
237      */
238     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
239       $smarty->assign("is_account","true");
240       $this->is_group     = true;
241       $this->uid          = $this->cn;
242       $this->attrs['uid'] = $this->cn;
244       /* Change state if needed */
245       if (isset($_POST['modify_state'])){
246         $this->is_account= !$this->is_account;
247       }
249       /* Group Dialog with enabled environment options */
250       if ($this->is_account){
251         $display= $this->show_header(_("Remove environment extension"),
252             _("Environment extension enabled. You can disable it by clicking below."));
253       } else {
254   
255       /* Environment is disabled 
256          If theres is no posixAccount enabled, you won't be able to enable 
257          environment extensions
258        */
259         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
260           // 4. There is a PosixAccount
261           $display= $this->show_header(_("Add environment extension"),
262               _("Environment extension disabled. You can enable it by clicking below."));
263           return $display;
264         }else{
265           // 4. There is no PosixAccount
266           $display= $this->show_header(_("Add environment extension"),
267               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
268           return $display;
269         }
270       }
271     }else{
272       /* Editing from Usermenu 
273        *  Tell smarty that this accoutn is enabled 
274        */
275       $smarty->assign("is_account","true");
277       $this->is_group = false;
279       /* Do we need to flip is_account state? */
280       if (isset($_POST['modify_state'])){
281         $this->is_account= !$this->is_account;
282       }
284       if(isset($this->parent)){
286         // 3. Account enabled . Editing from adminmenu
287         if ($this->is_account){
288           $display= $this->show_header(_("Remove environment extension"),
289               _("Environment extension enabled. You can disable it by clicking below."));
290         } else {
292           if($this->parent->by_object['posixAccount']->is_account==true){
293             // 4. There is a PosixAccount
294             $display= $this->show_header(_("Add environment extension"),
295                 _("Environment extension disabled. You can enable it by clicking below."));
296             return $display;
297           }else{
298             // 4. There is a PosixAccount
299             $display= $this->show_header(_("Add environment extension"),
300                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
301             return $display;
302           }
303         }
304       }
305     }
306     /* Account is Account : is_accounbt=true.
307      * Else we won't reach this. 
308      */
309    
310     /* Prepare all variables for smarty */
311     foreach($this->attributes as $s_attr){
312       /* Set value*/
313       $smarty->assign($s_attr,$this->$s_attr);
314      
315       /* Set checkbox state*/
316       if(empty($this->$s_attr)){
317         $smarty->assign($s_attr."CHK","");
318       }else{
319         $smarty->assign($s_attr."CHK"," checked ");
320       }
321     
322       /* Prepare ACL settings*/
323       if(chkacl($this->acl,$s_attr)=="") {
324         $smarty->assign($s_attr."ACL","");
325       }else{
326         $smarty->assign($s_attr."ACL"," disabled ");
327       }
328  
329     }
331     foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
332       if(chkacl($this->acl,$s_attr)=="") {
333         $smarty->assign($s_attr."ACL","");
334       }else{
335         $smarty->assign($s_attr."ACL"," disabled ");
336       }
337     }
339     if(empty($this->useProfile)){
340       $smarty->assign("gotoProfileACL","disabled");
341       $smarty->assign("useProfileCHK","");
342     }else{
343       $smarty->assign("gotoProfileACL","");
344       $smarty->assign("useProfileCHK"," checked ");
345     }
347  
348     $smarty->assign("useProfileACL","");
349     if($this->acl != "#none#"){
350       $smarty->assign("useProfileACL","");
351       $smarty->assign("gotoProfileFlag_CACL"," ");
352       $smarty->assign("gotoProfileQuotaACL"," ");
353     }else{
354       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
355       $smarty->assign("useProfileACL","disabled");
356       $smarty->assign("gotoProfileServer"," disabled ");
357       $smarty->assign("gotoProfileQuotaACL"," disabled ");
358     }
360     /* HANDLE Profile Settings here 
361      * Assign available Quota and resolution settings
362      * Get all available profile server
363      * Get cache checkbox
364      * Assign this all to Smarty 
365      */
367     if(empty($this->gotoProfileFlag_L)){
368       $smarty->assign("gotoProfileFlag_LCHK"," ");
369     }else{
370       $smarty->assign("gotoProfileFlag_LCHK"," checked ");
371     }
373     if(empty($this->gotoProfileFlag_C)){
374       $smarty->assign("gotoProfileFlag_CCHK"," ");
375     }else{
376       $smarty->assign("gotoProfileFlag_CCHK"," checked ");
377     }
379     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
381     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
382     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
383     if(!is_array($this->gotoProfileServers)){
384       $this->gotoProfileServers =array();
385     }
386     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
388     /* Handle kiosk profiles 
389      * Read available from filesystem
390      * Open management if post is transmitted
391      */
393     /* Save */
394     if(isset($_POST['KioskClose'])){
395       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
396   
397       unset($this->dialog);
398       $this->dialog=NULL;
399       $this->is_dialog = false;
400     }
401     $tmp = new kioskManagementDialog($this->config,$this->dn);
402     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
404     $list['none']=_("None");
406     $list = array_reverse($list);
408     /* Reassign help class */
409     $_SESSION['current_class_for_help'] = get_class($this);
410  
411     /* Open Management Dialog */
412     if(isset($_POST['KioskManagementDialog'])){
413       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
414       $this->dialog->parent= $this;
415       $this->dialog->acl = $this->acl;
416       $this->is_dialog = true;
417     }
419     $smarty->assign("gotoKioskProfiles",$list);
420     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
422     /* Logonscript Management
423      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
424      * Perform add Delete edit Posts 
425      */
427     /* Dialog Save */
428     if(isset($_POST['LogonSave'])){
429       $this->dialog->save_object();
430       if(count($this->dialog->check())!=0){
431         foreach($this->dialog->check() as $msg){
432           print_red($msg);
433         }
434       }else{
435         $tmp = $this->dialog->save();
436         unset($this->dialog);
437         $this->dialog=NULL;
438         $this->is_dialog=false;
439         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
440       }
441     }
442     
443     /* Dialog Quit without saving */
444     if(isset($_POST['LogonCancel'])){
445       $this->is_dialog= false;
446       unset($this->dialog);
447       $this->dialog= NULL;
448     }
449    
450     /* Check Edit Del New Posts for a selected LogonScript */ 
451     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
453       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
454        * In this case we create a new Logon Script.
455        */
456       if(isset($_POST['gotoLogonScriptNew'])){
457         $this->is_dialog = true;
458         $this->dialog = new logonManagementDialog($this->config,$this->dn);
459       }
461       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
462        * We only can delete if there is an entry selected.
463        */
464       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
465         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
466       }
467       
468       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
469        * There must be an entry selected to perform edit request.
470        */
471       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
472         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
473         $this->is_dialog = true;
474         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
475       }
476     }
477      
478     /* Append List to smarty*/
479     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
480     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
482     /* In this section server shares will be defined 
483      * A user can select one of the given shares and a mount point
484      *  and attach this combination to his setup.
485      */
486     
487     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
488     if(!is_array($this->gotoShareSelections)){
489       print $this->gotoShareSelections;
490       $this->gotoShareSelections = array();
491     }
492     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
494     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
495      * This entry will be, a combination of mountPoint and sharedefinitions 
496      */
497     if(isset($_POST['gotoShareAdd'])){
498       /* We assign a share to this user, if we don't know where to mount the share */
499       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
500         print_red(_("You must specify a valid mount point."));
501       }elseif(!(
502         preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
503         preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
504         preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
505         preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
506         preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
507         preg_match("/^.USER/",$_POST['gotoShareMountPoint'])
508         )
509       ){
510         print_red(_("You must specify a valid mount point.")); 
511       }else{
512         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
513         $s_mount = $_POST['gotoShareMountPoint'];
514         $s_user  = $_POST['ShareUser'];
515         /* Preparing the new assignment */ 
516         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
517         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
518         $this->gotoShares[$a_share['name']."|".$a_share['server']]['OtherStuff']="";
519         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
520       }
521     }  
523     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
524      * If there is no defined share selected, we will abort the deletion without any message 
525      */
526     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
527       unset($this->gotoShares[$_POST['gotoShare']]);
528     }
530     $smarty->assign("gotoShares",$this->printOutAssignedShares());
531     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
533     /* Hotplug devices will be handled here 
534      * There are 3 possible methods for this feature
535      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
536      * Delete will erase an entry, the entry must be selcted in the ListBox first
537      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
538      */
540     /* If there is a new entry wanted, open a new entry by initilising the dialog */
541     if(isset($_POST['gotoHotplugDeviceNew'])){
542       $this->dialog = new hotplugDialog($this->config,$this->dn);
543       $this->is_dialog = true;
544     }
546     /* We have to delete the selected hotplug from the list*/
547     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
548       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
549     }
551     /* There are already defined hotplugs from other users we could use */
552     if(isset($_POST['gotoHotplugDeviceUse'])){
553       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
554       $this->is_dialog = true;
555     }
557     /* Dialog Aborted */
558     if(isset($_POST['HotPlugCancel'])){
559       unset($this->dialog);
560       $this->dialog= NULL;
561       $this->is_dialog = false;
562     }
563  
564     /* Dialod saved */
565     if(isset($_POST['HotPlugSave'])){
566       $this->dialog->save_object();
567       if(count($this->dialog->check())!=0){
568         foreach($this->dialog->check() as $msg){
569           print_red($msg);
570         }
571       }else{
572         $this->dialog->save_object();
573         $a_tmp = $this->dialog->save();
574         if(is_array($a_tmp)){
575           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
576         }
577         unset($this->dialog);
578         $this->dialog= NULL;
579         $this->is_dialog = false;
580       }
581     }
582     
583     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
584     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
585   
586     /* Printer Assignment will managed below 
587      * A printer can be assigned in two different ways and two different types
588      * There are 2 types of users assigned to a printer : user and admin
589      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
590      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
591      */ 
592     
593     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
594     if(isset($_POST['gotoPrinterAdd'])){
595       $this->is_dialog=true;
596       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
597     }
599     if(isset($_POST['PrinterCancel'])){
600         $this->is_dialog=false;
601         unset($this->dialog);
602         $this->dialog=NULL;
603     }
605     if(isset($_POST['PrinterSave'])){
606       if(count($this->dialog->check())!=0){
607         $tmp = $this->dialog->check();
608         foreach($tmp as $msg){
609           print_red($msg);
610         } 
611       }else{
612         $this->dialog->save_object();
613         $tmp = $this->dialog->save();
614         $tmp2= $this->dialog->getPrinter(true);
615         $this->gotoPrinter[$tmp]=$tmp2[$tmp];
616         $this->gotoPrinter[$tmp]['mode']="user";
617         $this->is_dialog=false;
618         unset($this->dialog);
619         $this->dialog   =NULL;
620       }
621     }
622   
623     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
624       $printer = $_POST['gotoPrinterSel'];
625       unset($this->gotoPrinter[$printer]);
626     }
628     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
629       $printer = $_POST['gotoPrinterSel'];
630       if($this->gotoPrinter[$printer]['mode']=="user"){
631         $this->gotoPrinter[$printer]['mode']="admin";
632       }else{
633         $this->gotoPrinter[$printer]['mode']="user";
634       }
635     }
637     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
638     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
639  
640     /* General behavior */
641     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
642       $this->dialog->save_object();
643       return ($this->dialog->execute());
644     }
645     if($this->acl != "#none#"){
646       $smarty->assign("useProfileACL","");
647     }else{
648       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
649       $smarty->assign("gotoProfileServerACL"," disabled ");
650       $smarty->assign("gotoProfileQuotaACL"," disabled ");
651     }
653     if(!$this->useProfile){
654       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
655       $smarty->assign("gotoProfileServerACL"," disabled ");
656       $smarty->assign("gotoProfileQuotaACL"," disabled ");
657     }
659     /* Als smarty vars are set. Get smarty template and generate output */
660     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
661     
662     return($display);
663   }
665   function remove_from_parent()
666   {
667     /* only if it was an account*/
668     if (!$this->initially_was_account){
669       return;
670     }
672     /* include global link_info */
673     $ldap= $this->config->get_ldap_link();
675     /* Remove and write to LDAP */
676     plugin::remove_from_parent();
678     /* Don't save our template variables */
679     $skip = array("uid",
680                   "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
681     /* Skip all these attributes */
682     foreach($skip as $del){
683       unset($this->attrs[$del]);
684     }
686     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
688     $ldap->cd($this->dn);
689     $this->cleanup();
690 $ldap->modify ($this->attrs); 
693     show_ldap_error($ldap->get_error());
695     /* Optionally execute a command after we're done */
696     $this->handle_post_events("remove");
697   }
700   /* Save data to object */
701   function save_object()
702   {
703     /* Get all Posted vars 
704      * Setup checkboxes 
705      */
706    
707     
708  
709     if(isset($_POST['iamposted'])){
710       if(isset($_POST['useProfile'])){
711         $this->useProfile = true;
712       }else{
713         $this->useProfile = false;
714       }
715       if(isset($_POST['gotoProfileFlag_C'])){
716         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
717       }else{
718         $this->gotoProfileFlag_C = false;
719       }
720       if(isset($_POST['gotoProfileFlag_L'])){
721         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
722       }else{
723         $this->gotoProfileFlag_L = false;
724       }
726       plugin::save_object();
727       foreach($this->attributes as $s_attr){
728         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
729         if(isset($_POST[$s_attr])){
730           $this->$s_attr = $_POST[$s_attr];
731         }else{
732           $this->$s_attr = false;
733         }
734       }
735     }
736   }
739   /* Check supplied data */
740   function check()
741   {
742     $message= array();
743   
744     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
745       $message[]=_("Please set a valid profile quota size.");
746     } 
747     if(!isset($this->attrs['objectClass'])){
748       $this->attrs['objectClass']=array();
749     } 
750     if(!$this->is_group){
751       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
752         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
753       }
754     }
755     return ($message);
756   }
759   /* Save to LDAP */
760   function save()
761   {
762   
763     /* only save changed variables ....*/
764     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
765     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
766       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
767         $method="https://";
768       }else{
769         $method="http://";
770       }
772       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
773       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
774     }else{
775       $this->gotoKioskProfile= array();
776     }
777     
778     plugin::save();
779     $ldap= $this->config->get_ldap_link();
781     $realyUsedAttrs= array();
783     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
784     /* Creating Kiosk Profiles */
785     foreach($this->newKioskProfiles as $file){
786       $contents = $file['contents'];
787       $fp = @fopen($path."/".$file['name'],"w");
788       if(!$fp){
789         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
790       }else{
791         fwrite($fp,$contents,strlen($contents));
792       }
793       @unlink($file['tmp_name']);
794     }
795  
796     /* Save already used objectClasses */
797     $ocs        = $this->attrs['objectClass'];
798     unset($ocs['count']);
799     $this->attrs = array();
800     $this->attrs['objectClass']= $ocs;
801     foreach($this->objectclasses as $objc){
802       if(!in_array($objc,$this->attrs['objectClass'])){
803         $this->attrs['objectClass'][]=$objc;
804       }
805     }
808     /* Save usersettings to Printer */
810     if(chkacl($this->acl,"gotoPrinter")!=""){
811       $this->gotoPrinter = array();
812     }  
813     
814     if($this->is_group){
815       $s_suffix = "Group";
816     }else{
817       $s_suffix = "User";
818     }
819   
821     /* 1. Search all printers that have our uid/cn as member 
822      * 2. Delete this uid/cn from every single entry and save it again.
823      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
824      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
825      */
826     $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
827     while($attr = $ldap->fetch()){
829       /* Walk trough all printers and check if our user id used, if so remove it.
830        * Later we will insert our uid at the right place.
831        */
833       /* Remove normal entries (User)*/
834       if(isset($attr['goto'.$s_suffix.'Printer'])) {
835         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
836           if($this->uid==$user){
837             unset($attr['goto'.$s_suffix.'Printer'][$key]);
838           }
839         }    
840       }
842       /* Remove administrational entries (Admin)*/
843       if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
844         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
845           if($this->uid==$user){
846             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
847           }
848         }    
849       }
851       /* Extract useable tags, to be able to save all changes 
852        */
853       $attrs_used = array();
854       foreach($attr as $key=>$val){
856         /* If index is numeric, skip it ...*/
857         if((!is_numeric($key))&&($key!="count")){
859           /* If entry contains 'count' remove it */
860           if(is_array($val)&&isset($val['count'])){
861             unset($val['count']);
862           }
863           $attrs_used[$key]=$val;
864         }
865       }
866       /* the result of cleaning the entry is 
867        *  to be able to directly save this again,
868        *  if all changes are made 
869        */
870       $attr= $attrs_used;
872 #fix : Id don't know why such an entry was set ... 
873       if(isset($attr['GOTOADMINPRINTER'])){
874         unset($attr['GOTOADMINPRINTER']);
875       }
877       /* Save changes */
878       $ldap->cd($attr['dn']);
879       unset($attr['dn']);
880 $ldap->modify ($attr); 
882       if($ldap->get_error()!="Success"){
883         print_red(_("Error while writing printer")." : ".$ldap->get_error());
884       }
885     }
887     /* All printers are cleaned, (our cn/uid removed) 
888      *  now we must add our uid / cn 
889      *  to the new configured printers.
890      */
891     foreach($this->gotoPrinter as $printer) {
892       $ldap->cd($printer['dn']);
893       $ldap->cat($printer['dn']);
894       $attrs= $ldap->fetch();
895       $attrs_used = array(); 
896       foreach($attrs as $key=>$val){
897         if((!is_numeric($key))&&($key!="count")){
898           if(is_array($val)&&isset($val['count'])){
899             unset($val['count']);
900           }
901           $attrs_used[$key]=$val;
902         }
903       }
904       /* $attrs contains all values 
905        * we need, to save the entry lateron 
906       */
907       $attrs= $attrs_used;
909       /* Depending on the type (User/Admin) 
910        *  switch these attributes, that makes it easier
911        */
912       if($printer['mode'] == "user"){
913         $attribute  = "goto".$s_suffix."Printer";
914         $attribute2 = "goto".$s_suffix."AdminPrinter";
915       }else{
916         $attribute  = "goto".$s_suffix."AdminPrinter";
917         $attribute2 = "goto".$s_suffix."Printer";
918       }
920       /* If this user is already assigned to $attribute2 
921        * delete user from $attribute2, to be albe to attach him to $attribute
922        * A user can't be admin and normal user for one printer
923        */
924       if(!isset($printer[$attribute2])){
925         $printer[$attribute2]=array();
926       }else{
927         if(in_array($this->uid,$printer[$attribute2])){ 
928           $tmp = array_flip($printer[$attribute2]);
929           unset($tmp[$this->uid]);
930           $attrs[$attribute2]=array_flip($tmp);
931         }
932         /* If Last entry removed, clear attribute*/
933         if(empty($attrs[$attribute2])){
934           $attrs[$attribute2]=array();
935         }
936       }
937     
938       /* Attach user to the $attribute, if he is'nt already attached
939        */
940       if(!isset($attrs[$attribute])){
941         $attrs[$attribute]=array($this->uid);
942       }else{
943         unset($attrs[$attribute]['count']);
944         if(!in_array($this->uid,$attrs[$attribute])){
945           $attrs[$attribute][]=$this->uid;
946         }
947       }
949       $ldap->cd($attrs['dn']);
950       unset($attrs['dn']);
951 $ldap->modify ($attrs); 
953       if($ldap->get_error()!="Success"){
954         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
955       }
956     }
957   
958     /* Prepare HotPlug devices */
959     $this->attrs['gotoHotplugDevice'] = array();
960     foreach($this->gotoHotplugDevices as $name => $device){
961       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
962     }
964     /* Prepare LogonScripts */
965     $this->attrs['gotoLogonScript'] = array();
966     foreach($this->gotoLogonScripts as $name => $script){
967       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
968                                             $script['LogonOverload'].$script['LogonLast']."|".
969                                             $script['LogonPriority']."|".
970                                             base64_encode($script['LogonData'])."|".
971                                             $script['LogonDescription'];
972     }
974     /* Prepare Shares */
975     $this->attrs['gotoShare']=array();
976     foreach($this->gotoShares as $name => $share){
977       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff']."|".$share['Username'];
978     }
981     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile");
982   
983     foreach($saveThis as $tosave){
984       if(!empty($this->$tosave)){
985         $this->attrs[$tosave]=$this->$tosave;
986       }else{
987         $this->attrs[$tosave]=array();
988       }
989     }
990  
991     /* Prepare Flags */
992     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
993     if(empty($this->attrs['gotoProfileFlags'][0])){
994       $this->attrs['gotoProfileFlags']=array();
995       }
997     if($this->useProfile == false){
998       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
999       $this->attrs['gotoProfileServer']= array(); 
1000     }
1002     foreach($this->attributes as $s_attr){
1003       if(chkacl($this->acl,$s_attr)!="") {
1004         if(isset($this->attrs[$s_attr])){
1005           unset($this->attrs[$s_attr]);
1006         }
1007       }
1008     }
1010     $ldap->cat ($this->dn);
1011     if ($ldap->fetch()){
1012       $mode= "modify";
1013     } else {
1014       $mode= "add";
1015       $ldap->cd($this->config->current['BASE']);
1016       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1017     }
1019     $ldap->cd($this->dn);
1020     $this->cleanup();
1021     $ldap->$mode($this->attrs);
1022     if($ldap->get_error()!="Success"){
1023       print_red($ldap->get_error());
1024     }
1025     $this->handle_post_events($mode);
1026   }
1028 /* Generate ListBox frindly output for the defined shares 
1029  * Possibly Add or remove an attribute here, 
1030  */
1031   function printOutAssignedShares()
1032   {
1033     $a_return = array();
1034     if(is_array($this->gotoShares)){
1035       foreach($this->gotoShares as $share){
1036         if (!preg_match('/^!/', $share['server'])){
1037           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1038         }
1039       }
1040     }
1041     return($a_return);
1042   }
1044 /* Generate ListBox frindly output for the definedhotplugs 
1045  * Possibly Add or remove an attribute here,
1046  */
1047 function printOutHotPlugDevices()
1048   {
1049     $a_return= array();
1050     if(is_array($this->gotoHotplugDevices)){
1051       foreach($this->gotoHotplugDevices as $key=>$device){
1052         $a_return[$key] = $device['name']." - ".$device['id'];
1053       }
1054     }
1055     return($a_return);
1056   }
1058   /* Generates ListBox frienly output of used printer devices 
1059    * Append ' - admin' if printer is used in admin mode
1060    */
1061   function printOutPrinterDevices()
1062   {
1063     $a_return = array();
1064     if(is_array($this->gotoPrinter)){
1065       foreach($this->gotoPrinter as $printer){
1066         if($printer['mode'] == "admin"){
1067           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1068         }else{
1069           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1070         }
1071       }
1072     }
1073     return($a_return);
1074   }
1076   /* Generates ListBox frienly output of used logonscripts 
1077    */
1078   function printOutLogonScripts()
1079   {
1080     $a_return = array();
1081     if(is_array($this->gotoLogonScripts)){
1082       foreach($this->gotoLogonScripts as $script){
1083         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1084       }
1085     }
1086     return($a_return);
1087   }
1093 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1094 ?>