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
16 var $in_dialog = false;
17 var $uid = "";
19 var $is_group = false;
20 var $view_logged = FALSE;
22 /* Attribute definition
23 */
25 /* profile management */
26 var $useProfile = false; // Specifies if we want to use a Server
27 var $gotoProfileServer = ""; // Specifies the selected profile server
28 var $gotoProfileServers = array();// Specifies all available and selectable servers
29 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
30 var $gotoProfileFlagC = ""; // Flag is set to C if we have the profile caching fucntion enabled
32 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
33 var $gotoXResolutions = array();// Contains all available resolutions for this account
34 var $gotoProfileFlagL = ""; // Flag is set to L to enable runtime resolution change
35 var $gotoProfileQuota = ""; // User Quota Settings
37 /* Logon script section*/
38 var $gotoLogonScripts = array();// Contains all available Logon Scripts
39 var $gotoLogonScript = ""; // The selected Logon Script
41 /* Printer */
42 var $gotoPrinter = array();// All available Printer, with their configurations
43 var $gotoPrinterSel = ""; // The selected Printer
44 var $gosaDefaultPrinter = ""; // Default printer
46 /* Share */
47 var $gotoShares = array();// Current Share Options
48 var $gotoShare = ""; // currently selected Share Option
49 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
50 var $gotoAvailableShares= array();// Available Shares for this account
52 /* Kiosk profile */
53 var $kiosk_enabled = FALSE;
54 var $gotoKioskProfile = ""; // The selected Kiosk Profile
55 var $gotoKioskProfile_Server = ""; // The selected Kiosk Profile
56 var $gotoKioskProfile_Profile = ""; // The selected Kiosk Profile
57 var $gotoKioskProfiles = array();// All available Kiosk profiles
59 /* Hotplug Devices */
60 var $gotoHotplugDevice = array(); // Selected hotplug
61 var $gotoHotplugDevices = array();// Already configured hotplug devices
62 var $gotoHotplugDeviceDN= array();
64 var $NewAddedPrinters = array();
65 var $NewDeletedPrinters = array();
67 /* general settings */
68 // Sets the attributes which will kept on page reload, which will be saved, ...
70 var $CopyPasteVars = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
72 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
73 "gotoXResolution","gotoProfileQuota",
74 "gotoLogonScripts","gotoLogonScript",
75 "gotoPrinter", "gosaDefaultPrinter",
76 "gotoShares","gotoShare",
77 "gotoKioskProfile");
78 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
79 var $cn;
80 var $OrigCn;
81 var $add_del_printer_member_was_called = false;
83 var $multiple_support =TRUE;
85 function environment (&$config, $dn= NULL)
86 {
87 plugin::plugin ($config, $dn);
89 /* Setting uid to default */
90 if(isset($this->attrs['uid'][0])){
91 $this->uid = $this->attrs['uid'][0];
92 }
94 /* Check : Are we currently editing a group or user dialog */
95 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
96 $suffix="Group";
97 $this->uid = $this->attrs['cn'][0];
98 $this->attrs['uid'] = $this->attrs['cn'][0];
99 $this->OrigCn = $this->attrs['cn'][0];
100 }else{
101 $suffix="User";
102 }
104 /* Get all Printer assignments */
105 $ldap = $this->config->get_ldap_link();
106 $ldap->cd($this->config->current['BASE']);
107 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
108 while($printer = $ldap->fetch()){
109 $this->gotoPrinter[$printer['cn'][0]]=$printer;
110 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
111 }
112 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
113 while($printer = $ldap->fetch()){
114 $this->gotoPrinter[$printer['cn'][0]]=$printer;
115 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
116 }
119 /* Prepare hotplugs */
120 if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
121 $ldap = $this->config->get_ldap_link();
122 $ldap->cd($this->config->current['BASE']);
123 for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
124 $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
125 if($ldap->count()){
126 $attrs = $ldap->fetch();
128 if(isset($attrs['gotoHotplugDevice'][0])){
129 $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
130 $tmp2 = array();
131 $tmp2['name'] = $attrs['cn'][0];
132 $tmp2['description'] = $tmp[0];
133 $tmp2['id'] = $tmp[1];
134 $tmp2['produkt'] = $tmp[2];
135 $tmp2['vendor'] = $tmp[3];
136 $tmp2['dn'] = $attrs['dn'];
137 $this->gotoHotplugDevices[] = $tmp2;
138 }
139 }else{
140 print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
141 }
142 }
143 }
146 /* prepare LogonScripts */
147 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
148 unset($this->attrs['gotoLogonScript']['count']);
149 foreach($this->attrs['gotoLogonScript'] as $device){
150 $tmp = $tmp2 = array();
151 $tmp = split("\|",$device);
152 $tmp2['LogonName'] = $tmp[0];
153 $tmp2['LogonPriority'] = $tmp[2];
154 if(preg_match("/O/i",$tmp[1])){
155 $tmp2['LogonOverload'] = "O";
156 }else{
157 $tmp2['LogonOverload'] = "";
158 }
159 if(preg_match("/L/i",$tmp[1])){
160 $tmp2['LogonLast'] = "L";
161 }else{
162 $tmp2['LogonLast'] = "";
163 }
164 $tmp2['LogonData'] = base64_decode($tmp[3]);
165 $tmp2['LogonDescription'] = $tmp[4];
166 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
167 }
168 }
170 /* Prepare Shares */
171 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
172 unset($this->attrs['gotoShare']['count']);
173 foreach($this->attrs['gotoShare'] as $share){
174 $tmp = $tmp2 = array();
175 $tmp = split("\|",$share);
176 $tmp2['server'] =$tmp[0];
177 $tmp2['name'] =$tmp[1];
179 /* Decode base64 if needed */
180 if (!preg_match('%/%', $tmp[2])){
181 $tmp2['mountPoint'] =base64_decode($tmp[2]);
182 } else {
183 $tmp2['mountPoint'] =$tmp[2];
184 }
186 if(isset($tmp[3])){
187 $tmp2['PwdHash'] =$tmp[3];
188 }else{
189 $tmp2['PwdHash'] ="";
190 }
191 if(isset($tmp[4])){
192 $tmp2['Username'] =$tmp[4];
193 }else{
194 $tmp2['Username'] ="";
195 }
196 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
197 }
198 }
200 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
201 $chr = $this->gotoProfileFlags[$i];
202 $name = "gotoProfileFlag".$chr;
203 $this->$name=$chr;
204 }
206 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
207 $this->useProfile = true;
208 }else{
209 $this->useProfile = false;
210 }
212 /* Set resolutions */
213 $this->gotoXResolutions = array("auto"=>_("auto"),
214 "640x480" => "640x480",
215 "800x600" => "800x600",
216 "1024x768" => "1024x768",
217 "1152x864" => "1152x864",
218 "1280x768" => "1280x768",
219 "1280x1024" => "1280x1024");
221 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
222 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
224 if(is_readable($file)){
225 $str = file_get_contents($file);
226 $lines = split("\n",$str);
227 foreach($lines as $line){
228 $line = trim($line);
229 if(!empty($line)){
230 $this->gotoXResolutions[$line]=$line;
231 }
232 }
233 //natcasesort($this->gotoXResolutions);
234 }else{
235 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
236 }
237 }
239 $this->gotoProfileServers= $config->getShareServerList() ;
240 $this->gotoShareSelections= $config->getShareList(true);
241 $this->gotoAvailableShares= $config->getShareList(false);
243 $this->update_kiosk_profiles();
245 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
246 }
249 function update_kiosk_profiles()
250 {
251 $tmp1 = array("none" => array(_("disabled")));
252 $tmp2 = array("none" => _("disabled"));
253 $ldap = $this->config->get_ldap_link();
254 $ldap->cd($this->config->current['BASE']);
255 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
256 $cnt = 0;
257 while($attrs = $ldap->fetch()){
258 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
259 $name = preg_replace("/^.*kiosk\//","",$attrs['gotoKioskProfile'][$i]);
260 $tmp1[$attrs['cn'][0]][] = $name;
261 }
262 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
263 $cnt ++;
264 }
266 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
267 $this->kiosk_enabled = TRUE;
268 }
270 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
271 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
273 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
274 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
276 $error = false;
277 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
278 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
279 $error = true;
280 }
281 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
282 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
283 $error = true;
284 }
285 if($error && !empty($this->gotoKioskProfile)){
286 print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
287 $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
288 }
289 }
292 /* Detect type of edited object (user|group)*/
293 function detect_grouptype()
294 {
295 if((!isset($this->parent))&&(!$this->is_account)){
296 $this->is_group = false;
297 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
298 $this->is_group = true;
299 }else{
300 $this->is_group = false;
301 }
302 }
305 function execute()
306 {
308 /* Call parent execute */
309 plugin::execute();
310 /* Log view */
311 if($this->is_account && !$this->view_logged){
312 $this->view_logged = TRUE;
313 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
314 new log("view","users/".get_class($this),$this->dn);
315 }else{
316 new log("view","groups/".get_class($this),$this->dn);
317 }
318 }
320 /* Are we editing from MyAccount and not editing a user */
321 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
323 /* Check profile server */
324 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
325 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
326 if(count($this->gotoProfileServers)){
328 /* Get First Profile */
329 $new = key($this->gotoProfileServers);
331 /* Another profile server found */
332 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
333 $this->gotoProfileServer,$new));
334 }else{
336 /* No other profile servers found */
337 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
338 $this->gotoProfileServer));
339 $this->gotoProfileServer = "";
340 }
341 }
342 }
344 $this->detect_grouptype();
346 /* Fill templating stuff */
347 $smarty= get_smarty();
348 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
349 $display= "";
351 $smarty->assign("is_group",$this->is_group);
353 /* Prepare all variables for smarty */
354 foreach($this->attributes as $s_attr){
355 /* Set value*/
356 $smarty->assign($s_attr,$this->$s_attr);
358 /* Set checkbox state*/
359 if(empty($this->$s_attr)){
360 $smarty->assign($s_attr."CHK","");
361 }else{
362 $smarty->assign($s_attr."CHK"," checked ");
363 }
365 /* Prepare ACL settings*/
366 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
367 }
369 /* Is accout enabled | are we editing from usermenu or admin menu
370 All these tab management is done here
371 */
374 /* Working from Usermenu an the Account is currently disbled
375 * this->parent : is only set if we are working in a list of tabs
376 * is_account : is only true if the needed objectClass is given
377 */
378 if((!isset($this->parent))&&(!$this->is_account)){
379 /* We are currently editing this tab from usermenu, but this account is not enabled */
380 $smarty->assign("is_account",$this->is_account);
381 /* Load template */
382 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
383 /* Avoid the "You are currently editing ...." message when you leave this tab */
384 $display .= back_to_main();
385 /* Display our message to the user */
386 return $display;
389 /* We are currently editing from group tabs, because
390 * $this->parent is set
391 * posixAccount is not set, so we are not in usertabs.
392 */
393 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
394 $smarty->assign("is_account","true");
395 $this->uid = $this->cn;
396 $this->attrs['uid'] = $this->cn;
398 /* Change state if needed */
399 if (isset($_POST['modify_state'])){
400 if(($this->acl_is_createable() && !$this->is_account) ||
401 ($this->acl_is_removeable() && $this->is_account)){
402 $this->is_account= !$this->is_account;
403 }
404 }
405 /* Group Dialog with enabled environment options */
406 if ($this->is_account){
407 $display= $this->show_enable_header(_("Remove environment extension"),
408 _("Environment extension enabled. You can disable it by clicking below."));
409 } else {
411 /* Environment is disabled
412 If theres is no posixAccount enabled, you won't be able to enable
413 environment extensions
414 */
415 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
416 // 4. There is a PosixAccount
417 $display= $this->show_enable_header(_("Add environment extension"),
418 _("Environment extension disabled. You can enable it by clicking below."));
419 return $display;
420 }else{
421 // 4. There is no PosixAccount
422 $display= $this->show_enable_header(_("Add environment extension"),
423 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
424 return $display;
425 }
426 }
427 }else{
428 /* Editing from Usermenu
429 * Tell smarty that this accoutn is enabled
430 */
431 $smarty->assign("is_account","true");
433 /* Change state if needed */
434 if (isset($_POST['modify_state'])){
435 if(($this->acl_is_createable() && !$this->is_account) ||
436 ($this->acl_is_removeable() && $this->is_account)){
437 $this->is_account= !$this->is_account;
438 }
439 }
441 if(isset($this->parent)){
443 // 3. Account enabled . Editing from adminmenu
444 if ($this->is_account){
445 $display= $this->show_disable_header(_("Remove environment extension"),
446 _("Environment extension enabled. You can disable it by clicking below."));
447 } else {
449 if($this->parent->by_object['posixAccount']->is_account==true){
450 // 4. There is a PosixAccount
451 $display= $this->show_disable_header(_("Add environment extension"),
452 _("Environment extension disabled. You can enable it by clicking below."));
453 return $display;
454 }else{
455 // 4. There is a PosixAccount
456 $display= $this->show_disable_header(_("Add environment extension"),
457 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
458 return $display;
459 }
460 }
461 }
462 }
464 /* Reset header toggle */
465 if($this->multiple_support_active){
466 $display = "";
467 }
469 /* Account is Account : is_accounbt=true.
470 * Else we won't reach this.
471 */
473 /* Prepare all variables for smarty */
474 foreach($this->attributes as $s_attr){
475 /* Set value*/
476 $smarty->assign($s_attr,$this->$s_attr);
478 /* Set checkbox state*/
479 if(empty($this->$s_attr)){
480 $smarty->assign($s_attr."CHK","");
481 }else{
482 $smarty->assign($s_attr."CHK"," checked ");
483 }
485 /* Prepare ACL settings*/
486 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
487 }
489 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
490 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
491 }
493 if($WriteOnly) {
494 $smarty->assign("gotoPrinterACL","r");
495 }else{
496 $smarty->assign("gotoPrinterACL","rw");
497 }
499 if(empty($this->useProfile)){
500 $smarty->assign("useProfileCHK","");
501 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
502 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
503 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
504 }else{
505 $smarty->assign("useProfileCHK"," checked ");
506 }
508 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
509 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
511 /* HANDLE Profile Settings here
512 * Assign available Quota and resolution settings
513 * Get all available profile server
514 * Get cache checkbox
515 * Assign this all to Smarty
516 */
518 if(empty($this->gotoProfileFlagL)){
519 $smarty->assign("gotoProfileFlagLCHK"," ");
520 }else{
521 $smarty->assign("gotoProfileFlagLCHK"," checked ");
522 }
524 if(empty($this->gotoProfileFlagC)){
525 $smarty->assign("gotoProfileFlagCCHK"," ");
526 }else{
527 $smarty->assign("gotoProfileFlagCCHK"," checked ");
528 }
531 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
532 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
534 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
535 if(!is_array($this->gotoProfileServers)){
536 $this->gotoProfileServers =array();
537 }
538 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
540 /* Handle kiosk profiles*/
541 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
542 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
543 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
544 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
547 /* Logonscript Management
548 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
549 * Perform add Delete edit Posts
550 */
552 /* Dialog Save */
553 if(isset($_POST['LogonSave'])){
555 if(!$this->acl_is_writeable("gotoLogonScript")){
556 print_red(_("You are not allowed to write Logon scripts."));
557 unset($this->dialog);
558 $this->dialog=FALSE;
559 $this->is_dialog=false;
560 }else{
561 $this->dialog->save_object();
562 if(count($this->dialog->check())!=0){
563 foreach($this->dialog->check() as $msg){
564 print_red($msg);
565 }
566 }else{
567 $tmp = $this->dialog->save();
568 unset($this->dialog);
569 $this->dialog=FALSE;
570 $this->is_dialog=false;
571 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
572 }
573 }
574 }
577 /* Dialog Quit without saving */
578 if(isset($_POST['LogonCancel'])){
579 $this->is_dialog= false;
580 unset($this->dialog);
581 $this->dialog= FALSE;
582 }
584 /* Check Edit Del New Posts for a selected LogonScript */
585 if($this->acl_is_writeable("gotoLogonScript") &&
586 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
588 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
589 * In this case we create a new Logon Script.
590 */
591 if(isset($_POST['gotoLogonScriptNew'])){
592 $this->is_dialog = true;
593 $this->dialog = new logonManagementDialog($this->config,$this->dn);
594 }
596 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
597 * We only can delete if there is an entry selected.
598 */
599 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
600 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
601 }
603 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
604 * There must be an entry selected to perform edit request.
605 */
606 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
607 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
608 $this->is_dialog = true;
609 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
610 }
611 }
613 /* Append List to smarty*/
614 $ls = $this->printOutLogonScripts();
615 $smarty->assign("gotoLogonScripts", $ls);
616 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
617 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
619 /* In this section server shares will be defined
620 * A user can select one of the given shares and a mount point
621 * and attach this combination to his setup.
622 */
624 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
625 if(!is_array($this->gotoShareSelections)){
626 $this->gotoShareSelections = array();
627 }
628 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
630 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
631 * This entry will be, a combination of mountPoint and sharedefinitions
632 */
633 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
635 /* We assign a share to this user, if we don't know where to mount the share */
636 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
637 print_red(_("You must select a valid share."));
638 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
639 print_red(_("You must specify a valid mount point."));
640 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
641 print_red(_("Spaces are not allowed in the mount path!"));
642 }elseif(!(
643 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
644 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
645 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
646 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
647 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
648 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
649 preg_match("/^%/",$_POST['gotoShareMountPoint'])
650 )
651 ){
652 print_red(_("You must specify a valid mount point."));
653 }else{
654 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
655 $s_mount = $_POST['gotoShareMountPoint'];
656 $s_user = $_POST['ShareUser'];
657 /* Preparing the new assignment */
658 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
659 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
660 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
661 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
663 if($this->multiple_support_active){
664 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
665 }
666 }
667 }
669 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
670 * If there is no defined share selected, we will abort the deletion without any message
671 */
672 $once = true;
673 if($this->acl_is_writeable("gotoShare")){
674 foreach($_POST as $name => $value){
675 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
676 $once = false;
677 $key = preg_replace("/^gotoShareDel_/","",$name);
678 $key = preg_replace("/_+[xy]$/","",$key);
679 $key = base64_decode($key);
680 if(isset($this->gotoShares[$key])) {
681 unset($this->gotoShares[$key]);
682 }
684 /* Remove corresponding password entry, too. This is a workaround
685 to get rid of old-style entries. */
686 $key= preg_replace("/\|/", "|!", $key);
687 if(isset($this->gotoShares[$key])) {
688 unset($this->gotoShares[$key]);
689 }
690 }
691 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
692 $once = false;
693 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
694 $key = preg_replace("/_+[xy]$/","",$key);
695 $key = base64_decode($key);
696 $this->gotoShares[$key]['PwdHash'] = "";
697 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
698 unset($this->gotoShares[$key]);
699 }
700 }
701 }
702 }
703 $divlistShares = new divSelectBox("gotoShares");
704 $divlistShares->SetHeight(100);
707 $tmp = array();
708 if($this->acl_is_readable("gotoShares")){
709 $tmp = $this->printOutAssignedShares();
710 }
713 foreach($tmp as $key => $value){
714 $img = "";
716 /* Skip apssword only entries */
717 if( empty($this->gotoShares[$key]['server']) &&
718 empty($this->gotoShares[$key]['name']) &&
719 empty($this->gotoShares[$key]['mountPoint']) &&
720 empty($this->gotoShares[$key]['Username'])){
721 continue;
722 }
724 $color = "";
725 if($this->multiple_support_active){
726 if($this->gotoShares[$key]['UsedByAllUsers']){
727 $value .= " (<b>"._("Used by all users")."</b>)";
728 }else{
729 $color = "color: #999999;";
730 $value .= " (<b>"._("Used by some users")."</b>)";
731 }
732 }
734 /* Check if entry starts with an ! */
735 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
737 /* If we are currently editing groups environment, skip those ! entries */
738 if($this->is_group) continue;
740 /* Create pwd reset images */
741 if($this->gotoShares[$key]['PwdHash'] != ""){
742 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
743 title='"._("Reset password hash")."'>";
744 }
745 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
746 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
747 }else{
749 /* Create pwd reset img && delete image */
750 if($this->gotoShares[$key]['PwdHash'] != ""){
751 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
752 title='"._("Reset password hash")."'>";
753 $img.= " ";
754 }
755 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
756 title='"._("Delete share entry")."'>";
757 $field1 = array("string" => $value , "attach" => "style='".$color."'");
758 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
759 }
760 $divlistShares->AddEntry(array($field1,$field2));
761 }
762 $smarty->assign("divlistShares",$divlistShares->DrawList());
764 /* Hotplug devices will be handled here
765 * There are 3 possible methods for this feature
766 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
767 * Delete will erase an entry, the entry must be selcted in the ListBox first
768 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
769 */
771 /* We have to delete the selected hotplug from the list*/
772 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
773 if($this->acl_is_writeable("gotoHotplugDevice")){
774 foreach($_POST['gotoHotplugDevice_post'] as $name){
775 unset($this->gotoHotplugDevices[$name]);
776 }
777 }
778 }
780 /* There are already defined hotplugs from other users we could use */
781 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
782 $tmp =array();
783 foreach($this->gotoHotplugDevices as $plugs){
784 $tmp[] = $plugs['name'];
785 }
786 $this->dialog = new hotplugDialog($this->config,$tmp);
787 $this->is_dialog = true;
788 }
790 /* Dialog Aborted */
791 if(isset($_POST['HotPlugCancel'])){
792 unset($this->dialog);
793 $this->dialog= FALSE;
794 $this->is_dialog = false;
795 }
797 /* Dialod saved */
798 if(isset($_POST['HotPlugSave'])){
800 $this->dialog->save_object();
801 if(count($this->dialog->check())!=0){
802 foreach($this->dialog->check() as $msg){
803 print_red($msg);
804 }
805 }else{
806 $this->dialog->save_object();
807 $a_tmp = $this->dialog->save();
809 if(is_array($a_tmp)){
810 foreach($a_tmp as $name => $hotplug){
811 $this->gotoHotplugDevices[$name]= $hotplug;
812 }
813 }
814 unset($this->dialog);
815 $this->dialog= FALSE;
816 $this->is_dialog = false;
817 }
818 }
819 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
820 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
822 /* Printer Assignment will managed below
823 * A printer can be assigned in two different ways and two different types
824 * There are 2 types of users assigned to a printer : user and admin
825 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
826 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
827 */
829 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
830 if(isset($_POST['gotoPrinterAdd'])){
832 $this->is_dialog=true;
833 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
834 }
836 if(isset($_POST['PrinterCancel'])){
837 $this->is_dialog=false;
838 unset($this->dialog);
839 $this->dialog=FALSE;
840 }
842 if(isset($_POST['PrinterSave'])){
843 if(count($this->dialog->check())!=0){
844 $tmp = $this->dialog->check();
845 foreach($tmp as $msg){
846 print_red($msg);
847 }
848 }else{
849 $this->dialog->save_object();
850 $tmp = $this->dialog->save();
851 $tmp2= $this->dialog->getPrinter(true);
853 foreach($tmp as $pname){
854 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
855 $printerObj->set_acl_base($tmp2[$pname]['dn']);
857 $type = false;
859 if($this->is_group){
860 if($this->dn == "new"){
861 $type = "AddGroup";
862 }elseif(isset($this->NewDeletedPrinters[$pname])){
863 $type = "AddGroup";
864 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
865 $type = "AddGroup";
866 }
867 }else{
868 if(isset($this->NewDeletedPrinters[$pname])){
869 $type = "AddUser";
870 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
871 $type = "AddUser";
872 }
873 }
875 if($type){
876 $this->gotoPrinter[$pname]=$tmp2[$pname];
877 $this->gotoPrinter[$pname]['mode']="user";
878 $this->add_del_printer_member_was_called = true;
880 $this->NewAddedPrinters[$pname] = $pname;
881 if(isset($this->NewDeletedPrinters[$pname])){
882 unset($this->NewDeletedPrinters[$pname]);
883 }
884 }
885 }
887 $this->is_dialog=false;
888 unset($this->dialog);
889 $this->dialog =FALSE;
890 }
891 }
893 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
894 $printer = $_POST['gotoPrinterSel'];
895 foreach($printer as $pname){
897 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
898 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
900 $type = false;
901 if($this->is_group){
902 if(isset($this->NewAddedPrinters[$pname])){
903 $type = "Group";
904 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
905 $type = "Group";
906 }
907 }else{
908 if(isset($this->NewAddedPrinters[$pname])){
909 $type = "User";
910 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
911 $type = "User";
912 }
913 }
914 if($type){
915 $this->add_del_printer_member_was_called = true;
916 unset($this->gotoPrinter[$pname]);
918 $this->NewDeletedPrinters[$pname] = $pname;
919 if(isset($this->NewAddedPrinters[$pname])){
920 UNSET($this->NewAddedPrinters[$pname]);
921 }
922 }
923 }
924 }
926 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
927 $printers = $_POST['gotoPrinterSel'];
928 $this->add_del_printer_member_was_called = true;
929 foreach($printers as $printer){
930 if($this->gotoPrinter[$printer]['mode']=="user"){
931 $this->gotoPrinter[$printer]['mode']="admin";
932 }else{
933 $this->gotoPrinter[$printer]['mode']="user";
934 }
935 }
936 }
938 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
939 if($this->is_group){
940 print_red(_("GOsa default printer flag is not allowed within groups."));
941 }else{
942 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
943 $this->gosaDefaultPrinter= "";
944 } else {
945 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
946 }
947 }
948 }
950 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
951 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
953 /* General behavior */
954 if(is_object($this->dialog)){
955 $this->dialog->save_object();
956 $disp =$this->dialog->execute();
957 return($disp);
958 }
960 /* Als smarty vars are set. Get smarty template and generate output */
961 $smarty->assign("multiple_support",$this->multiple_support_active);
962 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
963 return($display);
964 }
966 function remove_from_parent()
967 {
968 /* only if it was an account*/
969 if (!$this->initially_was_account){
970 return;
971 }
973 /* include global link_info */
974 $ldap= $this->config->get_ldap_link();
976 /* Remove and write to LDAP */
977 plugin::remove_from_parent();
979 /* Don't save our template variables */
980 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
982 /* Skip all these attributes */
983 foreach($skip as $del){
984 unset($this->attrs[$del]);
985 }
987 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
989 $ldap->cd($this->dn);
990 $this->cleanup();
991 $ldap->modify ($this->attrs);
993 if($this->is_group){
994 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
995 }else{
996 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
997 }
999 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
1001 /* Optionally execute a command after we're done */
1002 $this->handle_post_events("remove",array("uid" => $this->uid));
1003 }
1006 /* Save data to object */
1007 function save_object()
1008 {
1009 /* Get all Posted vars
1010 * Setup checkboxes
1011 */
1012 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
1013 if(isset($_POST['iamposted'])){
1015 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1017 if(isset($_POST['kiosk_server'])){
1018 $tmp = $_POST['kiosk_server'];
1019 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1020 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1021 }
1022 }
1023 if(isset($_POST['kiosk_profile'])){
1024 $tmp = $_POST['kiosk_profile'];
1025 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1026 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1027 }
1028 }
1030 if(preg_match("/w/",$PACL)){
1031 if(isset($_POST['useProfile'])){
1032 $this->useProfile = true;
1033 }else{
1034 $this->useProfile = false;
1035 }
1036 }
1038 if($this->acl_is_writeable("gotoProfileFlagC")){
1039 if(isset($_POST['gotoProfileFlagC'])){
1040 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1041 }else{
1042 $this->gotoProfileFlagC = false;
1043 }
1044 }
1046 if($this->acl_is_writeable("gotoProfileFlagL")){
1047 if(isset($_POST['gotoProfileFlagL'])){
1048 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1049 }else{
1050 $this->gotoProfileFlagL = false;
1051 }
1052 }
1054 plugin::save_object();
1055 foreach($this->attributes as $s_attr){
1056 if((!isset($_POST[$s_attr])) ||
1057 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1058 if(!$this->acl_is_writeable($s_attr)){
1059 continue;
1060 }else{
1061 if(isset($_POST[$s_attr])){
1062 $this->$s_attr = $_POST[$s_attr];
1063 }else{
1064 $this->$s_attr = false;
1065 }
1066 }
1067 }
1068 }
1069 }
1072 /* Check supplied data */
1073 function check()
1074 {
1075 /* Call common method to give check the hook */
1076 $message= plugin::check();
1078 $this->detect_grouptype();
1080 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1081 $message[]=_("Please set a valid profile quota size.");
1082 }
1083 if(!isset($this->attrs['objectClass'])){
1084 $this->attrs['objectClass']=array();
1085 }
1086 if(!$this->is_group){
1087 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1088 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
1089 }
1090 }
1091 return ($message);
1092 }
1095 /* Save to LDAP */
1096 function save()
1097 {
1098 /* If group was renamed, all printer settings get lost
1099 */
1100 /* only save changed variables ....*/
1101 if ($this->gotoKioskProfile_Server != "none"){
1102 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1103 $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1104 }else{
1105 $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1106 }
1107 $this->gotoKioskProfile= $method;
1108 }else{
1109 $this->gotoKioskProfile= array();
1110 }
1112 plugin::save();
1113 $ldap= $this->config->get_ldap_link();
1115 $realyUsedAttrs= array();
1117 /* Save already used objectClasses */
1118 $ocs = $this->attrs['objectClass'];
1119 unset($ocs['count']);
1120 $this->attrs = array();
1121 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1123 /* 1. Search all printers that have our uid/cn as member
1124 * 2. Delete this uid/cn from every single entry and save it again.
1125 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1126 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1127 */
1129 $this->detect_grouptype();
1131 if($this->add_del_printer_member_was_called){
1133 $types = array( "gotoUserPrinter" => "AddUser",
1134 "gotoGroupPrinter" => "AddGroup",
1135 "gotoUserAdminPrinter" => "AddAdminUser",
1136 "gotoGroupAdminPrinter" => "AddAdminGroup");
1138 if($this->is_group){
1139 $s_suffix = "Group";
1140 $useVar = "cn";
1141 }else{
1142 $useVar = "uid";
1143 $s_suffix = "User";
1144 }
1146 /* Remove old entries */
1147 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1148 while($attr = $ldap->fetch()){
1149 $printerObj = NULL;
1150 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1151 $printerObj->set_acl_base($attr['dn']);
1152 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1153 $printerObj->by_object['printgeneric']->save();
1154 }
1156 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1157 while($attr = $ldap->fetch()){
1158 $printerObj = NULL;
1159 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1160 $printerObj->set_acl_base($attr['dn']);
1161 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1162 $printerObj->by_object['printgeneric']->save();
1163 }
1165 foreach($this->gotoPrinter as $printer){
1166 $printerObj = NULL;
1167 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1168 $printerObj->set_acl_base($printer['dn']);
1171 if($printer['mode'] == "admin") {
1172 $attribute = "goto".$s_suffix."AdminPrinter";
1173 }else{
1174 $attribute = "goto".$s_suffix."Printer";
1175 }
1177 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1178 $printerObj->by_object['printgeneric']->save();
1179 }
1180 }
1182 /* Prepare HotPlug devices */
1183 $this->attrs['gotoHotplugDeviceDN'] = array();
1184 foreach($this->gotoHotplugDevices as $name => $device){
1185 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1186 }
1188 /* Prepare LogonScripts */
1189 $this->attrs['gotoLogonScript'] = array();
1190 foreach($this->gotoLogonScripts as $name => $script){
1191 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1192 $script['LogonOverload'].$script['LogonLast']."|".
1193 $script['LogonPriority']."|".
1194 base64_encode($script['LogonData'])."|".
1195 $script['LogonDescription'];
1196 }
1198 /* Prepare Shares */
1199 $this->attrs['gotoShare']=array();
1200 foreach($this->gotoShares as $name => $share){
1201 $mntp= $share['mountPoint'];
1202 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1203 $mntp= base64_encode($mntp);
1204 }
1205 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1206 }
1209 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1210 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1212 foreach($saveThis as $tosave){
1213 if(!empty($this->$tosave)){
1214 $this->attrs[$tosave]=$this->$tosave;
1215 }else{
1216 $this->attrs[$tosave]=array();
1217 }
1218 }
1220 /* Prepare Flags */
1221 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1222 if(empty($this->attrs['gotoProfileFlags'][0])){
1223 $this->attrs['gotoProfileFlags']=array();
1224 }
1226 if($this->useProfile == false){
1227 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1228 $this->attrs['gotoProfileServer']= array();
1229 }
1231 $ldap->cat ($this->dn, array('dn'));
1232 if ($ldap->fetch()){
1233 $mode= "modify";
1234 } else {
1235 $mode= "add";
1236 $ldap->cd($this->config->current['BASE']);
1237 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1238 }
1240 $ldap->cd($this->dn);
1241 $this->cleanup();
1242 $ldap->$mode($this->attrs);
1244 $cat = "users";
1245 if($this->is_group){
1246 $cat = "groups";
1247 }
1249 /* Log last action */
1250 if($this->initially_was_account){
1251 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1252 }else{
1253 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1254 }
1256 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1257 $this->handle_post_events($mode,array("uid"=>$this->uid));
1258 }
1260 /* Generate ListBox frindly output for the defined shares
1261 * Possibly Add or remove an attribute here,
1262 */
1263 function printOutAssignedShares()
1264 {
1265 $a_return = array();
1266 if(is_array($this->gotoShares)){
1267 foreach($this->gotoShares as $share){
1268 if(preg_match("/^!/",$share['server'])){
1269 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1270 }else{
1271 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1272 }
1273 }
1274 natcasesort($a_return);
1275 }
1276 return($a_return);
1277 }
1279 /* Generate ListBox frindly output for the definedhotplugs
1280 * Possibly Add or remove an attribute here,
1281 */
1282 function printOutHotPlugDevices()
1283 {
1284 $a_return= array();
1285 if(is_array($this->gotoHotplugDevices)){
1286 foreach($this->gotoHotplugDevices as $key=>$device){
1287 $a_return[$key] = $device['name']." - ".$device['id'];
1288 }
1289 }
1290 return($a_return);
1291 }
1293 /* Generates ListBox frienly output of used printer devices
1294 * Append ' - admin' if printer is used in admin mode
1295 */
1296 function printOutPrinterDevices()
1297 {
1298 $a_return = array();
1300 if($this->acl_is_readable("gotoPrinter")){
1302 if(is_array($this->gotoPrinter)){
1303 foreach($this->gotoPrinter as $printer){
1304 if($printer['mode'] == "admin"){
1305 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1306 }else{
1307 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1308 }
1309 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1310 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1311 }
1312 }
1313 }
1314 }
1315 return($a_return);
1316 }
1319 function PrepareForCopyPaste($source)
1320 {
1321 plugin::PrepareForCopyPaste($source);
1323 $class= get_class($this);
1324 $o_source = new $class($this->config,$source['dn']);
1325 foreach($this->CopyPasteVars as $attr){
1326 $this->$attr = $o_source->$attr;
1327 }
1328 }
1331 function saveCopyDialog()
1332 {
1333 if(isset($_POST['cn'])){
1334 $this->cn = $_POST['cn'];
1335 $this->uid = $_POST['cn'];
1336 }
1337 }
1340 /* Generates ListBox frienly output of used logonscripts
1341 */
1342 function printOutLogonScripts()
1343 {
1344 $a_return = array();
1345 if(is_array($this->gotoLogonScripts)){
1346 foreach($this->gotoLogonScripts as $script){
1347 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1348 }
1349 }
1350 return($a_return);
1351 }
1354 function multiple_execute()
1355 {
1356 /* Reset header toggle */
1357 $this->is_account = TRUE;
1358 return($this->execute());
1359 }
1362 /* Initialize plugin with given atribute arrays
1363 */
1364 function init_multiple_support($attrs,$all)
1365 {
1366 plugin::init_multiple_support($attrs,$all);
1368 /* Prepare Shares */
1369 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1370 unset($this->multi_attrs_all['gotoShare']['count']);
1371 foreach($this->multi_attrs_all['gotoShare'] as $share){
1372 $tmp = $tmp2 = array();
1373 $tmp = split("\|",$share);
1374 $tmp2['server'] =$tmp[0];
1375 $tmp2['name'] =$tmp[1];
1377 /* Decode base64 if needed */
1378 if (!preg_match('%/%', $tmp[2])){
1379 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1380 } else {
1381 $tmp2['mountPoint'] =$tmp[2];
1382 }
1384 if(isset($tmp[3])){
1385 $tmp2['PwdHash'] =$tmp[3];
1386 }else{
1387 $tmp2['PwdHash'] ="";
1388 }
1389 if(isset($tmp[4])){
1390 $tmp2['Username'] =$tmp[4];
1391 }else{
1392 $tmp2['Username'] ="";
1393 }
1394 $tmp2['UsedByAllUsers'] = FALSE;
1395 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1396 }
1397 }
1399 /* Prepare Shares */
1400 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1401 unset($this->multi_attrs['gotoShare']['count']);
1402 foreach($this->multi_attrs['gotoShare'] as $share){
1403 $tmp = $tmp2 = array();
1404 $tmp = split("\|",$share);
1405 $tmp2['server'] =$tmp[0];
1406 $tmp2['name'] =$tmp[1];
1408 /* Decode base64 if needed */
1409 if (!preg_match('%/%', $tmp[2])){
1410 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1411 } else {
1412 $tmp2['mountPoint'] =$tmp[2];
1413 }
1415 if(isset($tmp[3])){
1416 $tmp2['PwdHash'] =$tmp[3];
1417 }else{
1418 $tmp2['PwdHash'] ="";
1419 }
1420 if(isset($tmp[4])){
1421 $tmp2['Username'] =$tmp[4];
1422 }else{
1423 $tmp2['Username'] ="";
1424 }
1425 $tmp2['UsedByAllUsers'] = TRUE;
1426 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1427 }
1428 }
1429 }
1432 function set_multi_edit_values($attrs)
1433 {
1434 $shares = $this->gotoShares;
1435 plugin::set_multi_edit_values($attrs);
1437 $this->gotoShares = $shares;
1438 foreach($attrs['gotoShares'] as $name => $share){
1439 if($share['UsedByAllUsers'] == TRUE){
1440 $this->gotoShares[$name] = $share;
1441 }
1442 }
1443 }
1446 /* Return selected values for multiple edit */
1447 function get_multi_edit_values()
1448 {
1449 $ret = plugin::get_multi_edit_values();
1450 $ret['gotoShares'] = $this->gotoShares;
1451 return($ret);
1452 }
1455 /* Return plugin informations for acl handling
1456 #FIXME these ACLs should work for groups too */
1457 static function plInfo()
1458 {
1459 return (array("plShortName" => _("Environment"),
1460 "plDescription" => _("Environment settings"), // Description
1461 "plSelfModify" => TRUE,
1462 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1463 "plPriority" => 3, // Position in tabs
1464 "plSection" => array("personal" => _("My account")),
1465 "plCategory" => array("users",
1466 "groups"),
1467 "plOptions" => array("resolution_hook" => array("type" => "string",
1468 "description" => _("Command to extend the list of possible screen resolutions"))),
1470 "plProvidedAcls" => array(
1472 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1473 "gotoProfileFlagC" => _("Cache profile localy") ,
1475 "gotoProfileQuota" => _("Profile quota") ,
1476 "gotoProfileServer" => _("Profile server") ,
1478 "gotoXResolution" => _("Resolution") ,
1479 "gotoKioskProfile" => _("Kiosk profile") ,
1481 "gosaDefaultPrinter" => _("Default printer") ,
1482 "gotoLogonScript" => _("Logon script") ,
1483 "gotoHotplugDevice" => _("Hotplug devices"),
1484 "gotoShare" => _("Shares"))
1485 ));
1486 }
1487 }
1489 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1490 ?>