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 var $gotoUserAdminPrinter;
44 var $gotoGroupAdminPrinter ;
45 var $gotoGroupPrinter;
46 var $gotoUserPrinter ;
48 /* attribute list for save action */
49 var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
50 "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
51 var $objectclasses = array("top", "gotoPrinter");
53 var $parent;
55 function printgeneric ($config, $dn,$parent_init,$parent)
56 {
57 $this->config = $config;
58 $this->dn = $dn;
60 /* If parent was posted(the tabs object) we can detect the printer type. */
61 if($parent){
62 $this->parent = $parent;
63 $this->getTypeOfPrinter();
64 }else{
65 $this->BelongsTo = "unknown";
66 return;
67 }
69 /* Update dn, to ensure storing as printer instead of WS / terminal */
70 if(preg_match("/Terminal/i",$this->BelongsTo) || preg_match("/TerminalTemplate/i",$this->BelongsTo)){
71 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
72 }
74 if(preg_match("/Workstation/i",$this->BelongsTo) || preg_match("/WorkstationTemplate/i",$this->BelongsTo)){
75 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
76 }
78 $this->orig_dn = $this->dn;
80 /* Get printer settings, possibly dn has changed */
81 plugin::plugin ($config, $this->dn);
83 /* Get is_account initially_was_account status */
84 $this->getTypeOfPrinter(true);
86 /* set orig dn to new if object is new */
87 $ldap= $this->config->get_ldap_link();
88 $ldap->cat($this->dn, array('dn'));
89 if(!$ldap->count()){
90 $this->orig_dn = "new";
91 }
93 /* create dns object */
94 $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
96 /* Set base */
97 if ($this->dn == "new"){
98 $ui= get_userinfo();
99 $this->base= dn2base($ui->dn);
100 $this->cn= "";
101 } else {
103 /* Set base and check if the extracted base exists */
104 if(preg_match("/ou=incoming,/",$this->dn)){
105 $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
106 }else{
107 $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
108 }
110 if(!isset($this->config->idepartments[$this->base])){
111 print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
112 $this->base = $_SESSION['CurrentMainBase'];
113 }
114 }
116 /* Extract selected ppd */
117 if(isset($this->gotoPrinterPPD)){
118 $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
119 }
121 $this->initial_PPD = $this->gotoPrinterPPD;
123 /* Prepare different member types */
124 foreach(array("AddUser" =>"gotoUserPrinter",
125 "AddGroup" =>"gotoGroupPrinter",
126 "AddAdminUser" =>"gotoUserAdminPrinter",
127 "AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
129 /* $this->members contains all members */
130 $this->member[$type]=array();
132 if (isset($this->attrs[$attr]['count'])) {
133 unset($this->attrs[$attr]['count']);
134 }
136 if(isset($this->attrs[$attr])){
137 foreach($this->attrs[$attr] as $mem){
138 if(preg_match("/Group/",$type)){
139 $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
140 if($ldap->count()){
141 $entry = $ldap->fetch();
142 $this->member[$type][$entry['cn'][0]]=$entry;
143 }
144 }else{
145 $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
146 if($ldap->count()){
147 $entry = $ldap->fetch();
148 $this->member[$type][$entry['uid'][0]]=$entry;
149 }
150 }
151 }
152 }
153 }
154 }
156 function set_acl_base($base)
157 {
158 plugin::set_acl_base($base);
159 if(is_object($this->netConfigDNS)){
160 $this->netConfigDNS->set_acl_base($base);
161 }
162 }
164 function set_acl_category($cat)
165 {
166 plugin::set_acl_category($cat);
167 if(is_object($this->netConfigDNS)){
168 $this->netConfigDNS->set_acl_category($cat);
169 }
170 }
172 /* Detect type of printer.
173 * Printer can be stand alone, belong to a workstation or belong to a terminal.
174 * We can detect the type printer type when comparing the tabs objects
175 */
176 function getTypeOfPrinter($UpdateAccountStatus = false)
177 {
178 /* Disable account as default
179 */
180 $this->is_account = $this->initially_was_account = false;
182 /* Detect type of printer via parent tabs.
183 */
185 $class = get_class($this->parent);
186 if(isset($this->parent->by_object['workgeneric'])){
188 /* Exclude templates
189 */
190 $this->cn = $this->parent->by_object['workgeneric']->cn;
191 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
192 $this->BelongsTo = "WorkstationTemplate";
193 }else{
194 $this->BelongsTo = "Workstation";
195 }
196 }elseif(isset($this->parent->by_object['termgeneric'])){
198 /* Exclude templates
199 */
200 $this->cn = $this->parent->by_object['termgeneric']->cn;
201 if($this->parent->by_object['termgeneric']->cn == "default"){
202 $this->BelongsTo = "TerminalTemplate";
203 }else{
204 $this->BelongsTo = "Terminal";
205 }
206 }elseif(isset($this->parent->by_name['printgeneric'])){
207 $this->BelongsTo = "Printer";
208 }
210 if($UpdateAccountStatus){
212 /* Set is_account / was account
213 */
214 if($this->dn == "new"){
215 $this->initially_was_account = false;
216 }
218 /* If is printer it must be a true account.
219 */
220 if(preg_match("/printer/i",$this->BelongsTo)){
221 $this->is_account = true;
222 }
224 /* Update dn, to ensure storing as printer instead of WS / terminal
225 */
226 if(preg_match("/terminal/i",$this->BelongsTo)){
227 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
228 }
230 if(preg_match("/workstation/i",$this->BelongsTo)){
231 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
232 }
234 /* Detect if this is a valid printer account;
235 */
236 $ldap = $this->config->get_ldap_link();
237 $ldap->cat($this->dn, array('objectClass'));
239 if($ldap->count()){
240 $attrs = $ldap->fetch();
241 if(in_array("gotoPrinter",$attrs['objectClass'])){
242 $this->initially_was_account = true;
243 $this->is_account = true;
244 }else{
245 $this->is_account = false;
246 }
247 }
248 }
249 }
251 function execute()
252 {
253 /* Call parent execute */
254 plugin::execute();
256 /* If type of printer couldn't be detected (because of missing parent object in construction)
257 * hide this tab.
258 */
259 if(preg_match("/unknown/i",$this->BelongsTo)){
260 $display= $this->show_enable_header(_("Add printer extension"),
261 _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
262 return($display);
263 }
265 /* Templates can't have printer extensions
266 */
267 if(preg_match("/WorkstationTemplate/i",$this->BelongsTo)){
268 $display= $this->show_enable_header(_("Add printer extension"),
269 _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
270 return($display);
271 }
272 if(preg_match("/TerminalTemplate/i",$this->BelongsTo)){
273 $display= $this->show_enable_header(_("Add printer extension"),
274 _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
275 return($display);
276 }
278 /* Get cn from base object */
279 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
280 $this->cn = $this->parent->by_object['workgeneric']->cn;
281 }
282 if(preg_match("/^Terminal$/i",$this->BelongsTo)){
283 $this->cn = $this->parent->by_object['termgeneric']->cn;
284 }
286 $smarty= get_smarty();
288 /* Assign acls */
289 $tmp = $this->plInfo();
290 foreach($tmp['plProvidedAcls'] as $name => $translation){
291 $smarty->assign($name."ACL", $this->getacl($name));
292 }
294 $display="";
296 /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
297 if(preg_match("/^Printer$/i",$this->BelongsTo)){
298 $smarty->assign("StandAlone",true);
299 }else{
300 $smarty->assign("StandAlone",false);
301 }
303 /* Do we need to flip is_account state? */
304 if(isset($_POST['modify_state'])){
305 if($this->is_account && $this->acl_is_removeable()){
306 $this->is_account= FALSE;
307 }elseif(!$this->is_account && $this->acl_is_createable()){
308 $this->is_account= TRUE;
309 }
310 }
312 /* Do we represent a valid printer? */
313 if (!$this->is_account && $this->parent == NULL){
314 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
315 _("This 'dn' has no printer features.")."</b>";
316 return($display);
317 }
319 /* If this is a WS / Terminal depending printer, display account state button */
320 if(!preg_match("/^Printer$/i",$this->BelongsTo)){
321 if((empty($this->cn)) && ($this->dn != "new")){
322 $display= $this->show_enable_header(_("Add printer extension"),
323 _("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);
324 $this->is_account= false;
325 return $display;
326 }
328 if (($this->is_account)){
329 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
330 $display= $this->show_disable_header(_("Remove printer extension"),
331 _("This workstation has printer extension enabled.You can disable it by clicking below."));
332 }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
333 $display= $this->show_disable_header(_("Remove printer extension"),
334 _("This terminal has printer extension enabled. You can disable it by clicking below."));
335 }
336 }else{
337 if(preg_match("/^Workstation$/i",$this->BelongsTo)){
338 $display= $this->show_disable_header(_("Add printer extension"),
339 _("This workstation has printer extension disabled. You can enable it by clicking below."));
340 }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
341 $display= $this->show_enable_header(_("Add printer extension"),
342 _("This terminal has printer extension disabled. You can enable it by clicking below."));
343 }
344 return ($display);
345 }
346 }
348 /* Base select dialog */
349 $once = true;
350 foreach($_POST as $name => $value){
351 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
352 $once = false;
353 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
354 $this->dialog->setCurrentBase($this->base);
355 $this->baseSelection = true;
356 }
357 }
359 /* Dialog handling for base select dialog
360 * Check if base was selected, dialog aborted etc */
361 if(is_object($this->dialog)){
363 $this->dialog->save_object();
364 if($this->baseSelection){
365 if($this->dialog->isClosed()){
366 $this->dialog = false;
367 $this->baseSelection = false;
368 }elseif($this->dialog->isSelected()){
370 /* A new base was selected, check if it is a valid one */
371 $tmp = $this->get_allowed_bases();
372 if(isset($tmp[$this->dialog->isSelected()])){
373 $this->base = $this->dialog->isSelected();
374 }
376 $this->dialog= false;
377 $this->baseSelection = false;
378 }else{
379 return($this->dialog->execute());
380 }
381 }
382 }
384 /* Fill templating stuff */
385 $smarty->assign("bases", $this->get_allowed_bases());
386 $smarty->assign("base_select", $this->base);
388 /* Assign attributes */
389 foreach ($this->attributes as $attr){
390 $smarty->assign("$attr", $this->$attr);
391 }
393 if(isset($_POST['AddUser'])){
394 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
395 }
396 if(isset($_POST['AddGroup'])){
397 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
398 }
399 if(isset($_POST['AddAdminUser'])){
400 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
401 }
402 if(isset($_POST['AddAdminGroup'])){
403 $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
404 }
406 /* Display ppd configure/select dialog */
407 if(isset($_POST['EditDriver'])){
408 if($this->PPDdialogToSave){
409 $this->dialog = $this->PPDdialogToSave;
410 }else{
411 $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
412 $this->dialog->cn= $this->cn;
413 }
414 }
416 /* remove ppd */
417 if(isset($_POST['RemoveDriver'])){
418 $this->gotoPrinterPPD = array();
419 $this->PPDdialogToSave = NULL;
420 }
422 /* Close ppd dialog */
423 if(isset($_POST['ClosePPD'])){
424 unset($this->dialog);
425 $this->dialog=NULL;
426 }
428 /* Save selected ppd */
429 if(isset($_POST['SavePPD'])){
430 $this->dialog->save_object();
431 if(count($this->dialog->check())){
432 foreach($this->dialog->check() as $msg){
433 print_red($msg);
434 }
435 }else{
436 $this->gotoPrinterPPD = array();
437 $this->gotoPrinterPPD = $this->dialog->save();
438 $this->PPDdialogToSave = $this->dialog;
439 unset($this->dialog);
440 $this->dialog=NULL;
441 }
442 }
444 /* Member management, delete user / group / admin ..*/
445 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
446 foreach($_POST['UserMember'] as $mem){
447 $this->DelMember('AddUser',$mem);
448 }
449 }
451 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
452 foreach($_POST['UserMember'] as $mem){
453 $this->DelMember('AddGroup',$mem);
454 }
455 }
457 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
458 foreach($_POST['AdminMember'] as $mem){
459 $this->DelMember('AddAdminUser',$mem);
460 }
461 }
463 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
464 foreach($_POST['AdminMember'] as $mem){
465 $this->DelMember('AddAdminGroup',$mem);
466 }
467 }
469 /* Abort user / group adding dialog */
470 if(isset($_POST['PrinterCancel'])){
471 unset($this->dialog);
472 $this->dialog= NULL;
473 }
475 /* Save selected users / groups */
476 if(isset($_POST['PrinterSave'])){
477 $this->dialog->save_object();
478 if(count($this->dialog->check())){
479 foreach($this->dialog->check() as $msg){
480 print_red($msg);
481 }
482 }else{
483 $data= $new = $this->dialog->save();
484 unset($data['type']);
485 foreach($data as $mem){
486 $this->AddMember($new['type'], $mem['dn']);
487 }
488 unset($this->dialog);
489 $this->dialog=NULL;
490 }
491 }
493 /* Display dialog, if there is currently one open*/
494 if($this->dialog != NULL){
495 $this->dialog->save_object();
496 $display = $this->dialog->execute();
497 return $display;
498 }
500 /* Parse selected ppd file */
501 require_once ("class_ppdManager.inc");
502 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
504 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
505 if(!preg_match("/\/$/",$path)){
506 $path = $path."/";
507 }
509 $ppdManager= new ppdManager($path);
510 if(!empty($this->gotoPrinterPPD)){
511 if((!file_exists($path.$this->gotoPrinterPPD))){
512 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
513 }else{
514 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
515 }
516 }else{
517 $smarty->assign("driverInfo", _("not defined"));
518 }
519 }else{
520 $smarty->assign("driverInfo",_("can't get ppd informations."));
521 }
523 /* Create user & admin user list */
524 $list=$this->generateList();
525 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
526 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
528 asort($userlist);
529 asort($adminlist);
531 if(!preg_match("/Printer/i",$this->BelongsTo)){
532 if(preg_match("/Terminal/i",$this->BelongsTo)){
533 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
534 }else{
535 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
536 }
537 $smarty->assign("cnACL" , $this->getacl("cn",true));
538 }else{
539 $smarty->assign("desc" ,"");
540 }
541 $smarty->assign("UserMember" ,$this->UserMember);
542 $smarty->assign("UserMembers" ,$userlist);
543 $smarty->assign("UserMemberKeys",array_flip($userlist));
545 $smarty->assign("AdminMember" ,$this->AdminMember);
546 $smarty->assign("AdminMembers" ,$adminlist);
547 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
548 if(preg_match("/Printer/i",$this->BelongsTo)){
549 $smarty->assign("netconfig", $this->netConfigDNS->execute());
550 } else {
551 $smarty->assign("netconfig", "");
552 }
554 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
555 }
557 function remove_from_parent()
558 {
559 /* Only remove if there was initially an account */
560 if($this->initially_was_account){
562 /* Update dn, to ensure storing as printer instead of WS / terminal
563 */
564 if(preg_match("/terminal/i",$this->BelongsTo)){
565 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
566 }
568 if(preg_match("/workstation/i",$this->BelongsTo)){
569 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
570 }
572 /* Check if this dn points to a printer, to avoid deleting something else */
573 $ldap= $this->config->get_ldap_link();
574 $ldap->cat($this->dn, array('dn',"objectClass"));
575 if(!$ldap->count()){
576 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
577 return;
578 }
580 /* Check if obejct is a printer */
581 $CheckPrinter = $ldap->fetch();
582 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
583 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
584 return;
585 }
587 /* Remove account & dns extension */
588 $this->netConfigDNS->remove_from_parent();
589 $ldap->rmdir($this->dn);
590 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
591 $this->handle_post_events("remove");
593 /* Delete references to object groups */
594 $ldap->cd ($this->config->current['BASE']);
595 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
596 while ($ldap->fetch()){
597 $og= new ogroup($this->config, $ldap->getDN());
598 unset($og->member[$this->dn]);
599 $og->save ();
600 }
602 /* Remove previously selected ppd file.*/
603 if(!empty($this->initial_PPD)){
604 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
605 $tmp->removeModifiedPPD();
606 }
607 }
608 }
611 /* Save data to object */
612 function save_object()
613 {
614 /* Create a base backup and reset the
615 base directly after calling plugin::save_object();
616 Base will be set seperatly a few lines below */
617 $base_tmp = $this->base;
618 plugin::save_object();
619 $this->base = $base_tmp;
621 if(is_object($this->netConfigDNS)){
622 $this->netConfigDNS->save_object();
623 }
625 /* Set new base if allowed */
626 $tmp = $this->get_allowed_bases();
627 if(isset($_POST['base'])){
628 if(isset($tmp[$_POST['base']])){
629 $this->base= $_POST['base'];
630 }
631 }
632 }
634 /* Check supplied data */
635 function check()
636 {
637 /* Call common method to give check the hook */
638 $message= plugin::check();
639 if (preg_match("/printer/i",$this->BelongsTo)){
640 $message= array_merge($message, $this->netConfigDNS->check());
641 }
643 /* Don't display check messages if this is a template object */
644 if(isset($this->parent->by_object['workgeneric'])){
645 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
646 return $message;
647 }
648 }elseif(isset($this->parent->by_object['termgeneric'])){
649 if($this->parent->by_object['termgeneric']->cn == "default"){
650 return $message;
651 }
652 }
654 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
656 /* must: cn */
657 if(preg_match("/printer/i",$this->BelongsTo) && (empty($this->cn))){
658 $message[]= "The required field 'Printer name' is not set.";
659 }
661 /* must: labeledURI */
662 if(empty($this->labeledURI)){
663 $message[]= "The required field 'Printer URL' is not set.";
664 }
666 /* Check if there is already an entry with this cn*/
667 if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){
668 $ldap= $this->config->get_ldap_link();
669 $ldap->cd ($this->base);
670 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
671 if ($ldap->count() != 0){
672 while ($attrs= $ldap->fetch()){
673 if ($attrs['dn'] != $this->orig_dn){
674 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
675 break;
676 }
677 }
678 }
679 }
681 return ($message);
682 }
685 /* Save to LDAP */
686 function save()
687 {
688 /* Update dn, to ensure storing as printer instead of WS / terminal
689 */
690 if(preg_match("/terminal/i",$this->BelongsTo)){
691 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
692 }
694 if(preg_match("/workstation/i",$this->BelongsTo)){
695 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
696 }
698 if(!$this->is_account) return;
699 if(isset($this->parent->by_object['workgeneric'])){
700 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
701 return;
702 }
703 }elseif(isset($this->parent->by_object['termgeneric'])){
704 if($this->parent->by_object['termgeneric']->cn == "default"){
705 return;
706 }
707 }
709 /* If type is still unknown, the initialisation of this printer failed, abort. */
710 if(preg_match("/unknown/i",$this->BelongsTo)){
711 return;
712 }
714 /* save ppd configuration */
715 if($this->PPDdialogToSave){
716 $this->PPDdialogToSave->save_ppd();
717 }
719 /* Remove previously selected ppd file.*/
720 if($this->initial_PPD != $this->gotoPrinterPPD){
721 if(!empty($this->initial_PPD)){
722 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
723 $tmp->removeModifiedPPD();
724 }
725 }
727 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
728 $method="https://";
729 }else{
730 $method="http://";
731 }
733 /* If no ppd is selected, remove this attribute */
734 if(!empty($this->gotoPrinterPPD)) {
735 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
736 }else{
737 $this->gotoPrinterPPD = array();
738 }
740 $dn= $this->dn;
741 plugin::save();
742 $ldap= $this->config->get_ldap_link();
744 /* reduce objectClasses to minimun */
745 $this->attrs['objectClass']= $this->objectclasses;
747 /* Remove all empty values */
748 if ($this->orig_dn == 'new'){
749 $attrs= array();
750 foreach ($this->attrs as $key => $val){
751 if (is_array($val) && count($val) == 0){
752 continue;
753 }
754 $attrs[$key]= $val;
755 }
756 $this->attrs= $attrs;
757 }
759 /* Append printer user
760 */
761 $this->attrs['gotoUserPrinter']=array();
762 foreach($this->member['AddUser'] as $mem){
763 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
764 }
766 /* Append printer group
767 */
768 $this->attrs['gotoGroupPrinter'] = array();
769 foreach($this->member['AddGroup'] as $mem){
770 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
771 }
773 /* Append printer admin user
774 */
775 $this->attrs['gotoUserAdminPrinter'] = array();
776 foreach($this->member['AddAdminUser'] as $mem){
777 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
778 }
780 /* Append printer admin group
781 */
782 $this->attrs['gotoGroupAdminPrinter']= array();
783 foreach($this->member['AddAdminGroup'] as $mem){
784 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
785 }
787 if($this->orig_dn == 'new'){
788 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
789 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
790 unset($this->attrs[$checkVar]);
791 }
792 }
793 }else{
794 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
795 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
796 }
797 }
799 /* Ensure to create a new object */
800 if(preg_match("/ou=incoming,/",$this->orig_dn)){
801 $this->orig_dn = "new";
802 }
804 /* Move object in necessary*/
805 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
806 $this->move($this->orig_dn, $this->dn);
807 }
809 /* Write back to ldap */
810 $ldap= $this->config->get_ldap_link();
811 $ldap->cat($this->dn);
812 if(!$ldap->count()){
813 $ldap->cd($this->config->current['BASE']);
814 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
815 $ldap->cd($this->dn);
817 /* Remove empty values */
818 foreach($this->attrs as $name => $value){
819 if(empty($value)){
820 unset($this->attrs[$name]);
821 }
822 }
824 $ldap->add($this->attrs);
825 $this->handle_post_events("add");
826 } else {
827 $ldap->cd($this->dn);
828 $this->cleanup();
829 $ldap->modify ($this->attrs);
830 $this->handle_post_events("modify");
831 }
832 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
834 if(preg_match("/printer/i",$this->BelongsTo)){
835 $this->netConfigDNS->cn = $this->cn;
836 $this->netConfigDNS->dn = $this->dn;
837 $this->netConfigDNS->save($this->dn);
838 }
840 /* Optionally execute a command after we're done */
841 $this->postcreate();
843 /* This is a multi object. Handle tagging here... */
844 $this->handle_object_tagging();
845 }
847 function generateList(){
848 $a_return=array();
850 foreach($this->member as $type => $values){
851 $a_return[$type]=array();
852 foreach($values as $value){
853 if((preg_match("/Group/i",$type))){
854 if(!isset($value['description'])){
855 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
856 }else{
857 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
858 }
859 }else{
860 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
861 }
862 }
863 }
864 return($a_return);
865 }
867 /* Return plugin informations for acl handling
868 #FIXME FAIscript seams to ununsed within this class... */
869 function plInfo()
870 {
871 return (array(
872 "plShortName" => _("Generic"),
873 "plDescription" => _("Print generic"),
874 "plSelfModify" => FALSE,
875 "plDepends" => array(),
876 "plPriority" => 4,
877 "plSection" => array("administration"),
878 "plCategory" => array("printer" => array("description" => _("Printer"),
879 "objectClass" => "gotoPrinter"),"workstation","terminal"),
880 "plProvidedAcls"=> array(
881 "cn" => _("Name"),
882 "base" => _("Base") ,
883 "description" => _("Description"),
884 "l" => _("Location"),
885 "labeledURI" => _("LabeledURL"),
886 "gotoPrinterPPD" => _("Printer PPD"),
887 "gotoUserPrinter" => _("Permissions"))
888 ));
889 }
892 /* Delete member */
893 function DelMember($type,$id)
894 {
895 /* Check if there was a printer "dn" given, or the "cn" */
896 foreach($this->member[$type] as $key => $printer){
897 if($printer['dn'] == $id) {
898 $id = $key;
899 }
900 }
902 if(!$this->acl_is_writeable("gotoUserPrinter")){
903 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
904 return(FALSE);
905 }
907 if(isset($this->member[$type][$id])){
908 unset($this->member[$type][$id]);
909 return(TRUE);
910 }
911 return(FALSE);
912 }
915 /* Add given obejct to members */
916 function AddMember($type,$dn)
917 {
918 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
919 if(!in_array_ics($type, $types)){
920 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
921 return(FALSE);
922 }
924 if(!$this->acl_is_writeable("gotoUserPrinter")){
925 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
926 return(FALSE);
927 }
929 /* Get name of index attributes */
930 if(preg_match("/user/i",$type)){
931 $var = "uid";
932 }else{
933 $var = "cn";
934 }
936 $ldap = $this->config->get_ldap_link();
937 $ldap->cd($dn);
938 $ldap->cat($dn,array($var,"cn"));
939 if($ldap->count()){
941 $attrs = $ldap->fetch();
943 if(isset($attrs[$var][0])){
944 $name = $attrs[$var][0];
946 /* Check if this uid/cn is already assigned to any permission */
947 foreach($types as $ctype){
949 /* If we want to add a user, only check user/userAdmin members */
950 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
951 continue;
952 }
954 /* If we want to add a group, only check groups/adminGroups .. */
955 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
956 continue;
957 }
959 if(isset( $this->member[$ctype][$name])){
960 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
961 return(FALSE);
962 }
963 }
965 /* Everything is fine. So add the given object to members */
966 $this->member[$type][$attrs[$var][0]] = $attrs ;
967 }else{
968 print_a($attrs);
969 }
970 }else{
971 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
972 return(FALSE);
973 }
974 return(TRUE);
975 }
976 }
980 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
981 ?>