059b35c20859f9bcb51100c4108e58d9e94e036d
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 = "1024x768"; // 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 = ""; // 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, ...
62 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags",
63 "gotoXResolution","gotoProfileQuota",
64 "gotoLogonScripts","gotoLogonScript",
65 "gotoPrinter",
66 "gotoShares","gotoShare",
67 "gotoKioskProfile","gotoKioskProfiles",
68 "gotoHotplugDevice");
69 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
70 var $cn;
72 function environment ($config, $dn= NULL)
73 {
74 plugin::plugin ($config, $dn);
77 /* Check : Are we currently editing a group or user dialog */
78 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
79 $suffix="Group";
80 $this->uid = $this->attrs['cn'][0];
81 $this->attrs['uid'] = $this->attrs['cn'][0];
82 }else{
83 $suffix="User";
84 }
86 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
88 /* Get all Printer assignments */
89 $ldap = $this->config->get_ldap_link();
90 $ldap->cd($this->config->current['BASE']);
91 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
92 while($printer = $ldap->fetch()){
93 $this->gotoPrinter[$printer['cn'][0]]=$printer;
94 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
95 }
96 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
97 while($printer = $ldap->fetch()){
98 $this->gotoPrinter[$printer['cn'][0]]=$printer;
99 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
100 }
102 /* prepare hotplugs */
103 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
104 unset($this->attrs['gotoHotplugDevice']['count']);
105 foreach($this->attrs['gotoHotplugDevice'] as $device){
106 $tmp = $tmp2 = array();
107 $tmp = split("\|",$device);
108 $tmp2['name'] = $tmp[0];
109 $tmp2['description'] = $tmp[1];
110 $tmp2['id'] = $tmp[2];
111 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
112 }
113 }
115 /* prepare LogonScripts */
116 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
117 unset($this->attrs['gotoLogonScript']['count']);
118 foreach($this->attrs['gotoLogonScript'] as $device){
119 $tmp = $tmp2 = array();
120 $tmp = split("\|",$device);
121 $tmp2['LogonName'] = $tmp[0];
122 $tmp2['LogonPriority'] = $tmp[2];
123 if(preg_match("/O/i",$tmp[1])){
124 $tmp2['LogonOverload'] = "O";
125 }else{
126 $tmp2['LogonOverload'] = "";
127 }
128 if(preg_match("/L/i",$tmp[1])){
129 $tmp2['LogonLast'] = "L";
130 }else{
131 $tmp2['LogonLast'] = "";
132 }
133 $tmp2['LogonData'] = base64_decode($tmp[3]);
134 $tmp2['LogonDescription'] = $tmp[4];
135 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
136 }
137 }
139 /* Prepare Shares */
140 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
141 unset($this->attrs['gotoShare']['count']);
142 foreach($this->attrs['gotoShare'] as $share){
143 $tmp = $tmp2 = array();
144 $tmp = split("\|",$share);
145 $tmp2['server'] =$tmp[0];
146 $tmp2['name'] =$tmp[1];
147 $tmp2['mountPoint'] =$tmp[2];
148 if(isset($tmp[3])){
149 $tmp2['OtherStuff'] =$tmp[3];
150 }else{
151 $tmp2['OtherStuff'] ="";
152 }
153 if(isset($tmp[4])){
154 $tmp2['Username'] =$tmp[4];
155 }else{
156 $tmp2['Username'] ="";
157 }
158 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
159 }
160 }
162 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
163 $chr = $this->gotoProfileFlags[$i];
164 $name = "gotoProfileFlag_".$chr;
165 $this->$name=$chr;
166 }
168 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
169 $this->useProfile = true;
170 }else{
171 $this->useProfile = false;
172 }
174 /* Set to group environment if we editing a group */
175 if(!isset($this->parent)){
176 $this->is_group = true;
177 }
179 $this->gotoProfileServers= $config->getShareServerList() ;
180 $this->gotoShareSelections= $config->getShareList(true);
181 $this->gotoAvailableShares= $config->getShareList(false);
183 }
185 function execute()
186 {
187 /* Call parent execute */
188 plugin::execute();
190 /* Fill templating stuff */
191 $smarty= get_smarty();
192 $display= "";
194 /* Prepare all variables for smarty */
195 foreach($this->attributes as $s_attr){
196 /* Set value*/
197 $smarty->assign($s_attr,$this->$s_attr);
199 /* Set checkbox state*/
200 if(empty($this->$s_attr)){
201 $smarty->assign($s_attr."CHK","");
202 }else{
203 $smarty->assign($s_attr."CHK"," checked ");
204 }
206 /* Prepare ACL settings*/
207 if(chkacl($this->acl,$s_attr)=="") {
208 $smarty->assign($s_attr."ACL","");
209 }else{
210 $smarty->assign($s_attr."ACL"," disabled ");
211 }
213 }
215 /* Is accout enabled | are we editing from usermenu or admin menu
216 All these tab management is done here
217 */
219 /* Working from Usermenu an the Account is currently disbled
220 * this->parent : is only set if we are working in a list of tabs
221 * is_account : is only true if the needed objectClass is given
222 */
223 if((!isset($this->parent))&&(!$this->is_account)){
224 /* We are currently editing this tab from usermenu, but this account is not enabled */
225 $smarty->assign("is_account",$this->is_account);
226 /* Load template */
227 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
228 /* Avoid the "You are currently editing ...." message when you leave this tab */
229 $display .= back_to_main();
230 /* Display our message to the user */
231 return $display;
234 /* We are currently editing from group tabs, because
235 * $this->parent is set
236 * posixAccount is not set, so we are not in usertabs.
237 */
238 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
239 $smarty->assign("is_account","true");
240 $this->is_group = true;
241 $this->uid = $this->cn;
242 $this->attrs['uid'] = $this->cn;
244 /* Change state if needed */
245 if (isset($_POST['modify_state'])){
246 $this->is_account= !$this->is_account;
247 }
249 /* Group Dialog with enabled environment options */
250 if ($this->is_account){
251 $display= $this->show_header(_("Remove environment extension"),
252 _("Environment extension enabled. You can disable it by clicking below."));
253 } else {
255 /* Environment is disabled
256 If theres is no posixAccount enabled, you won't be able to enable
257 environment extensions
258 */
259 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
260 // 4. There is a PosixAccount
261 $display= $this->show_header(_("Add environment extension"),
262 _("Environment extension disabled. You can enable it by clicking below."));
263 return $display;
264 }else{
265 // 4. There is no PosixAccount
266 $display= $this->show_header(_("Add environment extension"),
267 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
268 return $display;
269 }
270 }
271 }else{
272 /* Editing from Usermenu
273 * Tell smarty that this accoutn is enabled
274 */
275 $smarty->assign("is_account","true");
277 $this->is_group = false;
279 /* Do we need to flip is_account state? */
280 if (isset($_POST['modify_state'])){
281 $this->is_account= !$this->is_account;
282 }
284 if(isset($this->parent)){
286 // 3. Account enabled . Editing from adminmenu
287 if ($this->is_account){
288 $display= $this->show_header(_("Remove environment extension"),
289 _("Environment extension enabled. You can disable it by clicking below."));
290 } else {
292 if($this->parent->by_object['posixAccount']->is_account==true){
293 // 4. There is a PosixAccount
294 $display= $this->show_header(_("Add environment extension"),
295 _("Environment extension disabled. You can enable it by clicking below."));
296 return $display;
297 }else{
298 // 4. There is a PosixAccount
299 $display= $this->show_header(_("Add environment extension"),
300 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
301 return $display;
302 }
303 }
304 }
305 }
306 /* Account is Account : is_accounbt=true.
307 * Else we won't reach this.
308 */
310 /* Prepare all variables for smarty */
311 foreach($this->attributes as $s_attr){
312 /* Set value*/
313 $smarty->assign($s_attr,$this->$s_attr);
315 /* Set checkbox state*/
316 if(empty($this->$s_attr)){
317 $smarty->assign($s_attr."CHK","");
318 }else{
319 $smarty->assign($s_attr."CHK"," checked ");
320 }
322 /* Prepare ACL settings*/
323 if(chkacl($this->acl,$s_attr)=="") {
324 $smarty->assign($s_attr."ACL","");
325 }else{
326 $smarty->assign($s_attr."ACL"," disabled ");
327 }
329 }
331 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
332 if(chkacl($this->acl,$s_attr)=="") {
333 $smarty->assign($s_attr."ACL","");
334 }else{
335 $smarty->assign($s_attr."ACL"," disabled ");
336 }
337 }
339 if(empty($this->useProfile)){
340 $smarty->assign("gotoProfileACL","disabled");
341 $smarty->assign("useProfileCHK","");
342 }else{
343 $smarty->assign("gotoProfileACL","");
344 $smarty->assign("useProfileCHK"," checked ");
345 }
348 $smarty->assign("useProfileACL","");
349 if($this->acl != "#none#"){
350 $smarty->assign("useProfileACL","");
351 $smarty->assign("gotoProfileFlag_CACL"," ");
352 $smarty->assign("gotoProfileQuotaACL"," ");
353 }else{
354 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
355 $smarty->assign("useProfileACL","disabled");
356 $smarty->assign("gotoProfileServer"," disabled ");
357 $smarty->assign("gotoProfileQuotaACL"," disabled ");
358 }
360 /* HANDLE Profile Settings here
361 * Assign available Quota and resolution settings
362 * Get all available profile server
363 * Get cache checkbox
364 * Assign this all to Smarty
365 */
367 if(empty($this->gotoProfileFlag_L)){
368 $smarty->assign("gotoProfileFlag_LCHK"," ");
369 }else{
370 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
371 }
373 if(empty($this->gotoProfileFlag_C)){
374 $smarty->assign("gotoProfileFlag_CCHK"," ");
375 }else{
376 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
377 }
379 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
381 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
382 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
383 if(!is_array($this->gotoProfileServers)){
384 $this->gotoProfileServers =array();
385 }
386 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
388 /* Handle kiosk profiles
389 * Read available from filesystem
390 * Open management if post is transmitted
391 */
393 /* Save */
394 if(isset($_POST['KioskClose'])){
395 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
397 unset($this->dialog);
398 $this->dialog=NULL;
399 $this->is_dialog = false;
400 }
401 $tmp = new kioskManagementDialog($this->config,$this->dn);
402 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
404 $list['none']=_("None");
406 $list = array_reverse($list);
408 /* Reassign help class */
409 $_SESSION['current_class_for_help'] = get_class($this);
411 /* Open Management Dialog */
412 if(isset($_POST['KioskManagementDialog'])){
413 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
414 $this->dialog->parent= $this;
415 $this->dialog->acl = $this->acl;
416 $this->is_dialog = true;
417 }
419 $smarty->assign("gotoKioskProfiles",$list);
420 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
422 /* Logonscript Management
423 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
424 * Perform add Delete edit Posts
425 */
427 /* Dialog Save */
428 if(isset($_POST['LogonSave'])){
429 $this->dialog->save_object();
430 if(count($this->dialog->check())!=0){
431 foreach($this->dialog->check() as $msg){
432 print_red($msg);
433 }
434 }else{
435 $tmp = $this->dialog->save();
436 unset($this->dialog);
437 $this->dialog=NULL;
438 $this->is_dialog=false;
439 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
440 }
441 }
443 /* Dialog Quit without saving */
444 if(isset($_POST['LogonCancel'])){
445 $this->is_dialog= false;
446 unset($this->dialog);
447 $this->dialog= NULL;
448 }
450 /* Check Edit Del New Posts for a selected LogonScript */
451 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
453 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
454 * In this case we create a new Logon Script.
455 */
456 if(isset($_POST['gotoLogonScriptNew'])){
457 $this->is_dialog = true;
458 $this->dialog = new logonManagementDialog($this->config,$this->dn);
459 }
461 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
462 * We only can delete if there is an entry selected.
463 */
464 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
465 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
466 }
468 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
469 * There must be an entry selected to perform edit request.
470 */
471 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
472 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
473 $this->is_dialog = true;
474 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
475 }
476 }
478 /* Append List to smarty*/
479 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
480 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
482 /* In this section server shares will be defined
483 * A user can select one of the given shares and a mount point
484 * and attach this combination to his setup.
485 */
487 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
488 if(!is_array($this->gotoShareSelections)){
489 print $this->gotoShareSelections;
490 $this->gotoShareSelections = array();
491 }
492 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
494 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
495 * This entry will be, a combination of mountPoint and sharedefinitions
496 */
497 if(isset($_POST['gotoShareAdd'])){
498 /* We assign a share to this user, if we don't know where to mount the share */
499 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
500 print_red(_("You must specify a valid mount point."));
501 }elseif(!(
502 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
503 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
504 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
505 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
506 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
507 preg_match("/^.USER/",$_POST['gotoShareMountPoint'])
508 )
509 ){
510 print_red(_("You must specify a valid mount point."));
511 }else{
512 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
513 $s_mount = $_POST['gotoShareMountPoint'];
514 $s_user = $_POST['ShareUser'];
515 /* Preparing the new assignment */
516 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
517 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
518 $this->gotoShares[$a_share['name']."|".$a_share['server']]['OtherStuff']="";
519 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
520 }
521 }
523 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
524 * If there is no defined share selected, we will abort the deletion without any message
525 */
526 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
527 unset($this->gotoShares[$_POST['gotoShare']]);
528 }
530 $smarty->assign("gotoShares",$this->printOutAssignedShares());
531 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
533 /* Hotplug devices will be handled here
534 * There are 3 possible methods for this feature
535 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
536 * Delete will erase an entry, the entry must be selcted in the ListBox first
537 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
538 */
540 /* If there is a new entry wanted, open a new entry by initilising the dialog */
541 if(isset($_POST['gotoHotplugDeviceNew'])){
542 $this->dialog = new hotplugDialog($this->config,$this->dn);
543 $this->is_dialog = true;
544 }
546 /* We have to delete the selected hotplug from the list*/
547 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
548 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
549 }
551 /* There are already defined hotplugs from other users we could use */
552 if(isset($_POST['gotoHotplugDeviceUse'])){
553 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
554 $this->is_dialog = true;
555 }
557 /* Dialog Aborted */
558 if(isset($_POST['HotPlugCancel'])){
559 unset($this->dialog);
560 $this->dialog= NULL;
561 $this->is_dialog = false;
562 }
564 /* Dialod saved */
565 if(isset($_POST['HotPlugSave'])){
566 $this->dialog->save_object();
567 if(count($this->dialog->check())!=0){
568 foreach($this->dialog->check() as $msg){
569 print_red($msg);
570 }
571 }else{
572 $this->dialog->save_object();
573 $a_tmp = $this->dialog->save();
574 if(is_array($a_tmp)){
575 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
576 }
577 unset($this->dialog);
578 $this->dialog= NULL;
579 $this->is_dialog = false;
580 }
581 }
583 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
584 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
586 /* Printer Assignment will managed below
587 * A printer can be assigned in two different ways and two different types
588 * There are 2 types of users assigned to a printer : user and admin
589 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
590 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
591 */
593 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
594 if(isset($_POST['gotoPrinterAdd'])){
595 $this->is_dialog=true;
596 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
597 }
599 if(isset($_POST['PrinterCancel'])){
600 $this->is_dialog=false;
601 unset($this->dialog);
602 $this->dialog=NULL;
603 }
605 if(isset($_POST['PrinterSave'])){
606 if(count($this->dialog->check())!=0){
607 $tmp = $this->dialog->check();
608 foreach($tmp as $msg){
609 print_red($msg);
610 }
611 }else{
612 $this->dialog->save_object();
613 $tmp = $this->dialog->save();
614 $tmp2= $this->dialog->getPrinter(true);
615 $this->gotoPrinter[$tmp]=$tmp2[$tmp];
616 $this->gotoPrinter[$tmp]['mode']="user";
617 $this->is_dialog=false;
618 unset($this->dialog);
619 $this->dialog =NULL;
620 }
621 }
623 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
624 $printer = $_POST['gotoPrinterSel'];
625 unset($this->gotoPrinter[$printer]);
626 }
628 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
629 $printer = $_POST['gotoPrinterSel'];
630 if($this->gotoPrinter[$printer]['mode']=="user"){
631 $this->gotoPrinter[$printer]['mode']="admin";
632 }else{
633 $this->gotoPrinter[$printer]['mode']="user";
634 }
635 }
637 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
638 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
640 /* General behavior */
641 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
642 $this->dialog->save_object();
643 return ($this->dialog->execute());
644 }
645 if($this->acl != "#none#"){
646 $smarty->assign("useProfileACL","");
647 }else{
648 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
649 $smarty->assign("gotoProfileServerACL"," disabled ");
650 $smarty->assign("gotoProfileQuotaACL"," disabled ");
651 }
653 if(!$this->useProfile){
654 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
655 $smarty->assign("gotoProfileServerACL"," disabled ");
656 $smarty->assign("gotoProfileQuotaACL"," disabled ");
657 }
659 /* Als smarty vars are set. Get smarty template and generate output */
660 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
662 return($display);
663 }
665 function remove_from_parent()
666 {
667 /* only if it was an account*/
668 if (!$this->initially_was_account){
669 return;
670 }
672 /* include global link_info */
673 $ldap= $this->config->get_ldap_link();
675 /* Remove and write to LDAP */
676 plugin::remove_from_parent();
678 /* Don't save our template variables */
679 $skip = array("uid",
680 "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
681 /* Skip all these attributes */
682 foreach($skip as $del){
683 unset($this->attrs[$del]);
684 }
686 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
688 $ldap->cd($this->dn);
689 $ldap->modify($this->attrs);
691 show_ldap_error($ldap->get_error());
693 /* Optionally execute a command after we're done */
694 $this->handle_post_events("remove");
695 }
698 /* Save data to object */
699 function save_object()
700 {
701 /* Get all Posted vars
702 * Setup checkboxes
703 */
707 if(isset($_POST['iamposted'])){
708 if(isset($_POST['useProfile'])){
709 $this->useProfile = true;
710 }else{
711 $this->useProfile = false;
712 }
713 if(isset($_POST['gotoProfileFlag_C'])){
714 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
715 }else{
716 $this->gotoProfileFlag_C = false;
717 }
718 if(isset($_POST['gotoProfileFlag_L'])){
719 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
720 }else{
721 $this->gotoProfileFlag_L = false;
722 }
724 plugin::save_object();
725 foreach($this->attributes as $s_attr){
726 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
727 if(isset($_POST[$s_attr])){
728 $this->$s_attr = $_POST[$s_attr];
729 }else{
730 $this->$s_attr = false;
731 }
732 }
733 }
734 }
737 /* Check supplied data */
738 function check()
739 {
740 $message= array();
742 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
743 $message[]=_("Please set a valid profile quota size.");
744 }
745 if(!isset($this->attrs['objectClass'])){
746 $this->attrs['objectClass']=array();
747 }
748 if(!$this->is_group){
749 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
750 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
751 }
752 }
753 return ($message);
754 }
757 /* Save to LDAP */
758 function save()
759 {
761 /* only save changed variables ....*/
762 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
763 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
764 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
765 $method="https://";
766 }else{
767 $method="http://";
768 }
770 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
771 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
772 }else{
773 $this->gotoKioskProfile= array();
774 }
776 plugin::save();
777 $ldap= $this->config->get_ldap_link();
779 $realyUsedAttrs= array();
781 $path = search_config($this->config->data,"environment", "KIOSKPATH");
782 /* Creating Kiosk Profiles */
783 foreach($this->newKioskProfiles as $file){
784 $contents = $file['contents'];
785 $fp = @fopen($path."/".$file['name'],"w");
786 if(!$fp){
787 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
788 }else{
789 fwrite($fp,$contents,strlen($contents));
790 }
791 @unlink($file['tmp_name']);
792 }
794 /* Save already used objectClasses */
795 $ocs = $this->attrs['objectClass'];
796 unset($ocs['count']);
797 $this->attrs = array();
798 $this->attrs['objectClass']= $ocs;
799 foreach($this->objectclasses as $objc){
800 if(!in_array($objc,$this->attrs['objectClass'])){
801 $this->attrs['objectClass'][]=$objc;
802 }
803 }
806 /* Save usersettings to Printer */
808 if(chkacl($this->acl,"gotoPrinter")!=""){
809 $this->gotoPrinter = array();
810 }
812 if($this->is_group){
813 $s_suffix = "Group";
814 }else{
815 $s_suffix = "User";
816 }
819 /* 1. Search all printers that have our uid/cn as member
820 * 2. Delete this uid/cn from every single entry and save it again.
821 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
822 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
823 */
824 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
825 while($attr = $ldap->fetch()){
827 /* Walk trough all printers and check if our user id used, if so remove it.
828 * Later we will insert our uid at the right place.
829 */
831 /* Remove normal entries (User)*/
832 if(isset($attr['goto'.$s_suffix.'Printer'])) {
833 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
834 if($this->uid==$user){
835 unset($attr['goto'.$s_suffix.'Printer'][$key]);
836 }
837 }
838 }
840 /* Remove administrational entries (Admin)*/
841 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
842 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
843 if($this->uid==$user){
844 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
845 }
846 }
847 }
849 /* Extract useable tags, to be able to save all changes
850 */
851 $attrs_used = array();
852 foreach($attr as $key=>$val){
854 /* If index is numeric, skip it ...*/
855 if((!is_numeric($key))&&($key!="count")){
857 /* If entry contains 'count' remove it */
858 if(is_array($val)&&isset($val['count'])){
859 unset($val['count']);
860 }
861 $attrs_used[$key]=$val;
862 }
863 }
864 /* the result of cleaning the entry is
865 * to be able to directly save this again,
866 * if all changes are made
867 */
868 $attr= $attrs_used;
870 #fix : Id don't know why such an entry was set ...
871 if(isset($attr['GOTOADMINPRINTER'])){
872 unset($attr['GOTOADMINPRINTER']);
873 }
875 /* Save changes */
876 $ldap->cd($attr['dn']);
877 unset($attr['dn']);
878 $ldap->modify($attr);
879 if($ldap->get_error()!="Success"){
880 print_red(_("Error while writing printer")." : ".$ldap->get_error());
881 }
882 }
884 /* All printers are cleaned, (our cn/uid removed)
885 * now we must add our uid / cn
886 * to the new configured printers.
887 */
888 foreach($this->gotoPrinter as $printer) {
889 $ldap->cd($printer['dn']);
890 $ldap->cat($printer['dn']);
891 $attrs= $ldap->fetch();
892 $attrs_used = array();
893 foreach($attrs as $key=>$val){
894 if((!is_numeric($key))&&($key!="count")){
895 if(is_array($val)&&isset($val['count'])){
896 unset($val['count']);
897 }
898 $attrs_used[$key]=$val;
899 }
900 }
901 /* $attrs contains all values
902 * we need, to save the entry lateron
903 */
904 $attrs= $attrs_used;
906 /* Depending on the type (User/Admin)
907 * switch these attributes, that makes it easier
908 */
909 if($printer['mode'] == "user"){
910 $attribute = "goto".$s_suffix."Printer";
911 $attribute2 = "goto".$s_suffix."AdminPrinter";
912 }else{
913 $attribute = "goto".$s_suffix."AdminPrinter";
914 $attribute2 = "goto".$s_suffix."Printer";
915 }
917 /* If this user is already assigned to $attribute2
918 * delete user from $attribute2, to be albe to attach him to $attribute
919 * A user can't be admin and normal user for one printer
920 */
921 if(!isset($printer[$attribute2])){
922 $printer[$attribute2]=array();
923 }else{
924 if(in_array($this->uid,$printer[$attribute2])){
925 $tmp = array_flip($printer[$attribute2]);
926 unset($tmp[$this->uid]);
927 $attrs[$attribute2]=array_flip($tmp);
928 }
929 /* If Last entry removed, clear attribute*/
930 if(empty($attrs[$attribute2])){
931 $attrs[$attribute2]=array();
932 }
933 }
935 /* Attach user to the $attribute, if he is'nt already attached
936 */
937 if(!isset($attrs[$attribute])){
938 $attrs[$attribute]=array($this->uid);
939 }else{
940 unset($attrs[$attribute]['count']);
941 if(!in_array($this->uid,$attrs[$attribute])){
942 $attrs[$attribute][]=$this->uid;
943 }
944 }
946 $ldap->cd($attrs['dn']);
947 unset($attrs['dn']);
948 $ldap->modify($attrs);
949 if($ldap->get_error()!="Success"){
950 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
951 }
952 }
954 /* Prepare HotPlug devices */
955 $this->attrs['gotoHotplugDevice'] = array();
956 foreach($this->gotoHotplugDevices as $name => $device){
957 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
958 }
960 /* Prepare LogonScripts */
961 $this->attrs['gotoLogonScript'] = array();
962 foreach($this->gotoLogonScripts as $name => $script){
963 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
964 $script['LogonOverload'].$script['LogonLast']."|".
965 $script['LogonPriority']."|".
966 base64_encode($script['LogonData'])."|".
967 $script['LogonDescription'];
968 }
970 /* Prepare Shares */
971 $this->attrs['gotoShare']=array();
972 foreach($this->gotoShares as $name => $share){
973 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['OtherStuff']."|".$share['Username'];
974 }
977 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer");
979 foreach($saveThis as $tosave){
980 if(!empty($this->$tosave)){
981 $this->attrs[$tosave]=$this->$tosave;
982 }else{
983 $this->attrs[$tosave]=array();
984 }
985 }
987 /* Prepare Flags */
988 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
989 if(empty($this->attrs['gotoProfileFlags'][0])){
990 $this->attrs['gotoProfileFlags']=array();
991 }
993 if($this->useProfile == false){
994 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
995 $this->attrs['gotoProfileServer']= array();
996 }
998 foreach($this->attributes as $s_attr){
999 if(chkacl($this->acl,$s_attr)!="") {
1000 if(isset($this->attrs[$s_attr])){
1001 unset($this->attrs[$s_attr]);
1002 }
1003 }
1004 }
1006 $ldap->cat ($this->dn);
1007 if ($ldap->fetch()){
1008 $mode= "modify";
1009 } else {
1010 $mode= "add";
1011 $ldap->cd($this->config->current['BASE']);
1012 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1013 }
1015 $ldap->cd($this->dn);
1016 $ldap->$mode($this->attrs);
1017 if($ldap->get_error()!="Success"){
1018 print_red($ldap->get_error());
1019 }
1020 $this->handle_post_events($mode);
1021 }
1023 /* Generate ListBox frindly output for the defined shares
1024 * Possibly Add or remove an attribute here,
1025 */
1026 function printOutAssignedShares()
1027 {
1028 $a_return = array();
1029 if(is_array($this->gotoShares)){
1030 foreach($this->gotoShares as $share){
1031 if (!preg_match('/^!/', $share['server'])){
1032 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1033 }
1034 }
1035 }
1036 return($a_return);
1037 }
1039 /* Generate ListBox frindly output for the definedhotplugs
1040 * Possibly Add or remove an attribute here,
1041 */
1042 function printOutHotPlugDevices()
1043 {
1044 $a_return= array();
1045 if(is_array($this->gotoHotplugDevices)){
1046 foreach($this->gotoHotplugDevices as $key=>$device){
1047 $a_return[$key] = $device['name']." - ".$device['id'];
1048 }
1049 }
1050 return($a_return);
1051 }
1053 /* Generates ListBox frienly output of used printer devices
1054 * Append ' - admin' if printer is used in admin mode
1055 */
1056 function printOutPrinterDevices()
1057 {
1058 $a_return = array();
1059 if(is_array($this->gotoPrinter)){
1060 foreach($this->gotoPrinter as $printer){
1061 if($printer['mode'] == "admin"){
1062 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
1063 }else{
1064 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1065 }
1066 }
1067 }
1068 return($a_return);
1069 }
1071 /* Generates ListBox frienly output of used logonscripts
1072 */
1073 function printOutLogonScripts()
1074 {
1075 $a_return = array();
1076 if(is_array($this->gotoLogonScripts)){
1077 foreach($this->gotoLogonScripts as $script){
1078 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1079 }
1080 }
1081 return($a_return);
1082 }
1083 }
1088 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1089 ?>