dd7cf2e30bf8b2035252c405160e13a04415fc24
1 <?php
3 class printgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage terminal base 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 /* Generic terminal attributes */
11 var $interfaces = array();
12 var $ignore_account = FALSE;
14 /* Needed values and lists */
15 var $base = "";
16 var $cn = "";
17 var $l = "";
18 var $description = "";
19 var $labeledURI = "";
20 var $gotoPrinterPPD = "";
21 var $orig_dn = "";
23 var $UserMember ="";
24 var $UserMembers =array();
25 var $UserMemberKeys =array();
27 var $AdminMember ="";
28 var $AdminMembers =array();
29 var $AdminMemberKeys =array();
31 var $PPDdialogToSave = NULL;
32 var $BelongsTo = "unknown"; // Specifies if this is a standalone printer, or belongs to a terminal / WS
34 var $member =array();
35 var $strings = "";
36 var $dialog =NULL;
38 var $netConfigDNS;
39 var $baseSelection = false;
40 var $macAddress = "";
42 /* attribute list for save action */
43 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
44 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
45 var $objectclasses = array("top", "gotoPrinter");
47 var $gotoUserAdminPrinter;
48 var $gotoGroupAdminPrinter ;
49 var $gotoGroupPrinter;
50 var $gotoUserPrinter ;
52 function printgeneric ($config, $dn= NULL,$parent = NULL)
53 {
54 $this->config = $config;
55 $this->dn = $dn;
57 /* If parent was posted(the tabs object) we can detect the printer type. */
58 if($parent){
59 $this->parent = $parent;
60 $this->getTypeOfPrinter();
61 }else{
62 $this->BelongsTo = "unknown";
63 return;
64 }
66 /* Update dn, to ensure storing as printer instead of WS / terminal */
67 if($this->BelongsTo == "Terminal"){
68 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
69 }
71 if($this->BelongsTo == "Workstation"){
72 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
73 }
75 $this->orig_dn = $this->dn;
77 /* Get printer settings, possibly dn has changed */
78 plugin::plugin ($config, $this->dn);
80 /* Get is_account initially_was_account status */
81 $this->getTypeOfPrinter(true);
83 /* set orig dn to new if object is new */
84 $ldap= $this->config->get_ldap_link();
85 $ldap->cat($this->dn, array('dn'));
86 if(!$ldap->count()){
87 $this->orig_dn = "new";
88 }
90 /* create dns object */
91 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
93 /* Set base */
94 if ($this->dn == "new"){
95 $ui= get_userinfo();
96 $this->base= dn2base($ui->dn);
97 $this->cn= "";
98 } else {
100 /* Set base and check if the extracted base exists */
101 if(preg_match("/ou=incoming,/",$this->dn)){
102 $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
103 }else{
104 $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
105 }
107 if(!isset($this->config->idepartments[$this->base])){
108 print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
109 $this->base = $_SESSION['CurrentMainBase'];
110 }
111 }
113 /* Extract selected ppd */
114 if(isset($this->gotoPrinterPPD)){
115 $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
116 }
118 /* Prepare different member types */
119 foreach(array("AddUser" =>"gotoUserPrinter",
120 "AddGroup" =>"gotoGroupPrinter",
121 "AddAdminUser" =>"gotoUserAdminPrinter",
122 "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
124 /* $this->members contains all members */
125 $this->member[$type]=array();
127 if (isset($this->attrs[$attr]['count'])) {
128 unset($this->attrs[$attr]['count']);
129 }
131 if(isset($this->attrs[$attr])){
132 foreach($this->attrs[$attr] as $mem){
133 if(preg_match("/Group/",$type)){
134 $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
135 $entry = $ldap->fetch();
136 $this->member[$type][$entry['cn'][0]]=$entry;
137 }else{
138 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
139 $entry = $ldap->fetch();
140 if(isset($entry['uid'])){
141 $this->member[$type][$entry['uid'][0]]=$entry;
142 }
143 }
144 }
145 }
146 }
147 }
150 /* Detect type of printer.
151 * Printer can be stand alone, belong to a workstation or belong to a terminal.
152 * We can detect the type printer type when comparing the tabs objects
153 */
154 function getTypeOfPrinter($UpdateAccountStatus = false)
155 {
156 /* Disable account as default
157 */
158 $this->is_account = $this->initially_was_account = false;
160 /* Detect type of printer via parent tabs.
161 */
162 if(isset($this->parent->by_object['workgeneric'])){
164 /* Exclude templates
165 */
166 $this->cn = $this->parent->by_object['workgeneric']->cn;
167 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
168 $this->BelongsTo = "WorkstationTemplate";
169 }else{
170 $this->BelongsTo = "Workstation";
171 }
172 }elseif(isset($this->parent->by_object['termgeneric'])){
174 /* Exclude templates
175 */
176 $this->cn = $this->parent->by_object['termgeneric']->cn;
177 if($this->parent->by_object['termgeneric']->cn == "default"){
178 $this->BelongsTo = "TerminalTemplate";
179 }else{
180 $this->BelongsTo = "Terminal";
181 }
182 }elseif(isset($this->parent->by_name['printgeneric'])){
183 $this->BelongsTo = "Printer";
184 }
186 if($UpdateAccountStatus){
188 /* Set is_account / was account
189 */
190 if($this->dn == "new"){
191 $this->initially_was_account = false;
192 }
194 /* If is printer it must be a true account.
195 */
196 if($this->BelongsTo == "Printer"){
197 $this->is_account = true;
198 }
200 /* Update dn, to ensure storing as printer instead of WS / terminal
201 */
202 if($this->BelongsTo == "Terminal"){
203 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
204 }
206 if($this->BelongsTo == "Workstation"){
207 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
208 }
210 /* Detect if this is a valid printer account;
211 */
212 //FIXME: do we need to do this? we've already everything we need in $this->attrs...
213 $ldap = $this->config->get_ldap_link();
214 $ldap->cat($this->dn, array('objectClass'));
216 if($ldap->count()){
217 $attrs = $ldap->fetch();
218 if(in_array("gotoPrinter",$attrs['objectClass'])){
219 $this->initially_was_account = true;
220 $this->is_account = true;
221 }else{
222 $this->is_account = false;
223 }
224 }
225 }
226 }
228 function execute()
229 {
230 /* Call parent execute */
231 plugin::execute();
233 /* If type of printer couldn't be detected (because of missing parent object in construction)
234 * hide this tab.
235 */
236 if($this->BelongsTo == "unknown"){
237 $display= $this->show_header(_("Add printer extension"),
238 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
239 return($display);
240 }
242 /* Templates can't have printer extensions
243 */
244 if($this->BelongsTo == "WorkstationTemplate"){
245 $display= $this->show_header(_("Add printer extension"),
246 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
247 return($display);
248 }
249 if($this->BelongsTo == "TerminalTemplate"){
250 $display= $this->show_header(_("Add printer extension"),
251 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
252 return($display);
253 }
255 /* Get cn from base object */
256 if($this->BelongsTo == "Workstation"){
257 $this->cn = $this->parent->by_object['workgeneric']->cn;
258 }
259 if($this->BelongsTo == "Terminal"){
260 $this->cn = $this->parent->by_object['termgeneric']->cn;
261 }
263 $smarty= get_smarty();
264 $display="";
266 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
267 if($this->BelongsTo == "Printer"){
268 $smarty->assign("StandAlone",true);
269 }else{
270 $smarty->assign("StandAlone",false);
271 }
273 /* Do we need to flip is_account state? */
274 if (isset($_POST['modify_state'])){
275 $this->is_modified = true;
276 $this->is_account= !$this->is_account;
277 }
279 /* Do we represent a valid printer? */
280 if (!$this->is_account && $this->parent == NULL){
281 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
282 _("This 'dn' has no printer features.")."</b>";
283 return($display);
284 }
286 /* If this is a WS / Terminal depending printer, display account state button */
287 if($this->BelongsTo != "Printer"){
288 if((empty($this->cn)) && ($this->dn != "new")){
289 $display= $this->show_header(_("Add printer extension"),
290 _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
291 $this->is_account= false;
292 return $display;
293 }
295 if (($this->is_account)){
296 if($this->BelongsTo=="Workstation"){
297 $display= $this->show_header(_("Remove printer extension"),
298 _("This workstation has printer extension enabled.You can disable it by clicking below."));
299 }elseif($this->BelongsTo=="Terminal"){
300 $display= $this->show_header(_("Remove printer extension"),
301 _("This terminal has printer extension enabled. You can disable it by clicking below."));
302 }
303 }else{
304 if($this->BelongsTo=="Workstation"){
305 $display= $this->show_header(_("Add printer extension"),
306 _("This workstation has printer extension disabled. You can enable it by clicking below."));
307 }elseif($this->BelongsTo=="Terminal"){
308 $display= $this->show_header(_("Add printer extension"),
309 _("This terminal has printer extension disabled. You can enable it by clicking below."));
310 }
311 return ($display);
312 }
313 }
315 /* Base select dialog */
316 $once = true;
317 foreach($_POST as $name => $value){
318 if(preg_match("/^chooseBase/",$name) && $once){
319 $once = false;
320 $this->dialog = new baseSelectDialog($this->config);
321 $this->dialog->setCurrentBase($this->base);
322 $this->baseSelection = true;
323 }
324 }
326 /* Dialog handling for base select dialog
327 * Check if base was selected, dialog aborted etc */
328 if(is_object($this->dialog)){
330 $this->dialog->save_object();
331 if($this->baseSelection){
332 if($this->dialog->isClosed()){
333 $this->dialog = false;
334 $this->baseSelection = false;
335 }elseif($this->dialog->isSelected()){
336 $this->base = $this->dialog->isSelected();
337 $this->dialog= false;
338 $this->baseSelection = false;
339 }else{
340 return($this->dialog->execute());
341 }
342 }
343 }
345 /* Fill templating stuff */
346 $smarty->assign("bases", $this->config->idepartments);
347 $smarty->assign("base_select", $this->base);
349 /* Assign attributes */
350 foreach ($this->attributes as $attr){
351 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
352 $smarty->assign("$attr", $this->$attr);
353 }
355 $smarty->assign("baseACL", chkacl($this->acl,"base"));
357 if(isset($_POST['AddUser'])){
358 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
359 }
360 if(isset($_POST['AddGroup'])){
361 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
362 }
363 if(isset($_POST['AddAdminUser'])){
364 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
365 }
366 if(isset($_POST['AddAdminGroup'])){
367 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
368 }
370 /* Display ppd configure/select dialog */
371 if(isset($_POST['EditDriver'])){
372 if($this->PPDdialogToSave){
373 $this->dialog = $this->PPDdialogToSave;
374 }else{
375 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
376 }
377 }
379 /* remove ppd */
380 if(isset($_POST['RemoveDriver'])){
381 $this->gotoPrinterPPD = array();
382 $this->PPDdialogToSave = NULL;
383 }
385 /* Close ppd dialog */
386 if(isset($_POST['ClosePPD'])){
387 unset($this->dialog);
388 $this->dialog=NULL;
389 }
391 /* Save selected ppd */
392 if(isset($_POST['SavePPD'])){
393 $this->dialog->save_object();
394 if(count($this->dialog->check())){
395 foreach($this->dialog->check() as $msg){
396 print_red($msg);
397 }
398 }else{
399 $this->gotoPrinterPPD = array();
400 $this->gotoPrinterPPD = $this->dialog->save();
401 $this->PPDdialogToSave = $this->dialog;
402 unset($this->dialog);
403 $this->dialog=NULL;
404 }
405 }
407 /* Member management, delete user / group / admin ..*/
408 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
409 foreach($_POST['UserMember'] as $mem){
410 $this->DelMember('AddUser',$mem);
411 }
412 }
414 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
415 foreach($_POST['UserMember'] as $mem){
416 $this->DelMember('AddGroup',$mem);
417 }
418 }
420 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
421 foreach($_POST['AdminMember'] as $mem){
422 $this->DelMember('AddAdminUser',$mem);
423 }
424 }
426 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
427 foreach($_POST['AdminMember'] as $mem){
428 $this->DelMember('AddAdminGroup',$mem);
429 }
430 }
432 /* Abort user / group adding dialog */
433 if(isset($_POST['PrinterCancel'])){
434 unset($this->dialog);
435 $this->dialog= NULL;
436 }
438 /* Save selected users / groups */
439 if(isset($_POST['PrinterSave'])){
440 $this->dialog->save_object();
441 if(count($this->dialog->check())){
442 foreach($this->dialog->check() as $msg){
443 print_red($msg);
444 }
445 }else{
446 $data= $new = $this->dialog->save();
447 unset($data['type']);
448 foreach($data as $mem){
449 $this->AddMember($new['type'], $mem['dn']);
450 }
451 unset($this->dialog);
452 $this->dialog=NULL;
453 }
454 }
456 /* Display dialog, if there is currently one open*/
457 if($this->dialog != NULL){
458 $this->dialog->save_object();
459 $display = $this->dialog->execute();
460 return $display;
461 }
463 /* Parse selected ppd file */
464 require_once ("class_ppdManager.inc");
465 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
467 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
468 if(!preg_match("/\/$/",$path)){
469 $path = $path."/";
470 }
472 $ppdManager= new ppdManager($path);
473 if(!empty($this->gotoPrinterPPD)){
474 if((!file_exists($path.$this->gotoPrinterPPD))){
475 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
476 }else{
477 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
478 }
479 }else{
480 $smarty->assign("driverInfo", _("not defined"));
481 }
482 }else{
483 $smarty->assign("driverInfo",_("can't get ppd informations."));
484 }
486 /* Create user & admin user list */
487 $list=$this->generateList();
488 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
489 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
491 asort($userlist);
492 asort($adminlist);
494 if($this->BelongsTo != "Printer"){
495 if($this->BelongsTo == "Terminal"){
496 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
497 }else{
498 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
499 }
500 $smarty->assign("cnACL" ," disabled ");
501 }else{
502 $smarty->assign("desc" ,"");
503 }
504 $smarty->assign("UserMember" ,$this->UserMember);
505 $smarty->assign("UserMembers" ,$userlist);
506 $smarty->assign("UserMemberKeys",array_flip($userlist));
508 $smarty->assign("AdminMember" ,$this->AdminMember);
509 $smarty->assign("AdminMembers" ,$adminlist);
510 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
511 $smarty->assign("netconfig", $this->netConfigDNS->execute());
513 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
514 }
516 function remove_from_parent()
517 {
518 /* Only remove if there was initially an account */
519 if($this->initially_was_account){
521 /* Update dn, to ensure storing as printer instead of WS / terminal
522 */
523 if($this->BelongsTo == "Terminal"){
524 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
525 }
527 if($this->BelongsTo == "Workstation"){
528 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
529 }
531 /* Check if this dn points to a printer, to avoid deleting something else */
532 $ldap= $this->config->get_ldap_link();
533 $ldap->cat($this->dn, array('dn',"objectClass"));
534 if(!$ldap->count()){
535 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
536 return;
537 }
539 /* Check if obejct is a printer */
540 $CheckPrinter = $ldap->fetch();
541 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
542 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
543 return;
544 }
546 /* Remove account & dns extension */
547 $this->netConfigDNS->remove_from_parent();
548 $ldap->rmdir($this->dn);
549 show_ldap_error($ldap->get_error(), _("Removing printer failed"));
550 $this->handle_post_events("remove");
552 /* Delete references to object groups */
553 $ldap->cd ($this->config->current['BASE']);
554 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
555 while ($ldap->fetch()){
556 $og= new ogroup($this->config, $ldap->getDN());
557 unset($og->member[$this->dn]);
558 $og->save ();
559 }
560 }
561 }
564 /* Save data to object */
565 function save_object()
566 {
567 plugin::save_object();
568 $this->netConfigDNS->save_object();
569 /* Save base, since this is no LDAP attribute */
570 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
571 $this->base= $_POST['base'];
572 }
573 }
575 /* Check supplied data */
576 function check()
577 {
578 /* Call common method to give check the hook */
579 $message= plugin::check();
580 $message= array_merge($message, $this->netConfigDNS->check());
582 /* Don't display check messages if this is a template object */
583 if(isset($this->parent->by_object['workgeneric'])){
584 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
585 return $message;
586 }
587 }elseif(isset($this->parent->by_object['termgeneric'])){
588 if($this->parent->by_object['termgeneric']->cn == "default"){
589 return $message;
590 }
591 }
593 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
595 /* must: cn */
596 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
597 $message[]= "The required field 'Printer name' is not set.";
598 }
600 /* must: labeledURI */
601 if(empty($this->labeledURI)){
602 $message[]= "The required field 'Printer URL' is not set.";
603 }
605 /* Check if there is already an entry with this cn*/
606 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
607 $ldap= $this->config->get_ldap_link();
608 $ldap->cd ($this->base);
609 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
610 if ($ldap->count() != 0){
611 while ($attrs= $ldap->fetch()){
612 if ($attrs['dn'] != $this->orig_dn){
613 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
614 break;
615 }
616 }
617 }
618 }
620 return ($message);
621 }
624 /* Save to LDAP */
625 function save()
626 {
627 /* Update dn, to ensure storing as printer instead of WS / terminal
628 */
629 if($this->BelongsTo == "Terminal"){
630 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
631 }
633 if($this->BelongsTo == "Workstation"){
634 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
635 }
637 if(!$this->is_account) return;
638 if(isset($this->parent->by_object['workgeneric'])){
639 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
640 return;
641 }
642 }elseif(isset($this->parent->by_object['termgeneric'])){
643 if($this->parent->by_object['termgeneric']->cn == "default"){
644 return;
645 }
646 }
648 /* If type is still unknown, the initialisation of this printer failed, abort. */
649 if($this->BelongsTo == "unknown"){
650 return;
651 }
653 /* save ppd configuration */
654 if($this->PPDdialogToSave){
655 $this->PPDdialogToSave->save_ppd();
656 }
658 $dn= $this->dn;
659 plugin::save();
660 $ldap= $this->config->get_ldap_link();
662 /* reduce objectClasses to minimun */
663 $this->attrs['objectClass']= $this->objectclasses;
665 /* Remove all empty values */
666 if ($this->orig_dn == 'new'){
667 $attrs= array();
668 foreach ($this->attrs as $key => $val){
669 if (is_array($val) && count($val) == 0){
670 continue;
671 }
672 $attrs[$key]= $val;
673 }
674 $this->attrs= $attrs;
675 }
677 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
678 $method="https://";
679 }else{
680 $method="http://";
681 }
683 $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
685 /* Append printer user
686 */
687 $this->attrs['gotoUserPrinter']=array();
688 foreach($this->member['AddUser'] as $mem){
689 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
690 }
692 /* Append printer group
693 */
694 $this->attrs['gotoGroupPrinter'] = array();
695 foreach($this->member['AddGroup'] as $mem){
696 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
697 }
699 /* Append printer admin user
700 */
701 $this->attrs['gotoUserAdminPrinter'] =array();
702 foreach($this->member['AddAdminUser'] as $mem){
703 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
704 }
706 /* Append printer admin group
707 */
708 $this->attrs['gotoGroupAdminPrinter'] = array();
709 foreach($this->member['AddAdminGroup'] as $mem){
710 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
711 }
713 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
714 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
715 }
717 /* Write back to ldap */
718 $ldap= $this->config->get_ldap_link();
719 if ($this->orig_dn == 'new'){
720 $ldap->cd($this->config->current['BASE']);
721 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
722 $ldap->cd($this->dn);
723 $ldap->add($this->attrs);
724 $this->handle_post_events("add");
725 } else {
726 if ($this->orig_dn != $this->dn){
727 $this->move($this->orig_dn, $this->dn);
728 }
730 $ldap->cd($this->dn);
731 $this->cleanup();
732 $ldap->modify ($this->attrs);
734 $this->handle_post_events("modify");
735 }
736 show_ldap_error($ldap->get_error(), _("Saving printer failed"));
738 $this->netConfigDNS->cn = $this->cn;
739 $this->netConfigDNS->dn = $this->dn;
740 $this->netConfigDNS->save($this->dn);
742 /* Optionally execute a command after we're done */
743 $this->postcreate();
744 }
746 function generateList(){
747 $a_return=array();
748 foreach($this->member as $type => $values){
749 $a_return[$type]=array();
750 foreach($values as $value){
751 if((preg_match("/Group/i",$type))){
752 if(!isset($value['description'])){
753 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
754 }else{
755 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
756 }
757 }else{
758 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
759 }
760 }
761 }
762 return($a_return);
763 }
765 /* Delete member */
766 function DelMember($type,$id)
767 {
768 if(isset($this->member[$type][$id])){
769 unset($this->member[$type][$id]);
770 }
771 }
773 /* Add given obejct to members */
774 function AddMember($type,$dn)
775 {
776 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
777 if(!in_array_ics($type, $types)){
778 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
779 return;
780 }
782 /* Get name of index attributes */
783 if(preg_match("/user/i",$type)){
784 $var = "uid";
785 }else{
786 $var = "cn";
787 }
789 $ldap = $this->config->get_ldap_link();
790 $ldap->cd($dn);
791 $ldap->cat($dn,array("cn","uid"));
792 if($ldap->count()){
794 $attrs = $ldap->fetch();
795 $name = $attrs[$var][0];
797 /* Check if this uid/cn is already assigned to any permission */
798 foreach($types as $ctype){
799 if(isset( $this->member[$ctype][$name])){
800 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
801 return;
802 }
803 }
805 /* Everything is fine. So add the given object to members */
806 $this->member[$type][$attrs[$var][0]] = $attrs ;
807 }else{
808 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
809 }
810 }
811 }
813 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
814 ?>