Code

Corrected path
[gosa.git] / gosa-core / plugins / 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"));
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);
42   
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     }
53     /* Toggle all selected / deselected */
54     $chk = "<input type='checkbox' id='select_all' name='select_all'
55                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
57     /* set Page header */
58     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
59     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
60     $this->AddHeader(array("string" => _("Mime type name")." / "._("Department"), "attach" => "style=''"));
61     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
63     /* Add SubSearch checkbox */
64     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
66     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
67     $this->AddRegex   ("Regex",     _("Display mime types matching"),"*" , true);
68   }
71   /* This function allows us to add a user defined filter part at position $position*/
72   function AddUserBoxToFilter($position)
73   {
74     $str = "";
75     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
76       $smarty = get_smarty();
77       $smarty->assign("selectedRelease",$this->selectedRelease);
78       $smarty->assign("branchimage","images/branch.png");
79       $smarty->assign("releases",$this->AvailableReleases);
80       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
81     }
82     return($str);
83   }
86   /* Create list header, with create / copy & paste etc*/
87   function GenHeader()
88   {
89     /* Prepare departments,
90        which are shown in the listbox on top of the listbox
91      */
92     $options= "";
94     /* Get all departments within this subtree */
95     $ui= get_userinfo();
96     $first = "";
97     $found = FALSE;
98     $base = $this->config->current['BASE'];
100     /* Add base */
101     $tmp = array();
102     $tmp[] = array("dn"=>$this->config->current['BASE']);
103     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
104                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
106     $deps = array();
107     foreach($tmp as $tm){
108       $deps[$tm['dn']] = $tm['dn'];
109     }
111     /* Load possible departments */
112     $ui= get_userinfo();
113     $tdeps= $ui->get_module_departments($this->module);
114     $ids = $this->config->idepartments;
115     $first = "";
116     $found = FALSE;
117     foreach($ids as $dep => $name){
118       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
120         /* Keep first base dn in mind, we could need this
121          *  info if no valid base was found
122          */
123         if(empty($first)) {
124           $first = $dep['dn'];
125         }
127         $value = $ids[$dep];
128         if ($this->selectedBase == $dep){
129           $found = TRUE;
130           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
131         } else {
132           $options.= "<option value='".$dep."'>$value</option>";
133         }
134       }
135     }
137     /* The currently used base is not visible with your acl setup.
138      * Set base to first useable base.
139      */
140     if(!$found){
141       $this->selectedBase = $first;
142     }
144     /* Get acls */
145     $ui       = get_userinfo();
146     $acl      = $ui->get_permissions("cn=dummy,".get_ou('mimetypeou').$this->selectedBase,"mimetypes/mimetype");
147     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
150     /* If this is true we add an additional seperator. Just look a few lines below */  
151     $add_sep = false;
152  
153     /* Get copy & paste icon */
154     $Copy_Paste ="";
155     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
156       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
157       $add_sep = true;
158     }
160     /* Add default header */
161     $listhead = MultiSelectWindow::get_default_header();
163     /* And at least add a department selection box */
164     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
165       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
166         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
168     /* Create Layers menu */
169     $s  = ".|"._("Actions")."|\n";
170     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
171       "&nbsp;"._("Create")."|\n";
173     /* Append create options */
174     if(preg_match("/c/",$acl)) {
175       $s.= "...|<input class='center' type='image' src='images/list_new_mime.png' alt=''>".
176         "&nbsp;"._("Mime type")."|mime_new|\n";
177     }
179     /* Multiple options */
180     $s.= "..|---|\n";
181     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
182       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
184     /* Add multiple copy & cut icons */
185     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
186       $s.= "..|---|\n";
187       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
188         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
189       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
190         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
192       if($this->parent->CopyPasteHandler->entries_queued()){
193         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
194         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
195       }else{
196         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
197         $s.="..|".$img."&nbsp;"._("Paste")."\n";
198       }
199     }
201     /* Add snapshot icons */
202     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
203       $s .= "..|---|\n";
204       $s .= $this->get_snapshot_header(TRUE);
205     }
207     $this->SetDropDownHeaderMenu($s);
208     $this->SetListHeader($listhead);
209   }
212   /* Some basic settings */
213   function execute()
214   {
215     $this->ClearElementsList();
216     $this->GenHeader();
217   }
220   function setEntries($list)
221   {
222     /********************
223       Variable init
224      ********************/
226     /* Create links */
227     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
228     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
229     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
230     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
231     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
233     /* set Page header */
234     $action_col_size = 80;
235     if($this->parent->snapshotEnabled()){
236       $action_col_size += 38;
237     }
239     /********************
240       Attach objects
241      ********************/
243     foreach($list as $key => $val){
245       $ui       = get_userinfo();
246       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
247       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
249       /* Create action icons */
250       $actions = "";
251       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
252         $actions .= $this->GetSnapShotActions($val['dn']);
253       }
255       /* Get copy Paste icons */
256       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
257         $actions.= "<input class='center' type='image'
258           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
259         $actions.= "<input class='center' type='image'
260           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
261       }
263       $actions.= "<input class='center' type='image'
264         src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
266       /* Add delete button */
267       if(preg_match("/d/",$acl)){
268         $actions.= "<input class='center' type='image'
269           src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
270       }else{
271         $actions.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
272       }
274       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
276       if(!isset($val['description'][0])){
277         $desc = "";
278       }else{
279         $desc = " - [ ".$val['description'][0]." ]";
280       }
282       /* Cutted objects should be displayed in light grey */
283       $display = $val['cn'][0].$desc;
284       if($this->parent->CopyPasteHandler){
285         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
286           if($queue_data['dn'] == $val['dn']) {
287             $display = "<font color='#999999'>".$display."</font>";
288             break;
289           }
290         }
291       }
294       /* Create each field */
295       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
296                       "attach" => "style='width:20px;'");
297       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
298       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
299       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
300       $this->AddElement(array($field0,$field1,$field2,$field3));
301     }
304     /* Create summary string for list footer */
305     $num_deps=0;
306     if(!$this->SubSearch){
307       $num_deps = count($this->Added_Departments);
308     }
309     $num_objs = count($list);
311     $num_obj_str = _("Number of listed mimetypes");
312     $num_dep_str = _("Number of listed departments");
314     $str = "<img class='center' src='images/select_mimetype.png'
315               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
316     $str.= "<img class='center' src='images/folder.png'
317               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
319     $this->set_List_Bottom_Info($str);
320   }
322   function Save()
323   {
324     MultiSelectWindow::Save();  
325   }
327   function save_object()
328   {
329     /* Save automatic created POSTs like regex, checkboxes */
330     MultiSelectWindow::save_object(); 
332     /* check if returned selectedRelease is a valid release.
333         If it isn't set to a valid release */
334     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
335     if(!isset($this->AvailableReleases[$this->selectedRelease])){
336       $this->selectedRelease =key($this->AvailableReleases);
337     }
338     $mimefilter = session::get('mimefilter');
339     $mimefilter['release']  = $this->selectedRelease;
340     session::set('mimefilter',$mimefilter);
341   }
344 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
345 ?>