-
✘✘✘ WIBUHAX0R1337 ✘✘✘
-
✘
PATCH :
/
var
/
www
/
clients
/
client4
/
web4
/
web
/
ris
/
includes
/
lib
/
Upload File:
files >> /var/www/clients/client4/web4/web/ris/includes/lib/DBLite.class.php
<?php class DBLite { var $pk = 'id'; var $debug = false; var $queryString; var $sqlpath; var $conn; var $page_url = "admin.php"; var $totalrecord = 0; var $totalpage = 0; var $pagesize = 20; var $page = 1; var $order_by = "id"; var $order_range = "ASC"; function createPage($sql, $array='') { $this->totalrecord = $this->getRecordCount($sql, $array); $this->pagesize = ($this->pagesize>0)?$this->pagesize:$this->totalrecord; $this->totalpage = (int) ($this->totalrecord / $this->pagesize); if (($this->totalrecord % $this->pagesize) != 0) { $this->totalpage += 1; } $this->start = $this->pagesize * ($this->page - 1); if ($this->start < 0) { $this->start = 0; $this->pagenow = 1; } if ($this->order_by != '') { //$sql .= " ORDER BY ".$this->order_by." ".$this->order_range; } $sql .= " LIMIT ".$this->start.", ".$this->pagesize; return $sql; } function pagination() { global $g_util; $isFirst = ($this->page<2)?true:false; $isLast = ($this->page==$this->totalpage || $this->totalpage ==0)?true:false; $html = ""; $html .= "\n<div class=\"w3-cell-row\">"; $html .= "\n <div class=\" w3-cell w3-cell-middle\">"; $html .= "\n ทั้งหมด <b>".$this->totalrecord."</b> รายการ</div>"; if ($this->totalrecord>0) { $html .= "\n <div class=\" w3-cell w3-cell-middle w3-right-align\">"; if (!$isFirst) { $html .= "\n <a href=\"".$this->page_url."1"."\" title=\"แรกสุด\" class=\"w3-button\"><i class=\"fa fa-step-backward\" aria-hidden=\"true\"></i></a>"; $html .= "\n <a href=\"".$this->page_url.($this->page-1)."\" title=\"ก่อนหน้า\" class=\"w3-button\"><i class=\"fa fa-caret-left\" aria-hidden=\"true\"></i></a>"; }else{ $html .= "\n <!--i class=\"fa fa-step-backward\" aria-hidden=\"true\"></i>"; $html .= "\n <i class=\"fa fa-caret-left\" aria-hidden=\"true\"></i-->"; } $html .= "\n <b class=\"w3-margin-left w3-margin-right\">หน้า ".$this->page." จาก ".$this->totalpage."</b> "; if (!$isLast) { $html .= "\n <a href=\"".$this->page_url.($this->page+1)."\" title=\"ถัดไป\" class=\"w3-button\"><i class=\"fa fa-caret-right\" aria-hidden=\"true\"></i></a>"; $html .= "\n <a href=\"".$this->page_url.$this->totalpage."\" title=\"ท้ายสุด\" class=\"w3-button\"><i class=\"fa fa-step-forward\" aria-hidden=\"true\"></i></a>"; }else{ $html .= "\n <!--i class=\"fa fa-caret-right\" aria-hidden=\"true\"></i>"; $html .= "\n <i class=\"fa fa-step-forward\" aria-hidden=\"true\"></i-->"; } $html .= "\n </div>"; } $html .= "\n</div>"; print $html; } function pageNo($i, $revert=false) { if ($revert) { return ($this->totalrecord+1) - ((($this->page-1)*$this->pagesize)+($i+1)); }else{ return (($this->page-1)*$this->pagesize)+($i+1); } } function connect($db='', $user='', $pwd='', $host='localhost') { $this->conn = mysqli_connect($host, $user, $pwd, $db); // Check connection if (!$this->conn) { die("Connection failed: " . mysqli_connect_error()); } //echo "Connected successfully"; // mysql_connect($host, $user, $pwd) or die("Could not connect: " . mysql_error()); // mysql_select_db($db); // mysql_query("SET NAMES 'utf8'"); } function close() { mysqli_close($this->conn); } function selectDB($db) { mysql_select_db($db); } function printQuery() { print "<hr><span style=\"color:#0000FF;\">"; print $this->queryString; print "</span><hr>"; } function printError() { //print "<hr><span style=\"color:#FF0000;\">"; //print mysql_error(); //print "</span><hr>"; } function prepareInsertField($binds) { for ($i=0; $i<count($binds); $i++) { $arr_fields = array_keys($binds); if ($i<count($binds)-1) { $FIELDS .= "`".$arr_fields[$i]."`, "; }else{ $FIELDS .= "`".$arr_fields[$i]."`"; } } return $FIELDS; } function prepareInsertValue($binds) { for ($i=0; $i<count($binds); $i++) { $arr_fields = array_keys($binds); $value = str_replace("'", "\'", $binds[$arr_fields[$i]]); $value = trim(str_replace("\\\'", "\'", $value)); if ($i<count($binds)-1) { $VAULES .= "'".$value."', "; }else{ $VAULES .= "'".$value."'"; } } return $VAULES; } function prepareInsert($table, $binds) { $sql = "INSERT INTO ".$table." ({FIELDS}) VALUES ({VAULES})"; for ($i=0; $i<count($binds); $i++) { $arr_fields = array_keys($binds); $value = str_replace("'", "\'", $binds[$arr_fields[$i]]); $value = str_replace("\\\'", "\'", $value); if ($i<count($binds)-1) { $FIELDS .= "`".$arr_fields[$i]."`, "; }else{ $FIELDS .= "`".$arr_fields[$i]."`"; } if ($i<count($binds)-1) { $VAULES .= "'".$value."', "; }else{ $VAULES .= "'".$value."'"; } } $sql = str_replace('{FIELDS}', $FIELDS, $sql); $sql = str_replace('{VAULES}', $VAULES, $sql); return (count($binds)>0)?$sql:''; } function prepareUpdate($table, $binds, $id) { $sql = "UPDATE ".$table." SET {FIELDS} WHERE ".$this->pk."='".$id."'"; for ($i=0; $i<count($binds); $i++) { $arr_fields = array_keys($binds); $value = str_replace("'", "\'", $binds[$arr_fields[$i]]); $value = str_replace("\\\'", "\'", $value); if ($i<count($binds)-1) { $FIELDS .= "`".$arr_fields[$i]."`='".$value."', "; }else{ $FIELDS .= "`".$arr_fields[$i]."`='".$value."'"; } } $sql = str_replace('{FIELDS}', $FIELDS, $sql); return (count($binds)>0)?$sql:''; } function prepareQuery($sql, $values) { $sqls = explode('?', $sql); for ($i=0; $i<count($sqls)-1; $i++) { $newsql .= $sqls[$i]."'".$values[$i]."'"; } $newsql .= $sqls[$i]; return $newsql; } function query($sql, $values='') { $sql = ($values=='')?$sql:$this->prepareQuery($sql, $values); $this->queryString = $sql; // $sql_key = strtoupper(substr($sql, 0, 6)); // if ($sql_key == 'INSERT' || $sql_key == 'UPDATE' || $sql_key == 'DELETE') { // $sql_log = "INSERT INTO `log_sql` (LogDate, LogSQL, LogUser) VALUES (NOW(), '".str_replace("'", "\'", $sql)."', '".$_SESSION['ssb_admin_user']."')"; // mysql_query($sql_log); // } $result = mysqli_query($this->conn, $sql); //$this->printQuery(); if (!$result) { $this->printError(); } return $result; } function insertData($table, $binds) { $sql = $this->prepareInsert($table, $binds); $result = $this->query($sql); return $result; } function updateData($table, $binds, $id) { $sql = $this->prepareUpdate($table, $binds, $id); //echo $sql; $result = $this->query($sql); return $result; } function hasData($sql, $values='') { $result = $this->query($sql, $values); if ($result) { $record = mysqli_num_rows($result); mysqli_free_result($result); }else{ $record = 0; } return ($record>0)?true:false; } function getLastID($table) { $sql = "SELECT MAX(".$this->pk.") AS LastID FROM ".$table." WHERE 1"; $result = $this->query($sql, $values); if ($result) { $row = mysqli_fetch_object($result); } mysqli_free_result($result); return $row->LastID; } function getFirstID($table) { $sql = "SELECT MIN(".$this->pk.") AS FirstID FROM ".$table." WHERE 1"; $result = $this->query($sql, $values); if ($result) { $row = mysql_fetch_object($result); } return $row->FirstID; } function getNextID($table, $id) { $sql = "SELECT MIN(".$this->pk.") AS NextID FROM ".$table." WHERE ".$this->pk.">'".$id."' "; $result = $this->query($sql, $values); if ($result) { $row = mysql_fetch_object($result); } return $row->NextID; } function getPrevID($table, $id) { $sql = "SELECT MAX(".$this->pk.") AS PrevID FROM ".$table." WHERE ".$this->pk."<'".$id."' "; $result = $this->query($sql, $values); if ($result) { $row = mysql_fetch_object($result); } return $row->PrevID; } function getTotalRecord($table) { $sql = "SELECT ".$this->pk." FROM ".$table." WHERE 1"; $result = $this->query($sql); if ($result) { $record = mysqli_num_rows($result); }else{ $record = 0; } mysqli_free_result($result); return $record; } function getCurrentRecord($table, $id) { $sql = "SELECT ".$this->pk." FROM ".$table." WHERE ".$this->pk."<='".$id."' "; $result = $this->query($sql, $arrs); if ($result) { $record = mysqli_num_rows($result); }else{ $record = 0; } mysqli_free_result($result); return $record; } function getValues() { } function getValue($sql, $values='') { $result = $this->query($sql, $values); if ($result) { $arr = mysqli_fetch_array($result); } return $arr[0]; } function getArrays($sql, $auto_no='', $opt=MYSQL_ASSOC) { $arrs = array(); $result = $this->query($sql, $values); if ($result) { $index = 1; while($arr = mysql_fetch_array($result, $opt)) { if ($auto_no!='') { $arr[$auto_no] = $index++; } $arrs[] = $arr; } } return $arrs; } function getArray($sql, $opt=MYSQL_ASSOC) { $arrs = array(); $result = $this->query($sql, $values); if ($result) { $arr = mysql_fetch_array($result, $opt); } return $arr; } function getJSON($sql, $values='') { $arrs = $this->getArray($sql); return json_encode($arrs); } function getJSONs($sql, $auto_no='') { $arrs = $this->getArrays($sql, $auto_no); return json_encode($arrs); } function getObjectsByLang($sql, $values='') { $rows = array(); $result = $this->query($sql, $values); if ($result) { while($row = mysql_fetch_object($result)) { $rows[$row->language_id] = $row; } } return $rows; } function getObjects($sql, $values='') { $rows = array(); $result = $this->query($sql, $values); if ($result) { while($row = mysqli_fetch_object($result)) { $rows[] = $row; } } mysqli_free_result($result); return $rows; } function getObject($sql, $values='') { $result = $this->query($sql, $values); if ($result) { $row = mysqli_fetch_object($result); } mysqli_free_result($result); return $row; } function getRecordCount($sql, $arrs='') { $result = $this->query($sql, $arrs); if ($result) { $record = mysqli_num_rows($result); }else{ $record = 0; } mysqli_free_result($result); return $record; } function deleteData($table, $id) { $sql = "DELETE FROM ".$table." WHERE ".$this->pk."='".$id."'"; return $this->query($sql); } function getSQLDate($date='') { return ''; } function getOption($sql, $sel="", $cpid=true) { $html = ""; $i = 0; $result = $this->query($sql); if ($result) { while ($arr = mysqli_fetch_array($result)) { $selected=""; if ($cpid) { if ($arr[0] == $sel) { $selected=" selected"; } }else{ if ($arr[1] == $sel) { $selected=" selected"; } } $html .= "<option value=\"".$arr[0]."\"".$selected." class=\"".$arr[2]."\">".$arr[1]."</option>\n"; } } mysqli_free_result($result); return $html; } function getSqlFromText($file) { $filename = $this->SQL_PATH.$file.".sql"; if (is_file($filename)) { $fd = fopen ($filename, "r"); $sql = fread ($fd, filesize ($filename)); fclose ($fd); } return $sql; } function setSQLPath($path='includes/sql/') { $this->SQL_PATH = $path; } function getCSV($header, $sql, $values='') { $heads = array_keys($header); $data = ""; // header for ($i=0; $i<count($header); $i++) { $field = $heads[$i]; if ($i==count($header)-1) { $data .= "\"".$field."\""; }else{ $data .= "\"".$field."\","; } } $data .= "\n"; for ($i=0; $i<count($header); $i++) { $field = $heads[$i]; if ($i==count($header)-1) { $data .= "\"".$header[$field]."\""; }else{ $data .= "\"".$header[$field]."\","; } } $data .= "\n"; //data $result = $this->query($sql, $values); if ($result) { while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; if ($i==count($heads)-1) { $data .= "\"".$arr[$field]."\""; }else{ $data .= "\"".$arr[$field]."\","; } } $data .= "\n"; } } return $data; } function toCSV($sql, $values='') { $heads = $this->listField($sql); $data = ""; // header for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; if ($i==count($header)-1) { $data .= "\"".$field."\""; }else{ $data .= "\"".$field."\","; } } $data .= "\n"; //data $result = $this->query($sql, $values); if ($result) { while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; if ($i==count($heads)-1) { $data .= "\"".$arr[$field]."\""; }else{ $data .= "\"".$arr[$field]."\","; } } $data .= "\n"; } } return $data; } function listTable($db) { $tables = array(); $result = mysql_list_tables($db); $num_rows = mysql_num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $tables[$i] = mysql_tablename($result, $i); } return $tables; } function listField($sql) { $fields = array(); $result = $this->query($sql); $i = 0; while($i<mysql_num_fields($result)) { $meta=mysql_fetch_field($result,$i); $fields[$i] = $meta->name; $i++; } return $fields; } function viewData($sql, $sql2, $values='') { $heads = $this->listField($sql); $data = " <div class=\"grid_8 height250\"><table class=\"fancyTable\" id=\"data_view\" cellpadding=\"0\" cellspacing=\"0\"> <thead> <tr>"; // header for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; $data .= "<th>".$field."</th>\n"; } $data .= "</tr> </thead> <tbody>"; //data $result = $this->query($sql, $values); if ($result) { while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { $color = ($color=='#CCCCCC')?'#FFFFFF':'#CCCCCC'; $data .= "<tr>\n"; for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; $data .= "<td>".$arr[$field]."</td>\n"; } $data .= "</tr>\n"; } } $data .= "</tbody> <tfoot>"; $result = $this->query($sql2, $values); if ($result) { while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { $data .= "<tr>\n"; for ($i=0; $i<count($heads); $i++) { $field = $heads[$i]; if ($i>0) { $data .= "<td>".sprintf("%0.2f", $arr[$field])."</td>\n"; }else{ $data .= "<td>".$arr[$field]."</td>\n"; } } $data .= "</tr>\n"; } } $data .= "</tfoot> </table></div>"; print $data; } } ?>
2022 - 2023 Copyright By Lutfifakee || Padang Blackhat ♥