Code

4f669c95dc8796183ca115995ca3d000008a00cd
[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     /* Add Copy & Paste header */
175     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
177     /* Add snapshot icons */
178     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
180     $this->SetDropDownHeaderMenu($s);
181     $this->SetListHeader($listhead);
182   }
185   /* Some basic settings */
186   function execute()
187   {
188     $this->ClearElementsList();
189     $this->GenHeader();
190   }
193   function setEntries($list)
194   {
195     /********************
196       Variable init
197      ********************/
199     /* Create links */
200     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
201     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
202     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
203     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
204     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
206     /* set Page header */
207     $action_col_size = 80;
208     if($this->parent->snapshotEnabled()){
209       $action_col_size += 38;
210     }
212     /********************
213       Attach objects
214      ********************/
216     foreach($list as $key => $val){
218       $ui       = get_userinfo();
219       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
220       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
222       $action = "";
223       if($ui->is_cutable($val['dn'],"mimetypes","mimetype") && $this->parent->CopyPasteHandler){
224         $action .= "<input class='center' type='image'
225           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
226       }else{
227         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
228       }
230       if($ui->is_copyable($val['dn'],"mimetypes","mimetype") && $this->parent->CopyPasteHandler){
231         $action.= "<input class='center' type='image'
232           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
233       }else{
234         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
235       }
237       $action.= "<input class='center' type='image'
238         src='images/lists/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
240       /* Add snapshot icon */
241       $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
243       /* Add delete button */
244       if(preg_match("/d/",$acl)){
245         $action.= "<input class='center' type='image'
246           src='images/lists/trash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
247       }else{
248         $action.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
249       }
251       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
253       if(!isset($val['description'][0])){
254         $desc = "";
255       }else{
256         $desc = " - [ ".$val['description'][0]." ]";
257       }
259       /* Cutted objects should be displayed in light grey */
260       $display = $val['cn'][0].$desc;
261       if($this->parent->CopyPasteHandler){
262         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
263           if($queue_data['dn'] == $val['dn']) {
264             $display = "<font color='#999999'>".$display."</font>";
265             break;
266           }
267         }
268       }
271       /* Create each field */
272       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
273                       "attach" => "style='width:20px;'");
274       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
275       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
276       $field3 = array("string" => preg_replace("/%KEY%/", $key, $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
277       $this->AddElement(array($field0,$field1,$field2,$field3));
278     }
281     /* Create summary string for list footer */
282     $num_deps=0;
283     if(!$this->SubSearch){
284       $num_deps = count($this->Added_Departments);
285     }
286     $num_objs = count($list);
288     $num_obj_str = _("Number of listed mimetypes");
289     $num_dep_str = _("Number of listed departments");
291     $str = "<img class='center' src='images/select_mimetype.png'
292               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
293     $str.= "<img class='center' src='images/lists/folder.png'
294               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
296     $this->set_List_Bottom_Info($str);
297   }
299   function Save()
300   {
301     MultiSelectWindow::Save();  
302   }
304   function save_object()
305   {
306     /* Save automatic created POSTs like regex, checkboxes */
307     MultiSelectWindow::save_object(); 
308   }
311 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
312 ?>