diff --git a/index.php b/index.php
index 2641c58..38a9972 100644
--- a/index.php
+++ b/index.php
@@ -108,63 +108,19 @@
if(!is_dir($controller_dir)) die("Seme framework directory missing : ".pathinfo(__FILE__, PATHINFO_BASENAME));
if(!is_dir($core_dir)) die("Seme framework directory missing : ".pathinfo(__FILE__, PATHINFO_BASENAME));
-if(!defined('SENEROOT')) define('SENEROOT',__DIR__.DIRECTORY_SEPARATOR);
-if(!defined('SENEAPP')) define('SENEAPP',str_replace("\\", "/",$apps_dir));
-if(!defined('SENEASSETS')) define('SENEASSETS',$assets_dir);
-if(!defined('SENESYS')) define('SENESYS',$ssys_dir);
-if(!defined('SENEKEROSINE')) define('SENEKEROSINE',$kerosine_dir);
-if(!defined('SENELIB')) define('SENELIB',$library_dir);
-if(!defined('SENECACHE')) define('SENECACHE',$cache_dir);
-if(!defined('SENECFG')) define('SENECFG',$config_dir);
-if(!defined('SENEMODEL')) define('SENEMODEL',$model_dir);
-if(!defined('SENEVIEW')) define('SENEVIEW',$view_dir);
-if(!defined('SENECONTROLLER')) define('SENECONTROLLER',$controller_dir);
-if(!defined('SENECORE')) define('SENECORE',$core_dir);
-
-if(!isset($_SERVER['HTTP_HOST'])) $_SERVER['HTTP_HOST'] = 'localhost';
-if(!file_exists(SENECFG."/config.php")) die('unable to load config file : config.php');
-require_once(SENECFG."/config.php");
-$GLOBALS['sene_method'] = $sene_method;
-
-if(!file_exists(SENECFG."/controller.php")) die('unable to load config file : controller.php');
-require_once(SENECFG."/controller.php");
-
-if(!file_exists(SENECFG."/timezone.php")) die('unable to load config file : timezone.php');
-require_once(SENECFG."/timezone.php");
-
-if(!file_exists(SENECFG."/database.php")) die('unable to load config file : database.php');
-require_once(SENECFG."/database.php");
-
-if(!file_exists(SENECFG."/session.php")) die('unable to load config file : session.php');
-require_once(SENECFG."/session.php");
-if(!defined('SALTKEY')) define('SALTKEY',$saltkey);
-
-if(!file_exists(SENECFG."/core.php")) die('unable to load config file : core.php');
-require_once(SENECFG."/core.php");
-
-$GLOBALS['core_prefix'] = $core_prefix;
-$GLOBALS['core_controller'] = $core_controller;
-$GLOBALS['core_model'] = $core_model;
-
-if(!isset($default_controller,$notfound_controller)){
- $default_controller="welcome";
- $notfound_controller="notfound";
-}
-if(!defined('DEFAULT_CONTROLLER')) define("DEFAULT_CONTROLLER",$default_controller);
-if(!defined('NOTFOUND_CONTROLLER')) define("NOTFOUND_CONTROLLER",$notfound_controller);
-
-if(!isset($site)){
- die('please fill site url / base url in : '.SENECFG.'config.php. Example: https://www.example.com/');
-}
-if(!defined('BASEURL')) define("BASEURL",$site);
-if(!isset($admin_url)){
- $admin_url=$admin_secret_url;
-}
-if(!defined('ADMIN_URL')) define("ADMIN_URL",$admin_url);
-if(!defined('WEBSITE_VIEW_ID')) define("WEBSITE_VIEW_ID",$website_view_id);
-
-$routing = array();
+define('SENEROOT',__DIR__.DIRECTORY_SEPARATOR);
+define('SENEAPP',str_replace("\\", "/",$apps_dir));
+define('SENEASSETS',$assets_dir);
+define('SENESYS',$ssys_dir);
+define('SENEKEROSINE',$kerosine_dir);
+define('SENELIB',$library_dir);
+define('SENECACHE',$cache_dir);
+define('SENECFG',$config_dir);
+define('SENEMODEL',$model_dir);
+define('SENEVIEW',$view_dir);
+define('SENECONTROLLER',$controller_dir);
+define('SENECORE',$core_dir);
require_once SENEKEROSINE."/SENE_Engine.php";
-$se = new SENE_Engine();
-$se->SENE_Engine();
+$se = new SENE_Engine($db);
+$se->run();
diff --git a/kero/sine/SENE_Controller.php b/kero/sine/SENE_Controller.php
index a89eb33..239aec7 100644
--- a/kero/sine/SENE_Controller.php
+++ b/kero/sine/SENE_Controller.php
@@ -277,10 +277,17 @@ public function setDescription($description="en"){
public function setKeyword($keyword="lightweight,framework,php,api,generator"){
$this->keyword = $keyword;
}
- public function setRobots($robots="INDEX,FOLLOW"){
- if($robots != "INDEX,FOLLOW") $robots='NOINDEX,NOFOLLOW';
- $this->robots = $robots;
- }
+
+ /**
+ * Set robots properties for html meta head
+ * @param string $robots robots configuration (INDEX,FOLLOW|INDEX,NOFOLLOW)
+ */
+ protected function setRobots($robots)
+ {
+ $this->robots = $robots;
+ return $this;
+ }
+
public function setIcon($icon="favicon.png"){
$this->icon = $icon;
}
@@ -369,9 +376,16 @@ public function getDescription(){
public function getKeyword(){
return $this->keyword;
}
- public function getRobots(){
- return $this->robots;
- }
+
+ /**
+ * Return string for robots.txt location
+ * @return string keyword
+ */
+ protected function getRobots()
+ {
+ return $this->robots;
+ }
+
public function getIcon($icon="favicon.png"){
return $this->icon;
}
diff --git a/kero/sine/SENE_Engine.php b/kero/sine/SENE_Engine.php
index 01ec9d3..114de80 100644
--- a/kero/sine/SENE_Engine.php
+++ b/kero/sine/SENE_Engine.php
@@ -1,5 +1,52 @@
core_prefix = $GLOBALS['core_prefix'];
- if($GLOBALS['core_controller']) if(!empty($GLOBALS['core_controller'])) $this->core_controller = $GLOBALS['core_controller'];
- if($GLOBALS['core_model']) if(!empty($GLOBALS['core_model'])) $this->core_model = $GLOBALS['core_model'];
+ if(isset($GLOBALS['core_controller'])) if(!empty($GLOBALS['core_controller'])) $this->core_controller = $GLOBALS['core_controller'];
+ if(isset($GLOBALS['core_model'])) if(!empty($GLOBALS['core_model'])) $this->core_model = $GLOBALS['core_model'];
$this->admin_url=ADMIN_URL;
self::$__instance = $this;
@@ -30,8 +78,8 @@ public function __construct(){
$rs[$key] = $val;
}
$this->routes = $rs;
-
- $sene_method = $GLOBALS['sene_method'];
+ $sene_method = 'PATH_INFO';
+ if(isset($GLOBALS['sene_method'])) $sene_method = $GLOBALS['sene_method'];
if(isset($_SERVER['argv'])){
if(count($_SERVER['argv'])>1){
$i=0;
@@ -50,7 +98,7 @@ public function __construct(){
public static function getInstance(){
return self::$_instance;
}
- public function SENE_Engine(){
+ public function run(){
$core_controller_file = SENECORE.$this->core_prefix.$this->core_controller.'.php';
$core_model_file = SENECORE.$this->core_prefix.$this->core_model.'.php';
@@ -135,14 +183,14 @@ private function ovrRoutes($paths=array()){
}
private function newRouteFolder(){
$found=0;
- $sene_method = $GLOBALS['sene_method'];
+ $sene_method = 'PATH_INFO';
+ if(isset($GLOBALS['sene_method'])) $sene_method = $GLOBALS['sene_method'];
if(isset($_SERVER[$sene_method])){
- $path = $_SERVER[$sene_method];
- $path = str_replace("//","/",$path);
- $path = explode("/",str_replace("//","/",$path));
+ $path=$_SERVER[$sene_method];
+ $path=explode("/",$path);
$i=0;
foreach($path as $p){
- if(strlen($p)>0){
+ if(!empty($p)){
$pos = strpos($p, '?');
if ($pos !== false) {
//echo "pos: ".$pos;
@@ -166,7 +214,6 @@ private function newRouteFolder(){
}else{
$this->globalHandlerCMSPage($path);
}
-
$newpath = realpath(SENECONTROLLER.$path[1]);
if(is_dir($newpath)){
@@ -216,7 +263,6 @@ private function newRouteFolder(){
}
}
}
- $_SERVER['SEME_CONTROLLER_CLASS'] = $cname;
$reflection->invokeArgs($cname,$args);
}else{
$this->notFound($newpath);
@@ -258,7 +304,6 @@ private function newRouteFolder(){
}
}
}
- $_SERVER['SEME_CONTROLLER_CLASS'] = $cname;
$reflection->invokeArgs($cname,$args);
}else{
$this->notFound($newpath);
@@ -300,7 +345,6 @@ private function newRouteFolder(){
}
}
}
- $_SERVER['SEME_CONTROLLER_CLASS'] = $cname;
$reflection->invokeArgs($cname,$args);
}else{
@@ -692,8 +736,6 @@ function redir($url,$time=0,$type=1){
}
function base_url($url=""){
if(empty($url)) $url = "";
- //var_dump($url);
- //die();
return BASEURL.$url;
}
function base_url_admin($url=""){
@@ -741,9 +783,13 @@ function get_caller_info() {
}
function seme_error_handling($errno, $errstr, $error_file,$error_line,$error_context){
if(isset($_SERVER['argv'])){
+ echo '======='.PHP_EOL;
+ echo 'ERROR '.PHP_EOL;
+ echo '======='.PHP_EOL;
$backtraces = debug_backtrace();
- $bct = array();
- $fls = array('index.php','sene_controller.php','sene_model.php','sene_engine.php','sene_mysqli_engine.php','runner_controller.php');
+ $bct = array();
+ $fls = array();
+ //$fls = array('index.php','sene_controller.php','sene_model.php','sene_engine.php','sene_mysqli_engine.php');
$ef = explode('/',str_replace('\\','/',$error_file));
if(isset($ef[count($ef)-1])) $ef = $ef[count($ef)-1];
@@ -772,36 +818,34 @@ function seme_error_handling($errno, $errstr, $error_file,$error_line,$error_con
$error_file = $bcts[0]['file'];
$error_line = $bcts[0]['line'];
}
- $error_file = substr($error_file,strlen(SENEROOT));
- print '================= ERROR ===================='.PHP_EOL;
- print $error_file.''.PHP_EOL;
- print 'Line: '.$error_line.PHP_EOL;
- print 'Error: ['.$errno.'] '.$errstr.''.PHP_EOL;
- $error_file = substr($error_file,strlen(SENEROOT));
- print '--------------------------------------------'.PHP_EOL;
- print 'Backtrace: ---------------------------------'.PHP_EOL;
+ echo $error_file.PHP_EOL;
+ echo $error_line.PHP_EOL;
+ echo "Error: [$errno] $errstr".PHP_EOL;
+ echo '-------'.PHP_EOL;
+ echo "Backtrace".PHP_EOL;
$i=0;
foreach($bct as $e){
$i++;
if($i<=-1) continue;
if(!isset($e['file'])) continue;
- $e['file'] = substr($e['file'],strlen(SENEROOT));
- print $i.'. File: '.$e['file'].PHP_EOL;
- print 'Line: '.$e['line'].PHP_EOL;
+ echo 'File: '.$e['file'].PHP_EOL;
+ echo 'Line: '.$e['line'].PHP_EOL;
if(isset($e['class'])){
- print 'Class: '.$e['class'].PHP_EOL;
- print 'Method: '.$e['function'].PHP_EOL;
+ echo 'Class: '.$e['class'].PHP_EOL;
+ echo 'Method: '.$e['function'].PHP_EOL;
}else{
- print 'Function: '.$e['function'].PHP_EOL;
+ echo 'Function: '.$e['function'].PHP_EOL;
}
+
+ echo '--'.PHP_EOL;
}
- print '=========== Seme Framework v'.SENE_VERSION.' ============'.PHP_EOL;
- die();
+ echo '--SEME FRAMEWORK v'.SENE_VERSION.'--'.PHP_EOL;
}else{
- header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
+ header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
$backtraces = debug_backtrace();
- $bct = array();
- $fls = array('index.php','sene_controller.php','sene_model.php','sene_engine.php','sene_mysqli_engine.php');
+ $bct = array();
+ $fls = array();
+ //$fls = array('index.php','sene_controller.php','sene_model.php','sene_engine.php','sene_mysqli_engine.php');
$ef = explode('/',str_replace('\\','/',$error_file));
if(isset($ef[count($ef)-1])) $ef = $ef[count($ef)-1];
@@ -861,5 +905,6 @@ function seme_error_handling($errno, $errstr, $error_file,$error_line,$error_con
echo "
Seme Framework v".SENE_VERSION." Error Handler
";
die();
}
+
}
-if(!isset($_SERVER['SEME_ERR_BYPASS'])) set_error_handler("seme_error_handling");
+set_error_handler("seme_error_handling");
diff --git a/kero/sine/SENE_Model.php b/kero/sine/SENE_Model.php
index 1260f61..4f576ee 100644
--- a/kero/sine/SENE_Model.php
+++ b/kero/sine/SENE_Model.php
@@ -1,6 +1,6 @@
koneksi=mysqli_connect($db['host'],$db['user'],$db['pass'],$db['name']);
-
- $this->__mysqli = new mysqli();
- try {
- $this->__mysqli->connect($db['host'],$db['user'],$db['pass'],$db['name'],$port);
- }catch(Exception $e){
- trigger_error('Tidak dapat tersambung ke database.');
- die();
- }
- if ($this->__mysqli->connect_errno) {
- die('Couldn\'t connect to database. Please, check your database configuration on '.SENECFG.'/database.php');
- }
- $this->__mysqli->set_charset('utf8');
-
- self::$__instance = $this;
-
- $this->in_select = "";
- $this->in_where = "";
- $this->in_order = "";
- $this->table = "";
- $this->is_flush = 0;
- $this->is_cache = 0;
- $this->page = 0;
- $this->pagesize = 0;
- $this->cache_save = 0;
- $this->cache_flush = 0;
- $this->tis_limit = 0;
- $in_join=0;
- $this->as_from = array();
- $this->join = array();
+ $this->koneksi=koneksi_db();
}
- public static function getInstance(){
- return self::$_instance;
- }
- public function autocommit($var=1){
- return $this->__mysqli->autocommit($var);
- }
- public function begin(){
- return $this->__mysqli->begin_transaction();
- }
- public function commit(){
- return $this->__mysqli->commit();
- }
- public function rollback(){
- return $this->__mysqli->rollback();
- }
- public function savepoint($sp){
- return $this->__mysqli->savepoint($sp);
+ public function last_id(){
+ return mysql_insert_id($this->koneksi);
}
- public function debug($sql=""){
- $this->fieldname[] = 'error';
- $this->fieldname[] = 'code';
- $this->fieldname[] = 'sql';
- $this->fieldvalue[] = $this->__mysqli->errno;
- $this->fieldvalue[] = $this->__mysqli->error;
- $this->fieldvalue[] = $sql;
+ public function filter(&$str){
+ $str=filter_var($str,FILTER_SANITIZE_SPECIAL_CHARS);
}
- public function exec($sql){
- $res = $this->__mysqli->query($sql);
+ protected function exec($sql){
+ $res = mysql_query($sql,$this->koneksi);
if($res){
return 1;
}else{
- $this->debug($sql);
- trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
+ $this->fieldname[] = 'error';
+ $this->fieldname[] = 'code';
+ $this->fieldname[] = 'sql';
+ $this->fieldvalue[] = mysql_error($this->koneksi);
+ $this->fieldvalue[] = mysql_errno($this->koneksi);
+ $this->fieldvalue[] = $sql;
return 0;
}
}
- public function select_as($skey,$sval="",$escape=1){
- if(empty($escape)){
- if(is_array($skey)){
- foreach($skey as $k=>$v){
- $this->in_select .= "".$k." '".$v."', ";
- }
- }else{
- $this->in_select .= "".$skey." AS '".$sval."', ";
- }
- }else{
- if(is_array($skey)){
- foreach($skey as $k=>$v){
- $this->in_select .= "`".$k."` AS '".$v."', ";
- }
- }else{
- $this->in_select .= "`".$skey."` AS '".$sval."', ";
- }
-
- }
- return $this;
- }
- public function query($sql,$cache_enabled=0,$flushcache=0,$type="object"){
- //die($sql);
- if($cache_enabled){
- $name = "";
- $names = explode("from",strtolower($sql));
- if(isset($names[1])){
- $name = trim($names[1]);
- $name = str_replace("`","",$name);
- $names = explode(" ",$name);
-
- if(isset($names[0])) $name = $names[0];
- unset($names);
- }
- $cache=md5($sql).".json";
- if(!empty($name)){
- $cache=$name."-".md5($sql).".json";
- }
- //die(SENECACHE.'/'.$cache);
- //var_dump($cache_enabled);
- if(isset($GLOBALS['semeflush'])){
- $flushcache = $GLOBALS['semeflush'];
- }
- if(isset($GLOBALS['semecache'])){
- $cache_enabled = $GLOBALS['semecache'];
- }
- if($flushcache){
- //die("deleted");
- if(file_exists(SENECACHE.'/'.$cache))
- unlink(SENECACHE.'/'.$cache);
- }
- if(file_exists(SENECACHE.'/'.$cache)){
- //die("wololo");
- $fp = fopen(SENECACHE.'/'.$cache, "r");
- $str = fread($fp,filesize(SENECACHE.'/'.$cache));
- fclose($fp);
- $dataz = json_decode($str);
- return $dataz;
- }else{
- $res = $this->__mysqli->query($sql);
- if($res){
- $dataz=array();
- if($type=="array"){
- //die($type);
- while($data=$res->fetch_array()){
- array_push($dataz,$data);
- }
- }elseif($type=="assoc"){
- while($data=$res->fetch_assoc()){
- array_push($dataz,$data);
- }
- }else{
- while($data=$res->fetch_object()){
- $dataz[] = $data;
- }
- }
- $res->free();
- $str = json_encode($dataz);
- //die($str);
- $fp = fopen(SENECACHE.'/'.$cache, "w+");
- fwrite($fp, $str);
- fclose($fp);
- return $dataz;
- }else{
- //$this->debug($sql);
- trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
- return $this->fieldvalue;
- }
- }
- }else{
- //die("else");
- $res = $this->__mysqli->query($sql);
- if($res){
- $dataz=array();
- if($type=="array"){
- //die($type);
- while($data=$res->fetch_array()){
- array_push($dataz,$data);
- }
- }elseif($type=="assoc"){
- while($data=$res->fetch_assoc()){
- array_push($dataz,$data);
- }
- }else{
- while($data=$res->fetch_object()){
- $dataz[] = $data;
- }
- }
- $res->free();
- return $dataz;
- }else{
- //$this->debug($sql);
- trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
- return $this->fieldvalue;
- }
- }
- }
- public function select($sql="",$cache_enabled=0,$flushcache=0,$type="object"){
- //
- $exp1 = 0;
- $exp2 = 0;
- if(!is_array($sql)){
- $exp1 = count(explode("SELECT",$sql));
- $exp2 = count(explode("FROM",$sql));
- }
- if($exp1>1 && $exp2>1){
- return $this->query($sql,$cache_enabled,$flushcache,$type);
- }else if(is_array($sql)){
- foreach($sql as $s){
- if($s!="*"){
- $this->in_select .= "`".$s."`, ";
- }else{
- $this->in_select .= " * , ";
- }
- }
- return $this;
- }else if(!empty($sql)){
- if($sql!="*"){
- $this->in_select .= "`".$sql."`, ";
- }else{
- $this->in_select .= "".$sql.", ";
+ protected function select($sql){
+ $res = mysql_query($sql,$this->koneksi);
+ if($res){
+ $dataz=array();
+ while($data=mysql_fetch_assoc($res)){
+ array_push($dataz,$data);
}
- return $this;
+ return $dataz;
}else{
- $this->in_select .= "*";
- return $this;
+ $this->fieldname[] = 'error';
+ $this->fieldname[] = 'code';
+ $this->fieldname[] = 'sql';
+ $this->fieldvalue[] = mysql_error($this->koneksi);
+ $this->fieldvalue[] = mysql_errno($this->koneksi);
+ $this->fieldvalue[] = $sql;
+ return $this->fieldvalue;
}
-
}
-
public function getStat(){
return array("fieldname"=>$this->fieldname,"fieldvalue"=>$this->fieldvalue);
}
- public function lastId(){
- return $this->__mysqli->insert_id;
- }
- public function esc($var){
- if(is_array($var)){
-
- }else{
- if(strtoupper($var)=='NULL'){
- return 'NULL';
- }else{
- return '"'.$this->__mysqli->real_escape_string($var).'"';
- }
- }
-
- }
- public function __destruct(){
- if(is_resource($this->__mysqli)) $this->__mysqli->close();
- }
- public function getField(){
- return array("field"=>$this->fieldname,"value"=>fieldvalue);
- }
-
- /*
- * Function Where
- * ==========================================================
- * Params1 -> Bisa Array kalau bukan array, parameter 2 wajib
- * array berupa key value pair
- * kalau string berarti key
- * Params2 -> berupa value, default kosong
- * Params3 -> Operan AND, OR, dsb
- * Params4 -> bisa =, <>, like, notlike,
- * like%,%like,%like%
- * bisa juga not like%,%like,%like%
- * -----------------------------------------------------------
- */
- public function where($params,$params2="",$operand="AND",$comp="=",$bracket=0,$bracket2=0){
- //die("params: ".$params);
- //die("params2: ".$params2);
- //die("operand: ".$operand);
- //die("comp: ".$comp);
- $comp = strtolower($comp);
- $c="=";
- $operand = strtoupper($operand);
- if(is_array($params)){
- $comp = $operand;
- $comp = strtolower($comp);
- $operand = $params2;
- //die("comp: ".$comp);
- foreach($params as $k=>$v){
- switch($comp){
- case "like":
- $c= "LIKE";
- $val = $this->esc($val);
- break;
- case 'like%':
- $c= "LIKE";
- $val = ''.$v.'%';
- $val = $this->esc($val);
- break;
- case '%like':
- $c= "LIKE";
- $val = '%'.$v.'';
- $val = $this->esc($val);
- break;
- case 'like%%':
- $c= "LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case '%like%':
- $c= "LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "notlike":
- $c= "NOT LIKE";
- $val = $this->esc($val);
- break;
- case "notlike%%":
- $c= "NOT LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "%notlike%":
- $c= "NOT LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "notlike%":
- $c= "NOT LIKE";
- $val = "".$v.'%';
- $val = $this->esc($val);
- break;
- case "%notlike":
- $c= "NOT LIKE";
- $val = '%'.$v."";
- $val = $this->esc($val);
- break;
- case "!=":
- $c= "<>";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<>":
- $c= "<>";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case ">=":
- $c= ">=";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<=":
- $c= "<=";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case ">":
- $c= ">";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<":
- $c= "<";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- default:
- $c = "=";
- $val = $this->esc($v);
- }
-
- if($bracket){
- $this->in_where .= " ( ";
- }
-
- $kst = explode(".",$k);
- if(count($kst)){
- $kst = explode(".",$k);
- foreach($kst as $ks){
- $this->in_where .= "`".$ks."`.";
- }
- $this->in_where = rtrim($this->in_where,".");
- }else{
- $this->in_where .= "`".$k."`";
- unset($kst);
- }
- $this->in_where .= " ".$c." ".$val." ";
- if($bracket2){
- $this->in_where .= " ) ";
- }
- $this->in_where .= " ".strtoupper($operand)." ";
- }
- unset($c);
- unset($v);
- unset($k);
- unset($val);
- }else if(!empty($params) && strlen($params2)){
- $val = $params2;
- $v = $params2;
-
- if($bracket){
- $this->in_where .= " ( ";
- }
-
- $kst = explode(".",$params);
- if(count($kst)){
- $kst = explode(".",$params);
- foreach($kst as $ks){
- $this->in_where .= "`".$ks."`.";
- }
- $this->in_where = rtrim($this->in_where,".");
- }else{
- $this->in_where .= "`".$params."`";
- }
- unset($kst);
-
-
- switch($comp){
- case "like":
- $c = "LIKE";
- $val = $this->esc($val);
- break;
- case 'like%':
- $c= "LIKE";
- $val = "".$v.'%';
- //die($val);
- $val = $this->esc($val);
- //die($val);
- break;
- case '%like':
- $c= "LIKE";
- $val = '%'.$v."";
- $val = $this->esc($val);
- break;
- case 'like%%':
- $c= "LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "%like%":
- $c= "LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "notlike":
- $c= "NOT LIKE";
- $val = $this->esc($val);
- break;
- case "notlike%%":
- $c= "NOT LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "%notlike%":
- $c= "NOT LIKE";
- $val = '%'.$v.'%';
- $val = $this->esc($val);
- break;
- case "notlike%":
- $c= "NOT LIKE";
- $val = "".$v.'%';
- $val = $this->esc($val);
- break;
- case "%notlike":
- $c= "NOT LIKE";
- $val = '%'.$v."";
- $val = $this->esc($val);
- break;
- case "!=":
- $c= "<>";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<>":
- $c= "<>";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case ">=":
- $c= ">=";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<=":
- $c= "<=";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case ">":
- $c= ">";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- case "<":
- $c= "<";
- $val = "".$v."";
- $val = $this->esc($val);
- break;
- default:
- if(strtoupper($v) == "IS NULL"){
- $v = strtoupper($v);
- $c = "";
- $val = $v;
- }else{
- $c = "=";
- $val = $this->esc($v);
- }
- }
-
- $this->in_where .= " ".$c." ".$val." ";
- if($bracket2){
- $this->in_where .= " ) ";
- }
- $this->in_where .= " ".$operand." ";
- unset($c);
- unset($v);
- unset($k);
- unset($val);
- }
- return $this;
- }
- public function where_as($params,$params2="",$operand="AND",$comp="=",$bracket=0,$bracket2=0){
- $comp = strtolower($comp);
- $c="=";
- $operand = strtoupper($operand);
- if(is_array($params)){
- $comp = $operand;
- $comp = strtolower($comp);
- $operand = $params2;
- //die("comp: ".$comp);
- foreach($params as $k=>$v){
- switch($comp){
- case "like":
- $c= "LIKE";
- $val = ($val);
- break;
- case 'like%':
- $c= "LIKE";
- $val = '\''.$v.'%\'';
- $val = ($val);
- break;
- case '%like':
- $c= "LIKE";
- $val = '\'%'.$v.'\'';
- $val = ($val);
- break;
- case 'like%%':
- $c= "LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case '%like%':
- $c= "LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "notlike":
- $c= "NOT LIKE";
- $val = ($val);
- break;
- case "notlike%%":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "%notlike%":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "notlike%":
- $c= "NOT LIKE";
- $val = '\''.$v.'%\'';
- $val = ($val);
- break;
- case "%notlike":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'\'';
- $val = ($val);
- break;
- case "!=":
- $c= "<>";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<>":
- $c= "<>";
- $val = "".$v."";
- $val = ($val);
- break;
- case ">=":
- $c= ">=";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<=":
- $c= "<=";
- $val = "".$v."";
- $val = ($val);
- break;
- case ">":
- $c= ">";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<":
- $c= "<";
- $val = "".$v."";
- $val = ($val);
- break;
- default:
- $c = "=";
- $val = ($v);
- }
-
- if($bracket){
- $this->in_where .= " ( ";
- }
- $this->in_where .= "".$k."";
- unset($kst);
-
- $this->in_where .= " ".$c." ".$val."";
- if($bracket2){
- $this->in_where .= " ) ";
- }
- $this->in_where .= " ".strtoupper($operand)." ";
- }
- unset($c);
- unset($v);
- unset($k);
- unset($val);
- }else if(!empty($params) && strlen($params2)){
- $val = $params2;
- $v = $params2;
-
- if($bracket){
- $this->in_where .= " ( ";
- }
-
- $kst = explode(".",$params);
- if(count($kst)){
- $kst = explode(".",$params);
- foreach($kst as $ks){
- $this->in_where .= "".$ks.".";
- }
- $this->in_where = rtrim($this->in_where,".");
- }else{
- $this->in_where .= "".$params."";
- unset($kst);
- }
-
-
- switch($comp){
- case "like":
- $c = "LIKE";
- $val = ($val);
- break;
- case 'like%':
- $c= "LIKE";
- $val = "\'".$v.'%\'';
- $val = ($val);
- break;
- case '%like':
- $c= "LIKE";
- $val = '\'%'.$v.'\'';
- $val = ($val);
- break;
- case 'like%%':
- $c= "LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "%like%":
- $c= "LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "notlike":
- $c= "NOT LIKE";
- $val = ($val);
- break;
- case "notlike%%":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "%notlike%":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'%\'';
- $val = ($val);
- break;
- case "notlike%":
- $c= "NOT LIKE";
- $val = '\''.$v.'%\'';
- $val = ($val);
- break;
- case "%notlike":
- $c= "NOT LIKE";
- $val = '\'%'.$v.'\'';
- $val = ($val);
- break;
- case "!=":
- $c= "<>";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<>":
- $c= "<>";
- $val = "".$v."";
- $val = ($val);
- break;
- case ">":
- $c= ">";
- $val = "".$v."";
- $val = ($val);
- break;
- case ">=":
- $c= ">=";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<":
- $c= "<";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<=":
- $c= "<=";
- $val = "".$v."";
- $val = ($val);
- break;
- case ">":
- $c= ">";
- $val = "".$v."";
- $val = ($val);
- break;
- case "<":
- $c= "<";
- $val = "".$v."";
- $val = ($val);
- break;
- default:
- if(strtoupper($v) == "IS NULL"){
- $v = strtoupper($v);
- $c = "";
- $val = $v;
- }else{
- $c = "=";
- $val = $v;
- }
- }
- $this->in_where .= " ".$c." ".$val." ";
- if($bracket2){
- $this->in_where .= " ) ";
- }
- $this->in_where .= " ".$operand." ";
-
- $this->in_where = trim($this->in_where,"=");
-
- unset($c);
- unset($v);
- unset($k);
- unset($val);
- }
- return $this;
- }
- public function order_by($params,$params2="ASC"){
- if(is_array($params)){
- foreach($params as $k=>$v){
- $this->in_order .= $k." ".strtoupper($v).", ";
- }
-
- }else if(!empty($params) && !empty($params2)){
- $this->in_order .= $params." ".strtoupper($params2).", ";
- }
- return $this;
- }
- public function from($table,$as=""){
- if(empty($table)){
- trigger_error("tabel name required");
- die();
- }
- if(!empty($as)){
- $as = strtolower($as);
- if(isset($this->as_from[$as])){
- if($this->as_from[$as] != $table){
- trigger_error('Table alias "'.$as.'" for "'.$this->as_from[$as].'" has been used, please change!');
- foreach($this->as_from as $k=>$v){
- trigger_error($k.': '.$v);
- }
- die();
- }
-
+ public function prettyName($name){
+ $name=strtolower(trim($name));
+ $names=explode("_", $name);
+ $name='';
+ foreach($names as $n){
+ $name=$name.''.ucfirst($n).' ';
+ }
+ return $name;
+ }
+ public function formContent($name,$type="text",$value="",$req=0){
+ echo '';
+ if($type=="file"){
+ echo '
';
+ if($value==""){
+ echo '';
}else{
- $this->as_from[$as] = $table;
- }
- }
- $this->table = $table;
- return $this;
- }
- public function setTableAlias($as){
- if(empty($as)) trigger_error("table alias required");
- $this->as_from[$as] = $this->table;
- return $this;
- }
- public function cache_save($cache_save=1){
- $this->cache_save = $cache_save;
- return $this;
- }
- public function cache_flush($cache_flush=1){
- $this->cache_flush = $cache_flush;
- return $this;
- }
- public function pagesize($pagesize){
- $this->tis_limit++;
- $this->is_limit=0;
- $this->pagesize = (int) $pagesize;
- return $this;
- }
- public function nolimit(){
- $this->tis_limit = 0;
- $this->is_limit = 0;
- $this->pagesize = 0;
- $this->limit_a = 0;
- $this->limit_b = 0;
- return $this;
- }
- public function limit($a,$b=""){
- $this->is_limit=1;
- if(empty($b) && !empty($a)){
- $b = $a;
- $a = 0;
- }
- $this->limit_a=$a;
- $this->limit_b=$b;
- return $this;
- }
- public function page($page,$page_size=""){
- if(!empty($page_size) && empty($page)){
- $this->is_limit=1;
- $this->limit_a=0;
- $this->limit_b=$page_size;
- }else if(empty($page_size) && !empty($page)){
- $this->is_limit=1;
- $this->limit_a=0;
- $this->limit_b=$page;
- }else if(!empty($page_size) && !empty($page)){
- $this->is_limit = 1;
- $this->limit_a = ($page * $page_size) - $page_size;
- if($page == 1) $this->limit_a = ($page * $page_size) - $page_size;
- $this->limit_b = $page_size;
- }
- return $this;
- }
- public function limitpage($page,$pagesize=10){
- $this->is_limit = 0;
- $this->page = $page;
- $this->pagesize = $pagesize;
- return $this;
- }
- public function get($tipe="object",$is_debug=""){
- $this->in_select = rtrim($this->in_select,", ");
- if(empty($this->in_select)) $this->in_select = "*";
- $sql = "SELECT ".$this->in_select." FROM `".$this->table."`";
-
- if (count($this->join) > 0) {
- $table_alias = array_search($this->table, $this->as_from);
- if ($table_alias !== 0) {
- $sql .= ' '.$table_alias.' ';
- foreach ($this->join as $j) {
- $sql .= strtoupper($j->method).' JOIN '.$j->table.' ON ';
- foreach($j->on as $o){
- $sql .= '('.$o.') ';
- }
- }
- } else {
- trigger_error('Please use alias for main table first, you can set alias using $this->db->setTableAlias("YOURALIAS") OR $this->db->from("tabelname","tablealias");');
- die();
- }
- } else {
- $table_alias = array_search($this->table, $this->as_from);
- if ($table_alias !== 0) {
- $sql .= ' '.$table_alias.' ';
- }
- }
-
- if(!empty($this->in_where)){
- $this->in_where = rtrim($this->in_where,"AND ");
- $this->in_where = rtrim($this->in_where,"OR ");
- $sql .= " WHERE ".$this->in_where;
- }
-
- if(!empty($this->in_group)){
- $this->in_group = rtrim($this->in_group,", ");
- $sql .= $this->in_group;
- }
-
- if(!empty($this->in_order)){
- $this->in_order = rtrim($this->in_order,", ");
- $sql .= " ORDER BY ".$this->in_order;
- }
-
- if(empty($all)){
- if($this->is_limit){
- $a = $this->limit_a;
- $b = $this->limit_b;
- $sql .= " LIMIT ".$a.", ".$b;
- }else{
- $b = $this->pagesize;
- if((empty($page) || $page=="1" || $page==1)){
- if(!empty($b)) $sql .= " LIMIT ".$b;
- }else{
- $a = $this->page;
- $sql .= " LIMIT ".$a.",".$b;
- }
- }
-
- }
-
- $cache_save = 0;
- if(!empty($this->cache_save)){
- $cache_save = $this->cache_save;
- }
-
- $cache_flush = 0;
- if(!empty($this->cache_flush)){
- $cache_flush = $this->cache_flush;
- }
- if($is_debug) die($sql);
- $res = $this->query($sql,$cache_save,$cache_flush,$tipe);
- $this->flushQuery();
- return $res;
- }
-
- public function get_first($tipe="object",$is_debug=""){
- $this->in_select = rtrim($this->in_select,", ");
- if(empty($this->in_select)) $this->in_select = "*";
- $sql = "SELECT ".$this->in_select." FROM `".$this->table."`";
-
- if (count($this->join) > 0) {
- $table_alias = array_search($this->table, $this->as_from);
- if ($table_alias !== 0) {
- $sql .= ' '.$table_alias.' ';
- foreach ($this->join as $j) {
- $sql .= strtoupper($j->method).' JOIN '.$j->table.' ON ';
- foreach($j->on as $o){
- $sql .= '('.$o.') ';
- }
- }
- } else {
- trigger_error('Please use alias for main table first, you can set alias using $this->db->setTableAlias("YOURALIAS") OR $this->db->from("tabelname","tablealias");');
- die();
- }
- } else {
- $table_alias = array_search($this->table, $this->as_from);
- if ($table_alias !== 0) {
- $sql .= ' '.$table_alias.' ';
- }
- }
-
- if(!empty($this->in_where)){
- $this->in_where = rtrim($this->in_where,"AND ");
- $sql .= " WHERE ".$this->in_where;
- }
- $sql = rtrim($sql,' ');
- $sql = rtrim($sql,' AND');
- $sql = rtrim($sql,' OR');
- $sql = $sql.' ';
-
-
- if(!empty($this->in_group)){
- $this->in_group = rtrim($this->in_group,", ");
- $sql .= $this->in_group;
- }
-
- if(!empty($this->in_order)){
- $this->in_order = rtrim($this->in_order,", ");
- $sql .= " ORDER BY ".$this->in_order;
- }
-
- $b = 1;
- $a = 0;
- $sql .= " LIMIT ".$a.", ".$b;
-
- $cache_save = 0;
- if(!empty($this->cache_save)){
- $cache_save = $this->cache_save;
- }
-
- $cache_flush = 0;
- if(!empty($this->cache_flush)){
- $cache_flush = $this->cache_flush;
- }
- if($is_debug) die($sql);
- $res = $this->query($sql,$cache_save,$cache_flush,$tipe);
- $this->flushQuery();
- if(isset($res[0])) return $res[0];
- return new stdClass();
- }
- public function flushQuery(){
- $this->in_select = "";
- $this->in_where = "";
- $this->in_order = "";
- $this->in_group = "";
- $this->pagesize = 0;
- $this->page = 0;
- $this->is_limit = 0;
- $this->limit_a = 0;
- $this->limit_b = 0;
- $this->tis_limit = 0;
- $this->as_from = array();
- $this->join = array();
- $this->in_join = 0;
- return $this;
- }
- public function query_multi($sql){
- $this->__mysqli->multi_query($sql);
- if($this->__mysqli->errno){
- trigger_error($this->__mysqli->error);
- }
- }
- public function insert_batch($table,$datas=array(),$is_debug=0){
- $this->insert_multi($table,$datas,$is_debug);
- }
- public function insert_multi($table,$datas=array(),$is_debug=0){
- //$multi_array=0;
-
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
- $sql = 'INSERT INTO '.$table.' (';
-
- foreach($datas as $data){
- if(!is_array($data)){
- trigger_error('Must be array!');
- die();
- }
- foreach($data as $key=>$val){
- $sql .="".$key.",";
- }
- break;
- }
- $sql = rtrim($sql,",");
- $sql .= ") VALUES(";
-
- foreach($datas as $ds){
- foreach($ds as $key=>$val){
- if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
- $sql .="".strtoupper($val).",";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- $sql = rtrim($sql,",");
- $sql .= "),(";
- }
- $sql = rtrim($sql,",(");
- $sql .= ";";
-
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
- public function insert_ignore_multi($table,$datas=array(),$is_debug=0){
- //$multi_array=0;
-
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
- $sql = 'INSERT IGNORE INTO `'.$table.'`'.'(';
-
- foreach($datas as $data){
- if(!is_array($data)){
- trigger_error('Must be array!');
- die();
- }
- foreach($data as $key=>$val){
- $sql .="`".$key."`,";
- }
- break;
- }
- $sql = rtrim($sql,",");
- $sql .= ") VALUES(";
-
- foreach($datas as $ds){
- foreach($ds as $key=>$val){
- if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
- $sql .="".strtoupper($val).",";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- $sql = rtrim($sql,",");
- $sql .= "),(";
- }
- $sql = rtrim($sql,",(");
- $sql .= ";";
-
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
- public function insert($table,$datas=array(),$multi_array=0,$is_debug=0){
- //$multi_array=0;
- $this->last_id = 0;
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
- if($multi_array){
- $this->insert_multi($table,$datas,$is_debug);
+ echo '';
+ }
+ echo '';
+ }elseif($type=="datetime"){
+ echo '';
+ echo ''.$this->prettyName($name).'';
+ echo '';
+ ?>
+
+ ';
+ echo ''.$this->prettyName($name).'';
+ echo '';
+ ?>
+
+ ';
+ echo ''.$this->prettyName($name).'';
+ echo '';
+ ?>
+
+ ';
+ echo ''.$this->prettyName($name).'';
+ echo '';
+ }elseif($type=="switch"){
+ echo '';
+ echo ''.$this->prettyName($name).'';
+ echo '';
+ }elseif($type=="switchAlt"){
+ echo '';
+ echo ''.$this->prettyName($name).'';
+ echo '';
}else{
- $sql = 'INSERT INTO `'.$table.'`'.'(';
-
- foreach($datas as $key=>$val){
- $sql .="`".$key."`,";
- }
- $sql = rtrim($sql,",");
- $sql .= ") VALUES(";
-
- foreach($datas as $key=>$val){
- if(strtoupper($val) == 'NOW()'){
- $sql .="".strtoupper($val).",";
- }else if(strtoupper($val)=='NULL'){
- $sql .="NULL,";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- $sql = rtrim($sql,",");
- $sql .= ");";
-
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->last_id = $this->lastId();
- //var_dump($res);
- //var_dump($this->last_id);
- //die();
- $this->flushQuery();
- return $res;
- }
- }
- public function update($table,$datas=array(),$debug=0){
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
-
- $sql = "UPDATE `".$table."` SET ";
-
- foreach($datas as $key=>$val){
- if(strtoupper($val) == 'NOW()' || strtoupper($val) == 'NULL'){
- $sql .="`".$key."` = ".$val.",";
- }else{
- $sql .="`".$key."` = ".$this->esc($val).",";
- }
- }
-
- $sql = rtrim($sql,",");
-
- if(!empty($this->in_where)){
- $this->in_where = rtrim($this->in_where,"AND ");
- $this->in_where = rtrim($this->in_where,"OR ");
- $sql .= " WHERE ".$this->in_where;
- }
-
- if(!empty($this->pagesize) && ($this->tis_limit>0)){
- $b = $this->pagesize;
- $sql .= " LIMIT ".$b;
- }
- if($debug) die($sql);
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
- public function delete($table,$is_debug=0){
- if(empty($table)){
- trigger_error("Missing table name while deleting");
- die();
- }
-
- $sql = "DELETE FROM `".$table."`";
-
- if(!empty($this->in_where)){
- $this->in_where = rtrim($this->in_where,"AND ");
- $this->in_where = rtrim($this->in_where,"OR ");
- $sql .= " WHERE ".$this->in_where;
- }
- if(!empty($this->pagesize) && ($this->tis_limit>0)){
- $b = $this->pagesize;
- $sql .= " LIMIT ".$b;
- }
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
-
- public function join($table, $table_as, $table_key, $reff_as, $reff_key, $method='left')
- {
- $join = new stdClass();
- $join->method = strtoupper(trim($method));
- $join->table = '`'.$table.'` '.$table_as;
- $join->on = array($table_as.'.`'.$table_key.'` = '.$reff_as.'.`'.$reff_key.'`');
- $this->join[] = $join;
- $this->in_join = $this->in_join+1;
- $this->as_from[$table_as] = $table;
- return $this;
- }
- public function join_as($tbl, $reff, $method='left')
- {
- $join = new stdClass();
- $join->method = strtoupper(trim($method));
- $join->table = $tbl;
- $join->on = array($reff);
- $this->join[] = $join;
- $this->in_join = $this->in_join+1;
- return $this;
- }
-
- public function between($key,$val1,$val2,$is_not=0){
- $this->in_where .= "(";
- $this->in_where .= " ".$key."";
- if($is_not) $this->in_where .= " NOT ";
- $this->in_where .= " BETWEEN ".$val1." AND ".$val2."";
- $this->in_where .= ") AND ";
- return $this;
- }
- public function group_by($params){
- //die($params);
- if(is_array($params)){
- foreach($params as $k=>$v){
- $this->in_group .= " GROUP BY ".$v.", ";
- }
- } else {
- $this->in_group .= " GROUP BY ".$params.", ";
- }
- return $this;
- }
-
- public function replace($table,$datas=array(),$multi_array=0,$is_debug=0){
- //$multi_array=0;
- $this->last_id = 0;
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
- if($multi_array){
- $this->replace_multi($table,$datas,$is_debug);
- }else{
- $sql = 'REPLACE INTO `'.$table.'`'.'(';
-
- foreach($datas as $key=>$val){
- $sql .="`".$key."`,";
- }
- $sql = rtrim($sql,",");
- $sql .= ") VALUES(";
-
- foreach($datas as $key=>$val){
- if(strtoupper($val)=='NOW()'){
- $sql .="".$val.",";
- }else if(strtoupper($val)=='NULL'){
- $sql .="NULL,";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- $sql = rtrim($sql,",");
- $sql .= ");";
-
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->last_id = $this->lastId();
- $this->flushQuery();
- return $res;
- }
- }
- public function replace_multi($table,$datas=array(),$is_debug=0){
- //$multi_array=0;
-
- if(!is_array($datas)){
- trigger_error('Must be array!');
- die();
- }
- $sql = 'REPLACE INTO `'.$table.'`'.' (';
-
- foreach($datas as $data){
- if(!is_array($data)){
- trigger_error('Must be array!');
- die();
- }
- foreach($data as $key=>$val){
- if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
- $sql .="".strtoupper($val).",";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- break;
- }
- $sql = rtrim($sql,",");
- $sql .= ") VALUES(";
-
- foreach($datas as $ds){
- foreach($ds as $key=>$val){
- if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
- $sql .="".strtoupper($val).",";
- }else{
- $sql .="".$this->esc($val).",";
- }
- }
- $sql = rtrim($sql,",");
- $sql .= "),(";
- }
- $sql = rtrim($sql,",(");
- $sql .= ";";
-
- if($is_debug) die($sql);
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
- public function where_in($tbl_key,$values,$is_not="0",$after="AND"){
- $not = '';
-
- if($is_not == '1' || $is_not == 1) $not = 'NOT';
-
- $this->in_where .= ' '.$tbl_key.' '.$not.' IN (';
- foreach($values as $v){
- $this->in_where .= $this->esc($v).", ";
- }
- $this->in_where = rtrim($this->in_where,", ");
- $this->in_where .= ') '.$after.' ';
-
- return $this;
- }
- public function getCharSet(){
- $res = $this->__mysqli->character_set_name();
- if(!$res){
- trigger_error('Cant get charset '.$char_set.' to database.');
- }
- return $res;
- }
- public function setCharSet($char_set){
- $res = $this->__mysqli->set_charset($char_set);
- if(!$res){
- trigger_error('Cant change charset from '.$this->__mysqli->character_set_name().' to '.$char_set.' to database.');
+ echo '';
+ echo ''.$this->prettyName($name).'';
+ echo '';
}
- return 1;
+ echo ' ';
}
-}
+}
\ No newline at end of file
diff --git a/kero/sine/SENE_MySQLi_Engine.php b/kero/sine/SENE_MySQLi_Engine.php
index 038c14a..77261e7 100644
--- a/kero/sine/SENE_MySQLi_Engine.php
+++ b/kero/sine/SENE_MySQLi_Engine.php
@@ -1,7 +1,7 @@
=2){
+ $port = $db['port'];
+ }
+ }
mysqli_report(MYSQLI_REPORT_STRICT);
- //$this->koneksi=mysqli_connect($db['host'],$db['user'],$db['pass'],$db['name']);
$this->__mysqli = new mysqli();
try {
@@ -41,7 +46,26 @@ function __construct(){
if ($this->__mysqli->connect_errno) {
die('Couldn\'t connect to database. Please, check your database configuration on '.SENECFG.'/database.php');
}
- $this->__mysqli->set_charset('utf8');
+ if(isset($db['charset'])){
+ if(strlen($db['charset'])<=2){
+ $db['charset'] = 'utf8';
+ }
+ }else{
+ $db['charset'] = 'utf8';
+ }
+ $this->__mysqli->set_charset($db['charset']);
+
+ if(isset($db['dbcollate'])){
+ if(strlen($db['dbcollate'])<=2){
+ $db['dbcollate'] = '';
+ }
+ }else{
+ $db['dbcollate'] = '';
+ }
+ if(strlen($db['charset'])>2 && strlen($db['dbcollate'])>3){
+ $this->__mysqli->query('SET NAMES '.$db['charset'].' COLLATE '.$db['dbcollate'].'');
+ }
+
self::$__instance = $this;
@@ -59,6 +83,13 @@ function __construct(){
$in_join=0;
$this->as_from = array();
$this->join = array();
+ $this->union = new stdClass();
+ $this->union->select = array();
+ $this->union->table = array();
+ $this->union->from_as = 'u1';
+ $this->union->group_by = '';
+ $this->union->order_by = array();
+ $this->union->limit = '';
}
public static function getInstance(){
return self::$_instance;
@@ -181,7 +212,7 @@ public function query($sql,$cache_enabled=0,$flushcache=0,$type="object"){
return $dataz;
}else{
//$this->debug($sql);
- //trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
+ trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
return $this->fieldvalue;
}
}
@@ -208,7 +239,7 @@ public function query($sql,$cache_enabled=0,$flushcache=0,$type="object"){
return $dataz;
}else{
//$this->debug($sql);
- //trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
+ trigger_error('Error: '.$this->__mysqli->error.' -- SQL: '.$sql);
return $this->fieldvalue;
}
}
@@ -256,8 +287,8 @@ public function esc($var){
if(is_array($var)){
}else{
- if(strtolower($var)=='null'){
- return 'null';
+ if(strtoupper($var)=='NULL'){
+ return 'NULL';
}else{
return '"'.$this->__mysqli->real_escape_string($var).'"';
}
@@ -510,7 +541,7 @@ public function where($params,$params2="",$operand="AND",$comp="=",$bracket=0,$b
$val = $this->esc($val);
break;
default:
- if(strtolower($v) == "is null"){
+ if(strtoupper($v) == "IS NULL"){
$v = strtoupper($v);
$c = "";
$val = $v;
@@ -753,7 +784,7 @@ public function where_as($params,$params2="",$operand="AND",$comp="=",$bracket=0
$val = ($val);
break;
default:
- if(strtolower($v) == "is null"){
+ if(strtoupper($v) == "IS NULL"){
$v = strtoupper($v);
$c = "";
$val = $v;
@@ -1059,7 +1090,7 @@ public function insert_multi($table,$datas=array(),$is_debug=0){
foreach($datas as $ds){
foreach($ds as $key=>$val){
- if(strtolower($val)=='now()' || strtolower($val)=='null'){
+ if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
$sql .="".strtoupper($val).",";
}else{
$sql .="".$this->esc($val).",";
@@ -1100,7 +1131,7 @@ public function insert_ignore_multi($table,$datas=array(),$is_debug=0){
foreach($datas as $ds){
foreach($ds as $key=>$val){
- if(strtolower($val)=='now()' || strtolower($val)=='null'){
+ if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
$sql .="".strtoupper($val).",";
}else{
$sql .="".$this->esc($val).",";
@@ -1136,9 +1167,9 @@ public function insert($table,$datas=array(),$multi_array=0,$is_debug=0){
$sql .= ") VALUES(";
foreach($datas as $key=>$val){
- if(strtolower($val) == 'now()'){
+ if(strtoupper($val) == 'NOW()'){
$sql .="".strtoupper($val).",";
- }else if(strtolower($val)=='null'){
+ }else if(strtoupper($val)=='NULL'){
$sql .="NULL,";
}else{
$sql .="".$this->esc($val).",";
@@ -1157,13 +1188,6 @@ public function insert($table,$datas=array(),$multi_array=0,$is_debug=0){
return $res;
}
}
- /**
- * Update current table with key value array
- * key and value are automatically escaped
- * @param string $table table name
- * @param array $datas key value pair
- * @return object this object
- */
public function update($table,$datas=array(),$debug=0){
if(!is_array($datas)){
trigger_error('Must be array!');
@@ -1173,7 +1197,7 @@ public function update($table,$datas=array(),$debug=0){
$sql = "UPDATE `".$table."` SET ";
foreach($datas as $key=>$val){
- if(strtoupper($val) == 'now()' || strtoupper($val) == 'null'){
+ if(strtoupper($val) == 'NOW()' || strtoupper($val) == 'NULL'){
$sql .="`".$key."` = ".$val.",";
}else{
$sql .="`".$key."` = ".$this->esc($val).",";
@@ -1197,51 +1221,6 @@ public function update($table,$datas=array(),$debug=0){
$this->flushQuery();
return $res;
}
- /**
- * Same as update, but with no chararcter escape. Useful for update from column to column in single table.
- * *$this->db->esc() may required
- * @param string $table table name
- * @param array $datas key value pair
- * @return object this object
- */
- public function update_as($table,$datas=array(),$is_debug=0){
- if(!is_array($datas)){
- trigger_error("Must be array!");
- die();
- }
-
- $sql = "UPDATE `".$table."` SET ";
-
- foreach($datas as $key=>$val){
- if($val=="now()" || $val=="NOW()" || $val=="NULL" || $val=="null"){
- $sql .="".$key."=".$val.",";
- }else{
- $sql .="".$key."=".($val).",";
- }
- }
-
- $sql = rtrim($sql,",");
-
- if(!empty($this->in_where)){
- $this->in_where = rtrim($this->in_where,"AND ");
- $this->in_where = rtrim($this->in_where,"OR ");
- $sql .= " WHERE ".$this->in_where;
- }
-
- if(!empty($this->pagesize) && ($this->tis_limit>0)){
- $b = $this->pagesize;
- $sql .= " LIMIT ".$b;
- }
-
- $this->query_last = $sql;
- if($is_debug){
- http_response_code(500);
- die($sql);
- }
- $res = $this->exec($sql);
- $this->flushQuery();
- return $res;
- }
public function delete($table,$is_debug=0){
if(empty($table)){
trigger_error("Missing table name while deleting");
@@ -1326,9 +1305,9 @@ public function replace($table,$datas=array(),$multi_array=0,$is_debug=0){
$sql .= ") VALUES(";
foreach($datas as $key=>$val){
- if($val=='now()' || $val=='now()'){
+ if(strtoupper($val)=='NOW()'){
$sql .="".$val.",";
- }else if(strtolower($val)=='null'){
+ }else if(strtoupper($val)=='NULL'){
$sql .="NULL,";
}else{
$sql .="".$this->esc($val).",";
@@ -1359,7 +1338,7 @@ public function replace_multi($table,$datas=array(),$is_debug=0){
die();
}
foreach($data as $key=>$val){
- if(strtolower($val)=='now()' || strtolower($val)=='null'){
+ if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
$sql .="".strtoupper($val).",";
}else{
$sql .="".$this->esc($val).",";
@@ -1372,7 +1351,7 @@ public function replace_multi($table,$datas=array(),$is_debug=0){
foreach($datas as $ds){
foreach($ds as $key=>$val){
- if(strtolower($val)=='now()' || strtolower($val)=='null'){
+ if(strtoupper($val)=='NOW()' || strtoupper($val)=='NULL'){
$sql .="".strtoupper($val).",";
}else{
$sql .="".$this->esc($val).",";
@@ -1410,11 +1389,245 @@ public function getCharSet(){
}
return $res;
}
- public function setCharSet($char_set){
+ public function setCharSet($char_set,$dbcollate=''){
$res = $this->__mysqli->set_charset($char_set);
if(!$res){
trigger_error('Cant change charset from '.$this->__mysqli->character_set_name().' to '.$char_set.' to database.');
}
+ if(strlen($dbcollate)>3){
+ $this->__mysqli->query('SET NAMES '.$char_set.' COLLATE '.$dbcollate.'');
+ }
return 1;
}
+
+ /**
+ * Created Union Query table from query builder (last query)
+ * @return boolean $flush 0 not flush, 1 flush
+ * @return string Query
+ */
+ public function union_create($flush=1){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->table)) $this->union->table = array();
+ if(!is_array($this->union->table)) $this->union->table = array();
+
+ $this->in_select = rtrim($this->in_select,", ");
+ if(empty($this->in_select)) $this->in_select = "*";
+ $sql = "SELECT ".$this->in_select." FROM `".$this->table."`";
+
+ if (count($this->join) > 0) {
+ $table_alias = array_search($this->table, $this->as_from);
+ if ($table_alias !== 0) {
+ $sql .= ' '.$table_alias.' ';
+ foreach ($this->join as $j) {
+ $sql .= strtoupper($j->method).' JOIN '.$j->table.' ON ';
+ foreach($j->on as $o){
+ $sql .= '('.$o.') ';
+ }
+ }
+ } else {
+ trigger_error('Please use alias for main table first, you can set alias using $this->db->setTableAlias("YOURALIAS") OR $this->db->from("tabelname","tablealias");');
+ die();
+ }
+ } else {
+ $table_alias = array_search($this->table, $this->as_from);
+ if ($table_alias !== 0) {
+ $sql .= ' '.$table_alias.' ';
+ }
+ }
+
+ if(!empty($this->in_where)){
+ $this->in_where = rtrim($this->in_where,"AND ");
+ $this->in_where = rtrim($this->in_where,"OR ");
+ $sql .= " WHERE ".$this->in_where;
+ }
+ if(!empty($flush)) $this->flushQuery();
+ $this->union->table[] = $sql;
+ return $this;
+ }
+
+ /**
+ * Add select column for union method
+ * @param string $k Column name
+ * @param string $a Column Alias string
+ * @return object this object
+ */
+ public function union_select($k,$a=''){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->select)) $this->union->select = array();
+ if(!is_array($this->union->select)) $this->union->select = array();
+ if(strlen($a)==0){
+ $a = $k;
+ }
+ $this->union->select[$a] = $k;
+ return $this;
+ }
+
+ /**
+ * Set alias table for union method
+ * @param string $a Alias string
+ * @return object this object
+ */
+ public function union_alias($a){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->from_as)) $this->union->from_as = '';
+ if(!is_string($this->union->from_as)) $this->union->from_as = '';
+ if(strlen($a)==0){
+ trigger_error('Empty union_alias parameter');
+ die();
+ }
+ $this->union->from_as = $a;
+ return $this;
+ }
+
+ /**
+ * Set group by criteria for union method
+ * @param string $g Group by string
+ * @return object this object
+ */
+ public function union_group_by($g){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->group_by)) $this->union->group_by = '';
+ if(!is_string($this->union->group_by)) $this->union->group_by = '';
+ if(strlen($g)==0){
+ trigger_error('Empty union_grup_by parameter');
+ die();
+ }
+ $this->union->group_by = $g;
+ return $this;
+ }
+
+ /**
+ * Add order by criteria for union method
+ * @param string $c sort by column name
+ * @param string $d sort direction
+ * @return object this object
+ */
+ public function union_order_by($c,$d){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->order_by)) $this->union->order_by = array();
+ if(!is_array($this->union->order_by)) $this->union->order_by = array();
+ if(strlen($c)==0){
+ trigger_error('Empty union_grup_by parameter');
+ die();
+ }
+ $d = strtoupper($d);
+ if(strlen($d)==0){
+ $d = 'ASC';
+ }
+ $this->union->order_by[] = $c.' '.$d;
+ return $this;
+ }
+
+ /**
+ * Add limit query result for union
+ * @param string $a sort by column name
+ * @param string $b sort direction
+ * @return object this object
+ */
+ public function union_limit($a='',$b=''){
+ if(!isset($this->union)) $this->union = new stdClass();
+ if(!isset($this->union->order_by)) $this->union->order_by = array();
+ if(!is_array($this->union->order_by)) $this->union->order_by = array();
+
+ $a = (int) $a;
+ $b = (int) $b;
+ if($a<=0) $a = '';
+ if($b<=0) $b = '';
+ if(strlen($a) && strlen($b)){
+ $this->union->limit = $a.', '.$b;
+ }elseif(strlen($a) && strlen($b)==0){
+ $this->union->limit = $a;
+ }elseif(strlen($a)==0 && strlen($b)){
+ $this->union->limit = $b;
+ }else{
+ $this->union->limit = '';
+ }
+
+ return $this;
+ }
+
+ /**
+ * Get result Executed union query
+ * @return object this object
+ */
+ public function union_get($is_debug=0){
+ if(!isset($this->union->select)){
+ trigger_error('Missing union.select object on union_get');
+ die();
+ }
+ if(!isset($this->union->from_as)){
+ trigger_error('Missing union.from_as object on union_get');
+ die();
+ }
+ if(!isset($this->union->table)){
+ trigger_error('Missing union.table object on union_get');
+ die();
+ }
+ if(!is_array($this->union->table)){
+ trigger_error('Invalid type union.table object, is not an array');
+ die();
+ }
+ if(count($this->union->table)==0){
+ trigger_error('Empty union table');
+ die();
+ }
+ if(!is_string($this->union->group_by)){
+ trigger_error('Invalid type union.group_by object, is not a string');
+ die();
+ }
+ if(!is_array($this->union->order_by)){
+ trigger_error('Invalid type union.order_by object, is not an array');
+ die();
+ }
+ $sql = 'SELECT ';
+ if(count($this->union->select)){
+ foreach($this->union->select as $k=>$v){
+ if(!is_numeric($k) && $k != $v){
+ $sql .= ' '.$v.' AS '.$k.' ';
+ }else{
+ $sql .= ' '.$v.' ';
+ }
+ }
+ }else{
+ $sql .= ' * ';
+ }
+ $sql .= ' FROM ( ';
+ foreach($this->union->table as $k=>$v){
+ $sql .= $v.' UNION ';
+ }
+ $sql = chop($sql, ' UNION ');
+ $sql .= ' ) AS '.$this->union->from_as.' ';
+ if(strlen($this->union->group_by)){
+ $sql .= ' GROUP BY '.$this->union->group_by;
+ }
+ if(count($this->union->order_by)){
+ $sql .= ' ORDER BY ';
+ foreach($this->union->order_by as $k=>$v){
+ $sql .= ''.$v.', ';
+ }
+ $sql = rtrim($sql,', ');
+ }
+ if(strlen($this->union->limit)){
+ $sql .= ' LIMIT '.$this->union->limit;
+ }
+ if($is_debug){
+ die($sql);
+ }
+ return $this->query($sql);
+ }
+
+ /**
+ * Reset union object to its default value
+ * @return object this object
+ */
+ public function union_flush(){
+ $this->union = new stdClass();
+ $this->union->select = array();
+ $this->union->from_as = 'u1';
+ $this->union->table = array();
+ $this->union->group_by = '';
+ $this->union->order_by = array();
+ $this->union->limit = '';
+ return $this;
+ }
}
diff --git a/readme.md b/readme.md
index 604d93e..f558232 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,5 @@
-# Seme Framework v3.1.4
-[![Build Status](https://travis-ci.org/drosanda/seme-framework-v3.svg?branch=3.1.0)](https://travis-ci.org/drosanda/seme-framework-v3) [![Coverage Status](https://coveralls.io/repos/github/drosanda/seme-framework/badge.svg?branch=3.1.0)](https://coveralls.io/github/drosanda/seme-framework?branch=3.1.0) [![Website seme.framwork.web.id](https://img.shields.io/website-up-down-green-red/http/seme.framework.web.id)](https://seme.framework.web.id/)
+# Seme Framework v3.1.5
+[![Build Status](https://travis-ci.org/drosanda/seme-framework-v3.svg?branch=3.1.5)](https://travis-ci.org/drosanda/seme-framework-v3) [![Coverage Status](https://coveralls.io/repos/github/drosanda/seme-framework/badge.svg?branch=3.1.5)](https://coveralls.io/github/drosanda/seme-framework?branch=3.1.5) [![Website seme.framwork.web.id](https://img.shields.io/website-up-down-green-red/http/seme.framework.web.id)](https://seme.framework.web.id/)
Seme Framework PHP MVC Framework for creating small and medium app that needed for fast delivery. At first version of Seme Framework used for building API (Middle Ware) for another Application such as android, iOS, etc. And now as increasing of requirement, Seme Framework has expand the limit for creating Small and Medium App.
@@ -15,6 +15,11 @@ This framework suitable for Programmer that only know about Manual way of code.
- Admin Friendly. Seme Framework has re-routing feature for admin page, without refactoring the MVC.
- Theme Engine. Seme Framework has feature who can PUSH the content inside the layout view. Also support theming engine, if you want change the Style, you just clone the original one and modified safely.
+## Version 3.1.5
+ This is latest version of 3.1 branch. Here is the new feature:
+ - add SENE_MySQLi_Engine::update_as method
+ - Fix SENEROOT base directory defining method for docker support
+
## Version 3.1.4
This is latest version of 3.1 branch. Here is the new feature:
- add SENE_MySQLi_Engine::update_as method