Code

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