Exemple #1
0
function _log_focus($openid, $operation, $user_info = NULL)
{
    R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
    R::selectDatabase('wechat_csc');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    try {
        $user = R::getRedBean()->dispense('wxcsc_focus');
        $user->openid = $openid;
        $user->operation = $operation;
        if ($operation == 'focus' && $user_info != NULL) {
            $user->nickname = $user_info['nickname'];
            $user->sex = $user_info['sex'];
            $user->language = $user_info['language'];
            $user->city = $user_info['city'];
            $user->province = $user_info['province'];
            $user->country = $user_info['country'];
        }
        $user_id = R::store($user);
    } catch (Exception $e) {
        header('Content-type:text/json;charset=utf-8');
        echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
        die;
    }
    R::close();
}
Exemple #2
0
 public function select($group)
 {
     $this->host = $this->config[$group]['hostname'];
     $this->user = $this->config[$group]['username'];
     $this->pass = $this->config[$group]['password'];
     $this->dbname = $this->config[$group]['database'];
     R::selectDatabase($group);
 }
Exemple #3
0
 public static function loadDatabase($dbFile)
 {
     $path = strpos($dbFile, DIRECTORY_SEPARATOR) === false ? Config::$dbPath . DIRECTORY_SEPARATOR . $dbFile : $dbFile;
     $dsn = 'sqlite:' . $path;
     $key = basename($path);
     R::addDatabase($key, $dsn, null, null, true);
     R::selectDatabase($key);
     R::exec('PRAGMA foreign_keys=ON');
     R::exec('PRAGMA temp_store=MEMORY');
 }
 public static function joomla($prefix, $facade = null)
 {
     $app = JFactory::getApplication();
     if ($app->getCfg('dbtype') == 'mysqli') {
         $type = 'mysql';
     } else {
         $type = $app->getCfg('dbtype');
     }
     if (is_null($facade)) {
         R::addDatabase('joomla', $type . ':' . 'host=' . $app->getCfg('host') . ';' . 'dbname=' . $app->getCfg('db'), $app->getCfg('user'), $app->getCfg('password'));
         R::selectDatabase('joomla');
         R::prefix($prefix);
     } else {
         $facade::addDatabase('joomla', $type . ':' . 'host=' . $app->getCfg('host') . ';' . 'dbname=' . $app->getCfg('db'), $app->getCfg('user'), $app->getCfg('password'));
         $facade::selectDatabase('joomla');
         $facade::prefix($prefix, $facade);
     }
 }
