Code

Moved select_groups images
[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'
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();
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("cn=dummy,".$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     /* Get copy & paste icon */
159     $Copy_Paste ="";
160     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
161       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
162       $add_sep = true;
163     }
166     /* Create Layers menu */
167     $s  = ".|"._("Actions")."|\n";
168     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
169       "&nbsp;"._("Create")."|\n";
171     /* Append create options */
172     if(preg_match("/c/",$acl)) {
173       $s.= "...|<input class='center' type='image' src='images/list_new_mime.png' alt=''>".
174         "&nbsp;"._("Mime type")."|mime_new|\n";
175     }
177     /* Multiple options */
178     $s.= "..|---|\n";
179     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
180       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
182     /* Add multiple copy & cut icons */
183     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
184       $s.= "..|---|\n";
185       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
186         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
187       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
188         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
190       if($this->parent->CopyPasteHandler->entries_queued()){
191         $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
192         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
193       }else{
194         $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
195         $s.="..|".$img."&nbsp;"._("Paste")."\n";
196       }
197     }
199     /* Add snapshot icons */
200     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
201       $s .= "..|---|\n";
202       $s .= $this->get_snapshot_header(TRUE);
203     }
205     $this->SetDropDownHeaderMenu($s);
206     $this->SetListHeader($listhead);
207   }
210   /* Some basic settings */
211   function execute()
212   {
213     $this->ClearElementsList();
214     $this->GenHeader();
215   }
218   function setEntries($list)
219   {
220     /********************
221       Variable init
222      ********************/
224     /* Create links */
225     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
226     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
227     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
228     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
229     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
231     /* set Page header */
232     $action_col_size = 80;
233     if($this->parent->snapshotEnabled()){
234       $action_col_size += 38;
235     }
237     /********************
238       Attach objects
239      ********************/
241     foreach($list as $key => $val){
243       $ui       = get_userinfo();
244       $acl      = $ui->get_permissions($val['dn'],"mimetypes/mimetype");
245       $acl_all  = $ui->has_complete_category_acls($val['dn'],"mimetypes") ;
247       /* Create action icons */
248       $actions = "";
249       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
250         $actions .= $this->GetSnapShotActions($val['dn']);
251       }
253       /* Get copy Paste icons */
254       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
255         $actions.= "<input class='center' type='image'
256           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
257         $actions.= "<input class='center' type='image'
258           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
259       }
261       $actions.= "<input class='center' type='image'
262         src='images/lists/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
264       /* Add delete button */
265       if(preg_match("/d/",$acl)){
266         $actions.= "<input class='center' type='image'
267           src='images/lists/trash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
268       }else{
269         $actions.= "<img src='images/empty.png' alt='&nbsp;' class='center'>";
270       }
272       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
274       if(!isset($val['description'][0])){
275         $desc = "";
276       }else{
277         $desc = " - [ ".$val['description'][0]." ]";
278       }
280       /* Cutted objects should be displayed in light grey */
281       $display = $val['cn'][0].$desc;
282       if($this->parent->CopyPasteHandler){
283         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
284           if($queue_data['dn'] == $val['dn']) {
285             $display = "<font color='#999999'>".$display."</font>";
286             break;
287           }
288         }
289       }
292       /* Create each field */
293       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
294                       "attach" => "style='width:20px;'");
295       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
296       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
297       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
298       $this->AddElement(array($field0,$field1,$field2,$field3));
299     }
302     /* Create summary string for list footer */
303     $num_deps=0;
304     if(!$this->SubSearch){
305       $num_deps = count($this->Added_Departments);
306     }
307     $num_objs = count($list);
309     $num_obj_str = _("Number of listed mimetypes");
310     $num_dep_str = _("Number of listed departments");
312     $str = "<img class='center' src='images/select_mimetype.png'
313               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
314     $str.= "<img class='center' src='images/lists/folder.png'
315               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
317     $this->set_List_Bottom_Info($str);
318   }
320   function Save()
321   {
322     MultiSelectWindow::Save();  
323   }
325   function save_object()
326   {
327     /* Save automatic created POSTs like regex, checkboxes */
328     MultiSelectWindow::save_object(); 
329   }
332 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
333 ?>