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 = 100;
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 /* Append department selector */
135 $listhead .= " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
136 " <input class='center' type='image' src='images/list_submit.png' align='middle'
137 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
139 /* Create Layers menu */
140 $s = ".|"._("Actions")."|\n";
141 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
142 " "._("Create")."|\n";
144 /* Append create options */
145 if(preg_match("/c/",$acl)) {
146 $s.= "...|<input class='center' type='image' src='images/list_new_blocklist.png' alt=''>".
147 " "._("Blocklist")."|goFaxBlocklist_new|\n";
148 }
150 /* Multiple options */
151 $s.= "..|---|\n";
152 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
153 " "._("Remove")."|"."remove_multiple|\n";
155 /* Add multiple copy & cut icons */
156 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
157 $s.= "..|---|\n";
158 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
159 " "._("Copy")."|"."multiple_copy_systems|\n";
160 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
161 " "._("Cut")."|"."multiple_cut_systems|\n";
163 if($this->parent->CopyPasteHandler->entries_queued()){
164 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
165 $s.="..|".$img." "._("Paste")."|editPaste|\n";
166 }else{
167 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
168 $s.="..|".$img." "._("Paste")."\n";
169 }
170 }
172 /* Add snapshot icons */
173 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
174 $s .= "..|---|\n";
175 $s .= $this->get_snapshot_header(TRUE);
176 }
178 $this->SetDropDownHeaderMenu($s);
180 $this->SetListHeader($listhead);
181 }
183 function execute()
184 {
185 $this->ClearElementsList();
186 $this->GenHeader();
187 }
189 function setEntries($list)
190 {
191 // User and Template Images
192 $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
193 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
195 /* Dynamic action col, depending on snapshot icons */
196 $action_col_size = 100;
197 if($this->parent->snapshotEnabled()){
198 $action_col_size += 20;
199 }
201 /* Append to list */
202 $ui = get_userinfo();
203 foreach($list as $key => $val){
205 $acl = $ui->get_permissions($val['dn'],"gofaxlist/blocklist");
206 if(!preg_match("/r/",$acl)){
207 continue;
208 }
210 /* Edit link ; requires read access */
211 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='goFaxBlocklist_edit_%KEY%' title='"._("Edit user")."'>";
214 /* Create snapshot ; requires write access && create access */
215 if(preg_match("/w/",$acl) && preg_match("/c/",$acl)){
216 $action.= $this->GetSnapShotActions($val['dn']);
217 }
219 /* Add copy & cut icons */
220 if(preg_match("/(c.*w|w.*c)/",$acl) && $this->parent->CopyPasteHandler){
221 $action .= "<input class='center' type='image'
222 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
223 $action.= "<input class='center' type='image'
224 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
225 }
228 /* Delete entry ; requires remove access */
229 if(preg_match("/d/",$acl)){
230 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='goFaxBlocklist_del_%KEY%' title='"._("Delete user")."'>";
231 }
233 // Generate Array to Add
234 if(isset($val["description"][0])){
235 $display= $val["cn"][0]." [".$val["description"][0]."]";
236 }else{
237 $display= $val["cn"][0];
238 }
240 /* Cutted objects should be displayed in light grey */
241 if(isset($this->parent->CopyPasteHandler->queue) && is_array($this->parent->CopyPasteHandler->queue)){
242 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
243 if($queue_data['dn'] == $val['dn']) {
244 $display = "<font color='#999999'>".$display."</font>";
245 break;
246 }
247 }
248 }
251 /* Create each field */
252 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
253 "attach" => "style='width:20px;'");
254 $field1 = array("string" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
255 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
256 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
257 $this->AddElement( array($field0,$field1,$field2,$field3));
258 }
260 /* Create summary string for list footer */
261 $num_deps=0;
262 if(!$this->SubSearch){
263 $num_deps = count($this->Added_Departments);
264 }
265 $num_objs = count($list);
267 $num_obj_str = _("Number of listed blocklists");
268 $num_dep_str = _("Number of listed departments");
270 $str = "<img class='center' src='images/list_blocklist.png'
271 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
272 $str.= "<img class='center' src='images/folder.png'
273 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
275 $this->set_List_Bottom_Info($str);
277 }
279 function Save()
280 {
281 MultiSelectWindow :: Save();
282 }
284 function save_object()
285 {
286 /* Save automatic created POSTs like regex, checkboxes */
287 MultiSelectWindow :: save_object();
288 }
289 }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>