Example #1
0
 /**
  * Count records by where cond.
  *
  * @param array|string $where
  * @return int
  */
 public function count($where = array())
 {
     if (empty($where)) {
         return $this->db->count($this->_name);
     } else {
         return $this->db->where($where)->count($this->_name);
     }
 }
 function confirm_publish()
 {
     $db = new Database();
     $version = Input::instance()->post('version');
     $db->where(array('id >' => $version))->update('versions', array('published' => 0));
     $db->where(array('id <=' => $version))->update('versions', array('published' => 1));
     url::redirect('versions_admin');
 }
 function confirm_publish()
 {
     $db = new Database();
     $version = Input::instance()->post('version');
     $db->where(array('id >' => $version))->update('versions', array('published' => 0));
     $db->where(array('id <=' => $version))->update('versions', array('published' => 1));
     $m = $db->select('max(version) AS max')->from('pages_positions_store')->where('version <=', $version)->get();
     if ($m->count()) {
         $sql = "CREATE OR REPLACE VIEW pages_positions_published AS (SELECT * FROM pages_positions_store WHERE version=" . $m->current()->max . ")";
         $db->query($sql);
     }
     $type = Input::instance()->get('type', '');
     $type = $type > '' ? '?type=' . $type : '';
     url::redirect('versions_admin' . $type);
 }
Example #4
0
 public static function user_agents($start, $end)
 {
     $db = new Database();
     $sql = "select DISTINCT user_agent from zest_statistics where when_log > '{$start}' AND when_log < '{$end}'";
     $query = $db->query($sql)->result_array();
     //	print_r($query);
     //	exit;
     $array = array();
     foreach ($query as $q) {
         $count = $db->where(array('user_agent' => $q->user_agent, 'when_log >' => $start, 'when_log <' => $end))->count_records('statistics');
         if (zest::parse_user_agent($q->user_agent, 'is_browser')) {
             $browser = zest::parse_user_agent($q->user_agent, 'browser');
             $version = zest::parse_user_agent($q->user_agent, 'version');
             $version = explode('.', $version);
             $version = $version[0];
             $str = $browser . ' ' . $version;
             //		echo $str.' '.$count.'<br/>';
             if (isset($array[$str])) {
                 $count = $array[$str] + $count;
                 $array[$str] = $count;
             } else {
                 $array[$str] = $count;
             }
         }
     }
     arsort($array);
     //exit;
     return $array;
 }
Example #5
0
 public function get_document_metadata_fields()
 {
     $database = new Database();
     $database->select('key');
     $database->from('document_metadata');
     $database->where('document_id', $this->id);
     $results = arr::rotate($database->get()->result_array(false));
     return $results['key'];
 }
Example #6
0
 public function definir_acessos($acessos)
 {
     //remove os acesso do grupo
     $db = new Database();
     $db->where('grupo_acesso_id', $this->id)->delete('acessos');
     //adiciona os novos acessos
     foreach ($acessos as $acesso) {
         $db->insert('acessos', array('grupo_acesso_id' => $this->id, 'metodo' => $acesso));
     }
 }
Example #7
0
 /**
  * Returns a list of the field names and values for a given userlevel
  *
  * @param int $id incident id
  * @param int $user_level the user's role level
  * @return Result
  */
 public static function view_everything($id, $user_level)
 {
     $db = new Database();
     $db->select('form_response.form_response', 'form_field.field_name');
     $db->from('form_response');
     $db->join('form_field', 'form_response.form_field_id', 'form_field.id');
     $db->where(array('form_response.incident_id' => $id, 'form_field.field_ispublic_visible <=' => $user_level));
     $db->orderby('form_field.field_position');
     return $db->get();
 }
