Code

3cfeea35db5341510fa356608d4c66783d38d61e
[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 = 80;
46     if($this->parent->snapshotEnabled()){
47       $action_col_size += 38;
48     }
51     /* Toggle all selected / deselected */
52     $chk = "<input type='checkbox' id='select_all' name='select_all'
53                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
55     /* set Page header */
56     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
57     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
58     $this->AddHeader(array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"));
59     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
61     /* Add SubSearch checkbox */
62     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
64     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
65     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
66   }
68   function AddUserBoxToFilter($position){
69     $str = "";
70     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
71       $smarty = get_smarty();
72       $smarty->assign("selectedRelease",$this->selectedRelease);
73       $smarty->assign("branchimage","images/branch.png");
74       $smarty->assign("releases",$this->AvailableReleases);
75       $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
76     }
77     return($str);
78   }
80   function GenHeader()
81   {
82     /* Prepare departments,
83        which are shown in the listbox on top of the listbox
84     */
85     $options= "";
87     /* Get all departments within this subtree */
88     $base = $this->config->current['BASE'];
90     /* Add base */
91     $tmp = array();
92     $tmp[] = array("dn"=>$this->config->current['BASE']);
93     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
94                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
96     $deps = array();
97     foreach($tmp as $tm){
98       $deps[$tm['dn']] = $tm['dn'];
99     }
101     /* Load possible departments */
102     $ui= get_userinfo();
103     $tdeps= $ui->get_module_departments("application");
104     $ids = $this->config->idepartments;
105     $first = "";
106     $found = FALSE;
107     foreach($ids as $dep => $name){
108       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
110         /* Keep first base dn in mind, we could need this
111          *  info if no valid base was found
112          */
113         if(empty($first)) {
114           $first = $dep['dn'];
115         }
117         $value = $ids[$dep];
118         if ($this->selectedBase == $dep){
119           $found = TRUE;
120           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
121         } else {
122           $options.= "<option value='".$dep."'>$value</option>";
123         }
124       }
125     }
127     /* The currently used base is not visible with your acl setup.
128      * Set base to first useable base.
129      */
130     if(!$found){
131       $this->selectedBase = $first;
132     }
134     /* Get acls */
135     $ui       = get_userinfo();
136     $acl      = $ui->get_permissions("cn=dummy,".$this->selectedBase,"application/application");
137     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"application");
139     /* If this is true we have to add a seperator after 
140       adding the special icons, just have a look at the lines below */
141     $add_sep = false;
143     /* Get copy & paste icon */
144     $Copy_Paste ="";
145     if((preg_match("/(c.*w|w.*c)/",$acl_all)) && ($this->parent->CopyPasteHandler)){
146       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon(); 
147       $add_sep = true;
148     }
150     /* Add default header */
151     $listhead = MultiSelectWindow::get_default_header();
153     /* Add snapshot header icons */
154     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
155       $listhead .= $this->get_snapshot_header($this->selectedBase);
156       $add_sep = true;
157     }
159     /* Add create icon */
160     if(preg_match("/c/",$acl)){
161       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."'
162        title='"._("Create new application")."' name='appl_new'>&nbsp;";
163       $add_sep = true;
164     }
166     /* Add copy & paste icon */
167     $listhead.=  $Copy_Paste;
169     /* Add a seperator if required and the list will look perfectly */
170     if($add_sep){
171       $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
172     }
174     /* And the rest, a base selection box */
175     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
176       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
177         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
179         /* Multiple options */
180     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
181         title='"._("Remove selected applications")."' alt='"._("Remove applications")."' name='remove_multiple_applications'>&nbsp;";
183     /* Add multiple copy & cut icons */
184     if(is_object($this->parent->CopyPasteHandler)){
185       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
186         title='"._("Copy selected group")."' alt='"._("Copy groups")."' name='multiple_copy_groups'>&nbsp;";
187       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
188         title='"._("cut selected group")."' alt='"._("Cut groups")."' name='multiple_cut_groups'>&nbsp;";
189     }
190     $listhead .="</div>";
192     $this->SetListHeader($listhead);
193   }
195   /* so some basic settings */
196   function execute()
197   {
198     $this->ClearElementsList();
199     $this->GenHeader();
200     $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
201   }
203   function setEntries($list)
204   {
205     /********************
206       Variable init
207      ********************/
208   
209     /* Create links */
210     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
211     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
212     $userimg  = "<img class='center' src='images/select_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      ********************/
225     
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(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
237         /* Only add cut icon, if we are allowed to move this user */
238         if(preg_match("/m/",$acl)){
239           $actions.= "<input class='center' type='image'
240             src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
242           $actions.= "<input class='center' type='image'
243             src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
244         }
245       }
247       /* Add edit icon */
248       $actions.= "<input class='center' type='image'
249         src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
252       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
253         $actions.= $this->GetSnapShotActions($val['dn']);
254       }
256       /* If we are allowed to remove the application account, display remove icon */
257       if(preg_match("/d/",$acl)){
258         $actions.= "<input class='center' type='image'
259           src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
260       }else{
261         $actions.= "<img src='images/empty.png' alt='&nbsp;'>";
262       }
264       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
266       if(!isset($val['description'][0])){
267         $desc = "";
268       }else{
269         $desc = " - [ ".$val['description'][0]." ]";
270       }
272       /* Cutted objects should be displayed in light grey */
273       $display = $val['cn'][0].$desc;
274       if($this->parent->CopyPasteHandler){
275         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
276           if($queue_data['dn'] == $val['dn']) {
277             $display = "<font color='#999999'>".$display."</font>";
278             break;
279           }
280         }
281       }
283       /* Create each field */
284       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
285                       "attach" => "style='width:20px;'");
286       $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
287       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
288       $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
289       $this->AddElement(array($field0,$field1,$field2,$field3));
290     }
292     /* Create summary string for list footer */
293     $num_deps=0;
294     if(!$this->SubSearch){
295       $num_deps = count($this->Added_Departments);
296     }
297     $num_apps = count($list);
299     $num_app_str = _("Number of listed applications");
300     $num_dep_str = _("Number of listed departments");
301   
302     $str = "<img class='center' src='images/select_application.png' 
303               title='".$num_app_str."' alt='".$num_app_str."'>&nbsp;".$num_apps."&nbsp;&nbsp;&nbsp;&nbsp;";
304     $str.= "<img class='center' src='images/folder.png' 
305               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
307     $this->set_List_Bottom_Info($str);
308   }
310   function Save()
311   {
312     MultiSelectWindow::Save();  
313   }
315   function save_object()
316   {
317     /* Save automatic created POSTs like regex, checkboxes */
318     MultiSelectWindow::save_object(); 
319     $_SESSION['appfilter']['release']  = $this->selectedRelease;
320   }
323 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
324 ?>