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