예제 #1
0
파일: Sql.php 프로젝트: jubinpatel/horde
 /**
  *  Return the current value of the modseq. We take the MAX of the
  *  horde_histories table instead of the value of the horde_histories_modseq
  *  table to ensure we never miss an entry if we query the history system
  *  between the time we call nextModSeq() and the time the new entry is
  *  written.
  *
  * @param string $parent  Restrict to entries a specific parent.
  *
  * @return integer|boolean  The highest used modseq value, false if no history.
  */
 public function getHighestModSeq($parent = null)
 {
     $sql = 'SELECT history_modseq FROM horde_histories';
     if (!empty($parent)) {
         $sql .= ' WHERE object_uid LIKE ' . $this->_db->quote($parent . ':%');
     }
     $sql .= ' ORDER BY history_modseq DESC';
     $sql = $this->_db->addLimitOffset($sql, array('limit' => 1));
     try {
         $modseq = $this->_db->selectValue($sql);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_History_Exception($e);
     }
     if (is_null($modseq) || $modseq === false) {
         try {
             $modseq = $this->_db->selectValue('SELECT MAX(history_modseq) FROM horde_histories_modseq');
         } catch (Horde_Db_Exception $e) {
             throw new Horde_History_Exception($e);
         }
         if (!empty($modseq)) {
             return $modseq;
         } else {
             return false;
         }
     }
     return $modseq;
 }
예제 #2
0
파일: Sql.php 프로젝트: raz0rsdge/horde
 /**
  * Returns criteria statement fragments for querying shares.
  *
  * @param string  $userid  The userid of the user to check access for.
  * @param integer $perm    The level of permissions required.
  *
  * @return array  An array with query and where string fragments.
  */
 protected function _getUserAndGroupCriteria($userid, $perm = Horde_Perms::SHOW)
 {
     $query = $where = '';
     if (empty($userid)) {
         $where = '(' . $this->_db->buildClause('s.perm_guest', '&', $perm) . ' > 0)';
     } else {
         // (owner == $userid)
         $where .= 's.share_owner = ' . $this->_db->quote($userid);
         // (name == perm_creator and val & $perm)
         $where .= ' OR (' . $this->_db->buildClause('s.perm_creator', '&', $perm) . ' > 0)';
         // (name == perm_creator and val & $perm)
         $where .= ' OR (' . $this->_db->buildClause('s.perm_default', '&', $perm) . ' > 0)';
         // (name == perm_users and key == $userid and val & $perm)
         $query .= ' LEFT JOIN ' . $this->_table . '_users u ON u.share_id = s.share_id';
         $where .= ' OR ( u.user_uid = ' . $this->_db->quote($userid) . ' AND (' . $this->_db->buildClause('u.perm', '&', $perm) . ' > 0))';
         // If the user has any group memberships, check for those also.
         try {
             $groups = $this->_groups->listGroups($userid);
             if ($groups) {
                 // (name == perm_groups and key in ($groups) and val & $perm)
                 $ids = array_keys($groups);
                 $group_ids = array();
                 foreach ($ids as $id) {
                     $group_ids[] = $this->_db->quote((string) $id);
                 }
                 $query .= ' LEFT JOIN ' . $this->_table . '_groups g ON g.share_id = s.share_id';
                 $where .= ' OR (g.group_uid IN (' . implode(',', $group_ids) . ') AND (' . $this->_db->buildClause('g.perm', '&', $perm) . ' > 0))';
             }
         } catch (Horde_Group_Exception $e) {
             $this->_logger->err($e);
         }
     }
     return array($query, $where);
 }
예제 #3
0
파일: Sql.php 프로젝트: jubinpatel/horde
 /**
  * Sets one or more attributes of a group.
  *
  * @param mixed $gid               A group ID.
  * @param array|string $attribute  An attribute name or a hash of
  *                                 attributes.
  * @param string $value            An attribute value if $attribute is a
  *                                 string.
  *
  * @throws Horde_Group_Exception
  */
 public function setData($gid, $attribute, $value = null)
 {
     $attributes = is_array($attribute) ? $attribute : array($attribute => $value);
     $updates = array();
     foreach ($attributes as $attribute => $value) {
         $updates[] = $this->_db->quoteColumnName('group_' . $attribute) . ' = ' . $this->_db->quote($value);
     }
     try {
         $this->_db->update('UPDATE horde_groups SET ' . implode(', ', $updates) . ' WHERE group_uid = ?', array($gid));
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Group_Exception($e);
     }
 }
