Example #1
0
 /**
  * Provides the services/data_utils/bulk_verify service. This takes a report plus params (json object) in the $_POST
  * data and verifies all the records returned by the report according to the filter. Pass ignore=true to allow this to 
  * ignore any verification check rule failures (use with care!).
  */
 public function bulk_verify()
 {
     $db = new Database();
     $this->authenticate('write');
     $report = $_POST['report'];
     $params = json_decode($_POST['params'], true);
     $params['sharing'] = 'verification';
     $websites = $this->website_id ? array($this->website_id) : null;
     $this->reportEngine = new ReportEngine($websites, $this->user_id);
     try {
         // Load the report used for the verification grid with the same params
         $data = $this->reportEngine->requestReport("{$report}.xml", 'local', 'xml', $params);
         // now get a list of all the occurrence ids
         $ids = array();
         foreach ($data['content']['records'] as $record) {
             if ($record['record_status'] !== 'V' && (!empty($record['pass']) || $_POST['ignore'] === 'true')) {
                 $ids[$record['occurrence_id']] = $record['occurrence_id'];
                 $db->insert('occurrence_comments', array('occurrence_id' => $record['occurrence_id'], 'comment' => 'This record is assumed to be correct', 'created_by_id' => $this->user_id, 'created_on' => date('Y-m-d H:i:s'), 'updated_by_id' => $this->user_id, 'updated_on' => date('Y-m-d H:i:s')));
             }
         }
         $db->from('occurrences')->set(array('record_status' => 'V', 'verified_by_id' => $this->user_id, 'verified_on' => date('Y-m-d H:i:s'), 'updated_by_id' => $this->user_id, 'updated_on' => date('Y-m-d H:i:s')))->in('id', array_keys($ids))->update();
         echo count($ids);
         $db->from('cache_occurrences')->set(array('record_status' => 'V', 'cache_updated_on' => date('Y-m-d H:i:s')))->in('id', array_keys($ids))->update();
     } catch (Exception $e) {
         echo $e->getMessage();
         error::log_error('Exception during bulk verify', $e);
     }
 }
Example #2
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 #3
0
 /**
  * Scans the queue to see if we have any items. We need this method because when pcntl_fork() happens, the DB connection gets lost.
  *
  * @return boolean
  */
 public static function has_items()
 {
     // Get the highest priority task in the queue
     $db = new Database();
     $task = $db->from(Kohana::config('queue.table_name'))->orderby('priority', 'DESC')->limit(1)->get()->result(TRUE, __CLASS__);
     if (count($task)) {
         return TRUE;
     }
     return FALSE;
 }
Example #4
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 #5
0
 /**
  * 取得数据,支持批量取
  * @param string/array $key
  * @return mixed
  */
 public function get($key)
 {
     $this->db->from($this->tablename);
     if (\is_array($key)) {
         $key = \array_map('md5', $key);
         $this->db->in('key', $key);
     } else {
         $key = \md5($key);
         $this->db->where('key', $key);
     }
     $data = $this->db->get()->as_array();
     if (\is_array($key)) {
         $new_data = array();
         foreach ($data as $item) {
             $new_data[$item['key_str']] = $item['value'];
         }
         return $new_data;
     } else {
         return $data[0];
     }
 }
 public static function get_next_available_url_identifier(ORM $object, $url_identifier)
 {
     $database = new Database();
     $database->select('COUNT(*)');
     $database->from($object->table_name);
     $database->like('url_identifier', $url_identifier . '%', FALSE);
     $row = $database->get()->result_array(FALSE);
     $count = $row[0]['COUNT(*)'];
     if ($count > 0) {
         $url_identifier .= '-' . ($count + 1);
     }
     return $url_identifier;
 }
 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'];
     }
 }
 /**
  * Build a single form of the given operation. The fields are got from database.
  *
  * @param string operation		// insert, update, delete, view
  * @param integer pk_value
  * @return void
  */
 public function form($operation = '', $pk_value = '')
 {
     // Test permission as form operation
     $this->validate_permission(strtoupper($operation));
     // adjust form operation
     $operation = strtolower($operation);
     // get pk name
     $pk = $this->acme_controller_model->get_pk_name($this->table_name);
     // Form data
     $form = $this->db->get_where('acm_module_form', array('id_module' => $this->id_module, 'operation' => $operation))->row_array(0);
     // Fields
     $fields = $this->db->from('acm_module_form_field f')->where('id_module_form = ' . get_value($form, 'id_module_form') . ' AND dtt_inative IS NULL')->order_by('order_')->get()->result_array();
     // Values
     if ($pk == '' || $pk_value == '') {
         $values = array();
     } else {
         $values = $this->db->get_where($this->table_name, array($pk => $pk_value))->row_array(0);
     }
     // Case form operation is not insert, must validate pk given value
     if ($operation != 'insert' && count($values) <= 0 || get_value($form, 'dtt_inative') != '' || count($fields) <= 0) {
         redirect($this->controller);
     }
     // Adjust fields and put table name on each row
     $count = count($fields);
     for ($i = 0; $i < $count; $i++) {
         $fields[$i]['table_name'] = $this->table_name;
     }
     // Transform array values into html inputs
     $html_fields = $this->form->build_form_fields($fields, $values);
     // view args
     $args['form'] = $form;
     $args['html_fields'] = $html_fields;
     $args['fields'] = $fields;
     $args['values'] = $values;
     $args['operation'] = $operation;
     $args['pk_value'] = $pk_value;
     // Load view
     $this->template->load_view('App_module_manager/ACME_Controller/form-' . $operation, $args);
 }