Example #8
0
 /**
  * 删除过期数据
  *
  */
 public function delete_expired()
 {
     try {
         $this->_handler->where('expire', 0, '>')->where('expire', TIME, '<=')->delete($this->tablename);
         return true;
     } catch (Exception $e) {
         Core::debug()->error($e->getMessage());
         return false;
     }
 }
 /**
  * translate name into id
  *
  * @param string $item 
  * @return void
  * @author Andy Bennett
  */
 private static function translate_id($item)
 {
     if (substr($item, 0, 1) == '/' or substr($item, 0, 1) == '#') {
         return $item;
     } else {
         $db = new Database();
         $data = array('name' => "{$item}");
         //, 'url' => '/page/'.$item );
         $db->where('id', str_replace('page-', '', $item))->update('pages', $data);
         return '/page/' . $item;
     }
 }
 public function min_authors_for_object_name($object_name)
 {
     $database = new Database();
     $database->select('value');
     $database->from('workshop_config');
     $database->where(array('object_name' => $object_name, 'rule_name' => 'min'));
     $results = $database->get()->result_array(FALSE);
     if (count($results) == 0) {
         return Kohana::config('workshop.default.min_of_authors');
     } else {
         return $results[0]['value'];
     }
 }
 public function version_position_table($table, $version = null)
 {
     if (is_null($version)) {
         $version = versions_helper::get_version();
     }
     $db = new Database();
     $vs = new Database_Expression('(SELECT max(version) AS version FROM ' . $table . '_store LIMIT 1)');
     $r = $db->where('version', $vs)->get($table . '_store')->as_array(false);
     foreach ($r as $p) {
         unset($p['id']);
         $p['version'] = $version;
         $db->insert($table . '_store', $p);
     }
     $sql = "CREATE OR REPLACE VIEW " . $table . " AS (SELECT * FROM " . $table . "_store WHERE version=" . $version . ")";
     $db->query($sql);
 }
Example #12
0
 /**
  * 删除指定key的缓存,若$key===true则表示删除全部
  *
  * @param string $key
  */
 public function delete($key)
 {
     if (IS_DEBUG) {
         Core::debug()->info($key, 'database storage delete key');
     }
     if (is_array($key)) {
         $new_keys = array();
         foreach ($key as $k) {
             $k = $this->prefix . $k;
             $new_keys[] = md5($k);
         }
         $this->_handler->in('key', $new_keys);
     } elseif (true !== $key) {
         $key = $this->prefix . $key;
         $this->_handler->where('key', $key);
     }
     try {
         $this->_handler->delete($this->tablename);
         return true;
     } catch (Exception $e) {
         Core::debug()->warn($e->getMessage());
         return false;
     }
 }
Example #13
0
 public function remove_author_of(User_Model $author, ORM $object)
 {
     if ($this->is_possible_to_remove_authors_to($object)) {
         $database = new Database();
         $database->from('workshop_data');
         $database->where(array('user_id' => $author->id, 'object_name' => $object->object_name, 'object_id' => $object->id));
         $database->delete();
     } else {
         throw new Workshop_Min_Limit_Exception($object, $this->get_number_of_authors_of($object), 1, $this->config_delegate->min_authors_for($object));
     }
 }
Example #14
0
 /**
  * Get the number of reports by date for dashboard chart
  *
  * @param int $range No. of days in the past
  * @param int $user_id
  * @return array
  */
 public static function get_number_reports_by_date($range = NULL, $user_id = NULL)
 {
     // Table Prefix
     $table_prefix = Kohana::config('database.default.table_prefix');
     // Database instance
     $db = new Database();
     $params = array();
     $db->select('COUNT(id) as count', 'DATE(incident_date) as date', 'MONTH(incident_date) as month', 'DAY(incident_date) as day', 'YEAR(incident_date) as year')->from('incident')->groupby('date')->orderby('incident_date', 'ASC');
     if (!empty($user_id)) {
         $db->where('user_id', $user_id);
     }
     if (!empty($range)) {
         // Use Database_Expression to sanitize range param
         $range_expr = new Database_Expression('incident_date  >= DATE_SUB(CURDATE(), INTERVAL :range DAY)', array(':range' => (int) $range));
         $db->where($range_expr->compile());
     }
     $query = $db->get();
     $result = $query->result_array(FALSE);
     $array = array();
     foreach ($result as $row) {
         $timestamp = mktime(0, 0, 0, $row['month'], $row['day'], $row['year']) * 1000;
         $array["{$timestamp}"] = $row['count'];
     }
     return $array;
 }
