[2] | 1 | <?php |
---|
| 2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
| 3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 4 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
| 5 | |
---|
| 6 | class db_functions |
---|
| 7 | { |
---|
| 8 | var $db; |
---|
| 9 | var $user_id; |
---|
| 10 | |
---|
[64] | 11 | function db_functions() |
---|
| 12 | { |
---|
[13] | 13 | if (is_array($_SESSION['phpgw_info']['expresso']['server'])) |
---|
| 14 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; |
---|
| 15 | else |
---|
| 16 | $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server']; |
---|
| 17 | |
---|
[2] | 18 | $this->db = new db(); |
---|
| 19 | $this->db->Halt_On_Error = 'no'; |
---|
[597] | 20 | |
---|
[2] | 21 | $this->db->connect( |
---|
| 22 | $_SESSION['phpgw_info']['expresso']['server']['db_name'], |
---|
| 23 | $_SESSION['phpgw_info']['expresso']['server']['db_host'], |
---|
| 24 | $_SESSION['phpgw_info']['expresso']['server']['db_port'], |
---|
| 25 | $_SESSION['phpgw_info']['expresso']['server']['db_user'], |
---|
| 26 | $_SESSION['phpgw_info']['expresso']['server']['db_pass'], |
---|
| 27 | $_SESSION['phpgw_info']['expresso']['server']['db_type'] |
---|
| 28 | ); |
---|
[597] | 29 | $this->user_id = $_SESSION['phpgw_info']['expresso']['user']['account_id']; |
---|
[2] | 30 | } |
---|
| 31 | |
---|
| 32 | // BEGIN of functions. |
---|
| 33 | function read_acl($account_lid) |
---|
| 34 | { |
---|
| 35 | $query = "SELECT * FROM phpgw_expressoadmin WHERE manager_lid = '" . $account_lid . "'"; |
---|
| 36 | $this->db->query($query); |
---|
| 37 | while($this->db->next_record()) |
---|
| 38 | $result[] = $this->db->row(); |
---|
| 39 | return $result; |
---|
| 40 | } |
---|
[1516] | 41 | |
---|
| 42 | //returns true if cotas control property is set. |
---|
| 43 | function use_cota_control() { |
---|
| 44 | $query = "select * from phpgw_config where config_name='expressoAdmin_cotasOu' and config_value='true'"; |
---|
| 45 | $this->db->query($query); |
---|
| 46 | if($this->db->next_record()) |
---|
| 47 | return true; |
---|
| 48 | return false; |
---|
| 49 | } |
---|
| 50 | |
---|
[597] | 51 | /* |
---|
[548] | 52 | * Reativa os usuários desabilitados por tempo inativo modificando o seu ultimo acesso para o dia atual. |
---|
| 53 | */ |
---|
[597] | 54 | function reactivate_inactive_user($uidNumber) { |
---|
[548] | 55 | |
---|
| 56 | $sql = "select * from phpgw_access_log where account_id=$uidNumber order by li desc limit 1"; |
---|
| 57 | |
---|
| 58 | $this->db->query($sql); |
---|
| 59 | $this->db->next_record(); |
---|
| 60 | $linha = $this->db->row(); |
---|
| 61 | if(count($linha)>0) { |
---|
| 62 | $sql = "insert into phpgw_access_log (sessionid,loginid,ip,li,lo,account_id) values ('expirescontrol','".$linha["loginid"]."','0.0.0.0','".time()."','0','".$linha["account_id"]."')"; |
---|
| 63 | |
---|
| 64 | $this->db->query($sql); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
[597] | 68 | function insert_log_inactive_user_control($uid,$uidNumber) { |
---|
[548] | 69 | $sql = "insert into phpgw_access_log (sessionid,loginid,ip,li,lo,account_id) values ('expirescontrol','".$uid."','0.0.0.0','".time()."','0','".$uidNumber."')"; |
---|
| 70 | |
---|
| 71 | $this->db->query($sql); |
---|
| 72 | } |
---|
| 73 | |
---|
[64] | 74 | function copy_manager($params) |
---|
[2] | 75 | { |
---|
[64] | 76 | $manager = $params['manager']; |
---|
| 77 | $new_manager = $params['new_manager']; |
---|
| 78 | $manager_info = $this->read_acl($manager); |
---|
[2] | 79 | |
---|
[64] | 80 | //Escrevre no Banco a ACL do gerente |
---|
| 81 | $sql = "INSERT INTO phpgw_expressoadmin (manager_lid, context, acl) " |
---|
| 82 | . "VALUES('" . $new_manager . "','" . $manager_info[0]['context'] . "','" . $manager_info[0]['acl'] . "')"; |
---|
| 83 | |
---|
| 84 | if (!$this->db->query($sql)) |
---|
| 85 | { |
---|
[493] | 86 | echo lang('error in') . 'copy_manager: ' . pg_last_error(); |
---|
[64] | 87 | return false; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | //Pesquisa no Banco e pega os valores dos apps. |
---|
| 91 | $sql = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $manager_info[0]['manager_lid'] . "' AND context = '" . $manager_info[0]['context'] . "'"; |
---|
| 92 | $this->db->query($sql); |
---|
[2] | 93 | while($this->db->next_record()) |
---|
[64] | 94 | { |
---|
| 95 | $aplications[] = $this->db->row(); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios. |
---|
| 99 | for ($i=0; $i<count($aplications); $i++) |
---|
| 100 | { |
---|
| 101 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
| 102 | . "VALUES('" . $new_manager . "','" . $manager_info[0]['context'] . "','" . $aplications[$i]['app'] . "')"; |
---|
| 103 | if (!$this->db->query($sql)) |
---|
| 104 | { |
---|
[493] | 105 | echo lang('error adding application to new manager') . ': '. pg_last_error(); |
---|
[64] | 106 | return false; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | return true; |
---|
| 110 | } |
---|
[2] | 111 | |
---|
[64] | 112 | function get_next_id($type) |
---|
[2] | 113 | { |
---|
[64] | 114 | $return['status'] = true; |
---|
| 115 | |
---|
| 116 | $current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
| 117 | |
---|
| 118 | if ($current_config['expressoAdmin_nextid_db_host'] != '') |
---|
| 119 | { |
---|
| 120 | $this->db->disconnect(); |
---|
| 121 | $host = $current_config['expressoAdmin_nextid_db_host']; |
---|
| 122 | $port = $current_config['expressoAdmin_nextid_db_port']; |
---|
| 123 | $name = $current_config['expressoAdmin_nextid_db_name']; |
---|
| 124 | $user = $current_config['expressoAdmin_nextid_db_user']; |
---|
| 125 | $pass = $current_config['expressoAdmin_nextid_db_password']; |
---|
| 126 | |
---|
| 127 | $db = new db(); |
---|
| 128 | $db->Halt_On_Error = 'no'; |
---|
| 129 | $db->connect($name, $host, $port, $user, $pass, 'pgsql'); |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | $db = $this->db; |
---|
| 134 | } |
---|
| 135 | |
---|
[2] | 136 | // Busco o ID dos accounts |
---|
[64] | 137 | $query_accounts_nextid = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
| 138 | if (!$db->query($query_accounts_nextid)) |
---|
| 139 | { |
---|
| 140 | $return['status'] = false; |
---|
[493] | 141 | $result['msg'] = lang('Problems running query on DB') . '.'; |
---|
[64] | 142 | $db->disconnect(); |
---|
| 143 | return $return; |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | $accounts_nextid = $db->Query_ID->fields[0]; |
---|
| 148 | } |
---|
[2] | 149 | |
---|
| 150 | // Busco o ID dos groups |
---|
| 151 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
[64] | 152 | if (!$db->query($query_groups)) |
---|
| 153 | { |
---|
| 154 | $return['status'] = false; |
---|
[493] | 155 | $result['msg'] = lang('Problems running query on DB') . '.'; |
---|
[64] | 156 | $db->disconnect(); |
---|
| 157 | return $return; |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | $groups_nextid = $db->Query_ID->fields[0]; |
---|
| 162 | } |
---|
| 163 | |
---|
[597] | 164 | //Retorna o maior dos ID's incrementado de 1 |
---|
[64] | 165 | if ($accounts_nextid >= $groups_nextid) |
---|
| 166 | $id = $accounts_nextid; |
---|
| 167 | else |
---|
| 168 | $id = $groups_nextid; |
---|
| 169 | $return['id'] = (int)($id + 1); |
---|
[2] | 170 | |
---|
[64] | 171 | |
---|
| 172 | // Atualizo o BD |
---|
| 173 | $query_update_id = "UPDATE phpgw_nextid set id = '" . $return['id'] . "' WHERE appname = '" . $type . "'"; |
---|
| 174 | if (!$db->query($query_update_id)) |
---|
| 175 | { |
---|
| 176 | $return['status'] = false; |
---|
[493] | 177 | $result['msg'] = lang('Problems running query on DB') . '.'; |
---|
[2] | 178 | } |
---|
[64] | 179 | $db->disconnect(); |
---|
| 180 | return $return; |
---|
| 181 | } |
---|
[2] | 182 | |
---|
| 183 | function add_user2group($gidnumber, $uidnumber) |
---|
| 184 | { |
---|
| 185 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
| 186 | if (!$this->db->query($query)) |
---|
| 187 | { |
---|
| 188 | $result['status'] = false; |
---|
[493] | 189 | $result['msg'] = lang('Error on function') . " db_functions->add_user2group.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 190 | return $result; |
---|
| 191 | } |
---|
| 192 | while($this->db->next_record()) |
---|
| 193 | $user_in_group[] = $this->db->row(); |
---|
| 194 | |
---|
| 195 | if (count($user_in_group) == 0) |
---|
| 196 | { |
---|
| 197 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 198 | . "VALUES('phpgw_group','" . $gidnumber . "','" . $uidnumber . "','1')"; |
---|
| 199 | if (!$this->db->query($sql)) |
---|
| 200 | { |
---|
| 201 | $result['status'] = false; |
---|
[493] | 202 | $result['msg'] = lang('Error on function') . " db_functions->add_user2group.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 203 | return $result; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | $result['status'] = true; |
---|
| 207 | return $result; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | function remove_user2group($gidnumber, $uidnumber) |
---|
| 211 | { |
---|
| 212 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
| 213 | if (!$this->db->query($query)) |
---|
| 214 | { |
---|
| 215 | $result['status'] = false; |
---|
[493] | 216 | $result['msg'] = lang('Error on function') . " db_functions->remove_user2group.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 217 | return $result; |
---|
| 218 | } |
---|
| 219 | while($this->db->next_record()) |
---|
| 220 | $user_in_group[] = $this->db->row(); |
---|
| 221 | |
---|
| 222 | if (count($user_in_group) > 0) |
---|
| 223 | { |
---|
| 224 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '".$uidnumber."'"; |
---|
| 225 | if (!$this->db->query($sql)) |
---|
| 226 | { |
---|
| 227 | $result['status'] = false; |
---|
[493] | 228 | $result['msg'] = lang('Error on function') . " db_functions->remove_user2group.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 229 | return $result; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | $result['status'] = true; |
---|
| 233 | return $result; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | function add_pref_changepassword($uidnumber) |
---|
| 237 | { |
---|
| 238 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
| 239 | if (!$this->db->query($query)) |
---|
| 240 | { |
---|
| 241 | $result['status'] = false; |
---|
[493] | 242 | $result['msg'] = lang('Error on function') . " db_functions->add_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 243 | return $result; |
---|
| 244 | } |
---|
| 245 | while($this->db->next_record()) |
---|
| 246 | $user_pref_changepassword[] = $this->db->row(); |
---|
| 247 | |
---|
| 248 | if (count($user_pref_changepassword) == 0) |
---|
| 249 | { |
---|
| 250 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 251 | . "VALUES('preferences','changepassword','" . $uidnumber . "','1')"; |
---|
| 252 | if (!$this->db->query($sql)) |
---|
| 253 | { |
---|
| 254 | $result['status'] = false; |
---|
[493] | 255 | $result['msg'] = lang('Error on function') . " db_functions->add_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 256 | return $result; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | $result['status'] = true; |
---|
| 260 | return $result; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | function remove_pref_changepassword($uidnumber) |
---|
| 264 | { |
---|
| 265 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
| 266 | if (!$this->db->query($query)) |
---|
| 267 | { |
---|
| 268 | $result['status'] = false; |
---|
[493] | 269 | $result['msg'] = lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 270 | return $result; |
---|
| 271 | } |
---|
| 272 | while($this->db->next_record()) |
---|
| 273 | $user_pref_changepassword[] = $this->db->row(); |
---|
| 274 | |
---|
| 275 | if (count($user_pref_changepassword) != 0) |
---|
| 276 | { |
---|
| 277 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
| 278 | if (!$this->db->query($sql)) |
---|
| 279 | { |
---|
| 280 | $result['status'] = false; |
---|
[493] | 281 | $result['msg'] = lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 282 | return $result; |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | $result['status'] = true; |
---|
| 286 | return $result; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | function add_id2apps($id, $apps) |
---|
| 290 | { |
---|
| 291 | $result['status'] = true; |
---|
| 292 | if ($apps) |
---|
| 293 | { |
---|
| 294 | foreach($apps as $app => $value) |
---|
| 295 | { |
---|
| 296 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = '".$app."' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
| 297 | if (!$this->db->query($query)) |
---|
| 298 | { |
---|
| 299 | $result['status'] = false; |
---|
[493] | 300 | $result['msg'] = lang('Error on function') . " db_functions->add_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 301 | return $result; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | while($this->db->next_record()) |
---|
| 305 | $user_app[] = $this->db->row(); |
---|
| 306 | |
---|
| 307 | if (count($user_app) == 0) |
---|
| 308 | { |
---|
| 309 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 310 | . "VALUES('".$app."','run','" . $id . "','1')"; |
---|
| 311 | |
---|
| 312 | if (!$this->db->query($sql)) |
---|
| 313 | { |
---|
| 314 | $result['status'] = false; |
---|
[493] | 315 | $result['msg'] = lang('Error on function') . " db_functions->add_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 316 | return $result; |
---|
| 317 | } |
---|
| 318 | else |
---|
| 319 | { |
---|
[414] | 320 | $this->write_log("Added application","$id:$app"); |
---|
[2] | 321 | } |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | return $result; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | function remove_id2apps($id, $apps) |
---|
| 329 | { |
---|
| 330 | $result['status'] = true; |
---|
| 331 | if ($apps) |
---|
| 332 | { |
---|
| 333 | foreach($apps as $app => $value) |
---|
| 334 | { |
---|
| 335 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
| 336 | |
---|
| 337 | if (!$this->db->query($query)) |
---|
| 338 | { |
---|
| 339 | $result['status'] = false; |
---|
[493] | 340 | $result['msg'] = lang('Error on function') . " db_functions->remove_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 341 | return $result; |
---|
| 342 | } |
---|
| 343 | while($this->db->next_record()) |
---|
| 344 | $user_in_group[] = $this->db->row(); |
---|
| 345 | |
---|
| 346 | if (count($user_in_group) > 0) |
---|
| 347 | { |
---|
| 348 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '".$id."'"; |
---|
| 349 | if (!$this->db->query($sql)) |
---|
| 350 | { |
---|
| 351 | $result['status'] = false; |
---|
[493] | 352 | $result['msg'] = lang('Error on function') . " db_functions->remove_id2apps.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 353 | return $result; |
---|
| 354 | } |
---|
| 355 | else |
---|
| 356 | { |
---|
[414] | 357 | $this->write_log("Removed application from id","$id: $app"); |
---|
[2] | 358 | } |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | return $result; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | function get_user_info($uidnumber) |
---|
| 367 | { |
---|
| 368 | // Groups |
---|
| 369 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_account = '".$uidnumber."'"; |
---|
| 370 | $this->db->query($query); |
---|
| 371 | while($this->db->next_record()) |
---|
| 372 | $user_app[] = $this->db->row(); |
---|
| 373 | |
---|
| 374 | for ($i=0; $i<count($user_app); $i++) |
---|
| 375 | $return['groups'][] = $user_app[$i]['acl_location']; |
---|
| 376 | |
---|
| 377 | // ChangePassword |
---|
| 378 | $query = "SELECT acl_rights FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
| 379 | $this->db->query($query); |
---|
| 380 | while($this->db->next_record()) |
---|
| 381 | $changepassword[] = $this->db->row(); |
---|
| 382 | $return['changepassword'] = $changepassword[0]['acl_rights']; |
---|
| 383 | |
---|
| 384 | // Apps |
---|
| 385 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$uidnumber."' AND acl_location = 'run'"; |
---|
| 386 | $this->db->query($query); |
---|
| 387 | while($this->db->next_record()) |
---|
| 388 | $user_apps[] = $this->db->row(); |
---|
| 389 | |
---|
| 390 | if ($user_apps) |
---|
| 391 | { |
---|
| 392 | foreach ($user_apps as $app) |
---|
| 393 | { |
---|
| 394 | $return['apps'][$app['acl_appname']] = '1'; |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | return $return; |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | function get_group_info($gidnumber) |
---|
| 402 | { |
---|
| 403 | // Apps |
---|
| 404 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$gidnumber."' AND acl_location = 'run'"; |
---|
| 405 | $this->db->query($query); |
---|
| 406 | while($this->db->next_record()) |
---|
| 407 | $group_apps[] = $this->db->row(); |
---|
| 408 | |
---|
| 409 | if ($group_apps) |
---|
| 410 | { |
---|
| 411 | foreach ($group_apps as $app) |
---|
| 412 | { |
---|
| 413 | $return['apps'][$app['acl_appname']] = '1'; |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | // Members |
---|
| 418 | $query = "SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "'"; |
---|
| 419 | |
---|
| 420 | $this->db->query($query); |
---|
| 421 | while($this->db->next_record()) |
---|
| 422 | $group_members[] = $this->db->row(); |
---|
| 423 | |
---|
| 424 | if ($group_members) |
---|
| 425 | { |
---|
| 426 | foreach ($group_members as $member) |
---|
| 427 | { |
---|
| 428 | $return['members'][] = $member['acl_account']; |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | else |
---|
| 432 | $return['members'] = array(); |
---|
| 433 | |
---|
[3251] | 434 | // ACL Block Personal Data |
---|
| 435 | $query = "SELECT acl_rights FROM phpgw_acl WHERE acl_location = 'blockpersonaldata' AND acl_account = '" . $gidnumber . "'"; |
---|
| 436 | $this->db->query($query); |
---|
| 437 | if($this->db->next_record()) { |
---|
| 438 | $block_personal_data = $this->db->row(); |
---|
| 439 | $return['acl_block_personal_data'] = $block_personal_data['acl_rights']; |
---|
| 440 | } |
---|
[2] | 441 | return $return; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | function default_user_password_is_set($uid) |
---|
| 445 | { |
---|
| 446 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 447 | $this->db->query($query); |
---|
| 448 | while($this->db->next_record()) |
---|
| 449 | { |
---|
| 450 | $userPassword[] = $this->db->row(); |
---|
| 451 | } |
---|
| 452 | if (count($userPassword) == 0) |
---|
| 453 | return false; |
---|
| 454 | else |
---|
| 455 | return true; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | function set_user_password($uid, $password) |
---|
| 459 | { |
---|
| 460 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 461 | $this->db->query($query); |
---|
| 462 | while($this->db->next_record()) |
---|
| 463 | { |
---|
| 464 | $user[] = $this->db->row(); |
---|
| 465 | } |
---|
| 466 | if (count($user) == 0) |
---|
| 467 | { |
---|
| 468 | $sql = "INSERT INTO phpgw_expressoadmin_passwords (uid, password) VALUES('".$uid."','".$password."')"; |
---|
| 469 | |
---|
| 470 | if (!$this->db->query($sql)) |
---|
| 471 | { |
---|
| 472 | $result['status'] = false; |
---|
[493] | 473 | $result['msg'] = lang('Error on function') . " db_functions->set_user_password.\n" . lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 474 | return $result; |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | return true; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | function get_user_password($uid) |
---|
| 481 | { |
---|
| 482 | $query = "SELECT password FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 483 | $this->db->query($query); |
---|
| 484 | while($this->db->next_record()) |
---|
| 485 | { |
---|
| 486 | $userPassword[] = $this->db->row(); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | if (count($userPassword) == 1) |
---|
| 490 | { |
---|
| 491 | $sql = "DELETE FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 492 | $this->db->query($sql); |
---|
| 493 | return $userPassword[0]['password']; |
---|
| 494 | } |
---|
| 495 | else |
---|
| 496 | return false; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | function delete_user($user_info) |
---|
| 500 | { |
---|
| 501 | // AGENDA |
---|
| 502 | $this->db->query('SELECT cal_id FROM phpgw_cal WHERE owner ='.$user_info['uidnumber']); |
---|
| 503 | while($this->db->next_record()) |
---|
| 504 | { |
---|
| 505 | $ids[] = $this->db->row(); |
---|
| 506 | } |
---|
| 507 | if (count($ids)) |
---|
| 508 | { |
---|
| 509 | foreach($ids as $i => $id) |
---|
| 510 | { |
---|
| 511 | $this->db->query('DELETE FROM phpgw_cal WHERE cal_id='.$id['cal_id']); |
---|
| 512 | $this->db->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id['cal_id']); |
---|
| 513 | $this->db->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$id['cal_id']); |
---|
| 514 | $this->db->query('DELETE FROM phpgw_cal_extra WHERE cal_id='.$id['cal_id']); |
---|
| 515 | } |
---|
| 516 | } |
---|
[507] | 517 | |
---|
| 518 | // CONTATOS pessoais e grupos. |
---|
[2] | 519 | $this->db->query('SELECT id_contact FROM phpgw_cc_contact WHERE id_owner ='.$user_info['uidnumber']); |
---|
| 520 | while($this->db->next_record()) |
---|
| 521 | { |
---|
| 522 | $ids[] = $this->db->row(); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | if (count($ids)) |
---|
| 526 | { |
---|
| 527 | foreach($ids as $i => $id_contact) |
---|
| 528 | { |
---|
| 529 | $this->db->query('SELECT id_connection FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
| 530 | while($this->db->next_record()) |
---|
| 531 | { |
---|
| 532 | $id_conns[] = $this->db->row(); |
---|
| 533 | } |
---|
| 534 | if (count($id_conns)) |
---|
| 535 | { |
---|
| 536 | foreach($id_conns as $j => $id_conn) |
---|
| 537 | { |
---|
| 538 | $this->db->query('DELETE FROM phpgw_cc_connections WHERE id_connection='.$id_conn['id_connection']); |
---|
| 539 | $this->db->query('DELETE FROM phpgw_cc_contact_grps WHERE id_connection='.$id_conn['id_connection']); |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | $this->db->query('SELECT id_address FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
| 544 | while($this->db->next_record()) |
---|
| 545 | { |
---|
| 546 | $id_addresses[] = $$this->db->row(); |
---|
| 547 | } |
---|
| 548 | if (count($id_addresses)) |
---|
| 549 | { |
---|
| 550 | foreach($id_addresses as $j => $id_addrs) |
---|
| 551 | { |
---|
| 552 | $this->db->query('DELETE FROM phpgw_cc_addresses WHERE id_address='.$id_addrs['id_address']); |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | $this->db->query('DELETE FROM phpgw_cc_contact WHERE id_contact='.$id_contact['id_contact']); |
---|
| 556 | $this->db->query('DELETE FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
| 557 | $this->db->query('DELETE FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | $this->db->query('DELETE FROM phpgw_cc_groups WHERE owner='.$user_info['uidnumber']); |
---|
| 561 | |
---|
| 562 | // PREFERENCIAS |
---|
| 563 | $this->db->query('DELETE FROM phpgw_preferences WHERE preference_owner='.$user_info['uidnumber']); |
---|
| 564 | |
---|
| 565 | // ACL |
---|
| 566 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$user_info['uidnumber']); |
---|
| 567 | |
---|
| 568 | // Corrigir |
---|
| 569 | $return['status'] = true; |
---|
| 570 | return $return; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | function delete_group($gidnumber) |
---|
| 574 | { |
---|
| 575 | // ACL |
---|
| 576 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_location='.$gidnumber); |
---|
| 577 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$gidnumber); |
---|
| 578 | |
---|
| 579 | // Corrigir |
---|
| 580 | $return['status'] = true; |
---|
| 581 | return $return; |
---|
| 582 | } |
---|
| 583 | |
---|
[414] | 584 | function write_log($action, $about) |
---|
[2] | 585 | { |
---|
[414] | 586 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) " |
---|
| 587 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')"; |
---|
[586] | 588 | |
---|
| 589 | if (!$this->db->query($sql)) |
---|
| 590 | { |
---|
| 591 | //echo pg_last_error(); |
---|
| 592 | return false; |
---|
[2] | 593 | } |
---|
| 594 | |
---|
[586] | 595 | return true; |
---|
| 596 | } |
---|
| 597 | |
---|
[2] | 598 | function get_sieve_info() |
---|
| 599 | { |
---|
| 600 | $this->db->query('SELECT profileID,imapenablesieve,imapsieveserver,imapsieveport FROM phpgw_emailadmin'); |
---|
| 601 | |
---|
| 602 | $i=0; |
---|
| 603 | while($this->db->next_record()) |
---|
| 604 | { |
---|
| 605 | $serverList[$i]['profileID'] = $this->db->f(0); |
---|
| 606 | $serverList[$i]['imapenablesieve'] = $this->db->f(1); |
---|
| 607 | $serverList[$i]['imapsieveserver'] = $this->db->f(2); |
---|
| 608 | $serverList[$i]['imapsieveport'] = $this->db->f(3); |
---|
| 609 | $i++; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | return $serverList; |
---|
| 613 | } |
---|
[9] | 614 | |
---|
| 615 | function get_apps($account_lid) |
---|
| 616 | { |
---|
| 617 | $this->db->query("SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'"); |
---|
| 618 | |
---|
| 619 | while($this->db->next_record()) |
---|
| 620 | { |
---|
| 621 | $tmp = $this->db->row(); |
---|
| 622 | $availableApps[$tmp['app']] = 'run'; |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | return $availableApps; |
---|
| 626 | } |
---|
[27] | 627 | |
---|
| 628 | function get_sambadomains_list() |
---|
| 629 | { |
---|
| 630 | $query = "SELECT * FROM phpgw_expressoadmin_samba ORDER by samba_domain_name ASC"; |
---|
| 631 | $this->db->query($query); |
---|
| 632 | while($this->db->next_record()) |
---|
| 633 | $result[] = $this->db->row(); |
---|
| 634 | return $result; |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | function exist_domain_name_sid($sambadomainname, $sambasid) |
---|
| 638 | { |
---|
| 639 | $query = "SELECT * FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname' OR samba_domain_sid='$sambasid'"; |
---|
| 640 | $this->db->query($query); |
---|
| 641 | while($this->db->next_record()) |
---|
| 642 | $result[] = $this->db->row(); |
---|
| 643 | |
---|
| 644 | if (count($result) > 0) |
---|
| 645 | return true; |
---|
| 646 | else |
---|
| 647 | return false; |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | function delete_sambadomain($sambadomainname) |
---|
| 651 | { |
---|
| 652 | $this->db->query("DELETE FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname'"); |
---|
| 653 | return; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | function add_sambadomain($sambadomainname, $sambasid) |
---|
| 657 | { |
---|
| 658 | $sql = "INSERT INTO phpgw_expressoadmin_samba (samba_domain_name, samba_domain_sid) VALUES('$sambadomainname','$sambasid')"; |
---|
| 659 | $this->db->query($sql); |
---|
| 660 | return; |
---|
| 661 | } |
---|
[64] | 662 | |
---|
| 663 | function test_db_connection($params) |
---|
| 664 | { |
---|
| 665 | $host = $params['host']; |
---|
| 666 | $port = $params['port']; |
---|
| 667 | $name = $params['name']; |
---|
| 668 | $user = $params['user']; |
---|
| 669 | $pass = $params['pass']; |
---|
[597] | 670 | |
---|
[64] | 671 | $con_string = "host=$host port=$port dbname=$name user=$user password=$pass"; |
---|
| 672 | if ($db = pg_connect($con_string)) |
---|
| 673 | { |
---|
| 674 | pg_close($db); |
---|
| 675 | $result['status'] = true; |
---|
| 676 | } |
---|
| 677 | else |
---|
| 678 | { |
---|
| 679 | $result['status'] = false; |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | return $result; |
---|
| 683 | } |
---|
[180] | 684 | |
---|
| 685 | function manager_lid_exist($manager_lid) |
---|
| 686 | { |
---|
| 687 | $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'"; |
---|
| 688 | $this->db->query($query); |
---|
| 689 | while($this->db->next_record()) |
---|
| 690 | $result[] = $this->db->row(); |
---|
| 691 | if (count($result) > 0) |
---|
| 692 | return true; |
---|
| 693 | else |
---|
| 694 | return false; |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | function create_manager($params, $manager_acl) |
---|
| 698 | { |
---|
| 699 | //Escrevre no Banco a ACL do gerente |
---|
| 700 | $sql = "INSERT INTO phpgw_expressoadmin (manager_lid, context, acl) " |
---|
| 701 | . "VALUES('" . $params['ea_select_manager'] . "','" . $params['context'] . "','" . $manager_acl . "')"; |
---|
| 702 | $this->db->query($sql); |
---|
| 703 | |
---|
| 704 | //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios. |
---|
| 705 | if (count($_POST['applications_list'])) |
---|
| 706 | { |
---|
| 707 | foreach($_POST['applications_list'] as $app=>$value) |
---|
| 708 | { |
---|
| 709 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
| 710 | . "VALUES('" . $_POST['manager_lid'] . "','" . $_POST['context'] . "','" . $app . "')"; |
---|
| 711 | $this->db->query($sql); |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | return; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | function save_manager($params, $manager_acl) |
---|
| 719 | { |
---|
| 720 | $params['manager_lid'] = $params['hidden_manager_lid']; |
---|
| 721 | |
---|
| 722 | //Executa update na tabela para atualizar ACL |
---|
| 723 | $sql = "UPDATE phpgw_expressoadmin SET context = '" . $params['context'] . "',acl = '" . $manager_acl |
---|
| 724 | . "' WHERE manager_lid = '" . $params['manager_lid'] ."'"; |
---|
| 725 | $this->db->query($sql); |
---|
| 726 | |
---|
| 727 | //Deleta as aplicações e adiciona as novas. |
---|
| 728 | //Deleta |
---|
| 729 | $sql = "DELETE FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $params['manager_lid'] . "'"; |
---|
| 730 | $this->db->query($sql); |
---|
| 731 | |
---|
| 732 | // Adiciona |
---|
| 733 | if (count($params['applications_list'])) |
---|
| 734 | { |
---|
| 735 | foreach($params['applications_list'] as $app=>$value) |
---|
| 736 | { |
---|
| 737 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
| 738 | . "VALUES('" . $params['manager_lid'] . "','" . $params['context'] . "','" . $app . "')"; |
---|
| 739 | $this->db->query($sql); |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | return; |
---|
| 744 | } |
---|
[3251] | 745 | function save_acl_personal_data($gidnumber, $new_acl_personal_data, $op = '') { |
---|
| 746 | if($op == 'add') |
---|
| 747 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 748 | . "VALUES('preferences','blockpersonaldata','$gidnumber',$new_acl_personal_data)"; |
---|
| 749 | elseif($op == 'remove') |
---|
| 750 | $sql = "DELETE FROM phpgw_acl WHERE acl_account = '$gidnumber' and acl_location = 'blockpersonaldata'"; |
---|
| 751 | else |
---|
| 752 | $sql = "UPDATE phpgw_acl SET acl_rights = $new_acl_personal_data WHERE acl_account = '$gidnumber' " |
---|
| 753 | . "and acl_location = 'blockpersonaldata'"; |
---|
| 754 | |
---|
| 755 | //error_log($sql); |
---|
| 756 | $this->db->query($sql); |
---|
| 757 | |
---|
| 758 | return; |
---|
| 759 | } |
---|
[180] | 760 | |
---|
[2] | 761 | } |
---|
[548] | 762 | ?> |
---|