Code

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