Code

Updated base acl selector
[gosa.git] / gosa-core / plugins / admin / acl / class_aclRole.inc
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       $this->base  = session::get('CurrentMainBase');
66     }else{
67       $this->base = preg_replace("/^[^,]+,[^,]+,/","",$this->dn);
68       new log("view","acl/".get_class($this),$this->dn);
69     }
70    
71     /* Load ACL's */
72     $this->gosaAclTemplate= array();
73     if (isset($this->attrs["gosaAclTemplate"])){
74       for ($i= 0; $i<$this->attrs["gosaAclTemplate"]['count']; $i++){
75         $acl= $this->attrs["gosaAclTemplate"][$i];
76         $this->gosaAclTemplate= array_merge($this->gosaAclTemplate, $this->explodeACL($acl));
77       }
78     }
79     ksort($this->gosaAclTemplate);
81     /* Extract available categories from plugin info list */
82     $tmp= session::get('plist');
83     $plist= $tmp->info;
84     $oc = array();
85     foreach ($plist as $class => $acls){
87       /* Only feed categories */
88       if (isset($acls['plCategory'])){
90         /* Walk through supplied list and feed only translated categories */
91         foreach($acls['plCategory'] as $idx => $data){
93           /* Non numeric index means -> base object containing more informations */
94           if (preg_match('/^[0-9]+$/', $idx)){
95             if (!isset($this->ocMapping[$data])){
96               $this->ocMapping[$data]= array();
97               $this->ocMapping[$data][]= '0';
98             }
99             $this->ocMapping[$data][]= $class;
100           } else {
101             if (!isset($this->ocMapping[$idx])){
102               $this->ocMapping[$idx]= array();
103               $this->ocMapping[$idx][]= '0';
104             }
105             $this->ocMapping[$idx][]= $class;
106             $this->aclObjects[$idx]= $data['description'];
108             /* Additionally filter the classes we're interested in in "self edit" mode */
109             if (is_array($data['objectClass'])){
110               foreach($data['objectClass'] as $objectClass){
111                 if (in_array_ics($objectClass, $oc)){
112                   $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
113                   break;
114                 }
115               }
116             } else {
117               if (in_array_ics($data['objectClass'], $oc)){
118                 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
119               }
120             }
121           }
123         }
124       }
125     }
126     $this->aclObjects['all']= '*&nbsp;'._("All categories");
127     $this->ocMapping['all']= array('0' => 'all');
129     /* Sort categories */
130     asort($this->aclObjects);
132     /* Fill acl types */
133     $this->aclTypes= array( "reset" => _("Reset ACL"),
134                              "one" => _("One level"),
135                              "base" => _("Current object"),
136                              "sub" => _("Complete subtree"),
137                              "psub" => _("Complete subtree (permanent)"));
138     asort($this->aclTypes);
140     /* Finally - we want to get saved... */
141     $this->is_account= TRUE;
142     $this->orig_base = $this->base;
143     $this->orig_dn = $this->dn;
144     $this->orig_cn = $this->cn;
146     /* Instanciate base selector */
147     $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
148     $this->baseSelector->setSubmitButton(false);
149     $this->baseSelector->setHeight(300);
150     $this->baseSelector->update(true);
151   }
154   function execute()
155   {
156     /* Call parent execute */
157     plugin::execute();
159     $tmp= session::get('plist');
160     $plist= $tmp->info;
162     /* Handle posts */
163     if (isset($_POST['new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
164       $this->dialogState= 'create';
165       $this->dialog= TRUE;
166       $this->currentIndex= count($this->gosaAclTemplate);
167       $this->loadAclEntry(TRUE);
168     }
170     $new_acl= array();
171     $aclDialog= FALSE;
172     $firstedit= FALSE;
174     /* Act on HTML post and gets here.
175      */
176     if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act'] == "edit"){
177       $id = trim($_GET['id']);
178       $this->dialogState= 'create';
179       $firstedit= TRUE;
180       $this->dialog= TRUE;
181       $this->currentIndex= $id;
182       $this->loadAclEntry();
183     }
185     foreach($_POST as $name => $post){
187       /* Actions... */
188       if (preg_match('/^acl_edit_.*_x/', $name)){
189         $this->dialogState= 'create';
190         $firstedit= TRUE;
191         $this->dialog= TRUE;
192         $this->currentIndex= preg_replace('/^acl_edit_([0-9]+).*$/', '\1', $name);
193         $this->loadAclEntry();
194         continue;
195       }
196       if (preg_match('/^cat_edit_.*_x/', $name)){
197         $this->aclObject= preg_replace('/^cat_edit_([^_]+)_.*$/', '\1', $name);
198         $this->dialogState= 'edit';
199         foreach ($this->ocMapping[$this->aclObject] as $oc){
200           if (isset($this->aclContents[$oc])){
201             $this->savedAclContents[$oc]= $this->aclContents[$oc];
202           }
203         }
204         continue;
205       }
207       if(!$this->acl_is_writeable("gosaAclEntry")){
208         continue;
209       }
211       if (preg_match('/^acl_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
212         unset($this->gosaAclTemplate[preg_replace('/^acl_del_([0-9]+).*$/', '\1', $name)]);
213         continue;
214       }
216       if (preg_match('/^cat_del_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
217         $idx= preg_replace('/^cat_del_([^_]+)_.*$/', '\1', $name);
218         foreach ($this->ocMapping[$idx] as $key){
219           unset($this->aclContents["$idx/$key"]);
220         }
221         continue;
222       }
224       /* Sorting... */
225       if (preg_match('/^sortup_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
226         $index= preg_replace('/^sortup_([0-9]+).*$/', '\1', $name);
227         if ($index > 0){
228           $tmp= $this->gosaAclTemplate[$index];
229           $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index-1];
230           $this->gosaAclTemplate[$index-1]= $tmp;
231         }
232         continue;
233       }
234       if (preg_match('/^sortdown_.*_x/', $name) && $this->acl_is_writeable("gosaAclEntry")){
235         $index= preg_replace('/^sortdown_([0-9]+).*$/', '\1', $name);
236         if ($index < count($this->gosaAclTemplate)-1){
237           $tmp= $this->gosaAclTemplate[$index];
238           $this->gosaAclTemplate[$index]= $this->gosaAclTemplate[$index+1];
239           $this->gosaAclTemplate[$index+1]= $tmp;
240         }
241         continue;
242       }
244       /* ACL saving... */
245       if (preg_match('/^acl_.*_[^xy]$/', $name) && $this->acl_is_writeable("gosaAclEntry")){
246         list($dummy, $object, $attribute, $value)= explode('_', $name);
248         /* Skip for detection entry */
249         if ($object == 'dummy') {
250           continue;
251         }
253         /* Ordinary ACL */
254         if (!isset($new_acl[$object])){
255           $new_acl[$object]= array();
256         }
257         if (isset($new_acl[$object][$attribute])){
258           $new_acl[$object][$attribute].= $value;
259         } else {
260           $new_acl[$object][$attribute]= $value;
261         }
262       }
263     }
264    
265     if(isset($_POST['acl_dummy_0_0_0'])){
266       $aclDialog= TRUE;
267     }
268  
269     /* Only be interested in new acl's, if we're in the right _POST place */
270     if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
272       foreach ($this->ocMapping[$this->aclObject] as $oc){
273         unset($this->aclContents[$oc]);
274         unset($this->aclContents[$this->aclObject.'/'.$oc]);
275         if (isset($new_acl[$oc])){
276           $this->aclContents[$oc]= $new_acl[$oc];
277         }
278         if (isset($new_acl[$this->aclObject.'/'.$oc])){
279           $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
280         }
281       }
282     }
284     /* Save new acl in case of base edit mode */
285     if (1 == 0 && $this->aclType == 'base' && !$firstedit){
286       $this->aclContents= $new_acl;
287     }
289     /* Cancel new acl? */
290     if (isset($_POST['cancel_new_acl'])){
291       $this->dialogState= 'head';
292       $this->dialog= FALSE;
293       if ($this->wasNewEntry){
294         unset ($this->gosaAclTemplate[$this->currentIndex]);
295       }
296     }
298     /* Store ACL in main object? */
299     if (isset($_POST['submit_new_acl']) && $this->acl_is_writeable("gosaAclEntry")){
300       $this->gosaAclTemplate[$this->currentIndex]['type']= $this->aclType;
301       $this->gosaAclTemplate[$this->currentIndex]['members']= $this->recipients;
302       $this->gosaAclTemplate[$this->currentIndex]['acl']= $this->aclContents;
303       $this->dialogState= 'head';
304       $this->dialog= FALSE;
305     }
307     /* Cancel edit acl? */
308     if (isset($_POST['cancel_edit_acl'])){
309       $this->dialogState= 'create';
310       foreach ($this->ocMapping[$this->aclObject] as $oc){
311         if (isset($this->savedAclContents[$oc])){
312           $this->aclContents[$oc]= $this->savedAclContents[$oc];
313         }
314       }
315     }
317     /* Save edit acl? */
318     if (isset($_POST['submit_edit_acl']) && $this->acl_is_writeable("gosaAclEntry")){
319       $this->dialogState= 'create';
320     }
322     /* Add acl? */
323     if (isset($_POST['add_acl']) && $_POST['aclObject'] != "" && $this->acl_is_writeable("gosaAclEntry")){
324       $this->dialogState= 'edit';
325       $this->savedAclContents= array();
326       foreach ($this->ocMapping[$this->aclObject] as $oc){
327         if (isset($this->aclContents[$oc])){
328           $this->savedAclContents[$oc]= $this->aclContents[$oc];
329         }
330       }
331     }
333     /* Save common values */
334     foreach (array("aclType", "aclObject", "target") as $key){
335       if (isset($_POST[$key]) && $this->acl_is_writeable("gosaAclEntry")){
336         $this->$key= validate($_POST[$key]);
337       }
338     }
340     /* Create templating instance */
341     $smarty= get_smarty();
342     $smarty->assign("usePrototype", "true");
344     $smarty->assign("base", $this->baseSelector->render());
346     $tmp = $this->plInfo();
347     foreach($tmp['plProvidedAcls'] as $name => $translation){
348       $smarty->assign($name."ACL",$this->getacl($name));
349     }
351     if ($this->dialogState == 'head'){
352       /* Draw list */
353       $aclList= new divSelectBox("aclList");
354       $aclList->SetHeight(350);
356       /* Fill in entries */
357       foreach ($this->gosaAclTemplate as $key => $entry){
359         if($this->acl_is_readable("")){
360           $link = "<a href=?plug=".$_GET['plug']."&amp;id=".$key."&amp;act=edit>".$this->assembleAclSummary($entry)."</a>";
361         }else{
362           $link = $this->assembleAclSummary($entry);
363         }
365         $field1= array("string" => $this->aclTypes[$entry['type']], "attach" => "style='width:150px'");
366         $field2= array("string" => $link);
368         $action ="";
369         if($this->acl_is_writeable("gosaAclEntry")){
370           $action.= "<input type='image' name='sortup_$key' alt='up' 
371             title='"._("Up")."' src='images/lists/sort-up.png' align='top'>";
372           $action.= "<input type='image' name='sortdown_$key' alt='down' 
373             title='"._("Down")."' src='images/lists/sort-down.png'>";
374         }
375         if($this->acl_is_readable("gosaAclEntry")){
376           $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("Edit")."' name='acl_edit_$key' 
377             title='".msgPool::editButton(_("ACL"))."'>";
378         }
379         if($this->acl_is_writeable("gosaAclEntry")){
380           $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("Delete")."' name='acl_del_$key' 
381             title='".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       /* Add settings for all categories to the (permanent) list */
397       foreach ($this->aclObjects as $section => $dsc){
398         $summary= "";
399         foreach($this->ocMapping[$section] as $oc){
400           if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
401               $this->aclContents[$oc][0] != ""){
403             $summary.= "$oc, ";
404             continue;
405           }
406           if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
407             $summary.= "$oc, ";
408             continue;
409           }
410           if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
411             $summary.= "$oc, ";
412           }
413         }
415         /* Set summary... */
416         if ($summary == ""){
417           $summary= '<i>'._("No ACL settings for this category").'</i>';
418         } else {
419           $summary= sprintf(_("ACL for these objects: %s"), preg_replace('/, $/', '', $summary));
420         }
422         $action = "";
423         if($this->acl_is_readable("gosaAclEntry")){
424           $action.= "<input class='center' type='image' src='images/lists/edit.png' 
425             alt='"._("Edit")."' name='cat_edit_$section'   title='"._("Edit category ACL")."'>";
426         }
427         if($this->acl_is_writeable("gosaAclEntry")){
428           $action.= "<input class='center' type='image' src='images/lists/trash.png' 
429             alt='"._("Delete")."' name='cat_del_$section' title='"._("Reset category ACL")."'>";
430         }
432         $field1= array("string" => $dsc, "attach" => "style='width:140px'");
433         $field2= array("string" => $summary);
434         $field3= array("string" => $action, "attach" => "style='border-right:0px;width:50px'");
435         $aclList->AddEntry(array($field1, $field2, $field3));
436       }
438       $smarty->assign("aclList", $aclList->DrawList());
439       $smarty->assign("aclType", $this->aclType);
440       $smarty->assign("aclTypes", $this->aclTypes);
441       $smarty->assign("target", $this->target);
443       if ($this->aclType == 'base'){
444         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
445       }
446     }
448     if ($this->dialogState == 'edit'){
449       $smarty->assign('headline', sprintf(_("Edit ACL for '%s', scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
451       /* Collect objects for selected category */
452       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
453         if ($idx == 0){
454           continue;
455         }
456         $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
457       }
458       if ($this->aclObject == 'all'){
459         $aclObjects['all']= _("All objects in current subtree");
460       }
461       $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
462     }
464     /* Show main page */
465     $smarty->assign("dialogState", $this->dialogState);
467     /* Assign cn and decription if this is a role */
468     foreach(array("cn","description") as $name){
469       $smarty->assign($name,$this->$name);
470     }
471     return ($smarty->fetch (get_template_path('acl_role.tpl',dirname(__FILE__))));
472   }
474   function sort_by_priority($list)
475   {
476     $tmp= session::get('plist');
477     $plist= $tmp->info;
478     asort($plist);
479     $newSort = array();
481     foreach($list as $name => $translation){
482       $na  =  preg_replace("/^.*\//","",$name);
483       if (!isset($plist[$na]['plPriority'])){
484         $prio= 0;
485       } else {
486         $prio=  $plist[$na]['plPriority'] ;
487       }
489       $newSort[$name] = $prio;
490     }
492     asort($newSort);
494     $ret = array();
495     foreach($newSort as $name => $prio){
496       $ret[$name] = $list[$name];
497     }
498     return($ret);
499   }
501   function loadAclEntry($new= FALSE)
502   {
503     /* New entry gets presets... */
504     if ($new){
505       $this->aclType= 'sub';
506       $this->recipients= array();
507       $this->aclContents= array();
508     } else {
509       $acl= $this->gosaAclTemplate[$this->currentIndex];
510       $this->aclType= $acl['type'];
511       $this->recipients= $acl['members'];
512       $this->aclContents= $acl['acl'];
513     }
515     $this->wasNewEntry= $new;
516   }
519   function aclPostHandler()
520   {
521     if (isset($_POST['save_acl']) && $this->acl_is_writeable("gosaAclEntry")){
522       $this->save();
523       return TRUE;
524     }
526     return FALSE;
527   }
530   function save()
531   {
532     /* Assemble ACL's */
533     $tmp_acl= array();
534     foreach ($this->gosaAclTemplate as $prio => $entry){
535       $final= "";
536       $members= "";
537       if (isset($entry['members'])){
538         foreach ($entry['members'] as $key => $dummy){
539           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
540         }
541       }
542       $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
544       /* ACL's if needed */
545       if ($entry['type'] != "reset" && $entry['type'] != "role"){
546         $acl= ":";
547         if (isset($entry['acl'])){
548           foreach ($entry['acl'] as $object => $contents){
550             /* Only save, if we've some contents in there... */
551             if (count($contents)){
552               $acl.= $object.";";
554               foreach($contents as $attr => $permission){
556                 /* First entry? Its the one for global settings... */
557                 if ($attr == '0'){
558                   $acl.= $permission;
559                 } else {
560                   $acl.= '#'.$attr.';'.$permission;
561                 }
563               }
564               $acl.= ',';
565             }
566             
567           }
568         }
569         $final.= preg_replace('/,$/', '', $acl);
570       }
572       $tmp_acl[]= $final;
573     } 
575     /* Call main method */
576     plugin::save();
578     /* Finally (re-)assign it... */
579     $this->attrs["gosaAclTemplate"]= $tmp_acl;
581     /* Remove acl from this entry if it is empty... */
582     if (!count($tmp_acl)){
583       /* Remove attribute */
584       if ($this->initially_was_account){
585         $this->attrs["gosaAclTempalte"]= array();
586       } else {
587         if (isset($this->attrs["gosaAclTemplate"])){
588           unset($this->attrs["gosaAclTemplate"]);
589         }
590       }
591     }
593     /* Do LDAP modifications */
594     $ldap= $this->config->get_ldap_link();
596     /* Check if object already exists */
597     $ldap->cat($this->dn);
598     if($ldap->count()){
599       $ldap->cd($this->dn);
600       $this->cleanup();
601       $ldap->modify ($this->attrs);
602       new log("modify","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
603     }else{
604       $ldap->cd($this->config->current['BASE']);
605       $ldap->create_missing_trees(preg_replace("/^[^,]+,/","",$this->dn));
606       $ldap->cd($this->dn);
607       $ldap->add($this->attrs);
608       new log("create","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
609     }
611     if (!$ldap->success()){
612       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
613     }
615     /* Refresh users ACL */
616     $ui= get_userinfo();
617     $ui->loadACL();
618     session::set('ui',$ui);
619   }
622   function remove_from_parent()
623   {
624     $ldap = $this->config->get_ldap_link();
625     $serach_for = "*:role:".base64_encode($this->dn).":*"; 
626     $ldap->search ("(&(objectClass=gosaACL)(gosaAclEntry=".$serach_for."))",array('dn','cn','sn','givenName','uid'));
627     $all_names = "";
630     $cnt = 3;
631     while(($attrs = $ldap->fetch()) && $cnt){
632       $name = $attrs['dn'];
633       $name = preg_replace("/[ ]/","&nbsp;",$name);
634       $name = "<i>'".$name."'</i>";
635       $all_names .= $name.", ";
636       $cnt --;
637     }
639     if(!empty($all_names)){
640       $all_names = preg_replace("/, $/","",$all_names);
641       if(!$cnt){
642         $all_names .= ", ...";
643       }
644       $all_names = "<span style='text-align:left;'>".$all_names."</span>";
645       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);
646       return;
647     }
648         
649     $ldap->rmDir($this->dn);
650     new log("remove","acl/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
651     if (!$ldap->success()){
652       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, "", get_class()));
653     }
655     /* Optionally execute a command after we're done */
656     $this->handle_post_events("remove");
658     /* Delete references to object groups */
659     $ldap->cd ($this->config->current['BASE']);
660     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
661     while ($ldap->fetch()){
662       $og= new ogroup($this->config, $ldap->getDN());
663       unset($og->member[$this->dn]);
664       $og->save ();
665       if (!$ldap->success()){
666         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, "", get_class()));
667       }
668     }
669   }
672   function save_object()
673   {
674     plugin::save_object();
675     if(isset($_POST['acl_role_posted'])){
676      
677       /* Refresh base */
678       if ($this->acl_is_moveable($this->base)){
679         if (!$this->baseSelector->update()) {
680           msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
681         }
682         if ($this->base != $this->baseSelector->getBase()) {
683           $this->base= $this->baseSelector->getBase();
684           $this->is_modified= TRUE;
685         }
686       }
687     }
688   }
691   function saveCopyDialog()
692   {
693     if(isset($_POST['cn'])){
694       $this->cn = $_POST['cn'];
695     }
696   }
697   
699   function getCopyDialog()
700   {
701     $smarty = get_smarty();
702     $smarty->assign("cn",$this->cn);
703     $str = $smarty->fetch(get_template_path("paste_role.tpl",TRUE,dirname(__FILE__)));
704     $ret = array();
705     $ret['string'] = $str;
706     $ret['status'] = "";
707     return($ret);
708   }
710   
711   function PrepareForCopyPaste($source)
712   {
713     plugin::PrepareForCopyPaste($source);
714     
715     $source_o = new aclrole($this->config,$source['dn']);
716     $this->gosaAclTemplate = $source_o->gosaAclTemplate;
717   }
718   
720   /* Return plugin informations for acl handling  */
721   static function plInfo()
722   {
723     return (array(
724           "plShortName" => _("Role"),
725           "plDescription" => _("Access control roles"),
726           "plSelfModify"  => FALSE,
727           "plDepends"     => array(),
728           "plPriority"    => 0,
729           "plSection"     => array("administration"),
730           "plCategory"    => array("acl"),
731           "plProvidedAcls"    => array(
732             "cn"                => _("Name"),
733             "base"              => _("Base"),
734             "description"       => _("Description"),
735             "gosaAclEntry"      => _("Permissions"))
736         ));
737   }
739   function check()
740   {
741     $message = plugin::check();
743     if(empty($this->cn)){
744       $message[] = msgPool::required(_("Name"));
745     }
746   
747     $ldap = $this->config->get_ldap_link();
748     $ldap->cd($this->config->current['BASE']);
749     if($this->cn != $this->orig_cn){
750       $ldap->search("(&(objectClass=gosaRole)(cn=".$this->cn."))");
751       if($ldap->count()) {
752         while($attrs = $ldap->fetch()){
753           if($attrs['dn'] != $this->orig_dn){
754             $message[] = msgPool::duplicated(_("Name"));
755           }
756         }
757       }
758     } 
759  
760     if(!count($this->gosaAclTemplate)){
761       $message[] = msgPool::required(_("ACL"));
762     }
763  
764     /* Check if we are allowed to create or move this object
765      */
766     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
767       $message[] = msgPool::permCreate();
768     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
769       $message[] = msgPool::permMove();
770     }
772     return($message);
773   }
777 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
778 ?>