Code

Added create move acls
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_divListMimeTypes.inc
1 <?php
3 class divListMimeTypes extends MultiSelectWindow
4 {
5   /* Current base */
6   var $selectedBase       = "";
7   var $departments        = array();
8   var $parent               ;
9   var $ui                   ;
11   /* Regex */
12   var $Regex              = "*";
14   /* Subsearch checkbox */
15   var $SubSearch;
17   function divListMimeTypes (&$config, &$parent)
18   {
19     /* Create divlist and setup */
20     MultiSelectWindow::MultiSelectWindow($config, "Mimetypes", "mimetypes");
21   
22     /* initialize required attributes */ 
23     $this->parent           = &$parent;
24     $this->ui               = get_userinfo();
26     /* Set list strings */
27     $this->SetTitle       (_("List of defined mime types"));
28     $this->SetSummary     (_("List of defined mime types"));
30     /* Result page will look like a headpage */
31     $this->SetHeadpageMode();
32     $this->EnableAplhabet(true);
33   
34     /* Disable buttonsm */
35     $this->EnableCloseButton(false);
36     $this->EnableSaveButton (false);
38     /* set Page header */
39     $action_col_size = 80;
40     if($this->parent->snapshotEnabled()){
41       $action_col_size += 38;
42     }
44     /* Toggle all selected / deselected */
45     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
46                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
48     /* set Page header */
49     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
50     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
51     $this->AddHeader(array("string" => _("Mime type")." / "._("Department"), "attach" => "style=''"));
52     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
54     /* Add SubSearch checkbox */
55     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
57     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
58     $this->AddRegex   ("Regex",     _("Display mime types matching"),"*" , true);
59   }
62   function AddUserBoxToFilter($position)
63   {
64     $str = "";
65     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
66       $smarty = get_smarty();
67       $releases = $this->parent->getReleases();
68       $smarty->assign("mime_release" , $releases[$this->parent->mime_release]);
69       $smarty->assign("mime_base"    , $releases[$this->parent->mime_base]);
70       $smarty->assign("branchimage","images/branch.png");
71       $smarty->assign("mime_releases", $releases);
72       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
73     }
74     return($str);
75   }
78   /* Create list header, with create / copy & paste etc*/
79   function GenHeader()
80   {
83     /* Add default header */
84     $listhead = MultiSelectWindow::get_default_header(false);
85     if(!$this->parent->IsReleaseManagementActivated()){
87       /* Prepare departments,
88          which are shown in the listbox on top of the listbox
89        */
90       $options= "";
92       /* Get all departments within this subtree */
93       $ui= get_userinfo();
94       $first = "";
95       $found = FALSE;
96       $base = $this->config->current['BASE'];
98       /* Add base */
99       $tmp = array();
100       $tmp[] = array("dn"=>$this->config->current['BASE']);
101       $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
102             array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
104       $deps = array();
105       foreach($tmp as $tm){
106         $deps[$tm['dn']] = $tm['dn'];
107       }
109       /* Load possible departments */
110       $ui= get_userinfo();
111       $tdeps= $ui->get_module_departments($this->module);
112       $ids = $this->config->idepartments;
113       $first = "";
114       $found = FALSE;
115       foreach($ids as $dep => $name){
116         if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
118           /* Keep first base dn in mind, we could need this
119            *  info if no valid base was found
120            */
121           if(empty($first)) {
122             $first = $dep['dn'];
123           }
125           $value = $ids[$dep];
126           if ($this->selectedBase == $dep){
127             $found = TRUE;
128             $options.= "<option selected='selected' value='".$dep."'>$value</option>";
129           } else {
130             $options.= "<option value='".$dep."'>$value</option>";
131           }
132         }
133       }
135       /* The currently used base is not visible with your acl setup.
136        * Set base to first useable base.
137        */
138       if(!$found){
139         $this->selectedBase = $first;
140       }
142       /* And at least add a department selection box */
143       $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
144         " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
145         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
147     }
149     /* Get acls */
150     $ui       = get_userinfo();
151     $acl      = $ui->get_permissions($this->parent->mime_base,"mimetypes/mimetype");
152     $acl_all  = $ui->has_complete_category_acls($this->parent->mime_base,"mimetypes") ;
155     /* If this is true we add an additional seperator. Just look a few lines below */  
156     $add_sep = false;
157  
158     /* Create Layers menu */
159     $s  = ".|"._("Actions")."|\n";
161     /* Append create options */
162     if(preg_match("/c/",$acl)) {
163       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
164         "&nbsp;"._("Create")."|\n";
165       $s.= "...|<input class='center' type='image' src='images/list_new_mime.png' alt=''>".
166         "&nbsp;"._("Mime type")."|mime_new|\n";
167       $s.= "..|---|\n";
168     }
170     /* Multiple options */
171     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
172       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
174     if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
175       $s.= "..|---|\n";
176       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
177         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
178       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
179         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
180     }
182     /* Copy & paste icons */
183     if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
184       $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
185       $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
186     }else{
187       $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
188       $s.="..|".$img."&nbsp;"._("Paste")."\n";
189     }
191     /* Add snapshot icons */
192     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
193       $s .= "..|---|\n";
194       $s .= $this->get_snapshot_header(TRUE);
195     }
197     $this->SetDropDownHeaderMenu($s);
198     $this->SetListHeader($listhead);
199   }
202   /* Some basic settings */
203   function execute()
204   {
205     $this->ClearElementsList();
206     $this->GenHeader();
207   }
210   function setEntries($list)
211   {
212     /********************
213       Variable init
214      ********************/
216     /* Create links */
217     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
218     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
219     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
220     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
221     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
223     /* set Page header */
224     $action_col_size = 80;
225     if($this->parent->snapshotEnabled()){
226       $action_col_size += 38;
227     }
229     /********************
230       Attach objects
231      ********************/
233     foreach($list as $key => $val){
235       $ui       = get_userinfo();
236       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
237       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
239       $action = "";
240       if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
241         $action.= "<input class='center' type='image'
242           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
243       }else{
244         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
245       }
247       if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
248         $action.= "<input class='center' type='image'
249           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
250       }else{
251         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
252       }
254       $action.= "<input class='center' type='image'
255         src='images/lists/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
257       /* Add snapshot icon */
258       if(preg_match("/(r.*w|w.*r)/",$acl_all)){
259         $action.= $this->GetSnapShotActions($val['dn']);
260       }else{
261         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
262         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
263       }
265       /* Add delete button */
266       if(preg_match("/d/",$acl)){
267         $action.= "<input class='center' type='image'
268           src='images/lists/trash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
269       }else{
270         $action.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
271       }
273       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
275       if(!isset($val['description'][0])){
276         $desc = "";
277       }else{
278         $desc = " - [ ".$val['description'][0]." ]";
279       }
281       /* Cutted objects should be displayed in light grey */
282       $display = $val['cn'][0].$desc;
283       if($this->parent->CopyPasteHandler){
284         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
285           if($queue_data['dn'] == $val['dn']) {
286             $display = "<font color='#999999'>".$display."</font>";
287             break;
288           }
289         }
290       }
293       /* Create each field */
294       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
295                       "attach" => "style='width:20px;'");
296       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
297       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
298       $field3 = array("string" => preg_replace("/%KEY%/", $key, $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
299       $this->AddElement(array($field0,$field1,$field2,$field3));
300     }
303     /* Create summary string for list footer */
304     $num_deps=0;
305     if(!$this->SubSearch){
306       $num_deps = count($this->Added_Departments);
307     }
308     $num_objs = count($list);
310     $num_obj_str = _("Number of listed mimetypes");
311     $num_dep_str = _("Number of listed departments");
313     $str = "<img class='center' src='images/select_mimetype.png'
314               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
315     $str.= "<img class='center' src='images/lists/folder.png'
316               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
318     $this->set_List_Bottom_Info($str);
319   }
321   function Save()
322   {
323     MultiSelectWindow::Save();  
324   }
326   function save_object()
327   {
328     /* Save automatic created POSTs like regex, checkboxes */
329     MultiSelectWindow::save_object(); 
330   }
333 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
334 ?>