"SET NAMES utf8")); $tdh_db_link->setAttribute(PDO::ATTR_CASE,PDO::CASE_NATURAL); } catch(PDOException $e) { if (defined('tdh_log')) { $fp = fopen(tdh_root.tdh_log,'a'); fwrite($fp,date('Y-m-d H:i:s').' '.$e->getMessage()); fclose($fp); } include(tdh_ctrl.'/404.php'); } $dboper = $tdh_db_link->query($v2); if (!$dboper) { $errorinfo = $tdh_db_link->errorInfo(); if (defined('tdh_log')) { $fp = fopen(tdh_root.tdh_log,'a'); fwrite($fp,date('Y-m-d H:i:s').' '.$errorinfo[2].chr(13).chr(10).'error query: '.$v2.chr(13).chr(10)); fclose($fp); } include(tdh_ctrl.'/404.php'); } $dboper->setFetchMode(PDO::FETCH_ASSOC); $dbquery = null; switch ($v3) { case 0: $dbquery = $dboper->rowCount(); break; case 1: $dbquery = $dboper->fetchColumn(); break; case 2: $dbquery = $dboper->fetch(); break; case 3: $dbquery = $dboper->fetchAll(); break; } return $dbquery; } function tdh_db_close() { global $tdh_db_link; $tdh_db_link = null; } function tdh_close() { tdh_db_close(); exit; } function tdh_ml_text($v1,$v2) { require_once('Mail.php'); $smtp['host'] = 'ssl://smtp.zoho.com'; $smtp['port'] = '465'; $smtp['username'] = 'admin@tjdma.org'; $smtp['password'] = 'kib64819'; $smtp['auth'] = true; global $txt_from,$txt_sender,$txt_subject,$txt_content; $headers['From'] = '=?utf-8?B?'.base64_encode($txt_sender).'?= <'.$txt_from.'>'; $headers['To'] = $v1; $headers['Subject'] = '=?UTF-8?B?'.base64_encode($txt_subject).'?='; $headers['Reply-To'] = $txt_from; $headers['Content-Type'] = 'text/plain; charset=utf-8'; $headers['Return-path'] = $txt_from; $pmail = Mail::factory('smtp',$smtp); $mail = $pmail->send($v1,$headers,$v2); if(PEAR::isError($mail)) { $fp = fopen(tdh_root.tdh_log,'a'); fwrite($fp,date('Y-m-d H:i:s').' '.$mail->getMessage().chr(13).chr(10)); fclose($fp); } } function tdh_ck_login($v1 = 1) { //if (session_status() == PHP_SESSION_NONE) session_start(); if (empty($_SESSION['login_data'])) { if ($v1==1) { global $msg_error; $msg_error['timeout'] = 1; include(tdh_ctrl.'/login.php'); } else { echo 'fail'; exit; } } } function tdh_ck_admin($v1 = 1) { //if (session_status() == PHP_SESSION_NONE) session_start(); if (empty($_SESSION['admin_data'])) { if ($v1==1) { global $msg_error; $msg_error['timeout'] = 1; include(tdh_ctrl.'/login.php'); } else { echo 'fail'; exit; } } else if ($_SESSION['admin_data']==2 || $_SESSION['admin_data']==3 || $_SESSION['admin_data']==4 || $_SESSION['admin_data']==5 || $_SESSION['admin_data']==6) { if (!($_REQUEST['ctrl']=='player2' || $_REQUEST['ctrl']=='player2_view' || $_REQUEST['ctrl']=='player2_pass_send' || $_REQUEST['ctrl']=='player3' || $_REQUEST['ctrl']=='player3_view' || $_REQUEST['ctrl']=='player3_pass_send' || $_REQUEST['ctrl']=='player3_final' || $_REQUEST['ctrl']=='player3_detail')) { global $msg_error; $msg_error['permission'] = 1; include(tdh_ctrl.'/login.php'); } } } function tdh_post($v1,$v2 = '') { return isset($_POST[$v1]) ? $_POST[$v1] : $v2; } function tdh_get($v1,$v2 = '') { return isset($_GET[$v1]) ? $_GET[$v1] : $v2; } function tdh_ck_error($v1 = '') { global $msg_error; if ($v1=='') return (count($msg_error) > 0); else return (isset($msg_error[$v1])); } function tdh_request($v1,$v2 = '') { return isset($_REQUEST[$v1]) ? $_REQUEST[$v1] : $v2; } function tdh_ck_captcha($v1) { global $msg_error; $p_captcha = isset($_REQUEST[$v1]) ? $_REQUEST[$v1] : null; $s_captcha = isset($_SESSION[$v1]) ? $_SESSION[$v1] : null; if (is_null($p_captcha) || is_null($s_captcha) || $p_captcha != $s_captcha) $msg_error[$v1] = 1; } function tdh_ck_email($v1) { global $msg_error; if (!isset($_REQUEST[$v1]) || !filter_var($_REQUEST[$v1],FILTER_VALIDATE_EMAIL)) $msg_error[$v1] = 1; } function tdh_ck_string($v1) { global $msg_error; if (!isset($_REQUEST[$v1]) || empty($_REQUEST[$v1])) $msg_error[$v1] = 1; } function tdh_ck_integer($v1) { global $msg_error; if (!isset($_REQUEST[$v1]) || !(filter_var($_REQUEST[$v1], FILTER_VALIDATE_INT) === 0 || !filter_var($_REQUEST[$v1], FILTER_VALIDATE_INT,array("options" => array("min_range"=>1))) === false)) $msg_error[$v1] = 1; } function tdh_ck_password($v1) { global $msg_error; if (!isset($_REQUEST[$v1]) || strlen($_REQUEST[$v1])<4) $msg_error[$v1] = 1; } function tdh_ck_common($v1,$v3 = '',$v4 = 1) { $v2 = null; if (strpos($v1,'_id')!==false) { tdh_ck_integer($v1); $v2 = substr($v1,0,strpos($v1,'_id')); } else if (strpos($v1,'_code')!==false) { tdh_ck_string($v1); $v2 = substr($v1,0,strpos($v1,'_code')); } if (is_null($v2) || tdh_ck_error($v1)) { if ($v4==1) include(tdh_ctrl.'/404.php'); else { echo 'fail'; exit; } } else { $v2a = (strpos($v1,'_id')!==false)? $v1." = ".$_REQUEST[$v1]:$v1." = '".$_REQUEST[$v1]."'"; } global $dbquery; $dbquery = tdh_db_open("select * from ".tdh_db_pre.$v2." where ".$v2a.$v3,2); if (empty($dbquery)) { if ($v4==1) include(tdh_ctrl.'/404.php'); else { echo 'fail'; exit; } } } ?>