1 <?php
3 class divListApplication extends MultiSelectWindow
4 {
5 /* Current base */
6 var $departments = array();
7 var $parent ;
8 var $ui ;
10 /* Regex */
11 var $Regex = "*";
13 /* Subsearch checkbox */
14 var $SubSearch;
15 var $selectedBase ="";
17 function divListApplication (&$config,&$parent)
18 {
19 MultiSelectWindow::MultiSelectWindow($config,"Application", "application");
21 $this->parent = &$parent;
22 $this->ui = get_userinfo();
24 /* Set list strings */
25 $this->SetTitle(_("List of Applications"));
26 $this->SetSummary(_("This table displays all applications in the selected tree."));
28 /* Result page will look like a headpage */
29 $this->SetHeadpageMode();
31 $this->EnableAplhabet(true);
33 /* Disable buttonsm */
34 $this->EnableCloseButton(false);
35 $this->EnableSaveButton (false);
37 /* set Page header */
38 $action_col_size = 80;
39 if($this->parent->snapshotEnabled()){
40 $action_col_size += 38;
41 }
44 /* Toggle all selected / deselected */
45 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("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" => " ", "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", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
57 /* Name ,Text ,Default , Connect with alphabet */
58 $this->AddRegex ("Regex", _("Display users 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("app_release" , $releases[$this->parent->app_release]);
69 $smarty->assign("app_base" , $releases[$this->parent->app_base]);
70 $smarty->assign("branchimage","images/branch.png");
71 $smarty->assign("app_releases", $releases);
72 $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
73 }
74 return($str);
75 }
78 function GenHeader()
79 {
80 /* Prepare departments,
81 which are shown in the listbox on top of the listbox
82 */
83 $options= "";
85 /* Add default header */
86 $listhead = MultiSelectWindow::get_default_header(false);
88 if(!$this->parent->IsReleaseManagementActivated()){
90 /* Get all departments within this subtree */
91 $base = $this->config->current['BASE'];
93 /* Add base */
94 $tmp = array();
95 $tmp[] = array("dn"=>$this->config->current['BASE']);
96 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
97 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
99 $deps = array();
100 foreach($tmp as $tm){
101 $deps[$tm['dn']] = $tm['dn'];
102 }
104 /* Load possible departments */
105 $ui= get_userinfo();
106 $tdeps= $ui->get_module_departments("application");
107 $ids = $this->config->idepartments;
108 $first = "";
109 $found = FALSE;
110 foreach($ids as $dep => $name){
111 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
113 /* Keep first base dn in mind, we could need this
114 * info if no valid base was found
115 */
116 if(empty($first)) {
117 $first = $dep['dn'];
118 }
120 $value = $ids[$dep];
121 if ($this->selectedBase == $dep){
122 $found = TRUE;
123 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
124 } else {
125 $options.= "<option value='".$dep."'>$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 }
138 /* And the rest, a base selection box */
139 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
140 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
141 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
142 }
144 /* Get acls */
145 $ui = get_userinfo();
146 $acl = $ui->get_permissions($this->selectedBase,"application/application");
147 $acl_all = $ui->has_complete_category_acls($this->parent->app_base,"application");
149 /* Create Layers menu */
150 $s = ".|"._("Actions")."|\n";
152 /* Append create options */
153 if(preg_match("/c/",$acl)) {
154 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
155 " "._("Create")."|\n";
156 $s.= "...|<input class='center' type='image' src='images/list_new_app' alt=''>".
157 " "._("Application")."|appl_new|\n";
158 }
160 /* Multiple options */
161 $s.= "..|---|\n";
162 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
163 " "._("Remove")."|"."remove_multiple|\n";
165 if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
166 $s.= "..|---|\n";
167 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
168 " "._("Copy")."|"."multiple_copy_systems|\n";
169 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(r.*d|d.*r)/",$acl_all)){
170 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
171 " "._("Cut")."|"."multiple_cut_systems|\n";
172 }
173 }
175 /* Copy & paste icons */
176 if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
177 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
178 $s.="..|".$img." "._("Paste")."|editPaste|\n";
179 }else{
180 $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
181 $s.="..|".$img." "._("Paste")."\n";
182 }
184 /* Add snapshot icons */
185 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
186 $s .= "..|---|\n";
187 $s .= $this->get_snapshot_header(TRUE);
188 }
190 $this->SetDropDownHeaderMenu($s);
191 $this->SetListHeader($listhead);
192 }
195 /* so some basic settings */
196 function execute()
197 {
198 $this->ClearElementsList();
199 $this->GenHeader();
200 }
203 function setEntries($list)
204 {
205 /********************
206 Variable init
207 ********************/
209 /* Create links */
210 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
211 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
212 $userimg = "<img class='center' src='plugins/groups/images/groups.png' alt='User' title='%s'>";
213 $applimg = "<img class='center' src='images/select_application.png' alt='A' title='"._("Application")."'>";
214 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
216 /* set Page header */
217 $action_col_size = 80;
218 if($this->parent->snapshotEnabled()){
219 $action_col_size += 38;
220 }
222 /********************
223 Attach objects
224 ********************/
226 $ui = get_userinfo();
227 foreach($list as $key => $val){
229 $acl = $ui->get_permissions($val['dn'],"application/application");
230 $acl_all= $ui->has_complete_category_acls($val['dn'],"application");
232 /* Create action icons */
233 $actions= "";
235 /* Add Copy & Paste icon */
236 if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
237 $actions .= "<input class='center' type='image'
238 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
239 }else{
240 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
241 }
243 if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
244 $actions.= "<input class='center' type='image'
245 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
246 }else{
247 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
248 }
250 /* Add edit icon */
251 $actions.= "<input class='center' type='image'
252 src='images/lists/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
254 /* Add snapshot icon */
255 if(preg_match("/(r.*w|w.*r)/",$acl_all)){
256 $actions.= $this->GetSnapShotActions($val['dn']);
257 }else{
258 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
259 $actions.="<img src='images/empty.png' alt=' ' class='center'> ";
260 }
262 /* If we are allowed to remove the application account, display remove icon */
263 if(preg_match("/d/",$acl)){
264 $actions.= "<input class='center' type='image'
265 src='images/lists/trash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
266 }else{
267 $actions.= "<img src='images/empty.png' alt=' '>";
268 }
270 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
272 if(!isset($val['description'][0])){
273 $desc = "";
274 }else{
275 $desc = " - [ ".$val['description'][0]." ]";
276 }
278 /* Cutted objects should be displayed in light grey */
279 $display = $val['cn'][0].$desc;
280 if($this->parent->CopyPasteHandler){
281 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
282 if($queue_data['dn'] == $val['dn']) {
283 $display = "<font color='#999999'>".$display."</font>";
284 break;
285 }
286 }
287 }
289 /* Create each field */
290 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
291 "attach" => "style='width:20px;'");
292 $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
293 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
294 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
295 $this->AddElement(array($field0,$field1,$field2,$field3));
296 }
298 /* Create summary string for list footer */
299 $num_deps=0;
300 if(!$this->SubSearch){
301 $num_deps = count($this->Added_Departments);
302 }
303 $num_apps = count($list);
305 $num_app_str = _("Number of listed applications");
306 $num_dep_str = _("Number of listed departments");
308 $str = "<img class='center' src='images/select_application.png'
309 title='".$num_app_str."' alt='".$num_app_str."'> ".$num_apps." ";
310 $str.= "<img class='center' src='images/lists/folder.png'
311 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
313 $this->set_List_Bottom_Info($str);
314 }
316 function Save()
317 {
318 MultiSelectWindow::Save();
319 }
321 function save_object()
322 {
323 /* Save automatic created POSTs like regex, checkboxes */
324 MultiSelectWindow::save_object();
325 }
327 }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>