Code

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