Code

Fixed msgPool call
[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 $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");
27   
28     /* initialize required attributes */ 
29     $this->selectedRelease  = get_ou('mimetypeou').session::get('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"));
38     /* Result page will look like a headpage */
39     $this->SetHeadpageMode();
40     $this->EnableAplhabet(true);
41   
42     /* Disable buttonsm */
43     $this->EnableCloseButton(false);
44     $this->EnableSaveButton (false);
46     /* set Page header */
47     $action_col_size = 80;
48     if($this->parent->snapshotEnabled()){
49       $action_col_size += 38;
50     }
52     /* Toggle all selected / deselected */
53     $chk = "<input type='checkbox' id='select_all' name='select_all'
54                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
56     /* set Page header */
57     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
58     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
59     $this->AddHeader(array("string" => _("Mime type")." / "._("Department"), "attach" => "style=''"));
60     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
62     /* Add SubSearch checkbox */
63     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
65     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
66     $this->AddRegex   ("Regex",     _("Display mime types matching"),"*" , true);
67   }
70   /* This function allows us to add a user defined filter part at position $position*/
71   function AddUserBoxToFilter($position)
72   {
73     $str = "";
74     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
75       $smarty = get_smarty();
76       $smarty->assign("selectedRelease",$this->selectedRelease);
77       $smarty->assign("branchimage","images/branch.png");
78       $smarty->assign("releases",$this->AvailableReleases);
79       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
80     }
81     return($str);
82   }
85   /* Create list header, with create / copy & paste etc*/
86   function GenHeader()
87   {
88     /* Prepare departments,
89        which are shown in the listbox on top of the listbox
90      */
91     $options= "";
93     /* Get all departments within this subtree */
94     $ui= get_userinfo();
95     $first = "";
96     $found = FALSE;
97     $base = $this->config->current['BASE'];
99     /* Add base */
100     $tmp = array();
101     $tmp[] = array("dn"=>$this->config->current['BASE']);
102     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
103                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
105     $deps = array();
106     foreach($tmp as $tm){
107       $deps[$tm['dn']] = $tm['dn'];
108     }
110     /* Load possible departments */
111     $ui= get_userinfo();
112     $tdeps= $ui->get_module_departments($this->module);
113     $ids = $this->config->idepartments;
114     $first = "";
115     $found = FALSE;
116     foreach($ids as $dep => $name){
117       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
119         /* Keep first base dn in mind, we could need this
120          *  info if no valid base was found
121          */
122         if(empty($first)) {
123           $first = $dep['dn'];
124         }
126         $value = $ids[$dep];
127         if ($this->selectedBase == $dep){
128           $found = TRUE;
129           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
130         } else {
131           $options.= "<option value='".$dep."'>$value</option>";
132         }
133       }
134     }
136     /* The currently used base is not visible with your acl setup.
137      * Set base to first useable base.
138      */
139     if(!$found){
140       $this->selectedBase = $first;
141     }
143     /* Get acls */
144     $ui       = get_userinfo();
145     $acl      = $ui->get_permissions("cn=dummy,".get_ou('mimetypeou').$this->selectedBase,"mimetypes/mimetype");
146     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
149     /* If this is true we add an additional seperator. Just look a few lines below */  
150     $add_sep = false;
151  
152     /* Get copy & paste icon */
153     $Copy_Paste ="";
154     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
155       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
156       $add_sep = true;
157     }
159     /* Add default header */
160     $listhead = MultiSelectWindow::get_default_header();
162     /* And at least add a department selection box */
163     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
164       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
165         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
167     /* Create Layers menu */
168     $s  = ".|"._("Actions")."|\n";
169     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
170       "&nbsp;"._("Create")."|\n";
172     /* Append create options */
173     if(preg_match("/c/",$acl)) {
174       $s.= "...|<input class='center' type='image' src='images/list_new_mime.png' alt=''>".
175         "&nbsp;"._("Mime type")."|mime_new|\n";
176     }
178     /* Multiple options */
179     $s.= "..|---|\n";
180     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
181       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
183     /* Add multiple copy & cut icons */
184     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
185       $s.= "..|---|\n";
186       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
187         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
188       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
189         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
191       if($this->parent->CopyPasteHandler->entries_queued()){
192         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
193         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
194       }else{
195         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
196         $s.="..|".$img."&nbsp;"._("Paste")."\n";
197       }
198     }
200     /* Add snapshot icons */
201     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
202       $s .= "..|---|\n";
203       $s .= $this->get_snapshot_header(TRUE);
204     }
206     $this->SetDropDownHeaderMenu($s);
207     $this->SetListHeader($listhead);
208   }
211   /* Some basic settings */
212   function execute()
213   {
214     $this->ClearElementsList();
215     $this->GenHeader();
216   }
219   function setEntries($list)
220   {
221     /********************
222       Variable init
223      ********************/
225     /* Create links */
226     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
227     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
228     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
229     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
230     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
232     /* set Page header */
233     $action_col_size = 80;
234     if($this->parent->snapshotEnabled()){
235       $action_col_size += 38;
236     }
238     /********************
239       Attach objects
240      ********************/
242     foreach($list as $key => $val){
244       $ui       = get_userinfo();
245       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
246       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
248       /* Create action icons */
249       $actions = "";
250       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
251         $actions .= $this->GetSnapShotActions($val['dn']);
252       }
254       /* Get copy Paste icons */
255       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
256         $actions.= "<input class='center' type='image'
257           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
258         $actions.= "<input class='center' type='image'
259           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
260       }
262       $actions.= "<input class='center' type='image'
263         src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
265       /* Add delete button */
266       if(preg_match("/d/",$acl)){
267         $actions.= "<input class='center' type='image'
268           src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
269       }else{
270         $actions.= "<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, $actions), "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/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(); 
331     /* check if returned selectedRelease is a valid release.
332         If it isn't set to a valid release */
333     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
334     if(!isset($this->AvailableReleases[$this->selectedRelease])){
335       $this->selectedRelease =key($this->AvailableReleases);
336     }
337     $mimefilter = session::get('mimefilter');
338     $mimefilter['release']  = $this->selectedRelease;
339     session::set('mimefilter',$mimefilter);
340   }
343 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
344 ?>