Code

Added some gpi stuff, not complete,
[gosa.git] / plugins / admin / systems / class_glpiSelectUser.inc
1 <?php
3 class glpiSelectUser extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account= TRUE;
12   var $attributes= array();
13   var $objectclasses= array("whatever");
15   var $users = array();
16   var $departments = array();
18   var $ui;
20   function glpiSelectUser ($config, $dn= NULL)
21   {
22     plugin::plugin ($config, $dn);
24     if(!isset($_SESSION['glpi_user_filter'])){
25       $tmp['users_regex'] = "*";
26       $tmp['base']       = $this->config->current['BASE'];
27       $_SESSION['glpi_user_filter'] = $tmp;
28     }
30     $this->ui = get_userinfo();  
31   }
33   function execute()
34   {
35     /* Call parent execute */
36     plugin::execute();
38     $filter = $_SESSION['glpi_user_filter'];
40     $s_action="";
42     /* Test Posts */
43     foreach($_POST as $key => $val){
44       // Post for delete
45       if(preg_match("/dep_back.*/i",$key)){
46         $s_action="back";
47       }elseif(preg_match("/user_new.*/",$key)){
48         $s_action="new";
49       }elseif(preg_match("/dep_home.*/i",$key)){
50         $s_action="home";
51       }
52     }
54     /* Homebutton is posted */
55     if($s_action=="home"){
56       $filter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
57       $filter['base']=(preg_replace("/^[^,]+,/","",$filter['base']));
58     }
60     if($s_action=="root"){
61       $filter['base']=($this->config->current['BASE']);
62     }
65     /* If Backbutton is Posted */
66     if($s_action=="back"){
67       $base_back          = preg_replace("/^[^,]+,/","",$filter['base']);
68       $base_back          = convert_department_dn($base_back);
70       if(isset($this->config->departments[trim($base_back)])){
71         $filter['base']= $this->config->departments[trim($base_back)];
72       }else{
73         $filter['base']= $this->config->departments["/"];
74       }
75     }
77     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
78       $entry = base64_decode($_GET['dep_id']);
79       $filter['base']= ($this->config->departments[$entry]); 
80     }    
82     $_SESSION['glpi_user_filter'] = $filter;
84     $this->reload();
86     /* Fill templating stuff */
87     $smarty= get_smarty();
88     $display= "";
90     $divlist = new divlist("glpi users");
91     $divlist->SetEntriesPerPage(0);
92     $divlist->SetHeader(array(
93           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
94           array("string" => _("Users")." / "._("Departments"), "attach" => "style=''"),
95           array("string" => _("Use"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
96     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
97     foreach($this->departments as $key=> $val){
99       if(!isset($this->config->departments[trim($key)])){
100         $this->config->departments[trim($key)]="";
101       }
103       $non_empty="";
104       $keys= str_replace("/","\/",$key);
105       foreach($this->config->departments as $keyd=>$vald ){
106         if(preg_match("/".$keys."\/.*/",$keyd)){
107           $non_empty="full";
108         }
109       }
111       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
112       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
113       $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
114       $divlist->AddEntry(array($field1,$field2,$field3));
115     }
117     $useruse = "<a href='?plug=".$_GET['plug']."&amp;act=user_tech_num&amp;id=%s'>%s</a>";
118     
119     foreach($this->users as $key=>$user){
120       $field1 = array("string" => "<img src='images/select_user.png' alt='user'>", "attach" => "style='text-align:center;width:20px;'");
121       $field2 = array("string" => sprintf($useruse,base64_encode($key),$user), "attach" => "style=''");
122       $field3 = array("string" => sprintf($useruse,base64_encode($key),"<img border=0 src='images/crossref.png' alt='"._("use")."'>"), 
123         "attach" => "style='width:60px;border-right:0px;text-align:right;'");
124       $divlist->AddEntry(array($field1,$field2,$field3));
125       
126     }
136     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
137       " <input class='center' type='image' align='middle' 
138       src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
139       " <input class='center' type='image' src='images/list_root.png' 
140       align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
141       " <input class='center' type='image' align='middle' 
142       src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
143       "</div>";
146     $filter= $_SESSION['glpi_user_filter'];
147     $smarty->assign("usershead", $listhead);
148     $smarty->assign("users", $divlist->DrawList());
149     $smarty->assign("search_image", get_template_path('images/search.png'));
150     $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
151     $smarty->assign("tree_image", get_template_path('images/tree.png'));
152     $smarty->assign("infoimage", get_template_path('images/info.png'));
153     $smarty->assign("launchimage", get_template_path('images/launch.png'));
154     $smarty->assign("apply", apply_filter());
155     $smarty->assign("alphabet", generate_alphabet());
156     $smarty->assign("users_regex", $filter['users_regex']);
159     $display.= $smarty->fetch(get_template_path('glpiSelectUser.tpl', TRUE));
160     return($display);
161   }
163   /* Save to LDAP */
164   function save()
165   {
166     plugin::save();
168     /* Optionally execute a command after we're done */
169 #$this->handle_post_events($mode);
170   }
172   function reload()
173   {
175     $filter= $_SESSION['glpi_user_filter'];
177     $base = $filter['base'];
178     $regex= $filter['users_regex'];
179     /* NEW LIST MANAGMENT
180      * We also need to search for the departments
181      * So we are able to navigate like in konquerer
182      */
184     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
185         TRUE, $base, array("ou", "description"), TRUE);
187     $this->departments= array();
188     $tmp = array();
189     foreach ($res3 as $value){
190       $tmp[strtolower($value['dn']).$value['dn']]=$value;
191     }
192     ksort($tmp);
193     foreach($tmp as $value){
194       if(isset($value["description"][0])){
195         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
196       }else{
197         $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
198       }
199     }
201     /* END NEW LIST MANAGMENT
202      */
203     $ou = get_people_ou();
204     $res2 = get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(sn=$regex))(objectClass=person))",
205         TRUE,$ou.$base, array("cn","sn","uid","givenName", "description"), TRUE);
207     $tmp = array();
209     foreach($res2 as $val){
210       $str = "";
211       if(isset($val['givenName'][0])){
212         $str .= $val['givenName'][0];
213       }
214       if(isset($val['sn'][0])){
215         $str .= $val['sn'][0];
216       }
217       if(isset($val['uid'][0])){
218         $str .= $val['uid'][0];
219       }
221       $tmp[$str] = $val;
222     }
224     ksort($tmp);
225     $this->users = array();
226     foreach($tmp as $value){
227       if (isset($value["givenName"][0]) && isset($value["sn"][0])){
228         $this->users[$value['dn']]= $value["sn"][0].", ".
229           $value["givenName"][0].
230           " [".$value["uid"][0]."]";
231       } else {
232         $this->users[$value["dn"]]= "[".$value["uid"][0]."]";
233       }
234     }
235   }
239 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
240 ?>