1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class aclrole extends acl
24 {
25 /* Definitions */
26 var $plHeadline= "Access control roles";
27 var $plDescription= "Edit AC roles";
29 /* attribute list for save action */
30 var $attributes= array('gosaAclTemplate',"cn","description");
31 var $objectclasses= array('top','gosaRole');
33 /* Helpers */
34 var $dialogState= "head";
35 var $aclType= "";
36 var $aclObject= "";
37 var $aclContents= array();
38 var $target= "group";
39 var $aclTypes= array();
40 var $aclObjects= array();
41 var $recipients= array();
42 var $isContainer= TRUE;
43 var $currentIndex= 0;
44 var $wasNewEntry= FALSE;
45 var $ocMapping= array();
46 var $savedAclContents= array();
47 var $myAclObjects = array();
49 /* Role attributes */
50 var $gosaAclTemplate= "";
51 var $cn = "";
52 var $description = "";
53 var $orig_dn;
54 var $orig_base;
55 var $base ="";
57 function aclrole (&$config, $dn= NULL)
58 {
59 /* Include config object */
60 plugin::plugin($config, $dn);
62 if($this->dn == "new"){
63 $this->base = session::get('CurrentMainBase');
64 }else{
65 $this->base = preg_replace("/^[^,]+,[^,]+,/","",$this->dn);
66 new log("view","acl/".get_class($this),$this->dn);
67 }
69 /* Load ACL's */
70 $this->gosaAclTemplate= array();
71 if (isset($this->attrs["gosaAclTemplate"])){
72 for ($i= 0; $i<$this->attrs["gosaAclTemplate"]['count']; $i++){
73 $acl= $this->attrs["gosaAclTemplate"][$i];
74 $this->gosaAclTemplate= array_merge($this->gosaAclTemplate, $this->explodeACL($acl));
75 }
76 }
77 ksort($this->gosaAclTemplate);
79 /* Extract available categories from plugin info list */
80 $tmp= session::get('plist');
81 $plist= $tmp->info;
82 $oc = array();
83 foreach ($plist as $class => $acls){
85 /* Only feed categories */
86 if (isset($acls['plCategory'])){
88 /* Walk through supplied list and feed only translated categories */
89 foreach($acls['plCategory'] as $idx => $data){
91 /* Non numeric index means -> base object containing more informations */
92 if (preg_match('/^[0-9]+$/', $idx)){
93 if (!isset($this->ocMapping[$data])){
94 $this->ocMapping[$data]= array();
95 $this->ocMapping[$data][]= '0';
96 }
97 $this->ocMapping[$data][]= $class;
98 } else {
99 if (!isset($this->ocMapping[$idx])){
100 $this->ocMapping[$idx]= array();
101 $this->ocMapping[$idx][]= '0';
102 }
103 $this->ocMapping[$idx][]= $class;
104 $this->aclObjects[$idx]= $data['description'];
106 /* Additionally filter the classes we're interested in in "self edit" mode */
107 if (is_array($data['objectClass'])){
108 foreach($data['objectClass'] as $objectClass){
109 if (in_array_ics($objectClass, $oc)){
110 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
111 break;
112 }
113 }
114 } else {
115 if (in_array_ics($data['objectClass'], $oc)){
116 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
117 }
118 }
119 }
121 }
122 }
123 }
124 $this->aclObjects['all']= '* '._("All categories");
125 $this->ocMapping['all']= array('0' => 'all');
127 /* Sort categories */
128 asort($this->aclObjects);
130 /* Fill acl types */
131 $this->aclTypes= array( "reset" => _("Reset ACL"),
132 "one" => _("One level"),
133 "base" => _("Current object"),
134 "sub" => _("Complete subtree"),
135 "psub" => _("Complete subtree (permanent)"));
136 asort($this->aclTypes);
138 /* Finally - we want to get saved... */
139 $this->is_account= TRUE;
140 $this->orig_base = $this->base;
141 $this->orig_dn = $this->dn;
142 }
145 function execute()
146 {
147 /* Call parent execute */
148 plugin::execute();
150 /* Base select dialog */
151 $once = true;
152 foreach($_POST as $name => $value){
153 if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
154 $once = false;
155 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
156 $this->dialog->setCurrentBase($this->base);
157 }
158 }
160 /* Dialog handling */
161 if(is_object($this->dialog)){
162 /* Must be called before save_object */
163 $this->dialog->save_object();
165 if($this->dialog->isClosed()){
166 $this->dialog = false;
167 }elseif($this->dialog->isSelected()){
169 /* Check if selected base is valid */
170 $tmp = $this->get_allowed_bases();
171 if(isset($tmp[$this->dialog->isSelected()])){
172 $this->base = $this->dialog->isSelected();
173 }
174 $this->dialog= false;
175 }else{
176 return($this->dialog->execute());
177 }
178 }
180 $tmp= session::get('plist');
181 $plist= $tmp->info;
183 /* Handle posts */
184 if (isset($_POST['new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
185 $this->dialogState= 'create';
186 $this->dialog= TRUE;
187 $this->currentIndex= count($this->gosaAclTemplate);
188 $this->loadAclEntry(TRUE);
189 }
191 $new_acl= array();
192 $aclDialog= FALSE;
193 $firstedit= FALSE;
195 /* Act on HTML post and gets here.
196 */
197 if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
198 $id = trim($_GET['id']);
199 $this->dialogState= 'create';
200 $firstedit= TRUE;
201 $this->dialog= TRUE;
202 $this->currentIndex= $id;
203 $this->loadAclEntry();
204 }
206 foreach($_POST as $name => $post){
208 /* Actions... */
209 if (preg_match('/^acl_edit_.*_x/', $name)){
210 $this->dialogState= 'create';
211 $firstedit= TRUE;
212 $this->dialog= TRUE;
213 $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
214 $this->loadAclEntry();
215 continue;
216 }
217 if (preg_match('/^cat_edit_.*_x/', $name)){
218 $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
219 $this->dialogState= 'edit';
220 foreach ($this->ocMapping[$this->aclObject] as $oc){
221 if (isset($this->aclContents[$oc])){
222 $this->savedAclContents[$oc]= $this->aclContents[$oc];
223 }
224 }
225 continue;
226 }
228 if(!$this->acl_is_writeable("gosaAclEntry")){
229 continue;
230 }
232 if (preg_match('/^acl_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
233 unset($this->gosaAclTemplate[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
234 continue;
235 }
237 if (preg_match('/^cat_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
238 $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
239 foreach ($this->ocMapping[$idx] as $key){
240 unset($this->aclContents["$idx/$key"]);
241 }
242 continue;
243 }
245 /* Sorting... */
246 if (preg_match('/^sortup_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
247 $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
248 if ($index > 0){
249 $tmp= $this->gosaAclTemplate[$index];
250 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index-1];
251 $this->gosaAclTemplate[$index-1]= $tmp;
252 }
253 continue;
254 }
255 if (preg_match('/^sortdown_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
256 $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
257 if ($index < count($this->gosaAclTemplate)-1){
258 $tmp= $this->gosaAclTemplate[$index];
259 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index+1];
260 $this->gosaAclTemplate[$index+1]= $tmp;
261 }
262 continue;
263 }
265 /* ACL saving... */
266 if (preg_match('/^acl_.*_[^xy]$/', $name) && $this->acl_is_writeable("gosaAclEntry")){
267 list($dummy, $object, $attribute, $value)= split('_', $name);
269 /* Skip for detection entry */
270 if ($object == 'dummy') {
271 continue;
272 }
274 /* Ordinary ACL */
275 if (!isset($new_acl[$object])){
276 $new_acl[$object]= array();
277 }
278 if (isset($new_acl[$object][$attribute])){
279 $new_acl[$object][$attribute].= $value;
280 } else {
281 $new_acl[$object][$attribute]= $value;
282 }
283 }
284 }
286 if(isset($_POST['acl_dummy_0_0_0'])){
287 $aclDialog= TRUE;
288 }
290 /* Only be interested in new acl's, if we're in the right _POST place */
291 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
293 foreach ($this->ocMapping[$this->aclObject] as $oc){
294 unset($this->aclContents[$oc]);
295 unset($this->aclContents[$this->aclObject.'/'.$oc]);
296 if (isset($new_acl[$oc])){
297 $this->aclContents[$oc]= $new_acl[$oc];
298 }
299 if (isset($new_acl[$this->aclObject.'/'.$oc])){
300 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
301 }
302 }
303 }
305 /* Save new acl in case of base edit mode */
306 if (1 == 0 && $this->aclType == 'base' && !$firstedit){
307 $this->aclContents= $new_acl;
308 }
310 /* Cancel new acl? */
311 if (isset($_POST['cancel_new_acl'])){
312 $this->dialogState= 'head';
313 $this->dialog= FALSE;
314 if ($this->wasNewEntry){
315 unset ($this->gosaAclTemplate[$this->currentIndex]);
316 }
317 }
319 /* Store ACL in main object? */
320 if (isset($_POST['submit_new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
321 $this->gosaAclTemplate[$this->currentIndex]['type']= $this->aclType;
322 $this->gosaAclTemplate[$this->currentIndex]['members']= $this->recipients;
323 $this->gosaAclTemplate[$this->currentIndex]['acl']= $this->aclContents;
324 $this->dialogState= 'head';
325 $this->dialog= FALSE;
326 }
328 /* Cancel edit acl? */
329 if (isset($_POST['cancel_edit_acl'])){
330 $this->dialogState= 'create';
331 foreach ($this->ocMapping[$this->aclObject] as $oc){
332 if (isset($this->savedAclContents[$oc])){
333 $this->aclContents[$oc]= $this->savedAclContents[$oc];
334 }
335 }
336 }
338 /* Save edit acl? */
339 if (isset($_POST['submit_edit_acl']) && $this->acl_is_writeable("gosaAclEntry")){
340 $this->dialogState= 'create';
341 }
343 /* Add acl? */
344 if (isset($_POST['add_acl']) && $_POST['aclObject'] != "" && $this->acl_is_writeable("gosaAclEntry")){
345 $this->dialogState= 'edit';
346 $this->savedAclContents= array();
347 foreach ($this->ocMapping[$this->aclObject] as $oc){
348 if (isset($this->aclContents[$oc])){
349 $this->savedAclContents[$oc]= $this->aclContents[$oc];
350 }
351 }
352 }
354 /* Save common values */
355 foreach (array("aclType", "aclObject", "target") as $key){
356 if (isset($_POST[$key]) && $this->acl_is_writeable("gosaAclEntry")){
357 $this->$key= validate($_POST[$key]);
358 }
359 }
361 /* Create templating instance */
362 $smarty= get_smarty();
364 $smarty->assign("bases", $this->get_allowed_bases());
365 $smarty->assign("base_select", $this->base);
367 $tmp = $this->plInfo();
368 foreach($tmp['plProvidedAcls'] as $name => $translation){
369 $smarty->assign($name."ACL",$this->getacl($name));
370 }
372 if ($this->dialogState == 'head'){
373 /* Draw list */
374 $aclList= new divSelectBox("aclList");
375 $aclList->SetHeight(350);
377 /* Fill in entries */
378 foreach ($this->gosaAclTemplate as $key => $entry){
380 if($this->acl_is_readable("")){
381 $link = "<a href=?plug=".$_GET['plug']."&id=".$key."&act=edit>".$this->assembleAclSummary($entry)."</a>";
382 }else{
383 $link = $this->assembleAclSummary($entry);
384 }
386 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
387 $field2= array("string" => $link);
389 $action ="";
390 if($this->acl_is_writeable("gosaAclEntry")){
391 $action.= "<input type='image' name='sortup_$key' alt='up'
392 title='"._("Up")."' src='images/lists/sort-up.png' align='top'>";
393 $action.= "<input type='image' name='sortdown_$key' alt='down'
394 title='"._("Down")."' src='images/lists/sort-down.png'>";
395 }
396 if($this->acl_is_readable("gosaAclEntry")){
397 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("Edit")."' name='acl_edit_$key'
398 title='".msgPool::editButton(_("ACL"))."'>";
399 }
400 if($this->acl_is_writeable("gosaAclEntry")){
401 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("Delete")."' name='acl_del_$key'
402 title='".msgPool::delButton(_("ACL"))."'>";
403 }
405 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
406 $aclList->AddEntry(array($field1, $field2, $field3));
407 }
409 $smarty->assign("aclList", $aclList->DrawList());
410 }
412 if ($this->dialogState == 'create'){
413 /* Draw list */
414 $aclList= new divSelectBox("aclList");
415 $aclList->SetHeight(450);
417 /* Add settings for all categories to the (permanent) list */
418 foreach ($this->aclObjects as $section => $dsc){
419 $summary= "";
420 foreach($this->ocMapping[$section] as $oc){
421 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
422 $this->aclContents[$oc][0] != ""){
424 $summary.= "$oc, ";
425 continue;
426 }
427 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"]) && isset($this->aclContents["$section/$oc"][0]) &&
428 $this->aclContents["$section/$oc"][0] != ""){
430 $summary.= "$oc, ";
431 continue;
432 }
433 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
434 $summary.= "$oc, ";
435 }
436 }
438 /* Set summary... */
439 if ($summary == ""){
440 $summary= '<i>'._("No ACL settings for this category").'</i>';
441 } else {
442 $summary= sprintf(_("ACL for these objects: %s"), preg_replace('/, $/', '', $summary));
443 }
445 $action = "";
446 if($this->acl_is_readable("gosaAclEntry")){
447 $action.= "<input class='center' type='image' src='images/lists/edit.png'
448 alt='"._("Edit")."' name='cat_edit_$section' title='"._("Edit category ACL")."'>";
449 }
450 if($this->acl_is_writeable("gosaAclEntry")){
451 $action.= "<input class='center' type='image' src='images/lists/trash.png'
452 alt='"._("Delete")."' name='cat_del_$section' title='"._("Reset category ACL")."'>";
453 }
455 $field1= array("string" => $dsc, "attach" => "style='width:140px'");
456 $field2= array("string" => $summary);
457 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
458 $aclList->AddEntry(array($field1, $field2, $field3));
459 }
461 $smarty->assign("aclList", $aclList->DrawList());
462 $smarty->assign("aclType", $this->aclType);
463 $smarty->assign("aclTypes", $this->aclTypes);
464 $smarty->assign("target", $this->target);
466 if ($this->aclType == 'base'){
467 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
468 }
469 }
471 if ($this->dialogState == 'edit'){
472 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
474 /* Collect objects for selected category */
475 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
476 if ($idx == 0){
477 continue;
478 }
479 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
480 }
481 if ($this->aclObject == 'all'){
482 $aclObjects['all']= _("All objects in current subtree");
483 }
484 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
485 }
487 /* Show main page */
488 $smarty->assign("dialogState", $this->dialogState);
490 /* Assign cn and decription if this is a role */
491 foreach(array("cn","description") as $name){
492 $smarty->assign($name,$this->$name);
493 }
494 return ($smarty->fetch (get_template_path('acl_role.tpl',dirname(__FILE__))));
495 }
497 function sort_by_priority($list)
498 {
499 $tmp= session::get('plist');
500 $plist= $tmp->info;
501 asort($plist);
502 $newSort = array();
504 foreach($list as $name => $translation){
505 $na = preg_replace("/^.*\//","",$name);
506 if (!isset($plist[$na]['plPriority'])){
507 $prio= 0;
508 } else {
509 $prio= $plist[$na]['plPriority'] ;
510 }
512 $newSort[$name] = $prio;
513 }
515 asort($newSort);
517 $ret = array();
518 foreach($newSort as $name => $prio){
519 $ret[$name] = $list[$name];
520 }
521 return($ret);
522 }
524 function loadAclEntry($new= FALSE)
525 {
526 /* New entry gets presets... */
527 if ($new){
528 $this->aclType= 'sub';
529 $this->recipients= array();
530 $this->aclContents= array();
531 } else {
532 $acl= $this->gosaAclTemplate[$this->currentIndex];
533 $this->aclType= $acl['type'];
534 $this->recipients= $acl['members'];
535 $this->aclContents= $acl['acl'];
536 }
538 $this->wasNewEntry= $new;
539 }
542 function aclPostHandler()
543 {
544 if (isset($_POST['save_acl']) && $this->acl_is_writeable("gosaAclEntry")){
545 $this->save();
546 return TRUE;
547 }
549 return FALSE;
550 }
553 function save()
554 {
555 /* Assemble ACL's */
556 $tmp_acl= array();
557 foreach ($this->gosaAclTemplate as $prio => $entry){
558 $final= "";
559 $members= "";
560 if (isset($entry['members'])){
561 foreach ($entry['members'] as $key => $dummy){
562 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
563 }
564 }
565 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
567 /* ACL's if needed */
568 if ($entry['type'] != "reset" && $entry['type'] != "role"){
569 $acl= ":";
570 if (isset($entry['acl'])){
571 foreach ($entry['acl'] as $object => $contents){
573 /* Only save, if we've some contents in there... */
574 if (count($contents)){
575 $acl.= $object.";";
577 foreach($contents as $attr => $permission){
579 /* First entry? Its the one for global settings... */
580 if ($attr == '0'){
581 $acl.= $permission;
582 } else {
583 $acl.= '#'.$attr.';'.$permission;
584 }
586 }
587 $acl.= ',';
588 }
590 }
591 }
592 $final.= preg_replace('/,$/', '', $acl);
593 }
595 $tmp_acl[]= $final;
596 }
598 /* Call main method */
599 plugin::save();
601 /* Finally (re-)assign it... */
602 $this->attrs["gosaAclTemplate"]= $tmp_acl;
604 /* Remove acl from this entry if it is empty... */
605 if (!count($tmp_acl)){
606 /* Remove attribute */
607 if ($this->initially_was_account){
608 $this->attrs["gosaAclTempalte"]= array();
609 } else {
610 if (isset($this->attrs["gosaAclTemplate"])){
611 unset($this->attrs["gosaAclTemplate"]);
612 }
613 }
614 }
616 /* Do LDAP modifications */
617 $ldap= $this->config->get_ldap_link();
619 /* Check if object already exists */
620 $ldap->cat($this->dn);
621 if($ldap->count()){
622 $ldap->cd($this->dn);
623 $this->cleanup();
624 $ldap->modify ($this->attrs);
625 new log("modify","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
626 }else{
627 $ldap->cd($this->config->current['BASE']);
628 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$this->dn));
629 $ldap->cd($this->dn);
630 $ldap->add($this->attrs);
631 new log("create","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
632 }
634 if (!$ldap->success()){
635 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
636 }
638 /* Refresh users ACL */
639 $ui= get_userinfo();
640 $ui->loadACL();
641 session::set('ui',$ui);
642 }
645 function remove_from_parent()
646 {
647 $ldap = $this->config->get_ldap_link();
648 $serach_for = "*:role:".base64_encode($this->dn).":*";
649 $ldap->search ("(&(objectClass=gosaACL)(gosaAclEntry=".$serach_for."))",array('dn','cn','sn','givenName','uid'));
650 $all_names = "";
653 $cnt = 3;
654 while(($attrs = $ldap->fetch()) && $cnt){
655 $name = $attrs['dn'];
656 $name = preg_replace("/[ ]/"," ",$name);
657 $name = "<i>'".$name."'</i>";
658 $all_names .= $name.", ";
659 $cnt --;
660 }
662 if(!empty($all_names)){
663 $all_names = preg_replace("/, $/","",$all_names);
664 if(!$cnt){
665 $all_names .= ", ...";
666 }
667 $all_names = "<span style='text-align:left;'>".$all_names."</span>";
668 msg_dialog::display(_("Object in use"), sprintf(_("This role cannot be removed while it is in use by these objects:")."<br><br>%s", $all_names), WARNING_DIALOG);
669 return;
670 }
672 $ldap->rmDir($this->dn);
673 new log("remove","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
674 if (!$ldap->success()){
675 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
676 }
678 /* Optionally execute a command after we're done */
679 $this->handle_post_events("remove");
681 /* Delete references to object groups */
682 $ldap->cd ($this->config->current['BASE']);
683 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
684 while ($ldap->fetch()){
685 $og= new ogroup($this->config, $ldap->getDN());
686 unset($og->member[$this->dn]);
687 $og->save ();
688 if (!$ldap->success()){
689 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, "", get_class()));
690 }
691 }
692 }
695 function save_object()
696 {
697 plugin::save_object();
698 if(isset($_POST['acl_role_posted'])){
700 /* Get base selection */
701 if(isset($_POST['base'])){
702 $tmp = $this->get_allowed_bases();
703 if(isset($tmp[$_POST['base']])){
704 $this->base = $_POST['base'];
705 }
706 }
707 }
708 }
711 function saveCopyDialog()
712 {
713 if(isset($_POST['cn'])){
714 $this->cn = $_POST['cn'];
715 }
716 }
719 function getCopyDialog()
720 {
721 $smarty = get_smarty();
722 $smarty->assign("cn",$this->cn);
723 $str = $smarty->fetch(get_template_path("paste_role.tpl",TRUE,dirname(__FILE__)));
724 $ret = array();
725 $ret['string'] = $str;
726 $ret['status'] = "";
727 return($ret);
728 }
731 function PrepareForCopyPaste($source)
732 {
733 plugin::PrepareForCopyPaste($source);
735 $source_o = new aclrole($this->config,$source['dn']);
736 $this->gosaAclTemplate = $source_o->gosaAclTemplate;
737 }
740 /* Return plugin informations for acl handling */
741 static function plInfo()
742 {
743 return (array(
744 "plShortName" => _("Role"),
745 "plDescription" => _("Access control roles"),
746 "plSelfModify" => FALSE,
747 "plDepends" => array(),
748 "plPriority" => 0,
749 "plSection" => array("administration"),
750 "plCategory" => array("acl"),
751 "plProvidedAcls" => array(
752 "cn" => _("Name"),
753 "base" => _("Base"),
754 "description" => _("Description"),
755 "gosaAclEntry" => _("Permissions"))
756 ));
757 }
759 function check()
760 {
761 $message = plugin::check();
763 if(empty($this->cn)){
764 $message[] = msgPool::required(_("Name"));
765 }
767 if(!count($this->gosaAclTemplate)){
768 $message[] = msgPool::required(_("ACL"));
769 }
771 /* Check if we are allowed to create or move this object
772 */
773 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
774 $message[] = msgPool::permCreate();
775 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
776 $message[] = msgPool::permMove();
777 }
779 return($message);
780 }
782 }
784 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
785 ?>