Code

Added conflict with kolab
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
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 $gotoUserPrinter ;
32   var $PPDdialogToSave  = NULL;
33   var $BelongsTo        = "unknown"; //  Specifies if this is a standalone printer, or belongs to a terminal / WS
35   var $member           =array();
36   var $strings          = "";
37   var $dialog           =NULL;
39   var $netConfigDNS;
40   var $baseSelection    = false;
41   var $macAddress       = "";
43   /* attribute list for save action */
44   var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress");
45   var $objectclasses  = array("top", "gotoPrinter");
47   function printgeneric ($config, $dn= NULL,$parent = NULL)
48   {
49     $this->config = $config;
50     $this->dn = $dn; 
51     
52     /* If parent was posted(the tabs object) we can detect the printer type. */
53     if($parent){
54       $this->parent = $parent;
55       $this->getTypeOfPrinter();
56     }else{
57       $this->BelongsTo = "unknown";
58       return;
59     }
61     /* Update dn, to ensure storing as printer instead of WS / terminal */
62     if($this->BelongsTo == "Terminal"){
63       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
64     }
66     if($this->BelongsTo == "Workstation"){
67       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
68     }
70     $this->orig_dn = $this->dn;
72     /* Get printer settings, possibly dn has changed */
73     plugin::plugin ($config, $this->dn);
75     /* Get is_account initially_was_account status */
76     $this->getTypeOfPrinter(true);
78     /* set orig dn to new if object is new */
79     $ldap= $this->config->get_ldap_link();
80     $ldap->cat($this->dn, array('dn'));
81     if(!$ldap->count()){
82       $this->orig_dn = "new";
83     }
84     
85     /* create dns object */
86     $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
88     /* Set base */
89     if ($this->dn == "new"){
90       $ui= get_userinfo();
91       $this->base= dn2base($ui->dn);
92       $this->cn= "";
93     } else {
94     
95       /* Set base and check if the extracted base exists */
96       if(preg_match("/ou=incoming,/",$this->dn)){
97         $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
98       }else{
99         $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
100       }
102       if(!isset($this->config->idepartments[$this->base])){
103         print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
104         $this->base = $_SESSION['CurrentMainBase'];
105       }
106     }
108     /* Extract selected ppd */
109     if(isset($this->gotoPrinterPPD)){
110       $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
111     }
113     /* Prepare different member types */ 
114     foreach(array("AddUser"       =>"gotoUserPrinter",
115           "AddGroup"      =>"gotoGroupPrinter",
116           "AddAdminUser"  =>"gotoUserAdminPrinter",
117           "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
119       /* $this->members contains all members */
120       $this->member[$type]=array();
122       if (isset($this->attrs[$attr]['count'])) {
123         unset($this->attrs[$attr]['count']);
124       }
126       if(isset($this->attrs[$attr])){
127         foreach($this->attrs[$attr] as $mem){
128           if(preg_match("/Group/",$type)){
129             $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
130             $entry = $ldap->fetch();
131             if(isset($entry['description'])){
132               $this->member[$type][$entry['cn'][0]]=$entry;
133             }
134           }else{
135             $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
136             $entry = $ldap->fetch();
137             if(isset($entry['uid'])){
138               $this->member[$type][$entry['uid'][0]]=$entry;
139             }
140           }
141         }
142       }
143     }
144   }
147   /* Detect type of printer.
148    * Printer can be stand alone, belong to a workstation or belong to a terminal. 
149    * We can detect the type printer type when comparing the tabs objects
150    */
151   function getTypeOfPrinter($UpdateAccountStatus = false)
152   {
153     /* Disable account as default
154      */  
155     $this->is_account = $this->initially_was_account = false;
157     /* Detect type of printer via parent tabs.
158      */
159     if(isset($this->parent->by_object['workgeneric'])){
161       /* Exclude templates 
162        */
163       $this->cn = $this->parent->by_object['workgeneric']->cn;
164       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
165         $this->BelongsTo = "WorkstationTemplate";
166       }else{
167         $this->BelongsTo = "Workstation";
168       }
169     }elseif(isset($this->parent->by_object['termgeneric'])){
171       /* Exclude templates 
172        */
173       $this->cn = $this->parent->by_object['termgeneric']->cn;
174       if($this->parent->by_object['termgeneric']->cn == "default"){
175         $this->BelongsTo = "TerminalTemplate";  
176       }else{
177         $this->BelongsTo = "Terminal";
178       }
179     }elseif(isset($this->parent->by_name['printgeneric'])){
180       $this->BelongsTo  = "Printer";
181     }
183     if($UpdateAccountStatus){
185       /* Set is_account / was account 
186        */
187       if($this->dn == "new"){
188         $this->initially_was_account = false;
189       }
191       /* If is printer it must be a true account.
192        */
193       if($this->BelongsTo == "Printer"){
194         $this->is_account = true;
195       }
197       /* Update dn, to ensure storing as printer instead of WS / terminal
198        */
199       if($this->BelongsTo == "Terminal"){
200         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
201       }
203       if($this->BelongsTo == "Workstation"){
204         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
205       }
207       /* Detect if this is a valid printer account;
208        */
209       //FIXME: do we need to do this? we've already everything we need in $this->attrs...
210       $ldap = $this->config->get_ldap_link();
211       $ldap->cat($this->dn, array('objectClass'));
213       if($ldap->count()){
214         $attrs = $ldap->fetch();
215         if(in_array("gotoPrinter",$attrs['objectClass'])){
216           $this->initially_was_account = true;
217           $this->is_account             = true;
218         }else{
219           $this->is_account = false;
220         }
221       }
222     }
223   }
225   function execute()
226   {
227     /* Call parent execute */
228     plugin::execute();
230     /* If type of printer couldn't be detected (because of missing parent object in construction) 
231      * hide this tab.
232      */
233     if($this->BelongsTo == "unknown"){
234       $display= $this->show_header(_("Add printer extension"),
235           _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
236       return($display);
237     }
239     /* Templates can't have printer extensions 
240      */
241     if($this->BelongsTo == "WorkstationTemplate"){
242       $display= $this->show_header(_("Add printer extension"),
243           _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
244       return($display);
245     }
246     if($this->BelongsTo == "TerminalTemplate"){
247       $display= $this->show_header(_("Add printer extension"),
248           _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
249       return($display);
250     }
252     /* Get cn from base object */
253     if($this->BelongsTo == "Workstation"){
254       $this->cn = $this->parent->by_object['workgeneric']->cn;
255     }
256     if($this->BelongsTo == "Terminal"){
257       $this->cn = $this->parent->by_object['termgeneric']->cn;
258     }
260     $smarty= get_smarty();
261     $display="";
263     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
264     if($this->BelongsTo == "Printer"){    
265       $smarty->assign("StandAlone",true);
266     }else{
267       $smarty->assign("StandAlone",false);
268     }
270     /* Do we need to flip is_account state? */
271     if (isset($_POST['modify_state'])){
272       $this->is_modified = true;
273       $this->is_account= !$this->is_account;
274     }
276     /* Do we represent a valid printer? */
277     if (!$this->is_account && $this->parent == NULL){
278       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
279         _("This 'dn' has no printer features.")."</b>";
280       return($display);
281     }
283     /* If this is a WS / Terminal depending printer, display account state button */
284     if($this->BelongsTo != "Printer"){
285       if((empty($this->cn)) && ($this->dn != "new")){
286         $display= $this->show_header(_("Add printer extension"),
287             _("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);
288         $this->is_account= false;
289         return $display;
290       }
292       if (($this->is_account)){
293         if($this->BelongsTo=="Workstation"){
294           $display= $this->show_header(_("Remove printer extension"),
295               _("This workstation has printer extension enabled.You can disable it by clicking below."));
296         }elseif($this->BelongsTo=="Terminal"){
297           $display= $this->show_header(_("Remove printer extension"),
298               _("This terminal has printer extension enabled. You can disable it by clicking below."));
299         }
300       }else{
301         if($this->BelongsTo=="Workstation"){
302           $display= $this->show_header(_("Add printer extension"),
303               _("This workstation has printer extension disabled. You can enable it by clicking below."));
304         }elseif($this->BelongsTo=="Terminal"){
305           $display= $this->show_header(_("Add printer extension"),
306               _("This terminal has printer extension disabled. You can enable it by clicking below."));
307         }  
308         return ($display);
309       }
310     }
312     /* Base select dialog */
313     $once = true;
314     foreach($_POST as $name => $value){
315       if(preg_match("/^chooseBase/",$name) && $once){
316         $once = false;
317         $this->dialog = new baseSelectDialog($this->config);
318         $this->dialog->setCurrentBase($this->base);
319         $this->baseSelection = true;
320       }
321     }
323     /* Dialog handling for base select dialog
324      * Check if base was selected, dialog aborted etc */
325     if(is_object($this->dialog)){
327       $this->dialog->save_object();
328       if($this->baseSelection){
329         if($this->dialog->isClosed()){
330           $this->dialog = false;
331           $this->baseSelection = false;
332         }elseif($this->dialog->isSelected()){
333           $this->base = $this->dialog->isSelected();
334           $this->dialog= false;
335           $this->baseSelection = false;
336         }else{
337           return($this->dialog->execute());
338         }
339       }
340     }
342     /* Fill templating stuff */
343     $smarty->assign("bases", $this->config->idepartments);
344     $smarty->assign("base_select", $this->base);
346     /* Assign attributes */
347     foreach ($this->attributes as $attr){
348       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
349       $smarty->assign("$attr", $this->$attr);
350     }
352     $smarty->assign("baseACL", chkacl($this->acl,"base"));
354     if(isset($_POST['AddUser'])){
355       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
356     }
357     if(isset($_POST['AddGroup'])){
358       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddGroup");
359     }
360     if(isset($_POST['AddAdminUser'])){
361       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminUser");
362     }
363     if(isset($_POST['AddAdminGroup'])){
364       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
365     }
367     /* Display ppd configure/select dialog      */
368     if(isset($_POST['EditDriver'])){
369       if($this->PPDdialogToSave){
370         $this->dialog = $this->PPDdialogToSave;
371       }else{
372         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
373       }
374     }
376     /* remove ppd */
377     if(isset($_POST['RemoveDriver'])){
378       $this->gotoPrinterPPD = array();
379       $this->PPDdialogToSave = NULL;
380     }
382     /* Close ppd dialog */
383     if(isset($_POST['ClosePPD'])){
384       unset($this->dialog);
385       $this->dialog=NULL;
386     }
388     /* Save selected ppd */
389     if(isset($_POST['SavePPD'])){
390       $this->dialog->save_object();
391       if(count($this->dialog->check())){
392         foreach($this->dialog->check() as $msg){
393           print_red($msg);
394         }
395       }else{
396         $this->gotoPrinterPPD = array();
397         $this->gotoPrinterPPD = $this->dialog->save();
398         $this->PPDdialogToSave = $this->dialog;
399         unset($this->dialog);
400         $this->dialog=NULL;
401       }
402     }
404     /* Member management, delete user / group / admin ..*/
405     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
406       if(isset($this->member['AddUser'][$_POST['UserMember']])){
407         unset($this->member['AddUser'][$_POST['UserMember']]);
408       }
409     }
411     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
412       if(isset($this->member['AddGroup'][$_POST['UserMember']])){
413         unset($this->member['AddGroup'][$_POST['UserMember']]);
414       }
415     }
417     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
418       if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){
419         unset($this->member['AddAdminUser'][$_POST['AdminMember']]);
420       }
421     }
423     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
424       if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
425         unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
426       }
427     }
429     /* Abort user / group adding dialog */
430     if(isset($_POST['PrinterCancel'])){
431       unset($this->dialog);
432       $this->dialog= NULL;
433     }
435     /* Save selected users / groups */
436     if(isset($_POST['PrinterSave'])){
437       $this->dialog->save_object();
438       if(count($this->dialog->check())){
439         foreach($this->dialog->check() as $msg){
440           print_red($msg);
441         }
442       }else{
443         $new = $this->dialog->save();
444         $data = $new;
445         unset($data['type']);
447         if(preg_match("/User/",$new['type'])){
448           $use = "uid";
449         }else{
450           $use = "cn";
451         }
453         foreach($data as $mem){
454           $this->member[$new['type']][$mem[$use][0]]=$mem;    
455         }
456         unset($this->dialog);
457         $this->dialog=NULL; 
458       }
459     }
461     /* Display dialog, if there is currently one open*/
462     if($this->dialog != NULL){
463       $this->dialog->save_object();
464       $display = $this->dialog->execute();
465       return $display;
466     }
468     /* Parse selected ppd file */
469     require_once ("class_ppdManager.inc");
470     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
472       $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
473       if(!preg_match("/\/$/",$path)){
474         $path = $path."/";
475       }
477       $ppdManager= new ppdManager($path);
478       if(!empty($this->gotoPrinterPPD)){
479         if((!file_exists($path.$this->gotoPrinterPPD))){
480           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
481         }else{
482           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
483         }
484       }else{
485         $smarty->assign("driverInfo", _("not defined"));
486       }
487     }else{
488       $smarty->assign("driverInfo",_("can't get ppd informations."));
489     }
491     /* Create user & admin user list */
492     $list=$this->generateList();
493     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
494     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
496     asort($userlist);
497     asort($adminlist);
499     if($this->BelongsTo != "Printer"){
500       if($this->BelongsTo == "Terminal"){
501         $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
502       }else{
503         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
504       }
505       $smarty->assign("cnACL"    ," disabled ");
506     }else{
507       $smarty->assign("desc"    ,"");
508     }
509     $smarty->assign("UserMember"    ,$this->UserMember);
510     $smarty->assign("UserMembers"   ,$userlist);
511     $smarty->assign("UserMemberKeys",array_flip($userlist));
513     $smarty->assign("AdminMember"    ,$this->AdminMember);
514     $smarty->assign("AdminMembers"   ,$adminlist);
515     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
516     $smarty->assign("netconfig", $this->netConfigDNS->execute());
518     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
519   }
521   function remove_from_parent()
522   {
523     /* Only remove if there was initially an account */
524     if($this->initially_was_account){
526       /* Update dn, to ensure storing as printer instead of WS / terminal
527        */
528       if($this->BelongsTo == "Terminal"){
529         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
530       }
532       if($this->BelongsTo == "Workstation"){
533         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
534       }
536       /* Check if this dn points to a printer, to avoid deleting something else */
537       $ldap= $this->config->get_ldap_link();
538       $ldap->cat($this->dn, array('dn',"objectClass"));
539       if(!$ldap->count()){
540         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
541         return;
542       }
544       /* Check if obejct is a printer */
545       $CheckPrinter = $ldap->fetch();
546       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
547         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
548         return;
549       }
551       /* Remove account & dns extension */ 
552       $this->netConfigDNS->remove_from_parent();
553       $ldap->rmdir($this->dn);
554       show_ldap_error($ldap->get_error(), _("Removing printer failed"));
555       $this->handle_post_events("remove");
557       /* Delete references to object groups */
558       $ldap->cd ($this->config->current['BASE']);
559       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
560       while ($ldap->fetch()){
561         $og= new ogroup($this->config, $ldap->getDN());
562         unset($og->member[$this->dn]);
563         $og->save ();
564       }
565     }
566   }
569   /* Save data to object */
570   function save_object()
571   {
572     plugin::save_object();
573     $this->netConfigDNS->save_object();
574     /* Save base, since this is no LDAP attribute */
575     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
576       $this->base= $_POST['base'];
577     }
578   }
580   /* Check supplied data */
581   function check()
582   {
583     /* Call common method to give check the hook */
584     $message= plugin::check();
585     $message= array_merge($message, $this->netConfigDNS->check());
587     /* Don't display check messages if this is a template object */
588     if(isset($this->parent->by_object['workgeneric'])){
589       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
590         return $message;
591       }
592     }elseif(isset($this->parent->by_object['termgeneric'])){
593       if($this->parent->by_object['termgeneric']->cn == "default"){
594         return $message;
595       }
596     }
598     $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
600     /* must: cn */
601     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
602       $message[]= "The required field 'Printer name' is not set.";
603     }
604     
605     /* must: labeledURI */
606     if(empty($this->labeledURI)){
607       $message[]= "The required field 'Printer URL' is not set.";
608     }
609     
610     /* Check if there is already an entry with this cn*/
611     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
612       $ldap= $this->config->get_ldap_link();
613       $ldap->cd ($this->base);
614       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
615       if ($ldap->count() != 0){
616         while ($attrs= $ldap->fetch()){
617           if ($attrs['dn'] != $this->orig_dn){
618             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
619             break;
620           }
621         }
622       }
623     }
625     return ($message);
626   }
629   /* Save to LDAP */
630   function save()
631   {
632     /* Update dn, to ensure storing as printer instead of WS / terminal
633      */
634     if($this->BelongsTo == "Terminal"){
635       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
636     }
638     if($this->BelongsTo == "Workstation"){
639       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
640     }
641     
642     if(!$this->is_account) return;
643     if(isset($this->parent->by_object['workgeneric'])){
644       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
645         return;
646       }
647     }elseif(isset($this->parent->by_object['termgeneric'])){
648       if($this->parent->by_object['termgeneric']->cn == "default"){
649         return;
650       }
651     }
653     /* If type is still unknown, the initialisation of this printer failed, abort. */
654     if($this->BelongsTo == "unknown"){
655       return;
656     }
658     /* save ppd configuration */
659     if($this->PPDdialogToSave){
660       $this->PPDdialogToSave->save_ppd();
661     }
663     $dn= $this->dn;
664     plugin::save();
665     $ldap= $this->config->get_ldap_link();
667     /* reduce objectClasses to minimun */
668     $this->attrs['objectClass']= $this->objectclasses;
670     /* Remove all empty values */
671     if ($this->orig_dn == 'new'){
672       $attrs= array();
673       foreach ($this->attrs as $key => $val){
674         if (is_array($val) && count($val) == 0){
675           continue;
676         }
677         $attrs[$key]= $val;
678       }
679       $this->attrs= $attrs;
680     }
682     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
683       $method="https://";
684     }else{
685       $method="http://";
686     }
687   
688     $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
690     /* Append printer user 
691      */
692     if((isset($this->attrs['gotoUserPrinter'])) && (is_string($this->attrs['gotoUserPrinter']))){
693       $this->attrs['gotoUserPrinter']=array();
694     }
695     foreach($this->member['AddUser'] as $mem){
696       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
697     }
699     /* Append printer group 
700      */
701     foreach($this->member['AddGroup'] as $mem){
702       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
703     }
705     /* Append printer admin user 
706      */
707     foreach($this->member['AddAdminUser'] as $mem){
708       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
709     }
711     /* Append printer admin group 
712      */
713     foreach($this->member['AddAdminGroup'] as $mem){
714       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
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   }
768 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
769 ?>