Code

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