Example #9
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 #10
0
 /**
  * 重新加载配置
  *
  * @param boolean $from_db 是否强制从数据库中读取,默认true
  * @param string $type 类型
  * @return Core_Config
  */
 public function reload($from_db = true, $type = '')
 {
     $tmp_file = $this->get_config_cache_file(Core::$project, $type);
     if ($this->is_use_cache && !$from_db && is_file($tmp_file)) {
         # 在data目录中直接读取
         $this->config[$type] = @unserialize(file_get_contents($tmp_file));
         if (!is_array($this->config[$type])) {
             $this->config[$type] = array();
         }
     } else {
         # 没有缓存数据,则直接在数据库里获取
         $db = new Database($this->database);
         $config = $db->from($this->tablename)->where('type', $type)->get(false, true)->as_array();
         if ($config) {
             $this->config = array();
             foreach ($config as $item) {
                 $this->config[$item['type']][$item['key_name']] = $this->data_unformat($item['value']);
             }
         } else {
             $this->config = array($type => array());
         }
         if ($this->is_use_cache) {
             // 普通模式下写缓存
             $rs = File::create_file($tmp_file, serialize($this->config));
             if (IS_DEBUG) {
                 Core::debug()->log('save extends config cache ' . ($rs ? 'success' : 'fail') . '.');
             }
         }
     }
 }
