Exemplo n.º 1
0
 /**
  * Gets all users with handle, passwd, auth_user_id
  * lastlogin, is_active and individual rights.
  *
  * The array will look like this:
  * <code>
  * $userData[0]['auth_user_id'] = 'wujha433gawefawfwfiuj2ou9823r98h';
  *             ['handle']       = 'myLogin';
  *             ['passwd']       = 'd346gs2gwaeiuhaeiuuweijfjuwaefhj';
  *             ['lastlogin']    = 1254801292; (Unix timestamp)
  *             ['is_active']    = 1; (1 = yes, 0 = no)
  *             ['owner_user_id']    = 1;
  *             ['owner_group_id']   = 1;
  * </code>
  *
  * Filters can be either complex or simple.
  *
  * In their simple form you just need to pass an associative array
  * with key/value, the key will be the table field name and value the value
  * you are searching. It will consider that you want an do to do a
  * field=value comparison, every additional filter will be appended with AND
  *
  * The complicated form of filters is to pass an array such as
  *
  * array(
  *     'fieldname' => array('op' => '>', 'value' => 'dummy', 'cond' => ''),
  *     'fieldname' => array('op' => '<', 'value' => 'dummy2', 'cond' => 'OR'),
  * );
  *
  * It can then build relatively complex queries. If you need joins or more
  * complicated queries than that please consider using an alternative
  * solution such as PEAR::DB_DataObject
  *
  * Any aditional field will be returned. The array key will be of the same
  * case it is given.
  *
  *  $cols = array('myField');
  *
  * e.g.: getUsers(null, $cols) will return
  *
  * <code>
  * $userData[0]['auth_user_id'] = 'wujha433gawefawfwfiuj2ou9823r98h';
  *             ['handle']       = 'myLogin';
  *             ['passwd']       = 'd346gs2gwaeiuhaeiuuweijfjuwaefhj';
  *             ['myField']      = 'value';
  * </code>
  *
  * @access  public
  * @param   array  filters to apply to fetched data
  * @param   array  custom fields you want to be returned. If not specified
  *                 the basic set of fields is returned. The keys are the
  *                 names and the values
  * @param   string  if not null 'ORDER BY $order' will be appended to the query
  * @param   boolean will return an associative array with the auth_user_id
  *                  as the key by using DB::getAssoc() instead of DB::getAll()
  * @return  mixed  Array with user data or DB error.
  */
 function getUsers($filters = array(), $addCustomFields = array(), $order = null, $rekey = false)
 {
     if (!$this->init_ok) {
         return false;
     }
     $fields = $where = '';
     if (sizeof($addCustomFields) > 0) {
         foreach ($addCustomFields as $v) {
             $customFields[] = $v;
         }
     }
     if (isset($this->authTableCols['lastlogin'])) {
         $customFields[] = $this->authTableCols['lastlogin'] . ' AS lastlogin';
     }
     if (isset($this->authTableCols['is_active'])) {
         $customFields[] = "CASE {$this->authTableCols['is_active']}\n                                WHEN 'Y' THEN 1\n                                WHEN 'N' THEN 0 END\n                                    AS is_active";
     }
     if (isset($this->authTableCols['owner_user_id'])) {
         $customFields[] = $this->authTableCols['owner_user_id'] . ' AS owner_user_id';
     }
     if (isset($this->authTableCols['owner_group_id'])) {
         $customFields[] = $this->authTableCols['owner_group_id'] . ' AS owner_group_id';
     }
     if (sizeof($customFields) > 0) {
         $fields = ',';
         $fields .= implode(',', $customFields);
     }
     if (sizeof($filters) > 0) {
         $where = ' WHERE';
         foreach ($filters as $f => $v) {
             if (is_array($v)) {
                 $cond = ' ' . $v['cond'];
                 $where .= " {$f}" . $v['op'] . $this->dbc->quoteSmart($v['value']) . $cond;
             } else {
                 $cond = ' AND';
                 $where .= " {$f}={$v}" . $cond;
             }
         }
         $where = substr($where, 0, -strlen($cond));
     }
     if (!is_null($order)) {
         $order = ' ORDER BY ' . $order;
     }
     // First: Get all data from auth table.
     $query = '
         SELECT
             ' . $this->authTableCols['user_id'] . '   AS auth_user_id,
             ' . $this->authTableCols['handle'] . '    AS handle,
             ' . $this->authTableCols['passwd'] . '    AS passwd
             ' . $fields . '
         FROM
             ' . $this->authTable . $where . $order;
     if ($rekey) {
         $res = $this->dbc->getAssoc($query, false, array(), DB_FETCHMODE_ASSOC);
     } else {
         $res = $this->dbc->getAll($query, array(), DB_FETCHMODE_ASSOC);
     }
     return $res;
 }
Exemplo n.º 2
0
 /**
  * Returns an array of the strings in the selected page
  *
  * @param string $pageID
  * @param string $langID
  * @return array
  */
 function &getPage($pageID = null, $langID = null)
 {
     $langID = $this->_getLangID($langID);
     if (PEAR::isError($langID)) {
         return $langID;
     }
     $lang_col = $this->_getLangCol($langID);
     $table = $this->_getLangTable($langID);
     $query = sprintf('SELECT %s, %s FROM %s WHERE %s ', $this->db->quoteIdentifier($this->options['string_id_col']), $this->db->quoteIdentifier($lang_col), $this->db->quoteIdentifier($table), $this->db->quoteIdentifier($this->options['string_page_id_col']));
     if (is_null($pageID)) {
         $query .= 'IS NULL';
     } else {
         $query .= ' = ' . $this->db->quote($pageID);
     }
     ++$this->_queries;
     $res = $this->db->getAssoc($query);
     return $res;
 }
Exemplo n.º 3
0
 /**
  * Reads all rights of current user into an
  * associative array.
  *
  * Right => 1
  *
  * @access  public
  * @return  void
  */
 function readRights()
 {
     $query = '
         SELECT
             R.right_id AS rightid, ' . LIVEUSER_MAX_LEVEL . '
         FROM
             ' . $this->prefix . 'userrights UR
         INNER JOIN
             ' . $this->prefix . 'rights R
         ON
             UR.right_id=R.right_id
         WHERE
             UR.perm_user_id=' . $this->permUserId;
     $result = $this->dbc->getAssoc($query);
     if (DB::isError($result)) {
         return $result;
     }
     // if
     $this->rights = $result;
 }