Code

REmoved command overload
[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 $initial_PPD      = "";
22   var $orig_dn          = "";
24   var $UserMember       ="";
25   var $UserMembers      =array();
26   var $UserMemberKeys   =array();
28   var $AdminMember      ="";
29   var $AdminMembers     =array();
30   var $AdminMemberKeys  =array();
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                                 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
46   var $objectclasses  = array("top", "gotoPrinter");
48     var $gotoUserAdminPrinter;
49   var $gotoGroupAdminPrinter ;
50   var $gotoGroupPrinter;
51   var $gotoUserPrinter ;
53   function printgeneric ($config, $dn= NULL,$parent = NULL)
54   {
55     $this->config = $config;
56     $this->dn = $dn; 
57     
58     /* If parent was posted(the tabs object) we can detect the printer type. */
59     if($parent){
60       $this->parent = $parent;
61       $this->getTypeOfPrinter();
62     }else{
63       $this->BelongsTo = "unknown";
64       return;
65     }
67     /* Update dn, to ensure storing as printer instead of WS / terminal */
68     if($this->BelongsTo == "Terminal" || $this->BelongsTo == "TerminalTemplate"){
69       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
70     }
72     if($this->BelongsTo == "Workstation" || $this->BelongsTo == "WorkstationTemplate"){
73       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
74     }
76     $this->orig_dn = $this->dn;
77     $ui= get_userinfo();
79     /* Get printer settings, possibly dn has changed */
80     plugin::plugin ($config, $this->dn);
82     /* Get is_account initially_was_account status */
83     $this->getTypeOfPrinter(true);
85     /* set orig dn to new if object is new */
86     $ldap= $this->config->get_ldap_link();
87     $ldap->cat($this->dn, array('dn'));
88     if(!$ldap->count()){
89       $this->orig_dn = "new";
90     }
91     
92     /* create dns object */
93     $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
95     /* Set base */
96     if ($this->dn == "new"){
97       $this->base= dn2base($ui->dn);
98       $this->cn= "";
99     } else {
100     
101       /* Set base and check if the extracted base exists */
102       if(preg_match("/ou=incoming,/",$this->dn)){
103         $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
104       }else{
105         $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
106       }
108       if(!isset($this->config->idepartments[$this->base])){
109         print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
110         $this->base = $_SESSION['CurrentMainBase'];
111       }
112     }
114     /* Extract selected ppd */
115     if(isset($this->gotoPrinterPPD)){
116       $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
117     }
119     $this->initial_PPD = $this->gotoPrinterPPD;
121     /* Prepare different member types */ 
122     foreach(array("AddUser"       =>"gotoUserPrinter",
123           "AddGroup"      =>"gotoGroupPrinter",
124           "AddAdminUser"  =>"gotoUserAdminPrinter",
125           "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
127       /* $this->members contains all members */
128       $this->member[$type]=array();
130       if (isset($this->attrs[$attr]['count'])) {
131         unset($this->attrs[$attr]['count']);
132       }
134       /* Set tag attribute if we've tagging activated */
135       $tag= "";
136       if ($ui->gosaUnitTag != "" && isset($config->current['STRICT_UNITS']) &&
137           preg_match('/TRUE/i', $config->current['STRICT_UNITS'])){
138         $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
139       }
141       if(isset($this->attrs[$attr])){
142         foreach($this->attrs[$attr] as $mem){
143           if(preg_match("/Group/",$type)){
144             $ldap->search("(&(objectClass=posixGroup)$tag(cn=".$mem."))",array("cn","description"));
145             if($ldap->count()){
146               $entry = $ldap->fetch();
147               if(isset($entry['cn'])){
148                 $this->member[$type][$entry['cn'][0]]=$entry;
149               }
150             }
151           }else{
152             $ldap->search("(&(objectClass=person)$tag(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
153             if($ldap->count()){
154               $entry = $ldap->fetch();
155               if(isset($entry['uid'])){
156                 $this->member[$type][$entry['uid'][0]]=$entry;
157               }
158             }
159           }
160         }
161       }
162     }
163   }
166   /* Detect type of printer.
167    * Printer can be stand alone, belong to a workstation or belong to a terminal. 
168    * We can detect the type printer type when comparing the tabs objects
169    */
170   function getTypeOfPrinter($UpdateAccountStatus = false)
171   {
172     /* Disable account as default
173      */  
174     $this->is_account = $this->initially_was_account = false;
176     /* Detect type of printer via parent tabs.
177      */
178     if(isset($this->parent->by_object['workgeneric'])){
180       /* Exclude templates 
181        */
182       $this->cn = $this->parent->by_object['workgeneric']->cn;
183       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
184         $this->BelongsTo = "WorkstationTemplate";
185       }else{
186         $this->BelongsTo = "Workstation";
187       }
188     }elseif(isset($this->parent->by_object['termgeneric'])){
190       /* Exclude templates 
191        */
192       $this->cn = $this->parent->by_object['termgeneric']->cn;
193       if($this->parent->by_object['termgeneric']->cn == "default"){
194         $this->BelongsTo = "TerminalTemplate";  
195       }else{
196         $this->BelongsTo = "Terminal";
197       }
198     }elseif(isset($this->parent->by_name['printgeneric'])){
199       $this->BelongsTo  = "Printer";
200     }
202     if($UpdateAccountStatus){
204       /* Set is_account / was account 
205        */
206       if($this->dn == "new"){
207         $this->initially_was_account = false;
208       }
210       /* If is printer it must be a true account.
211        */
212       if($this->BelongsTo == "Printer"){
213         $this->is_account = true;
214       }
216       /* Update dn, to ensure storing as printer instead of WS / terminal
217        */
218       if($this->BelongsTo == "Terminal"){
219         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
220       }
222       if($this->BelongsTo == "Workstation"){
223         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
224       }
226       /* Detect if this is a valid printer account;
227        */
228       //FIXME: do we need to do this? we've already everything we need in $this->attrs...
229       $ldap = $this->config->get_ldap_link();
230       $ldap->cat($this->dn, array('objectClass'));
232       if($ldap->count()){
233         $attrs = $ldap->fetch();
234         if(in_array("gotoPrinter",$attrs['objectClass'])){
235           $this->initially_was_account = true;
236           $this->is_account             = true;
237         }else{
238           $this->is_account = false;
239         }
240       }
241     }
242   }
244   function execute()
245   {
246     /* Call parent execute */
247     plugin::execute();
249     /* If type of printer couldn't be detected (because of missing parent object in construction) 
250      * hide this tab.
251      */
252     if($this->BelongsTo == "unknown"){
253       $display= $this->show_header(_("Add printer extension"),
254           _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
255       return($display);
256     }
258     /* Templates can't have printer extensions 
259      */
260     if($this->BelongsTo == "WorkstationTemplate"){
261       $display= $this->show_header(_("Add printer extension"),
262           _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
263       return($display);
264     }
265     if($this->BelongsTo == "TerminalTemplate"){
266       $display= $this->show_header(_("Add printer extension"),
267           _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
268       return($display);
269     }
271     /* Get cn from base object */
272     if($this->BelongsTo == "Workstation"){
273       $this->cn = $this->parent->by_object['workgeneric']->cn;
274     }
275     if($this->BelongsTo == "Terminal"){
276       $this->cn = $this->parent->by_object['termgeneric']->cn;
277     }
279     $smarty= get_smarty();
280     $display="";
282     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
283     if($this->BelongsTo == "Printer"){    
284       $smarty->assign("StandAlone",true);
285     }else{
286       $smarty->assign("StandAlone",false);
287     }
289     /* Do we need to flip is_account state? */
290     if (isset($_POST['modify_state'])){
291       $this->is_modified = true;
292       $this->is_account= !$this->is_account;
293     }
295     /* Do we represent a valid printer? */
296     if (!$this->is_account && $this->parent == NULL){
297       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
298         _("This 'dn' has no printer features.")."</b>";
299       return($display);
300     }
302     /* If this is a WS / Terminal depending printer, display account state button */
303     if($this->BelongsTo != "Printer"){
304       if((empty($this->cn)) && ($this->dn != "new")){
305         $display= $this->show_header(_("Add printer extension"),
306             _("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);
307         $this->is_account= false;
308         return $display;
309       }
311       if (($this->is_account)){
312         if($this->BelongsTo=="Workstation"){
313           $display= $this->show_header(_("Remove printer extension"),
314               _("This workstation has printer extension enabled.You can disable it by clicking below."));
315         }elseif($this->BelongsTo=="Terminal"){
316           $display= $this->show_header(_("Remove printer extension"),
317               _("This terminal has printer extension enabled. You can disable it by clicking below."));
318         }
319       }else{
320         if($this->BelongsTo=="Workstation"){
321           $display= $this->show_header(_("Add printer extension"),
322               _("This workstation has printer extension disabled. You can enable it by clicking below."));
323         }elseif($this->BelongsTo=="Terminal"){
324           $display= $this->show_header(_("Add printer extension"),
325               _("This terminal has printer extension disabled. You can enable it by clicking below."));
326         }  
327         return ($display);
328       }
329     }
331     /* Base select dialog */
332     $once = true;
333     foreach($_POST as $name => $value){
334       if(preg_match("/^chooseBase/",$name) && $once){
335         $once = false;
336         $this->dialog = new baseSelectDialog($this->config);
337         $this->dialog->setCurrentBase($this->base);
338         $this->baseSelection = true;
339       }
340     }
342     /* Dialog handling for base select dialog
343      * Check if base was selected, dialog aborted etc */
344     if(is_object($this->dialog)){
346       $this->dialog->save_object();
347       if($this->baseSelection){
348         if($this->dialog->isClosed()){
349           $this->dialog = false;
350           $this->baseSelection = false;
351         }elseif($this->dialog->isSelected()){
352           $this->base = $this->dialog->isSelected();
353           $this->dialog= false;
354           $this->baseSelection = false;
355         }else{
356           return($this->dialog->execute());
357         }
358       }
359     }
361     /* Fill templating stuff */
362     $smarty->assign("bases", $this->config->idepartments);
363     $smarty->assign("base_select", $this->base);
365     /* Assign attributes */
366     foreach ($this->attributes as $attr){
367       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
368       $smarty->assign("$attr", $this->$attr);
369     }
371     $smarty->assign("baseACL", chkacl($this->acl,"base"));
373     if(isset($_POST['AddUser'])){
374       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
375     }
376     if(isset($_POST['AddGroup'])){
377       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
378     }
379     if(isset($_POST['AddAdminUser'])){
380       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
381     }
382     if(isset($_POST['AddAdminGroup'])){
383       $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
384     }
386     /* Display ppd configure/select dialog      */
387     if(isset($_POST['EditDriver'])){
388       if($this->PPDdialogToSave){
389         $this->dialog = $this->PPDdialogToSave;
390       }else{
391         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
392       }
393     }
395     /* remove ppd */
396     if(isset($_POST['RemoveDriver'])){
397       $this->gotoPrinterPPD = array();
398       $this->PPDdialogToSave = NULL;
399     }
401     /* Close ppd dialog */
402     if(isset($_POST['ClosePPD'])){
403       unset($this->dialog);
404       $this->dialog=NULL;
405     }
407     /* Save selected ppd */
408     if(isset($_POST['SavePPD'])){
409       $this->dialog->save_object();
410       if(count($this->dialog->check())){
411         foreach($this->dialog->check() as $msg){
412           print_red($msg);
413         }
414       }else{
415         $this->gotoPrinterPPD = array();
416         $this->gotoPrinterPPD = $this->dialog->save();
417         $this->PPDdialogToSave = $this->dialog;
418         unset($this->dialog);
419         $this->dialog=NULL;
420       }
421     }
423     /* Member management, delete user / group / admin ..*/
424     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
425       foreach($_POST['UserMember'] as $mem){
426         $this->DelMember('AddUser',$mem);
427       }
428     }
430     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
431       foreach($_POST['UserMember'] as $mem){
432         $this->DelMember('AddGroup',$mem);
433       }
434     }
436     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
437       foreach($_POST['AdminMember'] as $mem){
438         $this->DelMember('AddAdminUser',$mem);
439       }
440     }
442     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
443       foreach($_POST['AdminMember'] as $mem){
444         $this->DelMember('AddAdminGroup',$mem);
445       }
446     }
448     /* Abort user / group adding dialog */
449     if(isset($_POST['PrinterCancel'])){
450       unset($this->dialog);
451       $this->dialog= NULL;
452     }
454     /* Save selected users / groups */
455     if(isset($_POST['PrinterSave'])){
456       $this->dialog->save_object();
457       if(count($this->dialog->check())){
458         foreach($this->dialog->check() as $msg){
459           print_red($msg);
460         }
461       }else{
462         $data= $new = $this->dialog->save();
463         unset($data['type']);
464         foreach($data as $mem){  
465           $this->AddMember($new['type'], $mem['dn']);    
466         }
467         unset($this->dialog);
468         $this->dialog=NULL; 
469       }
470     }
472     /* Display dialog, if there is currently one open*/
473     if($this->dialog != NULL){
474       $this->dialog->save_object();
475       $display = $this->dialog->execute();
476       return $display;
477     }
479     /* Parse selected ppd file */
480     require_once ("class_ppdManager.inc");
481     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
483       $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
484       if(!preg_match("/\/$/",$path)){
485         $path = $path."/";
486       }
488       $ppdManager= new ppdManager($path);
489       if(!empty($this->gotoPrinterPPD)){
490         if((!file_exists($path.$this->gotoPrinterPPD))){
491           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
492         }else{
493           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
494         }
495       }else{
496         $smarty->assign("driverInfo", _("not defined"));
497       }
498     }else{
499       $smarty->assign("driverInfo",_("can't get ppd informations."));
500     }
502     /* Create user & admin user list */
503     $list=$this->generateList();
504     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
505     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
507     asort($userlist);
508     asort($adminlist);
510     if($this->BelongsTo != "Printer"){
511       if($this->BelongsTo == "Terminal"){
512         $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
513       }else{
514         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
515       }
516       $smarty->assign("cnACL"    ," disabled ");
517     }else{
518       $smarty->assign("desc"    ,"");
519     }
520     $smarty->assign("UserMember"    ,$this->UserMember);
521     $smarty->assign("UserMembers"   ,$userlist);
522     $smarty->assign("UserMemberKeys",array_flip($userlist));
524     $smarty->assign("AdminMember"    ,$this->AdminMember);
525     $smarty->assign("AdminMembers"   ,$adminlist);
526     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
527     if($this->BelongsTo == "Printer"){
528       $this->netConfigDNS->cn= $this->cn;
529       $smarty->assign("netconfig", $this->netConfigDNS->execute());
530     } else {
531       $smarty->assign("netconfig", "");
532     }
534     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
535   }
537   function remove_from_parent()
538   {
539     /* Only remove if there was initially an account */
540     if($this->initially_was_account){
542       /* Update dn, to ensure storing as printer instead of WS / terminal
543        */
544       if($this->BelongsTo == "Terminal"){
545         $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
546       }
548       if($this->BelongsTo == "Workstation"){
549         $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
550       }
552       /* Check if this dn points to a printer, to avoid deleting something else */
553       $ldap= $this->config->get_ldap_link();
554       $ldap->cat($this->dn, array('dn',"objectClass"));
555       if(!$ldap->count()){
556         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
557         return;
558       }
560       /* Check if obejct is a printer */
561       $CheckPrinter = $ldap->fetch();
562       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
563         print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
564         return;
565       }
567       /* Remove account & dns extension */ 
568       $this->netConfigDNS->remove_from_parent();
569       $ldap->rmdir($this->dn);
570       show_ldap_error($ldap->get_error(), _("Removing printer failed"));
571       $this->handle_post_events("remove");
573       /* Delete references to object groups */
574       $ldap->cd ($this->config->current['BASE']);
575       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
576       while ($ldap->fetch()){
577         $og= new ogroup($this->config, $ldap->getDN());
578         unset($og->member[$this->dn]);
579         $og->save ();
580       }
582       /* Remove previously selected ppd file.*/
583       if(!empty($this->initial_PPD)){
584         $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
585         $tmp->removeModifiedPPD();
586       }
587     }
588   }
591   /* Save data to object */
592   function save_object()
593   {
594     plugin::save_object();
595     $this->netConfigDNS->save_object();
596     /* Save base, since this is no LDAP attribute */
597     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
598       $this->base= $_POST['base'];
599     }
600   }
602   /* Check supplied data */
603   function check()
604   {
605     /* Call common method to give check the hook */
606     $message= plugin::check();
607     if ($this->BelongsTo == 'printer'){
608       $message= array_merge($message, $this->netConfigDNS->check());
609     }
611     /* Don't display check messages if this is a template object */
612     if(isset($this->parent->by_object['workgeneric'])){
613       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
614         return $message;
615       }
616     }elseif(isset($this->parent->by_object['termgeneric'])){
617       if($this->parent->by_object['termgeneric']->cn == "default"){
618         return $message;
619       }
620     }
622     $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
624     /* must: cn */
625     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
626       $message[]= "The required field 'Printer name' is not set.";
627     }
629     if($this->BelongsTo == "Printer"){
630       $ui= get_userinfo();
631       $acl= get_permissions ($dn, $ui->subtreeACL);
632       $acl= get_module_permission($acl, "printer", $this->dn);
633       if (chkacl($acl, "create") != ""){
634         $message[]= _("You have no permissions to create a printer on this 'Base'.");
635       }
636     }
638     
639     /* must: labeledURI */
640     if(empty($this->labeledURI)){
641       $message[]= "The required field 'Printer URL' is not set.";
642     }
643     
644     /* Check if there is already an entry with this cn*/
645     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
646       $ldap= $this->config->get_ldap_link();
647       $ldap->cd ($this->base);
648       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
649       if ($ldap->count() != 0){
650         while ($attrs= $ldap->fetch()){
651           if ($attrs['dn'] != $this->orig_dn){
652             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
653             break;
654           }
655         }
656       }
657     }
659     return ($message);
660   }
663   /* Save to LDAP */
664   function save()
665   {
666     /* Update dn, to ensure storing as printer instead of WS / terminal
667      */
668     if($this->BelongsTo == "Terminal"){
669       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
670     }
672     if($this->BelongsTo == "Workstation"){
673       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
674       $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
675       $this->netConfigDNS->macAddress = $mac;
676     }
677     
678     if(!$this->is_account) return;
679     if(isset($this->parent->by_object['workgeneric'])){
680       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
681         return;
682       }
683     }elseif(isset($this->parent->by_object['termgeneric'])){
684       if($this->parent->by_object['termgeneric']->cn == "default"){
685         return;
686       }
687     }
689     /* If type is still unknown, the initialisation of this printer failed, abort. */
690     if($this->BelongsTo == "unknown"){
691       return;
692     }
694     /* save ppd configuration */
695     if($this->PPDdialogToSave){
696       $this->PPDdialogToSave->save_ppd();
697     }
699     /* Remove previously selected ppd file.*/
700     if($this->initial_PPD != $this->gotoPrinterPPD){
701       if(!empty($this->initial_PPD)){
702         $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
703         $tmp->removeModifiedPPD();
704       }
705     }
707     if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
708       $method="https://";
709     }else{
710       $method="http://";
711     }
713     /* If no ppd is selected, remove this attribute */
714     if(!empty($this->gotoPrinterPPD)) {
715       $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
716     }else{
717       $this->gotoPrinterPPD = array();
718     }
720     $dn= $this->dn;
721     plugin::save();
722     $ldap= $this->config->get_ldap_link();
724     /* reduce objectClasses to minimun */
725     $this->attrs['objectClass']= $this->objectclasses;
727     /* Remove all empty values */
728     if ($this->orig_dn == 'new'){
729       $attrs= array();
730       foreach ($this->attrs as $key => $val){
731         if (is_array($val) && count($val) == 0){
732           continue;
733         }
734         $attrs[$key]= $val;
735       }
736       $this->attrs= $attrs;
737     }
739     /* Append printer user 
740      */
741     $this->attrs['gotoUserPrinter']=array();
742     foreach($this->member['AddUser'] as $mem){
743       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
744     }
746     /* Append printer group 
747      */
748     $this->attrs['gotoGroupPrinter'] = array();
749     foreach($this->member['AddGroup'] as $mem){
750       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
751     }
753     /* Append printer admin user 
754      */
755     $this->attrs['gotoUserAdminPrinter'] =array();
756     foreach($this->member['AddAdminUser'] as $mem){
757       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
758     }
760     /* Append printer admin group 
761      */
762     $this->attrs['gotoGroupAdminPrinter'] = array();
763     foreach($this->member['AddAdminGroup'] as $mem){
764       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
765     }
767     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
768       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
769     }
771     if($this->orig_dn == 'new'){
772       foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
773         if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
774           unset($this->attrs[$checkVar]);
775         }
776       }
777     }
779     /* Ensure to create a new object */
780     if(preg_match("/ou=incoming,/",$this->orig_dn)){
781       $this->orig_dn = "new";
782     }
784     /* Write back to ldap */
785     $ldap= $this->config->get_ldap_link();
786     if ($this->orig_dn == 'new'){
787       $ldap->cd($this->config->current['BASE']);
788       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
789       $ldap->cd($this->dn);
790      
791       /* Remove empty values */ 
792       foreach($this->attrs as $name => $value){
793         if(empty($value)){
794           unset($this->attrs[$name]);
795         }
796       }
797       
798       $ldap->add($this->attrs);
799       $this->handle_post_events("add");
800     } else {
801       if ($this->orig_dn != $this->dn){
802         $this->move($this->orig_dn, $this->dn);
803       }
805       $ldap->cd($this->dn);
806       $this->cleanup();
807       $ldap->modify ($this->attrs); 
809       $this->handle_post_events("modify");
810     }
811     show_ldap_error($ldap->get_error(), _("Saving printer failed"));
814     $this->netConfigDNS->cn = $this->cn;
815     $this->netConfigDNS->dn = $this->dn;
816     $this->netConfigDNS->save($this->dn);
818     /* Optionally execute a command after we're done */
819     $this->postcreate();
821     /* This is a multi object. Handle tagging here... */
822     $this->handle_object_tagging();
823   }
825   function generateList(){
826     $a_return=array();
827     foreach($this->member as $type => $values){
828       $a_return[$type]=array();
829       foreach($values as $value){
830         if((preg_match("/Group/i",$type))){
831           if(!isset($value['description'])){
832             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
833           }else{
834             $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
835           }
836         }else{
837           $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
838         }
839       }
840     }
841     return($a_return);
842   }
844   /* Delete member */
845   function DelMember($type,$id)
846   {
847     if(isset($this->member[$type][$id])){
848       unset($this->member[$type][$id]);
849     }
850   }
852   /* Add given obejct to members */
853   function AddMember($type,$dn)
854   {
855     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
856     if(!in_array_ics($type, $types)){
857       print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
858       return;
859     }
861     /* Get name of index attributes */
862     if(preg_match("/user/i",$type)){
863       $var = "uid";
864     }else{
865       $var = "cn";
866     }
868     $ldap = $this->config->get_ldap_link();
869     $ldap->cd($dn);
870     $ldap->cat($dn,array("cn","uid"));
871     if($ldap->count()){
873       $attrs = $ldap->fetch();
874       $name = $attrs[$var][0];
876       /* Check if this uid/cn is already assigned to any permission */
877       foreach($types as $ctype){
878         if(isset(  $this->member[$ctype][$name])){
879           print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
880           return;
881         }
882       }
884       /* Everything is fine. So add the given object to members */
885       $this->member[$type][$attrs[$var][0]] = $attrs ;
886     }else{
887       print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
888     }
889   }
892 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
893 ?>