mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/trunk@1103 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
60ebbe4e02
commit
94c12ff8bf
6 changed files with 386 additions and 409 deletions
|
|
@ -15,6 +15,20 @@
|
|||
|
||||
class DB {
|
||||
|
||||
/**
|
||||
* @brief 조건문에서 조건을 등호로 표시하는 변수
|
||||
**/
|
||||
var $cond_operation = array(
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
'excess' => '>',
|
||||
'less' => '<=',
|
||||
'below' => '<',
|
||||
'notequal' => '!=',
|
||||
'notnull' => 'is not null',
|
||||
'null' => 'is null',
|
||||
);
|
||||
|
||||
var $fd = NULL; ///< connector resource or file description
|
||||
|
||||
var $result = NULL; ///< result
|
||||
|
|
@ -23,7 +37,7 @@
|
|||
var $errstr = ''; ///< 에러 발생시 에러 메세지
|
||||
var $query = ''; ///< 가장 최근에 수행된 query string
|
||||
|
||||
var $transaction_started = false;
|
||||
var $transaction_started = false; ///< 트랙잭션 처리 flag
|
||||
|
||||
var $is_connected = false; ///< DB에 접속이 되었는지에 대한 flag
|
||||
|
||||
|
|
@ -159,27 +173,29 @@
|
|||
**/
|
||||
function _executeQuery($cache_file, $source_args, $query_id) {
|
||||
global $lang;
|
||||
debugPrint($query_id);
|
||||
|
||||
if(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid');
|
||||
|
||||
if($source_args) $args = clone($source_args);
|
||||
|
||||
$output = include($cache_file);
|
||||
|
||||
if( (is_a($output, 'Object')||is_subclass_of($output,'Object'))&&!$output->toBool()) return $output;
|
||||
|
||||
// action값에 따라서 쿼리 생성으로 돌입
|
||||
switch($action) {
|
||||
switch($output->action) {
|
||||
case 'insert' :
|
||||
$output = $this->_executeInsertAct($tables, $column, $pass_quotes);
|
||||
$output = $this->_executeInsertAct($output);
|
||||
break;
|
||||
case 'update' :
|
||||
$output = $this->_executeUpdateAct($tables, $column, $args, $condition, $pass_quotes);
|
||||
$output = $this->_executeUpdateAct($output);
|
||||
break;
|
||||
case 'delete' :
|
||||
$output = $this->_executeDeleteAct($tables, $condition, $pass_quotes);
|
||||
$output = $this->_executeDeleteAct($output);
|
||||
break;
|
||||
case 'select' :
|
||||
$output = $this->_executeSelectAct($tables, $column, $invert_columns, $condition, $navigation, $group_script, $pass_quotes);
|
||||
$output = $this->_executeSelectAct($output);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -191,13 +207,9 @@
|
|||
/**
|
||||
* @brief $val을 $filter_type으로 검사
|
||||
**/
|
||||
function _checkFilter($key, $val, $filter_type, $minlength, $maxlength) {
|
||||
function _checkFilter($key, $val, $filter_type) {
|
||||
global $lang;
|
||||
|
||||
$length = strlen($val);
|
||||
if($minlength && $length < $minlength) return new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key}?$lang->{$key}:$key));
|
||||
if($maxlength && $length > $maxlength) return new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key}?$lang->{$key}:$key));
|
||||
|
||||
switch($filter_type) {
|
||||
case 'email' :
|
||||
case 'email_adderss' :
|
||||
|
|
@ -225,30 +237,41 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 조건문들 정리
|
||||
* @brief 이름, 값, operation으로 조건절 작성
|
||||
**/
|
||||
function _combineCondition($cond_group, $group_pipe) {
|
||||
if(!is_array($cond_group)) return;
|
||||
$cond_query = '';
|
||||
|
||||
foreach($cond_group as $group_idx => $group) {
|
||||
if(!is_array($group)) continue;
|
||||
|
||||
$buff = '';
|
||||
foreach($group as $key => $val) {
|
||||
$pipe = key($val);
|
||||
$cond = array_pop($val);
|
||||
if($buff) $buff .= ' '.$pipe.' '.$cond;
|
||||
else $buff = $cond;
|
||||
function getConditionPart($name, $value, $operation) {
|
||||
switch($operation) {
|
||||
case 'equal' :
|
||||
if(!$value) return;
|
||||
return $name.' = '.$value;
|
||||
break;
|
||||
case 'more' :
|
||||
if(!$value) return;
|
||||
return $name.' >= '.$value;
|
||||
break;
|
||||
case 'excess' :
|
||||
if(!$value) return;
|
||||
return $name.' > '.$value;
|
||||
break;
|
||||
case 'less' :
|
||||
if(!$value) return;
|
||||
return $name.' <= '.$value;
|
||||
break;
|
||||
case 'below' :
|
||||
if(!$value) return;
|
||||
return $name.' < '.$value;
|
||||
break;
|
||||
case 'notequal' :
|
||||
if(!$value) return;
|
||||
return $name.' != '.$value;
|
||||
break;
|
||||
case 'notnull' :
|
||||
return $name.' is not null';
|
||||
break;
|
||||
case 'null' :
|
||||
return $name.' is null';
|
||||
break;
|
||||
}
|
||||
|
||||
$g_pipe = $group_pipe[$group_idx];
|
||||
if(!$g_pipe) $g_pipe = 'and';
|
||||
if($cond_query) $cond_query .= sprintf(' %s ( %s )', $g_pipe, $buff);
|
||||
else $cond_query = '('.$buff.')';
|
||||
}
|
||||
return $cond_query;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -284,71 +284,81 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 삭제
|
||||
* @brief 조건문 작성하여 return
|
||||
**/
|
||||
function dropTable($target_name) {
|
||||
$query = sprintf('drop table `%s%s`;', $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_query($query);
|
||||
function getCondition($output) {
|
||||
if(!$output->conditions) return;
|
||||
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$sub_condition = '';
|
||||
foreach($val as $k =>$v) {
|
||||
if(!$v->value) continue;
|
||||
$name = $v->column;
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($v->value)."'";
|
||||
else $value = $v->value;
|
||||
$operation = $v->operation;
|
||||
|
||||
$str = $this->getConditionPart($name, $value, $operation);
|
||||
if($sub_condition) $sub_condition .= ' '.$v->pipe.' ';
|
||||
$sub_condition .= $str;
|
||||
}
|
||||
if($sub_condition) {
|
||||
if($condition && $val['pipe']) $condition .= ' '.$val['pipe'].' ';
|
||||
$condition .= '('.$sub_condition.')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블의 이름 변경
|
||||
**/
|
||||
function renameTable($source_name, $targe_name) {
|
||||
$query = sprintf("alter table `%s%s` rename `%s%s`;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name));
|
||||
$this->_query($query);
|
||||
}
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
|
||||
/**
|
||||
* @brief 테이블을 비움
|
||||
**/
|
||||
function truncateTable($target_name) {
|
||||
$query = sprintf("truncate table `%s%s`;", $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 데이터 Dump
|
||||
*
|
||||
* @todo 아직 미구현
|
||||
**/
|
||||
function dumpTable($target_name) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insertAct 처리
|
||||
**/
|
||||
function _executeInsertAct($tables, $column, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
$key_list[] = $key;
|
||||
if(in_array($key, $pass_quotes)) $val_list[] = $this->addQuotes($val);
|
||||
else $val_list[] = '\''.$this->addQuotes($val).'\'';
|
||||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
}
|
||||
|
||||
$query = sprintf("insert into `%s%s` (%s) values (%s);", $this->prefix, $table, '`'.implode('`,`',$key_list).'`', implode(',', $val_list));
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
if(!$value) $value = 'null';
|
||||
|
||||
$column_list[] = '`'.$name.'`';
|
||||
$value_list[] = $value;
|
||||
}
|
||||
|
||||
$query = sprintf("insert into %s (%s) values (%s);", implode(',',$table_list), implode(',',$column_list), implode(',', $value_list));
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief updateAct 처리
|
||||
**/
|
||||
function _executeUpdateAct($tables, $column, $args, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
// args에 아예 해당 key가 없으면 패스
|
||||
if(!isset($args->{$key})) continue;
|
||||
if(in_array($key, $pass_quotes)) $update_list[] = sprintf('`%s` = %s', $key, $this->addQuotes($val));
|
||||
else $update_list[] = sprintf('`%s` = \'%s\'', $key, $this->addQuotes($val));
|
||||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
}
|
||||
if(!count($update_list)) return;
|
||||
$update_query = implode(',',$update_list);
|
||||
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
|
||||
$query = sprintf("update `%s%s` set %s %s;", $this->prefix, $table, $update_query, $condition);
|
||||
$column_list[] = sprintf("`%s` = %s", $name, $value);
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("update %s set %s %s", implode(',',$table_list), implode(',',$column_list), $condition);
|
||||
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -356,12 +366,17 @@
|
|||
/**
|
||||
* @brief deleteAct 처리
|
||||
**/
|
||||
function _executeDeleteAct($tables, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
}
|
||||
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
|
||||
|
||||
$query = sprintf("delete from `%s%s` %s;", $this->prefix, $table, $condition);
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
||||
|
|
@ -371,32 +386,31 @@
|
|||
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
|
||||
* navigation이라는 method를 제공
|
||||
**/
|
||||
function _executeSelectAct($tables, $column, $invert_columns, $condition, $navigation, $group_script, $pass_quotes) {
|
||||
if(!count($tables)) $table = $this->prefix.array_pop($tables);
|
||||
else {
|
||||
foreach($tables as $key => $val) $table_list[] = sprintf('%s%s as %s', $this->prefix, $key, $val);
|
||||
function _executeSelectAct($output) {
|
||||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'` as '.$val;
|
||||
}
|
||||
$table = implode(',',$table_list);
|
||||
|
||||
if(!$column) $columns = '*';
|
||||
else {
|
||||
foreach($invert_columns as $key => $val) {
|
||||
$column_list[] = sprintf('%s as %s',$val, $key);
|
||||
if($val) $column_list[] = sprintf('%s as %s',$val, $key);
|
||||
else $column_list[] = sprintf('%s',$val);
|
||||
}
|
||||
$columns = implode(',', $column_list);
|
||||
}
|
||||
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
if($navigation->list_count) return $this->_getNavigationData($table, $columns, $condition, $navigation);
|
||||
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
|
||||
|
||||
$query = sprintf("select %s from %s %s", $columns, $table, $condition);
|
||||
if($output->list_count) return $this->_getNavigationData($table_list, $columns, $condition, $output);
|
||||
|
||||
$query .= ' '.$group_script;
|
||||
|
||||
if($navigation->index) {
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $key, $val);
|
||||
}
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
|
@ -415,11 +429,11 @@
|
|||
*
|
||||
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
|
||||
**/
|
||||
function _getNavigationData($table, $columns, $condition, $navigation) {
|
||||
function _getNavigationData($table_list, $columns, $condition, $output) {
|
||||
require_once('./classes/page/PageHandler.class.php');
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", $table, $condition);
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
|
|
@ -432,12 +446,17 @@
|
|||
else $page = $navigation->page;
|
||||
$start_count = ($page-1)*$navigation->list_count;
|
||||
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$query = sprintf("select %s from %s %s", implode(',',$columns), implode(',',$table_list), $condition);
|
||||
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
}
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
||||
$query .= sprintf('%s limit %d, %d', $query, $start_count, $output->list_count['value']);
|
||||
|
||||
$index = implode(',',$index_list);
|
||||
$query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
|
||||
$result = $this->_query($query);
|
||||
if($this->isError()) {
|
||||
$buff = new Object();
|
||||
|
|
|
|||
|
|
@ -10,20 +10,6 @@
|
|||
|
||||
class XmlQueryParser extends XmlParser {
|
||||
|
||||
/**
|
||||
* @brief 조건문에서 조건을 등호로 표시하는 변수
|
||||
**/
|
||||
var $cond_operation = array(
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
'excess' => '>',
|
||||
'less' => '<=',
|
||||
'below' => '<',
|
||||
'notequal' => '!=',
|
||||
'notnull' => 'is not null',
|
||||
'null' => 'is null',
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief 쿼리 파일을 찾아서 파싱하고 캐싱한다
|
||||
**/
|
||||
|
|
@ -32,56 +18,247 @@
|
|||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
unset($buff);
|
||||
|
||||
// 쿼리 스크립트를 만들때 필요한 변수들
|
||||
$filter_script = $notnull_script = $column_script = $default_script = '';
|
||||
list($module, $id) = explode('.',$query_id);
|
||||
|
||||
// insert, update, delete, select등의 action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// 테이블 정리 (배열코드로 변환)
|
||||
$tables = $this->_getTablesScript($xml_obj);
|
||||
$tables = $xml_obj->query->tables->table;
|
||||
if(!$tables) return;
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
foreach($tables as $key => $val) {
|
||||
// 테이블과 alias의 이름을 구함
|
||||
$table_name = $val->attrs->name;
|
||||
$alias = $val->attrs->alias;
|
||||
if(!$alias) $alias = $table_name;
|
||||
|
||||
$output->tables[$table_name] = $alias;
|
||||
|
||||
// 테이블을 찾아서 컬럼의 속성을 구함
|
||||
$table_file = sprintf('./modules/%s/schemas/%s.xml', $module, $table_name);
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$table_obj = parent::parse($table_xml);
|
||||
if($table_obj->table) {
|
||||
foreach($table_obj->table->column as $k => $v) {
|
||||
$buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
$column_script = $this->_getColumnsScript($xml_obj, $default_script, $notnull_script, $filter_script, $action);
|
||||
$columns = $xml_obj->query->columns->column;
|
||||
if(!$columns) {
|
||||
$output->column[] = array("*" => "*");
|
||||
} else {
|
||||
if(!is_array($columns)) $columns = array($columns);
|
||||
foreach($columns as $key => $val) {
|
||||
$name = $val->attrs->name;
|
||||
/*
|
||||
if(strpos('.',$name)===false && count($output->tables)==1) {
|
||||
$tmp = array_values($output->tables);
|
||||
$name = sprintf('%s.%s', $tmp[0], $val->attrs->name);
|
||||
}
|
||||
*/
|
||||
|
||||
$output->columns[] = array(
|
||||
"name" => $name,
|
||||
"var" => $val->attrs->var,
|
||||
"default" => $val->attrs->default,
|
||||
"notnull" => $val->attrs->notnull,
|
||||
"filter" => $val->attrs->filter,
|
||||
"minlength" => $val->attrs->minlength,
|
||||
"maxlength" => $val->attrs->maxlength,
|
||||
"alias" => $val->attrs->alias,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
$condition_script = $this->_getConditionScript($xml_obj, $default_script, $notnull_script, $filter_script);
|
||||
$conditions = $xml_obj->query->conditions;
|
||||
|
||||
$condition = $conditions->condition;
|
||||
if($condition) {
|
||||
$obj->condition = $condition;
|
||||
unset($condition);
|
||||
$condition = array($obj);
|
||||
}
|
||||
|
||||
$condition_group = $conditions->group;
|
||||
if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group);
|
||||
|
||||
if($condition && $condition_group) $cond = array_merge($condition, $condition_group);
|
||||
elseif($condition_group) $cond = $condition_group;
|
||||
else $cond = $condition;
|
||||
|
||||
if($cond) {
|
||||
foreach($cond as $key => $val) {
|
||||
unset($cond_output);
|
||||
|
||||
if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe;
|
||||
else $cond_output->pipe = null;
|
||||
|
||||
if(!$val->condition) continue;
|
||||
if(!is_array($val->condition)) $val->condition = array($val->condition);
|
||||
|
||||
foreach($val->condition as $k => $v) {
|
||||
$obj = $v->attrs;
|
||||
if(!$obj->alias) $obj->alias = $obj->column;
|
||||
$cond_output->condition[] = $obj;
|
||||
}
|
||||
|
||||
$output->conditions[] = $cond_output;
|
||||
}
|
||||
}
|
||||
|
||||
// group 정리
|
||||
$group_script = $this->_getGroupScript($xml_obj);
|
||||
$groups = $xml_obj->query->groups->group;
|
||||
if($groups) {
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
if(count($group_column_list)) $output->groups = $group_column_list;
|
||||
}
|
||||
|
||||
// 네비게이션 정리
|
||||
$navigation_script = $this->_getNavigationScript($xml_obj);
|
||||
$navigation = $xml_obj->query->navigation;
|
||||
if($navigation) {
|
||||
$order = $navigation->index;
|
||||
if($order) {
|
||||
if(!is_array($order)) $order = array($order);
|
||||
foreach($order as $order_info) {
|
||||
$output->order[] = $order_info->attrs;
|
||||
}
|
||||
}
|
||||
|
||||
// 캐쉬 내용 작성
|
||||
$buff =
|
||||
sprintf(
|
||||
'<?php if(!defined("__ZBXE__")) exit();'."\n".
|
||||
'$pass_quotes = array();'."\n".
|
||||
'$id = \'%s\';'."\n".
|
||||
'$action = \'%s\';'."\n".
|
||||
'$tables = array(%s);'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'$group_script = \'%s\''."\n".
|
||||
'?>',
|
||||
$query_id,
|
||||
$action,
|
||||
$tables,
|
||||
$default_script,
|
||||
$column_script,
|
||||
$notnull_script,
|
||||
$filter_script,
|
||||
$condition_script,
|
||||
$navigation_script,
|
||||
$group_script
|
||||
);
|
||||
$list_count = $navigation->list_count->attrs;
|
||||
$output->list_count = $list_count;
|
||||
|
||||
$page_count = $navigation->page_count->attrs;
|
||||
$output->page_count = $page_count;
|
||||
|
||||
$page = $navigation->page->attrs;
|
||||
$output->page = $page ;
|
||||
}
|
||||
|
||||
$column_count = count($output->columns);
|
||||
$condition_count = count($output->conditions);
|
||||
|
||||
// php script 생성
|
||||
|
||||
// table 정리
|
||||
$buff .= '$output->tables = array( ';
|
||||
foreach($output->tables as $key => $val) {
|
||||
$buff .= sprintf('"%s"=>"%s",', $key, $val);
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
|
||||
// column 정리
|
||||
if($column_count) {
|
||||
$buff .= '$output->columns = array ( ';
|
||||
foreach($output->columns as $key => $val) {
|
||||
$val['default'] = $this->getDefault($val['name'], $val['default']);
|
||||
if($val['var']) {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['var'], $val['var'], $val['default'] ,"\n");
|
||||
if($val['notnull']) $notnull_list[] = $val['var'];
|
||||
if($val['minlength']) $minlength_list[$val['var']] = $val['minlength'];
|
||||
if($val['maxlength']) $maxlength_list[$val['var']] = $val['maxlength'];
|
||||
} else {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>%s),%s', $val['name'], $val['default'] ,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// conditions 정리
|
||||
if($condition_count) {
|
||||
$buff .= '$output->conditions = array ( ';
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n");
|
||||
foreach($val->condition as $k => $v) {
|
||||
$v->default = $this->getDefault($v->column, $v->default);
|
||||
if($v->var) {
|
||||
if(strpos($v->var,".")===false) {
|
||||
if($v->filter) $filter_list[] = $v;
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
|
||||
} else {
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
}
|
||||
} else {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->name, $v->default ,$v->pipe, $v->operation,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ')),'."\n";
|
||||
}
|
||||
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// order 정리
|
||||
if($output->order) {
|
||||
$buff .= '$output->order = array(';
|
||||
foreach($output->order as $key => $val) {
|
||||
$buff .= sprintf('"%s"=>"%s",', $val->var, $val->order);
|
||||
}
|
||||
$buff .= ');'."\n";
|
||||
}
|
||||
|
||||
// list_count 정리
|
||||
if($output->list_count) {
|
||||
$buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page_count 정리
|
||||
if($output->page_count) {
|
||||
$buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page 정리
|
||||
if($output->page) {
|
||||
$buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n");
|
||||
}
|
||||
|
||||
// not null check
|
||||
if(count($notnull_list)) {
|
||||
foreach($notnull_list as $key => $val) {
|
||||
$pre_buff .= 'if(!$args->'.$val.') return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// minlength check
|
||||
if(count($minlength_list)) {
|
||||
foreach($minlength_list as $key => $val) {
|
||||
$pre_buff .= 'if(strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// maxlength check
|
||||
if(count($maxlength_list)) {
|
||||
foreach($maxlength_list as $key => $val) {
|
||||
$pre_buff .= 'if(strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// filter check
|
||||
if(count($filter_list)) {
|
||||
foreach($filter_list as $key => $val) {
|
||||
$pre_buff .= sprintf('unset($output); $output = $this->_checkFilter("%s",$args->%s,"%s"); if(!$output->toBool()) return $output;%s',$val->var,$val->var,$val->filter,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
$buff = "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. sprintf('$output->query_id = "%s";%s', $query_id, "\n")
|
||||
. sprintf('$output->action = "%s";%s', $action, "\n")
|
||||
. $pre_buff
|
||||
. $buff
|
||||
. 'return $output; ?>';
|
||||
|
||||
// 저장
|
||||
FileHandler::writeFile($cache_file, $buff);
|
||||
|
|
@ -90,17 +267,16 @@
|
|||
/**
|
||||
* @brief column, condition등의 key에 default 값을 세팅
|
||||
**/
|
||||
function _getDefaultCode($name, $value) {
|
||||
if($value == NULL) return;
|
||||
if(substr($value, -1)!=')') return sprintf('if(!$args->%s) $args->%s = \'%s\';'."\n", $name, $name, $value);
|
||||
|
||||
function getDefault($name, $value) {
|
||||
$str_pos = strpos($value, '(');
|
||||
if($str_pos===false) return '"'.$value.'"';
|
||||
|
||||
$func_name = substr($value, 0, $str_pos);
|
||||
$args = substr($value, $str_pos+1, strlen($value)-1);
|
||||
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '\''.$_SERVER['REMOTE_ADDR'].'\'';
|
||||
$val = '"$_SERVER[\'REMOTE_ADDR\']"';
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
|
|
@ -113,257 +289,16 @@
|
|||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s+%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
$val = sprintf('%s+%d', $name, $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s-%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
$val = sprintf('%s-%d', $name, $args);
|
||||
break;
|
||||
}
|
||||
|
||||
$output = sprintf('if(!$args->%s) $args->%s = %s;'."\n", $name, $name, $val);
|
||||
if($pass_quotes) $output .= sprintf('$pass_quotes[] = \'%s\';'."\n",$name);
|
||||
return $output;
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 필터 체크
|
||||
**/
|
||||
function _getFilterCode($key, $type, $minlength, $maxlength, $var='column', $notnull='') {
|
||||
if(!$type||!$minlength||!$maxlength) return;
|
||||
if(!$notnull) $notnull_code = sprintf('if($%s->%s) ', $var, $key);
|
||||
|
||||
return
|
||||
sprintf(
|
||||
'unset($output); %s$output = $this->_checkFilter(\'%s\', $%s->%s, \'%s\', \'%d\', \'%d\'); if(!$output->toBool()) return $output;'."\n",
|
||||
$notnull_code,
|
||||
$key,
|
||||
$var,
|
||||
$key,
|
||||
$type,
|
||||
(int)$minlength,
|
||||
(int)$maxlength
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief not null 체크된 항목에 대한 처리
|
||||
**/
|
||||
function _getNotNullCode($name, $var='column') {
|
||||
return
|
||||
sprintf(
|
||||
'if(!$%s->%s) return new Object(-1, sprintf($lang->filter->isnull, $lang->%s?$lang->%s:\'%s\'));'."\n",
|
||||
$var,
|
||||
$name,
|
||||
$name,
|
||||
$name,
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 대상 테이블에 대한 처리
|
||||
**/
|
||||
function _getTablesScript($xml_obj) {
|
||||
$obj_tables = $xml_obj->query->tables->table;
|
||||
if(!is_array($obj_tables)) $obj_tables = array('', $obj_tables);
|
||||
|
||||
foreach($obj_tables as $table_info) {
|
||||
$name = trim($table_info->attrs->name);
|
||||
if(!$name) continue;
|
||||
$alias = trim($table_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$table_list[] = sprintf('\'%s\'=>\'%s\'', $name, $alias);
|
||||
}
|
||||
return implode(",",$table_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 컬럼 처리
|
||||
**/
|
||||
function _getColumnsScript($xml_obj, &$default_script, &$notnull_script, &$filter_script, $action) {
|
||||
$obj_columns = $xml_obj->query->columns->column;
|
||||
if(!is_array($obj_columns)) $obj_columns = array('', $obj_columns);
|
||||
|
||||
foreach($obj_columns as $column_info) {
|
||||
$name = trim($column_info->attrs->name);
|
||||
if(!$name || $name == '*') continue;
|
||||
|
||||
$var = trim($column_info->attrs->var);
|
||||
$alias = trim($column_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$default = trim($column_info->attrs->default);
|
||||
$notnull = trim($column_info->attrs->notnull);
|
||||
|
||||
$filter_type = trim($column_info->attrs->filter);
|
||||
$minlength = (int)trim($column_info->attrs->minlength);
|
||||
$maxlength = (int)trim($column_info->attrs->maxlength);
|
||||
|
||||
$column_script .= sprintf('$column->%s = $args->%s;'."\n", $alias, $var?$var:$alias);
|
||||
$invert_columns[] = sprintf('\'%s\'=>\'%s\'', $alias, $name);
|
||||
|
||||
$default_script .= $this->_getDefaultCode($alias, $default);
|
||||
if($action != 'select') {
|
||||
if($filter_type) $filter_script .= $this->_getFilterCode($alias, $filter_type, $minlength, $maxlength, 'column', $notnull);
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($alias);
|
||||
}
|
||||
}
|
||||
if(is_array($invert_columns)) $column_script .= sprintf('$invert_columns = array(%s);'."\n", implode(',',$invert_columns));
|
||||
return $column_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건절 처리
|
||||
**/
|
||||
function _getConditionScript($xml_obj, &$default_script, &$notnull_script, &$filter_script) {
|
||||
$cond_idx = 0;
|
||||
|
||||
$obj_conditions = $xml_obj->query->conditions->condition;
|
||||
|
||||
$condition_script = $condition = $this->_getConditionQuery($cond_idx++, $obj_conditions, NULL, $notnull_script, $filter_script);
|
||||
|
||||
$obj_groups = $xml_obj->query->conditions->group;
|
||||
if(!is_array($obj_groups)) $obj_groups = array('', $obj_groups);
|
||||
|
||||
foreach($obj_groups as $obj_group) {
|
||||
$group_pipe = $obj_group->attrs->pipe;
|
||||
if(!$group_pipe) continue;
|
||||
$buff = $this->_getConditionQuery($cond_idx++, $obj_group->condition, $group_pipe, $notnull_script, $filter_script);
|
||||
$condition_script .= $buff;
|
||||
}
|
||||
|
||||
$condition_script .= '$condition = $this->_combineCondition($cond_group, $group_pipe);'."\n";
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건문의 쿼리를 만들어 줌
|
||||
**/
|
||||
function _getConditionQuery($cond_idx, $obj, $group_pipe, &$notnull_script, &$filter_script) {
|
||||
if(!is_array($obj)) $obj = array('', $obj);
|
||||
|
||||
$idx = 0;
|
||||
foreach($obj as $obj_cond) {
|
||||
$operation = $obj_cond->attrs->operation;
|
||||
if(!$operation) continue;
|
||||
|
||||
$column = $obj_cond->attrs->column;
|
||||
$var = $obj_cond->attrs->var;
|
||||
$filter = $obj_cond->attrs->filter;
|
||||
$notnull = $obj_cond->attrs->notnull;
|
||||
$pipe = $obj_cond->attrs->pipe;
|
||||
if(!$pipe) $pipe = 'and';
|
||||
$default = $obj_cond->attrs->default;
|
||||
|
||||
// 비교 대상이 다른 혹은 같은 테이블의 column일 경우
|
||||
if(eregi("\.", $var)) {
|
||||
switch($operation) {
|
||||
case 'in' :
|
||||
$buff = sprintf('%s in (%s)', $column, $var);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if(!$operation) $operation = 'and';
|
||||
$buff = sprintf('%s %s %s', $column, $operation, $var);
|
||||
break;
|
||||
}
|
||||
$condition_script .= sprintf('$cond_group[%d][][\'%s\'] = \'%s\';'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
// 입력받을 변수일 경우
|
||||
} else {
|
||||
switch($operation) {
|
||||
case 'like' :
|
||||
$buff = sprintf('sprintf("%s like \'%%%%%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'like_prefix' :
|
||||
$buff = sprintf('sprintf("%s like \'%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'in' :
|
||||
//$buff = sprintf('sprintf("%s in (%%s) ", $this->addQuotes($args->%s))', $column, $var);
|
||||
$buff = sprintf('sprintf("%s in (%%s) ", $args->%s)', $column, $var);
|
||||
break;
|
||||
case 'notnull' :
|
||||
case 'null' :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
unset($var);
|
||||
$buff = sprintf('"%s %s "', $column, $operation);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if($default) $buff = sprintf('sprintf("%s %s \'%%s\' ", $args->%s?$this->addQuotes($args->%s):\'%s\')', $column, $operation, $var?$var:$column, $var?$var:$column, $default);
|
||||
else $buff = sprintf('sprintf("%s %s \'%%s\' ", $this->addQuotes($args->%s))', $column, $operation, $var?$var:$column);
|
||||
break;
|
||||
}
|
||||
|
||||
$buff = sprintf('$cond_group[%d][][\'%s\'] = %s;'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
if(!$notnull && $var) $buff = sprintf('if($args->%s) ', $var).$buff;
|
||||
$condition_script .= $buff;
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($var?$var:$column, 'args');
|
||||
if($filter) $filter_script .= $this->_getFilterCode($var, $filter, 0, 0, 'args', $notnull);
|
||||
}
|
||||
}
|
||||
$condition_script .= sprintf('$group_pipe[%d] = \'%s\';'."\n", $cond_idx, $group_pipe);
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief group by 쿼리 처리
|
||||
**/
|
||||
function _getGroupScript($xml_obj) {
|
||||
$group_list = $xml_obj->query->groups->group;
|
||||
if(!$group_list) return;
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
|
||||
if(count($group_column_list)) {
|
||||
return ' GROUP BY '.implode(" , ", $group_column_list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief page navigation 처리
|
||||
**/
|
||||
function _getNavigationScript($xml_obj) {
|
||||
$obj_navigation = $xml_obj->query->navigation;
|
||||
if(!$obj_navigation) return;
|
||||
|
||||
$obj_index = $obj_navigation->index->attrs;
|
||||
$index_list = array();
|
||||
if(!is_array($obj_index)) $obj_index = array('', $obj_index);
|
||||
foreach($obj_index as $index_info) {
|
||||
$var = trim($index_info->var);
|
||||
if(!$var) continue;
|
||||
$default = trim($index_info->default);
|
||||
$order = trim($index_info->order);
|
||||
if(!$order) $order = 'asc';
|
||||
|
||||
$navigation_script .= sprintf('$navigation->index[] = array($args->%s?$args->%s:\'%s\', \'%s\');'."\n", $var, $var, $default, $order);
|
||||
}
|
||||
|
||||
$obj_list_count = $obj_navigation->list_count->attrs;
|
||||
$count_var = $obj_list_count->var;
|
||||
$count_default = $obj_list_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->list_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page_count = $obj_navigation->page_count->attrs;
|
||||
$count_var = $obj_page_count->var;
|
||||
$count_default = $obj_page_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->page_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page = $obj_navigation->page->attrs;
|
||||
$page_var = $obj_page->var;
|
||||
$page_default = $obj_page->default;
|
||||
if($page_var) $navigation_script .= sprintf('$navigation->page = $args->%s?$args->%s%s;'."\n", $page_var, $page_var, $page_default?':'.$page_default:'');
|
||||
|
||||
return $navigation_script;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
//ob_start();
|
||||
/**
|
||||
* @file index.php
|
||||
* @author zero (zero@zeroboard.com)
|
||||
|
|
@ -28,6 +27,7 @@
|
|||
**/
|
||||
require_once("./config/config.inc.php");
|
||||
|
||||
ob_start();
|
||||
/**
|
||||
* @brief Context 객체를 생성하여 초기화
|
||||
* 모든 Request Argument/ 환경변수등을 세팅
|
||||
|
|
@ -48,6 +48,6 @@
|
|||
$oModuleHandler->init();
|
||||
$oModule = &$oModuleHandler->procModule();
|
||||
$oModuleHandler->displayContent($oModule);
|
||||
//debugPrint(ob_get_contents());
|
||||
//ob_end_flush();
|
||||
debugPrint(ob_get_contents());
|
||||
ob_end_flush();
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
<table name="action_forward" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="act" default="act" notnull="notnull" />
|
||||
<column name="module" default="module" notnull="notnull" />
|
||||
<column name="type" default="type" notnull="notnull" />
|
||||
<column name="act" var="act" notnull="notnull" />
|
||||
<column name="module" var="module" notnull="notnull" />
|
||||
<column name="type" var="type" notnull="notnull" />
|
||||
</columns>
|
||||
</query>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<table name="modules">
|
||||
<column name="module_srl" type="number" size="11" notnull="notnull" primary_key="primary_key" />
|
||||
<column name="module" type="varchar" size="80" notnull="notnull" index="idx_module" />
|
||||
<column name="module_category_srl" type="number" size="11" notnull="notnull" default="0" index="idx_module_category" />
|
||||
<column name="module_category_srl" type="number" size="11" default="0" index="idx_module_category" />
|
||||
<column name="layout_srl" type="number" size="11" notnull="notnull" default="0" />
|
||||
<column name="mid" type="varchar" size="40" notnull="notnull" unique="unique_mid"/>
|
||||
<column name="skin" type="varchar" size="250" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue