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 = "";
18 /* Attribute definition
19 */
21 /* profile management */
22 var $useProfile = false; // Specifies if we want to use a Server
23 var $gotoProfileServer = ""; // Specifies the selected profile server
24 var $gotoProfileServers = array();// Specifies all available and selectable servers
25 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
26 var $gotoProfileFlag_C = ""; // Flag is set to C if we have the profile caching fucntion enabled
28 var $gotoXResolution = ""; // The selected resolution eg: 1024x768
29 var $gotoXResolutions = array();// Contains all available resolutions for this account
30 var $gotoProfileFlag_L = ""; // Flag is set to L to enable runtime resolution change
31 var $gotoProfileQuota = ""; // User Quota Settings
33 /* Logon script section*/
34 var $gotoLogonScripts = array();// Contains all available Logon Scripts
35 var $gotoLogonScript = ""; // The selected Logon Script
37 /* Printer */
38 var $gotoPrinters = array();// All available Printer
39 var $gotoPrinter = ""; // The selected Printer
41 /* Share */
42 var $gotoShares = array();// Currently Share Option
43 var $gotoShare = ""; // currently selected Share Option
44 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45 var $gotoAvailableShares= array();// Available Shares for this account
47 /* Kiosk profile */
48 var $gotoKioskProfile = ""; // The selected Kiosk Profile
49 var $gotoKioskProfiles = array();// All available Kiosk profiles
51 /* Hotplug Devices */
52 var $gotoHotplugDevice = ""; // Selected hotplug
53 var $gotoHotplugDevices = array();// Already configured hotplug devices
56 /* general settings */
57 // Sets the attributes which will kept on page reload, which will be saved, ...
58 var $attributes = array("uid","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
59 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
60 "gotoLogonScripts","gotoLogonScript",
61 "gotoPrinters","gotoPrinter",
62 "gotoShares","gotoShare","gotoShareSelections",
63 "gotoKioskProfile","gotoKioskProfiles",
64 "gotoHotplugDevice","gotoHotplugDevices");
65 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
67 function environment ($config, $dn= NULL)
68 {
69 plugin::plugin ($config, $dn);
71 /* Get all Printer assignments */
72 $ldap = $this->config->get_ldap_link();
73 $ldap->cd($this->config->current['BASE']);
74 $ldap->search("(&(objectClass=gotoPrinter)(gotoUserPrinter=".$this->uid."))",array("*"));
75 while($printer = $ldap->fetch()){
76 $this->gotoPrinters[$printer['cn'][0]]=$printer;
77 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
78 }
79 $ldap->search("(&(objectClass=gotoPrinter)(gotoAdminPrinter=".$this->uid."))",array("*"));
80 while($printer = $ldap->fetch()){
81 $this->gotoPrinters[$printer['cn'][0]]=$printer;
82 $this->gotoPrinters[$printer['cn'][0]]['mode']="admin";
83 }
85 /* prepare hotplugs */
86 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
87 unset($this->attrs['gotoHotplugDevice']['count']);
88 foreach($this->attrs['gotoHotplugDevice'] as $device){
89 $tmp = $tmp2 = array();
90 $tmp = split("\|",$device);
91 $tmp2['name'] = $tmp[0];
92 $tmp2['description'] = $tmp[1];
93 $tmp2['id'] = $tmp[2];
94 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
95 }
96 }
98 /* prepare LogonScripts */
99 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
100 unset($this->attrs['gotoLogonScript']['count']);
101 foreach($this->attrs['gotoLogonScript'] as $device){
102 $tmp = $tmp2 = array();
103 $tmp = split("\|",$device);
104 $tmp2['LogonName'] = $tmp[0];
105 $tmp2['LogonPriority'] = $tmp[2];
106 if(preg_match("/O/i",$tmp[1])){
107 $tmp2['LogonOverload'] = "O";
108 }else{
109 $tmp2['LogonOverload'] = "";
110 }
111 if(preg_match("/L/i",$tmp[1])){
112 $tmp2['LogonLast'] = "L";
113 }else{
114 $tmp2['LogonLast'] = "";
115 }
116 $tmp2['LogonData'] = base64_decode($tmp[3]);
117 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
118 }
119 }
121 /* Prepare Shares */
122 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
123 unset($this->attrs['gotoShare']['count']);
124 foreach($this->attrs['gotoShare'] as $share){
125 $tmp = $tmp2 = array();
126 $tmp = split("\|",$share);
127 $tmp2['name'] =$tmp[0];
128 $tmp2['mountPoint']=$tmp[1];
129 $this->gotoShares[$tmp[0]]=$tmp2;
130 }
131 }
133 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
134 $chr = $this->gotoProfileFlags[$i];
135 $name = "gotoProfileFlag_".$chr;
136 $this->$name=$chr;
137 }
139 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
140 $this->useProfile = true;
141 }else{
142 $this->useProfile = false;
143 }
145 }
147 function execute()
148 {
149 /* Fill templating stuff */
150 $smarty= get_smarty();
151 $display= "";
152 /* Is accout enabled | are we editing from usermenu or admin menu
153 All these tab management is done here
154 */
156 // 1. Account disabled . Editing from usermenu
157 if((!isset($this->parent))&&(!$this->is_account)){
158 /* We are currently editing this tab from usermenu, but this account is not enabled */
159 $smarty->assign("is_account",$this->is_account);
160 /* Load template */
161 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
162 /* Avoid the "You are currently editing ...." message when you leave this tab */
163 $display .= back_to_main();
164 /* Display our message to the user */
165 return $display;
167 // Account is enabled
168 }else{
169 /* Tell smarty that this accoutn is enabled */
170 $smarty->assign("is_account","true");
172 /* Do we need to flip is_account state? */
173 if (isset($_POST['modify_state'])){
174 $this->is_account= !$this->is_account;
175 }
176 if(!isset($this->parent)){
177 // 3. ? Account Enabled . Editing from usermenu
179 }else{
180 // 3. Account enabled . Editing from adminmenu
181 if ($this->is_account){
182 $display= $this->show_header(_("Remove environment extension"),
183 _("This server has environment extension enabled. You can disable it by clicking below."));
184 } else {
185 if((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)){
186 // 4. There is a PosixAccount
187 $display= $this->show_header(_("Add environment extension"),
188 _("This server has environment extension disabled. You can enable it by clicking below."));
189 return $display;
190 }else{
191 // 4. There is a PosixAccount
192 $display= $this->show_header(_("Add environment extension"),
193 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
194 return $display;
195 }
196 }
197 }
198 }
199 /* Account is Account : is_accounbt=true.
200 * Else we won't reach this.
201 */
203 /* Prepare all variables for smarty */
204 foreach($this->attributes as $s_attr){
205 /* Set value*/
206 $smarty->assign($s_attr,$this->$s_attr);
208 /* Set checkbox state*/
209 if(empty($this->$s_attr)){
210 $smarty->assign($s_attr."CHK","");
211 }else{
212 $smarty->assign($s_attr."CHK"," checked ");
213 }
215 /* Prepare ACL settings*/
216 if(chkacl($this->acl,$s_attr)=="") {
217 $smarty->assign($s_attr."ACL","");
218 }else{
219 $smarty->assign($s_attr."ACL"," disabled ");
220 }
222 }
224 /* HANDLE Profile Settings here
225 * Assign available Quota and resolution settings
226 * Get all available profile server
227 * Get cache checkbox
228 * Assign this all to Smarty
229 */
231 if(empty($this->useProfile)){
232 $smarty->assign("gotoProfileACL","disabled");
233 $smarty->assign("useProfileCHK","");
234 }else{
235 $smarty->assign("gotoProfileACL","");
236 $smarty->assign("useProfileCHK"," checked ");
237 }
239 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
240 $this->gotoProfileServers = array("none","none1");
242 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
243 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
245 /* Handle kiosk profiles
246 * Read available from filesystem
247 * Open management if post is transmitted
248 */
249 $tmp = new kioskManagementDialog($this->config,$this->dn);
250 $list = $tmp->getKioskProfiles();
252 $smarty->assign("gotoKioskProfiles",$list);
253 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
255 /* Open Management Dialog */
256 if(isset($_POST['KioskManagementDialog'])){
257 $this->dialog = new kioskManagementDialog($this->config,$this->dn);
258 $this->is_dialog = true;
259 }
261 /* Save */
262 if(isset($_POST['KioskClose'])){
263 unset($this->dialog);
264 $this->dialog=NULL;
265 $this->is_dialog = false;
266 }
268 /* Logonscript Management
269 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
270 * Perform add Delete edit Posts
271 */
273 /* Dialog Save */
274 if(isset($_POST['LogonSave'])){
275 $this->dialog->save_object();
276 if(count($this->dialog->check())!=0){
277 foreach($this->dialog->check() as $msg){
278 print_red($msg);
279 }
280 }else{
281 $tmp = $this->dialog->save();
282 unset($this->dialog);
283 $this->dialog=NULL;
284 $this->is_dialog=false;
285 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
286 }
287 }
289 /* Dialog Quit without saving */
290 if(isset($_POST['LogonCancel'])){
291 $this->is_dialog= false;
292 unset($this->dialog);
293 $this->dialog= NULL;
294 }
296 /* Check Edit Del New Posts for a selected LogonScript */
297 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
299 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
300 * In this case we create a new Logon Script.
301 */
302 if(isset($_POST['gotoLogonScriptNew'])){
303 $this->is_dialog = true;
304 $this->dialog = new logonManagementDialog($this->config,$this->dn);
305 }
307 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
308 * We only can delete if there is an entry selected.
309 */
310 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
311 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
312 }
314 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
315 * There must be an entry selected to perform edit request.
316 */
317 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
318 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
319 $this->is_dialog = true;
320 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
321 }
322 }
324 /* Append List to smarty*/
325 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
326 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
328 /* In this section server shares will be defined
329 * A user can select one of the given shares and a mount point
330 * and attach this combination to his setup.
331 */
333 $this->gotoShareSelections = $this->getShareList(true);
334 $this->gotoAvailableShares = $this->getShareList(false);
336 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
337 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
339 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
340 * This entry will be, a combination of mountPoint and sharedefinitions
341 */
342 if(isset($_POST['gotoShareAdd'])){
343 /* We assign a share to this user, if we don't know where to mount the share */
344 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))){
345 print_red("You must specify a valid mount point.");
346 }else{
347 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
348 $s_mount = $_POST['gotoShareMountPoint'];
350 /* Preparing the new assignment */
351 $this->gotoShares[$a_share['name']]=$a_share;
352 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
353 }
354 }
356 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
357 * If there is no defined share selected, we will abort the deletion without any message
358 */
359 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
360 unset($this->gotoShares[$_POST['gotoShare']]);
361 }
363 $smarty->assign("gotoShares",$this->printOutAssignedShares());
364 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
366 /* Hotplug devices will be handled here
367 * There are 3 possible methods for this feature
368 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
369 * Delete will erase an entry, the entry must be selcted in the ListBox first
370 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
371 */
373 /* If there is a new entry wanted, open a new entry by initilising the dialog */
374 if(isset($_POST['gotoHotplugDeviceNew'])){
375 $this->dialog = new hotplugDialog($this->config,$this->dn);
376 $this->is_dialog = true;
377 }
379 /* We have to delete the selected hotplug from the list*/
380 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
381 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
382 }
384 /* There are already defined hotplugs from other users we could use */
385 if(isset($_POST['gotoHotplugDeviceUse'])){
386 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
387 $this->is_dialog = true;
388 }
390 /* Dialog Aborted */
391 if(isset($_POST['HotPlugCancel'])){
392 unset($this->dialog);
393 $this->dialog= NULL;
394 $this->is_dialog = false;
395 }
397 /* Dialod saved */
398 if(isset($_POST['HotPlugSave'])){
399 $this->dialog->save_object();
400 if(count($this->dialog->check())!=0){
401 foreach($this->dialog->check() as $msg){
402 print_red($msg);
403 }
404 }else{
405 $this->dialog->save_object();
406 $a_tmp = $this->dialog->save();
407 if(is_array($a_tmp)){
408 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
409 }
410 unset($this->dialog);
411 $this->dialog= NULL;
412 $this->is_dialog = false;
413 }
414 }
416 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
417 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
419 /* Printer Assignment will managed below
420 * A printer can be assigned in two different ways and two different types
421 * There are 2 types of users assigned to a printer : user and admin
422 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
423 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
424 */
426 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
427 if(isset($_POST['gotoPrinterAdd'])){
428 $this->is_dialog=true;
429 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
430 }
432 if(isset($_POST['PrinterCancel'])){
433 $this->is_dialog=false;
434 unset($this->dialog);
435 $this->dialog=NULL;
436 }
438 if(isset($_POST['PrinterSave'])){
439 if(count($this->dialog->check())!=0){
440 $tmp = $this->dialog->check();
441 foreach($tmp as $msg){
442 print_red($msg);
443 }
444 }else{
445 $this->dialog->save_object();
446 $tmp = $this->dialog->save();
447 $tmp2= $this->dialog->getPrinter(true);
448 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
449 $this->gotoPrinters[$tmp]['mode']="user";
450 $this->is_dialog=false;
451 unset($this->dialog);
452 $this->dialog =NULL;
453 }
454 }
456 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
457 $printer = $_POST['gotoPrinter'];
458 unset($this->gotoPrinters[$printer]);
459 }
461 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
462 $printer = $_POST['gotoPrinter'];
463 if($this->gotoPrinters[$printer]['mode']=="user"){
464 $this->gotoPrinters[$printer]['mode']="admin";
465 }else{
466 $this->gotoPrinters[$printer]['mode']="user";
467 }
468 }
470 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
471 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
473 /* General behavior */
474 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
475 $this->dialog->save_object();
476 return ($this->dialog->execute());
477 }
479 /* Als smarty vars are set. Get smarty template and generate output */
480 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
482 return($display);
483 }
485 function remove_from_parent()
486 {
487 /* only if it was an account*/
488 if (!$this->initially_was_account){
489 return;
490 }
492 /* include global link_info */
493 $ldap= $this->config->get_ldap_link();
495 /* Remove and write to LDAP */
496 plugin::remove_from_parent();
498 /* Don't save our template variables */
499 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
500 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
501 "gotoPrinter");
502 /* Skip all these attributes */
503 foreach($skip as $del){
504 unset($this->attrs[$del]);
505 }
507 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
509 $ldap->cd($this->dn);
510 $ldap->modify($this->attrs);
512 show_ldap_error($ldap->get_error());
514 /* Optionally execute a command after we're done */
515 $this->handle_post_events("remove");
516 }
519 /* Save data to object */
520 function save_object()
521 {
522 /* Get all Posted vars
523 * Setup checkboxes
524 */
526 if(isset($_POST['iamposted'])){
527 plugin::save_object();
528 foreach($this->attributes as $s_attr){
529 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
530 if(isset($_POST[$s_attr])){
531 $this->$s_attr = $_POST[$s_attr];
532 }else{
533 $this->$s_attr = false;
534 }
535 }
536 }
537 }
540 /* Check supplied data */
541 function check()
542 {
543 $message= array();
544 return ($message);
545 }
548 /* Save to LDAP */
549 function save()
550 {
551 plugin::save();
552 $ldap= $this->config->get_ldap_link();
554 $realyUsedAttrs= array();
559 /* Save already used objectClasses */
560 $ocs = $this->attrs['objectClass'];
561 unset($ocs['count']);
562 $this->attrs = array();
563 $this->attrs['objectClass']= $ocs;
564 foreach($this->objectclasses as $objc){
565 if(!in_array($objc,$this->attrs['objectClass'])){
566 $this->attrs['objectClass'][]=$objc;
567 }
568 }
571 /* Save usersettings to Printer */
573 if(chkacl($this->acl,"gotoPrinter")!=""){
574 $this->gotoPrinters = array();
575 }
577 if(count($this->gotoPrinters)==0){
578 $ldap->search("(&(objectClass=gotoPrinter)(|(gotoUserPrinter=".$this->uid.")(gotoAdminPrinter=".$this->uid.")))",array("*"));
579 while($attr = $ldap->fetch()){
581 foreach($attr['gotoUserPrinter'] as $key => $user){
582 if($this->uid==$user){
583 unset($attr['gotoUserPrinter'][$key]);
584 }
585 }
587 foreach($attr['gotoAdminPrinter'] as $key => $user){
588 if($this->uid==$user){
589 unset($attr['gotoAdminPrinter'][$key]);
590 }
591 }
593 $attrs_used = array();
594 foreach($attr as $key=>$val){
595 if((!is_numeric($key))&&($key!="count")){
596 if(is_array($val)&&isset($val['count'])){
597 unset($val['count']);
598 }
599 $attrs_used[$key]=$val;
600 }
601 }
602 $attr= $attrs_used;
603 $tmp =array();
604 foreach($attr['gotoAdminPrinter'] as $print){
605 $tmp[]=$print;
606 }
607 $attr['gotoAdminPrinter'] = $tmp;
609 $tmp =array();
610 foreach($attr['gotoUserPrinter'] as $print){
611 $tmp[]=$print;
612 }
613 $attr['gotoUserPrinter'] = $tmp;
615 $ldap->cd($attr['dn']);
616 unset($attr['dn']);
617 $ldap->modify($attr);
618 if($ldap->get_error()!="Success"){
619 print_red("Printer saving ".$ldap->get_error());
620 }
621 }
622 }
624 foreach($this->gotoPrinters as $printer) {
625 $ldap->cd($printer['dn']);
626 $ldap->cat($printer['dn']);
627 $attrs= $ldap->fetch();
628 $attrs_used = array();
629 foreach($attrs as $key=>$val){
630 if((!is_numeric($key))&&($key!="count")){
631 if(is_array($val)&&isset($val['count'])){
632 unset($val['count']);
633 }
634 $attrs_used[$key]=$val;
635 }
636 }
637 $attrs= $attrs_used;
639 /* Filter entries */
641 if($printer['mode'] == "user"){
642 $attribute = "gotoUserPrinter";
643 $attribute2 = "gotoAdminPrinter";
644 }else{
645 $attribute = "gotoAdminPrinter";
646 $attribute2 = "gotoUserPrinter";
647 }
649 /* If this user is already assigned to $attribute2
650 * delete user from $attribute2, to be albe to attach him to $attribute
651 * A user can't be admin and normal user for one printer
652 */
653 if(!isset($printer[$attribute2])){
654 $printer[$attribute2]=array();
655 }else{
656 if(in_array($this->uid,$printer[$attribute2])){
657 $tmp = array_flip($attrs[$attribute2]);
658 unset($tmp[$this->uid]);
659 $attrs[$attribute2]=array_flip($tmp);
660 }
661 /* If Last entry removed, clear attribute*/
662 if(empty($attrs[$attribute2])){
663 $attrs[$attribute2]=array();
664 }
665 }
667 /* Attach user to the $attribute, if he is'nt already attached
668 */
669 if(!isset($attrs[$attribute])){
670 $attrs[$attribute]=array($this->uid);
671 }else{
672 unset($attrs[$attribute]['count']);
673 if(!in_array($this->uid,$attrs[$attribute])){
674 $attrs[$attribute][]=$this->uid;
675 }
676 }
678 $tmp =array();
679 if(isset($attrs['gotoAdminPrinter'])){
680 foreach($attrs['gotoAdminPrinter'] as $print){
681 $tmp[]=$print;
682 }
683 }
684 $attrs['gotoAdminPrinter'] = $tmp;
686 $tmp =array();
687 if(isset($attrs['gotoUserPrinter'])){
688 foreach($attrs['gotoUserPrinter'] as $print){
689 $tmp[]=$print;
690 }
691 }
692 $attrs['gotoUserPrinter'] = $tmp;
694 $ldap->cd($attrs['dn']);
695 unset($attrs['dn']);
696 $ldap->modify($attrs);
697 if($ldap->get_error()!="Success"){
698 print_red("Printer saving ".$ldap->get_error());
699 }
700 }
702 plugin::save();
704 if(isset($this->attrs['gotoPrinter'])){
705 unset($this->attrs['gotoPrinter']);
706 }
708 /* Prepare HotPlug devices */
709 $this->attrs['gotoHotplugDevice'] = array();
710 foreach($this->gotoHotplugDevices as $name => $device){
711 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
712 }
714 /* Prepare LogonScripts */
715 $this->attrs['gotoLogonScript'] = array();
716 foreach($this->gotoLogonScripts as $name => $script){
717 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
718 $script['LogonOverload'].$script['LogonLast']."|".
719 $script['LogonPriority']."|".
720 base64_encode($script['LogonData']);
721 }
723 /* Prepare Shares */
724 $this->attrs['gotoShare']=array();
725 foreach($this->gotoShares as $name => $share){
726 $this->attrs['gotoShare'][] = $share['name']."|".$share['mountPoint'];
727 }
729 if(!empty($this->gotoKioskProfile)){
730 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
731 }else{
732 $this->attrs['gotoKioskProfile']= array();
733 }
735 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
737 foreach($saveThis as $tosave){
738 if(!empty($this->$tosave)){
739 $this->attrs[$tosave]=$this->$tosave;
740 }else{
741 $this->attrs[$tosave]=array();
742 }
743 }
745 /* Prepare Flags */
746 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
747 if(empty($this->attrs['gotoProfileFlags'][0])){
748 $this->attrs['gotoProfileFlags']=array();
749 }
751 if($this->useProfile == false){
752 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
753 $this->attrs['gotoProfileServer']= array();
754 }
756 foreach($this->attributes as $s_attr){
757 if(chkacl($this->acl,$s_attr)!="") {
758 if(isset($this->attrs[$s_attr])){
759 unset($this->attrs[$s_attr]);
760 }
761 }
762 }
765 $ldap->cat ($this->dn);
766 if ($ldap->fetch()){
767 $mode= "modify";
768 } else {
769 $mode= "add";
770 $ldap->cd($this->config->current['BASE']);
771 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
772 }
774 $ldap->cd($this->dn);
775 $ldap->$mode($this->attrs);
776 if($ldap->get_error()!="Success"){
777 print_red($ldap->get_error());
778 }
779 $this->handle_post_events($mode);
780 }
782 /* This function returns all available Shares defined in this ldap
783 * There are two ways to call this function, if listboxEntry is true
784 * only name and path are attached to the array, in it is false, the whole
785 * entry will be parsed an atached to the result.
786 */
787 function getShareList($listboxEntry = false)
788 {
789 $ldap= $this->config->get_ldap_link();
790 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
791 $return= array();
792 while($entry = $ldap->fetch($a_res)){
793 $shareAttrs = split("\|",$entry['goExportEntry'][0]);
794 if($listboxEntry) {
795 $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[3];
796 }else{
797 $return[$shareAttrs[0]]['name'] = $shareAttrs[0];
798 $return[$shareAttrs[0]]['description'] = $shareAttrs[1];
799 $return[$shareAttrs[0]]['type'] = $shareAttrs[2];
800 $return[$shareAttrs[0]]['charset'] = $shareAttrs[3];
801 $return[$shareAttrs[0]]['path'] = $shareAttrs[4];
802 $return[$shareAttrs[0]]['option'] = $shareAttrs[5];
803 }
804 }
805 return($return);
806 }
809 /* Generate ListBox frindly output for the defined shares
810 * Possibly Add or remove an attribute here,
811 */
812 function printOutAssignedShares()
813 {
814 $a_return = array();
815 if(is_array($this->gotoShares)){
816 foreach($this->gotoShares as $share){
817 $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
818 }
819 }
820 return($a_return);
821 }
823 /* Generate ListBox frindly output for the definedhotplugs
824 * Possibly Add or remove an attribute here,
825 */
826 function printOutHotPlugDevices()
827 {
828 $a_return= array();
829 if(is_array($this->gotoHotplugDevices)){
830 foreach($this->gotoHotplugDevices as $key=>$device){
831 $a_return[$key] = $device['name']." - ".$device['id'];
832 }
833 }
834 return($a_return);
835 }
837 /* Generates ListBox frienly output of used printer devices
838 * Append ' - admin' if printer is used in admin mode
839 */
840 function printOutPrinterDevices()
841 {
842 $a_return = array();
843 if(is_array($this->gotoPrinters)){
844 foreach($this->gotoPrinters as $printer){
845 if($printer['mode'] == "admin"){
846 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
847 }else{
848 $a_return[$printer['cn'][0]]= $printer['cn'][0];
849 }
850 }
851 }
852 return($a_return);
853 }
855 /* Generates ListBox frienly output of used logonscripts
856 */
857 function printOutLogonScripts()
858 {
859 $a_return = array();
860 if(is_array($this->gotoLogonScripts)){
861 foreach($this->gotoLogonScripts as $script){
862 $a_return[$script['LogonName']]= $script['LogonName'];
863 }
864 }
865 return($a_return);
866 }
867 }
872 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
873 ?>