<?php
function getTitleType($id){

	$sql="select * from tb_flv_type where id='$id'";
	$query=mysql_query($sql);
	$rs=mysql_fetch_array($query);
	
	return $rs['title'];

}

function TypelistFuntSc($dbname,$filde,$table,$order,$value,$name,$shownone,$selected,$funct,$script) {
echo"<select name=\"$filde\" id=\"$filde\" ".$script.">";
if($shownone == "1") {echo"<option value=\"\">--ไม่มี--</value>";}
$strsql = "select * from ".$table." ".$funct." order by ".$order;
$dbquery = mysql_db_query($dbname,$strsql);
while ($result = mysql_fetch_array($dbquery)) {
	if($selected > "0") { if($result[$value] != $selected){$sld = "";}else{$sld = "selected";}}
echo "<option value=\"".$result[$value]."\" $sld>".$result[$name]."</option>";
}
echo"</select>";
}
function TypelistScript($dbname,$filde,$table,$order,$value,$name,$shownone,$selected,$script) {
echo"<select name=\"$filde\" id=\"$filde\" ".$script.">";
if($shownone == "1") {echo"<option value=\"\">--ไม่มี--</value>";}

$strsql = "select * from ".$table." order by ".$order;
$dbquery = mysql_db_query($dbname,$strsql);
while ($result = mysql_fetch_array($dbquery)) {
	if($selected > "0") { if($result[$value] != $selected){$sld = "";}else{$sld = "selected";}}
echo "<option value=\"".$result[$value]."\" $sld>".$result[$name]."</option>";
}
echo"</select>";
}
function GoToURL($url)
{
	echo"<script>window.location='".$url."';</script>";
}
function setFilename($FileName)
{
	$File=explode(".",$FileName);
	$output=time().".".$File[1];
	return $output;
}
function PrintContent($id,$lang)
{
	$SQL="SELECT cms_".$lang." FROM cms WHERE cms_id='".$id."'";
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	echo $ROW["cms_".$lang];
}
function getContent($id)
{
	$SQL="SELECT * FROM content WHERE content_id='".$id."'";
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	return $ROW;
}
function getContentNews($id)
{
	$SQL="SELECT * FROM news WHERE news_id='".$id."'";
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	return $ROW;
}
function getServices($id)
{
	$SQL="SELECT * FROM ourservices WHERE ourservices_id='".$id."'";
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	return $ROW;
}
function getItem($SQL)
{
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	return $ROW[0];
}
function Bullet()
{
	echo'<img src="images/c-sep-l.gif" />';
}
function FileUpload($itemName,$itemFile)
{
	if(file_exists($itemFile["tmp_name"]))
	{
		$name=$itemName."-".setFilename($itemFile["name"]);
		$RESULT=move_uploaded_file($itemFile["tmp_name"],"../upload/document/".$name)or die("Not Upload");
		if($RESULT){return $name;}else{return "";}
	}
	else{return "";}
}
function FileUpload2($itemName,$itemFile)
{
	if(file_exists($itemFile["tmp_name"]))
	{
		$name=$itemName."-".setFilename($itemFile["name"]);
		$RESULT=move_uploaded_file($itemFile["tmp_name"],"../upload/polymer2/".$name)or die("Not Upload");
		if($RESULT){return $name;}else{return "";}
	}
	else{return "";}
}
function DATEMINI($monthMini,$myDate)
{
	$myArr=explode("-",$myDate);
	$pos=$myArr[1]+0;
	$year=$myArr[0]+543;
	$date=($myArr[2]+0)."-".$monthMini[$pos]."-".$year;
	return $date;
}
function getMember($memCode)
{
	$sql="SELECT member_name,member_surname,member_date FROM member WHERE";
	$sql.=" member_id=".$memCode;
	$result=mysql_query($sql)or die($sql);
	$arr=mysql_fetch_array($result);
	$poster=$arr[0]." ".$arr[1];
	return $poster;
}
function ChkMenu($user,$type)
{
	$SQL="SELECT count(agency_id) FROM agency WHERE agency_user_id='".$user."' ";
	$SQL.="AND agency_type='".$type."'";
	$RESULT=mysql_query($SQL)or die($SQL);
	$ROW=mysql_fetch_array($RESULT);
	return $ROW[0];
}
function updateIntField($field,$table,$field_id,$id){
$sql_se="select $field from $table where $field_id='$id'";
$query_se=mysql_query($sql_se)or die('on');
$rs_se=mysql_fetch_array($query_se);

$sql="update $table set $field='".($rs_se[$field]+1)."' where $field_id='$id'";
$query=mysql_query($sql)or die($sql);

}


function updateTopic($id){
	$date=date("Y-m-d H:i:s");
	
	$sql="update topic set date_update='$date' where topic_id='$id'";
	$query=mysql_query($sql)or die($sql);
	
}
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}


function Typelist($dbname,$filde,$table,$order,$value,$name,$shownone,$selected) {
echo"<select name=\"$filde\" id=\"$filde\">";
if($shownone == "1") {echo"<option value=\"\">--ไม่มี--</value>";}

$strsql = "select * from ".$table." order by ".$order;
$dbquery = mysql_db_query($dbname,$strsql);
while ($result = mysql_fetch_array($dbquery)) {
	if($selected > "0") { if($result[$value] != $selected){$sld = "";}else{$sld = "selected";}}
echo "<option value=\"".$result[$value]."\" $sld>".$result[$name]."</option>";
}
echo"</select>";
}


