Advertisement
Guest User

user-wb.php

a guest
Jan 12th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1. public function getGroups()
  2.     {
  3.  
  4.         try {
  5.             $db = parse_ini_file('app/config/portal.ini');
  6.  
  7.             // read the database properties
  8.             $user = isset($db['user']) ? $db['user'] : NULL;
  9.             $pass = isset($db['pass']) ? $db['pass'] : NULL;
  10.             $name = isset($db['name']) ? $db['name'] : NULL;
  11.             $host = isset($db['host']) ? $db['host'] : NULL;
  12.             $port = isset($db['port']) ? $db['port'] : 5432;
  13.  
  14.             $conn = new PDO("pgsql:dbname={$name};user={$user}; password={$pass};host=$host;port={$port}");
  15.  
  16.             $results = array();
  17.             $result = $conn->query("select id, groupname, description from user_group");
  18.  
  19.             if (!empty($result)) {
  20.  
  21.                 while ($row = $result->fetchObject()) {
  22.                     $results[] = $row;
  23.                 }
  24.             }
  25.             return $results;
  26.         } catch (Exception $e) {
  27.             throw new SoapFault('Client', $e->getMessage());
  28.         }
  29.     }
  30.  
  31.     public function getUserGroups($login)
  32.     {
  33.         try {
  34.             $db = parse_ini_file('app/config/portal.ini');
  35.  
  36.             // read the database properties
  37.             $user = isset($db['user']) ? $db['user'] : NULL;
  38.             $pass = isset($db['pass']) ? $db['pass'] : NULL;
  39.             $name = isset($db['name']) ? $db['name'] : NULL;
  40.             $host = isset($db['host']) ? $db['host'] : NULL;
  41.             $port = isset($db['port']) ? $db['port'] : 5432;
  42.  
  43.             $conn = new PDO("pgsql:dbname={$name};user={$user}; password={$pass};host=$host;port={$port}");
  44.  
  45.             $results = array();
  46.             $result = $conn->query("SELECT user_id, group_id from user_groups WHERE user_id = (SELECT id from system_user where login='$login')");
  47.             if (!empty($result)) {
  48.  
  49.                 while ($row = $result->fetchObject()) {
  50.                     $results[] = $row;
  51.                 }
  52.             }
  53.             return $results;
  54.         } catch (Exception $e) {
  55.             throw new SoapFault('Client', $e->getMessage());
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement