1 <?php
3 class opengwAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "Opengroupware account";
7 var $plDescription = "This does something";
9 /* attribute list for save action */
10 var $attributes = array();
11 var $objectclasses = array();
13 var $SetPassword = false;
15 /* Attribute mapping opengroupware->ldap */
16 var $attrsToUse = array( "salutation" =>"vocation",
17 "name" =>"sn",
18 "firstname" =>"givenName",
19 "login" =>"uid",
20 "degree" =>"academicTitle",
21 "birthday" =>"dateOfBirth",
22 "sex" =>"gender",
23 "street" =>"street",
24 "zip" =>"postalCode",
25 "value_string"=>"mail",
26 "number" =>"telephoneNumber"
27 );
29 var $serverCon = false;
30 var $handle = NULL;
31 var $is_account = false;
32 var $initialy_was_account = false;
33 var $OGWPassword = "";
34 var $ReadOnly = false;
36 function opengwAccount ($config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
40 $this->info=array();
42 /* is no account and was no account */
43 $this->initialy_was_account = false;
44 $this->is_account = false;
46 /* check if datebase funktions are available, and if database configurations are available */
47 if(is_callable("pg_connect")){
49 /* Get configurations */
50 if(search_config($this->config->data,"opengwAccount","USERNAME")){
51 $atr = array();
52 $atr['LOGIN'] = search_config($this->config->data,"opengwAccount","USERNAME");
53 $atr['PASSWORD']= search_config($this->config->data,"opengwAccount","PASSWORD");
54 $atr['SERVER'] = search_config($this->config->data,"opengwAccount","DATAHOST");
55 $atr['DB'] = search_config($this->config->data,"opengwAccount","DATABASE");
56 $this->serverCon = $atr;
57 }else{
58 $this->serverCon = $this->config->data['SERVERS']['OPENGROUPWARE'];
59 }
60 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
62 /* Check if current configuration allows database connection */
63 if($this->handle->connected){
65 /* Set login name, to check if this is_account */
66 if(isset($this->attrs['uid'][0])){
67 $this->handle->info['login'] = $this->attrs['uid'][0];
68 }else{
69 $this->handle->info['login'] = "";
70 }
72 /* If this is account get data from database first */
73 if($this->handle->CheckExistence()){
74 $this->info = $this->handle->GetInfos($this->attrs['uid'][0]);
76 /* This is an account */
77 $this->initialy_was_account = true;
78 $this->is_account= true;
79 }else{
80 /* this is no account */
81 $this->initialy_was_account = false;
82 $this->is_account= false;
84 /* Selectable in GOsa */
85 $this->info['template_user_id'] = 0;
86 $this->info['is_locked'] = 0;
87 $this->info['LocationTeamID'] = 0;
88 $this->info['TeamIDis'] = array();
89 }
91 /* Set settings from ldap */
92 foreach($this->attrsToUse as $name=>$attr){
93 if(isset($this->attrs[$attr][0])){
94 $this->info[$name] = $this->attrs[$attr][0];
95 }else{
96 $this->info[$name] = false;
97 }
98 }
100 /* Description is displayed as 'Nickname' */
101 $this->info['description'] = $this->info['login'];
103 if($this->info['sex'] == "F"){
104 $this->info['sex'] = "female";
105 }else{
106 $this->info['sex'] = "male";
107 }
109 }
111 /* Transmit data back to ogw handle */
112 $this->handle->SetInfos($this->info);
113 }
114 }
116 function execute()
117 {
118 /* Show tab dialog headers */
119 $display= "";
120 $smarty= get_smarty();
122 /* set default values */
123 $tmp = $this->plInfo();
124 foreach($tmp['plProvidedAcls'] as $acl => $desc){
125 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
126 }
128 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
129 $smarty->assign('opengwAccountACL', "");
130 }else{
131 $smarty->assign('opengwAccountACL', " 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 /* Assign LocationTeams */
153 $tmp = array(""=>"none");
154 foreach($this->handle->validLocationTeam as $id){
155 $tmp[$id['company_id']] = $id['description'];
156 }
157 $smarty->assign("validLocationTeam",$tmp);
158 $smarty->assign("validLocationTeams",array_flip($tmp));
159 $smarty->assign("LocationTeam",$this->info['LocationTeamID']);
161 /* Assign TemplateUsers*/
162 $tmp = array();
163 foreach($this->handle->validTemplateUser as $id){
164 $tmp[$id['company_id']] = $id['name'];
165 }
166 $smarty->assign("validTemplateUser",$tmp);
167 $smarty->assign("validTemplateUsers",array_flip($tmp));
168 $smarty->assign("TemplateUser",$this->info['template_user_id']);
170 /* Create Team membership */
171 $str = "";
172 if(($this->is_account)==""){
173 $dis = "";
174 }else{
175 $dis = " disabled ";
176 }
178 if($this->acl_is_readable("Teams")){
179 foreach($this->handle->validTeams as $id){
180 if(in_array($id['company_id'],$this->info['TeamIDis'])){
181 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
182 checked name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
183 }else{
184 $str .= "<input ".$dis." type='checkbox' value='".$id['company_id']."'
185 name='team_".base64_encode($id['description'])."'>".$id['description']."<br>";
186 }
187 }
188 }
189 $smarty->assign("validTeams",$str);
191 /* Assign ogw checkbox */
192 if($this->is_account){
193 $smarty->assign("OGWstate","");
194 $smarty->assign("is_account", " checked ");
195 }else{
196 $smarty->assign("is_account", " ");
197 $smarty->assign("OGWstate"," disabled ");
198 }
200 /* Assign lock status */
201 if($this->info['is_locked']){
202 $smarty->assign("is_lockedCHK", " checked ");
203 }else{
204 $smarty->assign("is_lockedCHK", " ");
205 }
206 $smarty->assign("is_locked", $this->info['is_locked']);
208 }
209 }
210 $display.= $smarty->fetch (get_template_path('opengw.tpl', TRUE, dirname(__FILE__)));
211 return ($display);
212 }
214 function remove_from_parent()
215 {
216 /* remove database entries */
217 if($this->initialy_was_account){
218 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
219 $this->handle->SetInfos($this->info);
220 $this->handle->Perform("REMOVE");
221 }
222 }
225 /* Save data to object */
226 function save_object()
227 {
228 /* get post data */
229 if($this->is_account){
231 /* Get selected team chkboxes */
232 $this->info['TeamIDis'] = array();
233 if($this->acl_is_writeable("Teams")) {
234 foreach($_POST as $name => $value ){
235 if(preg_match("/team_/i",$name)){
236 if(!in_array($value,$this->info['TeamIDis'])){
237 $this->info['TeamIDis'][]=$value;
238 }
239 }
240 }
241 }
244 /* Get location Team*/
245 if(isset($_POST['LocationTeam']) && $this->acl_is_writeable("LocationTeam")){
246 $this->info['LocationTeamID'] = $_POST['LocationTeam'];
247 }
249 /* Get template user */
250 if(isset($_POST['TemplateUser']) && $this->acl_is_writeable("TemplateUser") ){
251 $this->info['template_user_id'] = $_POST['TemplateUser'];
252 }
254 /* get lock status */
255 if($this->acl_is_writeable("Locked")){
256 if(isset($_POST['is_locked'])){
257 $this->info['is_locked'] = $_POST['is_locked'];
258 }else{
259 $this->info['is_locked'] = 0;
260 }
261 }
262 }
264 /* change account status */
265 if(isset($_POST['is_account'])){
266 if($this->acl_is_createable()){
267 $this->is_account = $_POST['is_account'];
268 }
269 }else{
270 if($this->acl_is_removeable()){
271 $this->is_account = false;//$_POST['is_account'];
272 }
273 }
274 }
277 /* Save to LDAP */
278 function save()
279 {
280 /* Save data */
281 $this->handle = new ogw($this->serverCon['LOGIN'],$this->serverCon['PASSWORD'],$this->serverCon['SERVER'],$this->serverCon['DB']);
282 $this->handle->SetInfos($this->info);
283 $this->handle->checkInfos();
284 if($this->initialy_was_account){
285 $this->handle->Perform("EDIT");
286 }else{
287 $this->handle->Perform("ADD");
288 }
289 }
292 function PrepareForCopyPaste($src){
293 // Nothing to do, because this object can't be copied ... yet
294 }
297 /* Return plugin informations for acl handling
298 #FIXME This is only an enable/disable checkbox for this account, there is possibly a better solution available later */
299 function plInfo()
300 {
301 return (array(
302 "plShortName" => _("Opengroupware"),
303 "plDescription" => _("Open groupware account settings"),
304 "plSelfModify" => TRUE,
305 "plDepends" => array("user"),
306 "plPriority" => 3, // Position in tabs
307 "plSection" => "personal", // This belongs to personal
308 "plCategory" => array("users"),
309 "plOptions" => array(),
311 "plProvidedAcls" => array(
312 "LocationTeam" => _("Location team"),
313 "TemplateUser" => _("Template user"),
314 "Locked" => _("Locked"),
315 "Teams" => _("Teams"))
316 ));
317 }
318 }
319 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
320 ?>