Code

725fbdf93f7923dc1805bfd51c62df4442ffb565
[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                  = "";
18   /* Attribute definition
19    */
21   /* profile management */
22   var $useProfile         = false;  // Specifies if we want to use a Server 
23   var $gotoProfileServer  = "";     // Specifies the selected profile server
24   var $gotoProfileServers = array();// Specifies all available and selectable servers
25   var $gotoProfileFlags   = "";     // Flags enabled  ? only used to set ACL and save 
26   var $gotoProfileFlag_C  = "";     // Flag is set to C if we have the profile caching fucntion enabled 
27   
28   var $gotoXResolution    = "";     // The selected resolution eg: 1024x768
29   var $gotoXResolutions   = array();// Contains all available resolutions for this account
30   var $gotoProfileFlag_L  = "";     // Flag is set to L to enable runtime resolution change 
31   var $gotoProfileQuota   = "";     // User Quota Settings
33   /* Logon script section*/
34   var $gotoLogonScripts   = array();// Contains all available Logon Scripts  
35   var $gotoLogonScript    = "";     // The selected Logon Script
37   /* Printer */
38   var $gotoPrinters       = array();// All available Printer
39   var $gotoPrinter        = "";     //  The selected Printer
41   /* Share */
42   var $gotoShares         = array();// Currently Share Option
43   var $gotoShare          = "";     // currently selected Share Option
44   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45   var $gotoAvailableShares= array();// Available Shares for this account
46   
47   /* Kiosk profile */
48   var $gotoKioskProfile   = "";     // The selected Kiosk Profile
49   var $gotoKioskProfiles  = array();// All available Kiosk profiles
51   /* Hotplug Devices */
52   var $gotoHotplugDevice  = "";     // Selected hotplug
53   var $gotoHotplugDevices = array();// Already configured hotplug devices 
56   /* general settings */
57   // Sets the attributes which will kept on page reload, which will be saved, ...
58   var $attributes         = array("uid","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
59                                     "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
60                                     "gotoLogonScripts","gotoLogonScript",
61                                     "gotoPrinters","gotoPrinter",
62                                     "gotoShares","gotoShare","gotoShareSelections",
63                                     "gotoKioskProfile","gotoKioskProfiles",
64                                     "gotoHotplugDevice","gotoHotplugDevices");
65   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
67   function environment ($config, $dn= NULL)
68   {
69     plugin::plugin ($config, $dn);
71     /* Get all Printer assignments */
72     $ldap = $this->config->get_ldap_link();
73     $ldap->cd($this->config->current['BASE']);
74     $ldap->search("(&(objectClass=gotoPrinter)(gotoUserPrinter=".$this->uid."))",array("*"));
75     while($printer = $ldap->fetch()){
76       $this->gotoPrinters[$printer['cn'][0]]=$printer;
77       $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
78     }
79     $ldap->search("(&(objectClass=gotoPrinter)(gotoAdminPrinter=".$this->uid."))",array("*"));
80     while($printer = $ldap->fetch()){
81       $this->gotoPrinters[$printer['cn'][0]]=$printer;
82       $this->gotoPrinters[$printer['cn'][0]]['mode']="admin";
83     }
84     
85     /* prepare hotplugs */
86     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
87       unset($this->attrs['gotoHotplugDevice']['count']);
88       foreach($this->attrs['gotoHotplugDevice'] as $device){
89         $tmp = $tmp2 = array();
90         $tmp = split("\|",$device);
91         $tmp2['name']        = $tmp[0]; 
92         $tmp2['description'] = $tmp[1]; 
93         $tmp2['id']          = $tmp[2]; 
94         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
95       }
96     }
97     
98     /* prepare LogonScripts */
99     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
100       unset($this->attrs['gotoLogonScript']['count']);
101       foreach($this->attrs['gotoLogonScript'] as $device){
102         $tmp = $tmp2 = array();
103         $tmp = split("\|",$device);
104         $tmp2['LogonName']        = $tmp[0]; 
105         $tmp2['LogonPriority']    = $tmp[2]; 
106         if(preg_match("/O/i",$tmp[1])){
107           $tmp2['LogonOverload'] = "O";
108         }else{
109           $tmp2['LogonOverload'] = "";
110         }
111         if(preg_match("/L/i",$tmp[1])){
112           $tmp2['LogonLast'] = "L";
113         }else{
114           $tmp2['LogonLast'] = "";
115         }
116         $tmp2['LogonData']        = base64_decode($tmp[3]); 
117         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
118       }
119     }
120     
121     /* Prepare Shares */
122     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
123       unset($this->attrs['gotoShare']['count']);
124       foreach($this->attrs['gotoShare'] as $share){
125         $tmp = $tmp2 = array();
126         $tmp = split("\|",$share);
127         $tmp2['name']      =$tmp[0];
128         $tmp2['mountPoint']=$tmp[1];
129         $this->gotoShares[$tmp[0]]=$tmp2;
130       }
131     }
133     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
134       $chr = $this->gotoProfileFlags[$i];
135       $name = "gotoProfileFlag_".$chr;
136       $this->$name=$chr;
137     }
139     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
140       $this->useProfile = true;
141     }else{
142       $this->useProfile = false;
143     }
145   }
147   function execute()
148   {
149     /* Fill templating stuff */
150     $smarty= get_smarty();
151     $display= "";
152     /* Is accout enabled | are we editing from usermenu or admin menu 
153        All these tab management is done here
154     */
156     // 1. Account disabled . Editing from usermenu
157     if((!isset($this->parent))&&(!$this->is_account)){
158       /* We are currently editing this tab from usermenu, but this account is not enabled */
159       $smarty->assign("is_account",$this->is_account);
160       /* Load template */
161       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
162       /* Avoid the "You are currently editing ...." message when you leave this tab */
163       $display .= back_to_main(); 
164       /* Display our message to the user */
165       return $display;
167     // Account is enabled
168     }else{
169       /* Tell smarty that this accoutn is enabled */
170       $smarty->assign("is_account","true");
172       /* Do we need to flip is_account state? */
173       if (isset($_POST['modify_state'])){
174         $this->is_account= !$this->is_account;
175       }
176       if(!isset($this->parent)){
177           // 3. ? Account Enabled . Editing from usermenu        
179       }else{
180         // 3. Account enabled . Editing from adminmenu
181         if ($this->is_account){
182           $display= $this->show_header(_("Remove environment extension"),
183               _("This server has environment extension enabled. You can disable it by clicking below."));
184         } else {
185           if((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)){
186             // 4. There is a PosixAccount
187             $display= $this->show_header(_("Add environment extension"),
188                 _("This server has environment extension disabled. You can enable it by clicking below."));
189             return $display;
190           }else{
191             // 4. There is a PosixAccount
192             $display= $this->show_header(_("Add environment extension"),
193                 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
194             return $display;
195           }
196         }
197       }
198     }
199     /* Account is Account : is_accounbt=true.
200      * Else we won't reach this. 
201      */
202    
203     /* Prepare all variables for smarty */
204     foreach($this->attributes as $s_attr){
205       /* Set value*/
206       $smarty->assign($s_attr,$this->$s_attr);
207      
208       /* Set checkbox state*/
209       if(empty($this->$s_attr)){
210         $smarty->assign($s_attr."CHK","");
211       }else{
212         $smarty->assign($s_attr."CHK"," checked ");
213       }
214     
215       /* Prepare ACL settings*/
216       if(chkacl($this->acl,$s_attr)=="") {
217         $smarty->assign($s_attr."ACL","");
218       }else{
219         $smarty->assign($s_attr."ACL"," disabled ");
220       }
221  
222     }
223  
224     if($this->acl != "#none#"){
225       $smarty->assign("useProfileACL","");
226     }else{
227       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
228       $smarty->assign("gotoProfileServer"," disabled ");
229     }
231     /* HANDLE Profile Settings here 
232      * Assign available Quota and resolution settings
233      * Get all available profile server
234      * Get cache checkbox
235      * Assign this all to Smarty 
236      */
238     if(empty($this->useProfile)){
239       $smarty->assign("gotoProfileACL","disabled"); 
240       $smarty->assign("useProfileCHK",""); 
241     }else{
242       $smarty->assign("gotoProfileACL",""); 
243       $smarty->assign("useProfileCHK"," checked "); 
244     }
246     $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
247     $this->gotoProfileServers = array("none","none1");
249     $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
250     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
252     /* Handle kiosk profiles 
253      * Read available from filesystem
254      * Open management if post is transmitted
255      */
256     $tmp = new kioskManagementDialog($this->config,$this->dn);
257     $list = $tmp->getKioskProfiles();
259     $smarty->assign("gotoKioskProfiles",$list);
260     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
262     /* Open Management Dialog */
263     if(isset($_POST['KioskManagementDialog'])){
264       $this->dialog = new kioskManagementDialog($this->config,$this->dn); 
265       $this->is_dialog = true;
266     }
268     /* Save */
269     if(isset($_POST['KioskClose'])){
270       unset($this->dialog);
271       $this->dialog=NULL;
272       $this->is_dialog = false;
273     }
275     /* Logonscript Management
276      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
277      * Perform add Delete edit Posts 
278      */
280     /* Dialog Save */
281     if(isset($_POST['LogonSave'])){
282       $this->dialog->save_object();
283       if(count($this->dialog->check())!=0){
284         foreach($this->dialog->check() as $msg){
285           print_red($msg);
286         }
287       }else{
288         $tmp = $this->dialog->save();
289         unset($this->dialog);
290         $this->dialog=NULL;
291         $this->is_dialog=false;
292         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
293       }
294     }
295     
296     /* Dialog Quit without saving */
297     if(isset($_POST['LogonCancel'])){
298       $this->is_dialog= false;
299       unset($this->dialog);
300       $this->dialog= NULL;
301     }
302    
303     /* Check Edit Del New Posts for a selected LogonScript */ 
304     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
306       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
307        * In this case we create a new Logon Script.
308        */
309       if(isset($_POST['gotoLogonScriptNew'])){
310         $this->is_dialog = true;
311         $this->dialog = new logonManagementDialog($this->config,$this->dn);
312       }
314       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
315        * We only can delete if there is an entry selected.
316        */
317       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
318         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
319       }
320       
321       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
322        * There must be an entry selected to perform edit request.
323        */
324       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
325         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
326         $this->is_dialog = true;
327         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
328       }
329     }
330      
331     /* Append List to smarty*/
332     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
333     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
335     /* In this section server shares will be defined 
336      * A user can select one of the given shares and a mount point
337      *  and attach this combination to his setup.
338      */
339     
340     $this->gotoShareSelections    = $this->getShareList(true);
341     $this->gotoAvailableShares    = $this->getShareList(false);  
343     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
344     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
346     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
347      * This entry will be, a combination of mountPoint and sharedefinitions 
348      */
349     if(isset($_POST['gotoShareAdd'])){
350       /* We assign a share to this user, if we don't know where to mount the share */
351       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))){
352         print_red("You must specify a valid mount point.");
353       }else{
354         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
355         $s_mount = $_POST['gotoShareMountPoint'];
357         /* Preparing the new assignment */ 
358         $this->gotoShares[$a_share['name']]=$a_share;
359         $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
360       }
361     }  
363     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
364      * If there is no defined share selected, we will abort the deletion without any message 
365      */
366     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
367       unset($this->gotoShares[$_POST['gotoShare']]);
368     }
370     $smarty->assign("gotoShares",$this->printOutAssignedShares());
371     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
373     /* Hotplug devices will be handled here 
374      * There are 3 possible methods for this feature
375      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
376      * Delete will erase an entry, the entry must be selcted in the ListBox first
377      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
378      */
380     /* If there is a new entry wanted, open a new entry by initilising the dialog */
381     if(isset($_POST['gotoHotplugDeviceNew'])){
382       $this->dialog = new hotplugDialog($this->config,$this->dn);
383       $this->is_dialog = true;
384     }
386     /* We have to delete the selected hotplug from the list*/
387     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
388       unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
389     }
391     /* There are already defined hotplugs from other users we could use */
392     if(isset($_POST['gotoHotplugDeviceUse'])){
393       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
394       $this->is_dialog = true;
395     }
397     /* Dialog Aborted */
398     if(isset($_POST['HotPlugCancel'])){
399       unset($this->dialog);
400       $this->dialog= NULL;
401       $this->is_dialog = false;
402     }
403  
404     /* Dialod saved */
405     if(isset($_POST['HotPlugSave'])){
406       $this->dialog->save_object();
407       if(count($this->dialog->check())!=0){
408         foreach($this->dialog->check() as $msg){
409           print_red($msg);
410         }
411       }else{
412         $this->dialog->save_object();
413         $a_tmp = $this->dialog->save();
414         if(is_array($a_tmp)){
415           $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp; 
416         }
417         unset($this->dialog);
418         $this->dialog= NULL;
419         $this->is_dialog = false;
420       }
421     }
422     
423     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
424     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
425   
426     /* Printer Assignment will managed below 
427      * A printer can be assigned in two different ways and two different types
428      * There are 2 types of users assigned to a printer : user and admin
429      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
430      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
431      */ 
432     
433     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
434     if(isset($_POST['gotoPrinterAdd'])){
435       $this->is_dialog=true;
436       $this->dialog = new selectPrinterDialog($this->config,$this->dn);
437     }
439     if(isset($_POST['PrinterCancel'])){
440         $this->is_dialog=false;
441         unset($this->dialog);
442         $this->dialog=NULL;
443     }
445     if(isset($_POST['PrinterSave'])){
446       if(count($this->dialog->check())!=0){
447         $tmp = $this->dialog->check();
448         foreach($tmp as $msg){
449           print_red($msg);
450         } 
451       }else{
452         $this->dialog->save_object();
453         $tmp = $this->dialog->save();
454         $tmp2= $this->dialog->getPrinter(true);
455         $this->gotoPrinters[$tmp]=$tmp2[$tmp];
456         $this->gotoPrinters[$tmp]['mode']="user";
457         $this->is_dialog=false;
458         unset($this->dialog);
459         $this->dialog   =NULL;
460       }
461     }
462   
463     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
464       $printer = $_POST['gotoPrinter'];
465       unset($this->gotoPrinters[$printer]);
466     }
468     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
469       $printer = $_POST['gotoPrinter'];
470       if($this->gotoPrinters[$printer]['mode']=="user"){
471         $this->gotoPrinters[$printer]['mode']="admin";
472       }else{
473         $this->gotoPrinters[$printer]['mode']="user";
474       }
475     }
477     $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
478     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
479  
480     /* General behavior */
481     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
482       $this->dialog->save_object();
483       return ($this->dialog->execute());
484     }
485     if($this->acl != "#none#"){
486       $smarty->assign("useProfileACL","");
487     }else{
488       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
489       $smarty->assign("gotoProfileServerACL"," disabled ");
490     }
492     if(!$this->useProfile){
493       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
494       $smarty->assign("gotoProfileServerACL"," disabled ");
495     }
500     /* Als smarty vars are set. Get smarty template and generate output */
501     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
502     
503     return($display);
504   }
506   function remove_from_parent()
507   {
508     /* only if it was an account*/
509     if (!$this->initially_was_account){
510       return;
511     }
513     /* include global link_info */
514     $ldap= $this->config->get_ldap_link();
516     /* Remove and write to LDAP */
517     plugin::remove_from_parent();
519     /* Don't save our template variables */
520     $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
521                   "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
522                   "gotoPrinter");
523     /* Skip all these attributes */
524     foreach($skip as $del){
525       unset($this->attrs[$del]);
526     }
528     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
530     $ldap->cd($this->dn);
531     $ldap->modify($this->attrs);
533     show_ldap_error($ldap->get_error());
535     /* Optionally execute a command after we're done */
536     $this->handle_post_events("remove");
537   }
540   /* Save data to object */
541   function save_object()
542   {
543     /* Get all Posted vars 
544      * Setup checkboxes 
545      */
546     
547     if(isset($_POST['iamposted'])){
548       plugin::save_object();
549       foreach($this->attributes as $s_attr){
550         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
551         if(isset($_POST[$s_attr])){
552           $this->$s_attr = $_POST[$s_attr];
553         }else{
554           $this->$s_attr = false;
555         }
556       }
557     }
558   }
561   /* Check supplied data */
562   function check()
563   {
564     $message= array();
565     return ($message);
566   }
569   /* Save to LDAP */
570   function save()
571   {
572     plugin::save();
573     $ldap= $this->config->get_ldap_link();
575     $realyUsedAttrs= array();
576   
577  
578     
579   
580     /* Save already used objectClasses */
581     $ocs        = $this->attrs['objectClass'];
582     unset($ocs['count']);
583     $this->attrs = array();
584     $this->attrs['objectClass']= $ocs;
585     foreach($this->objectclasses as $objc){
586       if(!in_array($objc,$this->attrs['objectClass'])){
587         $this->attrs['objectClass'][]=$objc;
588       }
589     }
592     /* Save usersettings to Printer */
594     if(chkacl($this->acl,"gotoPrinter")!=""){
595       $this->gotoPrinters = array();
596     }  
598     if(count($this->gotoPrinters)==0){
599       $ldap->search("(&(objectClass=gotoPrinter)(|(gotoUserPrinter=".$this->uid.")(gotoAdminPrinter=".$this->uid.")))",array("*"));
600       while($attr = $ldap->fetch()){
601       
602         foreach($attr['gotoUserPrinter'] as $key => $user){
603           if($this->uid==$user){
604             unset($attr['gotoUserPrinter'][$key]);
605           }
606         }    
608         foreach($attr['gotoAdminPrinter'] as $key => $user){
609           if($this->uid==$user){
610             unset($attr['gotoAdminPrinter'][$key]);
611           }
612         }    
614         $attrs_used = array();
615         foreach($attr as $key=>$val){
616           if((!is_numeric($key))&&($key!="count")){
617             if(is_array($val)&&isset($val['count'])){
618               unset($val['count']);
619             }
620             $attrs_used[$key]=$val;
621           }
622         }
623         $attr= $attrs_used;
624         $tmp =array();
625         foreach($attr['gotoAdminPrinter'] as $print){
626           $tmp[]=$print;
627         }
628         $attr['gotoAdminPrinter'] = $tmp;
630         $tmp =array();
631         foreach($attr['gotoUserPrinter'] as $print){
632           $tmp[]=$print;
633         }
634         $attr['gotoUserPrinter'] = $tmp;
636         $ldap->cd($attr['dn']);
637         unset($attr['dn']);
638         $ldap->modify($attr);
639         if($ldap->get_error()!="Success"){
640           print_red("Printer saving ".$ldap->get_error());
641         }
642       }
643     }    
645     foreach($this->gotoPrinters as $printer) {
646       $ldap->cd($printer['dn']);
647       $ldap->cat($printer['dn']);
648       $attrs= $ldap->fetch();
649       $attrs_used = array(); 
650       foreach($attrs as $key=>$val){
651         if((!is_numeric($key))&&($key!="count")){
652           if(is_array($val)&&isset($val['count'])){
653             unset($val['count']);
654           }
655           $attrs_used[$key]=$val;
656         }
657       }
658       $attrs= $attrs_used;
660       /* Filter entries */
661  
662       if($printer['mode'] == "user"){
663         $attribute  = "gotoUserPrinter";
664         $attribute2 = "gotoAdminPrinter";
665       }else{
666         $attribute  = "gotoAdminPrinter";
667         $attribute2 = "gotoUserPrinter";
668       }
670       /* If this user is already assigned to $attribute2 
671        * delete user from $attribute2, to be albe to attach him to $attribute
672        * A user can't be admin and normal user for one printer
673        */
674       if(!isset($printer[$attribute2])){
675         $printer[$attribute2]=array();
676       }else{
677         if(in_array($this->uid,$printer[$attribute2])){ 
678           $tmp = array_flip($attrs[$attribute2]);
679           unset($tmp[$this->uid]);
680           $attrs[$attribute2]=array_flip($tmp);
681         }
682         /* If Last entry removed, clear attribute*/
683         if(empty($attrs[$attribute2])){
684           $attrs[$attribute2]=array();
685         }
686       }
687     
688       /* Attach user to the $attribute, if he is'nt already attached
689        */
690       if(!isset($attrs[$attribute])){
691         $attrs[$attribute]=array($this->uid);
692       }else{
693         unset($attrs[$attribute]['count']);
694         if(!in_array($this->uid,$attrs[$attribute])){
695           $attrs[$attribute][]=$this->uid;
696         }
697       }
699       $tmp =array();
700       if(isset($attrs['gotoAdminPrinter'])){
701         foreach($attrs['gotoAdminPrinter'] as $print){
702           $tmp[]=$print;
703         }
704       }
705       $attrs['gotoAdminPrinter'] = $tmp;
707       $tmp =array();
708       if(isset($attrs['gotoUserPrinter'])){
709         foreach($attrs['gotoUserPrinter'] as $print){
710           $tmp[]=$print;
711         }
712       }
713       $attrs['gotoUserPrinter'] = $tmp;
715       $ldap->cd($attrs['dn']);
716       unset($attrs['dn']);
717       $ldap->modify($attrs);
718       if($ldap->get_error()!="Success"){
719         print_red("Printer saving ".$ldap->get_error());
720       }
721     }
722   
723     if(isset($this->attrs['gotoPrinter'])){
724       unset($this->attrs['gotoPrinter']);
725     }
726  
727     /* Prepare HotPlug devices */
728     $this->attrs['gotoHotplugDevice'] = array();
729     foreach($this->gotoHotplugDevices as $name => $device){
730       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
731     }
733     /* Prepare LogonScripts */
734     $this->attrs['gotoLogonScript'] = array();
735     foreach($this->gotoLogonScripts as $name => $script){
736       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
737                                             $script['LogonOverload'].$script['LogonLast']."|".
738                                             $script['LogonPriority']."|".
739                                             base64_encode($script['LogonData']); 
740     }
742     /* Prepare Shares */
743     $this->attrs['gotoShare']=array();
744     foreach($this->gotoShares as $name => $share){
745       $this->attrs['gotoShare'][] = $share['name']."|".$share['mountPoint'];
746     }
748     if(!empty($this->gotoKioskProfile)){
749       $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
750     }else{
751       $this->attrs['gotoKioskProfile']= array();
752     }
754     $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
755   
756     foreach($saveThis as $tosave){
757       if(!empty($this->$tosave)){
758         $this->attrs[$tosave]=$this->$tosave;
759       }else{
760         $this->attrs[$tosave]=array();
761       }
762     }
763  
764     /* Prepare Flags */
765     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
766     if(empty($this->attrs['gotoProfileFlags'][0])){
767       $this->attrs['gotoProfileFlags']=array();
768       }
770     if($this->useProfile == false){
771       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
772       $this->attrs['gotoProfileServer']= array(); 
773     }
775     foreach($this->attributes as $s_attr){
776       if(chkacl($this->acl,$s_attr)!="") {
777         if(isset($this->attrs[$s_attr])){
778           unset($this->attrs[$s_attr]);
779         }
780       }
781     }
783     $ldap->cat ($this->dn);
784     if ($ldap->fetch()){
785       $mode= "modify";
786     } else {
787       $mode= "add";
788       $ldap->cd($this->config->current['BASE']);
789       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
790     }
792     $ldap->cd($this->dn);
793     $ldap->$mode($this->attrs);
794     if($ldap->get_error()!="Success"){
795       print_red($ldap->get_error());
796     }
797     $this->handle_post_events($mode);
798   }
800 /* This function returns all available Shares defined in this ldap 
801  * There are two ways to call this function, if listboxEntry is true
802  *  only name and path are attached to the array, in it is false, the whole 
803  *  entry will be parsed an atached to the result.
804  */
805   function getShareList($listboxEntry = false)
806   {
807     $ldap= $this->config->get_ldap_link();
808     $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
809     $return= array();
810     while($entry = $ldap->fetch($a_res)){
811       $shareAttrs = split("\|",$entry['goExportEntry'][0]);
812       if($listboxEntry) { 
813         $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[3];
814       }else{
815         $return[$shareAttrs[0]]['name']         = $shareAttrs[0]; 
816         $return[$shareAttrs[0]]['description']  = $shareAttrs[1]; 
817         $return[$shareAttrs[0]]['type']         = $shareAttrs[2]; 
818         $return[$shareAttrs[0]]['charset']      = $shareAttrs[3]; 
819         $return[$shareAttrs[0]]['path']         = $shareAttrs[4]; 
820         $return[$shareAttrs[0]]['option']       = $shareAttrs[5]; 
821       }
822     }
823     return($return);
824   }
827 /* Generate ListBox frindly output for the defined shares 
828  * Possibly Add or remove an attribute here, 
829  */
830   function printOutAssignedShares()
831   {
832     $a_return = array();
833     if(is_array($this->gotoShares)){
834       foreach($this->gotoShares as $share){
835         $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
836       }
837     }
838     return($a_return);
839   }
841 /* Generate ListBox frindly output for the definedhotplugs 
842  * Possibly Add or remove an attribute here,
843  */
844 function printOutHotPlugDevices()
845   {
846     $a_return= array();
847     if(is_array($this->gotoHotplugDevices)){
848       foreach($this->gotoHotplugDevices as $key=>$device){
849         $a_return[$key] = $device['name']." - ".$device['id'];
850       }
851     }
852     return($a_return);
853   }
855   /* Generates ListBox frienly output of used printer devices 
856    * Append ' - admin' if printer is used in admin mode
857    */
858   function printOutPrinterDevices()
859   {
860     $a_return = array();
861     if(is_array($this->gotoPrinters)){
862       foreach($this->gotoPrinters as $printer){
863         if($printer['mode'] == "admin"){
864           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
865         }else{
866           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
867         }
868       }
869     }
870     return($a_return);
871   }
873   /* Generates ListBox frienly output of used logonscripts 
874    */
875   function printOutLogonScripts()
876   {
877     $a_return = array();
878     if(is_array($this->gotoLogonScripts)){
879       foreach($this->gotoLogonScripts as $script){
880         $a_return[$script['LogonName']]= $script['LogonName']; 
881       }
882     }
883     return($a_return);
884   }
890 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
891 ?>