Code

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