예제 #4
0
파일: Sql.php 프로젝트: DSNS-LAB/Dmail
 /**
  */
 public function numberOfRecipients($hours, $user = false)
 {
     /* Build the SQL query. */
     $query = sprintf('SELECT COUNT(*) FROM %s WHERE sentmail_ts > ? AND sentmail_success = 1', $this->_params['table']);
     if ($user) {
         $query .= sprintf(' AND sentmail_who = %s', $this->_db->quote($GLOBALS['registry']->getAuth()));
     }
     /* Execute the query. */
     try {
         return $this->_db->selectValue($query, array(time() - $hours * 3600));
     } catch (Horde_Db_Exception $e) {
         return 0;
     }
 }
예제 #5
0
파일: Sql.php 프로젝트: jubinpatel/horde
 /**
  * @TODO
  */
 private function _equalClause($lhs, $rhs, $quote = true)
 {
     if (!is_array($rhs)) {
         if ($quote) {
             return sprintf(' %s = %s', $lhs, $this->_db->quote($rhs));
         }
         return sprintf(' %s = %s', $lhs, $rhs);
     }
     if (count($rhs) == 0) {
         return ' FALSE';
     }
     $glue = '';
     $ret = sprintf(' %s IN ( ', $lhs);
     foreach ($rhs as $value) {
         $ret .= $glue . $this->_db->quote($value);
         $glue = ', ';
     }
     return $ret . ' )';
 }
예제 #6
0
파일: Sql.php 프로젝트: jubinpatel/horde
 public function getMatchingPages($searchtext, $matchType = Wicked_Page::MATCH_ANY)
 {
     $searchtext = strtolower($searchtext);
     try {
         /* Short circuit the simple case. */
         if ($matchType == Wicked_Page::MATCH_ANY) {
             return $this->_retrieve($this->_params['table'], 'LOWER(page_name) LIKE ' . $this->_db->quote('%' . $searchtext . '%'));
         }
         $clauses = array();
         if ($matchType & Wicked_Page::MATCH_LEFT) {
             $clauses[] = 'LOWER(page_name) LIKE ' . $this->_db->quote($searchtext . '%');
         }
         if ($matchType & Wicked_Page::MATCH_RIGHT) {
             $clauses[] = 'LOWER(page_name) LIKE ' . $this->_db->quote('%' . $searchtext);
         }
     } catch (Horde_Db_Exception $e) {
         throw new Wicked_Exception($e);
     }
     if (!$clauses) {
         return array();
     }
     return $this->_retrieve($this->_params['table'], implode(' OR ', $clauses));
 }
