Example #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();
}
Example #2
0
/**
 * Convenience function for test hook.
 * If you added the proper Writer class, the facade should be able
 * to automatically load it, i.e. \RedBeanPHP\QueryWriter\MyWriter
 * 
 * @global array $ini
 * 
 * @param string $name name of the connection (key)
 * @param string $dsn  DSN to connect
 * @param string $user username
 * @param string $pass passwords
 */
function add_writer_to_tests($name, $dsn, $user, $pass)
{
    global $ini;
    \RedUNIT\Base::addToDriverList($name);
    R::addDatabase($name, $dsn, $user, $pass);
    $ini[$name] = true;
}
Example #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);
     }
 }
Example #5
0
 function __construct()
 {
     // Include database configuration
     include APPPATH . 'config/database.php';
     // Get Redbean
     include APPPATH . 'third_party/vendor/rb/rb.php';
     $this->config = $db;
     $this->default = $active_group;
     foreach ($this->config as $name => $group) {
         // Database data
         $host = $group['hostname'];
         $user = $group['username'];
         $pass = $group['password'];
         $dbname = $group['database'];
         // Setup DB connection
         R::addDatabase($name, "pgsql:host={$host};dbname={$dbname}", $user, $pass);
     }
     $this->select($this->default);
 }
Example #6
0
if (!$ldap_conn) {
    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);
function get_notice_prefer_dcs_csc($inner_name, $p_stage)
{
    $prefer_wechat = false;
    $prefer_email = false;
    $prefer_mobile = false;
    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);
    $email_prefix = explode("@", $inner_name);
    try {
        $notice_prefer = R::getRow('SELECT wechat, ' . '       email, ' . '       mobile ' . '  FROM wxpe_notice_prefer ' . ' WHERE (   username = :username_1 ' . '        OR username = :username_2 ) ' . '   AND stage = :stage ', [':username_1' => $email_prefix[0], ':username_2' => ucfirst($email_prefix[0]), ':stage' => $p_stage]);
        if (!empty($notice_prefer)) {
            $prefer_wechat = $notice_prefer['wechat'];
            $prefer_email = $notice_prefer['email'];
            $prefer_mobile = $notice_prefer['mobile'];
        } else {
            _log('Notice prefer of dcs csc [' . $email_prefix[0] . '] @ [' . $p_stage . '] not configed...');
        }
    } catch (Exception $e) {
        die(json_encode(['result' => 'failed', 'error' => 'db error wechat_pe', 'details' => $e->getMessage()]));
    }
    R::close();
    if (TEST_SEND) {
        $prefer_wechat = true;
        $prefer_email = true;
        $prefer_mobile = true;
    }
    return array($prefer_wechat, $prefer_email, $prefer_mobile);
}
Example #8
0
        $relate_6 = R::getRedBean()->dispense('dcom_yidongguanlian');
        $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());
}
<?php

require "config.php";
require "external/rb.php";
R::setup('mysql:host=' . $dbserver . ';dbname=' . $dbname, $dbuser, $dbpassword);
R::freeze(TRUE);
R::debug(TRUE, 2);
R::addDatabase('localdb', 'mysql:host=' . $dbserver . ';dbname=' . $dbname, $dbuser, $dbpassword, TRUE);
R::begin();
require 'actions-web.php';
if (isset($_COOKIE["loguserid"])) {
    $userid = $_COOKIE["loguserid"];
} else {
    $userid = 0;
}
if (isset($_COOKIE["logsession"])) {
    $session = $_COOKIE["logsession"];
}
$action = "";
if (isset($_GET["action"])) {
    $action = trim($_GET["action"]);
}
switch ($action) {
    case "smscode":
        $number = trim($_GET["number"]);
        smscode($number);
        break;
    case "register":
        $number = trim($_GET["validatednumber"]);
        $smscode = trim($_GET["smscode"]);
        $checkcode = trim($_GET["checkcode"]);
Example #10
0
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 {
    $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;
Example #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);
Example #12
0
function get_dcs_contact($dcs_name)
{
    $dcs_email = '';
    $dcs_phone = '';
    // portal
    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 {
        $dcs = R::getRow('SELECT email, ' . '       cell_phone ' . '  FROM gdsportal.auth_user ' . ' WHERE name = :name ', [':name' => $dcs_name]);
        $dcs_email = $dcs['email'];
        $dcs_phone = $dcs['cell_phone'];
    } catch (Exception $e) {
        die(json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]));
    }
    R::close();
    return array($dcs_email, $dcs_phone);
}
Example #13
0
$abook = array_pop($books["can"]);
asrt("red", $abook->cover);
$books = $r2->cooker($form2);
$abook = array_pop($books["can"]);
asrt("green", $abook->cover);
$r1->associate($book, $page1);
$r2->associate($book2, $page2);
$r1->view("shelf", "book,page");
$a = $r1->getAll("select * from shelf where id = {$id1} ");
$shelf = array_pop($a);
asrt($shelf["title_of_page"], "FIRST");
$r2->view("shelf", "book,page");
$shelf = $r2->getCell("select title_of_page from shelf where id = {$id2} ");
asrt($shelf, "SECOND");
R::addDatabase("D1", "sqlite:/tmp/database_1.txt", "");
R::addDatabase("D2", "sqlite:/tmp/database_2.txt", "");
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);
Example #14
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);
 }
