2e78c656bbf1171be9b80be4aa88f2ae4082702d
1 <?php
3 class divListBlocklist extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
13 /* checkboxes */
14 var $ShowSendBocklists ;
15 var $ShowReceiveBlocklists ;
17 /* Subsearch checkbox */
18 var $SubSearch;
20 var $parent ;
21 var $ui ;
23 function divListBlocklist ($config,$parent)
24 {
25 MultiSelectWindow::MultiSelectWindow($config, "Blocklists", "gofaxlist");
27 $this->parent = $parent;
28 $this->ui = get_userinfo();
30 /* Set list strings */
31 $this->SetTitle(_("List of blocklists"));
32 $this->SetSummary(_("List of blocklists"));
34 /* Result page will look like a headpage */
35 $this->SetHeadpageMode();
36 $this->SetInformation(_("This menu allows you to create, delete and edit selected blocklists. Having a large size of lists, you might prefer the range selectors on top of the select box."));
38 $this->EnableAplhabet (true);
40 /* Disable buttonsm */
41 $this->EnableCloseButton(false);
42 $this->EnableSaveButton (false);
44 /* Dynamic action col, depending on snapshot icons */
45 $action_col_size = 60;
46 if($this->parent->snapshotEnabled()){
47 $action_col_size += 20;
48 }
50 /* Toggle all selected / deselected */
51 $chk = "<input type='checkbox' id='select_all' name='select_all'
52 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
54 /* set Page header */
55 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
56 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
57 $this->AddHeader(array("string" => _("Blocklist name")." / "._("Department"), "attach" => "style=''"));
58 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
60 /* Add Checkboxes / SubSearch checkbox */
61 $this->AddCheckBox("ShowSendBocklists" , _("Select to see send blocklists"), _("Show send blocklists"),true);
62 $this->AddCheckBox("ShowReceiveBlocklists" , _("Select to see receive blocklists"), _("Show receive blocklists"),true);
64 $this->AddCheckBox(SEPERATOR);
65 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
67 /* Name ,Text ,Default , Connect with alphabet */
68 $this->AddRegex ("Regex", _("Regular expression for matching list names"),"*" , true);
69 }
72 function GenHeader()
73 {
74 /* Prepare departments,
75 which are shown in the listbox on top of the listbox
76 */
77 $options= "";
79 /* Get all departments within this subtree */
80 $base = $this->config->current['BASE'];
82 /* Add base */
83 $tmp = array();
84 $tmp[] = array("dn"=>$this->config->current['BASE']);
85 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
86 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
88 $deps = array();
89 foreach($tmp as $tm){
90 $deps[$tm['dn']] = $tm['dn'];
91 }
93 /* Load possible departments */
94 $ui= get_userinfo();
95 $tdeps= $ui->get_module_departments("gofaxlist");
96 $ids = $this->config->idepartments;
97 $first = "";
98 $found = FALSE;
99 foreach($ids as $dep => $name){
100 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
102 /* Keep first base dn in mind, we could need this
103 * info if no valid base was found
104 */
105 if(empty($first)) {
106 $first = $dep['dn'];
107 }
109 $value = $ids[$dep];
110 if ($this->selectedBase == $dep){
111 $found = TRUE;
112 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
113 } else {
114 $options.= "<option value='".$dep."'>$value</option>";
115 }
116 }
117 }
119 /* The currently used base is not visible with your acl setup.
120 * Set base to first useable base.
121 */
122 if(!$found){
123 $this->selectedBase = $first;
124 }
126 /* Get acls */
127 $ui = get_userinfo();
128 $acl = $ui->get_permissions($this->selectedBase,"gofaxlist/blocklist");
129 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"gofaxlist");
131 /* Add default header */
132 $listhead = MultiSelectWindow::get_default_header();
134 /* Add snaphot icons, if allowed */
135 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
136 $listhead .= $this->get_snapshot_header($this->selectedBase);
137 }
139 /* Add create icon if allowed */
140 if(preg_match("/c/",$acl)){
141 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_blocklist.png' ".
142 " title='"._("Create new blocklist")."' alt='"._("New Blocklist")."' name='goFaxBlocklist_new'> ".
143 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>";
144 }
146 /* Append department selector */
147 $listhead .= " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
148 " <input class='center' type='image' src='images/list_submit.png' align='middle'
149 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
151 /* Multiple options */
152 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
153 title='"._("Remove selected blocklists")."' alt='"._("Remove blocklists")."' name='remove_multiple_blocklists'> ";
155 $listhead .="</div>";
157 $this->SetListHeader($listhead);
158 }
160 function execute()
161 {
162 $this->ClearElementsList();
163 $this->GenHeader();
164 }
166 function setEntries($list)
167 {
168 // User and Template Images
169 $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
170 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
172 /* Dynamic action col, depending on snapshot icons */
173 $action_col_size = 60;
174 if($this->parent->snapshotEnabled()){
175 $action_col_size += 20;
176 }
178 /* Append to list */
179 $ui = get_userinfo();
180 foreach($list as $key => $val){
182 $acl = $ui->get_permissions($val['dn'],"gofaxlist/blocklist");
183 if(!preg_match("/r/",$acl)){
184 continue;
185 }
187 /* Edit link ; requires read access */
188 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='goFaxBlocklist_edit_%KEY%' title='"._("Edit user")."'>";
191 /* Create snapshot ; requires write access && create access */
192 if(preg_match("/w/",$acl) && preg_match("/c/",$acl)){
193 $action.= $this->GetSnapShotActions($val['dn']);
194 }
196 /* Delete entry ; requires remove access */
197 if(preg_match("/d/",$acl)){
198 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='goFaxBlocklist_del_%KEY%' title='"._("Delete user")."'>";
199 }
201 // Generate Array to Add
202 if(isset($val["description"][0])){
203 $display= $val["cn"][0]." [".$val["description"][0]."]";
204 }else{
205 $display= $val["cn"][0];
206 }
208 /* Cutted objects should be displayed in light grey */
209 if($this->parent->CopyPasteHandler){
210 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
211 if($queue_data['dn'] == $acl_entry['dn']) {
212 $display = "<font color='#999999'>".$display."</font>";
213 break;
214 }
215 }
216 }
219 /* Create each field */
220 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
221 "attach" => "style='width:20px;'");
222 $field1 = array("string" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
223 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
224 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
225 $this->AddElement( array($field0,$field1,$field2,$field3));
226 }
228 /* Create summary string for list footer */
229 $num_deps=0;
230 if(!$this->SubSearch){
231 $num_deps = count($this->Added_Departments);
232 }
233 $num_objs = count($list);
235 $num_obj_str = _("Number of listed blocklists");
236 $num_dep_str = _("Number of listed departments");
238 $str = "<img class='center' src='images/list_blocklist.png'
239 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
240 $str.= "<img class='center' src='images/folder.png'
241 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
243 $this->set_List_Bottom_Info($str);
245 }
247 function Save()
248 {
249 MultiSelectWindow :: Save();
250 }
252 function save_object()
253 {
254 /* Save automatic created POSTs like regex, checkboxes */
255 MultiSelectWindow :: save_object();
256 }
257 }
258 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
259 ?>