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 }
413 }
415 /* remove ppd */
416 if(isset($_POST['RemoveDriver'])){
417 $this->gotoPrinterPPD = array();
418 $this->PPDdialogToSave = NULL;
419 }
421 /* Close ppd dialog */
422 if(isset($_POST['ClosePPD'])){
423 unset($this->dialog);
424 $this->dialog=NULL;
425 }
427 /* Save selected ppd */
428 if(isset($_POST['SavePPD'])){
429 $this->dialog->save_object();
430 if(count($this->dialog->check())){
431 foreach($this->dialog->check() as $msg){
432 print_red($msg);
433 }
434 }else{
435 $this->gotoPrinterPPD = array();
436 $this->gotoPrinterPPD = $this->dialog->save();
437 $this->PPDdialogToSave = $this->dialog;
438 unset($this->dialog);
439 $this->dialog=NULL;
440 }
441 }
443 /* Member management, delete user / group / admin ..*/
444 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
445 foreach($_POST['UserMember'] as $mem){
446 $this->DelMember('AddUser',$mem);
447 }
448 }
450 if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
451 foreach($_POST['UserMember'] as $mem){
452 $this->DelMember('AddGroup',$mem);
453 }
454 }
456 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
457 foreach($_POST['AdminMember'] as $mem){
458 $this->DelMember('AddAdminUser',$mem);
459 }
460 }
462 if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
463 foreach($_POST['AdminMember'] as $mem){
464 $this->DelMember('AddAdminGroup',$mem);
465 }
466 }
468 /* Abort user / group adding dialog */
469 if(isset($_POST['PrinterCancel'])){
470 unset($this->dialog);
471 $this->dialog= NULL;
472 }
474 /* Save selected users / groups */
475 if(isset($_POST['PrinterSave'])){
476 $this->dialog->save_object();
477 if(count($this->dialog->check())){
478 foreach($this->dialog->check() as $msg){
479 print_red($msg);
480 }
481 }else{
482 $data= $new = $this->dialog->save();
483 unset($data['type']);
484 foreach($data as $mem){
485 $this->AddMember($new['type'], $mem['dn']);
486 }
487 unset($this->dialog);
488 $this->dialog=NULL;
489 }
490 }
492 /* Display dialog, if there is currently one open*/
493 if($this->dialog != NULL){
494 $this->dialog->save_object();
495 $display = $this->dialog->execute();
496 return $display;
497 }
499 /* Parse selected ppd file */
500 require_once ("class_ppdManager.inc");
501 if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
503 $path = $_SESSION['config']->data['MAIN']['PPD_PATH'];
504 if(!preg_match("/\/$/",$path)){
505 $path = $path."/";
506 }
508 $ppdManager= new ppdManager($path);
509 if(!empty($this->gotoPrinterPPD)){
510 if((!file_exists($path.$this->gotoPrinterPPD))){
511 $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
512 }else{
513 $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
514 }
515 }else{
516 $smarty->assign("driverInfo", _("not defined"));
517 }
518 }else{
519 $smarty->assign("driverInfo",_("can't get ppd informations."));
520 }
522 /* Create user & admin user list */
523 $list=$this->generateList();
524 $userlist = array_merge($list['AddUser'],$list['AddGroup']);
525 $adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
527 asort($userlist);
528 asort($adminlist);
530 if(!preg_match("/Printer/i",$this->BelongsTo)){
531 if(preg_match("/Terminal/i",$this->BelongsTo)){
532 $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
533 }else{
534 $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
535 }
536 $smarty->assign("cnACL" , $this->getacl("cn",true));
537 }else{
538 $smarty->assign("desc" ,"");
539 }
540 $smarty->assign("UserMember" ,$this->UserMember);
541 $smarty->assign("UserMembers" ,$userlist);
542 $smarty->assign("UserMemberKeys",array_flip($userlist));
544 $smarty->assign("AdminMember" ,$this->AdminMember);
545 $smarty->assign("AdminMembers" ,$adminlist);
546 $smarty->assign("AdminMemberKeys",array_flip($adminlist));
547 if(preg_match("/Printer/i",$this->BelongsTo)){
548 $smarty->assign("netconfig", $this->netConfigDNS->execute());
549 } else {
550 $smarty->assign("netconfig", "");
551 }
553 return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
554 }
556 function remove_from_parent()
557 {
558 /* Only remove if there was initially an account */
559 if($this->initially_was_account){
561 /* Update dn, to ensure storing as printer instead of WS / terminal
562 */
563 if(preg_match("/terminal/i",$this->BelongsTo)){
564 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
565 }
567 if(preg_match("/workstation/i",$this->BelongsTo)){
568 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
569 }
571 /* Check if this dn points to a printer, to avoid deleting something else */
572 $ldap= $this->config->get_ldap_link();
573 $ldap->cat($this->dn, array('dn',"objectClass"));
574 if(!$ldap->count()){
575 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
576 return;
577 }
579 /* Check if obejct is a printer */
580 $CheckPrinter = $ldap->fetch();
581 if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
582 print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
583 return;
584 }
586 /* Remove account & dns extension */
587 $this->netConfigDNS->remove_from_parent();
588 $ldap->rmdir($this->dn);
589 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
590 $this->handle_post_events("remove");
592 /* Delete references to object groups */
593 $ldap->cd ($this->config->current['BASE']);
594 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
595 while ($ldap->fetch()){
596 $og= new ogroup($this->config, $ldap->getDN());
597 unset($og->member[$this->dn]);
598 $og->save ();
599 }
601 /* Remove previously selected ppd file.*/
602 if(!empty($this->initial_PPD)){
603 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
604 $tmp->removeModifiedPPD();
605 }
606 }
607 }
610 /* Save data to object */
611 function save_object()
612 {
613 /* Create a base backup and reset the
614 base directly after calling plugin::save_object();
615 Base will be set seperatly a few lines below */
616 $base_tmp = $this->base;
617 plugin::save_object();
618 $this->base = $base_tmp;
620 if(is_object($this->netConfigDNS)){
621 $this->netConfigDNS->save_object();
622 }
624 /* Set new base if allowed */
625 $tmp = $this->get_allowed_bases();
626 if(isset($_POST['base'])){
627 if(isset($tmp[$_POST['base']])){
628 $this->base= $_POST['base'];
629 }
630 }
631 }
633 /* Check supplied data */
634 function check()
635 {
636 /* Call common method to give check the hook */
637 $message= plugin::check();
638 if (preg_match("/printer/i",$this->BelongsTo)){
639 $message= array_merge($message, $this->netConfigDNS->check());
640 }
642 /* Don't display check messages if this is a template object */
643 if(isset($this->parent->by_object['workgeneric'])){
644 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
645 return $message;
646 }
647 }elseif(isset($this->parent->by_object['termgeneric'])){
648 if($this->parent->by_object['termgeneric']->cn == "default"){
649 return $message;
650 }
651 }
653 $dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
655 /* must: cn */
656 if(preg_match("/printer/i",$this->BelongsTo) && (empty($this->cn))){
657 $message[]= "The required field 'Printer name' is not set.";
658 }
660 /* must: labeledURI */
661 if(empty($this->labeledURI)){
662 $message[]= "The required field 'Printer URL' is not set.";
663 }
665 /* Check if there is already an entry with this cn*/
666 if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){
667 $ldap= $this->config->get_ldap_link();
668 $ldap->cd ($this->base);
669 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
670 if ($ldap->count() != 0){
671 while ($attrs= $ldap->fetch()){
672 if ($attrs['dn'] != $this->orig_dn){
673 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
674 break;
675 }
676 }
677 }
678 }
680 return ($message);
681 }
684 /* Save to LDAP */
685 function save()
686 {
687 /* Update dn, to ensure storing as printer instead of WS / terminal
688 */
689 if(preg_match("/terminal/i",$this->BelongsTo)){
690 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
691 }
693 if(preg_match("/workstation/i",$this->BelongsTo)){
694 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
695 }
697 if(!$this->is_account) return;
698 if(isset($this->parent->by_object['workgeneric'])){
699 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
700 return;
701 }
702 }elseif(isset($this->parent->by_object['termgeneric'])){
703 if($this->parent->by_object['termgeneric']->cn == "default"){
704 return;
705 }
706 }
708 /* If type is still unknown, the initialisation of this printer failed, abort. */
709 if(preg_match("/unknown/i",$this->BelongsTo)){
710 return;
711 }
713 /* save ppd configuration */
714 if($this->PPDdialogToSave){
715 $this->PPDdialogToSave->save_ppd();
716 }
718 /* Remove previously selected ppd file.*/
719 if($this->initial_PPD != $this->gotoPrinterPPD){
720 if(!empty($this->initial_PPD)){
721 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
722 $tmp->removeModifiedPPD();
723 }
724 }
726 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
727 $method="https://";
728 }else{
729 $method="http://";
730 }
732 /* If no ppd is selected, remove this attribute */
733 if(!empty($this->gotoPrinterPPD)) {
734 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
735 }else{
736 $this->gotoPrinterPPD = array();
737 }
739 $dn= $this->dn;
740 plugin::save();
741 $ldap= $this->config->get_ldap_link();
743 /* reduce objectClasses to minimun */
744 $this->attrs['objectClass']= $this->objectclasses;
746 /* Remove all empty values */
747 if ($this->orig_dn == 'new'){
748 $attrs= array();
749 foreach ($this->attrs as $key => $val){
750 if (is_array($val) && count($val) == 0){
751 continue;
752 }
753 $attrs[$key]= $val;
754 }
755 $this->attrs= $attrs;
756 }
758 /* Append printer user
759 */
760 $this->attrs['gotoUserPrinter']=array();
761 foreach($this->member['AddUser'] as $mem){
762 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
763 }
765 /* Append printer group
766 */
767 $this->attrs['gotoGroupPrinter'] = array();
768 foreach($this->member['AddGroup'] as $mem){
769 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
770 }
772 /* Append printer admin user
773 */
774 $this->attrs['gotoUserAdminPrinter'] = array();
775 foreach($this->member['AddAdminUser'] as $mem){
776 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
777 }
779 /* Append printer admin group
780 */
781 $this->attrs['gotoGroupAdminPrinter']= array();
782 foreach($this->member['AddAdminGroup'] as $mem){
783 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
784 }
786 if($this->orig_dn == 'new'){
787 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
788 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
789 unset($this->attrs[$checkVar]);
790 }
791 }
792 }else{
793 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
794 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
795 }
796 }
798 /* Move object in necessary*/
799 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
800 $this->move($this->orig_dn, $this->dn);
801 }
803 /* Write back to ldap */
804 $ldap= $this->config->get_ldap_link();
805 $ldap->cat($this->dn);
806 if(!$ldap->count()){
807 $ldap->cd($this->config->current['BASE']);
808 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
809 $ldap->cd($this->dn);
810 $ldap->add($this->attrs);
811 $this->handle_post_events("add");
812 } else {
813 $ldap->cd($this->dn);
814 $this->cleanup();
815 $ldap->modify ($this->attrs);
816 $this->handle_post_events("modify");
817 }
818 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
820 if(preg_match("/printer/i",$this->BelongsTo)){
821 $this->netConfigDNS->cn = $this->cn;
822 $this->netConfigDNS->dn = $this->dn;
823 $this->netConfigDNS->save($this->dn);
824 }
826 /* Optionally execute a command after we're done */
827 $this->postcreate();
829 /* This is a multi object. Handle tagging here... */
830 $this->handle_object_tagging();
831 }
833 function generateList(){
834 $a_return=array();
836 foreach($this->member as $type => $values){
837 $a_return[$type]=array();
838 foreach($values as $value){
839 if((preg_match("/Group/i",$type))){
840 if(!isset($value['description'])){
841 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
842 }else{
843 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
844 }
845 }else{
846 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
847 }
848 }
849 }
850 return($a_return);
851 }
853 /* Return plugin informations for acl handling
854 #FIXME FAIscript seams to ununsed within this class... */
855 function plInfo()
856 {
857 return (array(
858 "plShortName" => _("Generic"),
859 "plDescription" => _("Print generic"),
860 "plSelfModify" => FALSE,
861 "plDepends" => array(),
862 "plPriority" => 4,
863 "plSection" => array("administration"),
864 "plCategory" => array("printer" => array("description" => _("Printer"),
865 "objectClass" => "gotoPrinter"),"workstation","terminal"),
866 "plProvidedAcls"=> array(
867 "cn" => _("Name"),
868 "base" => _("Base") ,
869 "description" => _("Description"),
870 "l" => _("Location"),
871 "labeledURI" => _("LabeledURL"),
872 "gotoPrinterPPD" => _("Printer PPD"),
873 "gotoUserPrinter" => _("Permissions"))
874 ));
875 }
878 /* Delete member */
879 function DelMember($type,$id)
880 {
881 /* Check if there was a printer "dn" given, or the "cn" */
882 foreach($this->member[$type] as $key => $printer){
883 if($printer['dn'] == $id) {
884 $id = $key;
885 }
886 }
888 if(!$this->acl_is_writeable("gotoUserPrinter")){
889 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
890 return(FALSE);
891 }
893 if(isset($this->member[$type][$id])){
894 unset($this->member[$type][$id]);
895 return(TRUE);
896 }
897 return(FALSE);
898 }
901 /* Add given obejct to members */
902 function AddMember($type,$dn)
903 {
904 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
905 if(!in_array_ics($type, $types)){
906 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
907 return(FALSE);
908 }
910 if(!$this->acl_is_writeable("gotoUserPrinter")){
911 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
912 return(FALSE);
913 }
915 /* Get name of index attributes */
916 if(preg_match("/user/i",$type)){
917 $var = "uid";
918 }else{
919 $var = "cn";
920 }
922 $ldap = $this->config->get_ldap_link();
923 $ldap->cd($dn);
924 $ldap->cat($dn,array($var,"cn"));
925 if($ldap->count()){
927 $attrs = $ldap->fetch();
929 if(isset($attrs[$var][0])){
930 $name = $attrs[$var][0];
932 /* Check if this uid/cn is already assigned to any permission */
933 foreach($types as $ctype){
935 /* If we want to add a user, only check user/userAdmin members */
936 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
937 continue;
938 }
940 /* If we want to add a group, only check groups/adminGroups .. */
941 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
942 continue;
943 }
945 if(isset( $this->member[$ctype][$name])){
946 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
947 return(FALSE);
948 }
949 }
951 /* Everything is fine. So add the given object to members */
952 $this->member[$type][$attrs[$var][0]] = $attrs ;
953 }else{
954 print_a($attrs);
955 }
956 }else{
957 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
958 return(FALSE);
959 }
960 return(TRUE);
961 }
962 }
966 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
967 ?>