d3e8a69c121b397f1aa56ea23a7779cc30f175c1
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
50 VAR $newKioskProfiles = array();
52 /* Hotplug Devices */
53 var $gotoHotplugDevice = ""; // Selected hotplug
54 var $gotoHotplugDevices = array();// Already configured hotplug devices
57 /* general settings */
58 // Sets the attributes which will kept on page reload, which will be saved, ...
59 var $attributes = array("uid","useProfile","gotoProfileServer","gotoProfileServers","gotoProfileFlags","gotoProfileFlag_C",
60 "gotoXResolution","gotoXResolutions","gotoProfileFlag_L","gotoProfileQuota",
61 "gotoLogonScripts","gotoLogonScript",
62 "gotoPrinters","gotoPrinter",
63 "gotoShares","gotoShare","gotoShareSelections",
64 "gotoKioskProfile","gotoKioskProfiles",
65 "gotoHotplugDevice","gotoHotplugDevices");
66 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
68 function environment ($config, $dn= NULL)
69 {
70 plugin::plugin ($config, $dn);
72 /* Get all Printer assignments */
73 $ldap = $this->config->get_ldap_link();
74 $ldap->cd($this->config->current['BASE']);
75 $ldap->search("(&(objectClass=gotoPrinter)(gotoUserPrinter=".$this->uid."))",array("*"));
76 while($printer = $ldap->fetch()){
77 $this->gotoPrinters[$printer['cn'][0]]=$printer;
78 $this->gotoPrinters[$printer['cn'][0]]['mode']="user";
79 }
80 $ldap->search("(&(objectClass=gotoPrinter)(gotoAdminPrinter=".$this->uid."))",array("*"));
81 while($printer = $ldap->fetch()){
82 $this->gotoPrinters[$printer['cn'][0]]=$printer;
83 $this->gotoPrinters[$printer['cn'][0]]['mode']="admin";
84 }
86 /* prepare hotplugs */
87 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
88 unset($this->attrs['gotoHotplugDevice']['count']);
89 foreach($this->attrs['gotoHotplugDevice'] as $device){
90 $tmp = $tmp2 = array();
91 $tmp = split("\|",$device);
92 $tmp2['name'] = $tmp[0];
93 $tmp2['description'] = $tmp[1];
94 $tmp2['id'] = $tmp[2];
95 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
96 }
97 }
99 /* prepare LogonScripts */
100 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
101 unset($this->attrs['gotoLogonScript']['count']);
102 foreach($this->attrs['gotoLogonScript'] as $device){
103 $tmp = $tmp2 = array();
104 $tmp = split("\|",$device);
105 $tmp2['LogonName'] = $tmp[0];
106 $tmp2['LogonPriority'] = $tmp[2];
107 if(preg_match("/O/i",$tmp[1])){
108 $tmp2['LogonOverload'] = "O";
109 }else{
110 $tmp2['LogonOverload'] = "";
111 }
112 if(preg_match("/L/i",$tmp[1])){
113 $tmp2['LogonLast'] = "L";
114 }else{
115 $tmp2['LogonLast'] = "";
116 }
117 $tmp2['LogonData'] = base64_decode($tmp[3]);
118 $tmp2['LogonDescription'] = $tmp[4];
119 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
120 }
121 }
123 /* Prepare Shares */
124 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
125 unset($this->attrs['gotoShare']['count']);
126 foreach($this->attrs['gotoShare'] as $share){
127 $tmp = $tmp2 = array();
128 $tmp = split("\|",$share);
129 $tmp2['name'] =$tmp[0];
130 $tmp2['mountPoint']=$tmp[1];
131 $this->gotoShares[$tmp[0]]=$tmp2;
132 }
133 }
135 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
136 $chr = $this->gotoProfileFlags[$i];
137 $name = "gotoProfileFlag_".$chr;
138 $this->$name=$chr;
139 }
141 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
142 $this->useProfile = true;
143 }else{
144 $this->useProfile = false;
145 }
147 }
149 function execute()
150 {
151 /* Fill templating stuff */
152 $smarty= get_smarty();
153 $display= "";
154 /* Is accout enabled | are we editing from usermenu or admin menu
155 All these tab management is done here
156 */
158 // 1. Account disabled . Editing from usermenu
159 if((!isset($this->parent))&&(!$this->is_account)){
160 /* We are currently editing this tab from usermenu, but this account is not enabled */
161 $smarty->assign("is_account",$this->is_account);
162 /* Load template */
163 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
164 /* Avoid the "You are currently editing ...." message when you leave this tab */
165 $display .= back_to_main();
166 /* Display our message to the user */
167 return $display;
169 // Account is enabled
170 }else{
171 /* Tell smarty that this accoutn is enabled */
172 $smarty->assign("is_account","true");
174 /* Do we need to flip is_account state? */
175 if (isset($_POST['modify_state'])){
176 $this->is_account= !$this->is_account;
177 }
178 if(!isset($this->parent)){
179 // 3. ? Account Enabled . Editing from usermenu
181 }else{
182 // 3. Account enabled . Editing from adminmenu
183 if ($this->is_account){
184 $display= $this->show_header(_("Remove environment extension"),
185 _("This server has environment extension enabled. You can disable it by clicking below."));
186 } else {
187 if((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)){
188 // 4. There is a PosixAccount
189 $display= $this->show_header(_("Add environment extension"),
190 _("This server has environment extension disabled. You can enable it by clicking below."));
191 return $display;
192 }else{
193 // 4. There is a PosixAccount
194 $display= $this->show_header(_("Add environment extension"),
195 _("This server has environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
196 return $display;
197 }
198 }
199 }
200 }
201 /* Account is Account : is_accounbt=true.
202 * Else we won't reach this.
203 */
205 /* Prepare all variables for smarty */
206 foreach($this->attributes as $s_attr){
207 /* Set value*/
208 $smarty->assign($s_attr,$this->$s_attr);
210 /* Set checkbox state*/
211 if(empty($this->$s_attr)){
212 $smarty->assign($s_attr."CHK","");
213 }else{
214 $smarty->assign($s_attr."CHK"," checked ");
215 }
217 /* Prepare ACL settings*/
218 if(chkacl($this->acl,$s_attr)=="") {
219 $smarty->assign($s_attr."ACL","");
220 }else{
221 $smarty->assign($s_attr."ACL"," disabled ");
222 }
224 }
226 if($this->acl != "#none#"){
227 $smarty->assign("useProfileACL","");
228 }else{
229 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
230 $smarty->assign("gotoProfileServer"," disabled ");
231 }
233 /* HANDLE Profile Settings here
234 * Assign available Quota and resolution settings
235 * Get all available profile server
236 * Get cache checkbox
237 * Assign this all to Smarty
238 */
240 if(empty($this->useProfile)){
241 $smarty->assign("gotoProfileACL","disabled");
242 $smarty->assign("useProfileCHK","");
243 }else{
244 $smarty->assign("gotoProfileACL","");
245 $smarty->assign("useProfileCHK"," checked ");
246 }
248 $this->gotoXResolutions = array("640x480","800x600","1024x768","1280x768","1280x1024");
249 $this->gotoProfileServers =$this->getShareServerList() ;
251 $smarty->assign("gotoXResolutions",$this->gotoXResolutions);
252 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
253 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
255 /* Handle kiosk profiles
256 * Read available from filesystem
257 * Open management if post is transmitted
258 */
260 /* Open Management Dialog */
261 if(isset($_POST['KioskManagementDialog'])){
262 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
263 $this->is_dialog = true;
264 }
266 /* Save */
267 if(isset($_POST['KioskClose'])){
268 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
270 unset($this->dialog);
271 $this->dialog=NULL;
272 $this->is_dialog = false;
273 }
274 $tmp = new kioskManagementDialog($this->config,$this->dn);
275 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
277 $smarty->assign("gotoKioskProfiles",$list);
278 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
280 /* Logonscript Management
281 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
282 * Perform add Delete edit Posts
283 */
285 /* Dialog Save */
286 if(isset($_POST['LogonSave'])){
287 $this->dialog->save_object();
288 if(count($this->dialog->check())!=0){
289 foreach($this->dialog->check() as $msg){
290 print_red($msg);
291 }
292 }else{
293 $tmp = $this->dialog->save();
294 unset($this->dialog);
295 $this->dialog=NULL;
296 $this->is_dialog=false;
297 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
298 }
299 }
301 /* Dialog Quit without saving */
302 if(isset($_POST['LogonCancel'])){
303 $this->is_dialog= false;
304 unset($this->dialog);
305 $this->dialog= NULL;
306 }
308 /* Check Edit Del New Posts for a selected LogonScript */
309 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
311 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
312 * In this case we create a new Logon Script.
313 */
314 if(isset($_POST['gotoLogonScriptNew'])){
315 $this->is_dialog = true;
316 $this->dialog = new logonManagementDialog($this->config,$this->dn);
317 }
319 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
320 * We only can delete if there is an entry selected.
321 */
322 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
323 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
324 }
326 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
327 * There must be an entry selected to perform edit request.
328 */
329 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
330 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
331 $this->is_dialog = true;
332 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
333 }
334 }
336 /* Append List to smarty*/
337 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
338 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
340 /* In this section server shares will be defined
341 * A user can select one of the given shares and a mount point
342 * and attach this combination to his setup.
343 */
345 $this->gotoShareSelections = $this->getShareList(true);
346 $this->gotoAvailableShares = $this->getShareList(false);
348 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
349 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
351 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
352 * This entry will be, a combination of mountPoint and sharedefinitions
353 */
354 if(isset($_POST['gotoShareAdd'])){
355 /* We assign a share to this user, if we don't know where to mount the share */
356 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))){
357 print_red("You must specify a valid mount point.");
358 }else{
359 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
360 $s_mount = $_POST['gotoShareMountPoint'];
362 /* Preparing the new assignment */
363 $this->gotoShares[$a_share['name']]=$a_share;
364 $this->gotoShares[$a_share['name']]['mountPoint']=$s_mount;
365 }
366 }
368 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
369 * If there is no defined share selected, we will abort the deletion without any message
370 */
371 if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
372 unset($this->gotoShares[$_POST['gotoShare']]);
373 }
375 $smarty->assign("gotoShares",$this->printOutAssignedShares());
376 $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
378 /* Hotplug devices will be handled here
379 * There are 3 possible methods for this feature
380 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
381 * Delete will erase an entry, the entry must be selcted in the ListBox first
382 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
383 */
385 /* If there is a new entry wanted, open a new entry by initilising the dialog */
386 if(isset($_POST['gotoHotplugDeviceNew'])){
387 $this->dialog = new hotplugDialog($this->config,$this->dn);
388 $this->is_dialog = true;
389 }
391 /* We have to delete the selected hotplug from the list*/
392 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
393 unset($this->gotoHotplugDevices[$_POST['gotoHotplugDevice']]);
394 }
396 /* There are already defined hotplugs from other users we could use */
397 if(isset($_POST['gotoHotplugDeviceUse'])){
398 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
399 $this->is_dialog = true;
400 }
402 /* Dialog Aborted */
403 if(isset($_POST['HotPlugCancel'])){
404 unset($this->dialog);
405 $this->dialog= NULL;
406 $this->is_dialog = false;
407 }
409 /* Dialod saved */
410 if(isset($_POST['HotPlugSave'])){
411 $this->dialog->save_object();
412 if(count($this->dialog->check())!=0){
413 foreach($this->dialog->check() as $msg){
414 print_red($msg);
415 }
416 }else{
417 $this->dialog->save_object();
418 $a_tmp = $this->dialog->save();
419 if(is_array($a_tmp)){
420 $this->gotoHotplugDevices[$a_tmp['name']]= $a_tmp;
421 }
422 unset($this->dialog);
423 $this->dialog= NULL;
424 $this->is_dialog = false;
425 }
426 }
428 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
429 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
431 /* Printer Assignment will managed below
432 * A printer can be assigned in two different ways and two different types
433 * There are 2 types of users assigned to a printer : user and admin
434 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
435 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
436 */
438 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
439 if(isset($_POST['gotoPrinterAdd'])){
440 $this->is_dialog=true;
441 $this->dialog = new selectPrinterDialog($this->config,$this->dn);
442 }
444 if(isset($_POST['PrinterCancel'])){
445 $this->is_dialog=false;
446 unset($this->dialog);
447 $this->dialog=NULL;
448 }
450 if(isset($_POST['PrinterSave'])){
451 if(count($this->dialog->check())!=0){
452 $tmp = $this->dialog->check();
453 foreach($tmp as $msg){
454 print_red($msg);
455 }
456 }else{
457 $this->dialog->save_object();
458 $tmp = $this->dialog->save();
459 $tmp2= $this->dialog->getPrinter(true);
460 $this->gotoPrinters[$tmp]=$tmp2[$tmp];
461 $this->gotoPrinters[$tmp]['mode']="user";
462 $this->is_dialog=false;
463 unset($this->dialog);
464 $this->dialog =NULL;
465 }
466 }
468 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
469 $printer = $_POST['gotoPrinter'];
470 unset($this->gotoPrinters[$printer]);
471 }
473 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinter']))&&(!empty($_POST['gotoPrinter']))){
474 $printer = $_POST['gotoPrinter'];
475 if($this->gotoPrinters[$printer]['mode']=="user"){
476 $this->gotoPrinters[$printer]['mode']="admin";
477 }else{
478 $this->gotoPrinters[$printer]['mode']="user";
479 }
480 }
482 $smarty->assign("gotoPrinters",$this->printOutPrinterDevices());
483 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
485 /* General behavior */
486 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
487 $this->dialog->save_object();
488 return ($this->dialog->execute());
489 }
490 if($this->acl != "#none#"){
491 $smarty->assign("useProfileACL","");
492 }else{
493 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
494 $smarty->assign("gotoProfileServerACL"," disabled ");
495 }
497 if(!$this->useProfile){
498 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
499 $smarty->assign("gotoProfileServerACL"," disabled ");
500 }
502 /* Als smarty vars are set. Get smarty template and generate output */
503 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
505 return($display);
506 }
508 function remove_from_parent()
509 {
510 /* only if it was an account*/
511 if (!$this->initially_was_account){
512 return;
513 }
515 /* include global link_info */
516 $ldap= $this->config->get_ldap_link();
518 /* Remove and write to LDAP */
519 plugin::remove_from_parent();
521 /* Don't save our template variables */
522 $skip = array("useProfile","uid","gotoProfileServers","gotoProfileFlag_C","gotoXResolutions","gotoProfileFlag_L",
523 "gotoLogonScripts","gotoPrinters","gotoShares","gotoShareSelections","gotoKioskProfiles","gotoHotplugDevices",
524 "gotoPrinter");
525 /* Skip all these attributes */
526 foreach($skip as $del){
527 unset($this->attrs[$del]);
528 }
530 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
532 $ldap->cd($this->dn);
533 $ldap->modify($this->attrs);
535 show_ldap_error($ldap->get_error());
537 /* Optionally execute a command after we're done */
538 $this->handle_post_events("remove");
539 }
542 /* Save data to object */
543 function save_object()
544 {
545 /* Get all Posted vars
546 * Setup checkboxes
547 */
549 if(isset($_POST['iamposted'])){
550 plugin::save_object();
551 foreach($this->attributes as $s_attr){
552 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinters","gotoLogonScripts","uid"))) continue;
553 if(isset($_POST[$s_attr])){
554 $this->$s_attr = $_POST[$s_attr];
555 }else{
556 $this->$s_attr = false;
557 }
558 }
559 }
560 }
563 /* Check supplied data */
564 function check()
565 {
566 $message= array();
568 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
569 $message[]=_("Please set a valid profile quota size.");
570 }
572 return ($message);
573 }
576 /* Save to LDAP */
577 function save()
578 {
579 plugin::save();
580 $ldap= $this->config->get_ldap_link();
582 $realyUsedAttrs= array();
585 $path = search_config($this->config->data['MENU'],"environment", "KIOSKPATH");
586 /* Creating Kiosk Profiles */
587 foreach($this->newKioskProfiles as $file){
588 $contents = $file['contents'];
589 $fp = @fopen($path."/".$file['name'],"w");
590 if(!$fp){
591 print_red("Can't save new kiosk profiles, possibly permission denied for folder :",$path);
592 }else{
593 fwrite($fp,$contents,strlen($contents));
594 }
595 @unlink($file['tmp_name']);
596 }
603 /* Save already used objectClasses */
604 $ocs = $this->attrs['objectClass'];
605 unset($ocs['count']);
606 $this->attrs = array();
607 $this->attrs['objectClass']= $ocs;
608 foreach($this->objectclasses as $objc){
609 if(!in_array($objc,$this->attrs['objectClass'])){
610 $this->attrs['objectClass'][]=$objc;
611 }
612 }
615 /* Save usersettings to Printer */
617 if(chkacl($this->acl,"gotoPrinter")!=""){
618 $this->gotoPrinters = array();
619 }
621 if(count($this->gotoPrinters)==0){
622 $ldap->search("(&(objectClass=gotoPrinter)(|(gotoUserPrinter=".$this->uid.")(gotoAdminPrinter=".$this->uid.")))",array("*"));
623 while($attr = $ldap->fetch()){
625 foreach($attr['gotoUserPrinter'] as $key => $user){
626 if($this->uid==$user){
627 unset($attr['gotoUserPrinter'][$key]);
628 }
629 }
631 foreach($attr['gotoAdminPrinter'] as $key => $user){
632 if($this->uid==$user){
633 unset($attr['gotoAdminPrinter'][$key]);
634 }
635 }
637 $attrs_used = array();
638 foreach($attr as $key=>$val){
639 if((!is_numeric($key))&&($key!="count")){
640 if(is_array($val)&&isset($val['count'])){
641 unset($val['count']);
642 }
643 $attrs_used[$key]=$val;
644 }
645 }
646 $attr= $attrs_used;
647 $tmp =array();
648 foreach($attr['gotoAdminPrinter'] as $print){
649 $tmp[]=$print;
650 }
651 $attr['gotoAdminPrinter'] = $tmp;
653 $tmp =array();
654 foreach($attr['gotoUserPrinter'] as $print){
655 $tmp[]=$print;
656 }
657 $attr['gotoUserPrinter'] = $tmp;
659 $ldap->cd($attr['dn']);
660 unset($attr['dn']);
661 $ldap->modify($attr);
662 if($ldap->get_error()!="Success"){
663 print_red("Printer saving ".$ldap->get_error());
664 }
665 }
666 }
668 foreach($this->gotoPrinters as $printer) {
669 $ldap->cd($printer['dn']);
670 $ldap->cat($printer['dn']);
671 $attrs= $ldap->fetch();
672 $attrs_used = array();
673 foreach($attrs as $key=>$val){
674 if((!is_numeric($key))&&($key!="count")){
675 if(is_array($val)&&isset($val['count'])){
676 unset($val['count']);
677 }
678 $attrs_used[$key]=$val;
679 }
680 }
681 $attrs= $attrs_used;
683 /* Filter entries */
685 if($printer['mode'] == "user"){
686 $attribute = "gotoUserPrinter";
687 $attribute2 = "gotoAdminPrinter";
688 }else{
689 $attribute = "gotoAdminPrinter";
690 $attribute2 = "gotoUserPrinter";
691 }
693 /* If this user is already assigned to $attribute2
694 * delete user from $attribute2, to be albe to attach him to $attribute
695 * A user can't be admin and normal user for one printer
696 */
697 if(!isset($printer[$attribute2])){
698 $printer[$attribute2]=array();
699 }else{
700 if(in_array($this->uid,$printer[$attribute2])){
701 $tmp = array_flip($attrs[$attribute2]);
702 unset($tmp[$this->uid]);
703 $attrs[$attribute2]=array_flip($tmp);
704 }
705 /* If Last entry removed, clear attribute*/
706 if(empty($attrs[$attribute2])){
707 $attrs[$attribute2]=array();
708 }
709 }
711 /* Attach user to the $attribute, if he is'nt already attached
712 */
713 if(!isset($attrs[$attribute])){
714 $attrs[$attribute]=array($this->uid);
715 }else{
716 unset($attrs[$attribute]['count']);
717 if(!in_array($this->uid,$attrs[$attribute])){
718 $attrs[$attribute][]=$this->uid;
719 }
720 }
722 $tmp =array();
723 if(isset($attrs['gotoAdminPrinter'])){
724 foreach($attrs['gotoAdminPrinter'] as $print){
725 $tmp[]=$print;
726 }
727 }
728 $attrs['gotoAdminPrinter'] = $tmp;
730 $tmp =array();
731 if(isset($attrs['gotoUserPrinter'])){
732 foreach($attrs['gotoUserPrinter'] as $print){
733 $tmp[]=$print;
734 }
735 }
736 $attrs['gotoUserPrinter'] = $tmp;
738 $ldap->cd($attrs['dn']);
739 unset($attrs['dn']);
740 $ldap->modify($attrs);
741 if($ldap->get_error()!="Success"){
742 print_red("Printer saving ".$ldap->get_error());
743 }
744 }
746 if(isset($this->attrs['gotoPrinter'])){
747 unset($this->attrs['gotoPrinter']);
748 }
750 /* Prepare HotPlug devices */
751 $this->attrs['gotoHotplugDevice'] = array();
752 foreach($this->gotoHotplugDevices as $name => $device){
753 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
754 }
756 /* Prepare LogonScripts */
757 $this->attrs['gotoLogonScript'] = array();
758 foreach($this->gotoLogonScripts as $name => $script){
759 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
760 $script['LogonOverload'].$script['LogonLast']."|".
761 $script['LogonPriority']."|".
762 base64_encode($script['LogonData'])."|".
763 $script['LogonDescription'];
764 }
766 /* Prepare Shares */
767 $this->attrs['gotoShare']=array();
768 foreach($this->gotoShares as $name => $share){
769 $this->attrs['gotoShare'][] = $share['name']."|".$share['mountPoint'];
770 }
772 if(!empty($this->gotoKioskProfile)){
773 $this->attrs['gotoKioskProfile']= $this->gotoKioskProfile;
774 }else{
775 $this->attrs['gotoKioskProfile']= array();
776 }
778 $saveThis = array("gotoKioskProfile","gotoProfileQuota","gotoXResolution","gotoProfileServer");
780 foreach($saveThis as $tosave){
781 if(!empty($this->$tosave)){
782 $this->attrs[$tosave]=$this->$tosave;
783 }else{
784 $this->attrs[$tosave]=array();
785 }
786 }
788 /* Prepare Flags */
789 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
790 if(empty($this->attrs['gotoProfileFlags'][0])){
791 $this->attrs['gotoProfileFlags']=array();
792 }
794 if($this->useProfile == false){
795 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
796 $this->attrs['gotoProfileServer']= array();
797 }
799 foreach($this->attributes as $s_attr){
800 if(chkacl($this->acl,$s_attr)!="") {
801 if(isset($this->attrs[$s_attr])){
802 unset($this->attrs[$s_attr]);
803 }
804 }
805 }
807 $ldap->cat ($this->dn);
808 if ($ldap->fetch()){
809 $mode= "modify";
810 } else {
811 $mode= "add";
812 $ldap->cd($this->config->current['BASE']);
813 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
814 }
816 $ldap->cd($this->dn);
817 $ldap->$mode($this->attrs);
818 if($ldap->get_error()!="Success"){
819 print_red($ldap->get_error());
820 }
821 $this->handle_post_events($mode);
822 }
824 /* This function returns all available Shares defined in this ldap
825 * There are two ways to call this function, if listboxEntry is true
826 * only name and path are attached to the array, in it is false, the whole
827 * entry will be parsed an atached to the result.
828 */
829 function getShareList($listboxEntry = false)
830 {
831 $ldap= $this->config->get_ldap_link();
832 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry"));
833 $return= array();
834 while($entry = $ldap->fetch($a_res)){
835 unset($entry['goExportEntry']['count']);
836 foreach($entry['goExportEntry'] as $export){
837 $shareAttrs = split("\|",$export);
838 if($listboxEntry) {
839 $return[$shareAttrs[0]] = $shareAttrs[0]." - ".$shareAttrs[4];
840 }else{
841 $return[$shareAttrs[0]]['name'] = $shareAttrs[0];
842 $return[$shareAttrs[0]]['description'] = $shareAttrs[1];
843 $return[$shareAttrs[0]]['type'] = $shareAttrs[2];
844 $return[$shareAttrs[0]]['charset'] = $shareAttrs[3];
845 $return[$shareAttrs[0]]['path'] = $shareAttrs[4];
846 $return[$shareAttrs[0]]['option'] = $shareAttrs[5];
847 }
848 }
849 }
850 return($return);
851 }
854 /* This function returns all available ShareServer
855 */
856 function getShareServerList()
857 {
858 $ldap= $this->config->get_ldap_link();
859 $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
860 $return= array();
861 while($entry = $ldap->fetch($a_res)){
862 $return[$entry['cn'][0]] = $entry['cn'][0];
863 }
864 return($return);
865 }
867 /* Generate ListBox frindly output for the defined shares
868 * Possibly Add or remove an attribute here,
869 */
870 function printOutAssignedShares()
871 {
872 $a_return = array();
873 if(is_array($this->gotoShares)){
874 foreach($this->gotoShares as $share){
875 $a_return[$share['name']]= $share['name']." ".$share['mountPoint'];
876 }
877 }
878 return($a_return);
879 }
881 /* Generate ListBox frindly output for the definedhotplugs
882 * Possibly Add or remove an attribute here,
883 */
884 function printOutHotPlugDevices()
885 {
886 $a_return= array();
887 if(is_array($this->gotoHotplugDevices)){
888 foreach($this->gotoHotplugDevices as $key=>$device){
889 $a_return[$key] = $device['name']." - ".$device['id'];
890 }
891 }
892 return($a_return);
893 }
895 /* Generates ListBox frienly output of used printer devices
896 * Append ' - admin' if printer is used in admin mode
897 */
898 function printOutPrinterDevices()
899 {
900 $a_return = array();
901 if(is_array($this->gotoPrinters)){
902 foreach($this->gotoPrinters as $printer){
903 if($printer['mode'] == "admin"){
904 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Admin");
905 }else{
906 $a_return[$printer['cn'][0]]= $printer['cn'][0];
907 }
908 }
909 }
910 return($a_return);
911 }
913 /* Generates ListBox frienly output of used logonscripts
914 */
915 function printOutLogonScripts()
916 {
917 $a_return = array();
918 if(is_array($this->gotoLogonScripts)){
919 foreach($this->gotoLogonScripts as $script){
920 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
921 }
922 }
923 return($a_return);
924 }
925 }
930 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
931 ?>