4177481b96ac6c0756666db3c74e6565be8c884e
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 $gotoPrinters = array();// All available Printer
42 var $gotoPrinter = ""; // The selected Printer
44 /* Share */
45 var $gotoShares = array();// Currently Share Option
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","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
63 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
64 "gotoLogonScripts","gotoLogonScript",
65 "gotoPrinters","gotoPrinter",
66 "gotoShares","gotoShare","gotoShareSelections",
67 "gotoKioskProfile","gotoKioskProfiles",
68 "gotoHotplugDevice","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);
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->gotoPrinters[$printer['cn'][0]]=$printer;
92 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
93 }
94 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
95 while($printer = $ldap->fetch()){
96 $this->gotoPrinters[$printer['cn'][0]]=$printer;
97 $this->gotoPrinters[$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'] = base64_decode($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['name'] =$tmp[0];
144 $tmp2['mountPoint']=base64_decode($tmp[1]);
145 $this->gotoShares[$tmp[0]]=$tmp2;
146 }
147 }
149 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
150 $chr = $this->gotoProfileFlags[$i];
151 $name = "gotoProfileFlag_".$chr;
152 $this->$name=$chr;
153 }
155 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
156 $this->useProfile = true;
157 }else{
158 $this->useProfile = false;
159 }
161 /* Set to group environment if we editing a group */
162 if(!isset($this->parent)){
163 $this->is_group = true;
164 }
167 }
169 function execute()
170 {
171 /* Fill templating stuff */
172 $smarty= get_smarty();
173 $display= "";
174 /* Is accout enabled | are we editing from usermenu or admin menu
175 All these tab management is done here
176 */
178 // 1. Account disabled . Editing from usermenu
179 if((!isset($this->parent))&&(!$this->is_account)){
180 print "asdf";
181 /* We are currently editing this tab from usermenu, but this account is not enabled */
182 $smarty->assign("is_account",$this->is_account);
183 /* Load template */
184 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
185 /* Avoid the "You are currently editing ...." message when you leave this tab */
186 $display .= back_to_main();
187 /* Display our message to the user */
188 return $display;
190 // Account is enabled
191 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
192 $smarty->assign("is_account","true");
193 $this->is_Account = true;
194 $this->is_group = true;
195 $this->uid = $this->cn;
196 $this->attrs['uid'] = $this->cn;
198 if (isset($_POST['modify_state'])){
199 $this->is_account= !$this->is_account;
200 }
202 // 3. Account enabled . Editing from adminmenu
203 if ($this->is_account){
204 $display= $this->show_header(_("Remove environment extension"),
205 _("This server has environment extension enabled. You can disable it by clicking below."));
206 } else {
207 if((in_array("posixAccount",$this->attrs['objectClass']))){
208 // 4. There is a PosixAccount
209 $display= $this->show_header(_("Add environment extension"),
210 _("This server has environment extension disabled. You can enable it by clicking below."));
211 return $display;
212 }else{
213 // 4. There is a PosixAccount
214 $display= $this->show_header(_("Add environment extension"),
215 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."));
216 return $display;
217 }
218 }
222 }else{
223 /* Tell smarty that this accoutn is enabled */
224 $smarty->assign("is_account","true");
226 /* Do we need to flip is_account state? */
227 if (isset($_POST['modify_state'])){
228 $this->is_account= !$this->is_account;
229 }
230 if(!isset($this->parent)){
231 // 3. ? Account Enabled . Editing from usermenu
233 }else{
234 // 3. Account enabled . Editing from adminmenu
235 if ($this->is_account){
236 $display= $this->show_header(_("Remove environment extension"),
237 _("This server has environment extension enabled. You can disable it by clicking below."));
238 } else {
239 if((isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))||($this->parent->by_object['posixAccount']->is_account==true)){
240 // 4. There is a PosixAccount
241 $display= $this->show_header(_("Add environment extension"),
242 _("This server has environment extension disabled. You can enable it by clicking below."));
243 return $display;
244 }else{
245 // 4. There is a PosixAccount
246 $display= $this->show_header(_("Add environment extension"),
247 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
248 return $display;
249 }
250 }
251 }
252 }
253 /* Account is Account : is_accounbt=true.
254 * Else we won't reach this.
255 */
257 /* Prepare all variables for smarty */
258 foreach($this->attributes as $s_attr){
259 /* Set value*/
260 $smarty->assign($s_attr,$this->$s_attr);
262 /* Set checkbox state*/
263 if(empty($this->$s_attr)){
264 $smarty->assign($s_attr."CHK","");
265 }else{
266 $smarty->assign($s_attr."CHK"," checked ");
267 }
269 /* Prepare ACL settings*/
270 if(chkacl($this->acl,$s_attr)=="") {
271 $smarty->assign($s_attr."ACL","");
272 }else{
273 $smarty->assign($s_attr."ACL"," disabled ");
274 }
276 }
278 if($this->acl != "#none#"){
279 $smarty->assign("useProfileACL","");
280 }else{
281 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
282 $smarty->assign("gotoProfileServer"," disabled ");
283 }
285 /* HANDLE Profile Settings here
286 * Assign available Quota and resolution settings
287 * Get all available profile server
288 * Get cache checkbox
289 * Assign this all to Smarty
290 */
292 if(empty($this->useProfile)){
293 $smarty->assign("gotoProfileACL","disabled");
294 $smarty->assign("useProfileCHK","");
295 }else{
296 $smarty->assign("gotoProfileACL","");
297 $smarty->assign("useProfileCHK"," checked ");
298 }
300 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
301 $this->gotoProfileServers =$this->getShareServerList() ;
303 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
304 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
305 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
307 /* Handle kiosk profiles
308 * Read available from filesystem
309 * Open management if post is transmitted
310 */
312 /* Open Management Dialog */
313 if(isset($_POST['KioskManagementDialog'])){
314 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
315 $this->dialog->parent= $this;
316 $this->is_dialog = true;
317 }
319 /* Save */
320 if(isset($_POST['KioskClose'])){
321 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
323 unset($this->dialog);
324 $this->dialog=NULL;
325 $this->is_dialog = false;
326 }
327 $tmp = new kioskManagementDialog($this->config,$this->dn);
328 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
330 $smarty->assign("gotoKioskProfiles",$list);
331 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
333 /* Logonscript Management
334 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
335 * Perform add Delete edit Posts
336 */
338 /* Dialog Save */
339 if(isset($_POST['LogonSave'])){
340 $this->dialog->save_object();
341 if(count($this->dialog->check())!=0){
342 foreach($this->dialog->check() as $msg){
343 print_red($msg);
344 }
345 }else{
346 $tmp = $this->dialog->save();
347 unset($this->dialog);
348 $this->dialog=NULL;
349 $this->is_dialog=false;
350 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
351 }
352 }
354 /* Dialog Quit without saving */
355 if(isset($_POST['LogonCancel'])){
356 $this->is_dialog= false;
357 unset($this->dialog);
358 $this->dialog= NULL;
359 }
361 /* Check Edit Del New Posts for a selected LogonScript */
362 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
364 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
365 * In this case we create a new Logon Script.
366 */
367 if(isset($_POST['gotoLogonScriptNew'])){
368 $this->is_dialog = true;
369 $this->dialog = new logonManagementDialog($this->config,$this->dn);
370 }
372 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
373 * We only can delete if there is an entry selected.
374 */
375 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
376 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
377 }
379 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
380 * There must be an entry selected to perform edit request.
381 */
382 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
383 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
384 $this->is_dialog = true;
385 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
386 }
387 }
389 /* Append List to smarty*/
390 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
391 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
393 /* In this section server shares will be defined
394 * A user can select one of the given shares and a mount point
395 * and attach this combination to his setup.
396 */
398 $this->gotoShareSelections = $this->getShareList(true);
399 $this->gotoAvailableShares = $this->getShareList(false);
401 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
402 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
404 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
405 * This entry will be, a combination of mountPoint and sharedefinitions
406 */
407 if(isset($_POST['gotoShareAdd'])){
408 /* We assign a share to this user, if we don't know where to mount the share */
409 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
410 print_red("You must specify a valid mount point.");
411 }else{
412 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
413 $s_mount = $_POST['gotoShareMountPoint'];
415 /* Preparing the new assignment */
416 $this->gotoShares[$a_share['name']]=$a_share;
417 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
418 }
419 }
421 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
422 * If there is no defined share selected, we will abort the deletion without any message
423 */
424 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
425 unset($this->gotoShares[$_POST['gotoShare']]);
426 }
428 $smarty->assign("gotoShares",$this->printOutAssignedShares());
429 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
431 /* Hotplug devices will be handled here
432 * There are 3 possible methods for this feature
433 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
434 * Delete will erase an entry, the entry must be selcted in the ListBox first
435 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
436 */
438 /* If there is a new entry wanted, open a new entry by initilising the dialog */
439 if(isset($_POST['gotoHotplugDeviceNew'])){
440 $this->dialog = new hotplugDialog($this->config,$this->dn);
441 $this->is_dialog = true;
442 }
444 /* We have to delete the selected hotplug from the list*/
445 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
446 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
447 }
449 /* There are already defined hotplugs from other users we could use */
450 if(isset($_POST['gotoHotplugDeviceUse'])){
451 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
452 $this->is_dialog = true;
453 }
455 /* Dialog Aborted */
456 if(isset($_POST['HotPlugCancel'])){
457 unset($this->dialog);
458 $this->dialog= NULL;
459 $this->is_dialog = false;
460 }
462 /* Dialod saved */
463 if(isset($_POST['HotPlugSave'])){
464 $this->dialog->save_object();
465 if(count($this->dialog->check())!=0){
466 foreach($this->dialog->check() as $msg){
467 print_red($msg);
468 }
469 }else{
470 $this->dialog->save_object();
471 $a_tmp = $this->dialog->save();
472 if(is_array($a_tmp)){
473 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
474 }
475 unset($this->dialog);
476 $this->dialog= NULL;
477 $this->is_dialog = false;
478 }
479 }
481 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
482 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
484 /* Printer Assignment will managed below
485 * A printer can be assigned in two different ways and two different types
486 * There are 2 types of users assigned to a printer : user and admin
487 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
488 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
489 */
491 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
492 if(isset($_POST['gotoPrinterAdd'])){
493 $this->is_dialog=true;
494 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
495 }
497 if(isset($_POST['PrinterCancel'])){
498 $this->is_dialog=false;
499 unset($this->dialog);
500 $this->dialog=NULL;
501 }
503 if(isset($_POST['PrinterSave'])){
504 if(count($this->dialog->check())!=0){
505 $tmp = $this->dialog->check();
506 foreach($tmp as $msg){
507 print_red($msg);
508 }
509 }else{
510 $this->dialog->save_object();
511 $tmp = $this->dialog->save();
512 $tmp2= $this->dialog->getPrinter(true);
513 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
514 $this->gotoPrinters[$tmp]['mode']="user";
515 $this->is_dialog=false;
516 unset($this->dialog);
517 $this->dialog =NULL;
518 }
519 }
521 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
522 $printer = $_POST['gotoPrinter'];
523 unset($this->gotoPrinters[$printer]);
524 }
526 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
527 $printer = $_POST['gotoPrinter'];
528 if($this->gotoPrinters[$printer]['mode']=="user"){
529 $this->gotoPrinters[$printer]['mode']="admin";
530 }else{
531 $this->gotoPrinters[$printer]['mode']="user";
532 }
533 }
535 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
536 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
538 /* General behavior */
539 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
540 $this->dialog->save_object();
541 return ($this->dialog->execute());
542 }
543 if($this->acl != "#none#"){
544 $smarty->assign("useProfileACL","");
545 }else{
546 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
547 $smarty->assign("gotoProfileServerACL"," disabled ");
548 }
550 if(!$this->useProfile){
551 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
552 $smarty->assign("gotoProfileServerACL"," disabled ");
553 }
555 /* Als smarty vars are set. Get smarty template and generate output */
556 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
558 return($display);
559 }
561 function remove_from_parent()
562 {
563 /* only if it was an account*/
564 if (!$this->initially_was_account){
565 return;
566 }
568 /* include global link_info */
569 $ldap= $this->config->get_ldap_link();
571 /* Remove and write to LDAP */
572 plugin::remove_from_parent();
574 /* Don't save our template variables */
575 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
576 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
577 "gotoPrinter");
578 /* Skip all these attributes */
579 foreach($skip as $del){
580 unset($this->attrs[$del]);
581 }
583 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
585 $ldap->cd($this->dn);
586 $ldap->modify($this->attrs);
588 show_ldap_error($ldap->get_error());
590 /* Optionally execute a command after we're done */
591 $this->handle_post_events("remove");
592 }
595 /* Save data to object */
596 function save_object()
597 {
598 /* Get all Posted vars
599 * Setup checkboxes
600 */
602 if(isset($_POST['iamposted'])){
603 plugin::save_object();
604 foreach($this->attributes as $s_attr){
605 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
606 if(isset($_POST[$s_attr])){
607 $this->$s_attr = $_POST[$s_attr];
608 }else{
609 $this->$s_attr = false;
610 }
611 }
612 }
613 }
616 /* Check supplied data */
617 function check()
618 {
619 $message= array();
621 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
622 $message[]=_("Please set a valid profile quota size.");
623 }
624 if(!isset($this->attrs['objectClass'])){
625 $this->attrs['objectClass']=array();
626 }
627 if(!$this->is_group){
628 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
629 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
630 }
631 }
632 return ($message);
633 }
636 /* Save to LDAP */
637 function save()
638 {
639 plugin::save();
640 $ldap= $this->config->get_ldap_link();
642 $realyUsedAttrs= array();
645 $path = search_config($this->config->data['MENU'],"environment", "KIOSKPATH");
646 /* Creating Kiosk Profiles */
647 foreach($this->newKioskProfiles as $file){
648 $contents = $file['contents'];
649 $fp = @fopen($path."/".$file['name'],"w");
650 if(!$fp){
651 print_red("Can't save new kiosk profiles, possibly permission denied for folder :",$path);
652 }else{
653 fwrite($fp,$contents,strlen($contents));
654 }
655 @unlink($file['tmp_name']);
656 }
658 /* Save already used objectClasses */
659 $ocs = $this->attrs['objectClass'];
660 unset($ocs['count']);
661 $this->attrs = array();
662 $this->attrs['objectClass']= $ocs;
663 foreach($this->objectclasses as $objc){
664 if(!in_array($objc,$this->attrs['objectClass'])){
665 $this->attrs['objectClass'][]=$objc;
666 }
667 }
670 /* Save usersettings to Printer */
672 if(chkacl($this->acl,"gotoPrinter")!=""){
673 $this->gotoPrinters = array();
674 }
676 if($this->is_group){
677 $s_suffix = "Group";
678 }else{
679 $s_suffix = "User";
680 }
683 if(count($this->gotoPrinters)==0){
684 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
685 while($attr = $ldap->fetch()){
687 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
688 if($this->uid==$user){
689 unset($attr['goto'.$s_suffix.'Printer'][$key]);
690 }
691 }
693 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
694 if($this->uid==$user){
695 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
696 }
697 }
699 $attrs_used = array();
700 foreach($attr as $key=>$val){
701 if((!is_numeric($key))&&($key!="count")){
702 if(is_array($val)&&isset($val['count'])){
703 unset($val['count']);
704 }
705 $attrs_used[$key]=$val;
706 }
707 }
708 $attr= $attrs_used;
709 $tmp =array();
710 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $print){
711 $tmp[]=$print;
712 }
713 $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
715 $tmp =array();
716 foreach($attr['goto'.$s_suffix.'Printer'] as $print){
717 $tmp[]=$print;
718 }
719 $attr['goto'.$s_suffix.'Printer'] = $tmp;
721 $ldap->cd($attr['dn']);
722 unset($attr['dn']);
723 $ldap->modify($attr);
724 if($ldap->get_error()!="Success"){
725 print_red("Printer saving ".$ldap->get_error());
726 }
727 }
728 }
730 foreach($this->gotoPrinters as $printer) {
731 $ldap->cd($printer['dn']);
732 $ldap->cat($printer['dn']);
733 $attrs= $ldap->fetch();
734 $attrs_used = array();
735 foreach($attrs as $key=>$val){
736 if((!is_numeric($key))&&($key!="count")){
737 if(is_array($val)&&isset($val['count'])){
738 unset($val['count']);
739 }
740 $attrs_used[$key]=$val;
741 }
742 }
743 $attrs= $attrs_used;
745 /* Filter entries */
747 if($printer['mode'] == "user"){
748 $attribute = "goto".$s_suffix."Printer";
749 $attribute2 = "goto".$s_suffix."AdminPrinter";
750 }else{
751 $attribute = "goto".$s_suffix."AdminPrinter";
752 $attribute2 = "goto".$s_suffix."UserPrinter";
753 }
755 /* If this user is already assigned to $attribute2
756 * delete user from $attribute2, to be albe to attach him to $attribute
757 * A user can't be admin and normal user for one printer
758 */
759 if(!isset($printer[$attribute2])){
760 $printer[$attribute2]=array();
761 }else{
762 if(in_array($this->uid,$printer[$attribute2])){
763 $tmp = array_flip($attrs[$attribute2]);
764 unset($tmp[$this->uid]);
765 $attrs[$attribute2]=array_flip($tmp);
766 }
767 /* If Last entry removed, clear attribute*/
768 if(empty($attrs[$attribute2])){
769 $attrs[$attribute2]=array();
770 }
771 }
773 /* Attach user to the $attribute, if he is'nt already attached
774 */
775 if(!isset($attrs[$attribute])){
776 $attrs[$attribute]=array($this->uid);
777 }else{
778 unset($attrs[$attribute]['count']);
779 if(!in_array($this->uid,$attrs[$attribute])){
780 $attrs[$attribute][]=$this->uid;
781 }
782 }
784 $tmp =array();
785 if(isset($attrs['goto'.$s_suffix.'AdminPrinter'])){
786 foreach($attrs['goto'.$s_suffix.'AdminPrinter'] as $print){
787 $tmp[]=$print;
788 }
789 }
790 $attrs['goto'.$s_suffix.'AdminPrinter'] = $tmp;
792 $tmp =array();
793 if(isset($attrs['goto'.$s_suffix.'Printer'])){
794 foreach($attrs['goto'.$s_suffix.'Printer'] as $print){
795 $tmp[]=$print;
796 }
797 }
798 $attrs['goto'.$s_suffix.'Printer'] = $tmp;
800 $ldap->cd($attrs['dn']);
801 unset($attrs['dn']);
802 $ldap->modify($attrs);
803 if($ldap->get_error()!="Success"){
804 print_red("Printer saving ".$ldap->get_error());
805 }
806 }
808 if(isset($this->attrs['gotoPrinter'])){
809 unset($this->attrs['gotoPrinter']);
810 }
812 /* Prepare HotPlug devices */
813 $this->attrs['gotoHotplugDevice'] = array();
814 foreach($this->gotoHotplugDevices as $name => $device){
815 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".base64_encode($device['id']);
816 }
818 /* Prepare LogonScripts */
819 $this->attrs['gotoLogonScript'] = array();
820 foreach($this->gotoLogonScripts as $name => $script){
821 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
822 $script['LogonOverload'].$script['LogonLast']."|".
823 $script['LogonPriority']."|".
824 base64_encode($script['LogonData'])."|".
825 $script['LogonDescription'];
826 }
828 /* Prepare Shares */
829 $this->attrs['gotoShare']=array();
830 foreach($this->gotoShares as $name => $share){
831 $this->attrs['gotoShare'][] = $share['name']."|".base64_encode($share['mountPoint']);
832 }
834 if(!empty($this->gotoKioskProfile)){
835 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
836 }else{
837 $this->attrs['gotoKioskProfile']= array();
838 }
840 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
842 foreach($saveThis as $tosave){
843 if(!empty($this->$tosave)){
844 $this->attrs[$tosave]=$this->$tosave;
845 }else{
846 $this->attrs[$tosave]=array();
847 }
848 }
850 /* Prepare Flags */
851 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
852 if(empty($this->attrs['gotoProfileFlags'][0])){
853 $this->attrs['gotoProfileFlags']=array();
854 }
856 if($this->useProfile == false){
857 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
858 $this->attrs['gotoProfileServer']= array();
859 }
861 foreach($this->attributes as $s_attr){
862 if(chkacl($this->acl,$s_attr)!="") {
863 if(isset($this->attrs[$s_attr])){
864 unset($this->attrs[$s_attr]);
865 }
866 }
867 }
869 $ldap->cat ($this->dn);
870 if ($ldap->fetch()){
871 $mode= "modify";
872 } else {
873 $mode= "add";
874 $ldap->cd($this->config->current['BASE']);
875 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
876 }
878 $ldap->cd($this->dn);
879 $ldap->$mode($this->attrs);
880 if($ldap->get_error()!="Success"){
881 print_red($ldap->get_error());
882 }
883 $this->handle_post_events($mode);
884 }
886 /* This function returns all available Shares defined in this ldap
887 * There are two ways to call this function, if listboxEntry is true
888 * only name and path are attached to the array, in it is false, the whole
889 * entry will be parsed an atached to the result.
890 */
891 function getShareList($listboxEntry = false)
892 {
893 $ldap= $this->config->get_ldap_link();
894 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
895 $return= array();
896 while($entry = $ldap->fetch($a_res)){
897 unset($entry['goExportEntry']['count']);
898 foreach($entry['goExportEntry'] as $export){
899 $shareAttrs = split("\|",$export);
900 if($listboxEntry) {
901 $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[4];
902 }else{
903 $return[$shareAttrs[0]]['name'] = $shareAttrs[0];
904 $return[$shareAttrs[0]]['description'] = $shareAttrs[1];
905 $return[$shareAttrs[0]]['type'] = $shareAttrs[2];
906 $return[$shareAttrs[0]]['charset'] = $shareAttrs[3];
907 $return[$shareAttrs[0]]['path'] = $shareAttrs[4];
908 $return[$shareAttrs[0]]['option'] = $shareAttrs[5];
909 }
910 }
911 }
912 return($return);
913 }
916 /* This function returns all available ShareServer
917 */
918 function getShareServerList()
919 {
920 $ldap= $this->config->get_ldap_link();
921 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
922 $return= array();
923 while($entry = $ldap->fetch($a_res)){
924 $return[$entry['cn'][0]] = $entry['cn'][0];
925 }
926 return($return);
927 }
929 /* Generate ListBox frindly output for the defined shares
930 * Possibly Add or remove an attribute here,
931 */
932 function printOutAssignedShares()
933 {
934 $a_return = array();
935 if(is_array($this->gotoShares)){
936 foreach($this->gotoShares as $share){
937 $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
938 }
939 }
940 return($a_return);
941 }
943 /* Generate ListBox frindly output for the definedhotplugs
944 * Possibly Add or remove an attribute here,
945 */
946 function printOutHotPlugDevices()
947 {
948 $a_return= array();
949 if(is_array($this->gotoHotplugDevices)){
950 foreach($this->gotoHotplugDevices as $key=>$device){
951 $a_return[$key] = $device['name']." - ".$device['id'];
952 }
953 }
954 return($a_return);
955 }
957 /* Generates ListBox frienly output of used printer devices
958 * Append ' - admin' if printer is used in admin mode
959 */
960 function printOutPrinterDevices()
961 {
962 $a_return = array();
963 if(is_array($this->gotoPrinters)){
964 foreach($this->gotoPrinters as $printer){
965 if($printer['mode'] == "admin"){
966 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
967 }else{
968 $a_return[$printer['cn'][0]]= $printer['cn'][0];
969 }
970 }
971 }
972 return($a_return);
973 }
975 /* Generates ListBox frienly output of used logonscripts
976 */
977 function printOutLogonScripts()
978 {
979 $a_return = array();
980 if(is_array($this->gotoLogonScripts)){
981 foreach($this->gotoLogonScripts as $script){
982 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
983 }
984 }
985 return($a_return);
986 }
987 }
992 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
993 ?>