function test_single() { $cmp = new StdClass(); $cmp->foo = 'asdf'; $res = DB::single('select * from test'); $this->assertEquals($cmp, $res); }
/** * @depends test_exists */ function test_update() { // Get the lock info $info = DB::single('select * from #prefix#lock'); // Back to original user id User::$user = (object) array('id' => 1); // Update the lock after one second delay sleep(1); $this->assertEquals(self::$lock->update(), true); $this->assertNotEquals(self::$lock->info(), $info); }
AND (YEAR(date_start) = :thai_year OR YEAR(date_start) = :year) AND data_date = :today '); $start_emp = $db->bind(':year', $year, PDO::PARAM_STR); $start_emp = $db->bind(':month', $month, PDO::PARAM_STR); $start_emp = $db->bind(':thai_year', $year_thai, PDO::PARAM_STR); $start_emp = $db->bind(':today', $today, PDO::PARAM_STR); $start_emp = $db->execute(); $start_emp = $db->rowCount(); $type_emp = $db->query('SELECT COUNT(CASE WHEN emp_type_id = 1 then 1 ELSE NULL END) as "emp", COUNT(CASE WHEN emp_type_id = 2 then 1 ELSE NULL END) as "contract", COUNT(CASE WHEN emp_type_id = 3 then 1 ELSE NULL END) as "part_time" FROM all_ro10_emp WHERE data_date = :today '); $type_emp = $db->bind(':today', $today); $type_emp = $db->execute(); $result = $db->single(); $emp = $result["emp"]; $contract = $result["contract"]; $part_time = $result["part_time"]; ?> <!-- Page Content --> <div id="page-content-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <h1>RO10 Manpower </h1> </div> <!-- /.col-lg-12 --> </div><!-- row --> <hr> <div class="row">
/** * A custom handler for `simple_auth()`. Note: Calls `session_start()` * for you, and creates the global `$user` object if a session is * valid, since we have the data already. */ public static function method($callback) { if (isset($_POST['username']) && isset($_POST['password'])) { self::init_session(); return call_user_func($callback, $_POST['username'], $_POST['password']); } else { $name = conf('General', 'session_name'); if (isset($_COOKIE[$name]) && !isset($_SESSION)) { self::init_session(); } if (isset($_SESSION['session_id'])) { if (Appconf::user('User', 'multi_login')) { $u = \user\Session::fetch_user($_SESSION['session_id']); if (is_object($u)) { $u->session_id = $_SESSION['session_id']; } } else { $u = DB::single('select * from `#prefix#user` where session_id = ? and expires > ?', $_SESSION['session_id'], gmdate('Y-m-d H:i:s')); } if (is_object($u)) { // Verify user agent as a last step (make hijacking harder) global $cache; $ua = $cache->get('_user_session_agent_' . $_SESSION['session_id']); if ($ua && $ua !== $_SERVER['HTTP_USER_AGENT']) { return FALSE; } $class = get_called_class(); self::$user = new $class((array) $u, FALSE); return TRUE; } } } return FALSE; }
/** * Fetch user for a given session ID. */ public static function fetch_user($id) { return \DB::single('select u.* from #prefix#user_session s left join #prefix#user u on s.user_id = u.id where s.session_id = ? and s.expires > ?', $id, gmdate('Y-m-d H:i:s')); }
<?php $page->layout = 'admin'; $this->require_admin(); if ($this->installed('elefant', ELEFANT_VERSION) === true) { $page->title = __('Upgrade completed'); echo '<p><a href="/blog/admin">' . __('Continue') . '</a></p>'; return; } $page->title = __('Upgrading Elefant'); DB::single('select `extra` from `#prefix#webpage` limit 1'); if (DB::error()) { // Add extra column to webpage DB::beginTransaction(); if (!DB::execute('alter table `#prefix#webpage` add column `extra` text')) { DB::rollback(); printf('<p>Error: %s</p>', DB::error()); return; } DB::commit(); } if (ELEFANT_VERSION === '1.3.10') { // Add extra user fields, social links, and notes DB::beginTransaction(); $db = DB::get_connection(1); $dbtype = $db->getAttribute(PDO::ATTR_DRIVER_NAME); $sqldata = sql_split(file_get_contents('apps/admin/conf/update/1.3.10_users_' . $dbtype . '.sql')); foreach ($sqldata as $sql) { if (!DB::execute($sql)) { DB::rollback(); printf('<p>Error: %s</p>', DB::error());
/** * Get the info about a lock. */ public function info($resource = false, $key = false) { $resource = $resource ? $resource : $this->resource; $key = $key ? $key : $this->key; return DB::single('select * from `lock` where resource = ? and resource_id = ?', $resource, $key); }
/** * A custom handler for `simple_auth()`. Note: Calls `session_start()` * for you, and creates the global `$user` object if a session is * valid, since we have the data already. */ public static function method($callback) { if (!isset($_SESSION)) { @session_set_cookie_params(time() + 2592000); @session_start(); } if (isset($_POST['username']) && isset($_POST['password'])) { return call_user_func($callback, $_POST['username'], $_POST['password']); } elseif (isset($_SESSION['session_id'])) { $u = DB::single('select * from `user` where session_id = ? and expires > ?', $_SESSION['session_id'], gmdate('Y-m-d H:i:s')); if ($u) { // Verify user agent as a last step (make hijacking harder) global $memcache; $ua = $memcache->get('_user_session_agent_' . $_SESSION['session_id']); if ($ua && $ua !== $_SERVER['HTTP_USER_AGENT']) { return false; } $class = get_called_class(); self::$user = new $class((array) $u, false); return true; } } return false; }
/** * Add a page to the tree under the specified parent. * $id can be a page ID or a node object. */ public function add($id, $parent = false) { if (is_object($id)) { $new_page = $id; } else { $pg = DB::single('select title, menu_title from webpage where id = ?', $id); $title = !empty($pg->menu_title) ? $pg->menu_title : $pg->title; $new_page = (object) array('data' => $title, 'attr' => (object) array('id' => $id, 'sort' => 0)); } // locate $parent and add child if ($parent) { $ref = $this->node($parent); if (!isset($ref->children)) { $ref->children = array(); } $new_page->attr->sort = count($ref->children); $ref->children[] = $new_page; $ref->state = 'open'; } else { $new_page->attr->sort = count($this->tree); $this->tree[] = $new_page; } return true; }
<body> <?php // include_once('themes/left.php'); ?> <div id="page-content-wrapper"> <div class="container-fluid"> <h3>รายชื่อพนักงานหน่วยงานที่เป็นพนักงานประจำ</h3> <?php require_once 'core/init.php'; $db = new DB(); $division = htmlspecialchars($_GET["division"]); $emp_type = htmlspecialchars($_GET["emp"]); $id_division = $db->query('SELECT department_id,division FROM all_tttbb_division WHERE department_id = :id_division'); $id_division = $db->bind(':id_division', $division, PDO::PARAM_STR); $id_division = $db->execute(); $id_division = $db->single(); foreach ($id_division as $key => $value2) { $division_name = $id_division["division"]; } echo "หน่วยงาน : ", $division_name; $today = date("Y-m-d"); $month = date("m"); $year = date("Y"); $year_thai = "2558"; $emp_division = $db->query('SELECT date_start,emp_id,t_firstname,t_lastname,job_title,section,division FROM all_ro10_emp WHERE division = :division AND emp_type_id = :emp_type AND data_date = :today ORDER BY date(date_start) ASC'); $emp_division = $db->bind(":division", $division_name); $emp_division = $db->bind(":emp_type", $emp_type);
/** * Fetch a single result as a model object. */ public function single () { $sql = $this->sql (); if ($sql === false) { return false; } $res = DB::single ($sql, $this->query_params); if (! $res) { $this->error = DB::error (); return $res; } $class = get_class ($this); $res = new $class ((array) $res, false); return $res; }
<body> <div id="page-content-wrapper"> <div class="container-fluid"> <h2>พนักงานในหน่วยงาน <?php $today = date("Y-m-d"); $month = date("m"); $year = date("Y"); $year_thai = "2558"; require_once 'core/init.php'; $db = new DB(); $division = htmlspecialchars($_GET["division"]); $id_division = $db->query('SELECT department_id,division FROM all_tttbb_division2 WHERE department_id = :id_division'); $id_division = $db->bind(':id_division', $division, PDO::PARAM_STR); $id_division = $db->execute(); $id_division = $db->single(); foreach ($id_division as $key => $value) { $division_name = $id_division["division"]; } echo $division_name; ?> </h2> <br> <div class="row"> <div class="col-lg-12"> <div class="col-lg-2"> <div align="right"><h4>Select Section</h4></div> </div> <div class="col-lg-4"> <div class="dropdown"> <?php
$start_emp = $db->bind(':year', $year, PDO::PARAM_STR); $start_emp = $db->bind(':month', $month, PDO::PARAM_STR); $start_emp = $db->bind(':thai_year', $year_thai, PDO::PARAM_STR); $start_emp = $db->bind(':today', $today, PDO::PARAM_STR); $start_emp = $db->execute(); $start_emp = $db->rowCount(); //add new line $type_emp = $db->query('SELECT COUNT(CASE WHEN emp_type_id = 1 then 1 ELSE NULL END) as "emp", COUNT(CASE WHEN emp_type_id = 2 then 1 ELSE NULL END) as "contract", COUNT(CASE WHEN emp_type_id = 3 then 1 ELSE NULL END) as "part_time", COUNT(emp_id) as all_emp FROM all_ro10_emp WHERE data_date = :today '); $type_emp = $db->bind(':today', $today); $type_emp = $db->execute(); $result = $db->single(); $emp = $result["emp"]; $contract = $result["contract"]; $part_time = $result["part_time"]; $all_emp = $result["all_emp"]; ?> <!-- Page Content --> <div id="page-content-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <h1>RO10 Manpower</h1> </div> <!-- /.col-lg-12 --> </div><!-- row --> <hr>
* Edit custom fields for a given type. */ $this->require_admin(); if (!isset($_GET['extends'])) { echo $this->error(500, __('Unknown error')); return; } if (!class_exists($_GET['extends'])) { echo $this->error(500, __('Unknown error')); return; } if (!isset($_GET['name'])) { $_GET['name'] = $_GET['extends']; } // Create the database table if it doesn't exist if (!DB::single('select count(*) from #prefix#extended_fields')) { $db = DB::get_connection(true); $queries = sql_split(file_get_contents(sprintf('apps/admin/conf/update/extended_fields_%s.sql', $db->getAttribute(PDO::ATTR_DRIVER_NAME)))); foreach ($queries as $query) { DB::execute($query); } } $page->layout = 'admin'; $page->title = __('Custom Fields') . ': ' . __($_GET['name']); $page->add_script('/apps/admin/js/handlebars-1.0.rc.1.js'); $page->add_script('/js/jquery-ui/jquery-ui.min.js'); $page->add_script('/apps/admin/js/extended.js'); $data = array('extends' => $_GET['extends']); $data['fields'] = ExtendedFields::for_class($_GET['extends']); if (!is_array($data['fields'])) { $data['fields'] = array();