}
//------------------------------------------------------------------------------------------------------------------------------------------------
function regNumFormat($userID)
{ return sprintf("%05d",$userID); }
//------------------------------------------------------------------------------------------------------------------------------------------------
function memberNoFormat($mID)
{ return "MEM".sprintf("%06d",$mID); }
//------------------------------------------------------------------------------------------------------------------------------------------------
function curFormat($str)
{ return "Baht ".number_format($str); }
//------------------------------------------------------------------------------------------------------------------------------------------------
function absFormat($str)
{ return "ABS".sprintf("%07d", $str); }
//------------------------------------------------------------------------------------------------------------------------------------------------
function invFormat($str)
{ return "INV".sprintf("%07d", $str); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_curUrl()
{
$_SERVER['QUERY_STRING']!=""?$returnVal=current_url()."?".$_SERVER['QUERY_STRING']:$returnVal=current_url()."?cur=cur";
return $returnVal;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function insertText($str)
{ return addslashes(htmlspecialchars($str)); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function showText($str)
{ return stripcslashes(htmlspecialchars_decode($str)); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function stripslashesStr($str)
{ return stripslashes($str); }
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function genHeaderMenu()
{
$ci=& get_instance();
$ci->load->database();
$ci->db->select('ccID,contentName,urlCI as url');
$ci->db->where('visible', 'y');
$ci->db->order_by('orderNo', 'ASC');
//$ci->db->from('content_cate');
$query = $ci->db->get('content_cate');
foreach ($query->result_array() as $row)
{
$mainDropdown[$row['ccID']]['name']=$row['contentName'];
$mainDropdown[$row['ccID']]['url']=$row['url'];
}
while ($element=each($mainDropdown))
{
$ci->db->select('cpID,cpID,pageName, content, contentType');
$ci->db->where('visible', 'y');
$ci->db->where('ccID', $element['key']);
$ci->db->order_by('orderNo', 'ASC');
$query = $ci->db->get('content_page');
if ($query->num_rows())
{
?>
foreach ($query->result_array() as $row)
{
if ($row['contentType']=="html")
$setUrl=site_url("Home/displayContent?cpID=".$row['cpID']);
else
$setUrl=site_url($row['content']);
?>
}
?>
}
else
{
?>
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function logout($mode="admin")
{
session_start();
session_unset();
session_destroy();
if ($mode=="admin")
redirect('BackOffice/index');
else
redirect('Home/home');
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function chkSession()
{
$pageName=current_url();
if ((empty($_SESSION['user'])) or ($_SESSION['user'] == ""))
redirect('Home/login?act=loginPlz&toPage='.base64_encode(get_curUrl()));
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function chkSessionBf()
{
if ((empty($_SESSION['veriUser'])) or ($_SESSION['veriUser'] == ""))
redirect('BackOffice/login?act=loginPlz');
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getMaxID($field,$dbName)
{
$ci=& get_instance();
$ci->load->database();
$maxID = 0;
$row = $ci->db->query("SELECT MAX(".strtoupper($field).") AS MAXID FROM ".strtoupper($dbName)."")->row();
if ($row)
$maxID = $row->MAXID;
return $maxID+1;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function breadcrumb($str)
{
?>
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setSeoBackOffice($seoTxt="")
{
// SEO_ARRAY อยู่ใน constants.php
$seoArr = unserialize (SEO_BACKOFFICE_ARRAY);
if ($seoTxt!="")
$seoArr[0]=$seoTxt;
?>
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setSeo($seoTxt="")
{
// SEO_ARRAY อยู่ใน constants.php
$seoArr = unserialize (SEO_ARRAY);
if ($seoTxt!="")
$seoArr[0]=$seoTxt;
?>
}
$acceptFile="pdf|doc|docx|xls|xlsx|jpg|png|gif";
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function txtClient($str)
{
$msgTxt['loginPlz']="Please Login.";
$msgTxt['noData']="Cannot find data.";
$msgTxt['saveDone']="Data has been saved";
$msgTxt['cantSend']="Can not sent email.";
$msgTxt['sendEmail']="Your email has been send.";
$msgTxt['cantSave']="Incompleted data, please check & try again.";
$msgTxt['delDone']="Data has been deleted.";
$msgTxt['cantDel']="Data can not be deleted.";
$msgTxt['reqData']="A value is required.";
$msgTxt['noPermission']="You don't have Permission. Please contact Admin.";
$msgTxt['cancelPayment']="Your Payment is Cancel.";
$msgTxt['noBookingOnline']="You cannot booking Online Please contact theatre";
$msgTxt['insertData']="Please Insert required Data.";
$msgTxt['thisFile']="Please enter pdf, doc, docx, xls, xlsx, jpg, png and gif extension";
if (array_key_exists($str, $msgTxt))
return $msgTxt[$str];
else
return false;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function showMsg($msg,$msgType='msg',$display='box')
{
?>
$chkMsg=txtClient($msg);
if ($chkMsg!=false)
$msg=$chkMsg;
if ($msgType=='err')
$display=="box"?$msgArr=array("divClass"=>"alert-danger text-danger","fontColor"=>"fontMsgRed","faIcon"=>"fa-exclamation-triangle"):$msgArr=array("divClass"=>"text-danger","fontColor"=>"text-danger","faIcon"=>"fa-exclamation-triangle");
else
$display=="box"?$msgArr=array("divClass"=>"alert-success text-success","fontColor"=>"fontMsgGreen","faIcon"=>"fa-check"):$msgArr=array("divClass"=>"text-success","fontColor"=>"text-success","faIcon"=>"fa-check");
if ((empty($msg)) or ($msg == ""))
$msg = "Cannot Save Your Data. Please try again.";
if ($display=="box")
{
?>
}
else
{
?>
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function findName()
{
list($usec, $sec) = explode(" ", microtime());
$usecTime = (float)$usec + (float)$sec;
//list($timeStamp,$usec) = split('[.]',$usecTime);
list($timeStamp,$usec) = explode('.',$usecTime);
return ($timeStamp.sprintf("%04d",$usec));
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function cutText($str,$number)
{
$str=showText($str);
if(strlen($str)<=$number)
return $str;
else
return substr($str,0,$number)."...";
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function delFile($delMe)
{
if (is_file($delMe))
return unlink($delMe);
else
return false;
}
?>
//------------------------------------------------------------------------------------------------------------------------------------------------------------
function dateOnly()
{ return date("Y-m-d"); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------
function now()
{ return date("Y-m-d H:i:s"); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function strToTimestamp($str)
{ return strtotime($str); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function convDate($str,$dateFormat="Y-m-d")
{
return date($dateFormat, strtotime($str));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function dateMulti($date,$showTime='n',$monthStyle="short",$langType="en",$yearStyle=4)
{
if($monthStyle=="short")
{
$thMonth=array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.", "พ.ย.","ธ.ค.");
$enMonth = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", "Nov","Dec");
}
else
{
$thMonth=array("มกราคม.","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม", "พฤษจิกายน","ธันวาคม");
$enMonth = array("January","February","March","April","May","June","July","August","September","October", "November","December");
}
$date=date('Y-m-d H:i:s', strtotime($date));
list($date, $time) = explode (' ', $date);
list($year, $month, $day) = explode ('-', $date);
if ($day{0} == 0)
$day = $day{1};
if ($langType == "en")
{
$yearStyle == 2?$myYear = substr($year,-2):$myYear=$year;
$myMonth = $enMonth[$month-1];
if ($showTime == "y")
$myYear=$myYear." @ ".substr($time,0,-3);
return $myMonth." ".$day.", ".$myYear;
}
if ($langType == "th")
{
$year += 543;
$yearStyle == 2?$myYear = substr($year,-2):$myYear=$year;
$myMonth = $thMonth[$month-1];
if ($showTime == "y")
$myYear=$myYear." @ ".substr($time,0,-3)." น.";
return $day." ".$myMonth." ".$myYear;
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
function displayStartToEndDate($startDate,$endDate,$monthStyle="long",$langType="th",$yearStyle=2)
{
if($monthStyle=="short")
{
$thMonth=array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.", "พ.ย.","ธ.ค.");
$enMonth=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", "Nov","Dec");
}
else
{
$thMonth=array("มกราคม.","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม", "พฤษจิกายน","ธันวาคม");
$enMonth = array("January","February","March","April","May","June","July","August","September","October", "November","December");
}
if ($langType == "en")
$yearStyle == 2?$myYear = date('y', strtotime($startDate)):$myYear=date('Y', strtotime($startDate));
else
{
$year=date('Y', strtotime($startDate))+543;
$yearStyle == 2?$myYear = substr($year,-2):$myYear=$year;
}
if (date('m', strtotime($startDate))==date('m', strtotime($endDate)))
{
$day=date('j', strtotime($startDate))."-".date('j', strtotime($endDate));
if ($langType == "en")
return $day." ".$enMonth[date('m', strtotime($startDate))-1]." ".$myYear;
else
return $day." ".$thMonth[date('m', strtotime($startDate))-1]." ".$myYear;
}
else
{
if ($langType == "en")
return date('j', strtotime($startDate))." ".$enMonth[date('m', strtotime($startDate))-1]."-".date('j', strtotime($endDate))." ".$enMonth[date('m', strtotime($endDate))-1]." ".$myYear;
else
return date('j', strtotime($startDate))." ".$thMonth[date('m', strtotime($startDate))-1]."-".date('j', strtotime($endDate))." ".$thMonth[date('m', strtotime($endDate))-1]." ".$myYear;
}
}
?>
function genCerName($userID,$forYear)
{ return "cer_".$forYear."_".$userID.".jpg"; }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
function dailyRegType()
{ return array("itDay","thDay"); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function fullRegType()
{ return array("as","it","th","vip"); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function aseanCountry()
{ return array("ID","MY","PH","SG","BN","VN","MM","KH","LA"); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function invSpID() // usedFor absSub, แก้จาก invSpInMoblie
{ return array(45,46); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function sendMailListArr()
{
return array("sendMailList"=>"เฉพาะรายชื่อใน Mail List","sendToJITMM"=>"เฉพาะสมาชิก","sentToOral"=>"เฉพาะ Oral","sentToPoster"=>"เฉพาะ Poster");
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_timeTable($str)
{
$timeTable['regTimeup']=date('Y')."-12-15"; // ปิดการลงทะเบียน
$timeTable['absTimeUpOral']=date('Y')."-08-30"; // ปิดการส่ง oral
$timeTable['absTimeUp']=date('Y')."-09-30"; // ปิดการส่ง Abs
$timeTable['editAbsDate']=date('Y')."-10-31"; // ปิดการแก้้ไข
$timeTable['firstDate']=date('Y')."-10-31"; // หมดลงทะเบียนรอบแรก
$timeTable['secondDate']=date('Y')."-11-15"; // หมดลงทะเบียนรอบสองหลังจากนี้ใช้ on site
$timeTable['regTime']=array($timeTable['firstDate'],$timeTable['secondDate']); // เวลาลงทะเบียนแบบ array
$timeTable['jitmmDate']="12-14 December ".date('Y');
$timeTable['jitmmDateShort']="12-14 Dec ".date('Y');
return $timeTable[$str];
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_setForYear()
{
$setForYearDate="2020-12-31"; // ใช้ข้อมูลของปีไหย
list($setForYear, $setForMonth, $setForDate) = explode("-", $setForYearDate);
return $setForYear;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function emailInfo()
{
return array("senderName"=> "JITMM".date("Y"),"senderEmail"=>"jitmm@mahidol.ac.th");
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function coreMemberFee($fee=0)
{ return $fee; }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function coreMemberTime()
{ return array("startDate"=>date('Y'),"endDate"=>(date('Y')+5)); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function pf()
{ return "jitmm_"; }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function webTitle()
{
$seoArr = unserialize (SEO_ARRAY);
return $seoArr[0];
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_thaiCode()
{
return "TH";
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_prefixUser($str)
{
$str="thai"?$returnVal="T":$returnVal= "F";
return $returnVal;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_respPayment($str)
{
$reponsePaymentArr['canceled'] = "Customer canceled from Payment System, No payment has been done.";
$reponsePaymentArr['error'] = "Payment application error.";
$reponsePaymentArr['inprocess'] = "Your transaction in process, waiting for creditcard approval result.";
$reponsePaymentArr['approved'] = "Your payment has been sent.";
$reponsePaymentArr['declined'] = "Creditcard authorization declined.";
$reponsePaymentArr['outofservice'] = "Payment System temporary out of service";
return $reponsePaymentArr[$str];
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_configPath($str="")
{
$imgType="gif|jpg|png";
$docType="xls|xlsx|doc|docx|pdf|jpg|png|gif";
$whSize=array(200,150);
$fileSize=array("img"=>2048,"doc"=>5120);
if ($str=="noImg")
return "assets/img/no-profile-img.gif";
else if ($str=="qrPath")
return "uploadQr/";
else if ($str=="cerPath")
return array("cerImg/",$imgType,$fileSize['img'],$whSize[0],$whSize[1]);
else if ($str=="userPhoto")
return array("userPhoto/",$imgType,$fileSize['img'],$whSize[0],$whSize[1]);
else if ($str=="adminPhoto")
return array("adminPhoto/",$imgType,$fileSize['img'],$whSize[0],$whSize[1]);
else if ($str=="uploadDoc")
return array("uploadDoc/",$docType,$fileSize['doc']);
else
return array("uploadTmp/",$docType."|".$imgType,$fileSize['doc'],$whSize[0],$whSize[1]);
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
?>
function setEtcVal()
{ return 1; }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function displayBreadcrumb($menuTitle)
{
?>
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function findFileName ($curUrl)
{
$arrPath = explode('/',$curUrl);
return end($arrPath);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
?>
class Content_model extends CI_Model {
public function __construct()
{
parent::__construct();
// Your own constructor code
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_content_page($cpID="",$ccID="",$visible="",$smVisible="",$field="*",$orderBy="orderNo",$orderType="asc")
{
$this->db->select($field);
if ($cpID!="")
$this->db->where('cpID', $cpID);
if ($ccID!="")
$this->db->where('ccID', $ccID);
if ($visible!="")
$this->db->where('visible', $visible);
if ($smVisible!="")
$this->db->where('siteMapVisible', $smVisible);
$this->db->order_by($orderBy, $orderType);
$query = $this->db->get('content_page');
if ($cpID!="")
return $query->row_array();
else
return $query->result_array();
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_content_cate($ccID="",$cpID="",$visible="",$adminVisible="",$field="*",$orderBy="orderNo",$orderType="asc")
{
$this->db->select($field);
if ($visible!="")
$this->db->where('visible', $visible);
if ($adminVisible!="")
$this->db->where('adminVisible', $adminVisible);
if ($cpID!="")
$this->db->where('cpID', $cpID);
if ($ccID!="")
$this->db->where('ccID', $ccID);
$this->db->order_by($orderBy, $orderType);
$query = $this->db->get('content_cate');
if ($ccID!="")
return $query->row_array();
else
return $query->result_array();
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
public function set_email()
{
$this->db->set('title',insertText($this->input->post('title')));
$this->db->set('content',insertText($this->input->post('message')));
$this->db->set('createDate',now());
if ($this->input->post('submit')=="Save")
{
$this->db->set('adminID',$_SESSION['veriUser']);
$this->db->insert('email');
}
else
{
$this->db->where('eID',$this->input->post('eID'));
$this->db->update('email');
}
if ($this->db->trans_status() === false)
return false;
else
return true;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_email($eID="",$field="*")
{
$this->db->select($field);
if ($eID!="")
$this->db->where('eID', $eID);
$query = $this->db->get('email');
if ($eID!="")
return $query->row_array();
else
return $query->result_array();
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
public function set_newsletter()
{
if ($this->input->post('SubmitNews')=="Submit")
{
$this->db->trans_start();
$this->db->set('email', $this->input->post('email'));
$this->db->insert('mail_list');
}
if ($this->db->trans_status() === false)
{
$this->db->trans_rollback();
$this->db->trans_complete();
return false;
}
else
{
$this->db->trans_commit();
$this->db->trans_complete();
return true;
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_news($nID="",$limit=3)
{
if ($nID!="")
{
$query = $this->db->query("select nID,title,content,startDate from ".pf()."news where visibleIndexPage='y' and ((`endDate` > '".dateOnly()."') or (endDate is NULL)) and ((startDate is NULL) or (startDate <= '".dateOnly()."')) and nID='".$nID."' ");
return $query->row_array();
}
else
{
$limit=="all"?$setLimit="":$setLimit="LIMIT 0,".$limit;
$query = $this->db->query("select nID,title,content,startDate from ".pf()."news where visibleIndexPage='y' and ((`endDate` > '".dateOnly()."') or (endDate is NULL)) and ((startDate is NULL) or (startDate <= '".dateOnly()."')) order by startDate DESC ".$setLimit);
return $query->result_array();
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_impDate($imID="",$limit=3)
{
if ($imID!="")
{
$query = $this->db->query("select imID,impDate,title,content,startTime,endTime from ".pf()."imp_date where visible='y' and ((impDate >= '".dateOnly()."') or (endDate >= '".dateOnly()."')) and imID='".$imID."' ");
return $query->row_array();
}
else
{
$limit=="all"?$setLimit="":$setLimit="LIMIT 0,".$limit;
$query = $this->db->query("select imID,impDate,title from ".pf()."imp_date where visible='y' and ((impDate >= '".dateOnly()."') or (endDate >= '".dateOnly()."')) order by impDate ASC ".$setLimit);
//echo "select imID,impDate,title from ".pf()."imp_date where visible='y' and ((impDate >= '".dateOnly()."') or (endDate >= '".dateOnly()."')) order by impDate ASC LIMIT 0,3";
return $query->result_array();
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
public function get_content($cpID)
{
$this->db->select('ccID,cpID,pageName,content');
$this->db->from('content_page');
$this->db->where('cpID', $cpID);
$this->db->where('visible', 'y');
$query = $this->db->get();
return $query->row_array();
}
}
?>