Code

Corrected kioskpath parsing
[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['name']      =$tmp[0];
144         $tmp2['mountPoint']=base64_decode($tmp[1]);
145         $this->gotoShares[$tmp[0]]=$tmp2;
146       }
147     }
149     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
150       $chr = $this->gotoProfileFlags[$i];
151       $name = "gotoProfileFlag_".$chr;
152       $this->$name=$chr;
153     }
155     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
156       $this->useProfile = true;
157     }else{
158       $this->useProfile = false;
159     }
161     /* Set to group environment if we editing a group */
162     if(!isset($this->parent)){
163       $this->is_group = true;
164     }
167   }
169   function execute()
170   {
171     /* Fill templating stuff */
172     $smarty= get_smarty();
173     $display= "";
174     /* Is accout enabled | are we editing from usermenu or admin menu 
175        All these tab management is done here
176     */
178     /* Working from Usermenu an the Account is currently disbled
179      * this->parent :  is only set if we are working in a list of tabs
180      * is_account   :  is only true if the needed objectClass is given
181     */
182     if((!isset($this->parent))&&(!$this->is_account)){
183       /* We are currently editing this tab from usermenu, but this account is not enabled */
184       $smarty->assign("is_account",$this->is_account);
185       /* Load template */
186       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
187       /* Avoid the "You are currently editing ...." message when you leave this tab */
188       $display .= back_to_main(); 
189       /* Display our message to the user */
190       return $display;
191     
193     /* We are currently editing from group tabs, because 
194      * $this->parent is set
195      * posixAccount is not set, so we are not in usertabs.
196      */
197     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
198       $smarty->assign("is_account","true");
199       $this->is_group     = true;
200       $this->uid          = $this->cn;
201       $this->attrs['uid'] = $this->cn;
203       /* Change state if needed */
204       if (isset($_POST['modify_state'])){
205         $this->is_account= !$this->is_account;
206       }
208       /* Group Dialog with enabled environment options */
209       if ($this->is_account){
210         $display= $this->show_header(_("Remove environment extension"),
211             _("Environment extension enabled. You can disable it by clicking below."));
212       } else {
213   
214       /* Environment is disabled 
215          If theres is no posixAccount enabled, you won't be able to enable 
216          environment extensions
217        */
218         if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
219           // 4. There is a PosixAccount
220           $display= $this->show_header(_("Add environment extension"),
221               _("Environment extension disabled. You can enable it by clicking below."));
222           return $display;
223         }else{
224           // 4. There is no PosixAccount
225           $display= $this->show_header(_("Add environment extension"),
226               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
227           return $display;
228         }
229       }
230     }else{
231       /* Editing from Usermenu 
232        *  Tell smarty that this accoutn is enabled 
233        */
234       $smarty->assign("is_account","true");
236       /* Do we need to flip is_account state? */
237       if (isset($_POST['modify_state'])){
238         $this->is_account= !$this->is_account;
239       }
241       if(isset($this->parent)){
242         // 3. Account enabled . Editing from adminmenu
243         if ($this->is_account){
244           $display= $this->show_header(_("Remove environment extension"),
245               _("Environment extension enabled. You can disable it by clicking below."));
246         } else {
247           if((isset($this->attrs['objectClass']))
248                 &&((in_array("posixAccount",$this->attrs['objectClass'])))
249                   ||($this->parent->by_object['posixAccount']->is_account==true)){
250             // 4. There is a PosixAccount
251             $display= $this->show_header(_("Add environment extension"),
252                 _("Environment extension disabled. You can enable it by clicking below."));
253             return $display;
254           }else{
255             // 4. There is a PosixAccount
256             $display= $this->show_header(_("Add environment extension"),
257                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
258             return $display;
259           }
260         }
261       }
262     }
263     /* Account is Account : is_accounbt=true.
264      * Else we won't reach this. 
265      */
266    
267     /* Prepare all variables for smarty */
268     foreach($this->attributes as $s_attr){
269       /* Set value*/
270       $smarty->assign($s_attr,$this->$s_attr);
271      
272       /* Set checkbox state*/
273       if(empty($this->$s_attr)){
274         $smarty->assign($s_attr."CHK","");
275       }else{
276         $smarty->assign($s_attr."CHK"," checked ");
277       }
278     
279       /* Prepare ACL settings*/
280       if(chkacl($this->acl,$s_attr)=="") {
281         $smarty->assign($s_attr."ACL","");
282       }else{
283         $smarty->assign($s_attr."ACL"," disabled ");
284       }
285  
286     }
287  
288     if($this->acl != "#none#"){
289       $smarty->assign("useProfileACL","");
290     }else{
291       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
292       $smarty->assign("gotoProfileServer"," disabled ");
293     }
295     /* HANDLE Profile Settings here 
296      * Assign available Quota and resolution settings
297      * Get all available profile server
298      * Get cache checkbox
299      * Assign this all to Smarty 
300      */
302     if(empty($this->useProfile)){
303       $smarty->assign("gotoProfileACL","disabled"); 
304       $smarty->assign("useProfileCHK",""); 
305     }else{
306       $smarty->assign("gotoProfileACL",""); 
307       $smarty->assign("useProfileCHK"," checked "); 
308     }
310     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
311     $this->gotoProfileServers =$this->getShareServerList() ;
313     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
314     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
315     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
317     /* Handle kiosk profiles 
318      * Read available from filesystem
319      * Open management if post is transmitted
320      */
322     /* Open Management Dialog */
323     if(isset($_POST['KioskManagementDialog'])){
324       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
325       $this->dialog->parent= $this;
326       $this->is_dialog = true;
327     }
329     /* Save */
330     if(isset($_POST['KioskClose'])){
331       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
332   
333       unset($this->dialog);
334       $this->dialog=NULL;
335       $this->is_dialog = false;
336     }
337     $tmp = new kioskManagementDialog($this->config,$this->dn);
338     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
340     $smarty->assign("gotoKioskProfiles",$list);
341     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
343     /* Logonscript Management
344      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
345      * Perform add Delete edit Posts 
346      */
348     /* Dialog Save */
349     if(isset($_POST['LogonSave'])){
350       $this->dialog->save_object();
351       if(count($this->dialog->check())!=0){
352         foreach($this->dialog->check() as $msg){
353           print_red($msg);
354         }
355       }else{
356         $tmp = $this->dialog->save();
357         unset($this->dialog);
358         $this->dialog=NULL;
359         $this->is_dialog=false;
360         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
361       }
362     }
363     
364     /* Dialog Quit without saving */
365     if(isset($_POST['LogonCancel'])){
366       $this->is_dialog= false;
367       unset($this->dialog);
368       $this->dialog= NULL;
369     }
370    
371     /* Check Edit Del New Posts for a selected LogonScript */ 
372     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
374       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
375        * In this case we create a new Logon Script.
376        */
377       if(isset($_POST['gotoLogonScriptNew'])){
378         $this->is_dialog = true;
379         $this->dialog = new logonManagementDialog($this->config,$this->dn);
380       }
382       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
383        * We only can delete if there is an entry selected.
384        */
385       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
386         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
387       }
388       
389       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
390        * There must be an entry selected to perform edit request.
391        */
392       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
393         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
394         $this->is_dialog = true;
395         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
396       }
397     }
398      
399     /* Append List to smarty*/
400     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
401     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
403     /* In this section server shares will be defined 
404      * A user can select one of the given shares and a mount point
405      *  and attach this combination to his setup.
406      */
407     
408     $this->gotoShareSelections    = $this->getShareList(true);
409     $this->gotoAvailableShares    = $this->getShareList(false);  
411     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
412     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
414     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
415      * This entry will be, a combination of mountPoint and sharedefinitions 
416      */
417     if(isset($_POST['gotoShareAdd'])){
418       /* We assign a share to this user, if we don't know where to mount the share */
419       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
420         print_red(_("You must specify a valid mount point."));
421       }else{
422         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
423         $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['name']."|".base64_encode($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"));
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]] = $shareAttrs[0]." - ".$shareAttrs[4];
912         }else{
913           $return[$shareAttrs[0]]['name']         = $shareAttrs[0]; 
914           $return[$shareAttrs[0]]['description']  = $shareAttrs[1]; 
915           $return[$shareAttrs[0]]['type']         = $shareAttrs[2]; 
916           $return[$shareAttrs[0]]['charset']      = $shareAttrs[3]; 
917           $return[$shareAttrs[0]]['path']         = $shareAttrs[4]; 
918           $return[$shareAttrs[0]]['option']       = $shareAttrs[5]; 
919         }
920       }
921     }
922     return($return);
923   }
926 /* This function returns all available ShareServer  
927  */
928   function getShareServerList()
929   {
930     $ldap= $this->config->get_ldap_link();
931     $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
932     $return= array();
933     while($entry = $ldap->fetch($a_res)){
934       $return[$entry['cn'][0]] = $entry['cn'][0];
935     }
936     return($return);
937   }
939 /* Generate ListBox frindly output for the defined shares 
940  * Possibly Add or remove an attribute here, 
941  */
942   function printOutAssignedShares()
943   {
944     $a_return = array();
945     if(is_array($this->gotoShares)){
946       foreach($this->gotoShares as $share){
947         $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
948       }
949     }
950     return($a_return);
951   }
953 /* Generate ListBox frindly output for the definedhotplugs 
954  * Possibly Add or remove an attribute here,
955  */
956 function printOutHotPlugDevices()
957   {
958     $a_return= array();
959     if(is_array($this->gotoHotplugDevices)){
960       foreach($this->gotoHotplugDevices as $key=>$device){
961         $a_return[$key] = $device['name']." - ".$device['id'];
962       }
963     }
964     return($a_return);
965   }
967   /* Generates ListBox frienly output of used printer devices 
968    * Append ' - admin' if printer is used in admin mode
969    */
970   function printOutPrinterDevices()
971   {
972     $a_return = array();
973     if(is_array($this->gotoPrinters)){
974       foreach($this->gotoPrinters as $printer){
975         if($printer['mode'] == "admin"){
976           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
977         }else{
978           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
979         }
980       }
981     }
982     return($a_return);
983   }
985   /* Generates ListBox frienly output of used logonscripts 
986    */
987   function printOutLogonScripts()
988   {
989     $a_return = array();
990     if(is_array($this->gotoLogonScripts)){
991       foreach($this->gotoLogonScripts as $script){
992         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
993       }
994     }
995     return($a_return);
996   }
1002 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1003 ?>