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, "printer", $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 }
686 if(!$this->is_account) return;
687 if(isset($this->parent->by_object['workgeneric'])){
688 if($this->parent->by_object['workgeneric']->cn == "wdefault"){
689 return;
690 }
691 }elseif(isset($this->parent->by_object['termgeneric'])){
692 if($this->parent->by_object['termgeneric']->cn == "default"){
693 return;
694 }
695 }
697 /* If type is still unknown, the initialisation of this printer failed, abort. */
698 if($this->BelongsTo == "unknown"){
699 return;
700 }
702 /* save ppd configuration */
703 if($this->PPDdialogToSave){
704 $this->PPDdialogToSave->save_ppd();
705 }
707 /* Remove previously selected ppd file.*/
708 if($this->initial_PPD != $this->gotoPrinterPPD){
709 if(!empty($this->initial_PPD)){
710 $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
711 $tmp->removeModifiedPPD();
712 }
713 }
715 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
716 $method="https://";
717 }else{
718 $method="http://";
719 }
721 /* If no ppd is selected, remove this attribute */
722 if(!empty($this->gotoPrinterPPD)) {
723 $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
724 }else{
725 $this->gotoPrinterPPD = array();
726 }
728 $dn= $this->dn;
729 plugin::save();
730 $ldap= $this->config->get_ldap_link();
732 /* reduce objectClasses to minimun */
733 $this->attrs['objectClass']= $this->objectclasses;
735 /* Remove all empty values */
736 if ($this->orig_dn == 'new'){
737 $attrs= array();
738 foreach ($this->attrs as $key => $val){
739 if (is_array($val) && count($val) == 0){
740 continue;
741 }
742 $attrs[$key]= $val;
743 }
744 $this->attrs= $attrs;
745 }
747 /* Append printer user
748 */
749 $this->attrs['gotoUserPrinter']=array();
750 foreach($this->member['AddUser'] as $mem){
751 $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
752 }
754 /* Append printer group
755 */
756 $this->attrs['gotoGroupPrinter'] = array();
757 foreach($this->member['AddGroup'] as $mem){
758 $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
759 }
761 /* Append printer admin user
762 */
763 $this->attrs['gotoUserAdminPrinter'] =array();
764 foreach($this->member['AddAdminUser'] as $mem){
765 $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
766 }
768 /* Append printer admin group
769 */
770 $this->attrs['gotoGroupAdminPrinter'] = array();
771 foreach($this->member['AddAdminGroup'] as $mem){
772 $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
773 }
775 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
776 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
777 }
779 if($this->orig_dn == 'new'){
780 foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
781 if(count($this->attrs[$checkVar]) == 0 || empty($this->attrs[$checkVar])){
782 unset($this->attrs[$checkVar]);
783 }
784 }
785 }
787 /* Ensure to create a new object */
788 if(preg_match("/ou=incoming,/",$this->orig_dn)){
789 $this->orig_dn = "new";
790 }
792 /* Write back to ldap */
793 $ldap= $this->config->get_ldap_link();
794 if ($this->orig_dn == 'new'){
795 $ldap->cd($this->config->current['BASE']);
796 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
797 $ldap->cd($this->dn);
799 /* Remove empty values */
800 foreach($this->attrs as $name => $value){
801 if(empty($value)){
802 unset($this->attrs[$name]);
803 }
804 }
806 $ldap->add($this->attrs);
807 $this->handle_post_events("add");
808 } else {
809 if ($this->orig_dn != $this->dn){
810 $this->move($this->orig_dn, $this->dn);
811 }
813 $ldap->cd($this->dn);
814 $this->cleanup();
815 $ldap->modify ($this->attrs);
817 $this->handle_post_events("modify");
818 }
819 show_ldap_error($ldap->get_error(), _("Saving printer failed"));
821 /* Only save dns stuff if we are a standalone printer */
822 if($this->BelongsTo == "Printer"){
823 $this->netConfigDNS->cn = $this->cn;
824 $this->netConfigDNS->dn = $this->dn;
825 $this->netConfigDNS->save($this->dn);
826 }
828 /* Optionally execute a command after we're done */
829 $this->postcreate();
831 /* This is a multi object. Handle tagging here... */
832 $this->handle_object_tagging();
833 }
835 function generateList(){
836 $a_return=array();
837 foreach($this->member as $type => $values){
838 $a_return[$type]=array();
839 foreach($values as $value){
840 if((preg_match("/Group/i",$type))){
841 if(!isset($value['description'])){
842 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0];
843 }else{
844 $a_return[$type][$value['cn'][0]]= _("Group")." : ".$value['cn'][0]." [".$value['description'][0]."]";
845 }
846 }else{
847 $a_return[$type][$value['uid'][0]]=_("User")." : ".$value['cn'][0];
848 }
849 }
850 }
851 return($a_return);
852 }
854 /* Delete member */
855 function DelMember($type,$id)
856 {
857 if(isset($this->member[$type][$id])){
858 unset($this->member[$type][$id]);
859 }
860 }
862 /* Add given obejct to members */
863 function AddMember($type,$dn)
864 {
865 $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
866 if(!in_array_ics($type, $types)){
867 print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
868 return;
869 }
871 /* Get name of index attributes */
872 if(preg_match("/user/i",$type)){
873 $var = "uid";
874 }else{
875 $var = "cn";
876 }
878 $ldap = $this->config->get_ldap_link();
879 $ldap->cd($dn);
880 $ldap->cat($dn,array("cn","uid"));
881 if($ldap->count()){
883 $attrs = $ldap->fetch();
884 $name = $attrs[$var][0];
886 /* Check if this uid/cn is already assigned to any permission */
887 foreach($types as $ctype){
888 if(isset( $this->member[$ctype][$name])){
889 print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
890 return;
891 }
892 }
894 /* Everything is fine. So add the given object to members */
895 $this->member[$type][$attrs[$var][0]] = $attrs ;
896 }else{
897 print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
898 }
899 }
900 }
902 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
903 ?>