diff --git a/OpenVBX/models/vbx_message.php b/OpenVBX/models/vbx_message.php index 3ea608c7..3f84981a 100644 --- a/OpenVBX/models/vbx_message.php +++ b/OpenVBX/models/vbx_message.php @@ -271,7 +271,7 @@ function get_message($id) $user_group_select = "IF(u.email IS NOT NULL , 'user', 'group') as owner_type, IF( u.email IS NOT NULL , u.email , g.name) as owner, IF (u.email IS NOT NULL, u.id, g.id) as owner_id"; $ci->db->from($this->table)->select("messages.*, $user_group_select", false); - + if(is_array($id)) { $ci->db->where($id); @@ -293,7 +293,7 @@ function get_message($id) if(empty($result)) { $_id = $id; - if (is_array($id)) + if (is_array($id)) { $_id = $id['call_sid']; } @@ -395,14 +395,14 @@ function get_messages($options, $offset, $size) } function notify_message($message) - { + { $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $ci->load->model('vbx_incoming_numbers'); - + $recording_host = $ci->settings->get('recording_host', VBX_PARENT_TENANT); - + $vm_url = $message->content_url; if (!empty($recording_host) && trim($recording_host) != '') { $vm_url = str_replace('api.twilio.com',trim($recording_host), $vm_url); @@ -525,7 +525,7 @@ function message_owner() { return $group->name; } - + $user = new User(); $user->get_by_id($this->user_id); return $user->full_name(); @@ -577,7 +577,7 @@ function get_folders($user_id, $group_ids) { $folders[$inbox_id]->total = $user_message_total[0]->count; } - + if(!empty($group_ids)) { $groups = $ci->db @@ -606,7 +606,7 @@ function get_folders($user_id, $group_ids) ->where_in('gm.group_id', $group_ids) ->where('archived', false) ->where('m.tenant_id', $ci->tenant->id) - ->group_by('m.status, g.id') + ->group_by('m.status, g.id, g.name') //ND added g.name here to fix error ->get()->result(); $group_folder_totals = array(); diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 07021999..d7d09528 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -40,11 +40,11 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_offset = FALSE; var $ar_order = FALSE; var $ar_orderby = array(); - var $ar_set = array(); + var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); var $ar_store_array = array(); - + // Active Record Caching variables var $ar_caching = FALSE; var $ar_cache_exists = array(); @@ -56,7 +56,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_groupby = array(); var $ar_cache_having = array(); var $ar_cache_orderby = array(); - var $ar_cache_set = array(); + var $ar_cache_set = array(); // -------------------------------------------------------------------- @@ -72,12 +72,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function select($select = '*', $escape = NULL) { - // Set the global value if this was sepecified + // Set the global value if this was sepecified if (is_bool($escape)) { $this->_protect_identifiers = $escape; } - + if (is_string($select)) { $select = explode(',', $select); @@ -117,7 +117,7 @@ function select_max($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } - + // -------------------------------------------------------------------- /** @@ -178,7 +178,7 @@ function select_sum($select = '', $alias = '') * select_min() * select_avg() * select_sum() - * + * * @access public * @param string the field * @param string an alias @@ -190,29 +190,29 @@ function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') { $this->display_error('db_invalid_query'); } - + $type = strtoupper($type); - + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) { show_error('Invalid function type: '.$type); } - + if ($alias == '') { $alias = $this->_create_alias_from_table(trim($select)); } - + $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; $this->ar_cache_exists[] = 'select'; } - + return $this; } @@ -231,7 +231,7 @@ function _create_alias_from_table($item) { return end(explode('.', $item)); } - + return $item; } @@ -251,7 +251,7 @@ function distinct($val = TRUE) $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; } - + // -------------------------------------------------------------------- /** @@ -275,12 +275,12 @@ function from($from) $this->_track_aliases($v); $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); $this->ar_cache_exists[] = 'from'; - } + } } } @@ -289,11 +289,11 @@ function from($from) $val = trim($val); // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($val); - + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); @@ -319,7 +319,7 @@ function from($from) * @return object */ function join($table, $cond, $type = '') - { + { if ($type != '') { $type = strtoupper(trim($type)); @@ -335,7 +335,7 @@ function join($table, $cond, $type = '') } // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); // Strip apart the condition and protect the identifiers @@ -343,10 +343,10 @@ function join($table, $cond, $type = '') { $match[1] = $this->_protect_identifiers($match[1]); $match[3] = $this->_protect_identifiers($match[3]); - - $cond = $match[1].$match[2].$match[3]; + + $cond = $match[1].$match[2].$match[3]; } - + // Assemble the JOIN statement $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; @@ -377,7 +377,7 @@ function where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'AND ', $escape); } - + // -------------------------------------------------------------------- /** @@ -427,7 +427,7 @@ function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { $key = array($key => $value); } - + // If the escape value was not set will will base it on the global setting if ( ! is_bool($escape)) { @@ -443,13 +443,13 @@ function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - + if ( ! is_null($v)) { if ($escape === TRUE) { $k = $this->_protect_identifiers($k, FALSE, $escape); - + $v = ' '.$this->escape($v); } @@ -460,19 +460,19 @@ function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) } else { - $k = $this->_protect_identifiers($k, FALSE, $escape); + $k = $this->_protect_identifiers($k, FALSE, $escape); } $this->ar_where[] = $prefix.$k.$v; - + if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; $this->ar_cache_exists[] = 'where'; } - + } - + return $this; } @@ -493,7 +493,7 @@ function where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values); } - + // -------------------------------------------------------------------- /** @@ -529,7 +529,7 @@ function where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE); } - + // -------------------------------------------------------------------- /** @@ -559,7 +559,7 @@ function or_where_not_in($key = NULL, $values = NULL) * @param string The field to search * @param array The values searched on * @param boolean If the statement would be IN or NOT IN - * @param string + * @param string * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') @@ -568,12 +568,12 @@ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { return; } - + if ( ! is_array($values)) { $values = array($values); } - + $not = ($not) ? ' NOT' : ''; foreach ($values as $value) @@ -582,7 +582,7 @@ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') } $prefix = (count($this->ar_where) == 0) ? '' : $type; - + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; $this->ar_where[] = $where_in; @@ -596,7 +596,7 @@ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') $this->ar_wherein = array(); return $this; } - + // -------------------------------------------------------------------- /** @@ -632,7 +632,7 @@ function not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -668,7 +668,7 @@ function or_not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -680,7 +680,7 @@ function orlike($field, $match = '', $side = 'both') { return $this->or_like($field, $match, $side); } - + // -------------------------------------------------------------------- /** @@ -700,7 +700,7 @@ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { $field = array($field => $match); } - + foreach ($field as $k => $v) { $k = $this->_protect_identifiers($k); @@ -721,24 +721,24 @@ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } - + // some platforms require an escape sequence definition for LIKE wildcards if ($this->_like_escape_str != '') { $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_char); } - + $this->ar_like[] = $like_statement; if ($this->ar_caching === TRUE) { $this->ar_cache_like[] = $like_statement; $this->ar_cache_exists[] = 'like'; } - + } return $this; } - + // -------------------------------------------------------------------- /** @@ -754,15 +754,15 @@ function group_by($by) { $by = explode(',', $by); } - + foreach ($by as $val) { $val = trim($val); - + if ($val != '') { $this->ar_groupby[] = $this->_protect_identifiers($val); - + if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); @@ -783,7 +783,7 @@ function group_by($by) function groupby($by) { return $this->group_by($by); - } + } // -------------------------------------------------------------------- @@ -813,7 +813,7 @@ function having($key, $value = '', $escape = TRUE) function orhaving($key, $value = '', $escape = TRUE) { return $this->or_having($key, $value, $escape); - } + } // -------------------------------------------------------------------- /** @@ -830,7 +830,7 @@ function or_having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'OR ', $escape); } - + // -------------------------------------------------------------------- /** @@ -849,7 +849,7 @@ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { $key = array($key => $value); } - + foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; @@ -868,7 +868,7 @@ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { $v = ' '.$this->escape_str($v); } - + $this->ar_having[] = $prefix.$k.$v; if ($this->ar_caching === TRUE) { @@ -876,10 +876,10 @@ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) $this->ar_cache_exists[] = 'having'; } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -901,8 +901,8 @@ function order_by($orderby, $direction = '') { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - - + + if (strpos($orderby, ',') !== FALSE) { $temp = array(); @@ -913,19 +913,19 @@ function order_by($orderby, $direction = '') { $part = $this->_protect_identifiers(trim($part)); } - + $temp[] = $part; } - - $orderby = implode(', ', $temp); + + $orderby = implode(', ', $temp); } else if ($direction != $this->_random_keyword) { $orderby = $this->_protect_identifiers($orderby); } - + $orderby_statement = $orderby.$direction; - + $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) { @@ -935,7 +935,7 @@ function order_by($orderby, $direction = '') return $this; } - + // -------------------------------------------------------------------- /** @@ -947,7 +947,7 @@ function orderby($orderby, $direction = '') { return $this->order_by($orderby, $direction); } - + // -------------------------------------------------------------------- /** @@ -966,10 +966,10 @@ function limit($value, $offset = '') { $this->ar_offset = $offset; } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -984,7 +984,7 @@ function offset($offset) $this->ar_offset = $offset; return $this; } - + // -------------------------------------------------------------------- /** @@ -999,11 +999,11 @@ function offset($offset) function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); - + if ( ! is_array($key)) { $key = array($key => $value); - } + } foreach ($key as $k => $v) { @@ -1016,10 +1016,10 @@ function set($key, $value = '', $escape = TRUE) $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -1041,12 +1041,12 @@ function get($table = '', $limit = null, $offset = null) $this->_track_aliases($table); $this->from($table); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -1057,7 +1057,7 @@ function get($table = '', $limit = null, $offset = null) /** * "Count All Results" query * - * Generates a platform-specific query string that counts all records + * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @access public @@ -1071,12 +1071,12 @@ function count_all_results($table = '') $this->_track_aliases($table); $this->from($table); } - +$this->ar_orderby = array(); //ND and JB added this line $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); - + if ($query->num_rows() == 0) { return '0'; @@ -1110,12 +1110,12 @@ function get_where($table = '', $where = null, $limit = null, $offset = null) { $this->where($where); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -1134,7 +1134,7 @@ function getwhere($table = '', $where = null, $limit = null, $offset = null) { return $this->get_where($table, $where, $limit, $offset); } - + // -------------------------------------------------------------------- /** @@ -1148,12 +1148,12 @@ function getwhere($table = '', $where = null, $limit = null, $offset = null) * @return object */ function insert($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1173,16 +1173,16 @@ function insert($table = '', $set = NULL) } return FALSE; } - + $table = $this->ar_from[0]; } $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - + $this->_reset_write(); - return $this->query($sql); + return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1205,7 +1205,7 @@ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1225,10 +1225,10 @@ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) } return FALSE; } - + $table = $this->ar_from[0]; } - + if ($where != NULL) { $this->where($where); @@ -1238,9 +1238,9 @@ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { $this->limit($limit); } - + $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - + $this->_reset_write(); return $this->query($sql); } @@ -1279,7 +1279,7 @@ function empty_table($table = '') $sql = $this->_delete($table); $this->_reset_write(); - + return $this->query($sql); } @@ -1319,10 +1319,10 @@ function truncate($table = '') $sql = $this->_truncate($table); $this->_reset_write(); - + return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1388,7 +1388,7 @@ function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) } return FALSE; - } + } $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); @@ -1396,7 +1396,7 @@ function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { $this->_reset_write(); } - + return $this->query($sql); } @@ -1431,7 +1431,7 @@ function dbprefix($table = '') * @access private * @param string The table to inspect * @return string - */ + */ function _track_aliases($table) { if (is_array($table)) @@ -1442,23 +1442,23 @@ function _track_aliases($table) } return; } - + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { return $this->_track_aliases(explode(',', $table)); } - + // if a table alias is used we can recognize it by a space if (strpos($table, " ") !== FALSE) { // if the alias is written with the AS keyword, remove it $table = preg_replace('/ AS /i', ' ', $table); - + // Grab the alias $table = trim(strrchr($table, " ")); - + // Store the alias, if it doesn't already exist if ( ! in_array($table, $this->ar_aliased_tables)) { @@ -1484,7 +1484,7 @@ function _compile_select($select_override = FALSE) $this->_merge_cache(); // ---------------------------------------------------------------- - + // Write the "select" portion of the query if ($select_override !== FALSE) @@ -1494,13 +1494,13 @@ function _compile_select($select_override = FALSE) else { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - + if (count($this->ar_select) == 0) { - $sql .= '*'; + $sql .= '*'; } else - { + { // Cycle through the "select" portion of the query and prep each column name. // The reason we protect identifiers here rather then in the select() function // is because until the user calls the from() function we don't know if there are aliases @@ -1508,13 +1508,13 @@ function _compile_select($select_override = FALSE) { $this->ar_select[$key] = $this->_protect_identifiers($val); } - + $sql .= implode(', ', $this->ar_select); } } // ---------------------------------------------------------------- - + // Write the "FROM" portion of the query if (count($this->ar_from) > 0) @@ -1525,7 +1525,7 @@ function _compile_select($select_override = FALSE) } // ---------------------------------------------------------------- - + // Write the "JOIN" portion of the query if (count($this->ar_join) > 0) @@ -1536,7 +1536,7 @@ function _compile_select($select_override = FALSE) } // ---------------------------------------------------------------- - + // Write the "WHERE" portion of the query if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) @@ -1549,9 +1549,9 @@ function _compile_select($select_override = FALSE) $sql .= implode("\n", $this->ar_where); // ---------------------------------------------------------------- - + // Write the "LIKE" portion of the query - + if (count($this->ar_like) > 0) { if (count($this->ar_where) > 0) @@ -1563,20 +1563,20 @@ function _compile_select($select_override = FALSE) } // ---------------------------------------------------------------- - + // Write the "GROUP BY" portion of the query - + if (count($this->ar_groupby) > 0) { $sql .= "\nGROUP BY "; - + $sql .= implode(', ', $this->ar_groupby); } // ---------------------------------------------------------------- - + // Write the "HAVING" portion of the query - + if (count($this->ar_having) > 0) { $sql .= "\nHAVING "; @@ -1584,24 +1584,24 @@ function _compile_select($select_override = FALSE) } // ---------------------------------------------------------------- - + // Write the "ORDER BY" portion of the query if (count($this->ar_orderby) > 0) { $sql .= "\nORDER BY "; $sql .= implode(', ', $this->ar_orderby); - + if ($this->ar_order !== FALSE) { $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } + } } // ---------------------------------------------------------------- - + // Write the "LIMIT" portion of the query - + if (is_numeric($this->ar_limit)) { $sql .= "\n"; @@ -1628,7 +1628,7 @@ function _object_to_array($object) { return $object; } - + $array = array(); foreach (get_object_vars($object) as $key => $val) { @@ -1638,10 +1638,10 @@ function _object_to_array($object) $array[$key] = $val; } } - + return $array; } - + // -------------------------------------------------------------------- /** @@ -1651,7 +1651,7 @@ function _object_to_array($object) * * @access public * @return void - */ + */ function start_cache() { $this->ar_caching = TRUE; @@ -1666,7 +1666,7 @@ function start_cache() * * @access public * @return void - */ + */ function stop_cache() { $this->ar_caching = FALSE; @@ -1681,23 +1681,23 @@ function stop_cache() * * @access public * @return void - */ + */ function flush_cache() - { + { $this->_reset_run( array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), 'ar_cache_set' => array(), 'ar_cache_exists' => array() ) - ); + ); } // -------------------------------------------------------------------- @@ -1705,7 +1705,7 @@ function flush_cache() /** * Merge Cache * - * When called, this function merges any cached AR arrays with + * When called, this function merges any cached AR arrays with * locally called ones. * * @access private @@ -1770,25 +1770,25 @@ function _reset_run($ar_reset_items) function _reset_select() { $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), 'ar_aliased_tables' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, 'ar_order' => FALSE, ); - + $this->_reset_run($ar_reset_items); } - + // -------------------------------------------------------------------- /** @@ -1800,20 +1800,20 @@ function _reset_select() * @return void */ function _reset_write() - { + { $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_limit' => FALSE, + 'ar_orderby' => array(), + 'ar_limit' => FALSE, 'ar_order' => FALSE ); $this->_reset_run($ar_reset_items); } - + } /* End of file DB_active_rec.php */