Code

Added resolution hook results to WS & Terminal service
[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     if(isset($_POST['AddUser'])){
353       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
354     }
355     if(isset($_POST['AddGroup'])){
356       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddGroup");
357     }
358     if(isset($_POST['AddAdminUser'])){
359       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminUser");
360     }
361     if(isset($_POST['AddAdminGroup'])){
362       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
363     }
365     /* Display ppd configure/select dialog      */
366     if(isset($_POST['EditDriver'])){
367       if($this->PPDdialogToSave){
368         $this->dialog = $this->PPDdialogToSave;
369       }else{
370         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
371       }
372     }
374     /* remove ppd */
375     if(isset($_POST['RemoveDriver'])){
376       $this->gotoPrinterPPD = array();
377       $this->PPDdialogToSave = NULL;
378     }
380     /* Close ppd dialog */
381     if(isset($_POST['ClosePPD'])){
382       unset($this->dialog);
383       $this->dialog=NULL;
384     }
386     /* Save selected ppd */
387     if(isset($_POST['SavePPD'])){
388       $this->dialog->save_object();
389       if(count($this->dialog->check())){
390         foreach($this->dialog->check() as $msg){
391           print_red($msg);
392         }
393       }else{
394         $this->gotoPrinterPPD = array();
395         $this->gotoPrinterPPD = $this->dialog->save();
396         $this->PPDdialogToSave = $this->dialog;
397         unset($this->dialog);
398         $this->dialog=NULL;
399       }
400     }
402     /* Member management, delete user / group / admin ..*/
403     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
404       if(isset($this->member['AddUser'][$_POST['UserMember']])){
405         unset($this->member['AddUser'][$_POST['UserMember']]);
406       }
407     }
409     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
410       if(isset($this->member['AddGroup'][$_POST['UserMember']])){
411         unset($this->member['AddGroup'][$_POST['UserMember']]);
412       }
413     }
415     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
416       if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){
417         unset($this->member['AddAdminUser'][$_POST['AdminMember']]);
418       }
419     }
421     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
422       if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
423         unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
424       }
425     }
427     /* Abort user / group adding dialog */
428     if(isset($_POST['PrinterCancel'])){
429       unset($this->dialog);
430       $this->dialog= NULL;
431     }
433     /* Save selected users / groups */
434     if(isset($_POST['PrinterSave'])){
435       $this->dialog->save_object();
436       if(count($this->dialog->check())){
437         foreach($this->dialog->check() as $msg){
438           print_red($msg);
439         }
440       }else{
441         $new = $this->dialog->save();
442         $data = $new;
443         unset($data['type']);
445         if(preg_match("/User/",$new['type'])){
446           $use = "uid";
447         }else{
448           $use = "cn";
449         }
451         foreach($data as $mem){
452           $this->member[$new['type']][$mem[$use][0]]=$mem;    
453         }
454         unset($this->dialog);
455         $this->dialog=NULL; 
456       }
457     }
459     /* Display dialog, if there is currently one open*/
460     if($this->dialog != NULL){
461       $this->dialog->save_object();
462       $display = $this->dialog->execute();
463       return $display;
464     }
466     /* Parse selected ppd file */
467     require_once ("class_ppdManager.inc");
468     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
470       $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
471       if(!preg_match("/\/$/",$path)){
472         $path = $path."/";
473       }
475       $ppdManager= new ppdManager($path);
476       if(!empty($this->gotoPrinterPPD)){
477         if((!file_exists($path.$this->gotoPrinterPPD))){
478           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
479         }else{
480           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
481         }
482       }else{
483         $smarty->assign("driverInfo", _("not defined"));
484       }
485     }else{
486       $smarty->assign("driverInfo",_("can't get ppd informations."));
487     }
489     /* Create user & admin user list */
490     $list=$this->generateList();
491     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
492     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
494     asort($userlist);
495     asort($adminlist);
497     if($this->BelongsTo != "Printer"){
498       if($this->BelongsTo == "Terminal"){
499         $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
500       }else{
501         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
502       }
503       $smarty->assign("cnACL"    ," disabled ");
504     }else{
505       $smarty->assign("desc"    ,"");
506     }
507     $smarty->assign("UserMember"    ,$this->UserMember);
508     $smarty->assign("UserMembers"   ,$userlist);
509     $smarty->assign("UserMemberKeys",array_flip($userlist));
511     $smarty->assign("AdminMember"    ,$this->AdminMember);
512     $smarty->assign("AdminMembers"   ,$adminlist);
513     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
514     $smarty->assign("netconfig", $this->netConfigDNS->execute());
516     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
517   }
519   function remove_from_parent()
520   {
521     /* Only remove if there was initially an account */
522     if($this->initially_was_account){
524       /* Update dn, to ensure storing as printer instead of WS / terminal
525        */
526       if($this->BelongsTo == "Terminal"){
527         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
528       }
530       if($this->BelongsTo == "Workstation"){
531         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
532       }
534       /* Check if this dn points to a printer, to avoid deleting something else */
535       $ldap= $this->config->get_ldap_link();
536       $ldap->cat($this->dn, array('dn',"objectClass"));
537       if(!$ldap->count()){
538         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
539         return;
540       }
542       /* Check if obejct is a printer */
543       $CheckPrinter = $ldap->fetch();
544       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
545         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
546         return;
547       }
549       /* Remove account & dns extension */ 
550       $this->netConfigDNS->remove_from_parent();
551       $ldap->rmdir($this->dn);
552       show_ldap_error($ldap->get_error(), _("Removing printer failed"));
553       $this->handle_post_events("remove");
555       /* Delete references to object groups */
556       $ldap->cd ($this->config->current['BASE']);
557       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
558       while ($ldap->fetch()){
559         $og= new ogroup($this->config, $ldap->getDN());
560         unset($og->member[$this->dn]);
561         $og->save ();
562       }
563     }
564   }
567   /* Save data to object */
568   function save_object()
569   {
570     plugin::save_object();
571     $this->netConfigDNS->save_object();
572     /* Save base, since this is no LDAP attribute */
573     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
574       $this->base= $_POST['base'];
575     }
576   }
578   /* Check supplied data */
579   function check()
580   {
581     /* Call common method to give check the hook */
582     $message= plugin::check();
583     $message= array_merge($message, $this->netConfigDNS->check());
585     /* Don't display check messages if this is a template object */
586     if(isset($this->parent->by_object['workgeneric'])){
587       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
588         return $message;
589       }
590     }elseif(isset($this->parent->by_object['termgeneric'])){
591       if($this->parent->by_object['termgeneric']->cn == "default"){
592         return $message;
593       }
594     }
596     $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
598     /* must: cn */
599     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
600       $message[]= "The required field 'Printer name' is not set.";
601     }
602     
603     /* Check if there is already an entry with this cn*/
604     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
605       $ldap= $this->config->get_ldap_link();
606       $ldap->cd ($this->base);
607       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
608       if ($ldap->count() != 0){
609         while ($attrs= $ldap->fetch()){
610           if ($attrs['dn'] != $this->orig_dn){
611             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
612             break;
613           }
614         }
615       }
616     }
618     return ($message);
619   }
622   /* Save to LDAP */
623   function save()
624   {
625     /* Update dn, to ensure storing as printer instead of WS / terminal
626      */
627     if($this->BelongsTo == "Terminal"){
628       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
629     }
631     if($this->BelongsTo == "Workstation"){
632       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
633     }
634     
635     if(!$this->is_account) return;
636     if(isset($this->parent->by_object['workgeneric'])){
637       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
638         return;
639       }
640     }elseif(isset($this->parent->by_object['termgeneric'])){
641       if($this->parent->by_object['termgeneric']->cn == "default"){
642         return;
643       }
644     }
646     /* If type is still unknown, the initialisation of this printer failed, abort. */
647     if($this->BelongsTo == "unknown"){
648       return;
649     }
651     /* save ppd configuration */
652     if($this->PPDdialogToSave){
653       $this->PPDdialogToSave->save_ppd();
654     }
656     $dn= $this->dn;
657     plugin::save();
658     $ldap= $this->config->get_ldap_link();
660     /* reduce objectClasses to minimun */
661     $this->attrs['objectClass']= $this->objectclasses;
663     /* Remove all empty values */
664     if ($this->orig_dn == 'new'){
665       $attrs= array();
666       foreach ($this->attrs as $key => $val){
667         if (is_array($val) && count($val) == 0){
668           continue;
669         }
670         $attrs[$key]= $val;
671       }
672       $this->attrs= $attrs;
673     }
675     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
676       $method="https://";
677     }else{
678       $method="http://";
679     }
680   
681     $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
683     /* Append printer user 
684      */
685     if((isset($this->attrs['gotoUserPrinter'])) && (is_string($this->attrs['gotoUserPrinter']))){
686       $this->attrs['gotoUserPrinter']=array();
687     }
688     foreach($this->member['AddUser'] as $mem){
689       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
690     }
692     /* Append printer group 
693      */
694     foreach($this->member['AddGroup'] as $mem){
695       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
696     }
698     /* Append printer admin user 
699      */
700     foreach($this->member['AddAdminUser'] as $mem){
701       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
702     }
704     /* Append printer admin group 
705      */
706     foreach($this->member['AddAdminGroup'] as $mem){
707       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
708     }
710     /* Write back to ldap */
711     $ldap= $this->config->get_ldap_link();
712     if ($this->orig_dn == 'new'){
713       $ldap->cd($this->config->current['BASE']);
714       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
715       $ldap->cd($this->dn);
716       $ldap->add($this->attrs);
717       $this->handle_post_events("add");
718     } else {
719       if ($this->orig_dn != $this->dn){
720         $this->move($this->orig_dn, $this->dn);
721       }
723       $ldap->cd($this->dn);
724       $this->cleanup();
725       $ldap->modify ($this->attrs); 
727       $this->handle_post_events("modify");
728     }
729     show_ldap_error($ldap->get_error(), _("Saving printer failed"));
731     $this->netConfigDNS->cn = $this->cn;
732     $this->netConfigDNS->dn = $this->dn;
733     $this->netConfigDNS->save($this->dn);
735     /* Optionally execute a command after we're done */
736     $this->postcreate();
737   }
739   function generateList(){
740     $a_return=array();
741     foreach($this->member as $type => $values){
742       $a_return[$type]=array();
743       foreach($values as $value){
744         if((preg_match("/Group/i",$type))){
745           if(!isset($value['description'])){
746             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
747           }else{
748             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
749           }
750         }else{
751           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
752         }
753       }
754     }
755     return($a_return);
756   }
761 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
762 ?>