Code

Fixed printer add/remove
[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 $gotoProfileFlagC  = "";     // 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 $gotoProfileFlagL  = "";     // 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
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","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","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;
76   var $add_del_printer_member_was_called = false;
78   function environment ($config, $dn= NULL)
79   {
80     plugin::plugin ($config, $dn);
82     /* Check : Are we currently editing a group or user dialog */
83     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
84       $suffix="Group";
85       $this->uid          = $this->attrs['cn'][0];
86       $this->attrs['uid'] = $this->attrs['cn'][0];
87       $this->OrigCn = $this->attrs['cn'][0];
88     }else{
89       $suffix="User";
90     }
92     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
94     /* Get all Printer assignments */
95     $ldap = $this->config->get_ldap_link();
96     $ldap->cd($this->config->current['BASE']);
97     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
98     while($printer = $ldap->fetch()){
99       $this->gotoPrinter[$printer['cn'][0]]=$printer;
100       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
101     }
102     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
103     while($printer = $ldap->fetch()){
104       $this->gotoPrinter[$printer['cn'][0]]=$printer;
105       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
106     }
108     /* prepare hotplugs */
109     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
110       unset($this->attrs['gotoHotplugDevice']['count']);
111       foreach($this->attrs['gotoHotplugDevice'] as $device){
112         $tmp = $tmp2 = array();
113         $tmp = split("\|",$device);
114         $tmp2['name']        = $tmp[0]; 
115         $tmp2['description'] = $tmp[1]; 
116         $tmp2['id']          = $tmp[2]; 
118         /* Produkt ID */
119         if(!isset($tmp[3])){
120           $tmp[3] = "";
121         }
122         /* Vendor ID */
123         if(!isset($tmp[4])){
124           $tmp[4] = "";
125         }
127         $tmp2['produkt']     = $tmp[3]; 
128         $tmp2['vendor']      = $tmp[4];
130         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
131       }
132     }
134     /* prepare LogonScripts */
135     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
136       unset($this->attrs['gotoLogonScript']['count']);
137       foreach($this->attrs['gotoLogonScript'] as $device){
138         $tmp = $tmp2 = array();
139         $tmp = split("\|",$device);
140         $tmp2['LogonName']        = $tmp[0]; 
141         $tmp2['LogonPriority']    = $tmp[2]; 
142         if(preg_match("/O/i",$tmp[1])){
143           $tmp2['LogonOverload'] = "O";
144         }else{
145           $tmp2['LogonOverload'] = "";
146         }
147         if(preg_match("/L/i",$tmp[1])){
148           $tmp2['LogonLast'] = "L";
149         }else{
150           $tmp2['LogonLast'] = "";
151         }
152         $tmp2['LogonData']        = base64_decode($tmp[3]); 
153         $tmp2['LogonDescription'] = $tmp[4];
154         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
155       }
156     }
158     /* Prepare Shares */
159     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
160       unset($this->attrs['gotoShare']['count']);
161       foreach($this->attrs['gotoShare'] as $share){
162         $tmp = $tmp2 = array();
163         $tmp = split("\|",$share);
164         $tmp2['server']      =$tmp[0];
165         $tmp2['name']        =$tmp[1];
167         /* Decode base64 if needed */
168         if (!preg_match('%/%', $tmp[2])){
169           $tmp2['mountPoint']  =base64_decode($tmp[2]);
170         } else {
171           $tmp2['mountPoint']  =$tmp[2];
172         }
174         if(isset($tmp[3])){
175           $tmp2['PwdHash']  =$tmp[3];
176         }else{
177           $tmp2['PwdHash']  ="";
178         }
179         if(isset($tmp[4])){
180           $tmp2['Username']  =$tmp[4];
181         }else{
182           $tmp2['Username']  ="";
183         }
184         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
185       }
186     }
188     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
189       $chr = $this->gotoProfileFlags[$i];
190       $name = "gotoProfileFlag".$chr;
191       $this->$name=$chr;
192     }
194     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
195       $this->useProfile = true;
196     }else{
197       $this->useProfile = false;
198     }
200     /* Set to group environment if we editing a group */
201     if(!isset($this->parent)){
202       $this->is_group = true;
203     }
205     /* Set resolutions */
206     $this->gotoXResolutions = array("auto"=>_("auto"),
207                                     "640x480"   =>  "640x480",
208                                     "800x600"   =>  "800x600",
209                                     "1024x768"  =>  "1024x768",
210                                     "1152x864"  =>  "1152x864",
211                                     "1280x768"  =>  "1280x768",
212                                     "1280x1024" =>  "1280x1024");
214     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
215       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
217       if(is_readable($file)){
218         $str = file_get_contents($file);
219         $lines = split("\n",$str);
220         foreach($lines as $line){
221           $line = trim($line);
222           if(!empty($line)){
223             $this->gotoXResolutions[$line]=$line;
224           }
225         }
226         //natcasesort($this->gotoXResolutions);
227       }else{
228         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
229       }
230     }
232     $this->gotoProfileServers= $config->getShareServerList() ;
233     $this->gotoShareSelections= $config->getShareList(true);
234     $this->gotoAvailableShares= $config->getShareList(false);  
236   }
238   function execute()
239   {
240     /* Call parent execute */
241     plugin::execute();
243     /* Fill templating stuff */
244     $smarty= get_smarty();
245     $display= "";
247     /* Are we editing from MyAccount and not editing a user */
248     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
250     /* Prepare all variables for smarty */
251     foreach($this->attributes as $s_attr){
252       /* Set value*/
253       $smarty->assign($s_attr,$this->$s_attr);
255       /* Set checkbox state*/
256       if(empty($this->$s_attr)){
257         $smarty->assign($s_attr."CHK","");
258       }else{
259         $smarty->assign($s_attr."CHK"," checked ");
260       }
262       /* Prepare ACL settings*/
263       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
264     }
266     /* Is accout enabled | are we editing from usermenu or admin menu 
267        All these tab management is done here
268      */
271     /* Working from Usermenu an the Account is currently disbled
272      * this->parent :  is only set if we are working in a list of tabs
273      * is_account   :  is only true if the needed objectClass is given
274      */
275     if((!isset($this->parent))&&(!$this->is_account)){
276       /* We are currently editing this tab from usermenu, but this account is not enabled */
277       $smarty->assign("is_account",$this->is_account);
278       /* Load template */
279       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
280       /* Avoid the "You are currently editing ...." message when you leave this tab */
281       $display .= back_to_main(); 
282       /* Display our message to the user */
283       return $display;
286       /* We are currently editing from group tabs, because 
287        * $this->parent is set
288        * posixAccount is not set, so we are not in usertabs.
289        */
290     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
291       $smarty->assign("is_account","true");
292       $this->is_group     = true;
293       $this->uid          = $this->cn;
294       $this->attrs['uid'] = $this->cn;
296       /* Change state if needed */
297       if (isset($_POST['modify_state'])){
298         if(($this->acl_is_createable() && !$this->is_account) || 
299             ($this->acl_is_removeable() &&  $this->is_account)){
300           $this->is_account= !$this->is_account;
301         }
302       }
303       /* Group Dialog with enabled environment options */
304       if ($this->is_account){
305         $display= $this->show_enable_header(_("Remove environment extension"),
306             _("Environment extension enabled. You can disable it by clicking below."));
307       } else {
309         /* Environment is disabled 
310            If theres is no posixAccount enabled, you won't be able to enable 
311            environment extensions
312          */
313         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
314           // 4. There is a PosixAccount
315           $display= $this->show_enable_header(_("Add environment extension"),
316               _("Environment extension disabled. You can enable it by clicking below."));
317           return $display;
318         }else{
319           // 4. There is no PosixAccount
320           $display= $this->show_enable_header(_("Add environment extension"),
321               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
322           return $display;
323         }
324       }
325     }else{
326       /* Editing from Usermenu 
327        *  Tell smarty that this accoutn is enabled 
328        */
329       $smarty->assign("is_account","true");
331       $this->is_group = false;
333       /* Change state if needed */
334       if (isset($_POST['modify_state'])){
335         if(($this->acl_is_createable() && !$this->is_account) || 
336             ($this->acl_is_removeable() &&  $this->is_account)){
337           $this->is_account= !$this->is_account;
338         }
339       }
341       if(isset($this->parent)){
343         // 3. Account enabled . Editing from adminmenu
344         if ($this->is_account){
345           $display= $this->show_disable_header(_("Remove environment extension"),
346               _("Environment extension enabled. You can disable it by clicking below."));
347         } else {
349           if($this->parent->by_object['posixAccount']->is_account==true){
350             // 4. There is a PosixAccount
351             $display= $this->show_disable_header(_("Add environment extension"),
352                 _("Environment extension disabled. You can enable it by clicking below."));
353             return $display;
354           }else{
355             // 4. There is a PosixAccount
356             $display= $this->show_disable_header(_("Add environment extension"),
357                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
358             return $display;
359           }
360         }
361       }
362     }
363     /* Account is Account : is_accounbt=true.
364      * Else we won't reach this. 
365      */
367     /* Prepare all variables for smarty */
368     foreach($this->attributes as $s_attr){
369       /* Set value*/
370       $smarty->assign($s_attr,$this->$s_attr);
372       /* Set checkbox state*/
373       if(empty($this->$s_attr)){
374         $smarty->assign($s_attr."CHK","");
375       }else{
376         $smarty->assign($s_attr."CHK"," checked ");
377       }
379       /* Prepare ACL settings*/
380       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
381     }
383     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
384       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
385     }
387     if($WriteOnly) {
388       $smarty->assign("gotoPrinterACL","r");
389     }else{
390       $smarty->assign("gotoPrinterACL","rw");
391     }
393     if(empty($this->useProfile)){
394       $smarty->assign("useProfileCHK","");
395       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
396       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
397       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
398     }else{
399       $smarty->assign("useProfileCHK"," checked ");
400     }
403     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
405     /* HANDLE Profile Settings here 
406      * Assign available Quota and resolution settings
407      * Get all available profile server
408      * Get cache checkbox
409      * Assign this all to Smarty 
410      */
412     if(empty($this->gotoProfileFlagL)){
413       $smarty->assign("gotoProfileFlagLCHK"," ");
414     }else{
415       $smarty->assign("gotoProfileFlagLCHK"," checked ");
416     }
418     if(empty($this->gotoProfileFlagC)){
419       $smarty->assign("gotoProfileFlagCCHK"," ");
420     }else{
421       $smarty->assign("gotoProfileFlagCCHK"," checked ");
422     }
425     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
426     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
428     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
429     if(!is_array($this->gotoProfileServers)){
430       $this->gotoProfileServers =array();
431     }
432     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
434     /* Handle kiosk profiles 
435      * Read available from filesystem
436      * Open management if post is transmitted
437      */
439     /* Save */
440     if(isset($_POST['KioskClose'])){
441       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
443       unset($this->dialog);
444       $this->dialog=NULL;
445       $this->is_dialog = false;
446     }
448     /* Reassign help class */
449     $_SESSION['current_class_for_help'] = get_class($this);
451     /* Open Management Dialog */
452     if(isset($_POST['KioskManagementDialog'])){
453       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
454       $this->dialog->parent= $this;
455       $this->dialog->acl = $this->acl;
456       $this->is_dialog = true;
457     }
458     $tmp = new kioskManagementDialog($this->config,$this->dn);
459     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
460     $list['none']=_("None");
461     $list = array_reverse($list);
462     $smarty->assign("gotoKioskProfiles",$list);
463     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
465     /* Logonscript Management
466      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
467      * Perform add Delete edit Posts 
468      */
470     /* Dialog Save */
471     if(isset($_POST['LogonSave'])){
473       if(!$this->acl_is_writeable("gotoLogonScript")){
474         print_red(_("You are not allowed to write Logon scripts."));
475         unset($this->dialog);
476         $this->dialog=NULL;
477         $this->is_dialog=false;
478       }else{
479         $this->dialog->save_object();
480         if(count($this->dialog->check())!=0){
481           foreach($this->dialog->check() as $msg){
482             print_red($msg);
483           }
484         }else{
485           $tmp = $this->dialog->save();
486           unset($this->dialog);
487           $this->dialog=NULL;
488           $this->is_dialog=false;
489           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
490         }
491       }
492     }
493     
495     /* Dialog Quit without saving */
496     if(isset($_POST['LogonCancel'])){
497       $this->is_dialog= false;
498       unset($this->dialog);
499       $this->dialog= NULL;
500     }
502     /* Check Edit Del New Posts for a selected LogonScript */ 
503     if($this->acl_is_writeable("gotoLogonScript") && 
504         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
506       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
507        * In this case we create a new Logon Script.
508        */
509       if(isset($_POST['gotoLogonScriptNew'])){
510         $this->is_dialog = true;
511         $this->dialog = new logonManagementDialog($this->config,$this->dn);
512       }
514       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
515        * We only can delete if there is an entry selected.
516        */
517       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
518         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
519       }
521       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
522        * There must be an entry selected to perform edit request.
523        */
524       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
525         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
526         $this->is_dialog = true;
527         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
528       }
529     }
531     /* Append List to smarty*/
532     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
533     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
535     /* In this section server shares will be defined 
536      * A user can select one of the given shares and a mount point
537      *  and attach this combination to his setup.
538      */
540     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
541     if(!is_array($this->gotoShareSelections)){
542       print $this->gotoShareSelections;
543       $this->gotoShareSelections = array();
544     }
545     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
547     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
548      * This entry will be, a combination of mountPoint and sharedefinitions 
549      */
550     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
551       /* We assign a share to this user, if we don't know where to mount the share */
552       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
553         print_red(_("You must specify a valid mount point."));
554       }elseif(!(
555             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
556             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
557             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
558             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
559             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
560             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
561             preg_match("/^%/",$_POST['gotoShareMountPoint'])
562             )
563           ){
564         print_red(_("You must specify a valid mount point.")); 
565       }else{
566         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
567         $s_mount = $_POST['gotoShareMountPoint'];
568         $s_user  = $_POST['ShareUser'];
569         /* Preparing the new assignment */ 
570         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
571         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
572         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
573         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
574       }
575     }  
577     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
578      * If there is no defined share selected, we will abort the deletion without any message 
579      */
580     $once = true;
581     if($this->acl_is_writeable("gotoShare")){
582       foreach($_POST as $name => $value){
583         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
584           $once = false;  
585           $key  = preg_replace("/^gotoShareDel_/","",$name);
586           $key  = preg_replace("/_+[xy]$/","",$key);
587           $key  = base64_decode($key);
588           if(isset($this->gotoShares[$key])) {
589             unset($this->gotoShares[$key]);
590           }
592           /* Remove corresponding password entry, too. This is a workaround
593              to get rid of old-style entries. */
594           $key= preg_replace("/\|/", "|!", $key);
595           if(isset($this->gotoShares[$key])) {
596             unset($this->gotoShares[$key]);
597           }
598         }
599         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
600           $once = false;
601           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
602           $key  = preg_replace("/_+[xy]$/","",$key);
603           $key  = base64_decode($key);
604           $this->gotoShares[$key]['PwdHash'] = "";
605           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
606             unset($this->gotoShares[$key]);
607           }
608         }
609       }
610     }
611     $divlistShares = new divSelectBox("gotoShares");
612     $divlistShares->SetHeight(100);
613     $tmp = $this->printOutAssignedShares();
615     foreach($tmp as $key => $value){
616       $img = "";
618       /* Check if entry starts with an ! */
619       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
621         /* If we are currently editing groups environment, skip those ! entries */ 
622         if($this->is_group) continue;
624         /* Create pwd reset images */
625         if($this->gotoShares[$key]['PwdHash'] != ""){
626           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
627             title='"._("Reset password hash")."'>";
628         }
629         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
630         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
631       }else{
633         /* Create pwd reset img && delete image */
634         if($this->gotoShares[$key]['PwdHash'] != ""){
635           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
636             title='"._("Reset password hash")."'>";
637           $img.= "&nbsp;";
638         }
639         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
640           title='"._("Delete share entry")."'>";
641         $field1 = array("string" => $value);
642         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
643       }
644       $divlistShares->AddEntry(array($field1,$field2));
645     }
646     $smarty->assign("divlistShares",$divlistShares->DrawList());
648     /* Hotplug devices will be handled here 
649      * There are 3 possible methods for this feature
650      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
651      * Delete will erase an entry, the entry must be selcted in the ListBox first
652      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
653      */
655     /* If there is a new entry wanted, open a new entry by initilising the dialog */
656     if((isset($_POST['gotoHotplugDeviceNew'])) && ($this->acl_is_writeable("gotoHotplugDevice"))){
657       $this->dialog = new hotplugDialog($this->config,$this->dn);
658       $this->is_dialog = true;
659     }
661     /* We have to delete the selected hotplug from the list*/
662     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice'])) && $this->acl_is_writeable("gotoHotplugDevice")){
663       if($this->acl_is_writeable("gotoHotplugDevice")){
664         foreach($_POST['gotoHotplugDevice'] as $name){
665           unset($this->gotoHotplugDevices[$name]);
666         }
667       }
668     }
670     /* There are already defined hotplugs from other users we could use */
671     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
672       $tmp  =array();
673       foreach($this->gotoHotplugDevices as $plugs){
674         $tmp[] = $plugs['name'];
675       }
676       $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
677       $this->is_dialog = true;
678     }
680     /* Dialog Aborted */
681     if(isset($_POST['HotPlugCancel'])){
682       unset($this->dialog);
683       $this->dialog= NULL;
684       $this->is_dialog = false;
685     }
687     /* Dialod saved */
688     if(isset($_POST['HotPlugSave'])){
690       $this->dialog->save_object();
691       if(count($this->dialog->check())!=0){
692         foreach($this->dialog->check() as $msg){
693           print_red($msg);
694         }
695       }else{
696         $this->dialog->save_object();
697         $a_tmp = $this->dialog->save();
699         if(is_array($a_tmp)){
700           foreach($a_tmp as $name => $hotplug){
701             $this->gotoHotplugDevices[$name]= $hotplug; 
702           }
703         }
704         unset($this->dialog);
705         $this->dialog= NULL;
706         $this->is_dialog = false;
707       }
708     }
709     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
710     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
712     /* Printer Assignment will managed below 
713      * A printer can be assigned in two different ways and two different types
714      * There are 2 types of users assigned to a printer : user and admin
715      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
716      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
717      */ 
719     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
720     if(isset($_POST['gotoPrinterAdd'])){
722       $this->is_dialog=true;
723       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
724     }
726     if(isset($_POST['PrinterCancel'])){
727       $this->is_dialog=false;
728       unset($this->dialog);
729       $this->dialog=NULL;
730     }
732     if(isset($_POST['PrinterSave'])){
733       if(count($this->dialog->check())!=0){
734         $tmp = $this->dialog->check();
735         foreach($tmp as $msg){
736           print_red($msg);
737         } 
738       }else{
739         $this->dialog->save_object();
740         $tmp = $this->dialog->save();
741         $tmp2= $this->dialog->getPrinter(true);
743         foreach($tmp as $pname){
744         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn']);
745           if($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
746             $this->gotoPrinter[$pname]=$tmp2[$pname];
747             $this->gotoPrinter[$pname]['mode']="user";
748             $this->add_del_printer_member_was_called = true;
749           }
750         }
752         $this->is_dialog=false;
753         unset($this->dialog);
754         $this->dialog   =NULL;
755       }
756     }
758     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
759       $printer = $_POST['gotoPrinterSel'];
760       foreach($printer as $pname){
762         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn']);
763         if($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->dn)){
764           unset($this->gotoPrinter[$pname]);
765           $this->add_del_printer_member_was_called = true;
766         }
767       }
768     }
770     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
773       $printers = $_POST['gotoPrinterSel'];
775       foreach($printers as $printer){
776         if($this->gotoPrinter[$printer]['mode']=="user"){
777           $this->gotoPrinter[$printer]['mode']="admin";
778         }else{
779           $this->gotoPrinter[$printer]['mode']="user";
780         }
781       }
782     }
784     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
785       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
786         $this->gosaDefaultPrinter= "";
787       } else {
788         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
789       }
790     }
792     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
793     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
795     /* General behavior */
796     if($this->acl_is_writeable("gotoKioskProfile")){
797     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
798       $this->dialog->save_object();
799       $disp =$this->dialog->execute();
801       $tmp = new kioskManagementDialog($this->config,$this->dn);
802       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
803       $list['none']=_("None");
804       $list = array_reverse($list);
805       if(!isset($list[$this->gotoKioskProfile])){
806         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
807         $this->gotoKioskProfile = 'none';
808       }
809       return($disp);
810       }
811     }
813     /* Als smarty vars are set. Get smarty template and generate output */
814     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
815     return($display);
816   }
818   function remove_from_parent()
819   {
820     /* only if it was an account*/
821     if (!$this->initially_was_account){
822       return;
823     }
825     /* include global link_info */
826     $ldap= $this->config->get_ldap_link();
828     /* Remove and write to LDAP */
829     plugin::remove_from_parent();
831     /* Don't save our template variables */
832     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
834     /* Skip all these attributes */
835     foreach($skip as $del){
836       unset($this->attrs[$del]);
837     }
839     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
841     $ldap->cd($this->dn);
842     $this->cleanup();
843     $ldap->modify ($this->attrs); 
845     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
847     /* Optionally execute a command after we're done */
848     $this->handle_post_events("remove");
849   }
852   /* Save data to object */
853   function save_object()
854   {
855     /* Get all Posted vars 
856      * Setup checkboxes 
857      */
859     if(isset($_POST['iamposted'])){
860       if(isset($_POST['useProfile'])){
861         $this->useProfile = true;
862       }else{
863         $this->useProfile = false;
864       }
865       if(isset($_POST['gotoProfileFlagC'])){
866         $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
867       }else{
868         $this->gotoProfileFlagC = false;
869       }
870       if(isset($_POST['gotoProfileFlagL'])){
871         $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
872       }else{
873         $this->gotoProfileFlagL = false;
874       }
876       $tmp= $this->gosaDefaultPrinter;
877       plugin::save_object();
878       foreach($this->attributes as $s_attr){
879         if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
880         if(isset($_POST[$s_attr])){
881           $this->$s_attr = $_POST[$s_attr];
882         }else{
883           $this->$s_attr = false;
884         }
885       }
886       $this->gosaDefaultPrinter= $tmp;
887     }
888   }
891   /* Check supplied data */
892   function check()
893   {
894     /* Call common method to give check the hook */
895     $message= plugin::check();
897     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
898       $message[]=_("Please set a valid profile quota size.");
899     } 
900     if(!isset($this->attrs['objectClass'])){
901       $this->attrs['objectClass']=array();
902     } 
903     if(!$this->is_group){
904       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
905         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
906       }
907     }
908     return ($message);
909   }
912   /* Save to LDAP */
913   function save()
914   {
915     /* If group was renamed, all printer settings get lost
916      */ 
917     /* only save changed variables ....*/
918     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
919     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
920       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
921         $method="https://";
922       }else{
923         $method="http://";
924       }
926       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
927       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
928     }else{
929       $this->gotoKioskProfile= array();
930     }
932     plugin::save();
933     $ldap= $this->config->get_ldap_link();
935     $realyUsedAttrs= array();
937     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
938     /* Creating Kiosk Profiles */
939     foreach($this->newKioskProfiles as $file){
940       $contents = $file['contents'];
941       $fp = @fopen($path."/".$file['name'],"w");
942       if(!$fp){
943         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
944       }else{
945         fwrite($fp,$contents,strlen($contents));
946       }
947       @unlink($file['tmp_name']);
948     }
950     /* Save already used objectClasses */
951     $ocs        = $this->attrs['objectClass'];
952     unset($ocs['count']);
953     $this->attrs = array();
954     $this->attrs['objectClass']= $ocs;
955     foreach($this->objectclasses as $objc){
956       if(!in_array($objc,$this->attrs['objectClass'])){
957         $this->attrs['objectClass'][]=$objc;
958       }
959     }
961     /* 1. Search all printers that have our uid/cn as member 
962      * 2. Delete this uid/cn from every single entry and save it again.
963      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
964      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
965      */
966     
967     if($this->add_del_printer_member_was_called){
969       $types = array( "gotoUserPrinter"       => "AddUser",
970           "gotoGroupPrinter"      => "AddGroup",
971           "gotoUserAdminPrinter"  => "AddAdminUser",
972           "gotoGroupAdminPrinter" => "AddAdminGroup");
974       if($this->is_group){
975         $s_suffix = "Group";
976         $useVar   = "cn";
977       }else{
978         $useVar   = "uid";
979         $s_suffix = "User";
980       }
982       /* Remove old entries */
983       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
984       while($attr = $ldap->fetch()){
985         $printerObj = NULL;
986         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
987         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
988         $printerObj->by_object['printgeneric']->save();
989       }
991       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
992       while($attr = $ldap->fetch()){
993         $printerObj = NULL;
994         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
995         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
996         $printerObj->by_object['printgeneric']->save();
997       }
999       foreach($this->gotoPrinter as $printer){
1000         $printerObj = NULL;
1001         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1003         if($printer['mode'] == "admin") {
1004           $attribute = "goto".$s_suffix."AdminPrinter";
1005         }else{
1006           $attribute = "goto".$s_suffix."Printer";
1007         }
1009         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1010         $printerObj->by_object['printgeneric']->save();
1011       }
1012     }    
1014     /* Prepare HotPlug devices */
1015     $this->attrs['gotoHotplugDevice'] = array();
1016     foreach($this->gotoHotplugDevices as $name => $device){
1017       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1018         "|".$device['produkt']."|".$device['vendor'];
1019     }
1021     /* Prepare LogonScripts */
1022     $this->attrs['gotoLogonScript'] = array();
1023     foreach($this->gotoLogonScripts as $name => $script){
1024       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1025         $script['LogonOverload'].$script['LogonLast']."|".
1026         $script['LogonPriority']."|".
1027         base64_encode($script['LogonData'])."|".
1028         $script['LogonDescription'];
1029     }
1031     /* Prepare Shares */
1032     $this->attrs['gotoShare']=array();
1033     foreach($this->gotoShares as $name => $share){
1034       $mntp= $share['mountPoint'];
1035       if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1036         $mntp= base64_encode($mntp);
1037       }
1038       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1039     }
1042     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1043     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1045     foreach($saveThis as $tosave){
1046       if(!empty($this->$tosave)){
1047         $this->attrs[$tosave]=$this->$tosave;
1048       }else{
1049         $this->attrs[$tosave]=array();
1050       }
1051     }
1053     /* Prepare Flags */
1054     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1055     if(empty($this->attrs['gotoProfileFlags'][0])){
1056       $this->attrs['gotoProfileFlags']=array();
1057     }
1059     if($this->useProfile == false){
1060       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1061       $this->attrs['gotoProfileServer']= array(); 
1062     }
1064     $ldap->cat ($this->dn, array('dn'));
1065     if ($ldap->fetch()){
1066       $mode= "modify";
1067     } else {
1068       $mode= "add";
1069       $ldap->cd($this->config->current['BASE']);
1070       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1071     }
1073     $ldap->cd($this->dn);
1074     $this->cleanup();
1075     $ldap->$mode($this->attrs);
1076     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1077     $this->handle_post_events($mode);
1078   }
1080   /* Generate ListBox frindly output for the defined shares 
1081    * Possibly Add or remove an attribute here, 
1082    */
1083   function printOutAssignedShares()
1084   {
1085     $a_return = array();
1086     if(is_array($this->gotoShares)){
1087       foreach($this->gotoShares as $share){
1088         if(preg_match("/^!/",$share['server'])){
1089           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1090         }else{
1091           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1092         }
1093       }
1094       natcasesort($a_return);
1095     }
1096     return($a_return);
1097   }
1099   /* Generate ListBox frindly output for the definedhotplugs 
1100    * Possibly Add or remove an attribute here,
1101    */
1102   function printOutHotPlugDevices()
1103   {
1104     $a_return= array();
1105     if(is_array($this->gotoHotplugDevices)){
1106       foreach($this->gotoHotplugDevices as $key=>$device){
1107         $a_return[$key] = $device['name']." - ".$device['id'];
1108       }
1109     }
1110     return($a_return);
1111   }
1113   /* Generates ListBox frienly output of used printer devices 
1114    * Append ' - admin' if printer is used in admin mode
1115    */
1116   function printOutPrinterDevices()
1117   {
1118     $a_return = array();
1119     if(is_array($this->gotoPrinter)){
1120       foreach($this->gotoPrinter as $printer){
1121         if($printer['mode'] == "admin"){
1122           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1123         }else{
1124           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1125         }
1126         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1127           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1128         }
1129       }
1130     }
1131     return($a_return);
1132   }
1134   /* Generates ListBox frienly output of used logonscripts 
1135    */
1136   function printOutLogonScripts()
1137   {
1138     $a_return = array();
1139     if(is_array($this->gotoLogonScripts)){
1140       foreach($this->gotoLogonScripts as $script){
1141         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1142       }
1143     }
1144     return($a_return);
1145   }
1148   /* Return plugin informations for acl handling 
1149 #FIXME these ACLs should work for groups too */ 
1150   function plInfo()
1151   {
1152     return (array("plShortName"     => _("Environment"),
1153           "plDescription"   => _("Environment settings"),         // Description
1154           "plSelfModify"    => TRUE,                              
1155           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1156           "plPriority"      => 2,                                 // Position in tabs 
1157           "plSection"       => "personal",                        // This belongs to personal
1158           "plCategory"      => array("users", "groups"),          // Add to following categories 
1159           "plOptions"       => array("resolution_hook" => array("type" => "string",
1160               "description" => _("Command to extend the list of possible screen resolutions"))),
1162           "plProvidedAcls"  => array(
1164             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1165             "gotoProfileFlagC"    => _("Cache profile localy") ,
1167             "gotoProfileQuota"    => _("Profile quota") ,
1168             "gotoProfileServer"   => _("Profile server") ,
1170             "gotoXResolution"     => _("Resolution") ,
1171             "gotoKioskProfile"    => _("Kiosk profile") ,
1173             "gosaDefaultPrinter"  => _("Default printer") ,
1174             "gotoLogonScript"     => _("Logon script") ,
1175             "gotoHotplugDevice"   => _("Hotplug devices"),
1176             "gotoShare"           => _("Shares"))
1177             ));
1178   }
1181 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1182 ?>