예제 #7
0
파일: Driver.php 프로젝트: horde/horde
 /**
  * Searches forums for matching threads or posts.
  *
  * @param array $filter  Hash of filter criteria:
  *          'forums'         => Array of forum IDs to search.  If not
  *                              present, searches all forums.
  *          'keywords'       => Array of keywords to search for.  If not
  *                              present, finds all posts/threads.
  *          'allkeywords'    => Boolean specifying whether to find all
  *                              keywords; otherwise, wants any keyword.
  *                              False if not supplied.
  *          'message_author' => Name of author to find posts by.  If not
  *                              present, any author.
  *          'searchsubjects' => Boolean specifying whether to search
  *                              subjects.  True if not supplied.
  *          'searchcontents' => Boolean specifying whether to search
  *                              post contents.  False if not supplied.
  * @param string  $sort_by       The column by which to sort.
  * @param integer $sort_dir      The direction by which to sort:
  *                                   0 - ascending
  *                                   1 - descending
  * @param string  $from          The thread to start listing at.
  * @param string  $count         The number of threads to return.
  *
  * @return array  A search result hash where:
  *          'results'        => Array of messages.
  *          'total           => Total message number.
  * @throws Agora_Exception
  */
 public function search($filter, $sort_by = 'message_subject', $sort_dir = 0, $from = 0, $count = 0)
 {
     if (!isset($filter['allkeywords'])) {
         $filter['allkeywords'] = false;
     }
     if (!isset($filter['searchsubjects'])) {
         $filter['searchsubjects'] = true;
     }
     if (!isset($filter['searchcontents'])) {
         $filter['searchcontents'] = false;
     }
     /* Select forums ids to search in */
     $sql = 'SELECT forum_id, forum_name FROM ' . $this->_forums_table . ' WHERE ';
     if (empty($filter['forums'])) {
         $sql .= ' active = ? AND scope = ?';
         $values = array(1, $this->_scope);
     } else {
         $sql .= ' forum_id IN (' . implode(',', $filter['forums']) . ')';
         $values = array();
     }
     try {
         $forums = $this->_db->selectAssoc($sql, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Agora_Exception($e->getMessage());
     }
     /* Build query  */
     $sql = ' FROM ' . $this->_threads_table . ' WHERE forum_id IN (' . implode(',', array_keys($forums)) . ')';
     if (!empty($filter['keywords'])) {
         $sql .= ' AND (';
         if ($filter['searchsubjects']) {
             $keywords = '';
             foreach ($filter['keywords'] as $keyword) {
                 if (!empty($keywords)) {
                     $keywords .= $filter['allkeywords'] ? ' AND ' : ' OR ';
                 }
                 $keywords .= 'message_subject LIKE ' . $this->_db->quote('%' . $keyword . '%');
             }
             $sql .= '(' . $keywords . ')';
         }
         if ($filter['searchcontents']) {
             if ($filter['searchsubjects']) {
                 $sql .= ' OR ';
             }
             $keywords = '';
             foreach ($filter['keywords'] as $keyword) {
                 if (!empty($keywords)) {
                     $keywords .= $filter['allkeywords'] ? ' AND ' : ' OR ';
                 }
                 $keywords .= 'body LIKE ' . $this->_db->quote('%' . $keyword . '%');
             }
             $sql .= '(' . $keywords . ')';
         }
         $sql .= ')';
     }
     if (!empty($filter['author'])) {
         $sql .= ' AND message_author = ' . $this->_db->quote(Horde_String::lower($filter['author']));
     }
     /* Sort by result column. */
     $sql .= ' ORDER BY ' . $sort_by . ' ' . ($sort_dir ? 'DESC' : 'ASC');
     /* Slice directly in DB. */
     if ($count) {
         $total = $this->_db->selectValue('SELECT COUNT(*) ' . $sql);
         $sql = $this->_db->addLimitOffset($sql, array('limit' => $count, 'offset' => $from));
     }
     $sql = 'SELECT message_id, forum_id, message_subject, message_author, message_timestamp ' . $sql;
     try {
         $messages = $this->_db->select($sql);
     } catch (Horde_Db_Exception $e) {
         throw new Agora_Exception($e->getMessage());
     }
     if (empty($messages)) {
         return array('results' => array(), 'total' => 0);
     }
     $results = array();
     $msg_url = Horde::url('messages/index.php');
     $forum_url = Horde::url('threads.php');
     while ($message = $messages->fetch()) {
         if (!isset($results[$message['forum_id']])) {
             $index = array('agora' => $message['forum_id'], 'scope' => $this->_scope);
             $results[$message['forum_id']] = array('forum_id' => $message['forum_id'], 'forum_url' => $forum_url->add($index), 'forum_name' => $this->convertFromDriver($forums[$message['forum_id']]), 'messages' => array());
         }
         $index = array('agora' => $message['forum_id'] . '.' . $message['message_id'], 'scope' => $this->_scope);
         $results[$message['forum_id']]['messages'][] = array('message_id' => $message['message_id'], 'message_subject' => htmlspecialchars($this->convertFromDriver($message['message_subject'])), 'message_author' => $message['message_author'], 'message_date' => $this->dateFormat($message['message_timestamp']), 'message_url' => $msg_url->add($index));
     }
     return array('results' => $results, 'total' => $total);
 }
예제 #8
0
파일: Sql.php 프로젝트: jubinpatel/horde
 /**
  * Quotes user input if supported by the transport driver.
  *
  * @param string $string  A string to quote.
  *
  * @return string  The quoted string.
  */
 public function quote($string)
 {
     $this->_connect();
     return $this->_db->quote($string);
 }