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"), _("Ignore 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'];
81 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
82 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
84 /* Add base */
85 $deps[] = array("dn"=>$this->config->current['BASE']);
87 /* Load possible departments */
88 $first = "";
89 $found = FALSE;
90 $ui= get_userinfo();
91 $tdeps= $ui->get_module_departments("gofaxlist");
92 $ids = $this->config->idepartments;
93 foreach($deps as $dep){
94 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
96 /* Keep first base dn in mind, we could need this
97 * info if no valid base was found
98 */
99 if(empty($first)) {
100 $first = $dep['dn'];
101 }
103 $value = $ids[$dep['dn']];
104 if ($this->selectedBase == $dep['dn']){
105 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
106 } else {
107 $options.= "<option value='".$dep['dn']."'>$value</option>";
108 }
109 }
110 }
112 /* The currently used base is not visible with your acl setup.
113 * Set base to first useable base.
114 */
115 if(!$found){
116 $this->selectedBase = $first;
117 }
119 /* Get acls */
120 $ui = get_userinfo();
121 $acl = $ui->get_permissions($this->selectedBase,"gofaxlist/blocklist");
122 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"gofaxlist");
124 /* Add default header */
125 $listhead = MultiSelectWindow::get_default_header();
127 /* Add snaphot icons, if allowed */
128 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
129 $listhead .= $this->get_snapshot_header($this->selectedBase);
130 }
132 /* Add create icon if allowed */
133 if(preg_match("/c/",$acl)){
134 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_blocklist.png' ".
135 " title='"._("Create new blocklist")."' alt='"._("New Blocklist")."' name='goFaxBlocklist_new'> ".
136 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>";
137 }
139 /* Append department selector */
140 $listhead .= " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
141 " <input class='center' type='image' src='images/list_submit.png' align='middle'
142 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
144 /* Multiple options */
145 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
146 title='"._("Remove selected blocklists")."' alt='"._("Remove blocklists")."' name='remove_multiple_blocklists'> ";
148 $listhead .="</div>";
150 $this->SetListHeader($listhead);
151 }
153 function execute()
154 {
155 $this->ClearElementsList();
156 $this->GenHeader();
157 }
159 function setEntries($list)
160 {
161 // User and Template Images
162 $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
163 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
165 /* Dynamic action col, depending on snapshot icons */
166 $action_col_size = 60;
167 if($this->parent->snapshotEnabled()){
168 $action_col_size += 20;
169 }
171 /* Append to list */
172 $ui = get_userinfo();
173 foreach($list as $key => $val){
175 $acl = $ui->get_permissions($val['dn'],"gofaxlist/blocklist");
176 if(!preg_match("/r/",$acl)){
177 continue;
178 }
180 /* Edit link ; requires read access */
181 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='goFaxBlocklist_edit_%KEY%' title='"._("Edit user")."'>";
184 /* Create snapshot ; requires write access && create access */
185 if(preg_match("/w/",$acl) && preg_match("/c/",$acl)){
186 $action.= $this->GetSnapShotActions($val['dn']);
187 }
189 /* Delete entry ; requires remove access */
190 if(preg_match("/d/",$acl)){
191 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='goFaxBlocklist_del_%KEY%' title='"._("Delete user")."'>";
192 }
194 // Generate Array to Add
195 if(isset($val["description"][0])){
196 $display= $val["cn"][0]." [".$val["description"][0]."]";
197 }else{
198 $display= $val["cn"][0];
199 }
202 /* Create each field */
203 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
204 "attach" => "style='width:20px;'");
205 $field1 = array("string" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
206 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
207 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
208 $this->AddElement( array($field0,$field1,$field2,$field3));
209 }
210 }
212 function Save()
213 {
214 MultiSelectWindow :: Save();
215 }
217 function save_object()
218 {
219 /* Save automatic created POSTs like regex, checkboxes */
220 MultiSelectWindow :: save_object();
221 }
222 }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>