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 '