Code

Update for Trac Ticket #3181
[gosa.git] / trunk / gosa-plugins / goto / addons / goto / events / class_EventTargetAddUsersList.inc
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_EventTargetAddUserList.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 EventTargetAddUserList 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, "EventTargetAddUserList", 
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"=>"&nbsp;","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     $this->AddCheckBox("display_objectgroups" ,"1", _("Display object groups"),TRUE);
68   }
71   function execute()
72   {
73     $this->ClearElementsList();
74     $this->AddDepartments($this->selectedBase,2,1);
75     $this->setEntries();
76     $this->GenHeader();
77   }
80   function GenHeader()
81   {
82     $modules = array("users","groups");
84     /* Add base */
85     $tmp = array();
86     $base = $this->config->current['BASE'];
87     $tmp[] = array("dn"=>$this->config->current['BASE']);
88     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base,
89           array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
91     $deps = array();
92     foreach($tmp as $tm){
93       $deps[$tm['dn']] = $tm['dn'];
94     }
96     $department = $departments = array();
97     $ui= get_userinfo();
98     $d = $ui->get_module_departments($modules);
99     foreach($d as $department){
100       $departments[$department] = $department;
101     }
103     /* Load possible departments */
104     $ids = $this->config->idepartments;
105     $first = "";
106     $found = FALSE;
107     $options = array();
108     foreach($ids as $dep => $name){
109       if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
111         /* Keep first base dn in mind, we could need this
112          *  info if no valid base was found
113          */
114         if(empty($first)) {
115           $first = $dep['dn'];
116         }
118         $value = $ids[$dep];
119         if ($this->selectedBase == $dep){
120           $found = TRUE;
121           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
122         } else {
123           $options.= "<option value='".$dep."'>$value</option>";
124         }
125       }
126     }
128     $listhead = $this->get_default_header();
130     /* Add base selection */
131     $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
132       " <input class='center' type='image' src='images/lists/submit.png' align='middle'
133       title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'>&nbsp;";
135     $this->SetListHeader($listhead);
137   }
140   function setEntries()
141   {
142     $_target_list = array();
144     if($this->display_users){
145       $_target_list = array_merge($_target_list,
146           get_sub_list("(&(objectClass=person)(objectClass=gosaAccount))","users",get_people_ou(),get_people_ou().$this->selectedBase,
147           array("cn","objectClass","description","uid"),GL_NONE));
148     }
149     if($this->display_groups){
150       $_target_list = array_merge($_target_list,
151           get_sub_list("(objectClass=posixGroup)","groups",get_groups_ou(),get_groups_ou().$this->selectedBase,
152             array("cn","objectClass","description"),GL_NONE));
153     }
154     if($this->display_objectgroups){
155       $_target_list = array_merge($_target_list,
156           get_sub_list("(|(gosaGroupObjects=*G*)(gosaGroupObjects=*U*))","groups",get_groups_ou(),get_groups_ou().$this->selectedBase,
157             array("cn", "objectClass", "description"),GL_NONE));
158     }
159     $this->_target_list = $_target_list;
161     $tmp = array();
162     foreach($this->_target_list as $key => $object){
163       $tmp[$key] = $object['cn'][0];
164     }
165     natcasesort($tmp);
167     foreach($tmp as $key => $obj){
169       $obj = $this->_target_list[$key];
170       $name = $obj['cn'][0];
171       if(isset($obj['description'])){
172         $name .= "&nbsp;[".$obj['description'][0]."]";
173       }
175       $img ="";
176       if(in_array("gosaAccount",$obj['objectClass'])){
177         $img = '<img class="center" src="plugins/users/images/select_user.png" alt="U" title="'._("User").'">';
178       }elseif(in_array("posixGroup",$obj['objectClass'])){
179         $img = '<img class="center" src="plugins/groups/images/groups.png" alt="G" title="'._("Group").'">';
180       }elseif(in_array("gosaGroupOfNames", $obj['objectClass'])){
181         $img = '<img class="center" src="plugins/ogroups/images/ogroup.png" alt="O" title="'._("Object group").'">';
182       }
184       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>",
185                       "attach" => "style='width:20px;'");
186       $field2 = array("string" => $img,
187                       "attach" => "style='width:20px;'");
188       $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'");
189       $this->AddElement(array($field1,$field2,$field3));
190     }
191   }
194   function get_selected_targets()
195   {
196     $a_targets = array("USERS" => array(),"GROUPS" => array(), "OBJECTGROUPS" => array());
198     foreach($this->list_get_selected_items() as $id){
199       $obj = $this->_target_list[$id];
200       if(in_array("posixGroup",$obj['objectClass'])){
201         $a_targets['GROUPS'][] = $obj['cn'][0];
202       }
203       if(in_array("gosaAccount",$obj['objectClass'])){
204         $a_targets['USERS'][] = $obj['uid'][0];
205       }
206       if(in_array("gosaGroupOfNames", $obj['objectClass'])){
207         $a_targets['OBJECTGROUPS'][] = $obj['cn'][0];
208       }
209     }
211     return($a_targets);
212   }
215   /*! \brief  Returns a set of elements selected in a MultiSelectWindow
216     @return Array[integer]=integer
217    */
218   protected  function list_get_selected_items()
219   {
220     $ids = array();
221     foreach($_POST as $name => $value){
222       if(preg_match("/^item_selected_[0-9]*$/",$name)){
223         $id   = preg_replace("/^item_selected_/","",$name);
224         $ids[$id] = $id;
225       }
226     }
227     return($ids);
228   }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>