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;
76 $ui= get_userinfo();
78 /* Get printer settings, possibly dn has changed */
79 plugin::plugin ($config, $this->dn);
81 /* Get is_account initially_was_account status */
82 $this->getTypeOfPrinter(true);
84 /* set orig dn to new if object is new */
85 $ldap= $this->config->get_ldap_link();
86 $ldap->cat($this->dn, array('dn'));
87 if(!$ldap->count()){
88 $this->orig_dn = "new";
89 }
91 /* create dns object */
92 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
94 /* Set base */
95 if ($this->dn == "new"){
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 /* Set tag attribute if we've tagging activated */
132 $tag= "";
133 if ($ui->gosaUnitTag != "" && isset($config->current['STRICT_UNITS']) &&
134 preg_match('/TRUE/i', $config->current['STRICT_UNITS'])){
135 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
136 }
138 if(isset($this->attrs[$attr])){
139 foreach($this->attrs[$attr] as $mem){
140 if(preg_match("/Group/",$type)){
141 $ldap->search("(&(objectClass=posixGroup)$tag(cn=".$mem."))",array("cn","description"));
142 if($ldap->count()){
143 $entry = $ldap->fetch();
144 if(isset($entry['cn'])){
145 $this->member[$type][$entry['cn'][0]]=$entry;
146 }
147 }
148 }else{
149 $ldap->search("(&(objectClass=person)$tag(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
150 if($ldap->count()){
151 $entry = $ldap->fetch();
152 if(isset($entry['uid'])){
153 $this->member[$type][$entry['uid'][0]]=$entry;
154 }
155 }
156 }
157 }
158 }
159 }
160 }
163 /* Detect type of printer.
164 * Printer can be stand alone, belong to a workstation or belong to a terminal.
165 * We can detect the type printer type when comparing the tabs objects
166 */
167 function getTypeOfPrinter($UpdateAccountStatus = false)
168 {
169 /* Disable account as default
170 */
171 $this->is_account = $this->initially_was_account = false;
173 /* Detect type of printer via parent tabs.
174 */
175 if(isset($this->parent->by_object['workgeneric'])){
177 /* Exclude templates
178 */
179 $this->cn = $this->parent->by_object['workgeneric']->cn;
180 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
181 $this->BelongsTo = "WorkstationTemplate";
182 }else{
183 $this->BelongsTo = "Workstation";
184 }
185 }elseif(isset($this->parent->by_object['termgeneric'])){
187 /* Exclude templates
188 */
189 $this->cn = $this->parent->by_object['termgeneric']->cn;
190 if($this->parent->by_object['termgeneric']->cn == "default"){
191 $this->BelongsTo = "TerminalTemplate";
192 }else{
193 $this->BelongsTo = "Terminal";
194 }
195 }elseif(isset($this->parent->by_name['printgeneric'])){
196 $this->BelongsTo = "Printer";
197 }
199 if($UpdateAccountStatus){
201 /* Set is_account / was account
202 */
203 if($this->dn == "new"){
204 $this->initially_was_account = false;
205 }
207 /* If is printer it must be a true account.
208 */
209 if($this->BelongsTo == "Printer"){
210 $this->is_account = true;
211 }
213 /* Update dn, to ensure storing as printer instead of WS / terminal
214 */
215 if($this->BelongsTo == "Terminal"){
216 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
217 }
219 if($this->BelongsTo == "Workstation"){
220 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
221 }
223 /* Detect if this is a valid printer account;
224 */
225 //FIXME: do we need to do this? we've already everything we need in $this->attrs...
226 $ldap = $this->config->get_ldap_link();
227 $ldap->cat($this->dn, array('objectClass'));
229 if($ldap->count()){
230 $attrs = $ldap->fetch();
231 if(in_array("gotoPrinter",$attrs['objectClass'])){
232 $this->initially_was_account = true;
233 $this->is_account = true;
234 }else{
235 $this->is_account = false;
236 }
237 }
238 }
239 }
241 function execute()
242 {
243 /* Call parent execute */
244 plugin::execute();
246 /* If type of printer couldn't be detected (because of missing parent object in construction)
247 * hide this tab.
248 */
249 if($this->BelongsTo == "unknown"){
250 $display= $this->show_header(_("Add printer extension"),
251 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
252 return($display);
253 }
255 /* Templates can't have printer extensions
256 */
257 if($this->BelongsTo == "WorkstationTemplate"){
258 $display= $this->show_header(_("Add printer extension"),
259 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
260 return($display);
261 }
262 if($this->BelongsTo == "TerminalTemplate"){
263 $display= $this->show_header(_("Add printer extension"),
264 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
265 return($display);
266 }
268 /* Get cn from base object */
269 if($this->BelongsTo == "Workstation"){
270 $this->cn = $this->parent->by_object['workgeneric']->cn;
271 }
272 if($this->BelongsTo == "Terminal"){
273 $this->cn = $this->parent->by_object['termgeneric']->cn;
274 }
276 $smarty= get_smarty();
277 $display="";
279 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
280 if($this->BelongsTo == "Printer"){
281 $smarty->assign("StandAlone",true);
282 }else{
283 $smarty->assign("StandAlone",false);
284 }
286 /* Do we need to flip is_account state? */
287 if (isset($_POST['modify_state'])){
288 $this->is_modified = true;
289 $this->is_account= !$this->is_account;
290 }
292 /* Do we represent a valid printer? */
293 if (!$this->is_account && $this->parent == NULL){
294 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
295 _("This 'dn' has no printer features.")."</b>";
296 return($display);
297 }
299 /* If this is a WS / Terminal depending printer, display account state button */
300 if($this->BelongsTo != "Printer"){
301 if((empty($this->cn)) && ($this->dn != "new")){
302 $display= $this->show_header(_("Add printer extension"),
303 _("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);
304 $this->is_account= false;
305 return $display;
306 }
308 if (($this->is_account)){
309 if($this->BelongsTo=="Workstation"){
310 $display= $this->show_header(_("Remove printer extension"),
311 _("This workstation has printer extension enabled.You can disable it by clicking below."));
312 }elseif($this->BelongsTo=="Terminal"){
313 $display= $this->show_header(_("Remove printer extension"),
314 _("This terminal has printer extension enabled. You can disable it by clicking below."));
315 }
316 }else{
317 if($this->BelongsTo=="Workstation"){
318 $display= $this->show_header(_("Add printer extension"),
319 _("This workstation has printer extension disabled. You can enable it by clicking below."));
320 }elseif($this->BelongsTo=="Terminal"){
321 $display= $this->show_header(_("Add printer extension"),
322 _("This terminal has printer extension disabled. You can enable it by clicking below."));
323 }
324 return ($display);
325 }
326 }
328 /* Base select dialog */
329 $once = true;
330 foreach($_POST as $name => $value){
331 if(preg_match("/^chooseBase/",$name) && $once){
332 $once = false;
333 $this->dialog = new baseSelectDialog($this->config);
334 $this->dialog->setCurrentBase($this->base);
335 $this->baseSelection = true;
336 }
337 }
339 /* Dialog handling for base select dialog
340 * Check if base was selected, dialog aborted etc */
341 if(is_object($this->dialog)){
343 $this->dialog->save_object();
344 if($this->baseSelection){
345 if($this->dialog->isClosed()){
346 $this->dialog = false;
347 $this->baseSelection = false;
348 }elseif($this->dialog->isSelected()){
349 $this->base = $this->dialog->isSelected();
350 $this->dialog= false;
351 $this->baseSelection = false;
352 }else{
353 return($this->dialog->execute());
354 }
355 }
356 }
358 /* Fill templating stuff */
359 $smarty->assign("bases", $this->config->idepartments);
360 $smarty->assign("base_select", $this->base);
362 /* Assign attributes */
363 foreach ($this->attributes as $attr){
364 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
365 $smarty->assign("$attr", $this->$attr);
366 }
368 $smarty->assign("baseACL", chkacl($this->acl,"base"));
370 if(isset($_POST['AddUser'])){
371 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
372 }
373 if(isset($_POST['AddGroup'])){
374 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
375 }
376 if(isset($_POST['AddAdminUser'])){
377 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
378 }
379 if(isset($_POST['AddAdminGroup'])){
380 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
381 }
383 /* Display ppd configure/select dialog */
384 if(isset($_POST['EditDriver'])){
385 if($this->PPDdialogToSave){
386 $this->dialog = $this->PPDdialogToSave;
387 }else{
388 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
389 }
390 }
392 /* remove ppd */
393 if(isset($_POST['RemoveDriver'])){
394 $this->gotoPrinterPPD = array();
395 $this->PPDdialogToSave = NULL;
396 }
398 /* Close ppd dialog */
399 if(isset($_POST['ClosePPD'])){
400 unset($this->dialog);
401 $this->dialog=NULL;
402 }
404 /* Save selected ppd */
405 if(isset($_POST['SavePPD'])){
406 $this->dialog->save_object();
407 if(count($this->dialog->check())){
408 foreach($this->dialog->check() as $msg){
409 print_red($msg);
410 }
411 }else{
412 $this->gotoPrinterPPD = array();
413 $this->gotoPrinterPPD = $this->dialog->save();
414 $this->PPDdialogToSave = $this->dialog;
415 unset($this->dialog);
416 $this->dialog=NULL;
417 }
418 }
420 /* Member management, delete user / group / admin ..*/
421 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
422 foreach($_POST['UserMember'] as $mem){
423 $this->DelMember('AddUser',$mem);
424 }
425 }
427 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
428 foreach($_POST['UserMember'] as $mem){
429 $this->DelMember('AddGroup',$mem);
430 }
431 }
433 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
434 foreach($_POST['AdminMember'] as $mem){
435 $this->DelMember('AddAdminUser',$mem);
436 }
437 }
439 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
440 foreach($_POST['AdminMember'] as $mem){
441 $this->DelMember('AddAdminGroup',$mem);
442 }
443 }
445 /* Abort user / group adding dialog */
446 if(isset($_POST['PrinterCancel'])){
447 unset($this->dialog);
448 $this->dialog= NULL;
449 }
451 /* Save selected users / groups */
452 if(isset($_POST['PrinterSave'])){
453 $this->dialog->save_object();
454 if(count($this->dialog->check())){
455 foreach($this->dialog->check() as $msg){
456 print_red($msg);
457 }
458 }else{
459 $data= $new = $this->dialog->save();
460 unset($data['type']);
461 foreach($data as $mem){
462 $this->AddMember($new['type'], $mem['dn']);
463 }
464 unset($this->dialog);
465 $this->dialog=NULL;
466 }
467 }
469 /* Display dialog, if there is currently one open*/
470 if($this->dialog != NULL){
471 $this->dialog->save_object();
472 $display = $this->dialog->execute();
473 return $display;
474 }
476 /* Parse selected ppd file */
477 require_once ("class_ppdManager.inc");
478 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
480 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
481 if(!preg_match("/\/$/",$path)){
482 $path = $path."/";
483 }
485 $ppdManager= new ppdManager($path);
486 if(!empty($this->gotoPrinterPPD)){
487 if((!file_exists($path.$this->gotoPrinterPPD))){
488 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
489 }else{
490 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
491 }
492 }else{
493 $smarty->assign("driverInfo", _("not defined"));
494 }
495 }else{
496 $smarty->assign("driverInfo",_("can't get ppd informations."));
497 }
499 /* Create user & admin user list */
500 $list=$this->generateList();
501 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
502 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
504 asort($userlist);
505 asort($adminlist);
507 if($this->BelongsTo != "Printer"){
508 if($this->BelongsTo == "Terminal"){
509 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
510 }else{
511 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
512 }
513 $smarty->assign("cnACL" ," disabled ");
514 }else{
515 $smarty->assign("desc" ,"");
516 }
517 $smarty->assign("UserMember" ,$this->UserMember);
518 $smarty->assign("UserMembers" ,$userlist);
519 $smarty->assign("UserMemberKeys",array_flip($userlist));
521 $smarty->assign("AdminMember" ,$this->AdminMember);
522 $smarty->assign("AdminMembers" ,$adminlist);
523 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
524 if($this->BelongsTo == "Printer"){
525 $smarty->assign("netconfig", $this->netConfigDNS->execute());
526 } else {
527 $smarty->assign("netconfig", "");
528 }
530 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
531 }
533 function remove_from_parent()
534 {
535 /* Only remove if there was initially an account */
536 if($this->initially_was_account){
538 /* Update dn, to ensure storing as printer instead of WS / terminal
539 */
540 if($this->BelongsTo == "Terminal"){
541 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
542 }
544 if($this->BelongsTo == "Workstation"){
545 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
546 }
548 /* Check if this dn points to a printer, to avoid deleting something else */
549 $ldap= $this->config->get_ldap_link();
550 $ldap->cat($this->dn, array('dn',"objectClass"));
551 if(!$ldap->count()){
552 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
553 return;
554 }
556 /* Check if obejct is a printer */
557 $CheckPrinter = $ldap->fetch();
558 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
559 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
560 return;
561 }
563 /* Remove account & dns extension */
564 $this->netConfigDNS->remove_from_parent();
565 $ldap->rmdir($this->dn);
566 show_ldap_error($ldap->get_error(), _("Removing printer failed"));
567 $this->handle_post_events("remove");
569 /* Delete references to object groups */
570 $ldap->cd ($this->config->current['BASE']);
571 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
572 while ($ldap->fetch()){
573 $og= new ogroup($this->config, $ldap->getDN());
574 unset($og->member[$this->dn]);
575 $og->save ();
576 }
577 }
578 }
581 /* Save data to object */
582 function save_object()
583 {
584 plugin::save_object();
585 $this->netConfigDNS->save_object();
586 /* Save base, since this is no LDAP attribute */
587 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
588 $this->base= $_POST['base'];
589 }
590 }
592 /* Check supplied data */
593 function check()
594 {
595 /* Call common method to give check the hook */
596 $message= plugin::check();
597 if ($this->BelongsTo == 'printer'){
598 $message= array_merge($message, $this->netConfigDNS->check());
599 }
601 /* Don't display check messages if this is a template object */
602 if(isset($this->parent->by_object['workgeneric'])){
603 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
604 return $message;
605 }
606 }elseif(isset($this->parent->by_object['termgeneric'])){
607 if($this->parent->by_object['termgeneric']->cn == "default"){
608 return $message;
609 }
610 }
612 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
614 /* must: cn */
615 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
616 $message[]= "The required field 'Printer name' is not set.";
617 }
619 if($this->BelongsTo == "Printer"){
620 $ui= get_userinfo();
621 $acl= get_permissions ($dn, $ui->subtreeACL);
622 $acl= get_module_permission($acl, "printer", $this->dn);
623 if (chkacl($acl, "create") != ""){
624 $message[]= _("You have no permissions to create a printer on this 'Base'.");
625 }
626 }
629 /* must: labeledURI */
630 if(empty($this->labeledURI)){
631 $message[]= "The required field 'Printer URL' is not set.";
632 }
634 /* Check if there is already an entry with this cn*/
635 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
636 $ldap= $this->config->get_ldap_link();
637 $ldap->cd ($this->base);
638 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
639 if ($ldap->count() != 0){
640 while ($attrs= $ldap->fetch()){
641 if ($attrs['dn'] != $this->orig_dn){
642 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
643 break;
644 }
645 }
646 }
647 }
649 return ($message);
650 }
653 /* Save to LDAP */
654 function save()
655 {
656 /* Update dn, to ensure storing as printer instead of WS / terminal
657 */
658 if($this->BelongsTo == "Terminal"){
659 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
660 }
662 if($this->BelongsTo == "Workstation"){
663 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
664 }
666 if(!$this->is_account) return;
667 if(isset($this->parent->by_object['workgeneric'])){
668 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
669 return;
670 }
671 }elseif(isset($this->parent->by_object['termgeneric'])){
672 if($this->parent->by_object['termgeneric']->cn == "default"){
673 return;
674 }
675 }
677 /* If type is still unknown, the initialisation of this printer failed, abort. */
678 if($this->BelongsTo == "unknown"){
679 return;
680 }
682 /* save ppd configuration */
683 if($this->PPDdialogToSave){
684 $this->PPDdialogToSave->save_ppd();
685 }
687 $dn= $this->dn;
688 plugin::save();
689 $ldap= $this->config->get_ldap_link();
691 /* reduce objectClasses to minimun */
692 $this->attrs['objectClass']= $this->objectclasses;
694 /* Remove all empty values */
695 if ($this->orig_dn == 'new'){
696 $attrs= array();
697 foreach ($this->attrs as $key => $val){
698 if (is_array($val) && count($val) == 0){
699 continue;
700 }
701 $attrs[$key]= $val;
702 }
703 $this->attrs= $attrs;
704 }
706 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
707 $method="https://";
708 }else{
709 $method="http://";
710 }
712 $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
714 /* Append printer user
715 */
716 $this->attrs['gotoUserPrinter']=array();
717 foreach($this->member['AddUser'] as $mem){
718 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
719 }
721 /* Append printer group
722 */
723 $this->attrs['gotoGroupPrinter'] = array();
724 foreach($this->member['AddGroup'] as $mem){
725 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
726 }
728 /* Append printer admin user
729 */
730 $this->attrs['gotoUserAdminPrinter'] =array();
731 foreach($this->member['AddAdminUser'] as $mem){
732 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
733 }
735 /* Append printer admin group
736 */
737 $this->attrs['gotoGroupAdminPrinter'] = array();
738 foreach($this->member['AddAdminGroup'] as $mem){
739 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
740 }
742 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
743 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
744 }
746 if($this->orig_dn == 'new'){
747 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
748 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
749 unset($this->attrs[$checkVar]);
750 }
751 }
752 }
754 /* Write back to ldap */
755 $ldap= $this->config->get_ldap_link();
756 if ($this->orig_dn == 'new'){
757 $ldap->cd($this->config->current['BASE']);
758 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
759 $ldap->cd($this->dn);
760 $ldap->add($this->attrs);
761 $this->handle_post_events("add");
762 } else {
763 if ($this->orig_dn != $this->dn){
764 $this->move($this->orig_dn, $this->dn);
765 }
767 $ldap->cd($this->dn);
768 $this->cleanup();
769 $ldap->modify ($this->attrs);
771 $this->handle_post_events("modify");
772 }
773 show_ldap_error($ldap->get_error(), _("Saving printer failed"));
775 $this->netConfigDNS->cn = $this->cn;
776 $this->netConfigDNS->dn = $this->dn;
777 $this->netConfigDNS->save($this->dn);
779 /* Optionally execute a command after we're done */
780 $this->postcreate();
782 /* This is a multi object. Handle tagging here... */
783 $this->handle_object_tagging();
784 }
786 function generateList(){
787 $a_return=array();
788 foreach($this->member as $type => $values){
789 $a_return[$type]=array();
790 foreach($values as $value){
791 if((preg_match("/Group/i",$type))){
792 if(!isset($value['description'])){
793 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
794 }else{
795 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
796 }
797 }else{
798 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
799 }
800 }
801 }
802 return($a_return);
803 }
805 /* Delete member */
806 function DelMember($type,$id)
807 {
808 if(isset($this->member[$type][$id])){
809 unset($this->member[$type][$id]);
810 }
811 }
813 /* Add given obejct to members */
814 function AddMember($type,$dn)
815 {
816 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
817 if(!in_array_ics($type, $types)){
818 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
819 return;
820 }
822 /* Get name of index attributes */
823 if(preg_match("/user/i",$type)){
824 $var = "uid";
825 }else{
826 $var = "cn";
827 }
829 $ldap = $this->config->get_ldap_link();
830 $ldap->cd($dn);
831 $ldap->cat($dn,array("cn","uid"));
832 if($ldap->count()){
834 $attrs = $ldap->fetch();
835 $name = $attrs[$var][0];
837 /* Check if this uid/cn is already assigned to any permission */
838 foreach($types as $ctype){
839 if(isset( $this->member[$ctype][$name])){
840 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
841 return;
842 }
843 }
845 /* Everything is fine. So add the given object to members */
846 $this->member[$type][$attrs[$var][0]] = $attrs ;
847 }else{
848 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
849 }
850 }
851 }
853 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
854 ?>