Code

5719106bb021058caeac5dcf09b843c73ed27668
[gosa.git] / gosa-core / include / class_userFilterEditor.inc
1 <?php
3 class userFilterEditor extends plugin 
4 {
5   // The original entry else array(), allows us to perform existence checks.
6   public $entry = array();
8   // The values
9   public $name = "";
10   public $description = "";
11   public $selectedCategories = array();
12   public $share = FALSE;
13   public $enabled = TRUE;
14   public $filter = "(objectClass=*)";
16   // The list of all categories mangaged by the current filter object.
17   // Used in the grop-down box.
18   public $availableCategories = array();
19   public $orig_name = "";
22   /*! \brief    Instantiate the filter editing dialog. 
23    *            Parses the filter info into editable data.
24    */
25   function __construct($entry, $categories)
26   {
27     $this->availableCategories = $categories;
28     if($entry){
29       $this->entry = $entry;
30       $this->name = $entry['name'];
31       $this->description = $entry['description'];
32       $this->filter = $entry['filter'];
33       $this->selectedCategories = $entry['categories'];
34       $this->share = in_array("share",$entry['flags']);
35       $this->enable = in_array("enable",$entry['flags']);
36     }
37     $this->orig_name = $this->name;
38   }
41   /*! \brief    Retunrs the filters original name 
42    *  @param    The original name of the filter (if none was given 
43    *             an empty string is returned)
44    */
45   function getOriginalName()
46   {
47     return($this->orig_name);
48   }
51   /*! \brief    Retunrs the filters name.
52    *  @param    The name of the filter
53    */
54   function getCurrentName()
55   {
56     return($this->name);
57   }
60   /*! \brief    Generates the <HTML> content, to edit the filter settings.
61    *  @return   String  HTML form.
62    */
63   function execute()
64   {
65     plugin::execute();
66     $smarty = get_smarty();
67     $smarty->assign('name', $this->name);
68     $smarty->assign('filter', $this->filter);
69     $smarty->assign('share', $this->share);
70     $smarty->assign('enable', $this->enabled);
71     $smarty->assign('description', $this->description);
72     $smarty->assign('selectedCategories', $this->selectedCategories);
73     $smarty->assign('availableCategories', $this->availableCategories);
74     return($smarty->fetch(get_template_path('userFilterEditor.tpl', FALSE)));
75   }
78   /*! \brief    Keep values entered in the input form of the dialog. (POST/GET)
79    */
80   function save_object()
81   {
82     if(isset($_POST['userFilterEditor'])){
84       // Get posted strings
85       foreach(array('name','description','filter') as $attr){
86         if(isset($_POST[$attr])){
87           $this->$attr = get_post($attr);
88         }
89       }
91       // Get posted flags 
92       $this->share = isset($_POST['shareFilter']);
93       $this->enable = isset($_POST['enableFilter']);
95       // Get additional category  
96       if(isset($_POST['addCategory'])){
97         if(isset($_POST['manualCategory']) && !empty($_POST['manualCategory'])){
98           $this->selectedCategories[] = get_post('manualCategory');
99         }elseif(isset($_POST['availableCategory']) && !empty($_POST['availableCategory'])){
100           $this->selectedCategories[] = get_post('availableCategory');
101         }
102       }
104       // Remove categories
105       if(isset($_POST['delCategory']) && isset($_POST['usedCategory'])){
106         foreach($_POST['usedCategory'] as $cat){
107           if(isset($this->selectedCategories[$cat])) unset($this->selectedCategories[$cat]);
108         }
109       }
110     }
111   }
113   
114   /*! \brief    Validate user input 
115    *  @return   Array   An Array containing potential error messages
116    */
117   function check()
118   {
119     $msgs = plugin::check();
120   
121     // Check if the name is given
122     if(empty($this->name)){
123       $msgs[] = msgPool::required(_("Name"));
124     }elseif(preg_match("/[^a-z0-9\-_ ]/i", $this->name)){
125       
126       // Check for a valid name, no special chars here - in particular no ; 
127       $msgs[] = msgPool::invalid(_("Name"), $this->name,"/[a-z0-9\-_ ]/i");
128     }  
130     return($msgs);
131   }
134   /*! \brief    Transforms the entered values into a filter object (array) which is useable
135    *             for the userFilter overview dialog.
136    *  @return   Returns transformed filter data.
137    */
138   function save()
139   {
140     $ret= array();
141     $ret['name'] = $this->name;
142     $ret['description'] = $this->description;
143     $ret['categories'] = $this->selectedCategories;
144     $ret['filter'] = $this->filter;
145     $ret['flags'] = array();
146     if($this->share){
147       $ret['flags'][] = "share";
148     }
149     if($this->enable){
150       $ret['flags'][] = "enable";
151     }
152     return($ret);
153   }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>