Code

Added servername to environment share settings
[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 $gotoPrinters       = array();// All available Printer
42   var $gotoPrinter        = "";     //  The selected Printer
44   /* Share */
45   var $gotoShares         = array();// Currently Share Option
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","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
63                                     "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
64                                     "gotoLogonScripts","gotoLogonScript",
65                                     "gotoPrinters","gotoPrinter",
66                                     "gotoShares","gotoShare","gotoShareSelections",
67                                     "gotoKioskProfile","gotoKioskProfiles",
68                                     "gotoHotplugDevice","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    
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->gotoPrinters[$printer['cn'][0]]=$printer;
92       $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
93     }
94     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
95     while($printer = $ldap->fetch()){
96       $this->gotoPrinters[$printer['cn'][0]]=$printer;
97       $this->gotoPrinters[$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     }
168   }
170   function execute()
171   {
172     /* Fill templating stuff */
173     $smarty= get_smarty();
174     $display= "";
175     /* Is accout enabled | are we editing from usermenu or admin menu 
176        All these tab management is done here
177     */
179     /* Working from Usermenu an the Account is currently disbled
180      * this->parent :  is only set if we are working in a list of tabs
181      * is_account   :  is only true if the needed objectClass is given
182     */
183     if((!isset($this->parent))&&(!$this->is_account)){
184       /* We are currently editing this tab from usermenu, but this account is not enabled */
185       $smarty->assign("is_account",$this->is_account);
186       /* Load template */
187       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
188       /* Avoid the "You are currently editing ...." message when you leave this tab */
189       $display .= back_to_main(); 
190       /* Display our message to the user */
191       return $display;
192     
194     /* We are currently editing from group tabs, because 
195      * $this->parent is set
196      * posixAccount is not set, so we are not in usertabs.
197      */
198     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
199       $smarty->assign("is_account","true");
200       $this->is_group     = true;
201       $this->uid          = $this->cn;
202       $this->attrs['uid'] = $this->cn;
204       /* Change state if needed */
205       if (isset($_POST['modify_state'])){
206         $this->is_account= !$this->is_account;
207       }
209       /* Group Dialog with enabled environment options */
210       if ($this->is_account){
211         $display= $this->show_header(_("Remove environment extension"),
212             _("Environment extension enabled. You can disable it by clicking below."));
213       } else {
214   
215       /* Environment is disabled 
216          If theres is no posixAccount enabled, you won't be able to enable 
217          environment extensions
218        */
219         if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
220           // 4. There is a PosixAccount
221           $display= $this->show_header(_("Add environment extension"),
222               _("Environment extension disabled. You can enable it by clicking below."));
223           return $display;
224         }else{
225           // 4. There is no PosixAccount
226           $display= $this->show_header(_("Add environment extension"),
227               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
228           return $display;
229         }
230       }
231     }else{
232       /* Editing from Usermenu 
233        *  Tell smarty that this accoutn is enabled 
234        */
235       $smarty->assign("is_account","true");
237       /* Do we need to flip is_account state? */
238       if (isset($_POST['modify_state'])){
239         $this->is_account= !$this->is_account;
240       }
242       if(isset($this->parent)){
243         // 3. Account enabled . Editing from adminmenu
244         if ($this->is_account){
245           $display= $this->show_header(_("Remove environment extension"),
246               _("Environment extension enabled. You can disable it by clicking below."));
247         } else {
248           if((isset($this->attrs['objectClass']))
249                 &&((in_array("posixAccount",$this->attrs['objectClass'])))
250                   ||($this->parent->by_object['posixAccount']->is_account==true)){
251             // 4. There is a PosixAccount
252             $display= $this->show_header(_("Add environment extension"),
253                 _("Environment extension disabled. You can enable it by clicking below."));
254             return $display;
255           }else{
256             // 4. There is a PosixAccount
257             $display= $this->show_header(_("Add environment extension"),
258                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
259             return $display;
260           }
261         }
262       }
263     }
264     /* Account is Account : is_accounbt=true.
265      * Else we won't reach this. 
266      */
267    
268     /* Prepare all variables for smarty */
269     foreach($this->attributes as $s_attr){
270       /* Set value*/
271       $smarty->assign($s_attr,$this->$s_attr);
272      
273       /* Set checkbox state*/
274       if(empty($this->$s_attr)){
275         $smarty->assign($s_attr."CHK","");
276       }else{
277         $smarty->assign($s_attr."CHK"," checked ");
278       }
279     
280       /* Prepare ACL settings*/
281       if(chkacl($this->acl,$s_attr)=="") {
282         $smarty->assign($s_attr."ACL","");
283       }else{
284         $smarty->assign($s_attr."ACL"," disabled ");
285       }
286  
287     }
288  
289     if($this->acl != "#none#"){
290       $smarty->assign("useProfileACL","");
291     }else{
292       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
293       $smarty->assign("gotoProfileServer"," disabled ");
294     }
296     /* HANDLE Profile Settings here 
297      * Assign available Quota and resolution settings
298      * Get all available profile server
299      * Get cache checkbox
300      * Assign this all to Smarty 
301      */
303     if(empty($this->useProfile)){
304       $smarty->assign("gotoProfileACL","disabled"); 
305       $smarty->assign("useProfileCHK",""); 
306     }else{
307       $smarty->assign("gotoProfileACL",""); 
308       $smarty->assign("useProfileCHK"," checked "); 
309     }
311     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
312     $this->gotoProfileServers =$this->getShareServerList() ;
314     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
315     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
316     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
318     /* Handle kiosk profiles 
319      * Read available from filesystem
320      * Open management if post is transmitted
321      */
323     /* Open Management Dialog */
324     if(isset($_POST['KioskManagementDialog'])){
325       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
326       $this->dialog->parent= $this;
327       $this->is_dialog = true;
328     }
330     /* Save */
331     if(isset($_POST['KioskClose'])){
332       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
333   
334       unset($this->dialog);
335       $this->dialog=NULL;
336       $this->is_dialog = false;
337     }
338     $tmp = new kioskManagementDialog($this->config,$this->dn);
339     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
341     $smarty->assign("gotoKioskProfiles",$list);
342     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
344     /* Logonscript Management
345      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
346      * Perform add Delete edit Posts 
347      */
349     /* Dialog Save */
350     if(isset($_POST['LogonSave'])){
351       $this->dialog->save_object();
352       if(count($this->dialog->check())!=0){
353         foreach($this->dialog->check() as $msg){
354           print_red($msg);
355         }
356       }else{
357         $tmp = $this->dialog->save();
358         unset($this->dialog);
359         $this->dialog=NULL;
360         $this->is_dialog=false;
361         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
362       }
363     }
364     
365     /* Dialog Quit without saving */
366     if(isset($_POST['LogonCancel'])){
367       $this->is_dialog= false;
368       unset($this->dialog);
369       $this->dialog= NULL;
370     }
371    
372     /* Check Edit Del New Posts for a selected LogonScript */ 
373     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
375       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
376        * In this case we create a new Logon Script.
377        */
378       if(isset($_POST['gotoLogonScriptNew'])){
379         $this->is_dialog = true;
380         $this->dialog = new logonManagementDialog($this->config,$this->dn);
381       }
383       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
384        * We only can delete if there is an entry selected.
385        */
386       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
387         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
388       }
389       
390       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
391        * There must be an entry selected to perform edit request.
392        */
393       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
394         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
395         $this->is_dialog = true;
396         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
397       }
398     }
399      
400     /* Append List to smarty*/
401     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
402     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
404     /* In this section server shares will be defined 
405      * A user can select one of the given shares and a mount point
406      *  and attach this combination to his setup.
407      */
408     
409     $this->gotoShareSelections    = $this->getShareList(true);
410     $this->gotoAvailableShares    = $this->getShareList(false);  
412     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
413     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
415     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
416      * This entry will be, a combination of mountPoint and sharedefinitions 
417      */
418     if(isset($_POST['gotoShareAdd'])){
419       /* We assign a share to this user, if we don't know where to mount the share */
420       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
421         print_red(_("You must specify a valid mount point."));
422       }else{
423         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
424         $s_mount = $_POST['gotoShareMountPoint'];
425         /* Preparing the new assignment */ 
426         $this->gotoShares[$a_share['name']]=$a_share;
427         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
428       }
429     }  
431     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
432      * If there is no defined share selected, we will abort the deletion without any message 
433      */
434     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
435       unset($this->gotoShares[$_POST['gotoShare']]);
436     }
438     $smarty->assign("gotoShares",$this->printOutAssignedShares());
439     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
441     /* Hotplug devices will be handled here 
442      * There are 3 possible methods for this feature
443      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
444      * Delete will erase an entry, the entry must be selcted in the ListBox first
445      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
446      */
448     /* If there is a new entry wanted, open a new entry by initilising the dialog */
449     if(isset($_POST['gotoHotplugDeviceNew'])){
450       $this->dialog = new hotplugDialog($this->config,$this->dn);
451       $this->is_dialog = true;
452     }
454     /* We have to delete the selected hotplug from the list*/
455     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
456       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
457     }
459     /* There are already defined hotplugs from other users we could use */
460     if(isset($_POST['gotoHotplugDeviceUse'])){
461       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
462       $this->is_dialog = true;
463     }
465     /* Dialog Aborted */
466     if(isset($_POST['HotPlugCancel'])){
467       unset($this->dialog);
468       $this->dialog= NULL;
469       $this->is_dialog = false;
470     }
471  
472     /* Dialod saved */
473     if(isset($_POST['HotPlugSave'])){
474       $this->dialog->save_object();
475       if(count($this->dialog->check())!=0){
476         foreach($this->dialog->check() as $msg){
477           print_red($msg);
478         }
479       }else{
480         $this->dialog->save_object();
481         $a_tmp = $this->dialog->save();
482         if(is_array($a_tmp)){
483           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
484         }
485         unset($this->dialog);
486         $this->dialog= NULL;
487         $this->is_dialog = false;
488       }
489     }
490     
491     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
492     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
493   
494     /* Printer Assignment will managed below 
495      * A printer can be assigned in two different ways and two different types
496      * There are 2 types of users assigned to a printer : user and admin
497      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
498      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
499      */ 
500     
501     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
502     if(isset($_POST['gotoPrinterAdd'])){
503       $this->is_dialog=true;
504       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
505     }
507     if(isset($_POST['PrinterCancel'])){
508         $this->is_dialog=false;
509         unset($this->dialog);
510         $this->dialog=NULL;
511     }
513     if(isset($_POST['PrinterSave'])){
514       if(count($this->dialog->check())!=0){
515         $tmp = $this->dialog->check();
516         foreach($tmp as $msg){
517           print_red($msg);
518         } 
519       }else{
520         $this->dialog->save_object();
521         $tmp = $this->dialog->save();
522         $tmp2= $this->dialog->getPrinter(true);
523         $this->gotoPrinters[$tmp]=$tmp2[$tmp];
524         $this->gotoPrinters[$tmp]['mode']="user";
525         $this->is_dialog=false;
526         unset($this->dialog);
527         $this->dialog   =NULL;
528       }
529     }
530   
531     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
532       $printer = $_POST['gotoPrinter'];
533       unset($this->gotoPrinters[$printer]);
534     }
536     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
537       $printer = $_POST['gotoPrinter'];
538       if($this->gotoPrinters[$printer]['mode']=="user"){
539         $this->gotoPrinters[$printer]['mode']="admin";
540       }else{
541         $this->gotoPrinters[$printer]['mode']="user";
542       }
543     }
545     $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
546     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
547  
548     /* General behavior */
549     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
550       $this->dialog->save_object();
551       return ($this->dialog->execute());
552     }
553     if($this->acl != "#none#"){
554       $smarty->assign("useProfileACL","");
555     }else{
556       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
557       $smarty->assign("gotoProfileServerACL"," disabled ");
558     }
560     if(!$this->useProfile){
561       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
562       $smarty->assign("gotoProfileServerACL"," disabled ");
563     }
565     /* Als smarty vars are set. Get smarty template and generate output */
566     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
567     
568     return($display);
569   }
571   function remove_from_parent()
572   {
573     /* only if it was an account*/
574     if (!$this->initially_was_account){
575       return;
576     }
578     /* include global link_info */
579     $ldap= $this->config->get_ldap_link();
581     /* Remove and write to LDAP */
582     plugin::remove_from_parent();
584     /* Don't save our template variables */
585     $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
586                   "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
587                   "gotoPrinter");
588     /* Skip all these attributes */
589     foreach($skip as $del){
590       unset($this->attrs[$del]);
591     }
593     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
595     $ldap->cd($this->dn);
596     $ldap->modify($this->attrs);
598     show_ldap_error($ldap->get_error());
600     /* Optionally execute a command after we're done */
601     $this->handle_post_events("remove");
602   }
605   /* Save data to object */
606   function save_object()
607   {
608     /* Get all Posted vars 
609      * Setup checkboxes 
610      */
611     
612     if(isset($_POST['iamposted'])){
613       plugin::save_object();
614       foreach($this->attributes as $s_attr){
615         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
616         if(isset($_POST[$s_attr])){
617           $this->$s_attr = $_POST[$s_attr];
618         }else{
619           $this->$s_attr = false;
620         }
621       }
622     }
623   }
626   /* Check supplied data */
627   function check()
628   {
629     $message= array();
630   
631     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
632       $message[]=_("Please set a valid profile quota size.");
633     } 
634     if(!isset($this->attrs['objectClass'])){
635       $this->attrs['objectClass']=array();
636     } 
637     if(!$this->is_group){
638       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
639         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
640       }
641     }
642     return ($message);
643   }
646   /* Save to LDAP */
647   function save()
648   {
649     plugin::save();
650     $ldap= $this->config->get_ldap_link();
652     $realyUsedAttrs= array();
655     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
656     /* Creating Kiosk Profiles */
657     foreach($this->newKioskProfiles as $file){
658       $contents = $file['contents'];
659       $fp = @fopen($path."/".$file['name'],"w");
660       if(!$fp){
661         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
662       }else{
663         fwrite($fp,$contents,strlen($contents));
664       }
665       @unlink($file['tmp_name']);
666     }
667  
668     /* Save already used objectClasses */
669     $ocs        = $this->attrs['objectClass'];
670     unset($ocs['count']);
671     $this->attrs = array();
672     $this->attrs['objectClass']= $ocs;
673     foreach($this->objectclasses as $objc){
674       if(!in_array($objc,$this->attrs['objectClass'])){
675         $this->attrs['objectClass'][]=$objc;
676       }
677     }
680     /* Save usersettings to Printer */
682     if(chkacl($this->acl,"gotoPrinter")!=""){
683       $this->gotoPrinters = array();
684     }  
685     
686     if($this->is_group){
687       $s_suffix = "Group";
688     }else{
689       $s_suffix = "User";
690     }
691   
693     if(count($this->gotoPrinters)==0){
694       $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
695       while($attr = $ldap->fetch()){
696       
697         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
698           if($this->uid==$user){
699             unset($attr['goto'.$s_suffix.'Printer'][$key]);
700           }
701         }    
703         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
704           if($this->uid==$user){
705             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
706           }
707         }    
709         $attrs_used = array();
710         foreach($attr as $key=>$val){
711           if((!is_numeric($key))&&($key!="count")){
712             if(is_array($val)&&isset($val['count'])){
713               unset($val['count']);
714             }
715             $attrs_used[$key]=$val;
716           }
717         }
718         $attr= $attrs_used;
719         $tmp =array();
720         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $print){
721           $tmp[]=$print;
722         }
723         $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
725         $tmp =array();
726         foreach($attr['goto'.$s_suffix.'Printer'] as $print){
727           $tmp[]=$print;
728         }
729         $attr['goto'.$s_suffix.'Printer'] = $tmp;
731         $ldap->cd($attr['dn']);
732         unset($attr['dn']);
733         $ldap->modify($attr);
734         if($ldap->get_error()!="Success"){
735           print_red(_("Error while writing printer")." : ".$ldap->get_error());
736         }
737       }
738     }    
740     foreach($this->gotoPrinters as $printer) {
741       $ldap->cd($printer['dn']);
742       $ldap->cat($printer['dn']);
743       $attrs= $ldap->fetch();
744       $attrs_used = array(); 
745       foreach($attrs as $key=>$val){
746         if((!is_numeric($key))&&($key!="count")){
747           if(is_array($val)&&isset($val['count'])){
748             unset($val['count']);
749           }
750           $attrs_used[$key]=$val;
751         }
752       }
753       $attrs= $attrs_used;
755       /* Filter entries */
756  
757       if($printer['mode'] == "user"){
758         $attribute  = "goto".$s_suffix."Printer";
759         $attribute2 = "goto".$s_suffix."AdminPrinter";
760       }else{
761         $attribute  = "goto".$s_suffix."AdminPrinter";
762         $attribute2 = "goto".$s_suffix."UserPrinter";
763       }
765       /* If this user is already assigned to $attribute2 
766        * delete user from $attribute2, to be albe to attach him to $attribute
767        * A user can't be admin and normal user for one printer
768        */
769       if(!isset($printer[$attribute2])){
770         $printer[$attribute2]=array();
771       }else{
772         if(in_array($this->uid,$printer[$attribute2])){ 
773           $tmp = array_flip($attrs[$attribute2]);
774           unset($tmp[$this->uid]);
775           $attrs[$attribute2]=array_flip($tmp);
776         }
777         /* If Last entry removed, clear attribute*/
778         if(empty($attrs[$attribute2])){
779           $attrs[$attribute2]=array();
780         }
781       }
782     
783       /* Attach user to the $attribute, if he is'nt already attached
784        */
785       if(!isset($attrs[$attribute])){
786         $attrs[$attribute]=array($this->uid);
787       }else{
788         unset($attrs[$attribute]['count']);
789         if(!in_array($this->uid,$attrs[$attribute])){
790           $attrs[$attribute][]=$this->uid;
791         }
792       }
794       $tmp =array();
795       if(isset($attrs['goto'.$s_suffix.'AdminPrinter'])){
796         foreach($attrs['goto'.$s_suffix.'AdminPrinter'] as $print){
797           $tmp[]=$print;
798         }
799       }
800       $attrs['goto'.$s_suffix.'AdminPrinter'] = $tmp;
802       $tmp =array();
803       if(isset($attrs['goto'.$s_suffix.'Printer'])){
804         foreach($attrs['goto'.$s_suffix.'Printer'] as $print){
805           $tmp[]=$print;
806         }
807       }
808       $attrs['goto'.$s_suffix.'Printer'] = $tmp;
810       $ldap->cd($attrs['dn']);
811       unset($attrs['dn']);
812       $ldap->modify($attrs);
813       if($ldap->get_error()!="Success"){
814         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
815       }
816     }
817   
818     if(isset($this->attrs['gotoPrinter'])){
819       unset($this->attrs['gotoPrinter']);
820     }
821  
822     /* Prepare HotPlug devices */
823     $this->attrs['gotoHotplugDevice'] = array();
824     foreach($this->gotoHotplugDevices as $name => $device){
825       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
826     }
828     /* Prepare LogonScripts */
829     $this->attrs['gotoLogonScript'] = array();
830     foreach($this->gotoLogonScripts as $name => $script){
831       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
832                                             $script['LogonOverload'].$script['LogonLast']."|".
833                                             $script['LogonPriority']."|".
834                                             base64_encode($script['LogonData'])."|".
835                                             $script['LogonDescription'];
836     }
838     /* Prepare Shares */
839     $this->attrs['gotoShare']=array();
840     foreach($this->gotoShares as $name => $share){
841       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint'];
842     }
844     if(!empty($this->gotoKioskProfile)){
845       $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
846     }else{
847       $this->attrs['gotoKioskProfile']= array();
848     }
850     $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
851   
852     foreach($saveThis as $tosave){
853       if(!empty($this->$tosave)){
854         $this->attrs[$tosave]=$this->$tosave;
855       }else{
856         $this->attrs[$tosave]=array();
857       }
858     }
859  
860     /* Prepare Flags */
861     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
862     if(empty($this->attrs['gotoProfileFlags'][0])){
863       $this->attrs['gotoProfileFlags']=array();
864       }
866     if($this->useProfile == false){
867       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
868       $this->attrs['gotoProfileServer']= array(); 
869     }
871     foreach($this->attributes as $s_attr){
872       if(chkacl($this->acl,$s_attr)!="") {
873         if(isset($this->attrs[$s_attr])){
874           unset($this->attrs[$s_attr]);
875         }
876       }
877     }
879     $ldap->cat ($this->dn);
880     if ($ldap->fetch()){
881       $mode= "modify";
882     } else {
883       $mode= "add";
884       $ldap->cd($this->config->current['BASE']);
885       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
886     }
888     $ldap->cd($this->dn);
889     $ldap->$mode($this->attrs);
890     if($ldap->get_error()!="Success"){
891       print_red($ldap->get_error());
892     }
893     $this->handle_post_events($mode);
894   }
896 /* This function returns all available Shares defined in this ldap 
897  * There are two ways to call this function, if listboxEntry is true
898  *  only name and path are attached to the array, in it is false, the whole 
899  *  entry will be parsed an atached to the result.
900  */
901   function getShareList($listboxEntry = false)
902   {
903     $ldap= $this->config->get_ldap_link();
904     $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
905     $return= array();
906     while($entry = $ldap->fetch($a_res)){
907       unset($entry['goExportEntry']['count']);
908       foreach($entry['goExportEntry'] as $export){
909         $shareAttrs = split("\|",$export);
910         if($listboxEntry) { 
911           $return[$shareAttrs[0].$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
912         }else{
913           $return[$shareAttrs[0].$entry['cn'][0]]['server']       = $entry['cn'][0];
914           $return[$shareAttrs[0].$entry['cn'][0]]['name']         = $shareAttrs[0]; 
915           $return[$shareAttrs[0].$entry['cn'][0]]['description']  = $shareAttrs[1]; 
916           $return[$shareAttrs[0].$entry['cn'][0]]['type']         = $shareAttrs[2]; 
917           $return[$shareAttrs[0].$entry['cn'][0]]['charset']      = $shareAttrs[3]; 
918           $return[$shareAttrs[0].$entry['cn'][0]]['path']         = $shareAttrs[4]; 
919           $return[$shareAttrs[0].$entry['cn'][0]]['option']       = $shareAttrs[5]; 
920         }
921       }
922     }
923     return($return);
924   }
927 /* This function returns all available ShareServer  
928  */
929   function getShareServerList()
930   {
931     $ldap= $this->config->get_ldap_link();
932     $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
933     $return= array();
934     while($entry = $ldap->fetch($a_res)){
935       unset($entry['goExportEntry']['count']);
936       foreach($entry['goExportEntry'] as $share){
937         $a_share = split("\|",$share);
938         $sharename = $a_share[0];
939         $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
940       }
941     }
942     return($return);
943   }
945 /* Generate ListBox frindly output for the defined shares 
946  * Possibly Add or remove an attribute here, 
947  */
948   function printOutAssignedShares()
949   {
950     $a_return = array();
951     if(is_array($this->gotoShares)){
952       foreach($this->gotoShares as $share){
953         $a_return[$share['name']]= $share['name']." [".$share['server']."]";
954       }
955     }
956     return($a_return);
957   }
959 /* Generate ListBox frindly output for the definedhotplugs 
960  * Possibly Add or remove an attribute here,
961  */
962 function printOutHotPlugDevices()
963   {
964     $a_return= array();
965     if(is_array($this->gotoHotplugDevices)){
966       foreach($this->gotoHotplugDevices as $key=>$device){
967         $a_return[$key] = $device['name']." - ".$device['id'];
968       }
969     }
970     return($a_return);
971   }
973   /* Generates ListBox frienly output of used printer devices 
974    * Append ' - admin' if printer is used in admin mode
975    */
976   function printOutPrinterDevices()
977   {
978     $a_return = array();
979     if(is_array($this->gotoPrinters)){
980       foreach($this->gotoPrinters as $printer){
981         if($printer['mode'] == "admin"){
982           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
983         }else{
984           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
985         }
986       }
987     }
988     return($a_return);
989   }
991   /* Generates ListBox frienly output of used logonscripts 
992    */
993   function printOutLogonScripts()
994   {
995     $a_return = array();
996     if(is_array($this->gotoLogonScripts)){
997       foreach($this->gotoLogonScripts as $script){
998         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
999       }
1000     }
1001     return($a_return);
1002   }
1008 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1009 ?>