Example #15
0
$hookPath = '';
$colorMap = array('mysql' => '0;31', 'pgsql' => '0;32', 'sqlite' => '0;34');
@(include 'cli/test_hook.php');
//Configure the databases
if (isset($ini['mysql'])) {
    $dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
    R::addDatabase('mysql', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE);
    R::selectDatabase('mysql');
    R::exec(' SET GLOBAL sql_mode="" ');
}
if (isset($ini['pgsql'])) {
    $dsn = "pgsql:host={$ini['pgsql']['host']};dbname={$ini['pgsql']['schema']}";
    R::addDatabase('pgsql', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE);
}
if (isset($ini['sqlite'])) {
    R::addDatabase('sqlite', 'sqlite:' . $ini['sqlite']['file'], NULL, NULL, FALSE);
}
R::selectDatabase('sqlite');
// Function to activate a driver
function activate_driver($d)
{
    R::selectDatabase($d);
}
$arguments = $_SERVER['argc'];
$mode = 'all';
if ($arguments > 1) {
    $mode = $_SERVER['argv'][1];
}
$classSpec = null;
if ($arguments > 2) {
    $classSpec = $_SERVER['argv'][2];
Example #16
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();
Example #17
0
}
/* 3、时间关联供应商清单 */
try {
    $sql = $db->prepare('SELECT cChr_INCID AS relate_id,                                                                                   /* 事件编号 */' . '       cChr_VendorName,                                                                                           /* 供应商名称 */' . '       CASE' . '           WHEN cDT_NotifyToVendorTime IS NULL THEN \'-\'' . '           ELSE CONVERT(VARCHAR(19), DATEADD(s, cDT_NotifyToVendorTime+ 8 * 3600, \'1970-01-01 00:00:00\'), 121)' . '       END AS vender_noticed,                                                                                     /* 通知供应商时间 */' . '       CASE' . '           WHEN cDT_VendorArrivedTime IS NULL THEN \'-\'' . '           ELSE CONVERT(VARCHAR(19), DATEADD(s, cDT_VendorArrivedTime+ 8 * 3600, \'1970-01-01 00:00:00\'), 121)' . '       END AS vender_arrived,                                                                                     /* 供应商到场时间 */' . '       CASE' . '           WHEN cDT_SparePartsArrivedTime IS NULL THEN \'-\'' . '           ELSE CONVERT(VARCHAR(19), DATEADD(s, cDT_SparePartsArrivedTime+ 8 * 3600, \'1970-01-01 00:00:00\'), 121)' . '       END AS parts_arrived,                                                                                      /* 配件到场时间 */' . '       cDpl_VendorSLABreach                                                                                       /* 是否违反SLA *//* 0-违反,1-违反 */' . '  FROM GDS_VendorMaintenanceRecord' . '  WHERE cChr_INCID IN (\'' . implode('\',\'', $event_ids) . '\')', [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
    $sql->execute();
    $event_vendors = $sql->fetchAll(PDO::FETCH_ASSOC);
    $sql = null;
    $db = null;
} catch (PDOException $e) {
    exit('DB remedy select failed \\n' . $e->getMessage());
}
$db = null;
SAVE:
/* 写入:报警信息 */
/* XXX数据中心YY客户发生z级事件 */
R::addDatabase('alarm', $GLOBALS['db_alarm_url'], $GLOBALS['db_alarm_user'], $GLOBALS['db_alarm_pass']);
R::selectDatabase('alarm');
if (!R::testConnection()) {
    exit('DB alarm connect failed \\n' . $e->getMessage());
}
R::freeze(TRUE);
try {
    foreach ($event_lvl1n2 as $event) {
        $alarm = R::getRedBean()->dispense('dcom_yidong');
        $alarm->yidong_code = $run_type . $run_time . '-' . $event['relate_id'];
        $alarm->fullname = $event['dc_name'];
        $alarm->yidong_miaoshu = $event['dc_name'] . ' ' . $event['customer_name'] . ' 发生 ' . $event['threshold'] . ' 级事件';
        $alarm->yidong_level = '请高度关注';
        $alarm->yidong_type = '客户SLA';
        $alarm->create_time = $run_time;
        if (R::store($alarm) <= 0) {
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 {
    $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'];
Example #19
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));
 }
Example #20
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');
Example #21
0
<?php

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
Example #22
0
$csc_host_base = 'https://wechat.gds-services.com';
$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 == '') {
 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;
 }