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 $orig_cn = "";
53 var $description = "";
54 var $orig_dn;
55 var $orig_base;
56 var $base ="";
57 var $baseSelector;
59 function aclrole (&$config, $dn= NULL)
60 {
61 /* Include config object */
62 plugin::plugin($config, $dn);
64 if($this->dn == "new"){
65 $ui = get_userinfo();
66 $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=test,".session::global_get("CurrentMainBase"):$ui->dn);
67 }else{
68 $this->base = preg_replace("/^[^,]+,[^,]+,/","",$this->dn);
69 new log("view","acl/".get_class($this),$this->dn);
70 }
72 /* Load ACL's */
73 $this->gosaAclTemplate= array();
74 if (isset($this->attrs["gosaAclTemplate"])){
75 for ($i= 0; $i<$this->attrs["gosaAclTemplate"]['count']; $i++){
76 $acl= $this->attrs["gosaAclTemplate"][$i];
77 $this->gosaAclTemplate= array_merge($this->gosaAclTemplate, $this->explodeACL($acl));
78 }
79 }
80 ksort($this->gosaAclTemplate);
82 /* Extract available categories from plugin info list */
83 $tmp= session::get('plist');
84 $plist= $tmp->info;
85 $oc = array();
86 foreach ($plist as $class => $acls){
88 /* Only feed categories */
89 if (isset($acls['plCategory'])){
91 /* Walk through supplied list and feed only translated categories */
92 foreach($acls['plCategory'] as $idx => $data){
94 /* Non numeric index means -> base object containing more informations */
95 if (preg_match('/^[0-9]+$/', $idx)){
96 if (!isset($this->ocMapping[$data])){
97 $this->ocMapping[$data]= array();
98 $this->ocMapping[$data][]= '0';
99 }
100 $this->ocMapping[$data][]= $class;
101 } else {
102 if (!isset($this->ocMapping[$idx])){
103 $this->ocMapping[$idx]= array();
104 $this->ocMapping[$idx][]= '0';
105 }
106 $this->ocMapping[$idx][]= $class;
107 $this->aclObjects[$idx]= $data['description'];
109 /* Additionally filter the classes we're interested in in "self edit" mode */
110 if (is_array($data['objectClass'])){
111 foreach($data['objectClass'] as $objectClass){
112 if (in_array_ics($objectClass, $oc)){
113 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
114 break;
115 }
116 }
117 } else {
118 if (in_array_ics($data['objectClass'], $oc)){
119 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
120 }
121 }
122 }
124 }
125 }
126 }
127 $this->aclObjects['all']= '* '._("All categories");
128 $this->ocMapping['all']= array('0' => 'all');
130 /* Sort categories */
131 asort($this->aclObjects);
133 /* Fill acl types */
134 $this->aclTypes= array( "reset" => _("Reset ACL"),
135 "one" => _("One level"),
136 "base" => _("Current object"),
137 "sub" => _("Complete subtree"),
138 "psub" => _("Complete subtree (permanent)"));
139 asort($this->aclTypes);
141 /* Finally - we want to get saved... */
142 $this->is_account= TRUE;
143 $this->orig_base = $this->base;
144 $this->orig_dn = $this->dn;
145 $this->orig_cn = $this->cn;
147 /* Instanciate base selector */
148 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
149 $this->baseSelector->setSubmitButton(false);
150 $this->baseSelector->setHeight(300);
151 $this->baseSelector->update(true);
152 }
155 function execute()
156 {
157 /* Call parent execute */
158 plugin::execute();
160 $tmp= session::get('plist');
161 $plist= $tmp->info;
163 /* Handle posts */
164 if (isset($_POST['new_acl']) && $this->acl_is_writeable("gosaAclTemplate")){
165 $this->dialogState= 'create';
166 $this->dialog= TRUE;
167 $this->currentIndex= count($this->gosaAclTemplate);
168 $this->loadAclEntry(TRUE);
169 }
171 $new_acl= array();
172 $aclDialog= FALSE;
173 $firstedit= FALSE;
175 /* Act on HTML post and gets here.
176 */
177 if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
178 $id = trim($_GET['id']);
179 $this->dialogState= 'create';
180 $firstedit= TRUE;
181 $this->dialog= TRUE;
182 $this->currentIndex= $id;
183 $this->loadAclEntry();
184 }
186 foreach($_POST as $name => $post){
188 /* Actions... */
189 if (preg_match('/^acl_edit_[0-9]*$/', $name)){
190 $this->dialogState= 'create';
191 $firstedit= TRUE;
192 $this->dialog= TRUE;
193 $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
194 $this->loadAclEntry();
195 continue;
196 }
197 if (preg_match('/^cat_edit_/', $name)){
198 $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
199 $this->dialogState= 'edit';
200 foreach ($this->ocMapping[$this->aclObject] as $oc){
201 if (isset($this->aclContents[$oc])){
202 $this->savedAclContents[$oc]= $this->aclContents[$oc];
203 }
204 }
205 continue;
206 }
208 if(!$this->acl_is_writeable("gosaAclTemplate")){
209 continue;
210 }
212 if (preg_match('/^acl_del_[0-9]*/', $name) && $this->acl_is_writeable("gosaAclTemplate")){
213 unset($this->gosaAclTemplate[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
214 continue;
215 }
217 if (preg_match('/^cat_del_.*/', $name) && $this->acl_is_writeable("gosaAclTemplate")){
218 $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
219 foreach ($this->ocMapping[$idx] as $key){
220 if(isset($this->aclContents[$idx]))
221 unset($this->aclContents[$idx]);
222 if(isset($this->aclContents["$idx/$key"]))
223 unset($this->aclContents["$idx/$key"]);
224 }
225 continue;
226 }
228 /* Sorting... */
229 if (preg_match('/^sortup_[0-9]*$/', $name) && $this->acl_is_writeable("gosaAclTemplate")){
230 $index= preg_replace('/^sortup_([0-9]*)$/', '\1', $name);
231 if ($index > 0){
232 $tmp= $this->gosaAclTemplate[$index];
233 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index-1];
234 $this->gosaAclTemplate[$index-1]= $tmp;
235 }
236 continue;
237 }
238 if (preg_match('/^sortdown_[0-9]*$/', $name) && $this->acl_is_writeable("gosaAclTemplate")){
239 $index= preg_replace('/^sortdown_([0-9]*)$/', '\1', $name);
240 if ($index < count($this->gosaAclTemplate)-1){
241 $tmp= $this->gosaAclTemplate[$index];
242 $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index+1];
243 $this->gosaAclTemplate[$index+1]= $tmp;
244 }
245 continue;
246 }
248 /* ACL saving... */
249 if (preg_match('/^acl_.*_[^xy]$/', $name) && $this->acl_is_writeable("gosaAclTemplate")){
250 list($dummy, $object, $attribute, $value)= explode('_', $name);
252 /* Skip for detection entry */
253 if ($object == 'dummy') {
254 continue;
255 }
257 /* Ordinary ACL */
258 if (!isset($new_acl[$object])){
259 $new_acl[$object]= array();
260 }
261 if (isset($new_acl[$object][$attribute])){
262 $new_acl[$object][$attribute].= $value;
263 } else {
264 $new_acl[$object][$attribute]= $value;
265 }
266 }
267 }
269 if(isset($_POST['acl_dummy_0_0_0'])){
270 $aclDialog= TRUE;
271 }
273 /* Only be interested in new acl's, if we're in the right _POST place */
274 if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
276 foreach ($this->ocMapping[$this->aclObject] as $oc){
277 unset($this->aclContents[$oc]);
278 unset($this->aclContents[$this->aclObject.'/'.$oc]);
279 if (isset($new_acl[$oc])){
280 $this->aclContents[$oc]= $new_acl[$oc];
281 }
282 if (isset($new_acl[$this->aclObject.'/'.$oc])){
283 $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
284 }
285 }
286 }
288 /* Save new acl in case of base edit mode */
289 if (1 == 0 && $this->aclType == 'base' && !$firstedit){
290 $this->aclContents= $new_acl;
291 }
293 /* Cancel new acl? */
294 if (isset($_POST['cancel_new_acl'])){
295 $this->dialogState= 'head';
296 $this->dialog= FALSE;
297 if ($this->wasNewEntry){
298 unset ($this->gosaAclTemplate[$this->currentIndex]);
299 }
300 }
302 /* Store ACL in main object? */
303 if (isset($_POST['submit_new_acl']) && $this->acl_is_writeable("gosaAclTemplate")){
304 $this->gosaAclTemplate[$this->currentIndex]['type']= $this->aclType;
305 $this->gosaAclTemplate[$this->currentIndex]['members']= $this->recipients;
306 $this->gosaAclTemplate[$this->currentIndex]['acl']= $this->aclContents;
307 $this->dialogState= 'head';
308 $this->dialog= FALSE;
309 }
311 /* Cancel edit acl? */
312 if (isset($_POST['cancel_edit_acl'])){
313 $this->dialogState= 'create';
314 foreach ($this->ocMapping[$this->aclObject] as $oc){
315 if (isset($this->savedAclContents[$oc])){
316 $this->aclContents[$oc]= $this->savedAclContents[$oc];
317 }
318 }
319 }
321 /* Save edit acl? */
322 if (isset($_POST['submit_edit_acl']) && $this->acl_is_writeable("gosaAclTemplate")){
323 $this->dialogState= 'create';
324 }
326 /* Add acl? */
327 if (isset($_POST['add_acl']) && $_POST['aclObject'] != "" && $this->acl_is_writeable("gosaAclTemplate")){
328 $this->dialogState= 'edit';
329 $this->savedAclContents= array();
330 foreach ($this->ocMapping[$this->aclObject] as $oc){
331 if (isset($this->aclContents[$oc])){
332 $this->savedAclContents[$oc]= $this->aclContents[$oc];
333 }
334 }
335 }
337 /* Save common values */
338 foreach (array("aclType", "aclObject", "target") as $key){
339 if (isset($_POST[$key]) && $this->acl_is_writeable("gosaAclTemplate")){
340 $this->$key= validate($_POST[$key]);
341 }
342 }
344 /* Create templating instance */
345 $smarty= get_smarty();
346 $smarty->assign("usePrototype", "true");
348 $smarty->assign("base", $this->baseSelector->render());
350 $tmp = $this->plInfo();
351 foreach($tmp['plProvidedAcls'] as $name => $translation){
352 $smarty->assign($name."ACL",$this->getacl($name));
353 }
355 if ($this->dialogState == 'head'){
356 /* Draw list */
357 $aclList= new divSelectBox("aclList");
358 $aclList->SetHeight(350);
360 /* Fill in entries */
361 foreach ($this->gosaAclTemplate as $key => $entry){
363 if($this->acl_is_readable("")){
364 $link = "<a href=?plug=".$_GET['plug']."&id=".$key."&act=edit>".$this->assembleAclSummary($entry)."</a>";
365 }else{
366 $link = $this->assembleAclSummary($entry);
367 }
369 $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
370 $field2= array("string" => $link);
372 $action ="";
373 if($this->acl_is_writeable("gosaAclTemplate")){
374 $action.=image('images/lists/sort-up.png','sortup_'.$key,'','top');
375 $action.=image('images/lists/sort-down.png','sortdown_'.$key,'','bottom');
376 }
377 if($this->acl_is_readable("gosaAclTemplate")){
378 $action.= image('images/lists/edit.png','acl_edit_'.$key,msgPool::editButton(_("ACL")));
379 }
380 if($this->acl_is_writeable("gosaAclTemplate")){
381 $action.= image('images/lists/trash.png','acl_del_'.$key,msgPool::delButton(_("ACL")));
382 }
384 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px;text-align:right;'");
385 $aclList->AddEntry(array($field1, $field2, $field3));
386 }
388 $smarty->assign("aclList", $aclList->DrawList());
389 }
391 if ($this->dialogState == 'create'){
392 /* Draw list */
393 $aclList= new divSelectBox("aclList");
394 $aclList->SetHeight(450);
396 // Create a map of all used sections, this allows us to simply hide the remove button
397 // if no acl is configured for the given section
398 // e.g. ';all;department/country;users/user;
399 $usedList = ";".implode(array_keys($this->aclContents),';').";";
402 /* Add settings for all categories to the (permanent) list */
403 foreach ($this->aclObjects as $section => $dsc){
404 $summary= "";
405 foreach($this->ocMapping[$section] as $oc){
406 if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
407 $this->aclContents[$oc][0] != ""){
409 $summary.= "$oc, ";
410 continue;
411 }
412 if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
413 $summary.= "$oc, ";
414 continue;
415 }
416 if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
417 $summary.= "$oc, ";
418 }
419 }
421 /* Set summary... */
422 if ($summary == ""){
423 $summary= '<i>'._("No ACL settings for this category").'</i>';
424 } else {
425 $summary= sprintf(_("ACL for these objects: %s"), preg_replace('/, $/', '', $summary));
426 }
428 $action = "";
429 if($this->acl_is_readable("gosaAclTemplate")){
430 $action.= image('images/lists/edit.png','cat_edit_'.$section,_("Edit category ACL"));
431 }
432 if($this->acl_is_writeable("gosaAclTemplate") && preg_match("/;".$section."(;|\/)/", $usedList)){
433 $action.= image('images/lists/trash.png','cat_del_'.$section,_("Delete category ACL"));
434 }
436 $field1= array("string" => $dsc, "attach" => "style='width:140px'");
437 $field2= array("string" => $summary);
438 $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
439 $aclList->AddEntry(array($field1, $field2, $field3));
440 }
442 $smarty->assign("aclList", $aclList->DrawList());
443 $smarty->assign("aclType", $this->aclType);
444 $smarty->assign("aclTypes", $this->aclTypes);
445 $smarty->assign("target", $this->target);
447 if ($this->aclType == 'base'){
448 $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
449 }
450 }
452 if ($this->dialogState == 'edit'){
453 $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
455 /* Collect objects for selected category */
456 foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
457 if ($idx == 0){
458 continue;
459 }
460 $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
461 }
462 if ($this->aclObject == 'all'){
463 $aclObjects['all']= _("All objects in current subtree");
464 }
465 $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
466 }
468 /* Show main page */
469 $smarty->assign("dialogState", $this->dialogState);
471 /* Assign cn and decription if this is a role */
472 foreach(array("cn","description") as $name){
473 $smarty->assign($name,$this->$name);
474 }
475 return ($smarty->fetch (get_template_path('acl_role.tpl',dirname(__FILE__))));
476 }
478 function sort_by_priority($list)
479 {
480 $tmp= session::get('plist');
481 $plist= $tmp->info;
482 asort($plist);
483 $newSort = array();
485 foreach($list as $name => $translation){
486 $na = preg_replace("/^.*\//","",$name);
487 if (!isset($plist[$na]['plPriority'])){
488 $prio= 0;
489 } else {
490 $prio= $plist[$na]['plPriority'] ;
491 }
493 $newSort[$name] = $prio;
494 }
496 asort($newSort);
498 $ret = array();
499 foreach($newSort as $name => $prio){
500 $ret[$name] = $list[$name];
501 }
502 return($ret);
503 }
505 function loadAclEntry($new= FALSE)
506 {
507 /* New entry gets presets... */
508 if ($new){
509 $this->aclType= 'sub';
510 $this->recipients= array();
511 $this->aclContents= array();
512 } else {
513 $acl= $this->gosaAclTemplate[$this->currentIndex];
514 $this->aclType= $acl['type'];
515 $this->recipients= $acl['members'];
516 $this->aclContents= $acl['acl'];
517 }
519 $this->wasNewEntry= $new;
520 }
523 function aclPostHandler()
524 {
525 if (isset($_POST['save_acl']) && $this->acl_is_writeable("gosaAclTemplate")){
526 $this->save();
527 return TRUE;
528 }
530 return FALSE;
531 }
534 function save()
535 {
536 /* Assemble ACL's */
537 $tmp_acl= array();
538 foreach ($this->gosaAclTemplate as $prio => $entry){
539 $final= "";
540 $members= "";
541 if (isset($entry['members'])){
542 foreach ($entry['members'] as $key => $dummy){
543 $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
544 }
545 }
546 $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
548 /* ACL's if needed */
549 if ($entry['type'] != "reset" && $entry['type'] != "role"){
550 $acl= ":";
551 if (isset($entry['acl'])){
552 foreach ($entry['acl'] as $object => $contents){
554 /* Only save, if we've some contents in there... */
555 if (count($contents)){
556 $acl.= $object.";";
558 foreach($contents as $attr => $permission){
560 /* First entry? Its the one for global settings... */
561 if ($attr == '0'){
562 $acl.= $permission;
563 } else {
564 $acl.= '#'.$attr.';'.$permission;
565 }
567 }
568 $acl.= ',';
569 }
571 }
572 }
573 $final.= preg_replace('/,$/', '', $acl);
574 }
576 $tmp_acl[]= $final;
577 }
579 /* Call main method */
580 plugin::save();
582 /* Finally (re-)assign it... */
583 $this->attrs["gosaAclTemplate"]= $tmp_acl;
585 /* Remove acl from this entry if it is empty... */
586 if (!count($tmp_acl)){
587 /* Remove attribute */
588 if ($this->initially_was_account){
589 $this->attrs["gosaAclTempalte"]= array();
590 } else {
591 if (isset($this->attrs["gosaAclTemplate"])){
592 unset($this->attrs["gosaAclTemplate"]);
593 }
594 }
595 }
597 /* Do LDAP modifications */
598 $ldap= $this->config->get_ldap_link();
600 /* Check if object already exists */
601 $ldap->cat($this->dn);
602 if($ldap->count()){
603 $ldap->cd($this->dn);
604 $this->cleanup();
605 $ldap->modify ($this->attrs);
606 new log("modify","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
607 }else{
608 $ldap->cd($this->config->current['BASE']);
609 $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$this->dn));
610 $ldap->cd($this->dn);
611 $ldap->add($this->attrs);
612 new log("create","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
613 }
615 if (!$ldap->success()){
616 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
617 }
619 /* Refresh users ACL */
620 $ui= get_userinfo();
621 $ui->loadACL();
622 session::set('ui',$ui);
623 }
626 function remove_from_parent()
627 {
628 $ldap = $this->config->get_ldap_link();
629 $serach_for = "*:role:".base64_encode($this->dn).":*";
630 $ldap->search ("(&(objectClass=gosaACL)(gosaAclEntry=".$serach_for."))",array('dn','cn','sn','givenName','uid'));
631 $all_names = "";
634 $cnt = 3;
635 while(($attrs = $ldap->fetch()) && $cnt){
636 $name = $attrs['dn'];
637 $name = preg_replace("/[ ]/"," ",$name);
638 $name = "<i>'".$name."'</i>";
639 $all_names .= $name.", ";
640 $cnt --;
641 }
643 if(!empty($all_names)){
644 $all_names = preg_replace("/, $/","",$all_names);
645 if(!$cnt){
646 $all_names .= ", ...";
647 }
648 $all_names = "<span style='text-align:left;'>".$all_names."</span>";
649 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);
650 return;
651 }
653 $ldap->rmDir($this->dn);
654 new log("remove","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
655 if (!$ldap->success()){
656 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
657 }
659 /* Optionally execute a command after we're done */
660 $this->handle_post_events("remove");
662 /* Delete references to object groups */
663 $ldap->cd ($this->config->current['BASE']);
664 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
665 while ($ldap->fetch()){
666 $og= new ogroup($this->config, $ldap->getDN());
667 unset($og->member[$this->dn]);
668 $og->save ();
669 if (!$ldap->success()){
670 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, "", get_class()));
671 }
672 }
673 }
676 function save_object()
677 {
678 plugin::save_object();
679 if(isset($_POST['acl_role_posted'])){
681 /* Refresh base */
682 if ($this->acl_is_moveable($this->base)){
683 if (!$this->baseSelector->update()) {
684 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
685 }
686 if ($this->base != $this->baseSelector->getBase()) {
687 $this->base= $this->baseSelector->getBase();
688 $this->is_modified= TRUE;
689 }
690 }
691 }
692 }
695 function saveCopyDialog()
696 {
697 if(isset($_POST['cn'])){
698 $this->cn = $_POST['cn'];
699 }
700 }
703 function getCopyDialog()
704 {
705 $smarty = get_smarty();
706 $smarty->assign("cn",$this->cn);
707 $str = $smarty->fetch(get_template_path("paste_role.tpl",TRUE,dirname(__FILE__)));
708 $ret = array();
709 $ret['string'] = $str;
710 $ret['status'] = "";
711 return($ret);
712 }
715 function PrepareForCopyPaste($source)
716 {
717 plugin::PrepareForCopyPaste($source);
719 $source_o = new aclrole($this->config,$source['dn']);
720 $this->gosaAclTemplate = $source_o->gosaAclTemplate;
721 }
724 /* Return plugin informations for acl handling */
725 static function plInfo()
726 {
727 return (array(
728 "plShortName" => _("Role"),
729 "plDescription" => _("Access control roles"),
730 "plSelfModify" => FALSE,
731 "plDepends" => array(),
732 "plPriority" => 0,
733 "plSection" => array("administration"),
734 "plCategory" => array("acl"),
735 "plProvidedAcls" => array(
736 "cn" => _("Name"),
737 "base" => _("Base"),
738 "description" => _("Description"),
739 "gosaAclTemplate" => _("Permissions"))
740 ));
741 }
743 function check()
744 {
745 $message = plugin::check();
747 if(empty($this->cn)){
748 $message[] = msgPool::required(_("Name"));
749 }
751 $ldap = $this->config->get_ldap_link();
752 $ldap->cd($this->config->current['BASE']);
753 if($this->cn != $this->orig_cn){
754 $ldap->search("(&(objectClass=gosaRole)(cn=".$this->cn."))");
755 if($ldap->count()) {
756 while($attrs = $ldap->fetch()){
757 if($attrs['dn'] != $this->orig_dn){
758 $message[] = msgPool::duplicated(_("Name"));
759 }
760 }
761 }
762 }
764 if(!count($this->gosaAclTemplate)){
765 $message[] = msgPool::required(_("ACL"));
766 }
768 // Check if a wrong base was supplied
769 if(!$this->baseSelector->checkLastBaseUpdate()){
770 $message[]= msgPool::check_base();;
771 }
773 /* Check if we are allowed to create or move this object
774 */
775 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
776 $message[] = msgPool::permCreate();
777 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
778 $message[] = msgPool::permMove();
779 }
781 return($message);
782 }
784 }
786 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
787 ?>