function TypelistDrop($dbname,$option,$page,$keyword,$current)
{
echo"<form name=\"downlist\"><select name=\"typdw\" OnChange=\"location.href=(downlist.typdw.options[selectedIndex].value)\">
<option value=\"index.php?option=$option&page=$page&keyword=$keyword\">-ทั้งหมด-</option>
";
$strsql = "select * from tgi_course_type order by type_id";
$dbquery = mysql_db_query($dbname, $strsql);

while ($result = mysql_fetch_array($dbquery)) {
	if($result[type_id] != $current){$sld = "";}else{$sld = "selected";}
echo "<option value=\"index.php?option=$option&page=$page&keyword=$keyword&typelist=".$result[type_id]."\" $sld>".$result[type_name]."</option>";
}
echo"</select></form>";
}


function jsalert($text)
{
echo"<script> alert(\"$text\"); </script>";
}


function jsback()
{
echo"<script> javascript:history.back(); </script>";
}


function jsload()
{

echo"
<script type=\"text/javascript\">  
$(window).load(function(){  
      $(\"#loading\").hide();  
})  
</script>";


echo"<div id=\"loading\">
กำลังดำเนินการ  โปรดรอสักครู่ ..
<img src=\"img/loading.gif\" alt=\"loading..\" />
</div>
";
}

function getExtension($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,$i+1,$l);

return $ext;

}

function getFilename($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,0,$i);

return $ext;

}

function getCoursecode($str) {
$j2se=explode("@",$str);
return $j2se[0];
}


$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array(
	"0"=>"",
	"1"=>"ม.ค.",
	"2"=>"ก.พ.",
	"3"=>"มี.ค.",
	"4"=>"เม.ย.",
	"5"=>"พ.ค.",
	"6"=>"มิ.ย",	
	"7"=>"ก.ค.",
	"8"=>"ส.ค.",
	"9"=>"ก.ย.",
	"10"=>"ต.ค.",
	"11"=>"พ.ย.",
	"12"=>"ธ.ค."					
);
function thai_date($time){
	global $thai_day_arr,$thai_month_arr;
	$thai_date_return.=	" ".date("j",$time);
	$thai_date_return.=" ".$thai_month_arr[date("n",$time)];
	$thai_date_return.=	" ".(date("Yํ",$time)+543);
	return $thai_date_return;
}
function thai_date_mini($time){
	global $thai_day_arr,$thai_month_arr;
	$thai_date_return.=	" ".date("j",$time);
	$thai_date_return.=" ".$thai_month_arr[date("n",$time)];
	return $thai_date_return;
}

function selectt($fild1,$fild2,$deffid1,$deffid2)
{
echo"<select name=\"".$fild1."\" id=\"".$fild1."\">";
for ($i=0; $i<=23; $i++)
{
if($i<10){$j="0$i";}else{$j=$i;}
if($j != $deffid1){$sld = "";}else{$sld = "selected";}
echo "<option value=\"$j\" $sld>$j</option>";
}
echo "</select>";
echo"<select name=\"".$fild2."\" id=\"".$fild2."\">";
for ($i=0; $i<=59; $i++)
{
if($i<10){$j="0$i";}else{$j=$i;}
if($j != $deffid2){$sld = "";}else{$sld = "selected";}
echo "<option value=\"$j\" $sld>$j</option>";
}
echo "</select>";
}


$eng_day_arr=array("SUN","MON","TUE","WED","THU","FRI","SAT");
$eng_month_arr=array(
	"0"=>"",
	"1"=>"JAN",
	"2"=>"FEB",
	"3"=>"MAR",
	"4"=>"APR",
	"5"=>"MAY",
	"6"=>"JUN",	
	"7"=>"JUL",
	"8"=>"AUS",
	"9"=>"SEP",
	"10"=>"OCT",
	"11"=>"NOV",
	"12"=>"DEC"					
);
function eng_date($time){
	global $eng_day_arr,$eng_month_arr;
	$eng_date_return.=	" ".date("j",$time);
	$eng_date_return.=" ".$eng_month_arr[date("n",$time)];
	$eng_date_return.=	" ".(date("Y",$time));
	return $eng_date_return;
}
function eng_date_mini($time){
	global $eng_day_arr,$eng_month_arr;
	$eng_date_return.=	" ".date("j",$time);
	$eng_date_return.=" ".$eng_month_arr[date("n",$time)];
	return $eng_date_return;
}
function extract_int($str){  
preg_match('/[^0-9]*([0-9]+)[^0-9]*/', $str, $regs);  
return (intval($regs[0]));  
} 

function editor($str){  
echo" <script type=\"text/javascript\">
        //<![CDATA[
            CKEDITOR.replace( '".$str."',{
            skin            : 'kama',
            language        : 'en',
            extraPlugins    : 'uicolor',
            uiColor            : '#EAEAEA',
            height            : 200,
            width            : 500,

            filebrowserBrowseUrl : 'ckeditor/ckfinder/ckfinder.html',
            filebrowserImageBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Images',
            filebrowserFlashBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Flash',
            filebrowserUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
            filebrowserImageUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            filebrowserFlashUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'

            } );
        //]]>
      </script>";
}

function minieditor($str){  
echo" <script type=\"text/javascript\">
        //<![CDATA[
            CKEDITOR.replace( '".$str."',{
            skin            : 'kama',
            language        : 'en',
            extraPlugins    : 'uicolor',
            uiColor            : '#EAEAEA',
            height            : 200,
            width            : 350,
    toolbarStartupExpanded : false,
            filebrowserBrowseUrl : 'ckeditor/ckfinder/ckfinder.html',
            filebrowserImageBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Images',
            filebrowserFlashBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Flash',
            filebrowserUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
            filebrowserImageUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            filebrowserFlashUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'

            } );
        //]]>
      </script>";
}

?>