Exemple #5
0
function activate_driver($d)
{
    R::selectDatabase($d);
}
Exemple #6
0
    exit('Ldap bind failed');
}
$user_dn = 'cn=' . $user_name . ',ou=people,dc=gds-services,dc=com';
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
$ldap_bd = ldap_bind($ldap_conn, $user_dn, $user_pass);
if (!$ldap_bd) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'invalid user']);
    ldap_close($ldap_conn);
    die;
}
ldap_close($ldap_conn);
// Save
R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
R::selectDatabase('wechat_pe');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user_exists = R::find('wxpe_users', 'openid = :openid', [':openid' => $user_openid]);
    $user_exists = array_filter($user_exists);
    if (empty($user_exists)) {
        $user_new = R::getRedBean()->dispense('wxpe_users');
        $user_new->openid = $user_openid;
        $user_new->phone = '';
        $user_new->email = $user_name;
        $user_new->extra = $user_pass;
        $user_new_id = R::store($user_new);
    } else {
Exemple #7
0
 public function __call($func, $args)
 {
     R::selectDatabase($this->key);
     $func = "R::{$func}";
     return call_user_func_array($func, $args);
 }
Exemple #8
0
 /**
  * 
  * @param string $dbname
  * @param boolean $frozen
  * @return void
  */
 protected static function RedBeanConnect($dbname, $frozen = true)
 {
     require_once implode(DIRECTORY_SEPARATOR, [ROOT_DIR, 'Library', 'database', 'rb.php']);
     $dbConfig = static::$dbConfig;
     switch (strtoupper($dbConfig->type)) {
         case 'SQLITE':
             $dns = "sqlite:/tmp/{$dbname}.sqlite3";
             $dbConfig->user = $dbConfig->password = null;
             break;
         case 'MARIA':
             $dns = "mysql:host={$dbConfig->host};dbname={$dbname}";
             break;
         case 'POSTGRESQL':
             $dns = "pgsql:host={$dbConfig->host};dbname={$dbname}";
             break;
         case null:
         default:
             $dns = null;
             $dbConfig->user = $dbConfig->password = null;
     }
     if (isset(R::$toolboxes[$dbname])) {
         R::selectDatabase($dbname);
     } else {
         R::addDatabase($dbname, $dns, $dbConfig->user, $dbConfig->password, $frozen);
         R::selectDatabase($dbname);
     }
     R::setAutoResolve();
     R::fancyDebug(DEBUG);
 }
Exemple #9
0
        $relate_6->yidong_code = $run_type . $run_time . '-' . $dc_id;
        $relate_6->zhanshileixing = 0;
        $relate_6->guanlianname = '客户用电较上月浮动最大Top5';
        $relate_6->yidongmiaoshu = json_encode($top5, JSON_UNESCAPED_UNICODE);
        $relate_6->guanlianzhi = $run_time;
        if (R::store($relate_6) <= 0) {
            exit('DB relate_6 insert failed \\n');
        }
    }
} catch (Exception $e) {
    exit('DB relate_6 insert failed \\n' . $e->getMessage());
}
R::close();
/* 写入运行日志 */
R::addDatabase('config', $GLOBALS['db_config_url'], $GLOBALS['db_config_user'], $GLOBALS['db_config_pass']);
R::selectDatabase('config');
if (!R::testConnection()) {
    exit('DB config connect failed \\n' . $e->getMessage());
}
R::freeze(TRUE);
try {
    $run_log = R::getRedBean()->dispense('sys_run_log');
    $run_log->alarm_type = $run_type;
    $run_log->last_run = $run_time;
    if (R::store($run_log) <= 0) {
        exit('DB config insert failed \\n');
    }
} catch (Exception $e) {
    exit('DB config insert failed \\n' . $e->getMessage());
}
R::close();
R::selectDatabase('kayako');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user = R::getRow('     SELECT su.userid,' . '            su.fullname, ' . '            sm.email,' . '            su.phone,' . '            su.userorganizationid,' . '            so.organizationname ' . '       FROM kayako_fusion.swusers su' . ' INNER JOIN kayako_fusion.swuseremails sm' . '         ON su.userid = sm.linktypeid' . '        AND sm.linktype = 1' . ' INNER JOIN kayako_fusion.swuserorganizations so' . '         ON so.userorganizationid = su.userorganizationid' . '      WHERE email = :email', [':email' => $user_name]);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]);
    die;
}
R::close();
// Save frequent people
R::addDatabase('supportsr', $GLOBALS['db_supportsr_url'], $GLOBALS['db_supportsr_user'], $GLOBALS['db_supportsr_pass']);
R::selectDatabase('supportsr');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    R::begin();
    foreach ($people_array as $people) {
        $person_old = R::getCell(' SELECT id ' . '   FROM supportsr.esr_frequent_people ' . '  WHERE name = :name ' . '    AND paper_number = :p_number ', [':name' => $people->pname, ':p_number' => $people->pidval]);
        if (empty($person_old) || $person_old == "") {
            $person_new = R::getRedBean()->dispense('esr_frequent_people');
            $person_new->name = $people->pname;
            $person_new->paper_type = $people->ptype == '身份证' ? '身份证/Id card' : ($people->ptype == '台胞证' ? '台胞证/Efficiency certificate' : ($people->ptype == '护照' ? '护照/Passport' : ($people->ptype == '港澳通行证' ? '港澳通行证/Hong Kong-Macau passport' : ($people->ptype == '驾驶证' ? '驾驶证/Driving license' : ''))));
            $person_new->paper_number = $people->pidval;
            $person_new->comid = $user['organizationname'] . '|*|' . $user['userorganizationid'];
            $person_new_id = R::store($person_new);
Exemple #11
0
<?php

/**
 * Pretest
 *
 * These tests will run before the configuration takes place
 * in the unit test suite (mostly error handling tests).
 *
 * @file    RedUNIT/Pretest.php
 * @desc    Test scripts that run before configuration
 * @author  Gabor de Mooij and the RedBeanPHP Community
 * @license New BSD/GPLv2
 *
 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
 * This source file is subject to the New BSD/GPLv2 License that is bundled
 * with this source code in the file license.txt.
 */
testpack('Running pre-tests. (before config).');
try {
    R::debug(TRUE);
    fail();
} catch (Exception $e) {
    pass();
}
asrt(R::testConnection(), FALSE);
R::addDatabase('broken', 'mysql:host=nowhere', 'defunct', 'void');
R::selectDatabase('broken');
asrt(R::testConnection(), FALSE);
function get_pe_wechat($staff_email)
{
    // Wechat PE
    //R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
    R::selectDatabase('wechat_pe');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    if (TEST_SEND) {
        $staff_email = DEBUG_EMAIL;
    }
    $email_prefix = explode("@", $staff_email);
    try {
        $openids = R::getAll(' SELECT openid ' . '   FROM wechat_pe.wxpe_users ' . '  WHERE email = :email_1 ' . '     OR email = :email_2 ', [':email_1' => $email_prefix[0], ':email_2' => ucfirst($email_prefix[0])]);
    } catch (Exception $e) {
        die(json_encode(['result' => 'failed', 'error' => 'db error wechat_pe', 'details' => $e->getMessage()]));
    }
    R::close();
    return $openids;
}
Exemple #13
0
R::selectDatabase("D1");
R::wipe('bottle');
foreach (R::dispense('bottle', 5) as $bottle) {
    R::store($bottle);
}
R::selectDatabase("D2");
R::wipe('bottle');
foreach (R::dispense('bottle', 3) as $bottle) {
    R::store($bottle);
}
R::selectDatabase("D1");
asrt(intval(R::getCell('select count(*) from bottle')), 5);
R::selectDatabase("D2");
asrt(intval(R::getCell('select count(*) from bottle')), 3);
asrt(count(R::findAndExport('bottle')), 3);
R::selectDatabase("D1");
asrt(count(R::findAndExport('bottle')), 5);
testpack("Facade Basics");
R::setup("sqlite:/tmp/teststore.txt");
//should work as well
pass();
R::exec("select 123");
pass();
unlink("/tmp/teststore.txt");
asrt(file_exists("/tmp/teststore.txt"), FALSE);
R::setup("sqlite:/tmp/teststore.txt");
asrt(R::$redbean instanceof RedBean_OODB, TRUE);
asrt(R::$toolbox instanceof RedBean_Toolbox, TRUE);
asrt(R::$adapter instanceof RedBean_Adapter, TRUE);
asrt(R::$writer instanceof RedBean_QueryWriter, TRUE);
$book = R::dispense("book");
function logresult($userid, $text)
{
    R::selectDatabase('localdb');
    R::begin();
    $logtext = "";
    if (is_array($text)) {
        foreach ($text as $value) {
            $logtext .= $value . "; ";
        }
    } else {
        $logtext = $text;
    }
    $logtext = strip_tags($logtext);
    $sent = R::dispense('sent');
    $sent->number = $userid;
    $sent->text = $logtext;
    R::store($sent);
    R::commit();
    R::selectDatabase('default');
}
Exemple #15
0
require 'api_rb.php';
require 'api_db.php';
// Query get name, title, skill
try {
    $db = new PDO($GLOBALS['db_remedy_url'], $GLOBALS['db_remedy_user'], $GLOBALS['db_remedy_pass'], array(PDO::ATTR_PERSISTENT => true));
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = $db->prepare(' SELECT Distinct remedy_login_id ' . '   FROM CTM_PeopleUserSupportGroupFunc ' . '  WHERE Functional_Role = \'Work Order Assignee\' ' . '    AND Organization = \'数据中心服务部\' ', [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
    $sql->execute();
    $staff_dcs_accounts = $sql->fetchAll(PDO::FETCH_ASSOC);
    $staff_dcs_account_vals = array_column($staff_dcs_accounts, 'remedy_login_id');
    $sql = null;
} catch (PDOException $e) {
    exit('DB remedy select failed \\n' . $e->getMessage());
}
R::addDatabase('portal', $GLOBALS['db_portal_url'], $GLOBALS['db_portal_user'], $GLOBALS['db_portal_pass']);
R::selectDatabase('portal');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    if (!empty($staff_dcs_account_vals)) {
        $staff_dcss = R::getAll('SELECT name        AS fullname, ' . '       email       AS email, ' . '       cell_phone  AS mobilenumber' . '  FROM gdsportal.auth_user ' . ' WHERE username IN (' . R::genSlots($staff_dcs_account_vals) . ')', $staff_dcs_account_vals);
    }
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]);
    die;
}
R::close();
// Return
Exemple #16
0
require 'api_rb.php';
require 'api_db.php';
session_start();
$user_name = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
$user_openid = isset($_SESSION['openid']) ? $_SESSION['openid'] : '';
// Log
_log(json_encode(['user_name' => $user_name, 'user_openid' => $user_openid]));
// Check
if (empty($user_name) || empty($user_openid)) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
    die;
}
// Valid
R::addDatabase('wechat', $GLOBALS['db_wechat_url'], $GLOBALS['db_wechat_user'], $GLOBALS['db_wechat_pass']);
R::selectDatabase('wechat');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Unbind
try {
    $user_exists = R::find('wxcsc_users', 'openid = :openid', [':openid' => $user_openid]);
    $user_exists = array_filter($user_exists);
    if (!empty($user_exists)) {
        foreach ($user_exists as $user_exist) {
            R::trash($user_exist);
        }
    }
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
Exemple #17
0
R::selectDatabase('portal');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $staff_skills = R::getRow('    SELECT s2.name AS staff_name,' . '           IFNULL(dict.text, "-") AS job_title,' . '           IFNULL(s2.img_url, "") AS staff_photo,' . '           IFNULL(GROUP_CONCAT(",", k.name), "-") AS skill_name,' . '           0 AS rate_score,' . '           0 AS experience_count' . '      FROM portal.p_stuff s2' . ' LEFT JOIN p_dict_info dict' . '        ON dict.value = s2.station' . '       AND dict.dict_name = "PEOPLE_STATION"' . ' LEFT JOIN portal.p_stuff_skill_r r' . '        ON s2.id = r.stuff_id' . ' LEFT JOIN portal.p_skill k' . '        ON r.skill_id = k.id' . '     WHERE s2.name = :staff_name' . '  GROUP BY s2.name,' . '           s2.station,' . '           s2.img_url' . '     LIMIT 1', [':staff_name' => $staff_id_or_name]);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]);
    die;
}
R::close();
// Query rating and experience count
R::addDatabase('kayako', $GLOBALS['db_kayako_url'], $GLOBALS['db_kayako_user'], $GLOBALS['db_kayako_pass']);
R::selectDatabase('kayako');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $staff_rate_score = R::getCell('     SELECT AVG(rating_result) AS rate_score' . '       FROM supportsr.esr_workorder_assignee_rating r' . '      WHERE r.workorder_assignee = :workorder_assignee' . '   GROUP BY r.workorder_assignee', [':workorder_assignee' => $staff_id_or_name]);
    _log(json_encode(['staff_rate_score' => $staff_rate_score]));
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]);
    die;
}
if (empty($staff_rate_score) || $staff_rate_score == NULL) {
    $staff_rate_score = 4.0;
}
Exemple #18
0
 public function index()
 {
     $errors = array();
     $info = array();
     $config_ok = false;
     $post = $this->input->post();
     $install = $this->input->post('install');
     $this->load->config('mapigniter');
     $defaults = array('private_data_path' => realpath('../' . $this->config->item('private_data_path')) . '/', 'public_data_path' => realpath('../' . $this->config->item('public_data_path')) . '/', 'cache_file_path' => realpath('../' . $this->config->item('cache_file_path')) . '/', 'mapserver_path' => $this->config->item('mapserver_path'), 'mapserver_cgi' => $this->config->item('mapserver_cgi'), 'psql_path' => $this->config->item('psql_path'), 'shp2pgsql_path' => $this->config->item('shp2pgsql_path'), 'ticket_email_origin' => $this->config->item('ticket_email_origin'), 'ticket_email_name' => $this->config->item('ticket_email_name'), 'ticket_email_subject' => $this->config->item('ticket_email_subject'), 'cache_expire' => $this->config->item('cache_expire'), 'cache_on' => $this->config->item('cache_on'), 'db_default_dbdriver' => 'postgre', 'db_default_database' => 'mapigniter', 'db_default_hostname' => 'localhost', 'db_default_username' => 'mapigniter', 'db_default_password' => 'postgres', 'db_userdata_dbdriver' => 'postgre', 'db_userdata_database' => 'mapigniterdata', 'db_userdata_hostname' => 'localhost', 'db_userdata_username' => 'mapigniter', 'db_userdata_password' => 'postgres');
     // Setup form defaults
     foreach ($defaults as $key => $value) {
         if (empty($post[$key])) {
             $post[$key] = $value;
         }
     }
     try {
         // Check MapServer
         $cmd = $post['mapserver_path'] . ' -v ';
         $info['mapserver_path'] = "Detecting MapServer with: {$cmd}";
         exec($cmd, $msoutput);
         //$info[] = implode('<br />', $msoutput);
         $regex = preg_match('/MapServer version \\d+\\.\\d+/i', implode(" ", $msoutput), $matches);
         if (!$regex) {
             $errors['mapserver_path'] = 'MapServer was not detected.';
         }
         // Check if can be called by configured url
         $info['mapserver_cgi'] = "Detecting MapServer at url: " . $post['mapserver_cgi'];
         $mapserver_cgi = trim(@file_get_contents($post['mapserver_cgi']));
         //$info[] = $mapserver_cgi;
         if ($mapserver_cgi !== 'No query information to decode. QUERY_STRING is set, but empty.') {
             $errors['mapserver_cgi'] = 'MapServer is not responding at url: ' . $post['mapserver_cgi'];
         }
         // Check PostgreSQL
         $cmd = $post['psql_path'] . ' --version';
         $info['postgresql'] = "Detecting PostgreSQL with: {$cmd}";
         exec($cmd, $pgoutput);
         //$info[] = implode('<br />', $pgoutput);
         $regex = preg_match('/psql \\(PostgreSQL\\) \\d+\\.\\d+\\.\\d+/i', implode(" ", $pgoutput), $matches);
         if (!$regex) {
             $errors['postgresql'] = 'PostgreSQL was not detected.';
         }
         // Check shp2pgsql tool
         $cmd = $post['shp2pgsql_path'];
         $info['shp2pgsql_path'] = "Detecting shp2pgsql with: {$cmd}";
         exec($cmd, $shp2pgoutput);
         //$info[] = htmlentities(implode('<br />', $shp2pgoutput));
         $regex = preg_match('/RELEASE\\: \\d+\\.\\d+/i', implode(" ", $shp2pgoutput), $matches);
         if (!$regex) {
             $errors['shp2pgsql_path'] = 'shp2pgsql was not detected.';
         }
         // Check php5-psql
         $info['php5_pgsql'] = "Detecting php5-pgsql with extension_loaded()";
         if (!extension_loaded('pgsql')) {
             $errors['php5_pgsql'] = 'php5-pgsql extension was not detected.';
         }
         // Check php5-curl
         $info['php5_curl'] = "Detecting php5-curl with extension_loaded()";
         if (!extension_loaded('curl')) {
             $errors['php5_curl'] = 'php5-curl extension was not detected.';
         }
         // Check php5-gd
         $info['php5_gd'] = "Detecting php5-gd with extension_loaded()";
         if (!extension_loaded('gd')) {
             $errors['php5_gd'] = 'php5-gd extension was not detected.';
         }
         // Check if private data folder is writeable
         $private_data_path = $post['private_data_path'];
         $info['private_data_path'] = "Checking private data folder: {$private_data_path} ...";
         $private_folder = is_writable($private_data_path);
         if (!$private_folder) {
             $errors['private_data_path'] = 'The private data folder (' . $private_data_path . ') cannot be written.';
         }
         // Check if public data folder is writeable
         $data_path = $post['public_data_path'];
         $info['public_data_path'] = "Checking public data folder: {$data_path} ...";
         $writeable = is_writable($data_path);
         if (!$writeable) {
             $errors['public_data_path'] = 'The public data folder (' . $data_path . ') cannot be written.';
         }
         // Check if configuration directory is writeable
         $info['config_path'] = 'Checking for configuration directory...';
         $dir = dirname($this->app_path . '/config/mapigniter.php');
         if (!is_writable($dir)) {
             $errors['config_path'] = 'Cannot create configuration files at ' . $dir;
         }
         // check apache rewrite module
         $info['apache_mod_rewrite'] = 'Checking for apache rewrite module with apache_get_modules()';
         $apache_modules = apache_get_modules();
         if (!in_array('mod_rewrite', $apache_modules)) {
             $errors['apache_mod_rewrite'] = 'Apache module rewrite was not detected';
         }
         // Check if mod_rewrite is active for application folder
         $info['htaccess_override'] = 'Checking if mod_rewrite is enabled for application folder...';
         // Use test controller to test
         $test_url = str_replace('/install/..', '/test', $this->app_url);
         $expected_result = 'test';
         $result = trim(@file_get_contents($test_url));
         if ($result !== $expected_result) {
             $errors['htaccess_override'] = 'Apache mod_rewrite is not working for application folder. Please change Apache configuration.';
         }
         // Check database
         $info['db_default_connect'] = 'Checking application database...';
         $this->load->model('database_model');
         // Setup DB connections
         R::addDatabase('default', "pgsql:host={$post['db_default_hostname']};dbname={$post['db_default_database']}", $post['db_default_username'], $post['db_default_password']);
         R::selectDatabase('default');
         try {
             $tables = $this->database_model->checkSchema();
         } catch (Exception $e) {
             $errors['db_default_connect'] = $e->getMessage();
         }
         // Setup DB connection
         $info['db_userdata_connect'] = 'Checking user data database...';
         R::addDatabase('userdata', "pgsql:host={$post['db_userdata_hostname']};dbname={$post['db_userdata_database']}", $post['db_userdata_username'], $post['db_userdata_password']);
         R::selectDatabase('userdata');
         try {
             $tables = $this->database_model->checkSchema();
         } catch (Exception $e) {
             $errors['db_userdata_connect'] = $e->getMessage();
         }
         // Check postgis on data database
         $info['db_userdata_postgis'] = 'Checking postgis on user data database...';
         R::selectDatabase('userdata');
         try {
             $result = R::getRow('SELECT postgis_full_version()');
         } catch (Exception $e) {
             $errors['db_userdata_postgis'] = 'Postgis was not found in "user data" database. Please add plpgsql, postgis functions and spatial reference table to the database.';
         }
         // Proceed to install if user ordered
         if ($install) {
             // Create configuration files
             $this->saveConfigFiles($post);
             foreach ($post as $k => $v) {
                 $this->config->set_item($k, $v);
             }
             // Install database
             R::selectDatabase('default');
             $this->database_model->install();
         }
         if (empty($errors)) {
             $config_ok = true;
         }
     } catch (Exception $e) {
         $errors['system'] = 'There was at least 1 error when checking system requirements.';
         $errors['system'] = $e->getMessage();
     }
     // Prepare output data
     $data = array('msgs' => array('errors' => $errors, 'info' => $info), 'post' => $post, 'defaults' => $defaults, 'config_ok' => $config_ok, 'install' => !empty($install), 'app_url' => $this->app_url);
     $content = $this->load->view('install', $data, TRUE);
     $this->load->view('layout/default', array('content' => $content));
 }
