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;
20 var $view_logged = FALSE;
22 /* Attribute definition
23 */
25 /* profile management */
26 var $useProfile = false; // Specifies if we want to use a Server
27 var $gotoProfileServer = ""; // Specifies the selected profile server
28 var $gotoProfileServers = array();// Specifies all available and selectable servers
29 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
30 var $gotoProfileFlagC = ""; // Flag is set to C if we have the profile caching fucntion enabled
32 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
33 var $gotoXResolutions = array();// Contains all available resolutions for this account
34 var $gotoProfileFlagL = ""; // Flag is set to L to enable runtime resolution change
35 var $gotoProfileQuota = ""; // User Quota Settings
37 /* Logon script section*/
38 var $gotoLogonScripts = array();// Contains all available Logon Scripts
39 var $gotoLogonScript = ""; // The selected Logon Script
41 /* Printer */
42 var $gotoPrinter = array();// All available Printer, with their configurations
43 var $gotoPrinterSel = ""; // The selected Printer
44 var $gosaDefaultPrinter = ""; // Default printer
46 /* Share */
47 var $gotoShares = array();// Current Share Options
48 var $gotoShare = ""; // currently selected Share Option
49 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
50 var $gotoAvailableShares= array();// Available Shares for this account
52 /* Kiosk profile */
53 var $kiosk_enabled = FALSE;
54 var $gotoKioskProfile = ""; // The selected Kiosk Profile
55 var $gotoKioskProfile_Server = ""; // The selected Kiosk Profile
56 var $gotoKioskProfile_Profile = ""; // The selected Kiosk Profile
57 var $gotoKioskProfiles = array();// All available Kiosk profiles
59 /* Hotplug Devices */
60 var $gotoHotplugDevice = array(); // Selected hotplug
61 var $gotoHotplugDevices = array();// Already configured hotplug devices
62 var $gotoHotplugDeviceDN= array();
64 var $NewAddedPrinters = array();
65 var $NewDeletedPrinters = array();
67 /* general settings */
68 // Sets the attributes which will kept on page reload, which will be saved, ...
70 var $CopyPasteVars = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
72 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
73 "gotoXResolution","gotoProfileQuota",
74 "gotoLogonScripts","gotoLogonScript",
75 "gotoPrinter", "gosaDefaultPrinter",
76 "gotoShares","gotoShare",
77 "gotoKioskProfile");
78 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
79 var $cn;
80 var $OrigCn;
81 var $add_del_printer_member_was_called = false;
83 function environment (&$config, $dn= NULL)
84 {
85 plugin::plugin ($config, $dn);
87 /* Setting uid to default */
88 if(isset($this->attrs['uid'][0])){
89 $this->uid = $this->attrs['uid'][0];
90 }
92 /* Check : Are we currently editing a group or user dialog */
93 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
94 $suffix="Group";
95 $this->uid = $this->attrs['cn'][0];
96 $this->attrs['uid'] = $this->attrs['cn'][0];
97 $this->OrigCn = $this->attrs['cn'][0];
98 }else{
99 $suffix="User";
100 }
102 /* Get all Printer assignments */
103 $ldap = $this->config->get_ldap_link();
104 $ldap->cd($this->config->current['BASE']);
105 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
106 while($printer = $ldap->fetch()){
107 $this->gotoPrinter[$printer['cn'][0]]=$printer;
108 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
109 }
110 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
111 while($printer = $ldap->fetch()){
112 $this->gotoPrinter[$printer['cn'][0]]=$printer;
113 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
114 }
117 /* Prepare hotplugs */
118 if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
119 $ldap = $this->config->get_ldap_link();
120 $ldap->cd($this->config->current['BASE']);
121 for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
122 $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
123 if($ldap->count()){
124 $attrs = $ldap->fetch();
126 if(isset($attrs['gotoHotplugDevice'][0])){
127 $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
128 $tmp2 = array();
129 $tmp2['name'] = $attrs['cn'][0];
130 $tmp2['description'] = $tmp[0];
131 $tmp2['id'] = $tmp[1];
132 $tmp2['produkt'] = $tmp[2];
133 $tmp2['vendor'] = $tmp[3];
134 $tmp2['dn'] = $attrs['dn'];
135 $this->gotoHotplugDevices[] = $tmp2;
136 }
137 }else{
138 print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
139 }
140 }
141 }
144 /* prepare LogonScripts */
145 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
146 unset($this->attrs['gotoLogonScript']['count']);
147 foreach($this->attrs['gotoLogonScript'] as $device){
148 $tmp = $tmp2 = array();
149 $tmp = split("\|",$device);
150 $tmp2['LogonName'] = $tmp[0];
151 $tmp2['LogonPriority'] = $tmp[2];
152 if(preg_match("/O/i",$tmp[1])){
153 $tmp2['LogonOverload'] = "O";
154 }else{
155 $tmp2['LogonOverload'] = "";
156 }
157 if(preg_match("/L/i",$tmp[1])){
158 $tmp2['LogonLast'] = "L";
159 }else{
160 $tmp2['LogonLast'] = "";
161 }
162 $tmp2['LogonData'] = base64_decode($tmp[3]);
163 $tmp2['LogonDescription'] = $tmp[4];
164 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
165 }
166 }
168 /* Prepare Shares */
169 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
170 unset($this->attrs['gotoShare']['count']);
171 foreach($this->attrs['gotoShare'] as $share){
172 $tmp = $tmp2 = array();
173 $tmp = split("\|",$share);
174 $tmp2['server'] =$tmp[0];
175 $tmp2['name'] =$tmp[1];
177 /* Decode base64 if needed */
178 if (!preg_match('%/%', $tmp[2])){
179 $tmp2['mountPoint'] =base64_decode($tmp[2]);
180 } else {
181 $tmp2['mountPoint'] =$tmp[2];
182 }
184 if(isset($tmp[3])){
185 $tmp2['PwdHash'] =$tmp[3];
186 }else{
187 $tmp2['PwdHash'] ="";
188 }
189 if(isset($tmp[4])){
190 $tmp2['Username'] =$tmp[4];
191 }else{
192 $tmp2['Username'] ="";
193 }
194 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
195 }
196 }
198 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
199 $chr = $this->gotoProfileFlags[$i];
200 $name = "gotoProfileFlag".$chr;
201 $this->$name=$chr;
202 }
204 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
205 $this->useProfile = true;
206 }else{
207 $this->useProfile = false;
208 }
210 /* Set resolutions */
211 $this->gotoXResolutions = array("auto"=>_("auto"),
212 "640x480" => "640x480",
213 "800x600" => "800x600",
214 "1024x768" => "1024x768",
215 "1152x864" => "1152x864",
216 "1280x768" => "1280x768",
217 "1280x1024" => "1280x1024");
219 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
220 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
222 if(is_readable($file)){
223 $str = file_get_contents($file);
224 $lines = split("\n",$str);
225 foreach($lines as $line){
226 $line = trim($line);
227 if(!empty($line)){
228 $this->gotoXResolutions[$line]=$line;
229 }
230 }
231 //natcasesort($this->gotoXResolutions);
232 }else{
233 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
234 }
235 }
237 $this->gotoProfileServers= $config->getShareServerList() ;
238 $this->gotoShareSelections= $config->getShareList(true);
239 $this->gotoAvailableShares= $config->getShareList(false);
241 $this->update_kiosk_profiles();
243 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
244 }
247 function update_kiosk_profiles()
248 {
249 $tmp1 = array("none" => array(_("disabled")));
250 $tmp2 = array("none" => _("disabled"));
251 $ldap = $this->config->get_ldap_link();
252 $ldap->cd($this->config->current['BASE']);
253 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
254 $cnt = 0;
255 while($attrs = $ldap->fetch()){
256 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
257 $name = preg_replace("/^.*kiosk\//","",$attrs['gotoKioskProfile'][$i]);
258 $tmp1[$attrs['cn'][0]][] = $name;
259 }
260 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
261 $cnt ++;
262 }
264 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
265 $this->kiosk_enabled = TRUE;
266 }
268 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
269 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
271 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
272 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
274 $error = false;
275 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
276 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
277 $error = true;
278 }
279 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
280 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
281 $error = true;
282 }
283 if($error && !empty($this->gotoKioskProfile)){
284 print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
285 $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
286 }
287 }
290 /* Detect type of edited object (user|group)*/
291 function detect_grouptype()
292 {
293 if((!isset($this->parent))&&(!$this->is_account)){
294 $this->is_group = false;
295 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
296 $this->is_group = true;
297 }else{
298 $this->is_group = false;
299 }
300 }
303 function execute()
304 {
306 /* Call parent execute */
307 plugin::execute();
308 /* Log view */
309 if($this->is_account && !$this->view_logged){
310 $this->view_logged = TRUE;
311 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
312 new log("view","users/".get_class($this),$this->dn);
313 }else{
314 new log("view","groups/".get_class($this),$this->dn);
315 }
316 }
318 /* Are we editing from MyAccount and not editing a user */
319 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
321 /* Check profile server */
322 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
323 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
324 if(count($this->gotoProfileServers)){
326 /* Get First Profile */
327 $new = key($this->gotoProfileServers);
329 /* Another profile server found */
330 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
331 $this->gotoProfileServer,$new));
332 }else{
334 /* No other profile servers found */
335 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
336 $this->gotoProfileServer));
337 $this->gotoProfileServer = "";
338 }
339 }
340 }
342 $this->detect_grouptype();
344 /* Fill templating stuff */
345 $smarty= get_smarty();
346 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
347 $display= "";
349 $smarty->assign("is_group",$this->is_group);
351 /* Prepare all variables for smarty */
352 foreach($this->attributes as $s_attr){
353 /* Set value*/
354 $smarty->assign($s_attr,$this->$s_attr);
356 /* Set checkbox state*/
357 if(empty($this->$s_attr)){
358 $smarty->assign($s_attr."CHK","");
359 }else{
360 $smarty->assign($s_attr."CHK"," checked ");
361 }
363 /* Prepare ACL settings*/
364 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
365 }
367 /* Is accout enabled | are we editing from usermenu or admin menu
368 All these tab management is done here
369 */
372 /* Working from Usermenu an the Account is currently disbled
373 * this->parent : is only set if we are working in a list of tabs
374 * is_account : is only true if the needed objectClass is given
375 */
376 if((!isset($this->parent))&&(!$this->is_account)){
377 /* We are currently editing this tab from usermenu, but this account is not enabled */
378 $smarty->assign("is_account",$this->is_account);
379 /* Load template */
380 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
381 /* Avoid the "You are currently editing ...." message when you leave this tab */
382 $display .= back_to_main();
383 /* Display our message to the user */
384 return $display;
387 /* We are currently editing from group tabs, because
388 * $this->parent is set
389 * posixAccount is not set, so we are not in usertabs.
390 */
391 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
392 $smarty->assign("is_account","true");
393 $this->uid = $this->cn;
394 $this->attrs['uid'] = $this->cn;
396 /* Change state if needed */
397 if (isset($_POST['modify_state'])){
398 if(($this->acl_is_createable() && !$this->is_account) ||
399 ($this->acl_is_removeable() && $this->is_account)){
400 $this->is_account= !$this->is_account;
401 }
402 }
403 /* Group Dialog with enabled environment options */
404 if ($this->is_account){
405 $display= $this->show_enable_header(_("Remove environment extension"),
406 _("Environment extension enabled. You can disable it by clicking below."));
407 } else {
409 /* Environment is disabled
410 If theres is no posixAccount enabled, you won't be able to enable
411 environment extensions
412 */
413 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
414 // 4. There is a PosixAccount
415 $display= $this->show_enable_header(_("Add environment extension"),
416 _("Environment extension disabled. You can enable it by clicking below."));
417 return $display;
418 }else{
419 // 4. There is no PosixAccount
420 $display= $this->show_enable_header(_("Add environment extension"),
421 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
422 return $display;
423 }
424 }
425 }else{
426 /* Editing from Usermenu
427 * Tell smarty that this accoutn is enabled
428 */
429 $smarty->assign("is_account","true");
431 /* Change state if needed */
432 if (isset($_POST['modify_state'])){
433 if(($this->acl_is_createable() && !$this->is_account) ||
434 ($this->acl_is_removeable() && $this->is_account)){
435 $this->is_account= !$this->is_account;
436 }
437 }
439 if(isset($this->parent)){
441 // 3. Account enabled . Editing from adminmenu
442 if ($this->is_account){
443 $display= $this->show_disable_header(_("Remove environment extension"),
444 _("Environment extension enabled. You can disable it by clicking below."));
445 } else {
447 if($this->parent->by_object['posixAccount']->is_account==true){
448 // 4. There is a PosixAccount
449 $display= $this->show_disable_header(_("Add environment extension"),
450 _("Environment extension disabled. You can enable it by clicking below."));
451 return $display;
452 }else{
453 // 4. There is a PosixAccount
454 $display= $this->show_disable_header(_("Add environment extension"),
455 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
456 return $display;
457 }
458 }
459 }
460 }
461 /* Account is Account : is_accounbt=true.
462 * Else we won't reach this.
463 */
465 /* Prepare all variables for smarty */
466 foreach($this->attributes as $s_attr){
467 /* Set value*/
468 $smarty->assign($s_attr,$this->$s_attr);
470 /* Set checkbox state*/
471 if(empty($this->$s_attr)){
472 $smarty->assign($s_attr."CHK","");
473 }else{
474 $smarty->assign($s_attr."CHK"," checked ");
475 }
477 /* Prepare ACL settings*/
478 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
479 }
481 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
482 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
483 }
485 if($WriteOnly) {
486 $smarty->assign("gotoPrinterACL","r");
487 }else{
488 $smarty->assign("gotoPrinterACL","rw");
489 }
491 if(empty($this->useProfile)){
492 $smarty->assign("useProfileCHK","");
493 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
494 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
495 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
496 }else{
497 $smarty->assign("useProfileCHK"," checked ");
498 }
500 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
501 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
503 /* HANDLE Profile Settings here
504 * Assign available Quota and resolution settings
505 * Get all available profile server
506 * Get cache checkbox
507 * Assign this all to Smarty
508 */
510 if(empty($this->gotoProfileFlagL)){
511 $smarty->assign("gotoProfileFlagLCHK"," ");
512 }else{
513 $smarty->assign("gotoProfileFlagLCHK"," checked ");
514 }
516 if(empty($this->gotoProfileFlagC)){
517 $smarty->assign("gotoProfileFlagCCHK"," ");
518 }else{
519 $smarty->assign("gotoProfileFlagCCHK"," checked ");
520 }
523 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
524 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
526 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
527 if(!is_array($this->gotoProfileServers)){
528 $this->gotoProfileServers =array();
529 }
530 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
532 /* Handle kiosk profiles*/
533 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
534 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
535 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
536 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
539 /* Logonscript Management
540 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
541 * Perform add Delete edit Posts
542 */
544 /* Dialog Save */
545 if(isset($_POST['LogonSave'])){
547 if(!$this->acl_is_writeable("gotoLogonScript")){
548 print_red(_("You are not allowed to write Logon scripts."));
549 unset($this->dialog);
550 $this->dialog=FALSE;
551 $this->is_dialog=false;
552 }else{
553 $this->dialog->save_object();
554 if(count($this->dialog->check())!=0){
555 foreach($this->dialog->check() as $msg){
556 print_red($msg);
557 }
558 }else{
559 $tmp = $this->dialog->save();
560 unset($this->dialog);
561 $this->dialog=FALSE;
562 $this->is_dialog=false;
563 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
564 }
565 }
566 }
569 /* Dialog Quit without saving */
570 if(isset($_POST['LogonCancel'])){
571 $this->is_dialog= false;
572 unset($this->dialog);
573 $this->dialog= FALSE;
574 }
576 /* Check Edit Del New Posts for a selected LogonScript */
577 if($this->acl_is_writeable("gotoLogonScript") &&
578 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
580 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
581 * In this case we create a new Logon Script.
582 */
583 if(isset($_POST['gotoLogonScriptNew'])){
584 $this->is_dialog = true;
585 $this->dialog = new logonManagementDialog($this->config,$this->dn);
586 }
588 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
589 * We only can delete if there is an entry selected.
590 */
591 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
592 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
593 }
595 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
596 * There must be an entry selected to perform edit request.
597 */
598 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
599 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
600 $this->is_dialog = true;
601 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
602 }
603 }
605 /* Append List to smarty*/
606 $ls = $this->printOutLogonScripts();
607 $smarty->assign("gotoLogonScripts", $ls);
608 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
609 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
611 /* In this section server shares will be defined
612 * A user can select one of the given shares and a mount point
613 * and attach this combination to his setup.
614 */
616 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
617 if(!is_array($this->gotoShareSelections)){
618 print $this->gotoShareSelections;
619 $this->gotoShareSelections = array();
620 }
621 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
623 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
624 * This entry will be, a combination of mountPoint and sharedefinitions
625 */
626 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
628 /* We assign a share to this user, if we don't know where to mount the share */
629 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
630 print_red(_("You must select a valid share."));
631 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
632 print_red(_("You must specify a valid mount point."));
633 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
634 print_red(_("Spaces are not allowed in the mount path!"));
635 }elseif(!(
636 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
637 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
638 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
639 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
640 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
641 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
642 preg_match("/^%/",$_POST['gotoShareMountPoint'])
643 )
644 ){
645 print_red(_("You must specify a valid mount point."));
646 }else{
647 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
648 $s_mount = $_POST['gotoShareMountPoint'];
649 $s_user = $_POST['ShareUser'];
650 /* Preparing the new assignment */
651 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
652 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
653 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
654 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
655 }
656 }
658 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
659 * If there is no defined share selected, we will abort the deletion without any message
660 */
661 $once = true;
662 if($this->acl_is_writeable("gotoShare")){
663 foreach($_POST as $name => $value){
664 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
665 $once = false;
666 $key = preg_replace("/^gotoShareDel_/","",$name);
667 $key = preg_replace("/_+[xy]$/","",$key);
668 $key = base64_decode($key);
669 if(isset($this->gotoShares[$key])) {
670 unset($this->gotoShares[$key]);
671 }
673 /* Remove corresponding password entry, too. This is a workaround
674 to get rid of old-style entries. */
675 $key= preg_replace("/\|/", "|!", $key);
676 if(isset($this->gotoShares[$key])) {
677 unset($this->gotoShares[$key]);
678 }
679 }
680 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
681 $once = false;
682 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
683 $key = preg_replace("/_+[xy]$/","",$key);
684 $key = base64_decode($key);
685 $this->gotoShares[$key]['PwdHash'] = "";
686 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
687 unset($this->gotoShares[$key]);
688 }
689 }
690 }
691 }
692 $divlistShares = new divSelectBox("gotoShares");
693 $divlistShares->SetHeight(100);
696 $tmp = array();
697 if($this->acl_is_readable("gotoShares")){
698 $tmp = $this->printOutAssignedShares();
699 }
702 foreach($tmp as $key => $value){
703 $img = "";
705 /* Skip apssword only entries */
706 if( empty($this->gotoShares[$key]['server']) &&
707 empty($this->gotoShares[$key]['name']) &&
708 empty($this->gotoShares[$key]['mountPoint']) &&
709 empty($this->gotoShares[$key]['Username'])){
710 continue;
711 }
713 /* Check if entry starts with an ! */
714 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
716 /* If we are currently editing groups environment, skip those ! entries */
717 if($this->is_group) continue;
719 /* Create pwd reset images */
720 if($this->gotoShares[$key]['PwdHash'] != ""){
721 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
722 title='"._("Reset password hash")."'>";
723 }
724 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
725 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
726 }else{
728 /* Create pwd reset img && delete image */
729 if($this->gotoShares[$key]['PwdHash'] != ""){
730 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
731 title='"._("Reset password hash")."'>";
732 $img.= " ";
733 }
734 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
735 title='"._("Delete share entry")."'>";
736 $field1 = array("string" => $value);
737 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
738 }
739 $divlistShares->AddEntry(array($field1,$field2));
740 }
741 $smarty->assign("divlistShares",$divlistShares->DrawList());
743 /* Hotplug devices will be handled here
744 * There are 3 possible methods for this feature
745 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
746 * Delete will erase an entry, the entry must be selcted in the ListBox first
747 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
748 */
750 /* We have to delete the selected hotplug from the list*/
751 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
752 if($this->acl_is_writeable("gotoHotplugDevice")){
753 foreach($_POST['gotoHotplugDevice_post'] as $name){
754 unset($this->gotoHotplugDevices[$name]);
755 }
756 }
757 }
759 /* There are already defined hotplugs from other users we could use */
760 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
761 $tmp =array();
762 foreach($this->gotoHotplugDevices as $plugs){
763 $tmp[] = $plugs['name'];
764 }
765 $this->dialog = new hotplugDialog($this->config,$tmp);
766 $this->is_dialog = true;
767 }
769 /* Dialog Aborted */
770 if(isset($_POST['HotPlugCancel'])){
771 unset($this->dialog);
772 $this->dialog= FALSE;
773 $this->is_dialog = false;
774 }
776 /* Dialod saved */
777 if(isset($_POST['HotPlugSave'])){
779 $this->dialog->save_object();
780 if(count($this->dialog->check())!=0){
781 foreach($this->dialog->check() as $msg){
782 print_red($msg);
783 }
784 }else{
785 $this->dialog->save_object();
786 $a_tmp = $this->dialog->save();
788 if(is_array($a_tmp)){
789 foreach($a_tmp as $name => $hotplug){
790 $this->gotoHotplugDevices[$name]= $hotplug;
791 }
792 }
793 unset($this->dialog);
794 $this->dialog= FALSE;
795 $this->is_dialog = false;
796 }
797 }
798 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
799 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
801 /* Printer Assignment will managed below
802 * A printer can be assigned in two different ways and two different types
803 * There are 2 types of users assigned to a printer : user and admin
804 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
805 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
806 */
808 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
809 if(isset($_POST['gotoPrinterAdd'])){
811 $this->is_dialog=true;
812 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
813 }
815 if(isset($_POST['PrinterCancel'])){
816 $this->is_dialog=false;
817 unset($this->dialog);
818 $this->dialog=FALSE;
819 }
821 if(isset($_POST['PrinterSave'])){
822 if(count($this->dialog->check())!=0){
823 $tmp = $this->dialog->check();
824 foreach($tmp as $msg){
825 print_red($msg);
826 }
827 }else{
828 $this->dialog->save_object();
829 $tmp = $this->dialog->save();
830 $tmp2= $this->dialog->getPrinter(true);
832 foreach($tmp as $pname){
833 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
834 $printerObj->set_acl_base($tmp2[$pname]['dn']);
836 $type = false;
838 if($this->is_group){
839 if($this->dn == "new"){
840 $type = "AddGroup";
841 }elseif(isset($this->NewDeletedPrinters[$pname])){
842 $type = "AddGroup";
843 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
844 $type = "AddGroup";
845 }
846 }else{
847 if(isset($this->NewDeletedPrinters[$pname])){
848 $type = "AddUser";
849 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
850 $type = "AddUser";
851 }
852 }
854 if($type){
855 $this->gotoPrinter[$pname]=$tmp2[$pname];
856 $this->gotoPrinter[$pname]['mode']="user";
857 $this->add_del_printer_member_was_called = true;
859 $this->NewAddedPrinters[$pname] = $pname;
860 if(isset($this->NewDeletedPrinters[$pname])){
861 unset($this->NewDeletedPrinters[$pname]);
862 }
863 }
864 }
866 $this->is_dialog=false;
867 unset($this->dialog);
868 $this->dialog =FALSE;
869 }
870 }
872 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
873 $printer = $_POST['gotoPrinterSel'];
874 foreach($printer as $pname){
876 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
877 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
879 $type = false;
880 if($this->is_group){
881 if(isset($this->NewAddedPrinters[$pname])){
882 $type = "Group";
883 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
884 $type = "Group";
885 }
886 }else{
887 if(isset($this->NewAddedPrinters[$pname])){
888 $type = "User";
889 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
890 $type = "User";
891 }
892 }
893 if($type){
894 $this->add_del_printer_member_was_called = true;
895 unset($this->gotoPrinter[$pname]);
897 $this->NewDeletedPrinters[$pname] = $pname;
898 if(isset($this->NewAddedPrinters[$pname])){
899 UNSET($this->NewAddedPrinters[$pname]);
900 }
901 }
902 }
903 }
905 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
906 $printers = $_POST['gotoPrinterSel'];
907 $this->add_del_printer_member_was_called = true;
908 foreach($printers as $printer){
909 if($this->gotoPrinter[$printer]['mode']=="user"){
910 $this->gotoPrinter[$printer]['mode']="admin";
911 }else{
912 $this->gotoPrinter[$printer]['mode']="user";
913 }
914 }
915 }
917 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
918 if($this->is_group){
919 print_red(_("GOsa default printer flag is not allowed within groups."));
920 }else{
921 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
922 $this->gosaDefaultPrinter= "";
923 } else {
924 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
925 }
926 }
927 }
929 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
930 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
932 /* General behavior */
933 if(is_object($this->dialog)){
934 $this->dialog->save_object();
935 $disp =$this->dialog->execute();
936 return($disp);
937 }
939 /* Als smarty vars are set. Get smarty template and generate output */
940 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
941 return($display);
942 }
944 function remove_from_parent()
945 {
946 /* only if it was an account*/
947 if (!$this->initially_was_account){
948 return;
949 }
951 /* include global link_info */
952 $ldap= $this->config->get_ldap_link();
954 /* Remove and write to LDAP */
955 plugin::remove_from_parent();
957 /* Don't save our template variables */
958 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
960 /* Skip all these attributes */
961 foreach($skip as $del){
962 unset($this->attrs[$del]);
963 }
965 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
967 $ldap->cd($this->dn);
968 $this->cleanup();
969 $ldap->modify ($this->attrs);
971 if($this->is_group){
972 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
973 }else{
974 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
975 }
977 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
979 /* Optionally execute a command after we're done */
980 $this->handle_post_events("remove",array("uid" => $this->uid));
981 }
984 /* Save data to object */
985 function save_object()
986 {
987 /* Get all Posted vars
988 * Setup checkboxes
989 */
990 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
991 if(isset($_POST['iamposted'])){
993 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
995 if(isset($_POST['kiosk_server'])){
996 $tmp = $_POST['kiosk_server'];
997 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
998 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
999 }
1000 }
1001 if(isset($_POST['kiosk_profile'])){
1002 $tmp = $_POST['kiosk_profile'];
1003 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1004 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1005 }
1006 }
1008 if(preg_match("/w/",$PACL)){
1009 if(isset($_POST['useProfile'])){
1010 $this->useProfile = true;
1011 }else{
1012 $this->useProfile = false;
1013 }
1014 }
1016 if($this->acl_is_writeable("gotoProfileFlagC")){
1017 if(isset($_POST['gotoProfileFlagC'])){
1018 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1019 }else{
1020 $this->gotoProfileFlagC = false;
1021 }
1022 }
1024 if($this->acl_is_writeable("gotoProfileFlagL")){
1025 if(isset($_POST['gotoProfileFlagL'])){
1026 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1027 }else{
1028 $this->gotoProfileFlagL = false;
1029 }
1030 }
1032 plugin::save_object();
1033 foreach($this->attributes as $s_attr){
1034 if((!isset($_POST[$s_attr])) ||
1035 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1036 if(!$this->acl_is_writeable($s_attr)){
1037 continue;
1038 }else{
1039 if(isset($_POST[$s_attr])){
1040 $this->$s_attr = $_POST[$s_attr];
1041 }else{
1042 $this->$s_attr = false;
1043 }
1044 }
1045 }
1046 }
1047 }
1050 /* Check supplied data */
1051 function check()
1052 {
1053 /* Call common method to give check the hook */
1054 $message= plugin::check();
1056 $this->detect_grouptype();
1058 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1059 $message[]=_("Please set a valid profile quota size.");
1060 }
1061 if(!isset($this->attrs['objectClass'])){
1062 $this->attrs['objectClass']=array();
1063 }
1064 if(!$this->is_group){
1065 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1066 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
1067 }
1068 }
1069 return ($message);
1070 }
1073 /* Save to LDAP */
1074 function save()
1075 {
1076 /* If group was renamed, all printer settings get lost
1077 */
1078 /* only save changed variables ....*/
1079 if ($this->gotoKioskProfile_Server != "none"){
1080 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1081 $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1082 }else{
1083 $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1084 }
1085 $this->gotoKioskProfile= $method;
1086 }else{
1087 $this->gotoKioskProfile= array();
1088 }
1090 plugin::save();
1091 $ldap= $this->config->get_ldap_link();
1093 $realyUsedAttrs= array();
1095 /* Save already used objectClasses */
1096 $ocs = $this->attrs['objectClass'];
1097 unset($ocs['count']);
1098 $this->attrs = array();
1099 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1101 /* 1. Search all printers that have our uid/cn as member
1102 * 2. Delete this uid/cn from every single entry and save it again.
1103 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1104 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1105 */
1107 $this->detect_grouptype();
1109 if($this->add_del_printer_member_was_called){
1111 $types = array( "gotoUserPrinter" => "AddUser",
1112 "gotoGroupPrinter" => "AddGroup",
1113 "gotoUserAdminPrinter" => "AddAdminUser",
1114 "gotoGroupAdminPrinter" => "AddAdminGroup");
1116 if($this->is_group){
1117 $s_suffix = "Group";
1118 $useVar = "cn";
1119 }else{
1120 $useVar = "uid";
1121 $s_suffix = "User";
1122 }
1124 /* Remove old entries */
1125 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1126 while($attr = $ldap->fetch()){
1127 $printerObj = NULL;
1128 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1129 $printerObj->set_acl_base($attr['dn']);
1130 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1131 $printerObj->by_object['printgeneric']->save();
1132 }
1134 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1135 while($attr = $ldap->fetch()){
1136 $printerObj = NULL;
1137 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1138 $printerObj->set_acl_base($attr['dn']);
1139 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1140 $printerObj->by_object['printgeneric']->save();
1141 }
1143 foreach($this->gotoPrinter as $printer){
1144 $printerObj = NULL;
1145 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1146 $printerObj->set_acl_base($printer['dn']);
1149 if($printer['mode'] == "admin") {
1150 $attribute = "goto".$s_suffix."AdminPrinter";
1151 }else{
1152 $attribute = "goto".$s_suffix."Printer";
1153 }
1155 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1156 $printerObj->by_object['printgeneric']->save();
1157 }
1158 }
1160 /* Prepare HotPlug devices */
1161 $this->attrs['gotoHotplugDeviceDN'] = array();
1162 foreach($this->gotoHotplugDevices as $name => $device){
1163 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1164 }
1166 /* Prepare LogonScripts */
1167 $this->attrs['gotoLogonScript'] = array();
1168 foreach($this->gotoLogonScripts as $name => $script){
1169 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1170 $script['LogonOverload'].$script['LogonLast']."|".
1171 $script['LogonPriority']."|".
1172 base64_encode($script['LogonData'])."|".
1173 $script['LogonDescription'];
1174 }
1176 /* Prepare Shares */
1177 $this->attrs['gotoShare']=array();
1178 foreach($this->gotoShares as $name => $share){
1179 $mntp= $share['mountPoint'];
1180 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1181 $mntp= base64_encode($mntp);
1182 }
1183 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1184 }
1187 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1188 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1190 foreach($saveThis as $tosave){
1191 if(!empty($this->$tosave)){
1192 $this->attrs[$tosave]=$this->$tosave;
1193 }else{
1194 $this->attrs[$tosave]=array();
1195 }
1196 }
1198 /* Prepare Flags */
1199 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1200 if(empty($this->attrs['gotoProfileFlags'][0])){
1201 $this->attrs['gotoProfileFlags']=array();
1202 }
1204 if($this->useProfile == false){
1205 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1206 $this->attrs['gotoProfileServer']= array();
1207 }
1209 $ldap->cat ($this->dn, array('dn'));
1210 if ($ldap->fetch()){
1211 $mode= "modify";
1212 } else {
1213 $mode= "add";
1214 $ldap->cd($this->config->current['BASE']);
1215 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1216 }
1218 $ldap->cd($this->dn);
1219 $this->cleanup();
1220 $ldap->$mode($this->attrs);
1222 $cat = "users";
1223 if($this->is_group){
1224 $cat = "groups";
1225 }
1227 /* Log last action */
1228 if($this->initially_was_account){
1229 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1230 }else{
1231 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1232 }
1234 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1235 $this->handle_post_events($mode,array("uid"=>$this->uid));
1236 }
1238 /* Generate ListBox frindly output for the defined shares
1239 * Possibly Add or remove an attribute here,
1240 */
1241 function printOutAssignedShares()
1242 {
1243 $a_return = array();
1244 if(is_array($this->gotoShares)){
1245 foreach($this->gotoShares as $share){
1246 if(preg_match("/^!/",$share['server'])){
1247 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1248 }else{
1249 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1250 }
1251 }
1252 natcasesort($a_return);
1253 }
1254 return($a_return);
1255 }
1257 /* Generate ListBox frindly output for the definedhotplugs
1258 * Possibly Add or remove an attribute here,
1259 */
1260 function printOutHotPlugDevices()
1261 {
1262 $a_return= array();
1263 if(is_array($this->gotoHotplugDevices)){
1264 foreach($this->gotoHotplugDevices as $key=>$device){
1265 $a_return[$key] = $device['name']." - ".$device['id'];
1266 }
1267 }
1268 return($a_return);
1269 }
1271 /* Generates ListBox frienly output of used printer devices
1272 * Append ' - admin' if printer is used in admin mode
1273 */
1274 function printOutPrinterDevices()
1275 {
1276 $a_return = array();
1278 if($this->acl_is_readable("gotoPrinter")){
1280 if(is_array($this->gotoPrinter)){
1281 foreach($this->gotoPrinter as $printer){
1282 if($printer['mode'] == "admin"){
1283 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1284 }else{
1285 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1286 }
1287 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1288 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1289 }
1290 }
1291 }
1292 }
1293 return($a_return);
1294 }
1297 function PrepareForCopyPaste($source)
1298 {
1299 plugin::PrepareForCopyPaste($source);
1301 $class= get_class($this);
1302 $o_source = new $class($this->config,$source['dn']);
1303 foreach($this->CopyPasteVars as $attr){
1304 $this->$attr = $o_source->$attr;
1305 }
1306 }
1309 function saveCopyDialog()
1310 {
1311 if(isset($_POST['cn'])){
1312 $this->cn = $_POST['cn'];
1313 $this->uid = $_POST['cn'];
1314 }
1315 }
1318 /* Generates ListBox frienly output of used logonscripts
1319 */
1320 function printOutLogonScripts()
1321 {
1322 $a_return = array();
1323 if(is_array($this->gotoLogonScripts)){
1324 foreach($this->gotoLogonScripts as $script){
1325 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1326 }
1327 }
1328 return($a_return);
1329 }
1332 /* Return plugin informations for acl handling
1333 #FIXME these ACLs should work for groups too */
1334 static function plInfo()
1335 {
1336 return (array("plShortName" => _("Environment"),
1337 "plDescription" => _("Environment settings"), // Description
1338 "plSelfModify" => TRUE,
1339 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1340 "plPriority" => 3, // Position in tabs
1341 "plSection" => array("personal" => _("My account")),
1342 "plCategory" => array("users",
1343 "groups"),
1344 "plOptions" => array("resolution_hook" => array("type" => "string",
1345 "description" => _("Command to extend the list of possible screen resolutions"))),
1347 "plProvidedAcls" => array(
1349 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1350 "gotoProfileFlagC" => _("Cache profile localy") ,
1352 "gotoProfileQuota" => _("Profile quota") ,
1353 "gotoProfileServer" => _("Profile server") ,
1355 "gotoXResolution" => _("Resolution") ,
1356 "gotoKioskProfile" => _("Kiosk profile") ,
1358 "gosaDefaultPrinter" => _("Default printer") ,
1359 "gotoLogonScript" => _("Logon script") ,
1360 "gotoHotplugDevice" => _("Hotplug devices"),
1361 "gotoShare" => _("Shares"))
1362 ));
1363 }
1364 }
1366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1367 ?>