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