Code

Added Vendor + Produkt to hotplugs
[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    = "auto";     // 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 $gotoPrinter        = array();// All available Printer, with their configurations
42   var $gotoPrinterSel     = "";     //  The selected Printer
43   var $gosaDefaultPrinter = "";     // Default printer
45   /* Share */
46   var $gotoShares         = array();// Current Share Options
47   var $gotoShare          = "";     // currently selected Share Option
48   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
49   var $gotoAvailableShares= array();// Available Shares for this account
50   
51   /* Kiosk profile */
52   var $gotoKioskProfile   = "none";     // The selected Kiosk Profile
53   var $gotoKioskProfiles  = array();// All available Kiosk profiles
54   var $newKioskProfiles   = array();
56   /* Hotplug Devices */
57   var $gotoHotplugDevice  = array();     // Selected hotplug
58   var $gotoHotplugDevices = array();// Already configured hotplug devices 
61   /* general settings */
62   // Sets the attributes which will kept on page reload, which will be saved, ...
64   var $CopyPasteVars      = array("gotoHotplugDevices","newKioskProfiles","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlag_L","gotoXResolutions","gotoProfileFlag_C","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66   var $attributes         = array("uid","gotoProfileServer","gotoProfileFlags",
67                                     "gotoXResolution","gotoProfileQuota",
68                                     "gotoLogonScripts","gotoLogonScript",
69                                     "gotoPrinter", "gosaDefaultPrinter",
70                                     "gotoShares","gotoShare",
71                                     "gotoKioskProfile","gotoKioskProfiles"
72                                     );
73   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
74   var $cn;
75   var $OrigCn;
77   function environment ($config, $dn= NULL)
78   {
79     plugin::plugin ($config, $dn);
81     /* Check : Are we currently editing a group or user dialog */
82     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
83       $suffix="Group";
84       $this->uid          = $this->attrs['cn'][0];
85       $this->attrs['uid'] = $this->attrs['cn'][0];
86       $this->OrigCn = $this->attrs['cn'][0];
87     }else{
88       $suffix="User";
89     }
91     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
93     /* Get all Printer assignments */
94     $ldap = $this->config->get_ldap_link();
95     $ldap->cd($this->config->current['BASE']);
96     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
97     while($printer = $ldap->fetch()){
98       $this->gotoPrinter[$printer['cn'][0]]=$printer;
99       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
100     }
101     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
102     while($printer = $ldap->fetch()){
103       $this->gotoPrinter[$printer['cn'][0]]=$printer;
104       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
105     }
106   
107     /* prepare hotplugs */
108     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
109       unset($this->attrs['gotoHotplugDevice']['count']);
110       foreach($this->attrs['gotoHotplugDevice'] as $device){
111         $tmp = $tmp2 = array();
112         $tmp = split("\|",$device);
113         $tmp2['name']        = $tmp[0]; 
114         $tmp2['description'] = $tmp[1]; 
115         $tmp2['id']          = $tmp[2]; 
117         /* Produkt ID */
118         if(!isset($tmp[3])){
119           $tmp[3] = "";
120         }
121         /* Vendor ID */
122         if(!isset($tmp[4])){
123           $tmp[4] = "";
124         }
125   
126         $tmp2['product']     = $tmp[3]; 
127         $tmp2['vendor']      = $tmp[4];
128  
129         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
130       }
131     }
132     
133     /* prepare LogonScripts */
134     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
135       unset($this->attrs['gotoLogonScript']['count']);
136       foreach($this->attrs['gotoLogonScript'] as $device){
137         $tmp = $tmp2 = array();
138         $tmp = split("\|",$device);
139         $tmp2['LogonName']        = $tmp[0]; 
140         $tmp2['LogonPriority']    = $tmp[2]; 
141         if(preg_match("/O/i",$tmp[1])){
142           $tmp2['LogonOverload'] = "O";
143         }else{
144           $tmp2['LogonOverload'] = "";
145         }
146         if(preg_match("/L/i",$tmp[1])){
147           $tmp2['LogonLast'] = "L";
148         }else{
149           $tmp2['LogonLast'] = "";
150         }
151         $tmp2['LogonData']        = base64_decode($tmp[3]); 
152         $tmp2['LogonDescription'] = $tmp[4];
153         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
154       }
155     }
156     
157     /* Prepare Shares */
158     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
159       unset($this->attrs['gotoShare']['count']);
160       foreach($this->attrs['gotoShare'] as $share){
161         $tmp = $tmp2 = array();
162         $tmp = split("\|",$share);
163         $tmp2['server']      =$tmp[0];
164         $tmp2['name']        =$tmp[1];
165         $tmp2['mountPoint']  =$tmp[2];
166         if(isset($tmp[3])){
167           $tmp2['PwdHash']  =$tmp[3];
168         }else{
169           $tmp2['PwdHash']  ="";
170         }
171         if(isset($tmp[4])){
172           $tmp2['Username']  =$tmp[4];
173         }else{
174           $tmp2['Username']  ="";
175         }
176         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
177       }
178     }
180     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
181       $chr = $this->gotoProfileFlags[$i];
182       $name = "gotoProfileFlag_".$chr;
183       $this->$name=$chr;
184     }
186     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
187       $this->useProfile = true;
188     }else{
189       $this->useProfile = false;
190     }
192     /* Set to group environment if we editing a group */
193     if(!isset($this->parent)){
194       $this->is_group = true;
195     }
197     /* Set resolutions */
198     $this->gotoXResolutions = array("auto"=>_("auto"),
199                                     "640x480"   =>  "640x480",
200                                     "800x600"   =>  "800x600",
201                                     "1024x768"  =>  "1024x768",
202                                     "1154x864"  =>  "1154x864",
203                                     "1280x768"  =>  "1280x768",
204                                     "1280x1024" =>  "1280x1024");
206     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
207       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
208   
209       if(is_readable($file)){
210         $str = file_get_contents($file);
211         $lines = split("\n",$str);
212         foreach($lines as $line){
213           $line = trim($line);
214           if(!empty($line)){
215             $this->gotoXResolutions[$line]=$line;
216           }
217         }
218         //natcasesort($this->gotoXResolutions);
219       }else{
220         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
221       }
222     }
224  
225     $this->gotoProfileServers= $config->getShareServerList() ;
226     $this->gotoShareSelections= $config->getShareList(true);
227     $this->gotoAvailableShares= $config->getShareList(false);  
229   }
231   function execute()
232   {
233         /* Call parent execute */
234         plugin::execute();
236   /* Fill templating stuff */
237   $smarty= get_smarty();
238   $display= "";
240   /* Prepare all variables for smarty */
241   foreach($this->attributes as $s_attr){
242     /* Set value*/
243     $smarty->assign($s_attr,$this->$s_attr);
245     /* Set checkbox state*/
246     if(empty($this->$s_attr)){
247       $smarty->assign($s_attr."CHK","");
248     }else{
249       $smarty->assign($s_attr."CHK"," checked ");
250     }
252     /* Prepare ACL settings*/
253     if(chkacl($this->acl,$s_attr)=="") {
254       $smarty->assign($s_attr."ACL","");
255     }else{
256       $smarty->assign($s_attr."ACL"," disabled ");
257     }
259   }
261   /* Is accout enabled | are we editing from usermenu or admin menu 
262      All these tab management is done here
263    */
265   /* Working from Usermenu an the Account is currently disbled
266      * this->parent :  is only set if we are working in a list of tabs
267      * is_account   :  is only true if the needed objectClass is given
268     */
269     if((!isset($this->parent))&&(!$this->is_account)){
270       /* We are currently editing this tab from usermenu, but this account is not enabled */
271       $smarty->assign("is_account",$this->is_account);
272       /* Load template */
273       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
274       /* Avoid the "You are currently editing ...." message when you leave this tab */
275       $display .= back_to_main(); 
276       /* Display our message to the user */
277       return $display;
278     
280     /* We are currently editing from group tabs, because 
281      * $this->parent is set
282      * posixAccount is not set, so we are not in usertabs.
283      */
284     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
285       $smarty->assign("is_account","true");
286       $this->is_group     = true;
287       $this->uid          = $this->cn;
288       $this->attrs['uid'] = $this->cn;
290       /* Change state if needed */
291       if (isset($_POST['modify_state'])){
292         $this->is_account= !$this->is_account;
293       }
295       /* Group Dialog with enabled environment options */
296       if ($this->is_account){
297         $display= $this->show_header(_("Remove environment extension"),
298             _("Environment extension enabled. You can disable it by clicking below."));
299       } else {
300   
301       /* Environment is disabled 
302          If theres is no posixAccount enabled, you won't be able to enable 
303          environment extensions
304        */
305         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
306           // 4. There is a PosixAccount
307           $display= $this->show_header(_("Add environment extension"),
308               _("Environment extension disabled. You can enable it by clicking below."));
309           return $display;
310         }else{
311           // 4. There is no PosixAccount
312           $display= $this->show_header(_("Add environment extension"),
313               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
314           return $display;
315         }
316       }
317     }else{
318       /* Editing from Usermenu 
319        *  Tell smarty that this accoutn is enabled 
320        */
321       $smarty->assign("is_account","true");
323       $this->is_group = false;
325       /* Do we need to flip is_account state? */
326       if (isset($_POST['modify_state'])){
327         $this->is_account= !$this->is_account;
328       }
330       if(isset($this->parent)){
332         // 3. Account enabled . Editing from adminmenu
333         if ($this->is_account){
334           $display= $this->show_header(_("Remove environment extension"),
335               _("Environment extension enabled. You can disable it by clicking below."));
336         } else {
338           if($this->parent->by_object['posixAccount']->is_account==true){
339             // 4. There is a PosixAccount
340             $display= $this->show_header(_("Add environment extension"),
341                 _("Environment extension disabled. You can enable it by clicking below."));
342             return $display;
343           }else{
344             // 4. There is a PosixAccount
345             $display= $this->show_header(_("Add environment extension"),
346                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
347             return $display;
348           }
349         }
350       }
351     }
352     /* Account is Account : is_accounbt=true.
353      * Else we won't reach this. 
354      */
355    
356     /* Prepare all variables for smarty */
357     foreach($this->attributes as $s_attr){
358       /* Set value*/
359       $smarty->assign($s_attr,$this->$s_attr);
360      
361       /* Set checkbox state*/
362       if(empty($this->$s_attr)){
363         $smarty->assign($s_attr."CHK","");
364       }else{
365         $smarty->assign($s_attr."CHK"," checked ");
366       }
367     
368       /* Prepare ACL settings*/
369       if(chkacl($this->acl,$s_attr)=="") {
370         $smarty->assign($s_attr."ACL","");
371       }else{
372         $smarty->assign($s_attr."ACL"," disabled ");
373       }
374  
375     }
377     foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
378       if(chkacl($this->acl,$s_attr)=="") {
379         $smarty->assign($s_attr."ACL","");
380       }else{
381         $smarty->assign($s_attr."ACL"," disabled ");
382       }
383     }
385     if(empty($this->useProfile)){
386       $smarty->assign("gotoProfileACL","disabled");
387       $smarty->assign("useProfileCHK","");
388     }else{
389       $smarty->assign("gotoProfileACL","");
390       $smarty->assign("useProfileCHK"," checked ");
391     }
393  
394     $smarty->assign("useProfileACL","");
395     if($this->acl != "#none#"){
396       $smarty->assign("useProfileACL","");
397       $smarty->assign("gotoProfileFlag_CACL"," ");
398       $smarty->assign("gotoProfileQuotaACL"," ");
399     }else{
400       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
401       $smarty->assign("useProfileACL","disabled");
402       $smarty->assign("gotoProfileServer"," disabled ");
403       $smarty->assign("gotoProfileQuotaACL"," disabled ");
404     }
406     /* HANDLE Profile Settings here 
407      * Assign available Quota and resolution settings
408      * Get all available profile server
409      * Get cache checkbox
410      * Assign this all to Smarty 
411      */
413     if(empty($this->gotoProfileFlag_L)){
414       $smarty->assign("gotoProfileFlag_LCHK"," ");
415     }else{
416       $smarty->assign("gotoProfileFlag_LCHK"," checked ");
417     }
419     if(empty($this->gotoProfileFlag_C)){
420       $smarty->assign("gotoProfileFlag_CCHK"," ");
421     }else{
422       $smarty->assign("gotoProfileFlag_CCHK"," checked ");
423     }
426     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
427     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
429     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
430     if(!is_array($this->gotoProfileServers)){
431       $this->gotoProfileServers =array();
432     }
433     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
435     /* Handle kiosk profiles 
436      * Read available from filesystem
437      * Open management if post is transmitted
438      */
440     /* Save */
441     if(isset($_POST['KioskClose'])){
442       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
443   
444       unset($this->dialog);
445       $this->dialog=NULL;
446       $this->is_dialog = false;
447     }
449     /* Reassign help class */
450     $_SESSION['current_class_for_help'] = get_class($this);
451  
452     /* Open Management Dialog */
453     if(isset($_POST['KioskManagementDialog'])){
454       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
455       $this->dialog->parent= $this;
456       $this->dialog->acl = $this->acl;
457       $this->is_dialog = true;
458     }
459     $tmp = new kioskManagementDialog($this->config,$this->dn);
460     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
461     $list['none']=_("None");
462     $list = array_reverse($list);
463     $smarty->assign("gotoKioskProfiles",$list);
464     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
466     /* Logonscript Management
467      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
468      * Perform add Delete edit Posts 
469      */
471     /* Dialog Save */
472     if(isset($_POST['LogonSave'])){
473       $this->dialog->save_object();
474       if(count($this->dialog->check())!=0){
475         foreach($this->dialog->check() as $msg){
476           print_red($msg);
477         }
478       }else{
479         $tmp = $this->dialog->save();
480         unset($this->dialog);
481         $this->dialog=NULL;
482         $this->is_dialog=false;
483         $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
484       }
485     }
486     
487     /* Dialog Quit without saving */
488     if(isset($_POST['LogonCancel'])){
489       $this->is_dialog= false;
490       unset($this->dialog);
491       $this->dialog= NULL;
492     }
493    
494     /* Check Edit Del New Posts for a selected LogonScript */ 
495     if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
497       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
498        * In this case we create a new Logon Script.
499        */
500       if(isset($_POST['gotoLogonScriptNew'])){
501         $this->is_dialog = true;
502         $this->dialog = new logonManagementDialog($this->config,$this->dn);
503       }
505       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
506        * We only can delete if there is an entry selected.
507        */
508       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
509         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
510       }
511       
512       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
513        * There must be an entry selected to perform edit request.
514        */
515       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
516         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
517         $this->is_dialog = true;
518         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
519       }
520     }
521      
522     /* Append List to smarty*/
523     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
524     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
526     /* In this section server shares will be defined 
527      * A user can select one of the given shares and a mount point
528      *  and attach this combination to his setup.
529      */
530     
531     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
532     if(!is_array($this->gotoShareSelections)){
533       print $this->gotoShareSelections;
534       $this->gotoShareSelections = array();
535     }
536     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
538     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
539      * This entry will be, a combination of mountPoint and sharedefinitions 
540      */
541     if(isset($_POST['gotoShareAdd'])){
542       /* We assign a share to this user, if we don't know where to mount the share */
543       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
544         print_red(_("You must specify a valid mount point."));
545       }elseif(!(
546         preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
547         preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
548         preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
549         preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
550         preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
551         preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
552         preg_match("/^%/",$_POST['gotoShareMountPoint'])
553         )
554       ){
555         print_red(_("You must specify a valid mount point.")); 
556       }else{
557         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
558         $s_mount = $_POST['gotoShareMountPoint'];
559         $s_user  = $_POST['ShareUser'];
560         /* Preparing the new assignment */ 
561         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
562         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
563         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
564         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
565       }
566     }  
568     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
569      * If there is no defined share selected, we will abort the deletion without any message 
570      */
571     $once = true;
572     foreach($_POST as $name => $value){
573       if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
574         $once = false;  
575         $key  = preg_replace("/^gotoShareDel_/","",$name);
576         $key  = preg_replace("/_+[xy]$/","",$key);
577         $key  = preg_replace("/_/", ".", $key);
578         if(isset($this->gotoShares[$key])) {
579           unset($this->gotoShares[$key]);
580         }
581       }
582       if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
583         $once = false;
584         $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
585         $key  = preg_replace("/_+[xy]$/","",$key);
586         $key  = preg_replace("/_/", ".", $key);
587         $this->gotoShares[$key]['PwdHash'] = "";
588       }
589     }
591     $divlistShares = new divSelectBox("gotoShares");
592     $divlistShares->SetHeight(100);
593     $tmp = $this->printOutAssignedShares();
594     
595     foreach($tmp as $key => $value){
596       $img = "";
597    
598       /* Check if entry starts with an ! */
599       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
601         /* If we are currently editing groups environment, skip those ! entries */ 
602         if($this->is_group) continue;
603     
604         /* Create pwd reset images */
605         if($this->gotoShares[$key]['PwdHash'] != ""){
606           $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
607             title='"._("Reset password hash")."'>";
608         }
609         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
610         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
611       }else{
613         /* Create pwd reset img && delete image */
614         if($this->gotoShares[$key]['PwdHash'] != ""){
615           $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
616             title='"._("Reset password hash")."'>";
617           $img.= "&nbsp;";
618         }
619         $img.= "<input type='image' name='gotoShareDel_".$key." 'src='images/edittrash.png' alt='"._("Delete")."' 
620           title='"._("Delete share entry")."'>";
621         $field1 = array("string" => $value);
622         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
623       }
624       $divlistShares->AddEntry(array($field1,$field2));
625     }
626     $smarty->assign("divlistShares",$divlistShares->DrawList());
628     /* Hotplug devices will be handled here 
629      * There are 3 possible methods for this feature
630      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
631      * Delete will erase an entry, the entry must be selcted in the ListBox first
632      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
633      */
635     /* If there is a new entry wanted, open a new entry by initilising the dialog */
636     if(isset($_POST['gotoHotplugDeviceNew'])){
637       $this->dialog = new hotplugDialog($this->config,$this->dn);
638       $this->is_dialog = true;
639     }
641     /* We have to delete the selected hotplug from the list*/
642     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
643       foreach($_POST['gotoHotplugDevice'] as $name){
644         unset($this->gotoHotplugDevices[$name]);
645       }
646     }
648     /* There are already defined hotplugs from other users we could use */
649     if(isset($_POST['gotoHotplugDeviceUse'])){
650       $this->dialog = new hotplugDialog($this->config,$this->dn,true);
651       $this->is_dialog = true;
652     }
654     /* Dialog Aborted */
655     if(isset($_POST['HotPlugCancel'])){
656       unset($this->dialog);
657       $this->dialog= NULL;
658       $this->is_dialog = false;
659     }
660  
661     /* Dialod saved */
662     if(isset($_POST['HotPlugSave'])){
663       $this->dialog->save_object();
664       if(count($this->dialog->check())!=0){
665         foreach($this->dialog->check() as $msg){
666           print_red($msg);
667         }
668       }else{
669         $this->dialog->save_object();
670         $a_tmp = $this->dialog->save();
671        
672         if(is_array($a_tmp)){
673           foreach($a_tmp as $name => $hotplug){
674             $this->gotoHotplugDevices[$name]= $hotplug; 
675           }
676         }
677         unset($this->dialog);
678         $this->dialog= NULL;
679         $this->is_dialog = false;
680       }
681     }
682     
683     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
684     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
685   
686     /* Printer Assignment will managed below 
687      * A printer can be assigned in two different ways and two different types
688      * There are 2 types of users assigned to a printer : user and admin
689      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
690      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
691      */ 
692     
693     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
694     if(isset($_POST['gotoPrinterAdd'])){
695       $this->is_dialog=true;
696       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
697     }
699     if(isset($_POST['PrinterCancel'])){
700         $this->is_dialog=false;
701         unset($this->dialog);
702         $this->dialog=NULL;
703     }
705     if(isset($_POST['PrinterSave'])){
706       if(count($this->dialog->check())!=0){
707         $tmp = $this->dialog->check();
708         foreach($tmp as $msg){
709           print_red($msg);
710         } 
711       }else{
712         $this->dialog->save_object();
713         $tmp = $this->dialog->save();
714         $tmp2= $this->dialog->getPrinter(true);
715   
716         foreach($tmp as $pname){
717           $this->gotoPrinter[$pname]=$tmp2[$pname];
718           $this->gotoPrinter[$pname]['mode']="user";
719         }
720   
721         $this->is_dialog=false;
722         unset($this->dialog);
723         $this->dialog   =NULL;
724       }
725     }
726   
727     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
728       $printer = $_POST['gotoPrinterSel'];
729       foreach($printer as $pname){
730         unset($this->gotoPrinter[$pname]);
731       }
732     }
734     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
737       $printers = $_POST['gotoPrinterSel'];
739       foreach($printers as $printer){
740         if($this->gotoPrinter[$printer]['mode']=="user"){
741           $this->gotoPrinter[$printer]['mode']="admin";
742         }else{
743           $this->gotoPrinter[$printer]['mode']="user";
744         }
745       }
746     }
748     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
749       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
750         $this->gosaDefaultPrinter= "";
751       } else {
752         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
753       }
754     }
756     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
757     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
758  
759     /* General behavior */
760     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
761       $this->dialog->save_object();
762       $disp =$this->dialog->execute();
764       $tmp = new kioskManagementDialog($this->config,$this->dn);
765       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
766       $list['none']=_("None");
767       $list = array_reverse($list);
768       if(!isset($list[$this->gotoKioskProfile])){
769         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
770         $this->gotoKioskProfile = 'none';
771       }
772       return($disp);
773     }
774     if($this->acl != "#none#"){
775       $smarty->assign("useProfileACL","");
776     }else{
777       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
778       $smarty->assign("gotoProfileServerACL"," disabled ");
779       $smarty->assign("gotoProfileQuotaACL"," disabled ");
780     }
782     if(!$this->useProfile){
783       $smarty->assign("gotoProfileFlag_CACL"," disabled ");
784       $smarty->assign("gotoProfileServerACL"," disabled ");
785       $smarty->assign("gotoProfileQuotaACL"," disabled ");
786     }
788     /* Als smarty vars are set. Get smarty template and generate output */
789     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
790     
791     return($display);
792   }
794   function remove_from_parent()
795   {
796     /* only if it was an account*/
797     if (!$this->initially_was_account){
798       return;
799     }
801     /* include global link_info */
802     $ldap= $this->config->get_ldap_link();
804     /* Remove and write to LDAP */
805     plugin::remove_from_parent();
807     /* Don't save our template variables */
808     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
810     /* Skip all these attributes */
811     foreach($skip as $del){
812       unset($this->attrs[$del]);
813     }
815     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
817     $ldap->cd($this->dn);
818     $this->cleanup();
819     $ldap->modify ($this->attrs); 
821     show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
823     /* Optionally execute a command after we're done */
824     $this->handle_post_events("remove");
825   }
828   /* Save data to object */
829   function save_object()
830   {
831     /* Get all Posted vars 
832      * Setup checkboxes 
833      */
834  
835     if(isset($_POST['iamposted'])){
836       if(isset($_POST['useProfile'])){
837         $this->useProfile = true;
838       }else{
839         $this->useProfile = false;
840       }
841       if(isset($_POST['gotoProfileFlag_C'])){
842         $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
843       }else{
844         $this->gotoProfileFlag_C = false;
845       }
846       if(isset($_POST['gotoProfileFlag_L'])){
847         $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
848       }else{
849         $this->gotoProfileFlag_L = false;
850       }
852       $tmp= $this->gosaDefaultPrinter;
853       plugin::save_object();
854       foreach($this->attributes as $s_attr){
855         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
856         if(isset($_POST[$s_attr])){
857           $this->$s_attr = $_POST[$s_attr];
858         }else{
859           $this->$s_attr = false;
860         }
861       }
862       $this->gosaDefaultPrinter= $tmp;
863     }
864   }
867   /* Check supplied data */
868   function check()
869   {
870     /* Call common method to give check the hook */
871     $message= plugin::check();
872   
873     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
874       $message[]=_("Please set a valid profile quota size.");
875     } 
876     if(!isset($this->attrs['objectClass'])){
877       $this->attrs['objectClass']=array();
878     } 
879     if(!$this->is_group){
880       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
881         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
882       }
883     }
884     return ($message);
885   }
888   /* Save to LDAP */
889   function save()
890   {
891     /* If group was renamed, all printer settings get lost
892      */ 
893     /* only save changed variables ....*/
894     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
895     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
896       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
897         $method="https://";
898       }else{
899         $method="http://";
900       }
902       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
903       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
904     }else{
905       $this->gotoKioskProfile= array();
906     }
907     
908     plugin::save();
909     $ldap= $this->config->get_ldap_link();
911     $realyUsedAttrs= array();
913     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
914     /* Creating Kiosk Profiles */
915     foreach($this->newKioskProfiles as $file){
916       $contents = $file['contents'];
917       $fp = @fopen($path."/".$file['name'],"w");
918       if(!$fp){
919         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
920       }else{
921         fwrite($fp,$contents,strlen($contents));
922       }
923       @unlink($file['tmp_name']);
924     }
925  
926     /* Save already used objectClasses */
927     $ocs        = $this->attrs['objectClass'];
928     unset($ocs['count']);
929     $this->attrs = array();
930     $this->attrs['objectClass']= $ocs;
931     foreach($this->objectclasses as $objc){
932       if(!in_array($objc,$this->attrs['objectClass'])){
933         $this->attrs['objectClass'][]=$objc;
934       }
935     }
938     /* Save usersettings to Printer */
940     if(chkacl($this->acl,"gotoPrinter")!=""){
941       $this->gotoPrinter = array();
942     }  
943     
944     if($this->is_group){
945       $s_suffix = "Group";
946     }else{
947       $s_suffix = "User";
948     }
949   
951     /* 1. Search all printers that have our uid/cn as member 
952      * 2. Delete this uid/cn from every single entry and save it again.
953      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
954      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
955      */
956     $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
957     while($attr = $ldap->fetch()){
959       /* Walk trough all printers and check if our user id used, if so remove it.
960        * Later we will insert our uid at the right place.
961        */
963       /* Remove normal entries (User)*/
964       if(isset($attr['goto'.$s_suffix.'Printer'])) {
965         foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
966           if($this->uid==$user){
967             unset($attr['goto'.$s_suffix.'Printer'][$key]);
968           }
969         }    
970       }
972       /* Remove administrational entries (Admin)*/
973       if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
974         foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
975           if($this->uid==$user){
976             unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
977           }
978         }    
979       }
981       /* Extract useable tags, to be able to save all changes 
982        */
983       $attrs_used = array();
984       foreach($attr as $key=>$val){
986         /* If index is numeric, skip it ...*/
987         if((!is_numeric($key))&&($key!="count")){
989           /* If entry contains 'count' remove it */
990           if(is_array($val)&&isset($val['count'])){
991             unset($val['count']);
992           }
993           $attrs_used[$key]=$val;
994         }
995       }
996       /* the result of cleaning the entry is 
997        *  to be able to directly save this again,
998        *  if all changes are made 
999        */
1000       $attr= $attrs_used;
1002 #fix : Id don't know why such an entry was set ... 
1003       if(isset($attr['GOTOADMINPRINTER'])){
1004         unset($attr['GOTOADMINPRINTER']);
1005       }
1007       /* Save changes */
1008       $ldap->cd($attr['dn']);
1009       unset($attr['dn']);
1010 $ldap->modify ($attr); 
1012       if($ldap->get_error()!="Success"){
1013         print_red(_("Error while writing printer")." : ".$ldap->get_error());
1014       }
1015     }
1017     /* All printers are cleaned, (our cn/uid removed) 
1018      *  now we must add our uid / cn 
1019      *  to the new configured printers.
1020      */
1021     foreach($this->gotoPrinter as $printer) {
1022       $ldap->cat($printer['dn']);
1023       $attrs= $ldap->fetch();
1024       $attrs_used = array(); 
1025       foreach($attrs as $key=>$val){
1026         if((!is_numeric($key))&&($key!="count")){
1027           if(is_array($val)&&isset($val['count'])){
1028             unset($val['count']);
1029           }
1030           $attrs_used[$key]=$val;
1031         }
1032       }
1033       /* $attrs contains all values 
1034        * we need, to save the entry lateron 
1035       */
1036       $attrs= $attrs_used;
1038       /* Depending on the type (User/Admin) 
1039        *  switch these attributes, that makes it easier
1040        */
1041       if($printer['mode'] == "user"){
1042         $attribute  = "goto".$s_suffix."Printer";
1043         $attribute2 = "goto".$s_suffix."AdminPrinter";
1044       }else{
1045         $attribute  = "goto".$s_suffix."AdminPrinter";
1046         $attribute2 = "goto".$s_suffix."Printer";
1047       }
1049       /* If this user is already assigned to $attribute2 
1050        * delete user from $attribute2, to be albe to attach him to $attribute
1051        * A user can't be admin and normal user for one printer
1052        */
1053       if(!isset($printer[$attribute2])){
1054         $printer[$attribute2]=array();
1055       }else{
1056         if(in_array($this->uid,$printer[$attribute2])){ 
1057           $tmp = array_flip($printer[$attribute2]);
1058           unset($tmp[$this->uid]);
1059           $attrs[$attribute2]=array_flip($tmp);
1060         }
1061         /* If Last entry removed, clear attribute*/
1062         if(empty($attrs[$attribute2])){
1063           $attrs[$attribute2]=array();
1064         }
1065       }
1066     
1067       /* Attach user to the $attribute, if he is'nt already attached
1068        */
1069       if(!isset($attrs[$attribute])){
1070         $attrs[$attribute]=array($this->uid);
1071       }else{
1072         unset($attrs[$attribute]['count']);
1073         if(!in_array($this->uid,$attrs[$attribute])){
1074           $attrs[$attribute][]=$this->uid;
1075         }
1076       }
1078       $ldap->cd($attrs['dn']);
1079       unset($attrs['dn']);
1080 $ldap->modify ($attrs); 
1082       if($ldap->get_error()!="Success"){
1083         print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
1084       }
1085     }
1086   
1087     /* Prepare HotPlug devices */
1088     $this->attrs['gotoHotplugDevice'] = array();
1089     foreach($this->gotoHotplugDevices as $name => $device){
1090       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1091         "|".$device['produkt']."|".$device['vendor'];
1092     }
1094     /* Prepare LogonScripts */
1095     $this->attrs['gotoLogonScript'] = array();
1096     foreach($this->gotoLogonScripts as $name => $script){
1097       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1098                                             $script['LogonOverload'].$script['LogonLast']."|".
1099                                             $script['LogonPriority']."|".
1100                                             base64_encode($script['LogonData'])."|".
1101                                             $script['LogonDescription'];
1102     }
1104     /* Prepare Shares */
1105     $this->attrs['gotoShare']=array();
1106     foreach($this->gotoShares as $name => $share){
1107       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['PwdHash']."|".$share['Username'];
1108     }
1111     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1112     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1113      
1114     foreach($saveThis as $tosave){
1115       if(!empty($this->$tosave)){
1116         $this->attrs[$tosave]=$this->$tosave;
1117       }else{
1118         $this->attrs[$tosave]=array();
1119       }
1120     }
1121  
1122     /* Prepare Flags */
1123     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1124     if(empty($this->attrs['gotoProfileFlags'][0])){
1125       $this->attrs['gotoProfileFlags']=array();
1126       }
1128     if($this->useProfile == false){
1129       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1130       $this->attrs['gotoProfileServer']= array(); 
1131     }
1133     foreach($this->attributes as $s_attr){
1134       if(chkacl($this->acl,$s_attr)!="") {
1135         if(isset($this->attrs[$s_attr])){
1136           unset($this->attrs[$s_attr]);
1137         }
1138       }
1139     }
1141     $ldap->cat ($this->dn, array('dn'));
1142     if ($ldap->fetch()){
1143       $mode= "modify";
1144     } else {
1145       $mode= "add";
1146       $ldap->cd($this->config->current['BASE']);
1147       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1148     }
1150     $ldap->cd($this->dn);
1151     $this->cleanup();
1152     $ldap->$mode($this->attrs);
1153     show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1154     $this->handle_post_events($mode);
1155   }
1157 /* Generate ListBox frindly output for the defined shares 
1158  * Possibly Add or remove an attribute here, 
1159  */
1160   function printOutAssignedShares()
1161   {
1162     $a_return = array();
1163     if(is_array($this->gotoShares)){
1164       foreach($this->gotoShares as $share){
1165         if(preg_match("/^!/",$share['server'])){
1166           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1167         }else{
1168           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1169         }
1170       }
1171     }
1172     return($a_return);
1173   }
1175 /* Generate ListBox frindly output for the definedhotplugs 
1176  * Possibly Add or remove an attribute here,
1177  */
1178 function printOutHotPlugDevices()
1179   {
1180     $a_return= array();
1181     if(is_array($this->gotoHotplugDevices)){
1182       foreach($this->gotoHotplugDevices as $key=>$device){
1183         $a_return[$key] = $device['name']." - ".$device['id'];
1184       }
1185     }
1186     return($a_return);
1187   }
1189   /* Generates ListBox frienly output of used printer devices 
1190    * Append ' - admin' if printer is used in admin mode
1191    */
1192   function printOutPrinterDevices()
1193   {
1194     $a_return = array();
1195     if(is_array($this->gotoPrinter)){
1196       foreach($this->gotoPrinter as $printer){
1197         if($printer['mode'] == "admin"){
1198           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1199         }else{
1200           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1201         }
1202         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1203           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1204         }
1205       }
1206     }
1207     return($a_return);
1208   }
1210   /* Generates ListBox frienly output of used logonscripts 
1211    */
1212   function printOutLogonScripts()
1213   {
1214     $a_return = array();
1215     if(is_array($this->gotoLogonScripts)){
1216       foreach($this->gotoLogonScripts as $script){
1217         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1218       }
1219     }
1220     return($a_return);
1221   }
1227 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1228 ?>