Code

6adc6a9e649150cc23daca4510d63bbbade9e67f
[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;
50     /* Toggle all selected / deselected */
51     $chk = "<input type='checkbox' id='select_all' name='select_all'
52                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
54     /* set Page header */
55     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
56     $this->AddHeader(array("string" => _("Mime type name")." / "._("Department"), "attach" => "style=''"));
57     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
59     /* Add SubSearch checkbox */
60     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
62     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
63     $this->AddRegex   ("Regex",     _("Display mime types matching"),"*" , true);
64   }
67   /* This function allows us to add a user defined filter part at position $position*/
68   function AddUserBoxToFilter($position)
69   {
70     $str = "";
71     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
72       $smarty = get_smarty();
73       $smarty->assign("selectedRelease",$this->selectedRelease);
74       $smarty->assign("branchimage","images/branch.png");
75       $smarty->assign("releases",$this->AvailableReleases);
76       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
77     }
78     return($str);
79   }
82   /* Create list header, with create / copy & paste etc*/
83   function GenHeader()
84   {
85     /* Prepare departments,
86        which are shown in the listbox on top of the listbox
87      */
88     $options= "";
89     foreach ($this->config->idepartments as $key => $value){
90       if ($this->selectedBase == $key){
91         $options.= "<option selected='selected' value='$key'>$value</option>";
92       } else {
93         $options.= "<option value='$key'>$value</option>";
94       }
95     }
97     $listhead = MultiSelectWindow::get_default_header();
98     $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_mime.png' alt='"._("new").
99       "' title='"._("Create new mime type")."' name='mime_new'>&nbsp;";
100     $add_sep = true;
102     /* And at least add a department selection box */
103     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
104       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
105         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
107     $listhead .="</div>";;
109     $this->SetListHeader($listhead);
110   }
113   /* Some basic settings */
114   function execute()
115   {
116     $this->ClearElementsList();
117     $this->GenHeader();
118   }
121   function setEntries($list)
122   {
123     /********************
124       Variable init
125      ********************/
127     /* Create links */
128     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
129     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
130     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
131     $mimeimg  = "<img class='center' src='images/select_mimetype.png' alt='A'  title='"._("Mime type")."'>";
132     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
134     /* set Page header */
135     $action_col_size = 80;
137     /********************
138       Attach objects
139      ********************/
141     foreach($list as $key => $val){
143       /* Create action icons */
144       $actions = "";
146       $actions.= "<input class='center' type='image'
147         src='images/edit.png' alt='"._("edit")."' name='mime_edit_%KEY%' title='"._("Edit this entry")."'>";
149       $actions.= "<input class='center' type='image'
150         src='images/edittrash.png' alt='"._("delete")."' name='mime_del_%KEY%' title='"._("Delete this entry")."'>";
152       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
154       if(!isset($val['description'][0])){
155         $desc = "";
156       }else{
157         $desc = " - [ ".$val['description'][0]." ]";
158       }
160       $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
161       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
162       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
163       $this->AddElement(array($field1,$field2,$field3));
164     }
165   }
167   function Save()
168   {
169     MultiSelectWindow::Save();  
170   }
172   function save_object()
173   {
174     /* Save automatic created POSTs like regex, checkboxes */
175     MultiSelectWindow::save_object(); 
177     /* check if returned selectedRelease is a valid release.
178         If it isn't set to a valid release */
179     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
180     if(!isset($this->AvailableReleases[$this->selectedRelease])){
181       $this->selectedRelease =key($this->AvailableReleases);
182     }
183     $_SESSION['mimefilter']['release']  = $this->selectedRelease;
184   }
187 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
188 ?>