Code

9cccd381a2afd013918ff2dcada07f989a971ad6
[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 $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; 
56     
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     }
90     
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 {
99     
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>&nbsp;<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     }
628     
629     /* must: labeledURI */
630     if(empty($this->labeledURI)){
631       $message[]= "The required field 'Printer URL' is not set.";
632     }
633     
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       $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
665       $this->netConfigDNS->macAddress = $mac;
666     }
667     
668     if(!$this->is_account) return;
669     if(isset($this->parent->by_object['workgeneric'])){
670       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
671         return;
672       }
673     }elseif(isset($this->parent->by_object['termgeneric'])){
674       if($this->parent->by_object['termgeneric']->cn == "default"){
675         return;
676       }
677     }
679     /* If type is still unknown, the initialisation of this printer failed, abort. */
680     if($this->BelongsTo == "unknown"){
681       return;
682     }
684     /* save ppd configuration */
685     if($this->PPDdialogToSave){
686       $this->PPDdialogToSave->save_ppd();
687     }
689     $dn= $this->dn;
690     plugin::save();
691     $ldap= $this->config->get_ldap_link();
693     /* reduce objectClasses to minimun */
694     $this->attrs['objectClass']= $this->objectclasses;
696     /* Remove all empty values */
697     if ($this->orig_dn == 'new'){
698       $attrs= array();
699       foreach ($this->attrs as $key => $val){
700         if (is_array($val) && count($val) == 0){
701           continue;
702         }
703         $attrs[$key]= $val;
704       }
705       $this->attrs= $attrs;
706     }
708     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
709       $method="https://";
710     }else{
711       $method="http://";
712     }
714     /* Only save ppd path, if the path is not empty (no ppd selected )*/ 
715     if(count($this->gotoPrinterPPD)) {
716       $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
717     }else{
718       $this->attrs['gotoPrinterPPD'] = array();
719     }
721     /* Append printer user 
722      */
723     $this->attrs['gotoUserPrinter']=array();
724     foreach($this->member['AddUser'] as $mem){
725       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
726     }
728     /* Append printer group 
729      */
730     $this->attrs['gotoGroupPrinter'] = array();
731     foreach($this->member['AddGroup'] as $mem){
732       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
733     }
735     /* Append printer admin user 
736      */
737     $this->attrs['gotoUserAdminPrinter'] =array();
738     foreach($this->member['AddAdminUser'] as $mem){
739       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
740     }
742     /* Append printer admin group 
743      */
744     $this->attrs['gotoGroupAdminPrinter'] = array();
745     foreach($this->member['AddAdminGroup'] as $mem){
746       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
747     }
749     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
750       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
751     }
753     if($this->orig_dn == 'new'){
754       foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
755         if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
756           unset($this->attrs[$checkVar]);
757         }
758       }
759     }
761     /* Write back to ldap */
762     $ldap= $this->config->get_ldap_link();
763     if ($this->orig_dn == 'new'){
764       $ldap->cd($this->config->current['BASE']);
765       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
766       $ldap->cd($this->dn);
767       $ldap->add($this->attrs);
768       $this->handle_post_events("add");
769     } else {
770       if ($this->orig_dn != $this->dn){
771         $this->move($this->orig_dn, $this->dn);
772       }
774       $ldap->cd($this->dn);
775       $this->cleanup();
776       $ldap->modify ($this->attrs); 
778       $this->handle_post_events("modify");
779     }
780     show_ldap_error($ldap->get_error(), _("Saving printer failed"));
783     $this->netConfigDNS->cn = $this->cn;
784     $this->netConfigDNS->dn = $this->dn;
785     $this->netConfigDNS->save($this->dn);
787     /* Optionally execute a command after we're done */
788     $this->postcreate();
790     /* This is a multi object. Handle tagging here... */
791     $this->handle_object_tagging();
792   }
794   function generateList(){
795     $a_return=array();
796     foreach($this->member as $type => $values){
797       $a_return[$type]=array();
798       foreach($values as $value){
799         if((preg_match("/Group/i",$type))){
800           if(!isset($value['description'])){
801             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
802           }else{
803             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
804           }
805         }else{
806           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
807         }
808       }
809     }
810     return($a_return);
811   }
813   /* Delete member */
814   function DelMember($type,$id)
815   {
816     if(isset($this->member[$type][$id])){
817       unset($this->member[$type][$id]);
818     }
819   }
821   /* Add given obejct to members */
822   function AddMember($type,$dn)
823   {
824     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
825     if(!in_array_ics($type, $types)){
826       print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
827       return;
828     }
830     /* Get name of index attributes */
831     if(preg_match("/user/i",$type)){
832       $var = "uid";
833     }else{
834       $var = "cn";
835     }
837     $ldap = $this->config->get_ldap_link();
838     $ldap->cd($dn);
839     $ldap->cat($dn,array("cn","uid"));
840     if($ldap->count()){
842       $attrs = $ldap->fetch();
843       $name = $attrs[$var][0];
845       /* Check if this uid/cn is already assigned to any permission */
846       foreach($types as $ctype){
847         if(isset(  $this->member[$ctype][$name])){
848           print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
849           return;
850         }
851       }
853       /* Everything is fine. So add the given object to members */
854       $this->member[$type][$attrs[$var][0]] = $attrs ;
855     }else{
856       print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
857     }
858   }
861 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
862 ?>