d66917ebd2e5c6772458c9cc8917991786e6de5c
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 = ""; // 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 "gotoHotplugDevices");
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 /* Get all Printer assignments */
87 $ldap = $this->config->get_ldap_link();
88 $ldap->cd($this->config->current['BASE']);
89 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
90 while($printer = $ldap->fetch()){
91 $this->gotoPrinter[$printer['cn'][0]]=$printer;
92 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
93 }
94 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
95 while($printer = $ldap->fetch()){
96 $this->gotoPrinter[$printer['cn'][0]]=$printer;
97 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
98 }
100 /* prepare hotplugs */
101 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
102 unset($this->attrs['gotoHotplugDevice']['count']);
103 foreach($this->attrs['gotoHotplugDevice'] as $device){
104 $tmp = $tmp2 = array();
105 $tmp = split("\|",$device);
106 $tmp2['name'] = $tmp[0];
107 $tmp2['description'] = $tmp[1];
108 $tmp2['id'] = $tmp[2];
109 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
110 }
111 }
113 /* prepare LogonScripts */
114 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
115 unset($this->attrs['gotoLogonScript']['count']);
116 foreach($this->attrs['gotoLogonScript'] as $device){
117 $tmp = $tmp2 = array();
118 $tmp = split("\|",$device);
119 $tmp2['LogonName'] = $tmp[0];
120 $tmp2['LogonPriority'] = $tmp[2];
121 if(preg_match("/O/i",$tmp[1])){
122 $tmp2['LogonOverload'] = "O";
123 }else{
124 $tmp2['LogonOverload'] = "";
125 }
126 if(preg_match("/L/i",$tmp[1])){
127 $tmp2['LogonLast'] = "L";
128 }else{
129 $tmp2['LogonLast'] = "";
130 }
131 $tmp2['LogonData'] = base64_decode($tmp[3]);
132 $tmp2['LogonDescription'] = $tmp[4];
133 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
134 }
135 }
137 /* Prepare Shares */
138 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
139 unset($this->attrs['gotoShare']['count']);
140 foreach($this->attrs['gotoShare'] as $share){
141 $tmp = $tmp2 = array();
142 $tmp = split("\|",$share);
143 $tmp2['server'] =$tmp[0];
144 $tmp2['name'] =$tmp[1];
145 $tmp2['mountPoint'] =$tmp[2];
146 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
147 }
148 }
150 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
151 $chr = $this->gotoProfileFlags[$i];
152 $name = "gotoProfileFlag_".$chr;
153 $this->$name=$chr;
154 }
156 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
157 $this->useProfile = true;
158 }else{
159 $this->useProfile = false;
160 }
162 /* Set to group environment if we editing a group */
163 if(!isset($this->parent)){
164 $this->is_group = true;
165 }
167 $this->gotoProfileServers= $config->getShareServerList() ;
168 $this->gotoShareSelections= $config->getShareList(true);
169 $this->gotoAvailableShares= $config->getShareList(false);
171 }
173 function execute()
174 {
175 /* Fill templating stuff */
176 $smarty= get_smarty();
177 $display= "";
178 /* Is accout enabled | are we editing from usermenu or admin menu
179 All these tab management is done here
180 */
182 /* Working from Usermenu an the Account is currently disbled
183 * this->parent : is only set if we are working in a list of tabs
184 * is_account : is only true if the needed objectClass is given
185 */
186 if((!isset($this->parent))&&(!$this->is_account)){
187 /* We are currently editing this tab from usermenu, but this account is not enabled */
188 $smarty->assign("is_account",$this->is_account);
189 /* Load template */
190 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
191 /* Avoid the "You are currently editing ...." message when you leave this tab */
192 $display .= back_to_main();
193 /* Display our message to the user */
194 return $display;
197 /* We are currently editing from group tabs, because
198 * $this->parent is set
199 * posixAccount is not set, so we are not in usertabs.
200 */
201 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
202 $smarty->assign("is_account","true");
203 $this->is_group = true;
204 $this->uid = $this->cn;
205 $this->attrs['uid'] = $this->cn;
207 /* Change state if needed */
208 if (isset($_POST['modify_state'])){
209 $this->is_account= !$this->is_account;
210 }
212 /* Group Dialog with enabled environment options */
213 if ($this->is_account){
214 $display= $this->show_header(_("Remove environment extension"),
215 _("Environment extension enabled. You can disable it by clicking below."));
216 } else {
218 /* Environment is disabled
219 If theres is no posixAccount enabled, you won't be able to enable
220 environment extensions
221 */
222 if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
223 // 4. There is a PosixAccount
224 $display= $this->show_header(_("Add environment extension"),
225 _("Environment extension disabled. You can enable it by clicking below."));
226 return $display;
227 }else{
228 // 4. There is no PosixAccount
229 $display= $this->show_header(_("Add environment extension"),
230 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
231 return $display;
232 }
233 }
234 }else{
235 /* Editing from Usermenu
236 * Tell smarty that this accoutn is enabled
237 */
238 $smarty->assign("is_account","true");
240 $this->is_group = false;
242 /* Do we need to flip is_account state? */
243 if (isset($_POST['modify_state'])){
244 $this->is_account= !$this->is_account;
245 }
247 if(isset($this->parent)){
248 // 3. Account enabled . Editing from adminmenu
249 if ($this->is_account){
250 $display= $this->show_header(_("Remove environment extension"),
251 _("Environment extension enabled. You can disable it by clicking below."));
252 } else {
253 if((isset($this->attrs['objectClass']))
254 &&((in_array("posixAccount",$this->attrs['objectClass'])))
255 ||($this->parent->by_object['posixAccount']->is_account==true)){
256 // 4. There is a PosixAccount
257 $display= $this->show_header(_("Add environment extension"),
258 _("Environment extension disabled. You can enable it by clicking below."));
259 return $display;
260 }else{
261 // 4. There is a PosixAccount
262 $display= $this->show_header(_("Add environment extension"),
263 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
264 return $display;
265 }
266 }
267 }
268 }
269 /* Account is Account : is_accounbt=true.
270 * Else we won't reach this.
271 */
273 /* Prepare all variables for smarty */
274 foreach($this->attributes as $s_attr){
275 /* Set value*/
276 $smarty->assign($s_attr,$this->$s_attr);
278 /* Set checkbox state*/
279 if(empty($this->$s_attr)){
280 $smarty->assign($s_attr."CHK","");
281 }else{
282 $smarty->assign($s_attr."CHK"," checked ");
283 }
285 /* Prepare ACL settings*/
286 if(chkacl($this->acl,$s_attr)=="") {
287 $smarty->assign($s_attr."ACL","");
288 }else{
289 $smarty->assign($s_attr."ACL"," disabled ");
290 }
292 }
294 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
295 if(chkacl($this->acl,$s_attr)=="") {
296 $smarty->assign($s_attr."ACL","");
297 }else{
298 $smarty->assign($s_attr."ACL"," disabled ");
299 }
300 }
302 if($this->acl != "#none#"){
303 $smarty->assign("useProfileACL","");
304 }else{
305 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
306 $smarty->assign("gotoProfileServer"," disabled ");
307 }
309 /* HANDLE Profile Settings here
310 * Assign available Quota and resolution settings
311 * Get all available profile server
312 * Get cache checkbox
313 * Assign this all to Smarty
314 */
316 if(empty($this->gotoProfileFlag_L)){
317 $smarty->assign("gotoProfileFlag_LCHK"," ");
318 }else{
319 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
320 }
322 if(empty($this->gotoProfileFlag_C)){
323 $smarty->assign("gotoProfileFlag_CCHK"," ");
324 }else{
325 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
326 }
328 if(empty($this->useProfile)){
329 $smarty->assign("gotoProfileACL","disabled");
330 $smarty->assign("useProfileCHK","");
331 }else{
332 $smarty->assign("gotoProfileACL","");
333 $smarty->assign("useProfileCHK"," checked ");
334 }
336 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
338 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
339 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
340 if(!is_array($this->gotoProfileServers)){
341 $this->gotoProfileServers =array();
342 }
343 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
345 /* Handle kiosk profiles
346 * Read available from filesystem
347 * Open management if post is transmitted
348 */
350 /* Open Management Dialog */
351 if(isset($_POST['KioskManagementDialog'])){
352 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
353 $this->dialog->parent= $this;
354 $this->is_dialog = true;
355 }
357 /* Save */
358 if(isset($_POST['KioskClose'])){
359 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
361 unset($this->dialog);
362 $this->dialog=NULL;
363 $this->is_dialog = false;
364 }
365 $tmp = new kioskManagementDialog($this->config,$this->dn);
366 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
368 $smarty->assign("gotoKioskProfiles",$list);
369 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
371 /* Logonscript Management
372 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
373 * Perform add Delete edit Posts
374 */
376 /* Dialog Save */
377 if(isset($_POST['LogonSave'])){
378 $this->dialog->save_object();
379 if(count($this->dialog->check())!=0){
380 foreach($this->dialog->check() as $msg){
381 print_red($msg);
382 }
383 }else{
384 $tmp = $this->dialog->save();
385 unset($this->dialog);
386 $this->dialog=NULL;
387 $this->is_dialog=false;
388 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
389 }
390 }
392 /* Dialog Quit without saving */
393 if(isset($_POST['LogonCancel'])){
394 $this->is_dialog= false;
395 unset($this->dialog);
396 $this->dialog= NULL;
397 }
399 /* Check Edit Del New Posts for a selected LogonScript */
400 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
402 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
403 * In this case we create a new Logon Script.
404 */
405 if(isset($_POST['gotoLogonScriptNew'])){
406 $this->is_dialog = true;
407 $this->dialog = new logonManagementDialog($this->config,$this->dn);
408 }
410 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
411 * We only can delete if there is an entry selected.
412 */
413 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
414 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
415 }
417 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
418 * There must be an entry selected to perform edit request.
419 */
420 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
421 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
422 $this->is_dialog = true;
423 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
424 }
425 }
427 /* Append List to smarty*/
428 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
429 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
431 /* In this section server shares will be defined
432 * A user can select one of the given shares and a mount point
433 * and attach this combination to his setup.
434 */
436 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
437 if(!is_array($this->gotoShareSelections)){
438 print $this->gotoShareSelections;
439 $this->gotoShareSelections = array();
440 }
441 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
443 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
444 * This entry will be, a combination of mountPoint and sharedefinitions
445 */
446 if(isset($_POST['gotoShareAdd'])){
447 /* We assign a share to this user, if we don't know where to mount the share */
448 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
449 print_red(_("You must specify a valid mount point."));
450 }else{
451 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
452 $s_mount = $_POST['gotoShareMountPoint'];
453 /* Preparing the new assignment */
454 $this->gotoShares[$a_share['name']]=$a_share;
455 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
456 }
457 }
459 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
460 * If there is no defined share selected, we will abort the deletion without any message
461 */
462 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
463 unset($this->gotoShares[$_POST['gotoShare']]);
464 }
466 $smarty->assign("gotoShares",$this->printOutAssignedShares());
467 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
469 /* Hotplug devices will be handled here
470 * There are 3 possible methods for this feature
471 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
472 * Delete will erase an entry, the entry must be selcted in the ListBox first
473 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
474 */
476 /* If there is a new entry wanted, open a new entry by initilising the dialog */
477 if(isset($_POST['gotoHotplugDeviceNew'])){
478 $this->dialog = new hotplugDialog($this->config,$this->dn);
479 $this->is_dialog = true;
480 }
482 /* We have to delete the selected hotplug from the list*/
483 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
484 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
485 }
487 /* There are already defined hotplugs from other users we could use */
488 if(isset($_POST['gotoHotplugDeviceUse'])){
489 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
490 $this->is_dialog = true;
491 }
493 /* Dialog Aborted */
494 if(isset($_POST['HotPlugCancel'])){
495 unset($this->dialog);
496 $this->dialog= NULL;
497 $this->is_dialog = false;
498 }
500 /* Dialod saved */
501 if(isset($_POST['HotPlugSave'])){
502 $this->dialog->save_object();
503 if(count($this->dialog->check())!=0){
504 foreach($this->dialog->check() as $msg){
505 print_red($msg);
506 }
507 }else{
508 $this->dialog->save_object();
509 $a_tmp = $this->dialog->save();
510 if(is_array($a_tmp)){
511 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
512 }
513 unset($this->dialog);
514 $this->dialog= NULL;
515 $this->is_dialog = false;
516 }
517 }
519 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
520 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
522 /* Printer Assignment will managed below
523 * A printer can be assigned in two different ways and two different types
524 * There are 2 types of users assigned to a printer : user and admin
525 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
526 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
527 */
529 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
530 if(isset($_POST['gotoPrinterAdd'])){
531 $this->is_dialog=true;
532 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
533 }
535 if(isset($_POST['PrinterCancel'])){
536 $this->is_dialog=false;
537 unset($this->dialog);
538 $this->dialog=NULL;
539 }
541 if(isset($_POST['PrinterSave'])){
542 if(count($this->dialog->check())!=0){
543 $tmp = $this->dialog->check();
544 foreach($tmp as $msg){
545 print_red($msg);
546 }
547 }else{
548 $this->dialog->save_object();
549 $tmp = $this->dialog->save();
550 $tmp2= $this->dialog->getPrinter(true);
551 $this->gotoPrinter[$tmp]=$tmp2[$tmp];
552 $this->gotoPrinter[$tmp]['mode']="user";
553 $this->is_dialog=false;
554 unset($this->dialog);
555 $this->dialog =NULL;
556 }
557 }
559 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
560 $printer = $_POST['gotoPrinterSel'];
561 unset($this->gotoPrinter[$printer]);
562 }
564 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
565 $printer = $_POST['gotoPrinterSel'];
566 if($this->gotoPrinter[$printer]['mode']=="user"){
567 $this->gotoPrinter[$printer]['mode']="admin";
568 }else{
569 $this->gotoPrinter[$printer]['mode']="user";
570 }
571 }
573 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
574 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
576 /* General behavior */
577 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
578 $this->dialog->save_object();
579 return ($this->dialog->execute());
580 }
581 if($this->acl != "#none#"){
582 $smarty->assign("useProfileACL","");
583 }else{
584 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
585 $smarty->assign("gotoProfileServerACL"," disabled ");
586 }
588 if(!$this->useProfile){
589 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
590 $smarty->assign("gotoProfileServerACL"," disabled ");
591 }
593 /* Als smarty vars are set. Get smarty template and generate output */
594 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
596 return($display);
597 }
599 function remove_from_parent()
600 {
601 /* only if it was an account*/
602 if (!$this->initially_was_account){
603 return;
604 }
606 /* include global link_info */
607 $ldap= $this->config->get_ldap_link();
609 /* Remove and write to LDAP */
610 plugin::remove_from_parent();
612 /* Don't save our template variables */
613 $skip = array("uid",
614 "gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
615 /* Skip all these attributes */
616 foreach($skip as $del){
617 unset($this->attrs[$del]);
618 }
620 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
622 $ldap->cd($this->dn);
623 $ldap->modify($this->attrs);
625 show_ldap_error($ldap->get_error());
627 /* Optionally execute a command after we're done */
628 $this->handle_post_events("remove");
629 }
632 /* Save data to object */
633 function save_object()
634 {
635 /* Get all Posted vars
636 * Setup checkboxes
637 */
641 if(isset($_POST['iamposted'])){
642 if(isset($_POST['useProfile'])){
643 $this->useProfile = $_POST['useProfile'];
644 }else{
645 $this->useProfile = true;
646 }
647 if(isset($_POST['gotoProfileFlag_C'])){
648 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
649 }else{
650 $this->gotoProfileFlag_C = false;
651 }
652 if(isset($_POST['gotoProfileFlag_L'])){
653 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
654 }else{
655 $this->gotoProfileFlag_L = false;
656 }
658 plugin::save_object();
659 foreach($this->attributes as $s_attr){
660 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
661 if(isset($_POST[$s_attr])){
662 $this->$s_attr = $_POST[$s_attr];
663 }else{
664 $this->$s_attr = false;
665 }
666 }
667 }
668 }
671 /* Check supplied data */
672 function check()
673 {
674 $message= array();
676 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
677 $message[]=_("Please set a valid profile quota size.");
678 }
679 if(!isset($this->attrs['objectClass'])){
680 $this->attrs['objectClass']=array();
681 }
682 if(!$this->is_group){
683 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
684 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
685 }
686 }
687 return ($message);
688 }
691 /* Save to LDAP */
692 function save()
693 {
694 plugin::save();
695 $ldap= $this->config->get_ldap_link();
697 $realyUsedAttrs= array();
700 $path = search_config($this->config->data,"environment", "KIOSKPATH");
701 /* Creating Kiosk Profiles */
702 foreach($this->newKioskProfiles as $file){
703 $contents = $file['contents'];
704 $fp = @fopen($path."/".$file['name'],"w");
705 if(!$fp){
706 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
707 }else{
708 fwrite($fp,$contents,strlen($contents));
709 }
710 @unlink($file['tmp_name']);
711 }
713 /* Save already used objectClasses */
714 $ocs = $this->attrs['objectClass'];
715 unset($ocs['count']);
716 $this->attrs = array();
717 $this->attrs['objectClass']= $ocs;
718 foreach($this->objectclasses as $objc){
719 if(!in_array($objc,$this->attrs['objectClass'])){
720 $this->attrs['objectClass'][]=$objc;
721 }
722 }
725 /* Save usersettings to Printer */
727 if(chkacl($this->acl,"gotoPrinter")!=""){
728 $this->gotoPrinter = array();
729 }
731 if($this->is_group){
732 $s_suffix = "Group";
733 }else{
734 $s_suffix = "User";
735 }
738 /* 1. Search all printers that have our uid/cn as member
739 * 2. Delete this uid/cn from every single entry and save it again.
740 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
741 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
742 */
743 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
744 while($attr = $ldap->fetch()){
746 /* Walk trough all printers and check if our user id used, if so remove it.
747 * Later we will insert our uid at the right place.
748 */
750 /* Remove normal entries (User)*/
751 if(isset($attr['goto'.$s_suffix.'Printer'])) {
752 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
753 if($this->uid==$user){
754 unset($attr['goto'.$s_suffix.'Printer'][$key]);
755 }
756 }
757 }
759 /* Remove administrational entries (Admin)*/
760 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
761 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
762 if($this->uid==$user){
763 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
764 }
765 }
766 }
768 /* Extract useable tags, to be able to save all changes
769 */
770 $attrs_used = array();
771 foreach($attr as $key=>$val){
773 /* If index is numeric, skip it ...*/
774 if((!is_numeric($key))&&($key!="count")){
776 /* If entry contains 'count' remove it */
777 if(is_array($val)&&isset($val['count'])){
778 unset($val['count']);
779 }
780 $attrs_used[$key]=$val;
781 }
782 }
783 /* the result of cleaning the entry is
784 * to be able to directly save this again,
785 * if all changes are made
786 */
787 $attr= $attrs_used;
789 #fix : Id don't know why such an entry was set ...
790 if(isset($attr['GOTOADMINPRINTER'])){
791 unset($attr['GOTOADMINPRINTER']);
792 }
794 /* Save changes */
795 $ldap->cd($attr['dn']);
796 unset($attr['dn']);
797 $ldap->modify($attr);
798 if($ldap->get_error()!="Success"){
799 print_red(_("Error while writing printer")." : ".$ldap->get_error());
800 }
801 }
803 /* All printers are cleaned, (our cn/uid removed)
804 * now we must add our uid / cn
805 * to the new configured printers.
806 */
807 foreach($this->gotoPrinter as $printer) {
808 $ldap->cd($printer['dn']);
809 $ldap->cat($printer['dn']);
810 $attrs= $ldap->fetch();
811 $attrs_used = array();
812 foreach($attrs as $key=>$val){
813 if((!is_numeric($key))&&($key!="count")){
814 if(is_array($val)&&isset($val['count'])){
815 unset($val['count']);
816 }
817 $attrs_used[$key]=$val;
818 }
819 }
820 /* $attrs contains all values
821 * we need, to save the entry lateron
822 */
823 $attrs= $attrs_used;
825 /* Depending on the type (User/Admin)
826 * switch these attributes, that makes it easier
827 */
828 if($printer['mode'] == "user"){
829 $attribute = "goto".$s_suffix."Printer";
830 $attribute2 = "goto".$s_suffix."AdminPrinter";
831 }else{
832 $attribute = "goto".$s_suffix."AdminPrinter";
833 $attribute2 = "goto".$s_suffix."Printer";
834 }
836 /* If this user is already assigned to $attribute2
837 * delete user from $attribute2, to be albe to attach him to $attribute
838 * A user can't be admin and normal user for one printer
839 */
840 if(!isset($printer[$attribute2])){
841 $printer[$attribute2]=array();
842 }else{
843 if(in_array($this->uid,$printer[$attribute2])){
844 $tmp = array_flip($printer[$attribute2]);
845 unset($tmp[$this->uid]);
846 $attrs[$attribute2]=array_flip($tmp);
847 }
848 /* If Last entry removed, clear attribute*/
849 if(empty($attrs[$attribute2])){
850 $attrs[$attribute2]=array();
851 }
852 }
854 /* Attach user to the $attribute, if he is'nt already attached
855 */
856 if(!isset($attrs[$attribute])){
857 $attrs[$attribute]=array($this->uid);
858 }else{
859 unset($attrs[$attribute]['count']);
860 if(!in_array($this->uid,$attrs[$attribute])){
861 $attrs[$attribute][]=$this->uid;
862 }
863 }
865 $ldap->cd($attrs['dn']);
866 unset($attrs['dn']);
867 $ldap->modify($attrs);
868 if($ldap->get_error()!="Success"){
869 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
870 }
871 }
873 /* Prepare HotPlug devices */
874 $this->attrs['gotoHotplugDevice'] = array();
875 foreach($this->gotoHotplugDevices as $name => $device){
876 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
877 }
879 /* Prepare LogonScripts */
880 $this->attrs['gotoLogonScript'] = array();
881 foreach($this->gotoLogonScripts as $name => $script){
882 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
883 $script['LogonOverload'].$script['LogonLast']."|".
884 $script['LogonPriority']."|".
885 base64_encode($script['LogonData'])."|".
886 $script['LogonDescription'];
887 }
889 /* Prepare Shares */
890 $this->attrs['gotoShare']=array();
891 foreach($this->gotoShares as $name => $share){
892 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint'];
893 }
895 if(!empty($this->gotoKioskProfile)){
896 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
897 }else{
898 $this->attrs['gotoKioskProfile']= array();
899 }
901 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
903 foreach($saveThis as $tosave){
904 if(!empty($this->$tosave)){
905 $this->attrs[$tosave]=$this->$tosave;
906 }else{
907 $this->attrs[$tosave]=array();
908 }
909 }
911 /* Prepare Flags */
912 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
913 if(empty($this->attrs['gotoProfileFlags'][0])){
914 $this->attrs['gotoProfileFlags']=array();
915 }
917 if($this->useProfile == false){
918 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
919 $this->attrs['gotoProfileServer']= array();
920 }
922 foreach($this->attributes as $s_attr){
923 if(chkacl($this->acl,$s_attr)!="") {
924 if(isset($this->attrs[$s_attr])){
925 unset($this->attrs[$s_attr]);
926 }
927 }
928 }
930 $ldap->cat ($this->dn);
931 if ($ldap->fetch()){
932 $mode= "modify";
933 } else {
934 $mode= "add";
935 $ldap->cd($this->config->current['BASE']);
936 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
937 }
939 $ldap->cd($this->dn);
940 $ldap->$mode($this->attrs);
941 if($ldap->get_error()!="Success"){
942 print_red($ldap->get_error());
943 }
944 $this->handle_post_events($mode);
945 }
947 /* Generate ListBox frindly output for the defined shares
948 * Possibly Add or remove an attribute here,
949 */
950 function printOutAssignedShares()
951 {
952 $a_return = array();
953 if(is_array($this->gotoShares)){
954 foreach($this->gotoShares as $share){
955 $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
956 }
957 }
958 return($a_return);
959 }
961 /* Generate ListBox frindly output for the definedhotplugs
962 * Possibly Add or remove an attribute here,
963 */
964 function printOutHotPlugDevices()
965 {
966 $a_return= array();
967 if(is_array($this->gotoHotplugDevices)){
968 foreach($this->gotoHotplugDevices as $key=>$device){
969 $a_return[$key] = $device['name']." - ".$device['id'];
970 }
971 }
972 return($a_return);
973 }
975 /* Generates ListBox frienly output of used printer devices
976 * Append ' - admin' if printer is used in admin mode
977 */
978 function printOutPrinterDevices()
979 {
980 $a_return = array();
981 if(is_array($this->gotoPrinter)){
982 foreach($this->gotoPrinter as $printer){
983 if($printer['mode'] == "admin"){
984 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
985 }else{
986 $a_return[$printer['cn'][0]]= $printer['cn'][0];
987 }
988 }
989 }
990 return($a_return);
991 }
993 /* Generates ListBox frienly output of used logonscripts
994 */
995 function printOutLogonScripts()
996 {
997 $a_return = array();
998 if(is_array($this->gotoLogonScripts)){
999 foreach($this->gotoLogonScripts as $script){
1000 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1001 }
1002 }
1003 return($a_return);
1004 }
1005 }
1010 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1011 ?>