Code

Updated snapshot handling
[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' 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" => "&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",  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     }
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/lists/submit.png' align='middle' 
136           title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
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         "&nbsp;"._("Create")."|\n";
145       $s.= "...|<input class='center' type='image' src='images/list_new_blocklist.png' alt=''>".
146         "&nbsp;"._("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       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
154     if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
155       $s.= "..|---|\n";
156       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
157         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
158       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
159         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
160     }
162     /* Copy & paste icons */
163     if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
164       $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
165       $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
166     }else{
167       $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
168       $s.="..|".$img."&nbsp;"._("Paste")."\n";
169     }
171     /* Add snapshot icons */
172     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
174     $this->SetDropDownHeaderMenu($s);
175     $this->SetListHeader($listhead);
176   }
178   function execute()
179   {
180     $this->ClearElementsList();
181     $this->GenHeader();
182   }
184   function setEntries($list)
185   {
186     // User and Template  Images
187     $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
188     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
190     /* Dynamic action col, depending on snapshot icons */
191     $action_col_size = 100;
192     if($this->parent->snapshotEnabled()){
193       $action_col_size += 20;
194     }
196     /* Append to list */
197     $ui = get_userinfo();
198     foreach($list as $key => $val){
200       $acl = $ui->get_permissions($val['dn'],"gofaxlist/blocklist");
201       $acl_all  = $ui->has_complete_category_acls($val['dn'],"gofaxlist");
203       if(!preg_match("/r/",$acl)){
204         continue;
205       }  
207       $action ="";
208       if($ui->is_cutable($val['dn'],"gofaxlist","blocklist") && $this->parent->CopyPasteHandler){
209         $action .= "<input class='center' type='image'
210           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
211       }else{
212         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
213       }
215       if($ui->is_copyable($val['dn'],"gofaxlist","blocklist") && $this->parent->CopyPasteHandler){
216         $action.= "<input class='center' type='image'
217           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
218       }else{
219         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
220       }
222       /* Edit link ; requires read access */
223       $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'     name='goFaxBlocklist_edit_%KEY%' title='"._("Edit user")."'>";
225       /* Add snapshot icon */
226       $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
227  
228       /* Delete entry ; requires remove access */
229       if(preg_match("/d/",$acl)){
230         $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."' name='goFaxBlocklist_del_%KEY%' title='"._("Delete user")."'>";
231       }
232       
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       }
250       
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('/ /', '&nbsp;', @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 = sprintf(_("Number of listed '%s'"),_("blocklists"));
268     $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
270     $str = "<img class='center' src='images/list_blocklist.png'
271               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
272     $str.= "<img class='center' src='images/lists/folder.png'
273               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
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   }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>