Code

Fixed baseSelect options
[gosa.git] / plugins / admin / applications / class_divListApplication.inc
1 <?php
3 class divListApplication 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   var $SaveAdditionalVars = array("selectedRelease");
21   function divListApplication ($config,$parent)
22   {
23     MultiSelectWindow::MultiSelectWindow($config,"Application", "application");
24    
25     $this->selectedRelease = "ou=apps,".$_SESSION['CurrentMainBase'];
26  
27     $this->parent       = $parent;
28     $this->ui           = get_userinfo();
30     /* Set list strings */
31     $this->SetTitle(_("List of Applications"));
32     $this->SetSummary(_("This table displays all applications in the selected tree."));
34     /* Result page will look like a headpage */
35     $this->SetHeadpageMode();
36     $this->SetInformation(_("This menu allows you to add, edit and remove selected applications. You may want to use the range selector on top of the application listbox, when working with a large number of applications."));
38     $this->EnableAplhabet(true);
39   
40     /* Disable buttonsm */
41     $this->EnableCloseButton(false);
42     $this->EnableSaveButton (false);
44     /* set Page header */
45     $action_col_size = 70;
46     if($this->parent->snapshotEnabled()){
47       $action_col_size += 38;
48     }
50     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
51     $this->AddHeader(array("string" => _("Application name")." / "._("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",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
57     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
58     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
59   }
61   function AddUserBoxToFilter($position){
62     $str = "";
63     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
64       $smarty = get_smarty();
65       $smarty->assign("selectedRelease",$this->selectedRelease);
66       $smarty->assign("branchimage","images/branch.png");
67       $smarty->assign("releases",$this->AvailableReleases);
68       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
69     }
70     return($str);
71   }
73   function GenHeader()
74   {
75     /* Prepare departments,
76        which are shown in the listbox on top of the listbox
77     */
78     $options= "";
80     /* Get all departments within this subtree */
81     $base = $this->config->current['BASE'];
82     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
83                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
85     /* Load possible departments */
86     $ui= get_userinfo();
87     $tdeps= $ui->get_module_departments("application");
89     $ids = $this->config->idepartments;
91     foreach($deps as $dep){
92       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
94         $value = $ids[$dep['dn']];
95         if ($this->selectedBase == $dep['dn']){
96           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
97         } else {
98           $options.= "<option value='".$dep['dn']."'>$value</option>";
99         }
100       }
101     }
103     /* Get copy & paste icon */
104     if($this->parent->CopyPasteHandler){
105       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
106     }else{
107       $Copy_Paste ="";
108     }
110     /* Create listhead, it will be shown on top of the divlist.
111      * It provides general navigation and object creation
112      */
113     $ui  = get_userinfo();
114     $acl = $ui->get_permissions("cn=dummy,".$this->selectedBase,"application/application");
115     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
116       " <input class='center' type='image' src='images/list_root.png' align='middle' ".
117       "title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
118       " <input class='center' type='image' align='middle' src='images/list_back.png' ".
119       "title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
120       " <input class='center' type='image' align='middle' src='images/list_home.png' ".
121       "title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
122       " <input class='center' type='image' src='images/list_reload.png' align='middle' ".
123       "title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
124       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
125     $listhead .= $this->get_snapshot_header($this->selectedBase);
127     if(preg_match("/c/",$acl)){
128     $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."'
129        title='"._("Create new application")."' name='appl_new'>&nbsp;";
130     }
132     $listhead.=  $Copy_Paste.
133       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
134       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
135       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
136         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
137       "</div>";
139     $this->SetListHeader($listhead);
140   }
142   /* so some basic settings */
143   function execute()
144   {
145     $this->ClearElementsList();
146     $this->GenHeader();
147     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
148   }
150   function setEntries($list)
151   {
152     /********************
153       Variable init
154      ********************/
155   
156     /* Create links */
157     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
158     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
159     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
160     $applimg  = "<img class='center' src='images/select_application.png' alt='A'  title='"._("Application")."'>";
161     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
163     /* set Page header */
164     $action_col_size = 70;
165     if($this->parent->snapshotEnabled()){
166       $action_col_size += 38;
167     }
169     /********************
170       Attach objects
171      ********************/
172     
173     $ui = get_userinfo();
174     foreach($list as $key => $val){
176       $acl = $ui->get_permissions($val['dn'],"application/application");
178       /* Create action icons */
179       $actions= "";
182       /* Add Copy & Paste icon */
183       if($this->parent->CopyPasteHandler){
185         /* Only add cut icon, if we are allowed to move this user */
186         if(preg_match("/m/",$acl)){
187           $actions.= "<input class='center' type='image'
188             src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
189         }else{
190           $actions.= "<img src='images/empty.png' alt='&nbsp;'>";
191         }
193         /* Copy is allowed everytime */
194         $actions.= "<input class='center' type='image'
195           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
196       }
198       /* Add edit icon */
199       $actions.= "<input class='center' type='image'
200         src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
201       $actions.= $this->GetSnapShotActions($val['dn']);
203       /* If we are allowed to remove the application account, display remove icon */
204       if(preg_match("/d/",$acl)){
205         $actions.= "<input class='center' type='image'
206           src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
207       }else{
208         $actions.= "<img src='images/empty.png' alt='&nbsp;'>";
209       }
211       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
213       if(!isset($val['description'][0])){
214         $desc = "";
215       }else{
216         $desc = " - [ ".$val['description'][0]." ]";
217       }
218       $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
219       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
220       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
221       $this->AddElement(array($field1,$field2,$field3));
222     }
223   }
225   function Save()
226   {
227     MultiSelectWindow::Save();  
228   }
230   function save_object()
231   {
232     /* Save automatic created POSTs like regex, checkboxes */
233     MultiSelectWindow::save_object(); 
234     $_SESSION['appfilter']['release']  = $this->selectedRelease;
235   }
238 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
239 ?>