Code

* Fixed undefined index for "All"
[gosa.git] / 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  = "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);
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"), _("Ignore 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'];
99     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
100         array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
102     /* Add base */
103     $deps[] = array("dn"=>$this->config->current['BASE']);
105     /* Load possible departments */
106     $ui   = get_userinfo();
107     $tdeps= $ui->get_module_departments($this->module);
109     $ids = $this->config->idepartments;
111     foreach($deps as $dep){
112       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
114         /* Keep first base dn in mind, we could need this
115          *  info if no valid base was found
116          */
117         if(empty($first)) {
118           $first = $dep['dn'];
119         }
120     
121         $value = $ids[$dep['dn']];
122         if ($this->selectedBase == $dep['dn']){
123           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
124         } else {
125           $options.= "<option value='".$dep['dn']."'>$value</option>";
126         }
127       }
128     }
130     /* The currently used base is not visible with your acl setup.
131      * Set base to first useable base.
132      */
133     if(!$found){
134       $this->selectedBase = $first;
135     }
137     /* Get acls */
138     $ui       = get_userinfo();
139     $acl      = $ui->get_permissions("cn=dummy,ou=mimetypes,".$this->selectedBase,"mimetypes/mimetype");
140     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
143     /* If this is true we add an additional seperator. Just look a few lines below */  
144     $add_sep = false;
145  
146     /* Get copy & paste icon */
147     $Copy_Paste ="";
148     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
149       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
150       $add_sep = true;
151     }
153     /* Add default header */
154     $listhead = MultiSelectWindow::get_default_header();
156     /* Create snapshot icons */
157     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
158       $listhead .= $this->get_snapshot_header($this->selectedBase);
159       $add_sep = true;
160     }
161     
162     /* Add create icon */
163     if(preg_match("/c/",$acl)){
164       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_mime.png' alt='"._("new").
165         "' title='"._("Create new mime type")."' name='mime_new'>&nbsp;";
166       $add_sep = true;
167     }
168   
169     /* Add copy & paste icons */
170     $listhead .= $Copy_Paste;
172     /* Add a seperator ? */
173     if($add_sep) {
174       $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
175     }
176     
177     /* And at least add a department selection box */
178     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
179       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
180         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
182         /* Multiple options */
183     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
184         title='"._("Remove selected mimetype")."' alt='"._("Remove mimetype")."' name='remove_multiple_mimetypes'>&nbsp;";
186     $listhead .="</div>";;
188     $this->SetListHeader($listhead);
189   }
192   /* Some basic settings */
193   function execute()
194   {
195     $this->ClearElementsList();
196     $this->GenHeader();
197   }
200   function setEntries($list)
201   {
202     /********************
203       Variable init
204      ********************/
206     /* Create links */
207     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
208     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
209     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
210     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
211     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
213     /* set Page header */
214     $action_col_size = 80;
215     if($this->parent->snapshotEnabled()){
216       $action_col_size += 38;
217     }
219     /********************
220       Attach objects
221      ********************/
223     foreach($list as $key => $val){
225       $ui       = get_userinfo();
226       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
227       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
229       /* Create action icons */
230       $actions = "";
231       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
232         $actions .= $this->GetSnapShotActions($val['dn']);
233       }
235       /* Get copy Paste icons */
236       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
237         $actions.= "<input class='center' type='image'
238           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
239         $actions.= "<input class='center' type='image'
240           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
241       }
243       $actions.= "<input class='center' type='image'
244         src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
246       /* Add delete button */
247       if(preg_match("/d/",$acl)){
248         $actions.= "<input class='center' type='image'
249           src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
250       }else{
251         $actions.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
252       }
254       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
256       if(!isset($val['description'][0])){
257         $desc = "";
258       }else{
259         $desc = " - [ ".$val['description'][0]." ]";
260       }
262       /* Create each field */
263       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
264                       "attach" => "style='width:20px;'");
265       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
266       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
267       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
268       $this->AddElement(array($field0,$field1,$field2,$field3));
269     }
270   }
272   function Save()
273   {
274     MultiSelectWindow::Save();  
275   }
277   function save_object()
278   {
279     /* Save automatic created POSTs like regex, checkboxes */
280     MultiSelectWindow::save_object(); 
282     /* check if returned selectedRelease is a valid release.
283         If it isn't set to a valid release */
284     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
285     if(!isset($this->AvailableReleases[$this->selectedRelease])){
286       $this->selectedRelease =key($this->AvailableReleases);
287     }
288     $_SESSION['mimefilter']['release']  = $this->selectedRelease;
289   }
292 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
293 ?>