1 <?php
3 class opengwAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "Opengroupware account";
7 var $plDescription = "This does something";
9 /* CLI vars */
10 var $cli_summary = "Manage users webdav account";
11 var $cli_description = "Some longer text\nfor help";
12 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14 /* attribute list for save action */
15 var $attributes = array();
16 var $objectclasses = array();
18 /* Attribute mapping opengroupware->ldap */
19 var $attrsToUse = array( "salutation" =>"vocation",
20 "name" =>"sn",
21 "firstname" =>"givenName",
22 "login" =>"uid",
23 "degree" =>"academicTitle",
24 "birthday" =>"dateOfBirth",
25 "sex" =>"gender",
26 "street" =>"street",
27 "zip" =>"postalCode",
28 "value_string"=>"mail",
29 "number" =>"telephoneNumber"
30 );
32 var $serverCon = false;
33 var $handle = NULL;
34 var $is_account = false;
35 var $initialy_was_account = false;
37 function opengwAccount ($config, $dn= NULL)
38 {
39 plugin::plugin ($config, $dn);
41 $this->info=array();
43 /* is no account and was no account */
44 $this->initialy_was_account = false;
45 $this->is_account = false;
47 /* check if datebase funktions are available, and if database configurations are available */
48 if(is_callable("pg_connect")){
50 /* Get configurations */
51 if(search_config($this->config->data,"opengwAccount","USERNAME")){
52 $atr = array();
53 $atr['LOGIN'] = search_config($this->config->data,"opengwAccount","USERNAME");
54 $atr['PASSWORD']= search_config($this->config->data,"opengwAccount","PASSWORD");
55 $atr['SERVER'] = search_config($this->config->data,"opengwAccount","DATAHOST");
56 $atr['DB'] = search_config($this->config->data,"opengwAccount","DATABASE");
57 $this->serverCon = $atr;
58 }else{
59 $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
60 }
61 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
63 /* Check if current configuration allows database connection */
64 if($this->handle->connected){
66 /* Set login name, to check if this is_account */
67 if(isset($this->attrs['uid'][0])){
68 $this->handle->info['login'] = $this->attrs['uid'][0];
69 }else{
70 $this->handle->info['login'] = "";
71 }
73 /* If this is account get data from database first */
74 if($this->handle->CheckExistence()){
75 $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
77 /* This is an account */
78 $this->initialy_was_account = true;
79 $this->is_account= true;
80 }else{
81 /* this is no account */
82 $this->initialy_was_account = false;
83 $this->is_account= false;
85 /* Selectable in GOsa */
86 $this->info['template_user_id'] = 0;
87 $this->info['is_locked'] = 0;
88 $this->info['LocationTeamID'] = 0;
89 $this->info['TeamIDis'] = array();
90 }
92 /* Set settings from ldap */
93 foreach($this->attrsToUse as $name=>$attr){
94 if(isset($this->attrs[$attr][0])){
95 $this->info[$name] = $this->attrs[$attr][0];
96 }else{
97 $this->info[$name] = false;
98 }
99 }
101 /* Description is displayed as 'Nickname' */
102 $this->info['description'] = $this->info['login'];
104 if($this->info['sex'] == "F"){
105 $this->info['sex'] = "female";
106 }else{
107 $this->info['sex'] = "male";
108 }
110 }
112 /* Transmit data back to ogw handle */
113 $this->handle->SetInfos($this->info);
114 }
115 }
117 function execute()
118 {
119 /* Show tab dialog headers */
120 $display= "";
121 $smarty= get_smarty();
123 /* set default values */
124 foreach(array("validLocationTeam","validTemplateUser","validLocationTeams","validTemplateUsers") as $ar){
125 $smarty->assign($ar,array());
126 }
127 $smarty->assign("OGWstate"," disabled ");
128 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount","is_account") as $ar){
129 $smarty->assign($ar,"");
130 $smarty->assign($ar."CHK","");
131 $smarty->assign($ar."ACL"," disabled ");
132 }
134 /* Check database extension */
135 if(!is_callable("pg_connect")){
136 print_red(_("OpenGroupware: Your configuration is missing a postgresql extension. Can't perform any database queries."));
137 }else
139 /* Check if config exists */
140 if(search_config($this->config->data,"opengwAccount","DATABASE")==""){
141 print_red(_("OpenGroupware: Missing database configuration for opengroupware. Can't get or set any informations."));
142 }else{
144 /* Create handle */
145 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
147 /* Check if we are successfully connected to db */
148 if(!$this->handle->connected){
149 print_red(_("OpenGroupware: Can't connect to specified database. Please check given configuration twice."));
150 }else{
152 /* Show main page */
153 $smarty->assign("OGWstate"," disabled ");
154 foreach(array("LocationTeam","TemplateUser","is_locked","validTeams","opengwAccount") as $ar){
155 $smarty->assign($ar."ACL",chkacl($this->acl,$ar));
156 }
158 /* Assign LocationTeams */
159 $tmp = array(""=>"none");
160 foreach($this->handle->validLocationTeam as $id){
161 $tmp[$id['company_id']] = $id['description'];
162 }
163 $smarty->assign("validLocationTeam",$tmp);
164 $smarty->assign("validLocationTeams",array_flip($tmp));
165 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
167 /* Assign TemplateUsers*/
168 $tmp = array();
169 foreach($this->handle->validTemplateUser as $id){
170 $tmp[$id['company_id']] = $id['name'];
171 }
172 $smarty->assign("validTemplateUser",$tmp);
173 $smarty->assign("validTemplateUsers",array_flip($tmp));
174 $smarty->assign("TemplateUser",$this->info['template_user_id']);
176 /* Create Team membership */
177 $str = "";
178 if(($this->is_account)&&(chkacl($this->acl,"TeamIDs")=="")){
179 $dis = "";
180 }else{
181 $dis = " disabled ";
182 }
184 foreach($this->handle->validTeams as $id){
185 if(in_array($id['company_id'],$this->info['TeamIDis'])){
186 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
187 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
188 }else{
189 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
190 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
191 }
192 }
193 $smarty->assign("validTeams",$str);
195 /* Assign ogw checkbox */
196 if($this->is_account){
197 $smarty->assign("OGWstate","");
198 $smarty->assign("is_account", " checked ");
199 }else{
200 $smarty->assign("is_account", " ");
201 $smarty->assign("OGWstate"," disabled ");
202 }
204 /* Assign acls */
205 foreach(array("LocationTeam","TemplateUser","Teams","is_locked") as $atr){
206 $smarty->assign($atr."ACL",chkacl($this->acl,$atr));
207 }
209 /* Assign lock status */
210 if($this->info['is_locked']){
211 $smarty->assign("is_lockedCHK", " checked ");
212 }else{
213 $smarty->assign("is_lockedCHK", " ");
214 }
215 $smarty->assign("is_locked", $this->info['is_locked']);
217 }
218 }
219 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
220 return ($display);
221 }
223 function remove_from_parent()
224 {
225 /* remove database entries */
226 if($this->initialy_was_account){
227 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
228 $this->handle->SetInfos($this->info);
229 $this->handle->Perform("REMOVE");
230 }
231 }
234 /* Save data to object */
235 function save_object()
236 {
237 /* get post data */
238 if($this->is_account){
240 /* Get selected team chkboxes */
241 $this->info['TeamIDis'] = array();
242 foreach($_POST as $name => $value ){
243 if(preg_match("/team_/i",$name)){
244 if(!in_array($value,$this->info['TeamIDis'])){
245 $this->info['TeamIDis'][]=$value;
246 }
247 }
248 }
250 /* Get location Team*/
251 if(isset($_POST['LocationTeam'])){
252 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
253 }
255 /* Get template user */
256 if(isset($_POST['TemplateUser'])){
257 $this->info['template_user_id'] = $_POST['TemplateUser'];
258 }
260 /* get lock status */
261 if(isset($_POST['is_locked'])){
262 $this->info['is_locked'] = $_POST['is_locked'];
263 }else{
264 $this->info['is_locked'] = 0;
265 }
266 }
268 /* change account status */
269 if(isset($_POST['is_account'])){
270 $this->is_account = $_POST['is_account'];
271 }else{
272 $this->is_account = false;//$_POST['is_account'];
273 }
275 }
278 /* Save to LDAP */
279 function save()
280 {
281 /* Save data */
282 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
283 $this->handle->SetInfos($this->info);
284 $this->handle->checkInfos();
285 if($this->initialy_was_account){
286 $this->handle->Perform("EDIT");
287 }else{
288 $this->handle->Perform("ADD");
289 }
290 }
292 }
293 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
294 ?>