1 <?php
3 class divListMimeTypes extends MultiSelectWindow
4 {
5 /* Current base */
6 var $selectedBase = "";
7 var $selectedRelease = "main";
8 var $AvailableReleases = array();
9 var $departments = array();
10 var $parent ;
11 var $ui ;
13 /* Regex */
14 var $Regex = "*";
16 /* Subsearch checkbox */
17 var $SubSearch;
19 /* These vars should be saved too */
20 var $SaveAdditionalVars = array("selectedRelease");
23 function divListMimeTypes ($config,$parent)
24 {
25 /* Create divlist and setup */
26 MultiSelectWindow::MultiSelectWindow($config, "Mimetypes", "mimetypes");
28 /* initialize required attributes */
29 $this->selectedRelease = "ou=mime,".$_SESSION['CurrentMainBase'];
30 $this->parent = $parent;
31 $this->ui = get_userinfo();
32 $this->AvailableReleases= $this->parent->getReleases($this->selectedBase);
34 /* Set list strings */
35 $this->SetTitle (_("List of defined mime types"));
36 $this->SetSummary (_("List of defined mime types"));
37 $this->SetInformation (_("This menu allows you to add, edit and remove selected mime types. You may want to use the range selector on top of the mime type listbox, when working with a large number of mime types."));
39 /* Result page will look like a headpage */
40 $this->SetHeadpageMode();
41 $this->EnableAplhabet(true);
43 /* Disable buttonsm */
44 $this->EnableCloseButton(false);
45 $this->EnableSaveButton (false);
47 /* set Page header */
48 $action_col_size = 80;
49 if($this->parent->snapshotEnabled()){
50 $action_col_size += 38;
51 }
55 /* Toggle all selected / deselected */
56 $chk = "<input type='checkbox' id='select_all' name='select_all'
57 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
59 /* set Page header */
60 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
61 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
62 $this->AddHeader(array("string" => _("Mime type name")." / "._("Department"), "attach" => "style=''"));
63 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
65 /* Add SubSearch checkbox */
66 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
68 /* Name ,Text ,Default , Connect with alphabet */
69 $this->AddRegex ("Regex", _("Display mime types matching"),"*" , true);
70 }
73 /* This function allows us to add a user defined filter part at position $position*/
74 function AddUserBoxToFilter($position)
75 {
76 $str = "";
77 if(($position == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
78 $smarty = get_smarty();
79 $smarty->assign("selectedRelease",$this->selectedRelease);
80 $smarty->assign("branchimage","images/branch.png");
81 $smarty->assign("releases",$this->AvailableReleases);
82 $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
83 }
84 return($str);
85 }
88 /* Create list header, with create / copy & paste etc*/
89 function GenHeader()
90 {
91 /* Prepare departments,
92 which are shown in the listbox on top of the listbox
93 */
94 $options= "";
96 /* Get all departments within this subtree */
97 $base = $this->config->current['BASE'];
98 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
99 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
101 /* Load possible departments */
102 $ui = get_userinfo();
103 $tdeps= $ui->get_module_departments($this->module);
105 $ids = $this->config->idepartments;
107 foreach($deps as $dep){
108 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
110 $value = $ids[$dep['dn']];
111 if ($this->selectedBase == $dep['dn']){
112 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
113 } else {
114 $options.= "<option value='".$dep['dn']."'>$value</option>";
115 }
116 }
117 }
119 /* Get acls */
120 $ui = get_userinfo();
121 $acl = $ui->get_permissions("cn=dummy,ou=mimetypes,".$this->selectedBase,"mimetypes/mimetype");
122 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
125 /* If this is true we add an additional seperator. Just look a few lines below */
126 $add_sep = false;
128 /* Get copy & paste icon */
129 $Copy_Paste ="";
130 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
131 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
132 $add_sep = true;
133 }
135 /* Add default header */
136 $listhead = MultiSelectWindow::get_default_header();
138 /* Create snapshot icons */
139 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
140 $listhead .= $this->get_snapshot_header($this->selectedBase);
141 $add_sep = true;
142 }
144 /* Add create icon */
145 if(preg_match("/c/",$acl)){
146 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_mime.png' alt='"._("new").
147 "' title='"._("Create new mime type")."' name='mime_new'> ";
148 $add_sep = true;
149 }
151 /* Add copy & paste icons */
152 $listhead .= $Copy_Paste;
154 /* Add a seperator ? */
155 if($add_sep) {
156 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
157 }
159 /* And at least add a department selection box */
160 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
161 " <input class='center' type='image' src='images/list_submit.png' align='middle'
162 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
164 /* Multiple options */
165 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
166 title='"._("Remove selected mimetype")."' alt='"._("Remove mimetype")."' name='remove_multiple_mimetypes'> ";
168 $listhead .="</div>";;
170 $this->SetListHeader($listhead);
171 }
174 /* Some basic settings */
175 function execute()
176 {
177 $this->ClearElementsList();
178 $this->GenHeader();
179 }
182 function setEntries($list)
183 {
184 /********************
185 Variable init
186 ********************/
188 /* Create links */
189 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
190 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
191 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
192 $mimeimg = "<img class='center' src='images/select_mimetype.png' alt='A' title='"._("Mime type")."'>";
193 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
195 /* set Page header */
196 $action_col_size = 80;
197 if($this->parent->snapshotEnabled()){
198 $action_col_size += 38;
199 }
201 /********************
202 Attach objects
203 ********************/
205 foreach($list as $key => $val){
207 $ui = get_userinfo();
208 $acl = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
209 $acl_all = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
211 /* Create action icons */
212 $actions = "";
213 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
214 $actions .= $this->GetSnapShotActions($val['dn']);
215 }
217 /* Get copy Paste icons */
218 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
219 $actions.= "<input class='center' type='image'
220 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
221 $actions.= "<input class='center' type='image'
222 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
223 }
225 $actions.= "<input class='center' type='image'
226 src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
228 /* Add delete button */
229 if(preg_match("/d/",$acl)){
230 $actions.= "<input class='center' type='image'
231 src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
232 }else{
233 $actions.= "<img src='images/empty.png' alt=' ' class='center'>";
234 }
236 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
238 if(!isset($val['description'][0])){
239 $desc = "";
240 }else{
241 $desc = " - [ ".$val['description'][0]." ]";
242 }
244 /* Create each field */
245 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
246 "attach" => "style='width:20px;'");
247 $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
248 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
249 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
250 $this->AddElement(array($field0,$field1,$field2,$field3));
251 }
252 }
254 function Save()
255 {
256 MultiSelectWindow::Save();
257 }
259 function save_object()
260 {
261 /* Save automatic created POSTs like regex, checkboxes */
262 MultiSelectWindow::save_object();
264 /* check if returned selectedRelease is a valid release.
265 If it isn't set to a valid release */
266 $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
267 if(!isset($this->AvailableReleases[$this->selectedRelease])){
268 $this->selectedRelease =key($this->AvailableReleases);
269 }
270 $_SESSION['mimefilter']['release'] = $this->selectedRelease;
271 }
273 }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>