id,5,$num-5); $new_id = $char.sprintf("%0".($num-5)."d",$id+1); }else if(strlen($char)=="4"){ $id = substr($data->id,4,$num-4); $new_id = $char.sprintf("%0".($num-4)."d",$id+1); }else if(strlen($char)=="3"){ $id = substr($data->id,3,$num-3); $new_id = $char.sprintf("%0".($num-3)."d",$id+1); }else if(strlen($char)=="2"){ $id = substr($data->id,2,$num-2); $new_id = $char.sprintf("%0".($num-2)."d",$id+1); }else{ $id = substr($data->id,1,$num-1); $new_id = $char.sprintf("%0".($num-1)."d",$id+1); } }else{ $new_id = $data->id+1; } return $new_id; } function insert($tb, $data){ $keyN = ""; $keyV = ""; foreach($data as $key => $val){ $i++; if($i>1){ $keyN .= ","; $keyV .= ","; } $keyN .= $key; $keyV .= "'".$val."'"; } $sql = "insert into tb_$tb ($keyN) values($keyV)"; $result = getResult($sql); if($result) return 1; else return 0; } //UPDATE function update($tb, $data, $where){ ?> $val){ $i++; if($i>1){ $keyV .= ","; } $keyV .= " $key = '".$val."'"; } $sql = "update tb_$tb set $keyV where $where"; $result = getResult($sql); if($result) return 1; else return 0; } //DELETE function delete($tb, $id, $fid){ $sql = "delete from tb_$tb where $id = '$fid'"; $result = getResult($sql); if($result) return 1; else return 0; } function check_login($user,$pass,$system){ $query = "select * from tb_student where idstu='".$user."' and citizent='".$pass."' "; $result = getResult($query); $n = mysql_num_rows($result); return $n; } function check_session($user){ if(empty($user)){ echo ' '; } } ?> '; exit; } } function is_reg_true($id){ if(empty($id)){ echo ''; exit; } } function is_session_false($session){ if(empty($session)){ echo ''; exit; } } function getOption($option){ global $content; echo $content->getTable_fname("tb_option","option_name",$option,"option_value"); } function directory_url(){ echo DOMAIN; } function the_sitename(){ getOption("site_name"); } function the_address(){ getOption("site_address"); } function the_tel(){ getOption("site_tel"); } function the_fax(){ getOption("site_fax"); } function the_email(){ getOption("site_email"); } function the_copy(){ getOption("site_copy"); } function the_analytics(){ getOption("google_analytics"); } function the_sitemap($id){ global $content; echo $content->getTable_fname("tb_pages","pages_id",$id,"pages_name_$_SESSION[language]"); } function the_member($option){ global $content; echo $content->getTable_fname("tb_member","member_id",$_SESSION['LogID'],$option); } function getWellcome(){ global $content; echo $content->getTable_fname("tb_pages","pages_id","010000","pages_content_$_SESSION[language]"); } function the_social(){ global $content; $social = $content->getTable_fname("tb_option","option_name","site_social","option_value"); $social2 = explode(",",$social); foreach($social2 as $key => $val){ $social3 = explode("=",$val); if($social3[0]=="youtube") echo ' '; if($social3[0]=="facebook") echo ' '; if($social3[0]=="twitter") echo ' '; if($social3[0]=="google") echo ' '; } } function is_andtrue($id1,$id2){ if($id1==$id2) return true; else return false; } function is_textfalse($txt){ if($txt=="") return false; else return true; } function displaydate($x) { $date_m=array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค."); $date_array=explode("-",$x); $y=$date_array[0]+543; $m=$date_array[1]-1; $d=$date_array[2]; $m=$date_m[$m]; $displaydate="$d $m $y"; //return $displaydate; } function sex($x) { $date_m=array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค."); $date_array=explode("-",$x); $y=$date_array[0]+543; $m=$date_array[1]-1; $d=$date_array[2]; $m=$date_m[$m]; $displaydate="$d $m $y"; //return $displaydate; } function format_date($date){ $d=explode("-",$date); $dd=$d[2]+0; $mm=$this->getMonth($d[1]-1); $yy = $d[0]+543; return "$dd $mm $yy"; } function format_datecute($date){ $date2=explode(" ",$date); $d=explode("-",$date2[0]); $dd=$d[2]+0; if($_SESSION['language']=="th") $mm=$this->getMonth($d[1]-1); else $mm=$this->getMonthEN($d[1]-1); $yy = $d[0]+543; return "$dd $mm $yy"; } function format_dateshot($date){ $date2=explode(" ",$date); $d=explode("-",$date2[0]); $dd=$d[2]+0; if($_SESSION['language']=="th") $mm=$this->getMonthShot($d[1]-1); else $mm=$this->getMonthShotEN($d[1]-1); $yy = ($d[0]+543)-2500; return "$dd $mm $yy"; } function format_dateshot2($date){ $date2=explode(" ",$date); $d=explode("-",$date2[0]); $dd=$d[2]+0; $mm=$this->getMonthShot($d[1]-1); $yy = ($d[0]+543)-2500; return "$dd $mm $yy"; } function format_date2($date){ $date2=explode(" ",$date); $d=explode("-",$date2[0]); $dd = $d[2]; $mm = $d[1]; $yy = $d[0]+543; return "$dd/$mm/$yy"; } function format_datetime($date){ $dd = explode(" ",$date); $tt=explode(":",$dd[1]); $d=explode("-",$dd[0]); $dd=$d[2]+0; $mm=$this->getMonth($d[1]-1); $yy = $d[0]+543; return "$dd $mm $yy เวลา $tt[0]:$tt[1] น."; } function format_datetime2($date){ $dd = explode(" ",$date); $tt=explode(":",$dd[1]); $d=explode("-",$dd[0]); $dd=$d[2]+0; $mm=$this->getMonth($d[1]-1); $yy = $d[0]+543; return "$dd $mm $yy $tt[0]:$tt[1]น."; } ?>link = mysql_connect(MYSQL_SERVER,MYSQL_USERNAME,MYSQL_PASSWORD); if($this->link ){ mysql_select_db(MYSQL_DATABASE); mysql_query("SET NAMES ".MYSQL_CHARSET); return 1; } else { echo "can not connect"; return 0; } } public function getResult($query){ $results = mysql_query($query)or die(mysql_error()); if(!$results) { return 0; } return $results; } public function getLastID($table,$id,$num,$char){ $string = "select $id as id from tb_$table order by $id desc limit 0,1"; $idresult = $this->getResult($string); $data = mysql_fetch_object($idresult); if($char!=""){ if(strlen($char)=="7"){ $id = substr($data->id,7,$num-7); $new_id = $char.sprintf("%0".($num-7)."d",$id+1); }else if(strlen($char)=="6"){ $id = substr($data->id,6,$num-6); $new_id = $char.sprintf("%0".($num-6)."d",$id+1); }else if(strlen($char)=="5"){ $id = substr($data->id,5,$num-5); $new_id = $char.sprintf("%0".($num-5)."d",$id+1); }else if(strlen($char)=="4"){ $id = substr($data->id,4,$num-4); $new_id = $char.sprintf("%0".($num-4)."d",$id+1); }else if(strlen($char)=="3"){ $id = substr($data->id,3,$num-3); $new_id = $char.sprintf("%0".($num-3)."d",$id+1); }else if(strlen($char)=="2"){ $id = substr($data->id,2,$num-2); $new_id = $char.sprintf("%0".($num-2)."d",$id+1); }else{ $id = substr($data->id,1,$num-1); $new_id = $char.sprintf("%0".($num-1)."d",$id+1); } }else{ $new_id = $data->id+1; } return $new_id; } public function getTable_fname($tb,$fid,$id,$fname){ //ดึงชื่อฟิวส์ออกมาแสดง พารามิเตอร์คือ ชื่อตาราง,ชื่อฟิวส์อ้างอิง,ค่าที่อ้างอิง,ชื่อฟิวส์ที่จะแสดง $sql = "select $fname from $tb where $fid = '$id' "; $result = mysql_query($sql)or die(mysql_error()); $fetch = mysql_fetch_array($result); return $fetch[$fname]; } public function getTable_where($tb,$fname,$where){ //ดึงชื่อฟิวส์ออกมาแสดง พารามิเตอร์คือ ชื่อตาราง,ชื่อฟิวส์อ้างอิง,เงื่อนไข $sql = "select $fname from $tb where $where "; $result = mysql_query($sql)or die(mysql_error()); $fetch = mysql_fetch_array($result); return $fetch[$fname]; } public function getNum_rows($tb,$id, $where){ //ดึงชื่อฟิวส์ออกมาแสดง พารามิเตอร์คือ ชื่อตาราง,ชื่อฟิวส์อ้างอิง,เงื่อนไข $sql = "select $id from $tb where $where "; $result = mysql_query($sql)or die(mysql_error()); $rows = mysql_num_rows($result); return $rows; } public function getTable_ALL($tb,$id, $where){ //ดึงชื่อฟิวส์ออกมาแสดง พารามิเตอร์คือ ชื่อตาราง,ชื่อฟิวส์อ้างอิง,เงื่อนไข $sql = "select $id from $tb where $where "; $result = mysql_query($sql)or die(mysql_error()); return mysql_fetch_object($result); } public function getTable_fname_fetch($tb,$fname,$where){ $sql="select $fname from $tb where $where"; return mysql_query($sql); } public function updateStatus($tb,$id,$fid,$status){ $sql = "update tb_$tb set showStatus = '$status' where $id = '$fid' "; $result = $this->getResult($sql); } //Insert public function insert($tb, $data){ $keyN = ""; $keyV = ""; foreach($data as $key => $val){ $i++; if($i>1){ $keyN .= ","; $keyV .= ","; } $keyN .= $key; $keyV .= "'".$val."'"; } $sql = "insert into tb_$tb ($keyN) values($keyV)"; $result = $this->getResult($sql); if($result) return 1; else return 0; } //UPDATE public function update($tb, $data, $where){ $keyV = ""; foreach($data as $key => $val){ $i++; if($i>1){ $keyV .= ","; } $keyV .= " $key = '".$val."'"; } $sql = "update tb_$tb set $keyV where $where"; $result = $this->getResult($sql); if($result) return 1; else return 0; } //DELETE public function delete($tb, $id, $fid){ $sql = "delete from tb_$tb where $id = '$fid'"; $result = $this->getResult($sql); if($result) return 1; else return 0; } public function getImage($id){ $query = "select image_name from tb_image where image_id = '$id' "; $result = $this->getResult($query); $data = mysql_fetch_object($result); $event_image = $data->image_name; return $event_image; } // end getEventImage public function useronline($type,$ip,$url){ $url = ($url=="")? "index.php": $url; $data = array( "id" => NULL, "ip" => $ip, "page" => "/".$url, "type" => $type, "time_in" => date("Y-m-d H:i:s") ); $this->insert("useronline",$data); $session=session_id(); $time=time(); $time_check=$time-600; //SET TIME 10 Minute $count=$this->getNum_rows("tb_online","*","session='$session'"); if($count=="0"){ $this->insert("online",array("session"=>$session,"time"=>$time)); } else { $this->update("online",array("time"=>$time),"session = '$session'"); } // if over 10 minute, delete session $sql4="DELETE FROM tb_online WHERE time<$time_check"; $result4=mysql_query($sql4); } } ?>