3c3a44073f6065accf932a69c003d1e9919e37ae
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 = 70;
49 if($this->parent->snapshotEnabled()){
50 $action_col_size += 38;
51 }
53 /* set Page header */
54 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
55 $this->AddHeader(array("string" => _("Mime type name")." / "._("Department"), "attach" => "style=''"));
56 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
58 /* Add SubSearch checkbox */
59 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
61 /* Name ,Text ,Default , Connect with alphabet */
62 $this->AddRegex ("Regex", _("Display mime types matching"),"*" , true);
63 }
66 /* This function allows us to add a user defined filter part at position $position*/
67 function AddUserBoxToFilter($position)
68 {
69 $str = "";
70 if(($position == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
71 $smarty = get_smarty();
72 $smarty->assign("selectedRelease",$this->selectedRelease);
73 $smarty->assign("branchimage","images/branch.png");
74 $smarty->assign("releases",$this->AvailableReleases);
75 $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
76 }
77 return($str);
78 }
81 /* Create list header, with create / copy & paste etc*/
82 function GenHeader()
83 {
84 /* Prepare departments,
85 which are shown in the listbox on top of the listbox
86 */
87 $options= "";
89 /* Get all departments within this subtree */
90 $base = $this->config->current['BASE'];
91 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
92 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
94 /* Load possible departments */
95 $ui = get_userinfo();
96 $tdeps= $ui->get_module_departments($this->module);
98 $ids = $this->config->idepartments;
100 foreach($deps as $dep){
101 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
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 $ui = get_userinfo();
113 $acl = $ui->get_permissions("cn=dummy,ou=mimetypes,".$this->selectedBase,"mimetypes/mimetype");
114 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
116 /* Get copy & paste icon */
117 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
118 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
119 }else{
120 $Copy_Paste ="";
121 }
123 /* Create listhead, it will be shown on top of the divlist.
124 * It provides general navigation and object creation
125 */
127 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
128 " <input class='center' type='image' src='images/list_root.png' align='middle' ".
129 "title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
130 " <input class='center' type='image' align='middle' src='images/list_back.png' ".
131 "title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
132 " <input class='center' type='image' align='middle' src='images/list_home.png' ".
133 "title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
134 " <input class='center' type='image' src='images/list_reload.png' align='middle' ".
135 "title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
136 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
138 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
139 $listhead .= $this->get_snapshot_header($this->selectedBase);
140 }
142 if(preg_match("/c/",$acl)){
143 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_mime.png' alt='"._("new").
144 "' title='"._("Create new mime type")."' name='mime_new'> ";
145 }
147 $listhead .=
148 $Copy_Paste.
149 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
150 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
151 " <input class='center' type='image' src='images/list_submit.png' align='middle'
152 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
153 "</div>";
155 $this->SetListHeader($listhead);
156 }
159 /* Some basic settings */
160 function execute()
161 {
162 $this->ClearElementsList();
163 $this->GenHeader();
164 }
167 function setEntries($list)
168 {
169 /********************
170 Variable init
171 ********************/
173 /* Create links */
174 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
175 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
176 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
177 $mimeimg = "<img class='center' src='images/select_mimetype.png' alt='A' title='"._("Mime type")."'>";
178 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
180 /* set Page header */
181 $action_col_size = 70;
182 if($this->parent->snapshotEnabled()){
183 $action_col_size += 38;
184 }
186 /********************
187 Attach objects
188 ********************/
190 foreach($list as $key => $val){
192 $ui = get_userinfo();
193 $acl = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
194 $acl_all = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
196 /* Create action icons */
197 $actions = "";
198 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
199 $actions .= $this->GetSnapShotActions($val['dn']);
200 }
202 /* Get copy Paste icons */
203 if($this->parent->CopyPasteHandler){
205 /* Only add cut icon, if we are allowed to move this user */
206 if(preg_match("/m/",$acl)){
207 $actions.= "<input class='center' type='image'
208 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
209 }else{
210 $actions.= "<img src='images/empty.png' alt=' '>";
211 }
213 /* Copy is allowed everytime */
214 $actions.= "<input class='center' type='image'
215 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
216 }
218 /* Add edit button */
219 $actions.= "<input class='center' type='image'
220 src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
222 /* Add delete button */
223 if(preg_match("/d/",$acl)){
224 $actions.= "<input class='center' type='image'
225 src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
226 }else{
227 $actions.= "<img src='images/empty.png' alt=' '>";
228 }
230 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
232 if(!isset($val['description'][0])){
233 $desc = "";
234 }else{
235 $desc = " - [ ".$val['description'][0]." ]";
236 }
237 $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
238 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
239 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
240 $this->AddElement(array($field1,$field2,$field3));
241 }
242 }
244 function Save()
245 {
246 MultiSelectWindow::Save();
247 }
249 function save_object()
250 {
251 /* Save automatic created POSTs like regex, checkboxes */
252 MultiSelectWindow::save_object();
254 /* check if returned selectedRelease is a valid release.
255 If it isn't set to a valid release */
256 $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
257 if(!isset($this->AvailableReleases[$this->selectedRelease])){
258 $this->selectedRelease =key($this->AvailableReleases);
259 }
260 $_SESSION['mimefilter']['release'] = $this->selectedRelease;
261 }
263 }
264 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
265 ?>