1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_EventAddUserDialog.inc 9597 2008-03-10 14:16:59Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class EventAddUserDialog extends MultiSelectWindow
24 {
25 public $display_server = TRUE;
26 public $display_workstation = TRUE;
27 public $display_ogroup = TRUE;
28 public $filter_iprange = FALSE;
30 public $regex = "*";
31 public $ipfrom = "0.0.0.0";
32 public $ipto = "*";
33 public $_target_list = array();
35 function __construct(&$config,$parent)
36 {
37 MultiSelectWindow::MultiSelectWindow($config, "EventAddUserDialog",
38 array("users","groups"));
40 $this->parent = $parent;
41 $this->ui = get_userinfo();
44 $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargetUserList","gotomasses");
45 $this->SetSummary(_("Targets"));
46 $this->EnableCloseButton(FALSE);
47 $this->EnableSaveButton(FALSE);
49 $this->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add and use the 'Use' button to accept."));
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 $this->EnableAplhabet(TRUE);
57 /* set Page header */
58 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
59 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
60 $this->AddHeader(array("string"=>_("System / Department")));
62 //$name,$string,$value,$conn,$image="images/lists/search.png")
63 $this->AddRegex("regex" ,"regex" ,"*" , TRUE);
65 $this->AddCheckBox("display_users" ,"1", _("Display users"),TRUE);
66 $this->AddCheckBox("display_groups" ,"1", _("Display groups"),TRUE);
67 }
70 function execute()
71 {
72 $this->ClearElementsList();
73 $this->AddDepartments($this->selectedBase,2,1);
74 $this->setEntries();
75 $this->GenHeader();
76 }
79 function GenHeader()
80 {
81 $modules = array("users","groups");
83 /* Add base */
84 $tmp = array();
85 $base = $this->config->current['BASE'];
86 $tmp[] = array("dn"=>$this->config->current['BASE']);
87 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base,
88 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
90 $deps = array();
91 foreach($tmp as $tm){
92 $deps[$tm['dn']] = $tm['dn'];
93 }
95 $department = $departments = array();
96 $ui= get_userinfo();
97 $d = $ui->get_module_departments($modules);
98 foreach($d as $department){
99 $departments[$department] = $department;
100 }
102 /* Load possible departments */
103 $ids = $this->config->idepartments;
104 $first = "";
105 $found = FALSE;
106 $options = array();
107 foreach($ids as $dep => $name){
108 if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
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 $listhead = $this->get_default_header();
129 /* Add base selection */
130 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
131 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
132 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
134 $this->SetListHeader($listhead);
136 }
139 function setEntries()
140 {
141 $_target_list = array();
143 if($this->display_users){
144 $_target_list = array_merge($_target_list,
145 get_sub_list("(&(objectClass=person)(objectClass=gosaAccount))","users",get_people_ou(),get_people_ou().$this->selectedBase,
146 array("cn","objectClass","description","uid"),GL_NONE));
147 }
148 if($this->display_groups){
149 $_target_list = array_merge($_target_list,
150 get_sub_list("(objectClass=posixGroup)","groups",get_groups_ou(),get_groups_ou().$this->selectedBase,
151 array("cn","objectClass","description"),GL_NONE));
152 }
153 $this->_target_list = $_target_list;
155 $tmp = array();
156 foreach($this->_target_list as $key => $object){
157 $tmp[$key] = $object['cn'][0];
158 }
159 natcasesort($tmp);
161 foreach($tmp as $key => $obj){
163 $obj = $this->_target_list[$key];
164 $name = $obj['cn'][0];
165 if(isset($obj['description'])){
166 $name .= " [".$obj['description'][0]."]";
167 }
169 $img ="";
170 if(in_array("gosaAccount",$obj['objectClass'])){
171 $img = '<img class="center" src="plugins/users/images/select_user.png" alt="U" title="'._("User").'">';
172 }elseif(in_array("posixGroup",$obj['objectClass'])){
173 $img = '<img class="center" src="plugins/groups/images/groups.png" alt="G" title="'._("Group").'">';
174 }
176 $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>",
177 "attach" => "style='width:20px;'");
178 $field2 = array("string" => $img,
179 "attach" => "style='width:20px;'");
180 $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'");
181 $this->AddElement(array($field1,$field2,$field3));
182 }
183 }
186 function get_selected_targets()
187 {
188 $a_targets = array("USERS" => array(),"GROUPS" => array());
190 foreach($this->list_get_selected_items() as $id){
191 $obj = $this->_target_list[$id];
192 if(in_array("posixGroup",$obj['objectClass'])){
193 $a_targets['GROUPS'][] = $obj['cn'][0];
194 }
195 if(in_array("gosaAccount",$obj['objectClass'])){
196 $a_targets['USERS'][] = $obj['uid'][0];
197 }
198 }
200 return($a_targets);
201 }
204 /*! \brief Returns a set of elements selected in a MultiSelectWindow
205 @return Array[integer]=integer
206 */
207 protected function list_get_selected_items()
208 {
209 $ids = array();
210 foreach($_POST as $name => $value){
211 if(preg_match("/^item_selected_[0-9]*$/",$name)){
212 $id = preg_replace("/^item_selected_/","",$name);
213 $ids[$id] = $id;
214 }
215 }
216 return($ids);
217 }
218 }
219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
220 ?>