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