Class Obj_lampang {
var $host = DB_host ;
var $user = DB_user ;
var $pass = DB_pass ;
var $dbname = DB_name ;
var $statusCndb = 0;
var $CheckObj;
var $cndblink = "Nocndb";
var $queryIP;
var $resulf;
var $sql;
var $rows;
var $arr;
var $new_id;
function Cndb($dbname='',$hostname='',$username='',$passname=''){
if($this->statusCndb ==1){
$this->Cdb();
$this->statusCndb = 0;
}
if($hostname != ""){$this->host = $hostname;}
if($username != ""){$this->user = $username;}
if($passname != ""){$this->pass = $passname;}
if($dbname != ""){$this->dbname = $dbname;}
$this->cndblink = mysql_connect($this->host,$this->user,$this->pass)or die("ไม่สามารถติดต่อฐานข้อมูลได้");
Mysql_Query("SET NAMES ".DB_coder);
if($this->cndblink){
$this->statusCndb = 1;
}
mysql_select_db($this->dbname);
}
function Query($sql){
$this->queryIP = Mysql_Query($sql);
return $this->queryIP;
mysql_free_result($this->queryIP);
}
function New_id($tbname,$file_id,$format=''){
$this->sql = "Select ".$file_id." From ".$tbname." Order by ".$file_id." DESC limit 0,1 " ;
$this->result = Mysql_Query($this->sql)or die("ภาษา Sql ผิด
".mysql_error()."
".$sql);
$this->rows = mysql_num_rows($this->result);
if($this->rows == 0){
$format = substr($format,0,-1);
$this->new_id = $format."0";
}else{
$this->arr = mysql_fetch_assoc($this->result);
$format = substr($format,0,- strlen($this->arr[$file_id]));
$this->new_id = $this->arr[$file_id]+1;
$this->new_id = $format.$this->new_id;
}
mysql_free_result($this->result);
return $this->new_id;
}
function Cdb(){
Mysql_close($this->cndblink)or die("ไม่สามารถปิดฐานข้อมูลได้");
}
function encode($value){
$code="";
for($i=0;$i";
$encode_value = number_format((((($code*6)-458)/4)),0,"","");
return $encode_value;
}
function decode($value){
$number2 = $value1{strlen($value1)-1};
$decode_value = number_format((((($value)*4)+458)/6),0,"","");
#echo $decode_value,"
";
$k=0;
for($i=0;$i<4;$i++){
#echo $decode_value{0};
for($j=1;$j<=$decode_value{0};$j++){
$number .= $decode_value{$j};
$k++;
}
#echo $number,"
";
$txt .= sprintf("%c",$number);
$decode_value = substr($decode_value,$k+1);
#echo $k;
$number = "";
$k=0;
}
#echo $number;
return $txt;
}
}
?>
class HtmlObj{
Var $sql;
Var $resulf;
Var $arr;
Var $htmlobj;
Var $javafoot='';
Var $alert;
Var $alert_value;
Var $table;
Var $field_id;
Var $field_name;
Var $value_def;
Var $text_def;
Var $name;
Var $funcname;
Var $formname;
Var $textjava;
Var $where;
Var $lists1;
Var $lists2;
Var $type_image;
var $upload_error = 0;
var $txtupload_error = "";
var $file_name = "";
var $maxsizefile = "30000";
Var $file_type_all;
function get_ip(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function set_name($value=''){$this->name = $value;}
function set_func_name($value=''){$this->funcname = $value;}
function set_form_name($value=''){$this->formname = $value;}
function set_alert($value=''){$this->alert = $value;}
function set_table($value='',$value2='',$value3='',$value4=''){$this->table = $value;$this->field_id = $value2;$this->field_name = $value3;$this->where = $value4;}
function set_def($value='',$value2=''){$this->value_def = $value;$this->text_def = $value2;}
function type_file($value=''){return $this->type_image;}
//function สร้าง TextBox
function ObjTB($name='',$value='',$detail='',$star='no'){
$this->name = $name;
$this->htmlobj = "\n";
if($this->alert != "" && $this->funcname !="" ){
if($star != "no") $this->htmlobj .= "*";
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".value=='' && status == true){ \n txt = txt+ '".$this->alert."\\n'; \n document.".$this->formname.".".$this->name.".focus(); \n status=false; \n }\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End function สร้าง TextBox
//function สร้าง TextFile
function ObjFile($name='',$value='',$detail=''){
$this->name = $name;
$this->htmlobj = "\n";
if($this->alert != "" && $this->funcname !="" ){
$this->htmlobj .= "*";
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".value=='' && status == true){ \n txt = txt+ '".$this->alert."\\n'; \n document.".$this->formname.".".$this->name.".focus(); \n status=false; \n }\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End function สร้าง TextFile
//function สร้าง TextPass
function alert_value($value=""){$this->alert_value = $value;}
function ObjPW($name='',$value='',$detail='',$star='no'){
$this->name = $name;
if($this->alert_value == "") $this->alert_value = " == '' ";
$this->htmlobj = "\n";
if($this->alert != "" && $this->funcname !="" ){
if($star != "no") $this->htmlobj .= "*";
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".value ".$this->alert_value." && status == true){ \n txt = txt+ '".$this->alert."\\n'; \n document.".$this->formname.".".$this->name.".focus(); \n status=false; \n }\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End function สร้าง TextPass
//function สร้าง TextArea
function ObjTA($name='',$rows,$cols,$value='',$detail=''){
$this->name = $name;
$this->htmlobj = "\n";
if($this->alert != "" && $this->funcname !="" ){
$this->htmlobj .= "*";
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".value=='' && status == true){ \n txt = txt+ '".$this->alert."\\n'; \n document.".$this->formname.".".$this->name.".focus(); \n status=false; \n }\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End function สร้าง TextArea
//Function ObjSl
function set_ObjSL($value1="",$value2=""){
$this->lists1 = $value1;
$this->lists2 = $value2;
}
function ObjSL($name='',$select='',$detail=""){
$this->name = $name;
$this->htmlobj = "\n";
if($this->value_def != "" && $this->text_def != "" && $this->alert != ""){
$this->htmlobj .= "*";
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".value=='".$this->value_def."' && status == true){ \n txt = txt+ '".$this->alert."\\n'; document.".$this->formname.".".$this->name.".focus(); \n \n status=false; \n }\n";
}
$this->alert = "";
$this->table = "";
$this->field_id = "";
$this->value_def = "";
$this->text_def = "";
return $this->htmlobj;
}
//End Function ObjSl
//Function checkbox
function ObjCB($name,$value='',$checked=''){
$this->name = $name;
$this->htmlobj = "htmlobj .= "Checked "; }
$this->htmlobj .= ">\n";
if($this->alert != "" && $this->funcname !="" ){
$this->javafoot .= "if(document.".$this->formname.".".$this->name.".checked==false && status == true){ \n txt = txt+ '".$this->alert."\\n'; \n document.".$this->formname.".".$this->name.".focus(); \n status=false; \n }\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End Function checkbox
//Function radio
function Obj_RB($name,$value='',$detail=''){
$this->name = $name;
$this->htmlobj = "";
if($this->alert != "" && $this->funcname !="" ){
$this->javafoot .= "
for(i=0;iformname.".".$this->name.".length;i++){
if(document.".$this->formname.".".$this->name."[i].checked == false) radio = radio+1;
}\n
if(radio == document.".$this->formname.".".$this->name.".length && status == true){
txt = txt+ '".$this->alert."\\n';
document.".$this->formname.".".$this->name."[0].focus(); \n
\n status=false; \n
}
radio = 0;
";
}
$this->alert = "";
return $this->htmlobj;
}
//end function radio
//Function ObjArray
function ObjCB_Arr($name,$value='',$type='checkbox',$detail=''){
$this->name = $name;
$this->htmlobj = "\n";
if($this->alert != "" && $this->funcname !="" ){
$this->javafoot .= "
for(i=0;iformname.".elements.length);i++){
if(document.".$this->formname.".elements[i].checked == true) radio = 0;
}
if(radio == 1 && status == true){
txt = txt+ '".$this->alert."\\n';
\n status=false;
radio = 1;
}\n";
}
$this->alert = "";
return $this->htmlobj;
}
//End Function ObjArray
//function สร้าง Form
function Form($name='',$method='POST',$action='',$detail=''){
$this->formname = $name;
$this->htmlobj = "\n";
$this->javafoot = "";
return $this->textjava;
}
//Function วันที่
function date_format($format='(dd)/(mm)/(yy)',$date='',$date_base=''){
$month["01"] = "มกราคม";
$month["02"] = "กุมภาพันธ์";
$month["03"] = "มีนาคม";
$month["04"] = "เมษายน";
$month["05"] = "พฤษภาคม";
$month["06"] = "มิถุนายน";
$month["07"] = "กรกฏาคม";
$month["08"] = "สิงหาคม";
$month["09"] = "กันยายน";
$month["10"] = "ตุลาคม";
$month["11"] = "พฤศจิกายน";
$month["12"] = "ธันวาคม";
$month2["01"] = "มค.";
$month2["02"] = "กพ.";
$month2["03"] = "มีค.";
$month2["04"] = "เมย.";
$month2["05"] = "พค.";
$month2["06"] = "มิย.";
$month2["07"] = "กค.";
$month2["08"] = "สค.";
$month2["09"] = "กย.";
$month2["10"] = "ตค.";
$month2["11"] = "พย.";
$month2["12"] = "ธค.";
$day["0"] = "อาทิตย์";
$day["1"] = "จันทร์";
$day["2"] = "อังคาร";
$day["3"] = "พุธ";
$day["4"] = "พฤหัสบดี";
$day["5"] = "ศุกร์";
$day["6"] = "เสาร์";
$day2["0"] = "อา.";
$day2["1"] = "จ.";
$day2["2"] = "อ.";
$day2["3"] = "พ.";
$day2["4"] = "พฤ.";
$day2["5"] = "ศ.";
$day2["6"] = "ส.";
if($date_base != "" && strlen($date_base) > 8){
$xx = split(" ",$date_base);
$day = split("-",$xx[0]);
$time = split(":",$xx[1]);
$date = mktime($time[0],$time[1],$time[2],$day[1],$day[2],$day[0]);
}else if($date_base != "" && strlen($date_base) <= 8){
$day = split("-",$date_base);
$date = mktime(0,0,0,$day[1],$day[2],$day[0]);
}else if($date == '') $date = time();
$format = str_replace("(d)",date("j",$date),$format);
$format = str_replace("(dd)",date("d",$date),$format);
$format = str_replace("(ddd)",date("D",$date),$format);
$format = str_replace("(DD)",$day[date("w",$date)],$format);
$format = str_replace("(D)",$day2[date("w",$date)],$format);
$format = str_replace("(mm)",date("m",$date),$format);
$format = str_replace("(yy)",date("Y",$date)+543,$format);
$format = str_replace("(MM)",$month[date("m",$date)],$format);
$format = str_replace("(M)",$month2[date("m",$date)],$format);
$format = str_replace("(H)",date("H",$date),$format);
$format = str_replace("(i)",date("i",$date),$format);
$format = str_replace("(s)",date("s",$date),$format);
return $format;
}
//End Function วันที่
//Function upload pic
function up_pic($part,$file){
if($file["tmp_name"] != ""){
$Qtmp = $file["tmp_name"];
$Qsize = $file["size"];
$Qname = $file["name"];
$Qtype = $file["type"];
$this->type_image = $file["type"] ;
if($Qtype == "image/gif"){
$Qtype = ".gif";
}else if($Qtype == "image/bmp"){
$Qtype = ".bmp";
}else if($Qtype == "image/png" ){
$Qtype = ".png";
}else if($Qtype == "image/jpg" || $Qtype == "image/jpeg" || $Qtype == "image/pjpeg"){
$Qtype = ".jpg";
}else{
$this->upload_error = 1;
$this->txtupload_error = "ระบบอนุญาติให้ใช้ไฟล์ภาพนามสกุล .gif .bmp .png .jpg .jpeg .pjpeg เท่านั้นค่ะ";
}
if($Qsize > $this->maxsizefile && $this->upload_error != 1){
$this->upload_error = 1;
$this->txtupload_error = "ไฟล์ภาพของท่านมีขนาดใหญ่เกินไปค่ะ";
}
if($this->upload_error == 0){
$filename = time().rand(10,99).$Qtype;
copy($Qtmp,$part.$filename);
return $filename;
}
}
}
//End function upload pic
// function upload file
function up_file($part,$file){
if($file["tmp_name"] != ""){
$Qtmp = $file["tmp_name"];
$Qsize = $file["size"];
$Qname = $file["name"];
$Qtype = $file["type"];
$this->type_image = $file["type"] ;
if($Qtype == "application/msword"){
$Qtype = ".doc";
}else if($Qtype == "application/pdf"){
$Qtype = ".pdf";
}else if($Qtype == "application/vnd.ms-excel" ){
$Qtype = ".xls";
}else{
$this->upload_error = 1;
$this->txtupload_error = "ระบบอนุญาติให้ใช้ไฟล์นามสกุล .doc .pdf .xls เท่านั้นค่ะ";
}
if($Qsize > $this->maxsizefile && $this->upload_error != 1){
$this->upload_error = 1;
$this->txtupload_error = "ไฟล์ของท่านมีขนาดใหญ่เกินไปค่ะ";
}
if($this->upload_error == 0){
$filename = time().rand(10,99).$Qtype;
copy($Qtmp,$part.$filename);
return $filename;
}
}
}
function setsizefile($value){$this->maxsizefile = $value;}
function fileerror($value=''){return $this->upload_error; $this->upload_error = 0;$this->txtupload_error = "";}
function txtfileerror($value=''){return $this->txtupload_error; }
function set_file_type_all($value=''){$this->file_type_all = $value;}
//End function upload
//Function upload all
function up_all($part,$file,$filename=''){
if($file["tmp_name"] != ""){
$Qtmp = $file["tmp_name"];
$Qsize = $file["size"];
$Qname = $file["name"];
$Qtype = $file["type"];
$this->type_image = $file["type"] ;
#echo $file["type"];
#exit();
if(!isset($this->file_type_all[$file["type"]][0])){
$this->upload_error = 1;
$this->txtupload_error = "ระบบไม่อนุญาติให้ใช้ไฟล์นามสกุล ที่ท่านเลือก ค่ะ";
}else{
$Qtype = $this->file_type_all[$file["type"]][1];
}
if($Qsize > $this->maxsizefile && $this->upload_error != 1){
$this->upload_error = 1;
$this->txtupload_error = "ไฟล์ของท่านมีขนาดใหญ่เกินไปค่ะ";
}
if($this->upload_error == 0){
if($filename != ""){
$filename = $filename.$Qtype;
}else{
$filename = time().rand(10,99).$Qtype;
}
copy($Qtmp,$part.$filename);
return $filename;
}
}
}
//End function upload pic
//Function แบ่งหน้า
function Select_page($sql,$page='1',$max='15',$link=''){
$resulf = Mysql_Query($sql);
$rows = Mysql_num_rows($resulf);
if($rows <= $max){
$total_page = 1;
}else{
$xxx = explode(".",(number_format($rows/$max,1)));
if($xxx[1] < 5 && $xxx[1] != 0) $i=1; else $i=0;
$total_page = (number_format($rows/$max,0,"",""))+$i;
}
if(!isset($page) || $page == "") $page = '1';
echo " of ",$total_page;
if($page=='1'){
$resql = $sql." limit 0,".$max." ";
}else{
$start = $max*($page-1);
$resql = $sql." limit ".$start.",".$max." ";
}
return $resql;
}
//End Function แบ่งหน้า
function text_read($Msg){
// ให้ขึ้นบันทัดใหม่ กรณีที่มีการเคาะ Enter
$Msg = eregi_replace(chr(13),"
",$Msg );
$Msg = eregi_replace(chr(32)," ",$Msg );
$Msg = eregi_replace(chr(9),"",$Msg );
$Msg = eregi_replace("(^|[>[:space:]\n])([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])([<[:space:]\n]|$)","\\2://\\3\\4", $Msg );
$Msg = eregi_replace("([[:alnum:]]+)@([^[:space:]]*)([[:alnum:]])([<[:space:]\n]|$)","\\1@\\2\\3", $Msg );
return $Msg;
}
}
?>
-:- การจัดการความรู้ Knowledge Management : คณะวิทยาการจัดการ มหาวิทยาลัยราชภัฎลำปาง -:-