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;
21 /* Attribute definition
22 */
24 /* profile management */
25 var $useProfile = false; // Specifies if we want to use a Server
26 var $gotoProfileServer = ""; // Specifies the selected profile server
27 var $gotoProfileServers = array();// Specifies all available and selectable servers
28 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
29 var $gotoProfileFlag_C = ""; // Flag is set to C if we have the profile caching fucntion enabled
31 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
32 var $gotoXResolutions = array();// Contains all available resolutions for this account
33 var $gotoProfileFlag_L = ""; // Flag is set to L to enable runtime resolution change
34 var $gotoProfileQuota = ""; // User Quota Settings
36 /* Logon script section*/
37 var $gotoLogonScripts = array();// Contains all available Logon Scripts
38 var $gotoLogonScript = ""; // The selected Logon Script
40 /* Printer */
41 var $gotoPrinter = array();// All available Printer, with their configurations
42 var $gotoPrinterSel = ""; // The selected Printer
44 /* Share */
45 var $gotoShares = array();// Current Share Options
46 var $gotoShare = ""; // currently selected Share Option
47 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
48 var $gotoAvailableShares= array();// Available Shares for this account
50 /* Kiosk profile */
51 var $gotoKioskProfile = "none"; // The selected Kiosk Profile
52 var $gotoKioskProfiles = array();// All available Kiosk profiles
53 var $newKioskProfiles = array();
55 /* Hotplug Devices */
56 var $gotoHotplugDevice = array(); // Selected hotplug
57 var $gotoHotplugDevices = array();// Already configured hotplug devices
60 /* general settings */
61 // Sets the attributes which will kept on page reload, which will be saved, ...
63 var $CopyPasteVars = array("gotoHotplugDevices","newKioskProfiles","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlag_L","gotoXResolutions","gotoProfileFlag_C","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
65 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags",
66 "gotoXResolution","gotoProfileQuota",
67 "gotoLogonScripts","gotoLogonScript",
68 "gotoPrinter",
69 "gotoShares","gotoShare",
70 "gotoKioskProfile","gotoKioskProfiles",
71 "gotoHotplugDevice");
72 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
73 var $cn;
74 var $OrigCn;
76 function environment ($config, $dn= NULL)
77 {
78 plugin::plugin ($config, $dn);
80 /* Check : Are we currently editing a group or user dialog */
81 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
82 $suffix="Group";
83 $this->uid = $this->attrs['cn'][0];
84 $this->attrs['uid'] = $this->attrs['cn'][0];
85 $this->OrigCn = $this->attrs['cn'][0];
86 }else{
87 $suffix="User";
88 }
90 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
92 /* Get all Printer assignments */
93 $ldap = $this->config->get_ldap_link();
94 $ldap->cd($this->config->current['BASE']);
95 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
96 while($printer = $ldap->fetch()){
97 $this->gotoPrinter[$printer['cn'][0]]=$printer;
98 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
99 }
100 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
101 while($printer = $ldap->fetch()){
102 $this->gotoPrinter[$printer['cn'][0]]=$printer;
103 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
104 }
106 /* prepare hotplugs */
107 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
108 unset($this->attrs['gotoHotplugDevice']['count']);
109 foreach($this->attrs['gotoHotplugDevice'] as $device){
110 $tmp = $tmp2 = array();
111 $tmp = split("\|",$device);
112 $tmp2['name'] = $tmp[0];
113 $tmp2['description'] = $tmp[1];
114 $tmp2['id'] = $tmp[2];
115 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
116 }
117 }
119 /* prepare LogonScripts */
120 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
121 unset($this->attrs['gotoLogonScript']['count']);
122 foreach($this->attrs['gotoLogonScript'] as $device){
123 $tmp = $tmp2 = array();
124 $tmp = split("\|",$device);
125 $tmp2['LogonName'] = $tmp[0];
126 $tmp2['LogonPriority'] = $tmp[2];
127 if(preg_match("/O/i",$tmp[1])){
128 $tmp2['LogonOverload'] = "O";
129 }else{
130 $tmp2['LogonOverload'] = "";
131 }
132 if(preg_match("/L/i",$tmp[1])){
133 $tmp2['LogonLast'] = "L";
134 }else{
135 $tmp2['LogonLast'] = "";
136 }
137 $tmp2['LogonData'] = base64_decode($tmp[3]);
138 $tmp2['LogonDescription'] = $tmp[4];
139 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
140 }
141 }
143 /* Prepare Shares */
144 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
145 unset($this->attrs['gotoShare']['count']);
146 foreach($this->attrs['gotoShare'] as $share){
147 $tmp = $tmp2 = array();
148 $tmp = split("\|",$share);
149 $tmp2['server'] =$tmp[0];
150 $tmp2['name'] =$tmp[1];
151 $tmp2['mountPoint'] =$tmp[2];
152 if(isset($tmp[3])){
153 $tmp2['OtherStuff'] =$tmp[3];
154 }else{
155 $tmp2['OtherStuff'] ="";
156 }
157 if(isset($tmp[4])){
158 $tmp2['Username'] =$tmp[4];
159 }else{
160 $tmp2['Username'] ="";
161 }
162 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
163 }
164 }
166 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
167 $chr = $this->gotoProfileFlags[$i];
168 $name = "gotoProfileFlag_".$chr;
169 $this->$name=$chr;
170 }
172 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
173 $this->useProfile = true;
174 }else{
175 $this->useProfile = false;
176 }
178 /* Set to group environment if we editing a group */
179 if(!isset($this->parent)){
180 $this->is_group = true;
181 }
183 $this->gotoProfileServers= $config->getShareServerList() ;
184 $this->gotoShareSelections= $config->getShareList(true);
185 $this->gotoAvailableShares= $config->getShareList(false);
187 }
189 function execute()
190 {
191 /* Call parent execute */
192 plugin::execute();
194 /* Fill templating stuff */
195 $smarty= get_smarty();
196 $display= "";
198 /* Prepare all variables for smarty */
199 foreach($this->attributes as $s_attr){
200 /* Set value*/
201 $smarty->assign($s_attr,$this->$s_attr);
203 /* Set checkbox state*/
204 if(empty($this->$s_attr)){
205 $smarty->assign($s_attr."CHK","");
206 }else{
207 $smarty->assign($s_attr."CHK"," checked ");
208 }
210 /* Prepare ACL settings*/
211 if(chkacl($this->acl,$s_attr)=="") {
212 $smarty->assign($s_attr."ACL","");
213 }else{
214 $smarty->assign($s_attr."ACL"," disabled ");
215 }
217 }
219 /* Is accout enabled | are we editing from usermenu or admin menu
220 All these tab management is done here
221 */
223 /* Working from Usermenu an the Account is currently disbled
224 * this->parent : is only set if we are working in a list of tabs
225 * is_account : is only true if the needed objectClass is given
226 */
227 if((!isset($this->parent))&&(!$this->is_account)){
228 /* We are currently editing this tab from usermenu, but this account is not enabled */
229 $smarty->assign("is_account",$this->is_account);
230 /* Load template */
231 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
232 /* Avoid the "You are currently editing ...." message when you leave this tab */
233 $display .= back_to_main();
234 /* Display our message to the user */
235 return $display;
238 /* We are currently editing from group tabs, because
239 * $this->parent is set
240 * posixAccount is not set, so we are not in usertabs.
241 */
242 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
243 $smarty->assign("is_account","true");
244 $this->is_group = true;
245 $this->uid = $this->cn;
246 $this->attrs['uid'] = $this->cn;
248 /* Change state if needed */
249 if (isset($_POST['modify_state'])){
250 $this->is_account= !$this->is_account;
251 }
253 /* Group Dialog with enabled environment options */
254 if ($this->is_account){
255 $display= $this->show_header(_("Remove environment extension"),
256 _("Environment extension enabled. You can disable it by clicking below."));
257 } else {
259 /* Environment is disabled
260 If theres is no posixAccount enabled, you won't be able to enable
261 environment extensions
262 */
263 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
264 // 4. There is a PosixAccount
265 $display= $this->show_header(_("Add environment extension"),
266 _("Environment extension disabled. You can enable it by clicking below."));
267 return $display;
268 }else{
269 // 4. There is no PosixAccount
270 $display= $this->show_header(_("Add environment extension"),
271 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
272 return $display;
273 }
274 }
275 }else{
276 /* Editing from Usermenu
277 * Tell smarty that this accoutn is enabled
278 */
279 $smarty->assign("is_account","true");
281 $this->is_group = false;
283 /* Do we need to flip is_account state? */
284 if (isset($_POST['modify_state'])){
285 $this->is_account= !$this->is_account;
286 }
288 if(isset($this->parent)){
290 // 3. Account enabled . Editing from adminmenu
291 if ($this->is_account){
292 $display= $this->show_header(_("Remove environment extension"),
293 _("Environment extension enabled. You can disable it by clicking below."));
294 } else {
296 if($this->parent->by_object['posixAccount']->is_account==true){
297 // 4. There is a PosixAccount
298 $display= $this->show_header(_("Add environment extension"),
299 _("Environment extension disabled. You can enable it by clicking below."));
300 return $display;
301 }else{
302 // 4. There is a PosixAccount
303 $display= $this->show_header(_("Add environment extension"),
304 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
305 return $display;
306 }
307 }
308 }
309 }
310 /* Account is Account : is_accounbt=true.
311 * Else we won't reach this.
312 */
314 /* Prepare all variables for smarty */
315 foreach($this->attributes as $s_attr){
316 /* Set value*/
317 $smarty->assign($s_attr,$this->$s_attr);
319 /* Set checkbox state*/
320 if(empty($this->$s_attr)){
321 $smarty->assign($s_attr."CHK","");
322 }else{
323 $smarty->assign($s_attr."CHK"," checked ");
324 }
326 /* Prepare ACL settings*/
327 if(chkacl($this->acl,$s_attr)=="") {
328 $smarty->assign($s_attr."ACL","");
329 }else{
330 $smarty->assign($s_attr."ACL"," disabled ");
331 }
333 }
335 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
336 if(chkacl($this->acl,$s_attr)=="") {
337 $smarty->assign($s_attr."ACL","");
338 }else{
339 $smarty->assign($s_attr."ACL"," disabled ");
340 }
341 }
343 if(empty($this->useProfile)){
344 $smarty->assign("gotoProfileACL","disabled");
345 $smarty->assign("useProfileCHK","");
346 }else{
347 $smarty->assign("gotoProfileACL","");
348 $smarty->assign("useProfileCHK"," checked ");
349 }
352 $smarty->assign("useProfileACL","");
353 if($this->acl != "#none#"){
354 $smarty->assign("useProfileACL","");
355 $smarty->assign("gotoProfileFlag_CACL"," ");
356 $smarty->assign("gotoProfileQuotaACL"," ");
357 }else{
358 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
359 $smarty->assign("useProfileACL","disabled");
360 $smarty->assign("gotoProfileServer"," disabled ");
361 $smarty->assign("gotoProfileQuotaACL"," disabled ");
362 }
364 /* HANDLE Profile Settings here
365 * Assign available Quota and resolution settings
366 * Get all available profile server
367 * Get cache checkbox
368 * Assign this all to Smarty
369 */
371 if(empty($this->gotoProfileFlag_L)){
372 $smarty->assign("gotoProfileFlag_LCHK"," ");
373 }else{
374 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
375 }
377 if(empty($this->gotoProfileFlag_C)){
378 $smarty->assign("gotoProfileFlag_CCHK"," ");
379 }else{
380 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
381 }
383 $this->gotoXResolutions = array("auto"=>_("auto"),
384 "640x480" => "640x480",
385 "800x600" => "800x600",
386 "1024x768" => "1024x768",
387 "1154x864" => "1154x864",
388 "1280x768" => "1280x768",
389 "1280x1024" => "1280x1024");
391 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
392 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
394 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
395 if(!is_array($this->gotoProfileServers)){
396 $this->gotoProfileServers =array();
397 }
398 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
400 /* Handle kiosk profiles
401 * Read available from filesystem
402 * Open management if post is transmitted
403 */
405 /* Save */
406 if(isset($_POST['KioskClose'])){
407 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
409 unset($this->dialog);
410 $this->dialog=NULL;
411 $this->is_dialog = false;
412 }
413 $tmp = new kioskManagementDialog($this->config,$this->dn);
414 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
416 $list['none']=_("None");
418 $list = array_reverse($list);
420 if(!isset($list[$this->gotoKioskProfile])){
421 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
422 $this->gotoKioskProfile = 'none';
423 }
425 /* Reassign help class */
426 $_SESSION['current_class_for_help'] = get_class($this);
428 /* Open Management Dialog */
429 if(isset($_POST['KioskManagementDialog'])){
430 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
431 $this->dialog->parent= $this;
432 $this->dialog->acl = $this->acl;
433 $this->is_dialog = true;
434 }
436 $smarty->assign("gotoKioskProfiles",$list);
437 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
439 /* Logonscript Management
440 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
441 * Perform add Delete edit Posts
442 */
444 /* Dialog Save */
445 if(isset($_POST['LogonSave'])){
446 $this->dialog->save_object();
447 if(count($this->dialog->check())!=0){
448 foreach($this->dialog->check() as $msg){
449 print_red($msg);
450 }
451 }else{
452 $tmp = $this->dialog->save();
453 unset($this->dialog);
454 $this->dialog=NULL;
455 $this->is_dialog=false;
456 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
457 }
458 }
460 /* Dialog Quit without saving */
461 if(isset($_POST['LogonCancel'])){
462 $this->is_dialog= false;
463 unset($this->dialog);
464 $this->dialog= NULL;
465 }
467 /* Check Edit Del New Posts for a selected LogonScript */
468 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
470 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
471 * In this case we create a new Logon Script.
472 */
473 if(isset($_POST['gotoLogonScriptNew'])){
474 $this->is_dialog = true;
475 $this->dialog = new logonManagementDialog($this->config,$this->dn);
476 }
478 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
479 * We only can delete if there is an entry selected.
480 */
481 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
482 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
483 }
485 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
486 * There must be an entry selected to perform edit request.
487 */
488 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
489 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
490 $this->is_dialog = true;
491 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
492 }
493 }
495 /* Append List to smarty*/
496 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
497 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
499 /* In this section server shares will be defined
500 * A user can select one of the given shares and a mount point
501 * and attach this combination to his setup.
502 */
504 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
505 if(!is_array($this->gotoShareSelections)){
506 print $this->gotoShareSelections;
507 $this->gotoShareSelections = array();
508 }
509 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
511 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
512 * This entry will be, a combination of mountPoint and sharedefinitions
513 */
514 if(isset($_POST['gotoShareAdd'])){
515 /* We assign a share to this user, if we don't know where to mount the share */
516 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
517 print_red(_("You must specify a valid mount point."));
518 }elseif(!(
519 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
520 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
521 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
522 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
523 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
524 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
525 preg_match("/^%/",$_POST['gotoShareMountPoint'])
526 )
527 ){
528 print_red(_("You must specify a valid mount point."));
529 }else{
530 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
531 $s_mount = $_POST['gotoShareMountPoint'];
532 $s_user = $_POST['ShareUser'];
533 /* Preparing the new assignment */
534 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
535 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
536 $this->gotoShares[$a_share['name']."|".$a_share['server']]['OtherStuff']="";
537 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
538 }
539 }
541 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
542 * If there is no defined share selected, we will abort the deletion without any message
543 */
544 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
545 unset($this->gotoShares[$_POST['gotoShare']]);
546 }
548 $smarty->assign("gotoShares",$this->printOutAssignedShares());
549 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
551 /* Hotplug devices will be handled here
552 * There are 3 possible methods for this feature
553 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
554 * Delete will erase an entry, the entry must be selcted in the ListBox first
555 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
556 */
558 /* If there is a new entry wanted, open a new entry by initilising the dialog */
559 if(isset($_POST['gotoHotplugDeviceNew'])){
560 $this->dialog = new hotplugDialog($this->config,$this->dn);
561 $this->is_dialog = true;
562 }
564 /* We have to delete the selected hotplug from the list*/
565 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
566 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
567 }
569 /* There are already defined hotplugs from other users we could use */
570 if(isset($_POST['gotoHotplugDeviceUse'])){
571 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
572 $this->is_dialog = true;
573 }
575 /* Dialog Aborted */
576 if(isset($_POST['HotPlugCancel'])){
577 unset($this->dialog);
578 $this->dialog= NULL;
579 $this->is_dialog = false;
580 }
582 /* Dialod saved */
583 if(isset($_POST['HotPlugSave'])){
584 $this->dialog->save_object();
585 if(count($this->dialog->check())!=0){
586 foreach($this->dialog->check() as $msg){
587 print_red($msg);
588 }
589 }else{
590 $this->dialog->save_object();
591 $a_tmp = $this->dialog->save();
592 if(is_array($a_tmp)){
593 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
594 }
595 unset($this->dialog);
596 $this->dialog= NULL;
597 $this->is_dialog = false;
598 }
599 }
601 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
602 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
604 /* Printer Assignment will managed below
605 * A printer can be assigned in two different ways and two different types
606 * There are 2 types of users assigned to a printer : user and admin
607 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
608 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
609 */
611 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
612 if(isset($_POST['gotoPrinterAdd'])){
613 $this->is_dialog=true;
614 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
615 }
617 if(isset($_POST['PrinterCancel'])){
618 $this->is_dialog=false;
619 unset($this->dialog);
620 $this->dialog=NULL;
621 }
623 if(isset($_POST['PrinterSave'])){
624 if(count($this->dialog->check())!=0){
625 $tmp = $this->dialog->check();
626 foreach($tmp as $msg){
627 print_red($msg);
628 }
629 }else{
630 $this->dialog->save_object();
631 $tmp = $this->dialog->save();
632 $tmp2= $this->dialog->getPrinter(true);
634 foreach($tmp as $pname){
635 $this->gotoPrinter[$pname]=$tmp2[$pname];
636 $this->gotoPrinter[$pname]['mode']="user";
637 }
639 $this->is_dialog=false;
640 unset($this->dialog);
641 $this->dialog =NULL;
642 }
643 }
645 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
646 $printer = $_POST['gotoPrinterSel'];
647 foreach($printer as $pname){
648 unset($this->gotoPrinter[$pname]);
649 }
650 }
652 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
655 $printers = $_POST['gotoPrinterSel'];
657 foreach($printers as $printer){
658 if($this->gotoPrinter[$printer]['mode']=="user"){
659 $this->gotoPrinter[$printer]['mode']="admin";
660 }else{
661 $this->gotoPrinter[$printer]['mode']="user";
662 }
663 }
664 }
666 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
667 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
669 /* General behavior */
670 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
671 $this->dialog->save_object();
672 return ($this->dialog->execute());
673 }
674 if($this->acl != "#none#"){
675 $smarty->assign("useProfileACL","");
676 }else{
677 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
678 $smarty->assign("gotoProfileServerACL"," disabled ");
679 $smarty->assign("gotoProfileQuotaACL"," disabled ");
680 }
682 if(!$this->useProfile){
683 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
684 $smarty->assign("gotoProfileServerACL"," disabled ");
685 $smarty->assign("gotoProfileQuotaACL"," disabled ");
686 }
688 /* Als smarty vars are set. Get smarty template and generate output */
689 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
691 return($display);
692 }
694 function remove_from_parent()
695 {
696 /* only if it was an account*/
697 if (!$this->initially_was_account){
698 return;
699 }
701 /* include global link_info */
702 $ldap= $this->config->get_ldap_link();
704 /* Remove and write to LDAP */
705 plugin::remove_from_parent();
707 /* Don't save our template variables */
708 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
710 /* Skip all these attributes */
711 foreach($skip as $del){
712 unset($this->attrs[$del]);
713 }
715 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
717 $ldap->cd($this->dn);
718 $this->cleanup();
719 $ldap->modify ($this->attrs);
721 show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
723 /* Optionally execute a command after we're done */
724 $this->handle_post_events("remove");
725 }
728 /* Save data to object */
729 function save_object()
730 {
731 /* Get all Posted vars
732 * Setup checkboxes
733 */
737 if(isset($_POST['iamposted'])){
738 if(isset($_POST['useProfile'])){
739 $this->useProfile = true;
740 }else{
741 $this->useProfile = false;
742 }
743 if(isset($_POST['gotoProfileFlag_C'])){
744 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
745 }else{
746 $this->gotoProfileFlag_C = false;
747 }
748 if(isset($_POST['gotoProfileFlag_L'])){
749 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
750 }else{
751 $this->gotoProfileFlag_L = false;
752 }
754 plugin::save_object();
755 foreach($this->attributes as $s_attr){
756 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
757 if(isset($_POST[$s_attr])){
758 $this->$s_attr = $_POST[$s_attr];
759 }else{
760 $this->$s_attr = false;
761 }
762 }
763 }
764 }
767 /* Check supplied data */
768 function check()
769 {
770 /* Call common method to give check the hook */
771 $message= plugin::check();
773 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
774 $message[]=_("Please set a valid profile quota size.");
775 }
776 if(!isset($this->attrs['objectClass'])){
777 $this->attrs['objectClass']=array();
778 }
779 if(!$this->is_group){
780 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
781 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
782 }
783 }
784 return ($message);
785 }
788 /* Save to LDAP */
789 function save()
790 {
791 /* If group was renamed, all printer settings get lost
792 */
793 /* only save changed variables ....*/
794 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
795 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
796 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
797 $method="https://";
798 }else{
799 $method="http://";
800 }
802 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
803 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
804 }else{
805 $this->gotoKioskProfile= array();
806 }
808 plugin::save();
809 $ldap= $this->config->get_ldap_link();
811 $realyUsedAttrs= array();
813 $path = search_config($this->config->data,"environment", "KIOSKPATH");
814 /* Creating Kiosk Profiles */
815 foreach($this->newKioskProfiles as $file){
816 $contents = $file['contents'];
817 $fp = @fopen($path."/".$file['name'],"w");
818 if(!$fp){
819 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
820 }else{
821 fwrite($fp,$contents,strlen($contents));
822 }
823 @unlink($file['tmp_name']);
824 }
826 /* Save already used objectClasses */
827 $ocs = $this->attrs['objectClass'];
828 unset($ocs['count']);
829 $this->attrs = array();
830 $this->attrs['objectClass']= $ocs;
831 foreach($this->objectclasses as $objc){
832 if(!in_array($objc,$this->attrs['objectClass'])){
833 $this->attrs['objectClass'][]=$objc;
834 }
835 }
838 /* Save usersettings to Printer */
840 if(chkacl($this->acl,"gotoPrinter")!=""){
841 $this->gotoPrinter = array();
842 }
844 if($this->is_group){
845 $s_suffix = "Group";
846 }else{
847 $s_suffix = "User";
848 }
851 /* 1. Search all printers that have our uid/cn as member
852 * 2. Delete this uid/cn from every single entry and save it again.
853 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
854 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
855 */
856 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
857 while($attr = $ldap->fetch()){
859 /* Walk trough all printers and check if our user id used, if so remove it.
860 * Later we will insert our uid at the right place.
861 */
863 /* Remove normal entries (User)*/
864 if(isset($attr['goto'.$s_suffix.'Printer'])) {
865 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
866 if($this->uid==$user){
867 unset($attr['goto'.$s_suffix.'Printer'][$key]);
868 }
869 }
870 }
872 /* Remove administrational entries (Admin)*/
873 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
874 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
875 if($this->uid==$user){
876 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
877 }
878 }
879 }
881 /* Extract useable tags, to be able to save all changes
882 */
883 $attrs_used = array();
884 foreach($attr as $key=>$val){
886 /* If index is numeric, skip it ...*/
887 if((!is_numeric($key))&&($key!="count")){
889 /* If entry contains 'count' remove it */
890 if(is_array($val)&&isset($val['count'])){
891 unset($val['count']);
892 }
893 $attrs_used[$key]=$val;
894 }
895 }
896 /* the result of cleaning the entry is
897 * to be able to directly save this again,
898 * if all changes are made
899 */
900 $attr= $attrs_used;
902 #fix : Id don't know why such an entry was set ...
903 if(isset($attr['GOTOADMINPRINTER'])){
904 unset($attr['GOTOADMINPRINTER']);
905 }
907 /* Save changes */
908 $ldap->cd($attr['dn']);
909 unset($attr['dn']);
910 $ldap->modify ($attr);
912 if($ldap->get_error()!="Success"){
913 print_red(_("Error while writing printer")." : ".$ldap->get_error());
914 }
915 }
917 /* All printers are cleaned, (our cn/uid removed)
918 * now we must add our uid / cn
919 * to the new configured printers.
920 */
921 foreach($this->gotoPrinter as $printer) {
922 $ldap->cat($printer['dn']);
923 $attrs= $ldap->fetch();
924 $attrs_used = array();
925 foreach($attrs as $key=>$val){
926 if((!is_numeric($key))&&($key!="count")){
927 if(is_array($val)&&isset($val['count'])){
928 unset($val['count']);
929 }
930 $attrs_used[$key]=$val;
931 }
932 }
933 /* $attrs contains all values
934 * we need, to save the entry lateron
935 */
936 $attrs= $attrs_used;
938 /* Depending on the type (User/Admin)
939 * switch these attributes, that makes it easier
940 */
941 if($printer['mode'] == "user"){
942 $attribute = "goto".$s_suffix."Printer";
943 $attribute2 = "goto".$s_suffix."AdminPrinter";
944 }else{
945 $attribute = "goto".$s_suffix."AdminPrinter";
946 $attribute2 = "goto".$s_suffix."Printer";
947 }
949 /* If this user is already assigned to $attribute2
950 * delete user from $attribute2, to be albe to attach him to $attribute
951 * A user can't be admin and normal user for one printer
952 */
953 if(!isset($printer[$attribute2])){
954 $printer[$attribute2]=array();
955 }else{
956 if(in_array($this->uid,$printer[$attribute2])){
957 $tmp = array_flip($printer[$attribute2]);
958 unset($tmp[$this->uid]);
959 $attrs[$attribute2]=array_flip($tmp);
960 }
961 /* If Last entry removed, clear attribute*/
962 if(empty($attrs[$attribute2])){
963 $attrs[$attribute2]=array();
964 }
965 }
967 /* Attach user to the $attribute, if he is'nt already attached
968 */
969 if(!isset($attrs[$attribute])){
970 $attrs[$attribute]=array($this->uid);
971 }else{
972 unset($attrs[$attribute]['count']);
973 if(!in_array($this->uid,$attrs[$attribute])){
974 $attrs[$attribute][]=$this->uid;
975 }
976 }
978 $ldap->cd($attrs['dn']);
979 unset($attrs['dn']);
980 $ldap->modify ($attrs);
982 if($ldap->get_error()!="Success"){
983 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
984 }
985 }
987 /* Prepare HotPlug devices */
988 $this->attrs['gotoHotplugDevice'] = array();
989 foreach($this->gotoHotplugDevices as $name => $device){
990 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
991 }
993 /* Prepare LogonScripts */
994 $this->attrs['gotoLogonScript'] = array();
995 foreach($this->gotoLogonScripts as $name => $script){
996 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
997 $script['LogonOverload'].$script['LogonLast']."|".
998 $script['LogonPriority']."|".
999 base64_encode($script['LogonData'])."|".
1000 $script['LogonDescription'];
1001 }
1003 /* Prepare Shares */
1004 $this->attrs['gotoShare']=array();
1005 foreach($this->gotoShares as $name => $share){
1006 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff']."|".$share['Username'];
1007 }
1010 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1011 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile");
1013 foreach($saveThis as $tosave){
1014 if(!empty($this->$tosave)){
1015 $this->attrs[$tosave]=$this->$tosave;
1016 }else{
1017 $this->attrs[$tosave]=array();
1018 }
1019 }
1021 /* Prepare Flags */
1022 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1023 if(empty($this->attrs['gotoProfileFlags'][0])){
1024 $this->attrs['gotoProfileFlags']=array();
1025 }
1027 if($this->useProfile == false){
1028 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1029 $this->attrs['gotoProfileServer']= array();
1030 }
1032 foreach($this->attributes as $s_attr){
1033 if(chkacl($this->acl,$s_attr)!="") {
1034 if(isset($this->attrs[$s_attr])){
1035 unset($this->attrs[$s_attr]);
1036 }
1037 }
1038 }
1040 $ldap->cat ($this->dn, array('dn'));
1041 if ($ldap->fetch()){
1042 $mode= "modify";
1043 } else {
1044 $mode= "add";
1045 $ldap->cd($this->config->current['BASE']);
1046 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1047 }
1049 $ldap->cd($this->dn);
1050 $this->cleanup();
1051 $ldap->$mode($this->attrs);
1052 show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1053 $this->handle_post_events($mode);
1054 }
1056 /* Generate ListBox frindly output for the defined shares
1057 * Possibly Add or remove an attribute here,
1058 */
1059 function printOutAssignedShares()
1060 {
1061 $a_return = array();
1062 if(is_array($this->gotoShares)){
1063 foreach($this->gotoShares as $share){
1064 if (!preg_match('/^!/', $share['server'])){
1065 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1066 }
1067 }
1068 }
1069 return($a_return);
1070 }
1072 /* Generate ListBox frindly output for the definedhotplugs
1073 * Possibly Add or remove an attribute here,
1074 */
1075 function printOutHotPlugDevices()
1076 {
1077 $a_return= array();
1078 if(is_array($this->gotoHotplugDevices)){
1079 foreach($this->gotoHotplugDevices as $key=>$device){
1080 $a_return[$key] = $device['name']." - ".$device['id'];
1081 }
1082 }
1083 return($a_return);
1084 }
1086 /* Generates ListBox frienly output of used printer devices
1087 * Append ' - admin' if printer is used in admin mode
1088 */
1089 function printOutPrinterDevices()
1090 {
1091 $a_return = array();
1092 if(is_array($this->gotoPrinter)){
1093 foreach($this->gotoPrinter as $printer){
1094 if($printer['mode'] == "admin"){
1095 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1096 }else{
1097 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1098 }
1099 }
1100 }
1101 return($a_return);
1102 }
1104 /* Generates ListBox frienly output of used logonscripts
1105 */
1106 function printOutLogonScripts()
1107 {
1108 $a_return = array();
1109 if(is_array($this->gotoLogonScripts)){
1110 foreach($this->gotoLogonScripts as $script){
1111 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1112 }
1113 }
1114 return($a_return);
1115 }
1116 }
1121 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1122 ?>