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 /* Set new acl base */
661 if($this->dn == "new") {
662 $this->set_acl_base($this->base);
663 }
665 if(preg_match("/printer/i",$this->BelongsTo)){
666 if ($this->orig_dn == "new" && !$this->acl_is_createable()){
667 $message[]= _("You have no permissions to create a group on this 'Base'.");
668 }
669 }
671 /* must: labeledURI */
672 if(empty($this->labeledURI)){
673 $message[]= "The required field 'Printer URL' is not set.";
674 }
676 /* Check if there is already an entry with this cn*/
677 if (($this->orig_dn != $dn)&&( preg_match("/printer/i",$this->BelongsTo))){
678 $ldap= $this->config->get_ldap_link();
679 $ldap->cd ($this->base);
680 $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
681 if ($ldap->count() != 0){
682 while ($attrs= $ldap->fetch()){
683 if ($attrs['dn'] != $this->orig_dn){
684 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
685 break;
686 }
687 }
688 }
689 }
691 return ($message);
692 }
695 /* Save to LDAP */
696 function save()
697 {
698 /* Update dn, to ensure storing as printer instead of WS / terminal
699 */
700 if(preg_match("/terminal/i",$this->BelongsTo)){
701 $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
702 }
704 if(preg_match("/workstation/i",$this->BelongsTo)){
705 $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
706 }
708 if(!$this->is_account) return;
709 if(isset($this->parent->by_object['workgeneric'])){
710 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
711 return;
712 }
713 }elseif(isset($this->parent->by_object['termgeneric'])){
714 if($this->parent->by_object['termgeneric']->cn == "default"){
715 return;
716 }
717 }
719 /* If type is still unknown, the initialisation of this printer failed, abort. */
720 if(preg_match("/unknown/i",$this->BelongsTo)){
721 return;
722 }
724 /* save ppd configuration */
725 if($this->PPDdialogToSave){
726 $this->PPDdialogToSave->save_ppd();
727 }
729 /* Remove previously selected ppd file.*/
730 if($this->initial_PPD != $this->gotoPrinterPPD){
731 if(!empty($this->initial_PPD)){
732 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
733 $tmp->removeModifiedPPD();
734 }
735 }
737 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
738 $method="https://";
739 }else{
740 $method="http://";
741 }
743 /* If no ppd is selected, remove this attribute */
744 if(!empty($this->gotoPrinterPPD)) {
745 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
746 }else{
747 $this->gotoPrinterPPD = array();
748 }
750 $dn= $this->dn;
751 plugin::save();
752 $ldap= $this->config->get_ldap_link();
754 /* reduce objectClasses to minimun */
755 $this->attrs['objectClass']= $this->objectclasses;
757 /* Remove all empty values */
758 if ($this->orig_dn == 'new'){
759 $attrs= array();
760 foreach ($this->attrs as $key => $val){
761 if (is_array($val) && count($val) == 0){
762 continue;
763 }
764 $attrs[$key]= $val;
765 }
766 $this->attrs= $attrs;
767 }
769 /* Append printer user
770 */
771 $this->attrs['gotoUserPrinter']=array();
772 foreach($this->member['AddUser'] as $mem){
773 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
774 }
776 /* Append printer group
777 */
778 $this->attrs['gotoGroupPrinter'] = array();
779 foreach($this->member['AddGroup'] as $mem){
780 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
781 }
783 /* Append printer admin user
784 */
785 $this->attrs['gotoUserAdminPrinter'] = array();
786 foreach($this->member['AddAdminUser'] as $mem){
787 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
788 }
790 /* Append printer admin group
791 */
792 $this->attrs['gotoGroupAdminPrinter']= array();
793 foreach($this->member['AddAdminGroup'] as $mem){
794 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
795 }
797 if($this->orig_dn == 'new'){
798 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
799 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
800 unset($this->attrs[$checkVar]);
801 }
802 }
803 }else{
804 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
805 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
806 }
807 }
809 /* Move object in necessary*/
810 if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
811 $this->move($this->orig_dn, $this->dn);
812 }
814 /* Write back to ldap */
815 $ldap= $this->config->get_ldap_link();
816 $ldap->cat($this->dn);
817 if(!$ldap->count()){
818 $ldap->cd($this->config->current['BASE']);
819 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
820 $ldap->cd($this->dn);
821 $ldap->add($this->attrs);
822 $this->handle_post_events("add");
823 } else {
824 $ldap->cd($this->dn);
825 $this->cleanup();
826 $ldap->modify ($this->attrs);
827 $this->handle_post_events("modify");
828 }
829 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
831 if(preg_match("/printer/i",$this->BelongsTo)){
832 $this->netConfigDNS->cn = $this->cn;
833 $this->netConfigDNS->dn = $this->dn;
834 $this->netConfigDNS->save($this->dn);
835 }
837 /* Optionally execute a command after we're done */
838 $this->postcreate();
840 /* This is a multi object. Handle tagging here... */
841 $this->handle_object_tagging();
842 }
844 function generateList(){
845 $a_return=array();
847 foreach($this->member as $type => $values){
848 $a_return[$type]=array();
849 foreach($values as $value){
850 if((preg_match("/Group/i",$type))){
851 if(!isset($value['description'])){
852 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
853 }else{
854 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
855 }
856 }else{
857 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
858 }
859 }
860 }
861 return($a_return);
862 }
864 /* Return plugin informations for acl handling
865 #FIXME FAIscript seams to ununsed within this class... */
866 function plInfo()
867 {
868 return (array(
869 "plShortName" => _("Generic"),
870 "plDescription" => _("Print generic"),
871 "plSelfModify" => FALSE,
872 "plDepends" => array(),
873 "plPriority" => 4,
874 "plSection" => array("administration"),
875 "plCategory" => array("printer" => array("description" => _("Printer"),
876 "objectClass" => "gotoPrinter"),"workstation","terminal"),
877 "plProvidedAcls"=> array(
878 "cn" => _("Name"),
879 "base" => _("Base") ,
880 "description" => _("Description"),
881 "l" => _("Location"),
882 "labeledURI" => _("LabeledURL"),
883 "gotoPrinterPPD" => _("Printer PPD"),
884 "gotoUserPrinter" => _("Permissions"))
885 ));
886 }
889 /* Delete member */
890 function DelMember($type,$id)
891 {
892 /* Check if there was a printer "dn" given, or the "cn" */
893 foreach($this->member[$type] as $key => $printer){
894 if($printer['dn'] == $id) {
895 $id = $key;
896 }
897 }
899 if(!$this->acl_is_writeable("gotoUserPrinter")){
900 print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
901 return(FALSE);
902 }
904 if(isset($this->member[$type][$id])){
905 unset($this->member[$type][$id]);
906 return(TRUE);
907 }
908 return(FALSE);
909 }
912 /* Add given obejct to members */
913 function AddMember($type,$dn)
914 {
915 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
916 if(!in_array_ics($type, $types)){
917 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
918 return(FALSE);
919 }
921 if(!$this->acl_is_writeable("gotoUserPrinter")){
922 print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
923 return(FALSE);
924 }
926 /* Get name of index attributes */
927 if(preg_match("/user/i",$type)){
928 $var = "uid";
929 }else{
930 $var = "cn";
931 }
933 $ldap = $this->config->get_ldap_link();
934 $ldap->cd($dn);
935 $ldap->cat($dn,array($var,"cn"));
936 if($ldap->count()){
938 $attrs = $ldap->fetch();
940 if(isset($attrs[$var][0])){
941 $name = $attrs[$var][0];
943 /* Check if this uid/cn is already assigned to any permission */
944 foreach($types as $ctype){
946 /* If we want to add a user, only check user/userAdmin members */
947 if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
948 continue;
949 }
951 /* If we want to add a group, only check groups/adminGroups .. */
952 if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
953 continue;
954 }
956 if(isset( $this->member[$ctype][$name])){
957 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
958 return(FALSE);
959 }
960 }
962 /* Everything is fine. So add the given object to members */
963 $this->member[$type][$attrs[$var][0]] = $attrs ;
964 }else{
965 print_a($attrs);
966 }
967 }else{
968 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
969 return(FALSE);
970 }
971 return(TRUE);
972 }
973 }
977 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
978 ?>