Example #15
0
 /**
  * Lists the reports.
  * @param int $page
  */
 function index($page = 1)
 {
     $this->template->content = new View('admin/mhi');
     $this->template->content->title = Kohana::lang('ui_admin.multiple_hosted_instances');
     $this->template->content->domain_name = $_SERVER['HTTP_HOST'];
     // check, has the form been submitted?
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('action', 'required', 'alpha', 'length[1,1]');
         $post->add_rules('instance_id.*', 'required', 'numeric');
         if ($post->validate()) {
             if ($post->action == 'a') {
                 // Approve Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '1';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.approved'));
             } elseif ($post->action == 'u') {
                 // Unapprove Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->site_active = '0';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.unapproved'));
             } elseif ($post->action == 'd') {
                 // Delete Action
                 foreach ($post->instance_id as $item) {
                     $update = new Mhi_Site_Model($item);
                     if ($update->loaded == true) {
                         $update->delete();
                     }
                 }
                 $form_action = Kohana::lang('ui_admin.deleted');
             }
             $form_saved = TRUE;
         } else {
             $form_error = TRUE;
         }
     }
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     // Status is the "Show All/Pending/Approved tabs'
     if (!empty($_GET['status'])) {
         $status = strtolower($_GET['status']);
         if ($status == 'a') {
             $filter = 'site_active = 1';
         } elseif ($status == 'p') {
             $filter = 'site_active = 0';
         }
     } else {
         $status = '0';
         $filter = '1=1';
         // Using 1=1 is a way to preserve the "where" statement to reduce code complexity
     }
     $this->template->content->status = $status;
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('mhi_site')->where($filter)->count_all()));
     $this->template->content->pagination = $pagination;
     $db = new Database();
     $db->select('mhi_site.*, mhi_users.email, mhi_users.firstname, mhi_users.lastname');
     $db->from('mhi_site');
     $db->join('mhi_users', 'mhi_users.id', 'mhi_site.user_id');
     $db->where($filter);
     $db->orderby('mhi_site.site_dateadd', 'desc');
     $db->limit((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $instances = $db->get();
     $this->template->content->instances = $instances;
     $this->template->content->total_items = $pagination->total_items;
     // Javascript Header
     $this->template->js = new View('admin/mhi_js');
 }
Example #16
0
 /**
  * 删除制定key的配置,支持多个
  *
  * @param string/array $key
  * @param string $type
  * @return boolean
  */
 public function delete($key, $type = '')
 {
     $db = new Database($this->database);
     $type = (string) $type;
     try {
         if (is_array($key)) {
             # 多个key
             $db->where('type', $type);
             $db->and_where_open();
             foreach ($key as $k) {
                 $db->or_where('key_md5', $k);
                 if ($this->config) {
                     unset($this->config[$type][$k]);
                 }
             }
             $db->and_where_close();
             $db->delete();
         } else {
             # 单个key
             $db->delete($this->tablename, array('type' => $type, 'key_md5' => md5($key)));
             if ($this->config) {
                 unset($this->config[$type][$key]);
             }
         }
         // 删除缓存
         $this->clear_cache();
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * This is still not enough! We need things like custom column orders
  * (so we can order plugins in their columns)
  *
  * @param array $settings Settings to be passed to the WHERE clause. Currently only separated by AND
  * @return unknown
  */
 function getPluginsBySetting($settings)
 {
     $out = array();
     $db = new Database();
     #$res = $db->query("SELECT * FROM plugin_instances LEFT JOIN container_plugin_settings ON plugin_instances.id = container_plugin_settings.id WHERE container_plugins.container_id='{$this->container_id}' ORDER BY container_plugins.id");
     $res = $db->from('plugin_instances')->where('container_id', $this->container_id);
     foreach ($settings as $column => $value) {
         $db->where($column, $value);
     }
     $res = $db->orderby('order', 'ASC')->get();
     foreach ($res->result(false) as $row) {
         $out[$row['plugin_name']]['column'] = $row['column'];
         $out[$row['plugin_name']]['order'] = $row['order'];
         $out[$row['plugin_name']]['template'] = $row['template'];
     }
     return $out;
 }
Example #18
0
    /**
     * add a new page into the tree
     *
     * @return void
     * @author Andy Bennett
     */
    public function add()
    {
        $table = steamcore::get_controls_model('pages')->get_table();
        $data = array();
        $data['title'] = "New Page";
        $data['name'] = url::title($data['title']);
        $data["date_added"] = date('Y-m-d H:i:s');
        $data["date_modified"] = date('Y-m-d H:i:s');
        $data["container"] = 1;
        $data["copy"] = '<div class="editablecontent">
							<div class="editable" id="anonymous_element_14">
								Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore  magna aliquyam erat, sed diam voluptua. At vero eos et  accusam et justo duo dolores et ea rebum. Stet clita kasd  gubergren, no sea takimata sanctus est Lorem ipsum dolor  sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing  elitr, sed diam nonumy eirmod tempor invidunt ut labore  et dolore magna aliquyam erat, sed diam voluptua.
							</div>
						</div>';
        $db = new Database();
        $r = $db->insert($table, $data);
        $id = $r->insert_id();
        $db->where('id', $id)->update($table, array('name' => 'page-' . $id));
        echo $id;
    }
 /**
  * Attempts to fetch and cache the database records to the internal storage
  * container as models. Please note, this function handles the validation of
  * any/all filters before it does anything.
  *
  * @param array $filters The filters to be used when building the SQL query;
  *   note, these must be valid fields in the database schema of the model
  *   (or an error is thrown). The values of this filters must also match the
  *   expected type (indicated in the model database schema)
  * @param int|mixed $limit Used to specify a limit for the number of models to
  *   fetch.
  */
 protected function _fetch_and_cache_db_records($filters = array(), $limit = null)
 {
     // validate the filters before we begin
     $this->_validate_filters($filters);
     // now, begin the search
     Database::connect();
     // add all of the filters to the query
     foreach ($filters as $name => $value) {
         Database::where($name, $value);
     }
     // finally, fetch the results
     $fields = array('id');
     if (is_integer($limit)) {
         $results = Database::get($this->_model_object->get_db_table(), $limit, $fields);
     } else {
         $results = Database::get($this->_model_object->get_db_table(), false, $fields);
     }
     // make sure we don't leave any hanging connections
     Database::disconnect();
     // now, cache the results
     if (empty($results)) {
         return;
     }
     // first, pluck the id's from results
     $ids = array_pluck('id', $results);
     // finally, instantiate new models for each result that was fetched
     $class_name = $this->get_model_class();
     $this->_data = array();
     foreach ($ids as $id) {
         $this->_data[] = new $class_name($id);
     }
 }
 public function save_sitemap($sitemap)
 {
     try {
         if (is_int($this->sitemap_id)) {
             throw new Exception("No sitemap id set");
         }
         $db = new Database();
         $db->where(array('id' => $this->sitemap_id))->update('sitemaps', array('sitemap' => $sitemap, 'date_modified' => date('Y-m-d H:i:s')));
         $r = $db->select('id')->getwhere('sitemaps', array('section' => basename(APPPATH), 'name' => 'admin-sitemap'));
         if ($r->count()) {
             $search = array('/page/' => '/apage/');
             $admin = str_replace(array_keys($search), array_values($search), $sitemap);
             $db->where(array('id' => $r->current()->id))->update('sitemaps', array('sitemap' => $admin, 'date_modified' => date('Y-m-d H:i:s')));
         }
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Example #21
0
 /**
  * Deletes the database record from memory.
  *
  * Please note: this assumes that the model was either fetched or saved before
  * being called. Otherwise, an error is thrown.
  * @throws Exception
  */
 public function delete()
 {
     $primary_key = $this->get_db_primary_key();
     $data = $this->get_data();
     if (!array_key_exists($primary_key, $data)) {
         trigger_error('Cannot delete this model; it was not saved', E_USER_ERROR);
         return;
     }
     Database::connect();
     Database::where($primary_key, $data[$primary_key]);
     Database::delete($this->get_db_table());
     Database::disconnect();
 }
Example #22
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
 * Switchboard - a Moded version of ESL... all the real work was done by the team that made ESL :)
 *
 * @author Mell Rosandich
 * @license LGPL
 * @package Switchboard
 * @contact mell@ourace.com
 */
// need to load all the Data for devices/trunks/voicemails.
$swdb = new Database();
$swdb->from('device');
$swdb->select('name,context_id,device_id,plugins');
$swdb->where('account_id', users::getAttr('account_id'));
$result = $swdb->get();
$DeviceRows = $result->as_array();
$swdb->from('trunk');
$swdb->select('name,trunk_id,server,plugins');
$swdb->where('account_id', users::getAttr('account_id'));
$result = $swdb->get();
$TrunkRows = $result->as_array();
$swdb->from('voicemail');
$swdb->select('name,voicemail_id,mailbox');
$swdb->where('account_id', users::getAttr('account_id'));
$result = $swdb->get();
$VoircemailRows = $result->as_array();
$swdb->from('context');
$swdb->select('context_id,account_id');
$swdb->where('account_id', users::getAttr('account_id'));
Example #23
0
 public function cronjob()
 {
     $db = new Database();
     //$query = $db->select('*')->from('order')->where("cronjob = 'pending' AND DATE_ADD(create_at, INTERVAL 1 DAY)")->get();
     $query = $db->select('*')->from('order')->where("cronjob = 'pending'")->get();
     foreach ($query as $item) {
         //echo "----".$item->id_order."*********";
         /*$q = $db->select('*')->from('order_products')->where("product_order=".$item->id_order)->get();
           foreach ($q as $r) {
               echo($r->product_name_order);
           }*/
         $db->where(array('id_order' => $item->id_order));
         $db->update('order', array('cronjob' => 'finished'));
     }
 }