803ea881eee9dc08180f6c7327a1a60c5c332b60
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 var $gotoUserAdminPrinter;
43 var $gotoGroupAdminPrinter ;
44 var $gotoGroupPrinter;
45 var $gotoUserPrinter ;
47 /* attribute list for save action */
48 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
49 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
50 var $objectclasses = array("top", "gotoPrinter");
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 if($ldap->count()){
136 $entry = $ldap->fetch();
137 $this->member[$type][$entry['cn'][0]]=$entry;
138 }
139 }else{
140 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
141 if($ldap->count()){
142 $entry = $ldap->fetch();
143 $this->member[$type][$entry['uid'][0]]=$entry;
144 }
145 }
146 }
147 }
148 }
149 }
152 /* Detect type of printer.
153 * Printer can be stand alone, belong to a workstation or belong to a terminal.
154 * We can detect the type printer type when comparing the tabs objects
155 */
156 function getTypeOfPrinter($UpdateAccountStatus = false)
157 {
158 /* Disable account as default
159 */
160 $this->is_account = $this->initially_was_account = false;
162 /* Detect type of printer via parent tabs.
163 */
164 if(isset($this->parent->by_object['workgeneric'])){
166 /* Exclude templates
167 */
168 $this->cn = $this->parent->by_object['workgeneric']->cn;
169 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
170 $this->BelongsTo = "WorkstationTemplate";
171 }else{
172 $this->BelongsTo = "Workstation";
173 }
174 }elseif(isset($this->parent->by_object['termgeneric'])){
176 /* Exclude templates
177 */
178 $this->cn = $this->parent->by_object['termgeneric']->cn;
179 if($this->parent->by_object['termgeneric']->cn == "default"){
180 $this->BelongsTo = "TerminalTemplate";
181 }else{
182 $this->BelongsTo = "Terminal";
183 }
184 }elseif(isset($this->parent->by_name['printgeneric'])){
185 $this->BelongsTo = "Printer";
186 }
188 if($UpdateAccountStatus){
190 /* Set is_account / was account
191 */
192 if($this->dn == "new"){
193 $this->initially_was_account = false;
194 }
196 /* If is printer it must be a true account.
197 */
198 if($this->BelongsTo == "Printer"){
199 $this->is_account = true;
200 }
202 /* Update dn, to ensure storing as printer instead of WS / terminal
203 */
204 if($this->BelongsTo == "Terminal"){
205 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
206 }
208 if($this->BelongsTo == "Workstation"){
209 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
210 }
212 /* Detect if this is a valid printer account;
213 */
214 //FIXME: do we need to do this? we've already everything we need in $this->attrs...
215 $ldap = $this->config->get_ldap_link();
216 $ldap->cat($this->dn, array('objectClass'));
218 if($ldap->count()){
219 $attrs = $ldap->fetch();
220 if(in_array("gotoPrinter",$attrs['objectClass'])){
221 $this->initially_was_account = true;
222 $this->is_account = true;
223 }else{
224 $this->is_account = false;
225 }
226 }
227 }
228 }
230 function execute()
231 {
232 /* Call parent execute */
233 plugin::execute();
235 /* If type of printer couldn't be detected (because of missing parent object in construction)
236 * hide this tab.
237 */
238 if($this->BelongsTo == "unknown"){
239 $display= $this->show_enable_header(_("Add printer extension"),
240 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
241 return($display);
242 }
244 /* Templates can't have printer extensions
245 */
246 if($this->BelongsTo == "WorkstationTemplate"){
247 $display= $this->show_enable_header(_("Add printer extension"),
248 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
249 return($display);
250 }
251 if($this->BelongsTo == "TerminalTemplate"){
252 $display= $this->show_enable_header(_("Add printer extension"),
253 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
254 return($display);
255 }
257 /* Get cn from base object */
258 if($this->BelongsTo == "Workstation"){
259 $this->cn = $this->parent->by_object['workgeneric']->cn;
260 }
261 if($this->BelongsTo == "Terminal"){
262 $this->cn = $this->parent->by_object['termgeneric']->cn;
263 }
265 $smarty= get_smarty();
266 $display="";
268 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
269 if($this->BelongsTo == "Printer"){
270 $smarty->assign("StandAlone",true);
271 }else{
272 $smarty->assign("StandAlone",false);
273 }
275 /* Do we need to flip is_account state? */
276 if (isset($_POST['modify_state'])){
277 $this->is_modified = true;
278 $this->is_account= !$this->is_account;
279 }
281 /* Do we represent a valid printer? */
282 if (!$this->is_account && $this->parent == NULL){
283 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
284 _("This 'dn' has no printer features.")."</b>";
285 return($display);
286 }
288 /* If this is a WS / Terminal depending printer, display account state button */
289 if($this->BelongsTo != "Printer"){
290 if((empty($this->cn)) && ($this->dn != "new")){
291 $display= $this->show_enable_header(_("Add printer extension"),
292 _("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);
293 $this->is_account= false;
294 return $display;
295 }
297 if (($this->is_account)){
298 if($this->BelongsTo=="Workstation"){
299 $display= $this->show_disable_header(_("Remove printer extension"),
300 _("This workstation has printer extension enabled.You can disable it by clicking below."));
301 }elseif($this->BelongsTo=="Terminal"){
302 $display= $this->show_disable_header(_("Remove printer extension"),
303 _("This terminal has printer extension enabled. You can disable it by clicking below."));
304 }
305 }else{
306 if($this->BelongsTo=="Workstation"){
307 $display= $this->show_disable_header(_("Add printer extension"),
308 _("This workstation has printer extension disabled. You can enable it by clicking below."));
309 }elseif($this->BelongsTo=="Terminal"){
310 $display= $this->show_enable_header(_("Add printer extension"),
311 _("This terminal has printer extension disabled. You can enable it by clicking below."));
312 }
313 return ($display);
314 }
315 }
317 /* Base select dialog */
318 $once = true;
319 foreach($_POST as $name => $value){
320 if(preg_match("/^chooseBase/",$name) && $once){
321 $once = false;
322 $this->dialog = new baseSelectDialog($this->config,$this);
323 $this->dialog->setCurrentBase($this->base);
324 $this->baseSelection = true;
325 }
326 }
328 /* Dialog handling for base select dialog
329 * Check if base was selected, dialog aborted etc */
330 if(is_object($this->dialog)){
332 $this->dialog->save_object();
333 if($this->baseSelection){
334 if($this->dialog->isClosed()){
335 $this->dialog = false;
336 $this->baseSelection = false;
337 }elseif($this->dialog->isSelected()){
338 $this->base = $this->dialog->isSelected();
339 $this->dialog= false;
340 $this->baseSelection = false;
341 }else{
342 return($this->dialog->execute());
343 }
344 }
345 }
347 /* Fill templating stuff */
348 $smarty->assign("bases", $this->config->idepartments);
349 $smarty->assign("base_select", $this->base);
351 /* Assign attributes */
352 foreach ($this->attributes as $attr){
353 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
354 $smarty->assign("$attr", $this->$attr);
355 }
357 $smarty->assign("baseACL", chkacl($this->acl,"base"));
359 if(isset($_POST['AddUser'])){
360 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
361 }
362 if(isset($_POST['AddGroup'])){
363 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
364 }
365 if(isset($_POST['AddAdminUser'])){
366 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
367 }
368 if(isset($_POST['AddAdminGroup'])){
369 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
370 }
372 /* Display ppd configure/select dialog */
373 if(isset($_POST['EditDriver'])){
374 if($this->PPDdialogToSave){
375 $this->dialog = $this->PPDdialogToSave;
376 }else{
377 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
378 }
379 }
381 /* remove ppd */
382 if(isset($_POST['RemoveDriver'])){
383 $this->gotoPrinterPPD = array();
384 $this->PPDdialogToSave = NULL;
385 }
387 /* Close ppd dialog */
388 if(isset($_POST['ClosePPD'])){
389 unset($this->dialog);
390 $this->dialog=NULL;
391 }
393 /* Save selected ppd */
394 if(isset($_POST['SavePPD'])){
395 $this->dialog->save_object();
396 if(count($this->dialog->check())){
397 foreach($this->dialog->check() as $msg){
398 print_red($msg);
399 }
400 }else{
401 $this->gotoPrinterPPD = array();
402 $this->gotoPrinterPPD = $this->dialog->save();
403 $this->PPDdialogToSave = $this->dialog;
404 unset($this->dialog);
405 $this->dialog=NULL;
406 }
407 }
409 /* Member management, delete user / group / admin ..*/
410 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
411 foreach($_POST['UserMember'] as $mem){
412 $this->DelMember('AddUser',$mem);
413 }
414 }
416 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
417 foreach($_POST['UserMember'] as $mem){
418 $this->DelMember('AddGroup',$mem);
419 }
420 }
422 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
423 foreach($_POST['AdminMember'] as $mem){
424 $this->DelMember('AddAdminUser',$mem);
425 }
426 }
428 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
429 foreach($_POST['AdminMember'] as $mem){
430 $this->DelMember('AddAdminGroup',$mem);
431 }
432 }
434 /* Abort user / group adding dialog */
435 if(isset($_POST['PrinterCancel'])){
436 unset($this->dialog);
437 $this->dialog= NULL;
438 }
440 /* Save selected users / groups */
441 if(isset($_POST['PrinterSave'])){
442 $this->dialog->save_object();
443 if(count($this->dialog->check())){
444 foreach($this->dialog->check() as $msg){
445 print_red($msg);
446 }
447 }else{
448 $data= $new = $this->dialog->save();
449 unset($data['type']);
450 foreach($data as $mem){
451 $this->AddMember($new['type'], $mem['dn']);
452 }
453 unset($this->dialog);
454 $this->dialog=NULL;
455 }
456 }
458 /* Display dialog, if there is currently one open*/
459 if($this->dialog != NULL){
460 $this->dialog->save_object();
461 $display = $this->dialog->execute();
462 return $display;
463 }
465 /* Parse selected ppd file */
466 require_once ("class_ppdManager.inc");
467 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
469 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
470 if(!preg_match("/\/$/",$path)){
471 $path = $path."/";
472 }
474 $ppdManager= new ppdManager($path);
475 if(!empty($this->gotoPrinterPPD)){
476 if((!file_exists($path.$this->gotoPrinterPPD))){
477 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
478 }else{
479 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
480 }
481 }else{
482 $smarty->assign("driverInfo", _("not defined"));
483 }
484 }else{
485 $smarty->assign("driverInfo",_("can't get ppd informations."));
486 }
488 /* Create user & admin user list */
489 $list=$this->generateList();
490 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
491 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
493 asort($userlist);
494 asort($adminlist);
496 if($this->BelongsTo != "Printer"){
497 if($this->BelongsTo == "Terminal"){
498 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
499 }else{
500 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
501 }
502 $smarty->assign("cnACL" ," disabled ");
503 }else{
504 $smarty->assign("desc" ,"");
505 }
506 $smarty->assign("UserMember" ,$this->UserMember);
507 $smarty->assign("UserMembers" ,$userlist);
508 $smarty->assign("UserMemberKeys",array_flip($userlist));
510 $smarty->assign("AdminMember" ,$this->AdminMember);
511 $smarty->assign("AdminMembers" ,$adminlist);
512 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
513 if($this->BelongsTo == "Printer"){
514 $smarty->assign("netconfig", $this->netConfigDNS->execute());
515 } else {
516 $smarty->assign("netconfig", "");
517 }
519 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
520 }
522 function remove_from_parent()
523 {
524 /* Only remove if there was initially an account */
525 if($this->initially_was_account){
527 /* Update dn, to ensure storing as printer instead of WS / terminal
528 */
529 if($this->BelongsTo == "Terminal"){
530 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
531 }
533 if($this->BelongsTo == "Workstation"){
534 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
535 }
537 /* Check if this dn points to a printer, to avoid deleting something else */
538 $ldap= $this->config->get_ldap_link();
539 $ldap->cat($this->dn, array('dn',"objectClass"));
540 if(!$ldap->count()){
541 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
542 return;
543 }
545 /* Check if obejct is a printer */
546 $CheckPrinter = $ldap->fetch();
547 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
548 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
549 return;
550 }
552 /* Remove account & dns extension */
553 $this->netConfigDNS->remove_from_parent();
554 $ldap->rmdir($this->dn);
555 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
556 $this->handle_post_events("remove");
558 /* Delete references to object groups */
559 $ldap->cd ($this->config->current['BASE']);
560 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
561 while ($ldap->fetch()){
562 $og= new ogroup($this->config, $ldap->getDN());
563 unset($og->member[$this->dn]);
564 $og->save ();
565 }
566 }
567 }
570 /* Save data to object */
571 function save_object()
572 {
573 plugin::save_object();
574 $this->netConfigDNS->save_object();
575 /* Save base, since this is no LDAP attribute */
576 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
577 $this->base= $_POST['base'];
578 }
579 }
581 /* Check supplied data */
582 function check()
583 {
584 /* Call common method to give check the hook */
585 $message= plugin::check();
586 if ($this->BelongsTo == 'printer'){
587 $message= array_merge($message, $this->netConfigDNS->check());
588 }
590 /* Don't display check messages if this is a template object */
591 if(isset($this->parent->by_object['workgeneric'])){
592 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
593 return $message;
594 }
595 }elseif(isset($this->parent->by_object['termgeneric'])){
596 if($this->parent->by_object['termgeneric']->cn == "default"){
597 return $message;
598 }
599 }
601 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
603 /* must: cn */
604 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
605 $message[]= "The required field 'Printer name' is not set.";
606 }
608 /* must: labeledURI */
609 if(empty($this->labeledURI)){
610 $message[]= "The required field 'Printer URL' is not set.";
611 }
613 /* Check if there is already an entry with this cn*/
614 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
615 $ldap= $this->config->get_ldap_link();
616 $ldap->cd ($this->base);
617 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
618 if ($ldap->count() != 0){
619 while ($attrs= $ldap->fetch()){
620 if ($attrs['dn'] != $this->orig_dn){
621 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
622 break;
623 }
624 }
625 }
626 }
628 return ($message);
629 }
632 /* Save to LDAP */
633 function save()
634 {
635 /* Update dn, to ensure storing as printer instead of WS / terminal
636 */
637 if($this->BelongsTo == "Terminal"){
638 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
639 }
641 if($this->BelongsTo == "Workstation"){
642 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
643 }
645 if(!$this->is_account) return;
646 if(isset($this->parent->by_object['workgeneric'])){
647 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
648 return;
649 }
650 }elseif(isset($this->parent->by_object['termgeneric'])){
651 if($this->parent->by_object['termgeneric']->cn == "default"){
652 return;
653 }
654 }
656 /* If type is still unknown, the initialisation of this printer failed, abort. */
657 if($this->BelongsTo == "unknown"){
658 return;
659 }
661 /* save ppd configuration */
662 if($this->PPDdialogToSave){
663 $this->PPDdialogToSave->save_ppd();
664 }
666 $dn= $this->dn;
667 plugin::save();
668 $ldap= $this->config->get_ldap_link();
670 /* reduce objectClasses to minimun */
671 $this->attrs['objectClass']= $this->objectclasses;
673 /* Remove all empty values */
674 if ($this->orig_dn == 'new'){
675 $attrs= array();
676 foreach ($this->attrs as $key => $val){
677 if (is_array($val) && count($val) == 0){
678 continue;
679 }
680 $attrs[$key]= $val;
681 }
682 $this->attrs= $attrs;
683 }
685 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
686 $method="https://";
687 }else{
688 $method="http://";
689 }
691 $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
693 /* Append printer user
694 */
695 $this->attrs['gotoUserPrinter']=array();
696 foreach($this->member['AddUser'] as $mem){
697 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
698 }
700 /* Append printer group
701 */
702 $this->attrs['gotoGroupPrinter'] = array();
703 foreach($this->member['AddGroup'] as $mem){
704 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
705 }
707 /* Append printer admin user
708 */
709 $this->attrs['gotoUserAdminPrinter'] = array();
710 foreach($this->member['AddAdminUser'] as $mem){
711 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
712 }
714 /* Append printer admin group
715 */
716 $this->attrs['gotoGroupAdminPrinter']= array();
717 foreach($this->member['AddAdminGroup'] as $mem){
718 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
719 }
721 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
722 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
723 }
725 if($this->orig_dn == 'new'){
726 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
727 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
728 unset($this->attrs[$checkVar]);
729 }
730 }
731 }
733 /* Move object in necessary*/
734 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
735 $this->move($this->orig_dn, $this->dn);
736 }
738 /* Write back to ldap */
739 $ldap= $this->config->get_ldap_link();
740 $ldap->cat($this->dn);
741 if(!$ldap->count()){
742 $ldap->cd($this->config->current['BASE']);
743 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
744 $ldap->cd($this->dn);
745 $ldap->add($this->attrs);
746 $this->handle_post_events("add");
747 } else {
748 $ldap->cd($this->dn);
749 $this->cleanup();
750 $ldap->modify ($this->attrs);
751 $this->handle_post_events("modify");
752 }
753 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
755 if($this->BelongsTo == "Printer"){
756 $this->netConfigDNS->cn = $this->cn;
757 $this->netConfigDNS->dn = $this->dn;
758 $this->netConfigDNS->save($this->dn);
759 }
761 /* Optionally execute a command after we're done */
762 $this->postcreate();
764 /* This is a multi object. Handle tagging here... */
765 $this->handle_object_tagging();
766 }
768 function generateList(){
769 $a_return=array();
770 foreach($this->member as $type => $values){
771 $a_return[$type]=array();
772 foreach($values as $value){
773 if((preg_match("/Group/i",$type))){
774 if(!isset($value['description'])){
775 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
776 }else{
777 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
778 }
779 }else{
780 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
781 }
782 }
783 }
784 return($a_return);
785 }
787 /* Return plugin informations for acl handling
788 #FIXME FAIscript seams to ununsed within this class... */
789 function plInfo()
790 {
791 return (array(
792 "plShortName" => _("Generic"),
793 "plDescription" => _("Print generic"),
794 "plSelfModify" => FALSE,
795 "plDepends" => array(),
796 "plPriority" => 0,
797 "plSection" => array("administration"),
798 "plCategory" => array("printer" => array("description" => _("Printer"),
799 "objectClass" => "gotoPrinter")),
800 "plProvidedAcls"=> array(
801 "cn" => _("Name"),
802 "description" => _("Description"),
803 "l" => _("Location"),
804 "labeledURI" => _("LabeledURL"),
805 "gotoPrinterPPD" => _("Printer PPD"),
806 "gotoUserPrinter" => _("Permissions"))
807 ));
808 }
811 /* Delete member */
812 function DelMember($type,$id)
813 {
814 /* Check if there was a printer "dn" given, or the "cn" */
815 foreach($this->member[$type] as $key => $printer){
816 if($printer['dn'] == $id) {
817 $id = $key;
818 }
819 }
821 if(!$this->acl_is_writeable($type)){
822 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
823 return(FALSE);
824 }
826 if(isset($this->member[$type][$id])){
827 unset($this->member[$type][$id]);
828 return(TRUE);
829 }
830 return(FALSE);
831 }
834 /* Add given obejct to members */
835 function AddMember($type,$dn)
836 {
837 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
838 if(!in_array_ics($type, $types)){
839 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
840 return(FALSE);
841 }
843 if(!$this->acl_is_writeable($type)){
844 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
845 return(FALSE);
846 }
848 /* Get name of index attributes */
849 if(preg_match("/user/i",$type)){
850 $var = "uid";
851 }else{
852 $var = "cn";
853 }
855 $ldap = $this->config->get_ldap_link();
856 $ldap->cd($dn);
857 $ldap->cat($dn,array("cn","uid"));
858 if($ldap->count()){
860 $attrs = $ldap->fetch();
861 $name = $attrs[$var][0];
863 /* Check if this uid/cn is already assigned to any permission */
864 foreach($types as $ctype){
865 if(isset( $this->member[$ctype][$name])){
866 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
867 return(FALSE);
868 }
869 }
871 /* Everything is fine. So add the given object to members */
872 $this->member[$type][$attrs[$var][0]] = $attrs ;
873 }else{
874 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
875 return(FALSE);
876 }
877 return(TRUE);
878 }
879 }
883 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
884 ?>