"; print $this->queryString; print "
"; } function printError() { print "
"; print $this->queryString; print ""; print mysqli_error($GLOBALS['conn']); print "
"; } function prepareInsertField($binds) { for ($i=0; $i $value) { //$value = str_replace("'", "\'", $value); //$value = str_replace("\\\'", "\'", $value); //$value = mysql_real_escape_string($value); $FIELDS .= "`".$key."`, "; if (strtoupper($value)=='NULL') { $VAULES .= " NULL, "; }else{ $VAULES .= "'".$value."', "; } } $FIELDS = substr($FIELDS, 0, -2); $VAULES = substr($VAULES, 0, -2); $sql = str_replace('{FIELDS}', $FIELDS, $sql); $sql = str_replace('{VAULES}', $VAULES, $sql); return (count($binds)>0)?$sql:''; } function prepareUpdate($table, $binds, $id) { $this->sql_log = ""; $sql = "SELECT * FROM ".$table." WHERE ".$this->pk."='".$id."'"; $row = $this->getObject($sql); $sql = "UPDATE ".$table." SET {FIELDS} WHERE ".$this->pk."='".$id."'"; foreach ($binds as $key=>$value ) { //$value = str_replace("'", "\'", $value); //$value = str_replace("\\\'", "\'", $value); //$value = mysql_real_escape_string($value); if ($value!=$row->$key) { if (strtoupper($value)=='NULL') { $FIELDS .= "`".$key."`= NULL, "; }else{ $FIELDS .= "`".$key."`='".$value."', "; } } } $FIELDS = substr($FIELDS, 0, -2); $sql = str_replace('{FIELDS}', $FIELDS, $sql); return ($FIELDS!='')?$sql:''; } function prepareQuery($sql, $values) { $sqls = explode('?', $sql); for ($i=0; $iprepareQuery($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']."')"; mysqli_query($GLOBALS['conn'], $sql_log); } $result = mysqli_query($GLOBALS['conn'], $sql); //$this->printQuery(); if (!$result) { $this->printError(); } return $result; } function insertData($table, $binds) { $sql = $this->prepareInsert($table, $binds); //print $sql; $result = $this->query($sql); return $result; } function updateData($table, $binds, $id) { $result = ''; $sql = $this->prepareUpdate($table, $binds, $id); if ($sql!='') { $result = $this->query($sql); } return $result; } function hasData($sql, $values='') { $result = $this->query($sql, $values); if ($result) { $record = mysqli_num_rows($result); }else{ $record = 1; } 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); } 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 = mysqli_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 = mysqli_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 = mysqli_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; } 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; } 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 = mysqli_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 = mysqli_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 = mysqli_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; } } return $rows; } function getObject($sql, $values='') { $result = $this->query($sql, $values); if ($result) { $row = mysqli_fetch_object($result); } return $row; } function getRecordCount($sql, $arrs='') { $result = $this->query($sql, $arrs); if ($result) { $record = mysqli_num_rows($result); }else{ $record = 0; } 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 .= ""; } } 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; $iquery($sql, $values); if ($result) { while($arr = mysqli_fetch_array($result, MYSQL_ASSOC)) { for ($i=0; $ilistField($sql); $data = ""; // header for ($i=0; $iquery($sql, $values); if ($result) { while($arr = mysqli_fetch_array($result, MYSQL_ASSOC)) { for ($i=0; $iquery($sql); $i = 0; while($iname; $i++; } return $fields; } function viewData($sql, $sql2, $values='') { $heads = $this->listField($sql); $data = "
"; // header for ($i=0; $i\n"; } $data .= ""; //data $result = $this->query($sql, $values); if ($result) { while($arr = mysqli_fetch_array($result)) { $color = ($color=='#CCCCCC')?'#FFFFFF':'#CCCCCC'; $data .= "\n"; for ($i=0; $i\n"; } $data .= "\n"; } } $data .= ""; $result = $this->query($sql2, $values); if ($result) { while($arr = mysqli_fetch_array($result)) { $data .= "\n"; for ($i=0; $i0) { $data .= "\n"; }else{ $data .= "\n"; } } $data .= "\n"; } } $data .= "
".sprintf("%0.2f", $arr[$field])."".$arr[$field]."
"; print $data; } } ?>