[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; |
---|
[414] | 108 | $result['msg'] = $this->functions->lang('Problems running query on DB') . '.'; |
---|
[64] | 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; |
---|
[414] | 122 | $result['msg'] = $this->functions->lang('Problems running query on DB') . '.'; |
---|
[64] | 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; |
---|
[414] | 144 | $result['msg'] = $this->functions->lang('Problems running query on DB') . '.'; |
---|
[2] | 145 | } |
---|
[64] | 146 | $db->disconnect(); |
---|
| 147 | return $return; |
---|
| 148 | } |
---|
[2] | 149 | |
---|
| 150 | function add_user2group($gidnumber, $uidnumber) |
---|
| 151 | { |
---|
| 152 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
| 153 | if (!$this->db->query($query)) |
---|
| 154 | { |
---|
| 155 | $result['status'] = false; |
---|
[414] | 156 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_user2group.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 157 | return $result; |
---|
| 158 | } |
---|
| 159 | while($this->db->next_record()) |
---|
| 160 | $user_in_group[] = $this->db->row(); |
---|
| 161 | |
---|
| 162 | if (count($user_in_group) == 0) |
---|
| 163 | { |
---|
| 164 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 165 | . "VALUES('phpgw_group','" . $gidnumber . "','" . $uidnumber . "','1')"; |
---|
| 166 | if (!$this->db->query($sql)) |
---|
| 167 | { |
---|
| 168 | $result['status'] = false; |
---|
[414] | 169 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_user2group.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 170 | return $result; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | $result['status'] = true; |
---|
| 174 | return $result; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | function remove_user2group($gidnumber, $uidnumber) |
---|
| 178 | { |
---|
| 179 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '" . $uidnumber . "'"; |
---|
| 180 | if (!$this->db->query($query)) |
---|
| 181 | { |
---|
| 182 | $result['status'] = false; |
---|
[414] | 183 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_user2group.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 184 | return $result; |
---|
| 185 | } |
---|
| 186 | while($this->db->next_record()) |
---|
| 187 | $user_in_group[] = $this->db->row(); |
---|
| 188 | |
---|
| 189 | if (count($user_in_group) > 0) |
---|
| 190 | { |
---|
| 191 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "' AND acl_account = '".$uidnumber."'"; |
---|
| 192 | if (!$this->db->query($sql)) |
---|
| 193 | { |
---|
| 194 | $result['status'] = false; |
---|
[414] | 195 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_user2group.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 196 | return $result; |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | $result['status'] = true; |
---|
| 200 | return $result; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | function add_pref_changepassword($uidnumber) |
---|
| 204 | { |
---|
| 205 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
| 206 | if (!$this->db->query($query)) |
---|
| 207 | { |
---|
| 208 | $result['status'] = false; |
---|
[414] | 209 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_pref_changepassword.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 210 | return $result; |
---|
| 211 | } |
---|
| 212 | while($this->db->next_record()) |
---|
| 213 | $user_pref_changepassword[] = $this->db->row(); |
---|
| 214 | |
---|
| 215 | if (count($user_pref_changepassword) == 0) |
---|
| 216 | { |
---|
| 217 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 218 | . "VALUES('preferences','changepassword','" . $uidnumber . "','1')"; |
---|
| 219 | if (!$this->db->query($sql)) |
---|
| 220 | { |
---|
| 221 | $result['status'] = false; |
---|
[414] | 222 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_pref_changepassword.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 223 | return $result; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | $result['status'] = true; |
---|
| 227 | return $result; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | function remove_pref_changepassword($uidnumber) |
---|
| 231 | { |
---|
| 232 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '" . $uidnumber . "'"; |
---|
| 233 | if (!$this->db->query($query)) |
---|
| 234 | { |
---|
| 235 | $result['status'] = false; |
---|
[414] | 236 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 237 | return $result; |
---|
| 238 | } |
---|
| 239 | while($this->db->next_record()) |
---|
| 240 | $user_pref_changepassword[] = $this->db->row(); |
---|
| 241 | |
---|
| 242 | if (count($user_pref_changepassword) != 0) |
---|
| 243 | { |
---|
| 244 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
| 245 | if (!$this->db->query($sql)) |
---|
| 246 | { |
---|
| 247 | $result['status'] = false; |
---|
[414] | 248 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_pref_changepassword.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 249 | return $result; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | $result['status'] = true; |
---|
| 253 | return $result; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | function add_id2apps($id, $apps) |
---|
| 257 | { |
---|
| 258 | $result['status'] = true; |
---|
| 259 | if ($apps) |
---|
| 260 | { |
---|
| 261 | foreach($apps as $app => $value) |
---|
| 262 | { |
---|
| 263 | $query = "SELECT * FROM phpgw_acl WHERE acl_appname = '".$app."' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
| 264 | if (!$this->db->query($query)) |
---|
| 265 | { |
---|
| 266 | $result['status'] = false; |
---|
[414] | 267 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_id2apps.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 268 | return $result; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | while($this->db->next_record()) |
---|
| 272 | $user_app[] = $this->db->row(); |
---|
| 273 | |
---|
| 274 | if (count($user_app) == 0) |
---|
| 275 | { |
---|
| 276 | $sql = "INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) " |
---|
| 277 | . "VALUES('".$app."','run','" . $id . "','1')"; |
---|
| 278 | |
---|
| 279 | if (!$this->db->query($sql)) |
---|
| 280 | { |
---|
| 281 | $result['status'] = false; |
---|
[414] | 282 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->add_id2apps.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 283 | return $result; |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
[414] | 287 | $this->write_log("Added application","$id:$app"); |
---|
[2] | 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | return $result; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | function remove_id2apps($id, $apps) |
---|
| 296 | { |
---|
| 297 | $result['status'] = true; |
---|
| 298 | if ($apps) |
---|
| 299 | { |
---|
| 300 | foreach($apps as $app => $value) |
---|
| 301 | { |
---|
| 302 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '" . $id . "'"; |
---|
| 303 | |
---|
| 304 | if (!$this->db->query($query)) |
---|
| 305 | { |
---|
| 306 | $result['status'] = false; |
---|
[414] | 307 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_id2apps.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 308 | return $result; |
---|
| 309 | } |
---|
| 310 | while($this->db->next_record()) |
---|
| 311 | $user_in_group[] = $this->db->row(); |
---|
| 312 | |
---|
| 313 | if (count($user_in_group) > 0) |
---|
| 314 | { |
---|
| 315 | $sql = "DELETE FROM phpgw_acl WHERE acl_appname = '" . $app . "' AND acl_location = 'run' AND acl_account = '".$id."'"; |
---|
| 316 | if (!$this->db->query($sql)) |
---|
| 317 | { |
---|
| 318 | $result['status'] = false; |
---|
[414] | 319 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->remove_id2apps.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 320 | return $result; |
---|
| 321 | } |
---|
| 322 | else |
---|
| 323 | { |
---|
[414] | 324 | $this->write_log("Removed application from id","$id: $app"); |
---|
[2] | 325 | } |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | } |
---|
| 329 | return $result; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | |
---|
| 333 | function get_user_info($uidnumber) |
---|
| 334 | { |
---|
| 335 | // Groups |
---|
| 336 | $query = "SELECT acl_location FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_account = '".$uidnumber."'"; |
---|
| 337 | $this->db->query($query); |
---|
| 338 | while($this->db->next_record()) |
---|
| 339 | $user_app[] = $this->db->row(); |
---|
| 340 | |
---|
| 341 | for ($i=0; $i<count($user_app); $i++) |
---|
| 342 | $return['groups'][] = $user_app[$i]['acl_location']; |
---|
| 343 | |
---|
| 344 | // ChangePassword |
---|
| 345 | $query = "SELECT acl_rights FROM phpgw_acl WHERE acl_appname = 'preferences' AND acl_location = 'changepassword' AND acl_account = '".$uidnumber."'"; |
---|
| 346 | $this->db->query($query); |
---|
| 347 | while($this->db->next_record()) |
---|
| 348 | $changepassword[] = $this->db->row(); |
---|
| 349 | $return['changepassword'] = $changepassword[0]['acl_rights']; |
---|
| 350 | |
---|
| 351 | // Apps |
---|
| 352 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$uidnumber."' AND acl_location = 'run'"; |
---|
| 353 | $this->db->query($query); |
---|
| 354 | while($this->db->next_record()) |
---|
| 355 | $user_apps[] = $this->db->row(); |
---|
| 356 | |
---|
| 357 | if ($user_apps) |
---|
| 358 | { |
---|
| 359 | foreach ($user_apps as $app) |
---|
| 360 | { |
---|
| 361 | $return['apps'][$app['acl_appname']] = '1'; |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | return $return; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | function get_group_info($gidnumber) |
---|
| 369 | { |
---|
| 370 | // Apps |
---|
| 371 | $query = "SELECT acl_appname FROM phpgw_acl WHERE acl_account = '".$gidnumber."' AND acl_location = 'run'"; |
---|
| 372 | $this->db->query($query); |
---|
| 373 | while($this->db->next_record()) |
---|
| 374 | $group_apps[] = $this->db->row(); |
---|
| 375 | |
---|
| 376 | if ($group_apps) |
---|
| 377 | { |
---|
| 378 | foreach ($group_apps as $app) |
---|
| 379 | { |
---|
| 380 | $return['apps'][$app['acl_appname']] = '1'; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | // Members |
---|
| 385 | $query = "SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'phpgw_group' AND acl_location = '" . $gidnumber . "'"; |
---|
| 386 | |
---|
| 387 | $this->db->query($query); |
---|
| 388 | while($this->db->next_record()) |
---|
| 389 | $group_members[] = $this->db->row(); |
---|
| 390 | |
---|
| 391 | if ($group_members) |
---|
| 392 | { |
---|
| 393 | foreach ($group_members as $member) |
---|
| 394 | { |
---|
| 395 | $return['members'][] = $member['acl_account']; |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | else |
---|
| 399 | $return['members'] = array(); |
---|
| 400 | |
---|
| 401 | return $return; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | function default_user_password_is_set($uid) |
---|
| 405 | { |
---|
| 406 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 407 | $this->db->query($query); |
---|
| 408 | while($this->db->next_record()) |
---|
| 409 | { |
---|
| 410 | $userPassword[] = $this->db->row(); |
---|
| 411 | } |
---|
| 412 | if (count($userPassword) == 0) |
---|
| 413 | return false; |
---|
| 414 | else |
---|
| 415 | return true; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | function set_user_password($uid, $password) |
---|
| 419 | { |
---|
| 420 | $query = "SELECT uid FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 421 | $this->db->query($query); |
---|
| 422 | while($this->db->next_record()) |
---|
| 423 | { |
---|
| 424 | $user[] = $this->db->row(); |
---|
| 425 | } |
---|
| 426 | if (count($user) == 0) |
---|
| 427 | { |
---|
| 428 | $sql = "INSERT INTO phpgw_expressoadmin_passwords (uid, password) VALUES('".$uid."','".$password."')"; |
---|
| 429 | |
---|
| 430 | if (!$this->db->query($sql)) |
---|
| 431 | { |
---|
| 432 | $result['status'] = false; |
---|
[414] | 433 | $result['msg'] = $this->functions->lang('Error on function') . " db_functions->set_user_password.\n" . $this->functions->lang('Server returns') . ': ' . pg_last_error(); |
---|
[2] | 434 | return $result; |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | return true; |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | function get_user_password($uid) |
---|
| 441 | { |
---|
| 442 | $query = "SELECT password 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 | |
---|
| 449 | if (count($userPassword) == 1) |
---|
| 450 | { |
---|
| 451 | $sql = "DELETE FROM phpgw_expressoadmin_passwords WHERE uid = '" . $uid . "'"; |
---|
| 452 | $this->db->query($sql); |
---|
| 453 | return $userPassword[0]['password']; |
---|
| 454 | } |
---|
| 455 | else |
---|
| 456 | return false; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | function delete_user($user_info) |
---|
| 460 | { |
---|
| 461 | // AGENDA |
---|
| 462 | $this->db->query('SELECT cal_id FROM phpgw_cal WHERE owner ='.$user_info['uidnumber']); |
---|
| 463 | while($this->db->next_record()) |
---|
| 464 | { |
---|
| 465 | $ids[] = $this->db->row(); |
---|
| 466 | } |
---|
| 467 | if (count($ids)) |
---|
| 468 | { |
---|
| 469 | foreach($ids as $i => $id) |
---|
| 470 | { |
---|
| 471 | $this->db->query('DELETE FROM phpgw_cal WHERE cal_id='.$id['cal_id']); |
---|
| 472 | $this->db->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$id['cal_id']); |
---|
| 473 | $this->db->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$id['cal_id']); |
---|
| 474 | $this->db->query('DELETE FROM phpgw_cal_extra WHERE cal_id='.$id['cal_id']); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | // CONATOS pessoais e grupos. |
---|
| 479 | $this->db->query('SELECT id_contact FROM phpgw_cc_contact WHERE id_owner ='.$user_info['uidnumber']); |
---|
| 480 | while($this->db->next_record()) |
---|
| 481 | { |
---|
| 482 | $ids[] = $this->db->row(); |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | if (count($ids)) |
---|
| 486 | { |
---|
| 487 | foreach($ids as $i => $id_contact) |
---|
| 488 | { |
---|
| 489 | $this->db->query('SELECT id_connection FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
| 490 | while($this->db->next_record()) |
---|
| 491 | { |
---|
| 492 | $id_conns[] = $this->db->row(); |
---|
| 493 | } |
---|
| 494 | if (count($id_conns)) |
---|
| 495 | { |
---|
| 496 | foreach($id_conns as $j => $id_conn) |
---|
| 497 | { |
---|
| 498 | $this->db->query('DELETE FROM phpgw_cc_connections WHERE id_connection='.$id_conn['id_connection']); |
---|
| 499 | $this->db->query('DELETE FROM phpgw_cc_contact_grps WHERE id_connection='.$id_conn['id_connection']); |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | $this->db->query('SELECT id_address FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
| 504 | while($this->db->next_record()) |
---|
| 505 | { |
---|
| 506 | $id_addresses[] = $$this->db->row(); |
---|
| 507 | } |
---|
| 508 | if (count($id_addresses)) |
---|
| 509 | { |
---|
| 510 | foreach($id_addresses as $j => $id_addrs) |
---|
| 511 | { |
---|
| 512 | $this->db->query('DELETE FROM phpgw_cc_addresses WHERE id_address='.$id_addrs['id_address']); |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | $this->db->query('DELETE FROM phpgw_cc_contact WHERE id_contact='.$id_contact['id_contact']); |
---|
| 516 | $this->db->query('DELETE FROM phpgw_cc_contact_conns WHERE id_contact='.$id_contact['id_contact']); |
---|
| 517 | $this->db->query('DELETE FROM phpgw_cc_contact_addrs WHERE id_contact='.$id_contact['id_contact']); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | $this->db->query('DELETE FROM phpgw_cc_groups WHERE owner='.$user_info['uidnumber']); |
---|
| 521 | |
---|
| 522 | // PREFERENCIAS |
---|
| 523 | $this->db->query('DELETE FROM phpgw_preferences WHERE preference_owner='.$user_info['uidnumber']); |
---|
| 524 | |
---|
| 525 | // ACL |
---|
| 526 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$user_info['uidnumber']); |
---|
| 527 | |
---|
| 528 | // Corrigir |
---|
| 529 | $return['status'] = true; |
---|
| 530 | return $return; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | function delete_group($gidnumber) |
---|
| 534 | { |
---|
| 535 | // ACL |
---|
| 536 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_location='.$gidnumber); |
---|
| 537 | $this->db->query('DELETE FROM phpgw_acl WHERE acl_account='.$gidnumber); |
---|
| 538 | |
---|
| 539 | // Corrigir |
---|
| 540 | $return['status'] = true; |
---|
| 541 | return $return; |
---|
| 542 | } |
---|
| 543 | |
---|
[414] | 544 | function write_log($action, $about) |
---|
[2] | 545 | { |
---|
[414] | 546 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) " |
---|
| 547 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')"; |
---|
[2] | 548 | $this->db->query($sql); |
---|
| 549 | return; |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | function get_sieve_info() |
---|
| 553 | { |
---|
| 554 | $this->db->query('SELECT profileID,imapenablesieve,imapsieveserver,imapsieveport FROM phpgw_emailadmin'); |
---|
| 555 | |
---|
| 556 | $i=0; |
---|
| 557 | while($this->db->next_record()) |
---|
| 558 | { |
---|
| 559 | $serverList[$i]['profileID'] = $this->db->f(0); |
---|
| 560 | $serverList[$i]['imapenablesieve'] = $this->db->f(1); |
---|
| 561 | $serverList[$i]['imapsieveserver'] = $this->db->f(2); |
---|
| 562 | $serverList[$i]['imapsieveport'] = $this->db->f(3); |
---|
| 563 | $i++; |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | return $serverList; |
---|
| 567 | } |
---|
[9] | 568 | |
---|
| 569 | function get_apps($account_lid) |
---|
| 570 | { |
---|
| 571 | $this->db->query("SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'"); |
---|
| 572 | |
---|
| 573 | while($this->db->next_record()) |
---|
| 574 | { |
---|
| 575 | $tmp = $this->db->row(); |
---|
| 576 | $availableApps[$tmp['app']] = 'run'; |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | return $availableApps; |
---|
| 580 | } |
---|
[27] | 581 | |
---|
| 582 | function get_sambadomains_list() |
---|
| 583 | { |
---|
| 584 | $query = "SELECT * FROM phpgw_expressoadmin_samba ORDER by samba_domain_name ASC"; |
---|
| 585 | $this->db->query($query); |
---|
| 586 | while($this->db->next_record()) |
---|
| 587 | $result[] = $this->db->row(); |
---|
| 588 | return $result; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | function exist_domain_name_sid($sambadomainname, $sambasid) |
---|
| 592 | { |
---|
| 593 | $query = "SELECT * FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname' OR samba_domain_sid='$sambasid'"; |
---|
| 594 | $this->db->query($query); |
---|
| 595 | while($this->db->next_record()) |
---|
| 596 | $result[] = $this->db->row(); |
---|
| 597 | |
---|
| 598 | if (count($result) > 0) |
---|
| 599 | return true; |
---|
| 600 | else |
---|
| 601 | return false; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | function delete_sambadomain($sambadomainname) |
---|
| 605 | { |
---|
| 606 | $this->db->query("DELETE FROM phpgw_expressoadmin_samba WHERE samba_domain_name='$sambadomainname'"); |
---|
| 607 | return; |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | function add_sambadomain($sambadomainname, $sambasid) |
---|
| 611 | { |
---|
| 612 | $sql = "INSERT INTO phpgw_expressoadmin_samba (samba_domain_name, samba_domain_sid) VALUES('$sambadomainname','$sambasid')"; |
---|
| 613 | $this->db->query($sql); |
---|
| 614 | return; |
---|
| 615 | } |
---|
[64] | 616 | |
---|
| 617 | function test_db_connection($params) |
---|
| 618 | { |
---|
| 619 | $host = $params['host']; |
---|
| 620 | $port = $params['port']; |
---|
| 621 | $name = $params['name']; |
---|
| 622 | $user = $params['user']; |
---|
| 623 | $pass = $params['pass']; |
---|
| 624 | |
---|
| 625 | $con_string = "host=$host port=$port dbname=$name user=$user password=$pass"; |
---|
| 626 | if ($db = pg_connect($con_string)) |
---|
| 627 | { |
---|
| 628 | pg_close($db); |
---|
| 629 | $result['status'] = true; |
---|
| 630 | } |
---|
| 631 | else |
---|
| 632 | { |
---|
| 633 | $result['status'] = false; |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | return $result; |
---|
| 637 | } |
---|
[180] | 638 | |
---|
| 639 | function manager_lid_exist($manager_lid) |
---|
| 640 | { |
---|
| 641 | $query = "SELECT manager_lid FROM phpgw_expressoadmin WHERE manager_lid = '" . $manager_lid . "'"; |
---|
| 642 | $this->db->query($query); |
---|
| 643 | while($this->db->next_record()) |
---|
| 644 | $result[] = $this->db->row(); |
---|
| 645 | if (count($result) > 0) |
---|
| 646 | return true; |
---|
| 647 | else |
---|
| 648 | return false; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | function create_manager($params, $manager_acl) |
---|
| 652 | { |
---|
| 653 | //Escrevre no Banco a ACL do gerente |
---|
| 654 | $sql = "INSERT INTO phpgw_expressoadmin (manager_lid, context, acl) " |
---|
| 655 | . "VALUES('" . $params['ea_select_manager'] . "','" . $params['context'] . "','" . $manager_acl . "')"; |
---|
| 656 | $this->db->query($sql); |
---|
| 657 | |
---|
| 658 | //Escrevre no Banco as aplicações que o gerente tem direito de disponibilizar aos seus usuarios. |
---|
| 659 | if (count($_POST['applications_list'])) |
---|
| 660 | { |
---|
| 661 | foreach($_POST['applications_list'] as $app=>$value) |
---|
| 662 | { |
---|
| 663 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
| 664 | . "VALUES('" . $_POST['manager_lid'] . "','" . $_POST['context'] . "','" . $app . "')"; |
---|
| 665 | $this->db->query($sql); |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | return; |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | function save_manager($params, $manager_acl) |
---|
| 673 | { |
---|
| 674 | $params['manager_lid'] = $params['hidden_manager_lid']; |
---|
| 675 | |
---|
| 676 | //Executa update na tabela para atualizar ACL |
---|
| 677 | $sql = "UPDATE phpgw_expressoadmin SET context = '" . $params['context'] . "',acl = '" . $manager_acl |
---|
| 678 | . "' WHERE manager_lid = '" . $params['manager_lid'] ."'"; |
---|
| 679 | $this->db->query($sql); |
---|
| 680 | |
---|
| 681 | //Deleta as aplicações e adiciona as novas. |
---|
| 682 | //Deleta |
---|
| 683 | $sql = "DELETE FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $params['manager_lid'] . "'"; |
---|
| 684 | $this->db->query($sql); |
---|
| 685 | |
---|
| 686 | // Adiciona |
---|
| 687 | if (count($params['applications_list'])) |
---|
| 688 | { |
---|
| 689 | foreach($params['applications_list'] as $app=>$value) |
---|
| 690 | { |
---|
| 691 | $sql = "INSERT INTO phpgw_expressoadmin_apps (manager_lid, context, app) " |
---|
| 692 | . "VALUES('" . $params['manager_lid'] . "','" . $params['context'] . "','" . $app . "')"; |
---|
| 693 | $this->db->query($sql); |
---|
| 694 | } |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | return; |
---|
| 698 | } |
---|
| 699 | |
---|
[2] | 700 | } |
---|
| 701 | ?> |
---|