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;
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 }
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 {
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> <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 $smarty->assign("netconfig", $this->netConfigDNS->execute());
529 } else {
530 $smarty->assign("netconfig", "");
531 }
533 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
534 }
536 function remove_from_parent()
537 {
538 /* Only remove if there was initially an account */
539 if($this->initially_was_account){
541 /* Update dn, to ensure storing as printer instead of WS / terminal
542 */
543 if($this->BelongsTo == "Terminal"){
544 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
545 }
547 if($this->BelongsTo == "Workstation"){
548 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
549 }
551 /* Check if this dn points to a printer, to avoid deleting something else */
552 $ldap= $this->config->get_ldap_link();
553 $ldap->cat($this->dn, array('dn',"objectClass"));
554 if(!$ldap->count()){
555 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
556 return;
557 }
559 /* Check if obejct is a printer */
560 $CheckPrinter = $ldap->fetch();
561 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
562 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
563 return;
564 }
566 /* Remove account & dns extension */
567 $this->netConfigDNS->remove_from_parent();
568 $ldap->rmdir($this->dn);
569 show_ldap_error($ldap->get_error(), _("Removing printer failed"));
570 $this->handle_post_events("remove");
572 /* Delete references to object groups */
573 $ldap->cd ($this->config->current['BASE']);
574 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
575 while ($ldap->fetch()){
576 $og= new ogroup($this->config, $ldap->getDN());
577 unset($og->member[$this->dn]);
578 $og->save ();
579 }
581 /* Remove previously selected ppd file.*/
582 if(!empty($this->initial_PPD)){
583 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
584 $tmp->removeModifiedPPD();
585 }
586 }
587 }
590 /* Save data to object */
591 function save_object()
592 {
593 plugin::save_object();
594 $this->netConfigDNS->save_object();
595 /* Save base, since this is no LDAP attribute */
596 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
597 $this->base= $_POST['base'];
598 }
599 }
601 /* Check supplied data */
602 function check()
603 {
604 /* Call common method to give check the hook */
605 $message= plugin::check();
606 if ($this->BelongsTo == 'printer'){
607 $message= array_merge($message, $this->netConfigDNS->check());
608 }
610 /* Don't display check messages if this is a template object */
611 if(isset($this->parent->by_object['workgeneric'])){
612 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
613 return $message;
614 }
615 }elseif(isset($this->parent->by_object['termgeneric'])){
616 if($this->parent->by_object['termgeneric']->cn == "default"){
617 return $message;
618 }
619 }
621 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
623 /* must: cn */
624 if(($this->BelongsTo == "Printer") && (empty($this->cn))){
625 $message[]= "The required field 'Printer name' is not set.";
626 }
628 if($this->BelongsTo == "Printer"){
629 $ui= get_userinfo();
630 $acl= get_permissions ($dn, $ui->subtreeACL);
631 $acl= get_module_permission($acl, "printer", $this->dn);
632 if (chkacl($acl, "create") != ""){
633 $message[]= _("You have no permissions to create a printer on this 'Base'.");
634 }
635 }
638 /* must: labeledURI */
639 if(empty($this->labeledURI)){
640 $message[]= "The required field 'Printer URL' is not set.";
641 }
643 /* Check if there is already an entry with this cn*/
644 if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
645 $ldap= $this->config->get_ldap_link();
646 $ldap->cd ($this->base);
647 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
648 if ($ldap->count() != 0){
649 while ($attrs= $ldap->fetch()){
650 if ($attrs['dn'] != $this->orig_dn){
651 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
652 break;
653 }
654 }
655 }
656 }
658 return ($message);
659 }
662 /* Save to LDAP */
663 function save()
664 {
665 /* Update dn, to ensure storing as printer instead of WS / terminal
666 */
667 if($this->BelongsTo == "Terminal"){
668 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
669 }
671 if($this->BelongsTo == "Workstation"){
672 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
673 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
674 $this->netConfigDNS->macAddress = $mac;
675 }
677 if(!$this->is_account) return;
678 if(isset($this->parent->by_object['workgeneric'])){
679 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
680 return;
681 }
682 }elseif(isset($this->parent->by_object['termgeneric'])){
683 if($this->parent->by_object['termgeneric']->cn == "default"){
684 return;
685 }
686 }
688 /* If type is still unknown, the initialisation of this printer failed, abort. */
689 if($this->BelongsTo == "unknown"){
690 return;
691 }
693 /* save ppd configuration */
694 if($this->PPDdialogToSave){
695 $this->PPDdialogToSave->save_ppd();
696 }
698 /* Remove previously selected ppd file.*/
699 if($this->initial_PPD != $this->gotoPrinterPPD){
700 if(!empty($this->initial_PPD)){
701 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
702 $tmp->removeModifiedPPD();
703 }
704 }
706 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
707 $method="https://";
708 }else{
709 $method="http://";
710 }
712 /* If no ppd is selected, remove this attribute */
713 if(!empty($this->gotoPrinterPPD)) {
714 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
715 }else{
716 $this->gotoPrinterPPD = array();
717 }
719 $dn= $this->dn;
720 plugin::save();
721 $ldap= $this->config->get_ldap_link();
723 /* reduce objectClasses to minimun */
724 $this->attrs['objectClass']= $this->objectclasses;
726 /* Remove all empty values */
727 if ($this->orig_dn == 'new'){
728 $attrs= array();
729 foreach ($this->attrs as $key => $val){
730 if (is_array($val) && count($val) == 0){
731 continue;
732 }
733 $attrs[$key]= $val;
734 }
735 $this->attrs= $attrs;
736 }
738 /* Append printer user
739 */
740 $this->attrs['gotoUserPrinter']=array();
741 foreach($this->member['AddUser'] as $mem){
742 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
743 }
745 /* Append printer group
746 */
747 $this->attrs['gotoGroupPrinter'] = array();
748 foreach($this->member['AddGroup'] as $mem){
749 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
750 }
752 /* Append printer admin user
753 */
754 $this->attrs['gotoUserAdminPrinter'] =array();
755 foreach($this->member['AddAdminUser'] as $mem){
756 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
757 }
759 /* Append printer admin group
760 */
761 $this->attrs['gotoGroupAdminPrinter'] = array();
762 foreach($this->member['AddAdminGroup'] as $mem){
763 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
764 }
766 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
767 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
768 }
770 if($this->orig_dn == 'new'){
771 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
772 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
773 unset($this->attrs[$checkVar]);
774 }
775 }
776 }
778 /* Ensure to create a new object */
779 if(preg_match("/ou=incoming,/",$this->orig_dn)){
780 $this->orig_dn = "new";
781 }
783 /* Write back to ldap */
784 $ldap= $this->config->get_ldap_link();
785 if ($this->orig_dn == 'new'){
786 $ldap->cd($this->config->current['BASE']);
787 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
788 $ldap->cd($this->dn);
790 /* Remove empty values */
791 foreach($this->attrs as $name => $value){
792 if(empty($value)){
793 unset($this->attrs[$name]);
794 }
795 }
797 $ldap->add($this->attrs);
798 $this->handle_post_events("add");
799 } else {
800 if ($this->orig_dn != $this->dn){
801 $this->move($this->orig_dn, $this->dn);
802 }
804 $ldap->cd($this->dn);
805 $this->cleanup();
806 $ldap->modify ($this->attrs);
808 $this->handle_post_events("modify");
809 }
810 show_ldap_error($ldap->get_error(), _("Saving printer failed"));
813 $this->netConfigDNS->cn = $this->cn;
814 $this->netConfigDNS->dn = $this->dn;
815 $this->netConfigDNS->save($this->dn);
817 /* Optionally execute a command after we're done */
818 $this->postcreate();
820 /* This is a multi object. Handle tagging here... */
821 $this->handle_object_tagging();
822 }
824 function generateList(){
825 $a_return=array();
826 foreach($this->member as $type => $values){
827 $a_return[$type]=array();
828 foreach($values as $value){
829 if((preg_match("/Group/i",$type))){
830 if(!isset($value['description'])){
831 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
832 }else{
833 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
834 }
835 }else{
836 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
837 }
838 }
839 }
840 return($a_return);
841 }
843 /* Delete member */
844 function DelMember($type,$id)
845 {
846 if(isset($this->member[$type][$id])){
847 unset($this->member[$type][$id]);
848 }
849 }
851 /* Add given obejct to members */
852 function AddMember($type,$dn)
853 {
854 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
855 if(!in_array_ics($type, $types)){
856 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
857 return;
858 }
860 /* Get name of index attributes */
861 if(preg_match("/user/i",$type)){
862 $var = "uid";
863 }else{
864 $var = "cn";
865 }
867 $ldap = $this->config->get_ldap_link();
868 $ldap->cd($dn);
869 $ldap->cat($dn,array("cn","uid"));
870 if($ldap->count()){
872 $attrs = $ldap->fetch();
873 $name = $attrs[$var][0];
875 /* Check if this uid/cn is already assigned to any permission */
876 foreach($types as $ctype){
877 if(isset( $this->member[$ctype][$name])){
878 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
879 return;
880 }
881 }
883 /* Everything is fine. So add the given object to members */
884 $this->member[$type][$attrs[$var][0]] = $attrs ;
885 }else{
886 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
887 }
888 }
889 }
891 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
892 ?>