public static function get_Size($pdo_connection, $catalog_id) { $db_name = FileConfig::get_Value('db_name', $catalog_id); switch (CDB::getDriverName()) { case 'mysql': // Return N/A for MySQL server prior version 5 (no information_schemas) if (version_compare(CDB::getServerVersion(), '5.0.0') >= 0) { // Prepare SQL statment $statment = array('table' => 'information_schema.TABLES', 'fields' => array("table_schema AS 'database', (sum( data_length + index_length) / 1024 / 1024 ) AS 'dbsize'"), 'where' => array("table_schema = '{$db_name}'"), 'groupby' => 'table_schema'); $result = CDBUtils::runQuery(CDBQuery::get_Select($statment, $pdo_connection), $pdo_connection); $db_size = $result->fetch(); $db_size = $db_size['dbsize'] * 1024 * 1024; return CUtils::Get_Human_Size($db_size); } else { echo 'Not supported (' . CDB::getServerVersion() . ') <br />'; } break; case 'pgsql': $statment = "SELECT pg_database_size('{$db_name}') AS dbsize"; $result = CDBUtils::runQuery($statment, $pdo_connection); $db_size = $result->fetch(); return CUtils::Get_Human_Size($db_size['dbsize']); break; case 'sqlite': $db_size = filesize(FileConfig::get_Value('db_name', $catalog_id)); return CUtils::Get_Human_Size($db_size); break; } }
public static function getConnectionStatus($PDO_connection) { // If MySQL of postGreSQL if (CDB::getDriverName() != 'sqlite') { return $PDO_connection->getAttribute(PDO::ATTR_CONNECTION_STATUS); } else { return 'N/A'; } }
public static function connect($dsn, $user = null, $password = null, $options = array()) { try { if (is_null(self::$connection)) { self::$connection = new PDO($dsn, $user, $password); } } catch (PDOException $e) { CErrorHandler::displayError($e); } return self::$connection; }
public static function get_Timestamp_Interval($period_timestamp = array()) { $period = array(); switch (CDB::getDriverName()) { case 'pgsql': $period['starttime'] = "TIMESTAMP '" . date("Y-m-d H:i:s", $period_timestamp[0]) . "'"; $period['endtime'] = "TIMESTAMP '" . date("Y-m-d H:i:s", $period_timestamp[1]) . "'"; break; default: $period['starttime'] = "'" . date("Y-m-d H:i:s", $period_timestamp[0]) . "'"; $period['endtime'] = "'" . date("Y-m-d H:i:s", $period_timestamp[1]) . "'"; break; } // end switch return $period; }
$days_stored_files[] = array(date("m-d", $day['start']), Jobs_Model::getStoredFiles($dbSql->db_link, array($day['start'], $day['end']))); } unset($graph); $graph = new CGraph("dashboard-graph04.jpg"); $graph->SetData($days_stored_files, 'bars'); // Graph rendering $view->assign('graph_stored_files', $graph->Render()); unset($graph); // ============================================================== // Last used volumes widget // ============================================================== $last_volumes = array(); // Building SQL statment $where = array(); $tmp = "(Media.Volstatus != 'Disabled') "; switch (CDB::getDriverName()) { case 'mysql': case 'pgsql': $tmp .= "AND (Media.LastWritten IS NOT NULL)"; break; case 'sqlite': $tmp .= "AND (Media.Lastwritten != 0)"; break; } $where[] = $tmp; $statment = array('table' => 'Media', 'fields' => array('Media.MediaId', 'Media.Volumename', 'Media.Lastwritten', 'Media.VolStatus', 'Media.VolJobs', 'Pool.Name AS poolname'), 'join' => array('table' => 'Pool', 'condition' => 'Media.PoolId = Pool.poolid'), 'where' => $where, 'orderby' => 'Media.Lastwritten DESC', 'limit' => '10'); // Run the query $result = CDBUtils::runQuery(CDBQuery::get_Select($statment), $dbSql->db_link); foreach ($result as $volume) { $last_volumes[] = $volume; }
public function __construct(&$view) { // Loading configuration file parameters try { if (!FileConfig::open(CONFIG_FILE)) { throw new Exception("The configuration file is missing"); } else { $this->catalog_nb = FileConfig::count_Catalogs(); } } catch (Exception $e) { CErrorHandler::displayError($e); } // Template engine initalization $this->view = $view; // Checking template cache permissions if (!is_writable(VIEW_CACHE_DIR)) { throw new Exception("The template cache folder <b>" . VIEW_CACHE_DIR . "</b> must be writable by Apache user"); } // Initialize smarty gettext function $language = FileConfig::get_Value('language'); if (!$language) { throw new Exception("Language translation problem"); } $this->translate = new CTranslation($language); $this->translate->set_Language($this->view); // Get catalog_id from http $_GET request if (!is_null(CHttpRequest::get_Value('catalog_id'))) { if (FileConfig::catalogExist(CHttpRequest::get_Value('catalog_id'))) { $this->catalog_current_id = CHttpRequest::get_Value('catalog_id'); $_SESSION['catalog_id'] = $this->catalog_current_id; } else { $_SESSION['catalog_id'] = 0; $this->catalog_current_id = 0; throw new Exception('The catalog_id value provided does not correspond to a valid catalog, please verify the config.php file'); } } else { if (isset($_SESSION['catalog_id'])) { // Stick with previously selected catalog_id $this->catalog_current_id = $_SESSION['catalog_id']; } } // Define catalog id and catalog label $this->view->assign('catalog_current_id', $this->catalog_current_id); $this->view->assign('catalog_label', FileConfig::get_Value('label', $this->catalog_current_id)); // Getting database connection paremeter from configuration file $dsn = FileConfig::get_DataSourceName($this->catalog_current_id); $driver = FileConfig::get_Value('db_type', $this->catalog_current_id); $user = ''; $pwd = ''; if ($driver != 'sqlite') { $user = FileConfig::get_Value('login', $this->catalog_current_id); $pwd = FileConfig::get_Value('password', $this->catalog_current_id); } switch ($driver) { case 'mysql': case 'pgsql': $this->db_link = CDB::connect($dsn, $user, $pwd); break; case 'sqlite': $this->db_link = CDB::connect($dsn); break; } // Getting driver name from PDO connection $this->db_driver = CDB::getDriverName(); // Set PDO connection options $this->db_link->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $this->db_link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->db_link->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('CDBResult', array($this))); // MySQL connection specific parameter if ($driver == 'mysql') { $this->db_link->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } // Bacula catalog selection if ($this->catalog_nb > 1) { // Catalogs list $this->view->assign('catalogs', FileConfig::get_Catalogs()); // Catalogs count $this->view->assign('catalog_nb', $this->catalog_nb); } }
} $this->dbg->add_line("process end"); $this->dbg->add_line("state: " . $this->state->get_state('mode')); } } /* $dbconfig = array( 'host'=>'sql208.0fees.net', 'db_name'=>'fees0_3157581_filmohren', 'user'=>'fees0_3157581', 'password'=>'3mk8a9'); */ $dbconfig = array('host' => 'localhost', 'db_name' => 'db_filmohren', 'user' => 'root', 'password' => ''); $cmd = new CCommander(); $dbg = new CMyDebug($cmd, true); $db = new CDB($dbconfig, $dbg); $proc = NULL; $auth = true; //$resp_arr = array('data'=>'','target'=>'','mode'=>'0'); if ($db->connect()) { $usr = new CUser($dbg); $state = new CState(); $data = array('p' => ''); $state->scan_states(); if (isset($_POST['ball']) && $_POST['ball'] != "") { $dbg->add_line("POST: " . $_POST['ball']); $_POST['ball'] = str_replace("\\", "", $_POST['ball']); $data['p'] = json_decode($_POST['ball'], true); if (isset($data['p']) && is_array($data['p']) && isset($data['p']['data']) && is_array($data['p']['data'])) { $dbg->add_line("decoding successfull..."); $dbg->add_line("sender: " . $data['p']['name']);
<?php include_once '../php_files/model/investiments/CDB.php'; $investiment = new CDB($_GET['initial_value'], $_GET['months']); echo 'R$ ' . $investiment->getGain() . '<br/><br/>'; var_dump($investiment->getValueTaxes());
| as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ */ // Time intervals in secondes define('FIRST_DAY', mktime(0, 0, 0, 1, 1, 1970)); define('DAY', 86400); define('WEEK', 7 * DAY); define('MONTH', 4 * WEEK); // Timestamp constants define('NOW', CDB::getServerTimestamp()); define('LAST_DAY', NOW - DAY); define('LAST_WEEK', NOW - 7 * DAY); define('LAST_MONTH', NOW - 4 * WEEK); // Job status code define('J_NOT_RUNNING', 'C'); define('J_RUNNING', 'R'); define('J_BLOCKED', 'B'); define('J_COMPLETED', 'T'); define('J_COMPLETED_ERROR', 'E'); define('J_NO_FATAL_ERROR', 'e'); define('J_FATAL', 'f'); define('J_CANCELED', 'A'); define('J_WAITING_CLIENT', 'F'); define('J_WAITING_SD', 'S'); define('J_WAITING_NEW_MEDIA', 'm');
public function saveMenuAndRole() { if ($this->_one[$this->_paramKey]) { $roleId = $this->_one[$this->_paramKey]; $this->_one->save(); } else { $this->_one->save(); $roleId = Yii::$app->db->getLastInsertID(); } $menu = CRequest::param("menu"); $select_menus = isset($menu['select_menus']) ? $menu['select_menus'] : ''; # 如果存在role_id 和选择的菜单 if ($roleId && $select_menus) { # 得到当前选择的menu_id和相应的所有上级menu_id $select_menu_ids = $this->getAllParentMenuIds($select_menus); $select_menu_ids = array_unique($select_menu_ids); # AdminRole中role_id 对应的所有 menu_id $role_menu_ids = $this->getDbRoleMenuIds($roleId); # 需要插入的role_id - menu_id 数组差集 $add_role_menu_ids = array_diff($select_menu_ids, $role_menu_ids); # 需要删除的role_id - menu_id 数组差集 $remove_role_menu_ids = array_diff($role_menu_ids, $select_menu_ids); # 事务 插入 和 删除 role_menu 表中,当前role_id 对应的menu_id $table = 'admin_role_menu'; $columnsArr = ['menu_id', 'role_id', 'created_at', 'updated_at']; $valueArr = []; $now_date = date("Y-m-d H:i:s"); if (!empty($add_role_menu_ids)) { foreach ($add_role_menu_ids as $menu_id) { $valueArr[] = [$menu_id, $roleId, $now_date, $now_date]; } } $innerTransaction = Yii::$app->db->beginTransaction(); try { if (!empty($add_role_menu_ids)) { \fec\helpers\CDB::batchInsert($table, $columnsArr, $valueArr); } if (!empty($remove_role_menu_ids)) { $remove_role_menu_id_str = implode(',', $remove_role_menu_ids); $table = AdminRoleMenu::tableName(); $sql = "delete from {$table} where menu_id in ({$remove_role_menu_id_str} ) and role_id = :role_id "; $data = ['role_id' => $roleId]; CDB::deleteBySql($sql, $data); } $innerTransaction->commit(); } catch (Exception $e) { $innerTransaction->rollBack(); } } }