Exemple #19
0
<?php

use R;
require 'RedUNIT/CUBRID.php';
//Load the CUBRID query writer
require '../RedBeanPHP/QueryWriter/CUBRID.php';
//Define extra test packages from the hook
$extraTestsFromHook = array('CUBRID/Setget', 'CUBRID/Writer');
//Create a connection for this database
$ini['CUBRID'] = array('host' => 'localhost', 'schema' => 'cubase', 'user' => 'dba', 'pass' => '');
$colorMap['CUBRID'] = '0;35';
$dsn = "cubrid:host={$ini['CUBRID']['host']};port=33000;dbname={$ini['CUBRID']['schema']}";
R::addDatabase('CUBRID', $dsn, $ini['CUBRID']['user'], $ini['CUBRID']['pass'], FALSE);
R::selectDatabase('CUBRID');
R::exec('AUTOCOMMIT IS ON');
require 'api_rb.php';
require 'api_db.php';
$workorder_id = isset($_REQUEST['woid']) ? $_REQUEST['woid'] : '';
$plan_date = isset($_REQUEST['d']) ? $_REQUEST['d'] : '';
// Log
_log(json_encode(['workorder_id' => $workorder_id, 'plan_date' => $plan_date]));
// Check
if (empty($workorder_id) || empty($plan_date)) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
    die;
}
// Query
R::addDatabase('dcems', $GLOBALS['db_dcems_url'], $GLOBALS['db_dcems_user'], $GLOBALS['db_dcems_pass']);
R::selectDatabase('dcems');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $workorder_id = str_replace('PI', '', $workorder_id);
    $people_logs = R::getAll('     SELECT b.vr_name AS people,' . '            IFNULL(b.vr_start_date, "-") AS start,' . '            IFNULL(b.vr_end_date, "-") AS end' . '       FROM gdsvisitorrecordorder a' . ' INNER JOIN gdsvisitorrecord b' . '         ON a.id = b.vr_group_id' . '        AND a.otype IS NULL' . '      WHERE (a.workorderid = :workorder_id' . '            OR a.id = :workorder_id_1) ' . '        AND b.vr_stand_date = :date', [':workorder_id' => $workorder_id, ':workorder_id_1' => $workorder_id, ':date' => str_replace('-', '', $plan_date)]);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error dcems', 'details' => $e->getMessage()]);
    die;
}
R::close();
// Return
header('Content-type:text/json;charset=utf-8');
Exemple #21
0
$csc_url_base = 'https://wechat.gds-services.com';
session_start();
$callback = isset($_REQUEST['bcb']) ? $_REQUEST['bcb'] : '';
$openid = isset($_SESSION['openid']) ? $_SESSION['openid'] : (isset($_REQUEST['openid']) ? $_REQUEST['openid'] : '');
_log(json_encode(['openid' => $openid, 'callback' => $callback]));
// Check
if ($openid == '') {
    header('Location: ' . $csc_url_base . '/static/html/user_not_focus_csc.html?bcb=' . $callback . '&rand=' . rand() . '#mp.weixin.qq.com');
    die;
}
if (!isset($_SESSION['openid'])) {
    $_SESSION['openid'] = $openid;
}
// Query
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user_email = R::getCell('SELECT wu.email' . '  FROM wxcsc_users wu' . ' WHERE wu.openid = :openid' . ' LIMIT 1', [':openid' => $openid]);
} catch (Exception $e) {
    header('Location: ' . $csc_url_base . '/static/html/error_message.html?msg=' . urlencode($e->getMesage()) . '&rand=' . rand() . '#mp.weixin.qq.com');
    die;
}
R::close();
_log(json_encode(['openid' => $openid, 'user_email' => $user_email]));
// Error return
if ($user_email == '') {
    if ($callback == 'user_bind_check_csc') {
 public function getExternalTable($mslayer)
 {
     try {
         $tparams = explode(' ', $mslayer->connection);
         foreach ($tparams as &$tparam) {
             $kv = explode('=', $tparam);
             $params[$kv[0]] = $kv[1];
         }
         @preg_match("/from (?P<name>\\w+)/i", $mslayer->data, $matches);
         if (empty($matches)) {
             return false;
         }
         $tablename = $matches[1];
         try {
             $result = R::addDatabase('temp', "pgsql:host={$params['host']};dbname={$params['dbname']}", $params['user'], $params['password']);
             R::selectDatabase('temp');
             $sql = "\n                    SELECT attname FROM pg_attribute, pg_type\n                    WHERE typname = '{$tablename}'\n                    AND attrelid = typrelid\n                    AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')\n                ";
             $result = R::getAll($sql);
             if (!empty($result)) {
                 foreach ($result as $item) {
                     $table['fields'][] = $item['attname'];
                 }
             }
             $sql = "SELECT Find_SRID('public', '{$tablename}', 'the_geom')";
             $result = R::getRow($sql);
             if (!empty($result)) {
                 $table['srs'] = 'EPSG:' . $result['find_srid'];
             } else {
                 $table['error'] = 'Could not get SRID from the_geom field';
             }
             $sql = "SELECT ST_extent(the_geom) from {$tablename}";
             $result = R::getRow($sql);
             if (!empty($result)) {
                 if (empty($result['st_extent'])) {
                     $table['error'] = 'Could not get table EXTENT. Is the table empty?';
                 } else {
                     $pattern = "/BOX\\((.+) (.+),(.+) (.+)\\)/i";
                     @preg_match_all($pattern, $result['st_extent'], $matches);
                     if (!empty($matches)) {
                         $table['extent'] = round($matches[1][0], 3) . ' ' . round($matches[2][0], 3) . ' ' . round($matches[3][0], 3) . ' ' . round($matches[4][0], 3);
                     } else {
                         $table['error'] = 'Could not get table EXTENT';
                     }
                 }
             } else {
                 $table['error'] = 'Could not get table EXTENT';
             }
         } catch (PDOException $e) {
             $table['error'] = $e->getMessage();
         }
     } catch (Exception $e) {
         $table['error'] = $e->getMessage();
     }
     R::selectDatabase('default');
     return $table;
 }