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();
37 $this->EnableAplhabet (true);
39 /* Disable buttonsm */
40 $this->EnableCloseButton(false);
41 $this->EnableSaveButton (false);
43 /* Dynamic action col, depending on snapshot icons */
44 $action_col_size = 100;
45 if($this->parent->snapshotEnabled()){
46 $action_col_size += 20;
47 }
49 /* Toggle all selected / deselected */
50 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
51 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
53 /* set Page header */
54 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
55 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
56 $this->AddHeader(array("string" => _("Name")." / "._("Department"), "attach" => "style=''"));
57 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
59 /* Add Checkboxes / SubSearch checkbox */
60 $this->AddCheckBox("ShowSendBocklists" , msgPool::selectToView(_("Send blocklist")), _("Show send blocklists"),true);
61 $this->AddCheckBox("ShowReceiveBlocklists" , msgPool::selectToView(_("Receive blocklist")), _("Show receive blocklists"),true);
63 $this->AddCheckBox(SEPERATOR);
64 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
66 /* Name,Text,Default,Connect with alphabet */
67 $this->AddRegex ("Regex", _("Regular expression for matching list names"),"*" , true);
68 }
71 function GenHeader()
72 {
73 /* Prepare departments,
74 which are shown in the listbox on top of the listbox
75 */
76 $options= "";
78 /* Get all departments within this subtree */
79 $base = $this->config->current['BASE'];
81 /* Add base */
82 $tmp = array();
83 $tmp[] = array("dn"=>$this->config->current['BASE']);
84 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
85 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
87 $deps = array();
88 foreach($tmp as $tm){
89 $deps[$tm['dn']] = $tm['dn'];
90 }
92 /* Load possible departments */
93 $ui= get_userinfo();
94 $tdeps= $ui->get_module_departments("gofaxlist");
95 $ids = $this->config->idepartments;
96 $first = "";
97 $found = FALSE;
98 foreach($ids as $dep => $name){
99 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
101 /* Keep first base dn in mind, we could need this
102 * info if no valid base was found
103 */
104 if(empty($first)) {
105 $first = $dep['dn'];
106 }
108 $value = $ids[$dep];
109 if ($this->selectedBase == $dep){
110 $found = TRUE;
111 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
112 } else {
113 $options.= "<option value='".$dep."'>$value</option>";
114 }
115 }
116 }
118 /* The currently used base is not visible with your acl setup.
119 * Set base to first useable base.
120 */
121 if(!$found){
122 $this->selectedBase = $first;
123 }
125 /* Get acls */
126 $ui = get_userinfo();
127 $acl = $ui->get_permissions($this->selectedBase,"gofaxlist/blocklist");
128 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"gofaxlist");
130 /* Add default header */
131 $listhead = MultiSelectWindow::get_default_header();
133 /* Append department selector */
134 $listhead .= " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
135 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
136 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
138 /* Create Layers menu */
139 $s = ".|"._("Actions")."|\n";
141 /* Append create options */
142 if(preg_match("/c/",$acl)) {
143 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
144 " "._("Create")."|\n";
145 $s.= "...|<input class='center' type='image' src='images/list_new_blocklist.png' alt=''>".
146 " "._("Blocklist")."|goFaxBlocklist_new|\n";
147 $s.= "..|---|\n";
148 }
150 /* Multiple options */
151 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
152 " "._("Remove")."|"."remove_multiple|\n";
154 /* Add Copy & Paste header */
155 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
157 /* Add snapshot icons */
158 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
160 $this->SetDropDownHeaderMenu($s);
161 $this->SetListHeader($listhead);
162 }
164 function execute()
165 {
166 $this->ClearElementsList();
167 $this->GenHeader();
168 }
170 function setEntries($list)
171 {
172 // User and Template Images
173 $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
174 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
176 /* Dynamic action col, depending on snapshot icons */
177 $action_col_size = 100;
178 if($this->parent->snapshotEnabled()){
179 $action_col_size += 20;
180 }
182 /* Append to list */
183 $ui = get_userinfo();
184 foreach($list as $key => $val){
186 $acl = $ui->get_permissions($val['dn'],"gofaxlist/blocklist");
187 $acl_all = $ui->has_complete_category_acls($val['dn'],"gofaxlist");
189 if(!preg_match("/r/",$acl)){
190 continue;
191 }
193 $action ="";
195 /* Add copy & cut functionality */
196 $action.= $this->parent->get_copypaste_action($val['dn'],"gofaxlist","blocklist");
198 /* Edit link ; requires read access */
199 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."' name='goFaxBlocklist_edit_%KEY%' title='"._("Edit user")."'>";
201 /* Add snapshot icon */
202 $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
204 /* Delete entry ; requires remove access */
205 if(preg_match("/d/",$acl)){
206 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."' name='goFaxBlocklist_del_%KEY%' title='"._("Delete user")."'>";
207 }
209 // Generate Array to Add
210 if(isset($val["description"][0])){
211 $display= $val["cn"][0]." [".$val["description"][0]."]";
212 }else{
213 $display= $val["cn"][0];
214 }
216 /* Cutted objects should be displayed in light grey */
217 if(isset($this->parent->CopyPasteHandler->queue) && is_array($this->parent->CopyPasteHandler->queue)){
218 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
219 if($queue_data['dn'] == $val['dn']) {
220 $display = "<font color='#999999'>".$display."</font>";
221 break;
222 }
223 }
224 }
227 /* Create each field */
228 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
229 "attach" => "style='width:20px;'");
230 $field1 = array("string" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
231 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
232 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
233 $this->AddElement( array($field0,$field1,$field2,$field3));
234 }
236 /* Create summary string for list footer */
237 $num_deps=0;
238 if(!$this->SubSearch){
239 $num_deps = count($this->Added_Departments);
240 }
241 $num_objs = count($list);
243 $num_obj_str = sprintf(_("Number of listed '%s'"),_("blocklists"));
244 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
246 $str = "<img class='center' src='images/list_blocklist.png'
247 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
248 $str.= "<img class='center' src='images/lists/folder.png'
249 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
251 $this->set_List_Bottom_Info($str);
253 }
255 function Save()
256 {
257 MultiSelectWindow :: Save();
258 }
260 function save_object()
261 {
262 /* Save automatic created POSTs like regex, checkboxes */
263 MultiSelectWindow :: save_object();
264 }
265 }
266 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
267 ?>