Example #11
0
 public function index()
 {
     $this->template->content = new View('admin/plugins');
     $this->template->content->title = 'Addons';
     if (isset($_GET['status']) && !empty($_GET['status'])) {
         $status = $_GET['status'];
         if (strtolower($status) == 'a') {
             $filter = 'plugin_active = 1';
         } elseif (strtolower($status) == 'i') {
             $filter = 'plugin_active = 0';
         } else {
             $status = "0";
             $filter = '1=1';
         }
     } else {
         $status = "0";
         $filter = '1=1';
     }
     // Add the hidden plugins to the list of plugins to filter out
     if (count(Kohana::config('plugins.hide_from_list')) != 0) {
         $filter .= ' AND plugin_name NOT IN (\'' . mysql_real_escape_string(implode('\',\'', Kohana::config('plugins.hide_from_list'))) . '\')';
     }
     $db = new Database();
     // Update the plugin list in the database
     $d = dir(PLUGINPATH);
     $directories = array();
     while (($entry = $d->read()) !== FALSE) {
         // Set the plugin to not enabled by default
         // Don't include hidden folders
         if ($entry[0] != '.') {
             $directories[$entry] = FALSE;
         }
     }
     // Sync the folder with the database
     foreach ($directories as $dir => $found) {
         if (!count($db->from('plugin')->where('plugin_name', $dir)->limit(1)->get())) {
             $plugin = ORM::factory('plugin');
             $plugin->plugin_name = $dir;
             $plugin->save();
         }
     }
     // Remove Any Plugins not found in the plugins folder from the database
     foreach (ORM::factory('plugin')->find_all() as $plugin) {
         if (!array_key_exists($plugin->plugin_name, $directories)) {
             $plugin->delete();
         }
     }
     // 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('comment_id.*', 'required', 'numeric');
         if ($post->validate()) {
             if ($post->action == 'a') {
                 // Activate Action
                 foreach ($post->plugin_id as $item) {
                     $plugin = ORM::factory('plugin', $item);
                     // Make sure we run the installer if it hasnt been installed yet.
                     // Then mark it as installed
                     if ($plugin->loaded and $plugin->plugin_name) {
                         Kohana::config_set('core.modules', array_merge(Kohana::config('core.modules'), array(PLUGINPATH . $plugin->plugin_name)));
                         // Name of the class (First letter of class should be capitalized)
                         $class = ucfirst($plugin->plugin_name) . '_Install';
                         // Find the Library File
                         $path = $this->_find_install($plugin->plugin_name);
                         if ($path) {
                             include $path;
                             // Run the installer
                             $install = new $class();
                             $install->run_install();
                         }
                         // Mark as Active and Mark as Installed
                         $plugin->plugin_active = 1;
                         $plugin->plugin_installed = 1;
                         $plugin->save();
                     }
                 }
             } elseif ($post->action == 'i') {
                 // Deactivate Action
                 foreach ($post->plugin_id as $item) {
                     $plugin = ORM::factory('plugin', $item);
                     if ($plugin->loaded) {
                         $plugin->plugin_active = 0;
                         $plugin->save();
                     }
                 }
             } elseif ($post->action == 'd') {
                 // Delete Action
                 foreach ($post->plugin_id as $item) {
                     $plugin = ORM::factory('plugin', $item);
                     if ($plugin->loaded and $plugin->plugin_name) {
                         Kohana::config_set('core.modules', array_merge(Kohana::config('core.modules'), array(PLUGINPATH . $plugin->plugin_name)));
                         // Name of the class (First letter of class should be capitalized)
                         $class = ucfirst($plugin->plugin_name) . '_Install';
                         // Find the Library File
                         $path = $this->_find_install($plugin->plugin_name);
                         if ($path) {
                             include $path;
                             // Run the uninstaller
                             $install = new $class();
                             $install->uninstall();
                         }
                         // Mark as InActive and Mark as UnInstalled
                         $plugin->plugin_active = 0;
                         $plugin->plugin_installed = 0;
                         $plugin->save();
                     }
                 }
             }
         } else {
             $form_error = TRUE;
         }
     }
     $plugins = ORM::factory('plugin')->where($filter)->orderby('plugin_name', 'ASC')->find_all();
     $this->template->content->plugins = $plugins;
     $this->template->content->total_items = $plugins->count();
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     // Status Tab
     $this->template->content->status = $status;
     // Javascript Header
     $this->template->js = new View('admin/plugins_js');
 }
Example #12
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 #13
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 #14
0
 /**
  * 重新加载配置
  *
  * @param boolean $from_db 是否强制从数据库中读取,默认true
  * @return Core_Config
  */
 public function reload($from_db = true)
 {
     $tmpfile = DIR_DATA . Core::$project . '/extends_config.txt';
     if (!$from_db && is_file($tmpfile)) {
         # 在data目录中直接读取
         $this->config = unserialize(file_get_contents($tmpfile));
         if (!is_array($this->config)) {
             $this->config = array();
         }
     } else {
         # 没有缓存数据,则直接在数据库里获取
         $db = new Database($this->database);
         $config = $db->from($this->tablename)->get(false, true)->as_array();
         if ($config) {
             foreach ($config as $item) {
                 $this->config[$item['type']][$item['key_name']] = @unserialize(gzuncompress($item['value']));
             }
         } else {
             $this->config = array();
         }
         // 写缓存
         File::create_file($tmpfile, serialize($this->config));
     }
 }
 /**
  * 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;
 }
 public function from($tables)
 {
     self::$from = "FROM " . $tables . " ";
     return self::get_instance();
 }
 function one_exists($post, $data)
 {
     $db = new Database();
     $r = $db->from('downloads')->where('lhs_link', $post)->where('status', 1)->where('id!=', $data[1])->get();
     if (count($r) > 0) {
         return false;
     } else {
         return true;
     }
 }