<?php
/* 快捷商城系统
 * 版本号：2.0
 * 官网：http://www.kjcms.cn
 * 2015-02-16
 */
class mod_index extends inc_mod_default {
	function datasource_save() {
		$where_name = fun_get::get("where_name");
		$where_condition = fun_get::get("where_condition");
		$where_val = fun_get::get("where_val");
		$arr_where = $arr_sort = array();
		for($i = 0 ; $i < count($where_name) ; $i++) {
			$arr_where[] = array(
				"name" => $where_name[$i],
				"condition" => fun_get::filter($where_condition[$i],true),
				"val" => $where_val[$i]
			);
		}
		$sort_name = fun_get::get("sort_name");
		$sort_by = fun_get::get("sort_by");
		$arr_sort = array();
		for($i = 0 ; $i < count($sort_name) ; $i++) {
			$arr_sort[] = array(
				"name" => $sort_name[$i],
				"by" => $sort_by[$i]
			);
		}
		$param_name = fun_get::get("param_name");
		if(empty($param_name) || !is_array($param_name)) $param_name = array();
		$arr_fields = array(
			"dirname" => fun_get::get("dirname"),
			"typename" => fun_get::get("typename"),
			"name" => fun_get::get("name"),
			"cnname" => fun_get::get("cnname"),
			"seltable" => fun_get::get("seltable"),
			"limit_start" => fun_get::get("limit_start"),
			"limit_end" => fun_get::get("limit_end"),
			"pagesize" => fun_get::get("pagesize"),
			"datasource_name" => fun_get::get("datasource_name"),
			"where" => $arr_where,
			"sort" => $arr_sort,
			"fields" => fun_get::get("fields"),
			"oldname" => fun_get::get("oldname"),
			"param_name" => $param_name,
		);
		$btnpagesize = fun_get::get("btnpagesize");
		if(empty($btnpagesize)) $arr_fields['pagesize'] = 0;
		$arr = cls_developer::datasource_save($arr_fields);
		cls_developer::datasource_create($arr_fields['dirname'] , $arr_fields['typename']);
		return $arr;
	}

	function get_sys_config($module) {
		$arr_return = array("list" => array());
		$obj_db = cls_obj::db();
		$str_where = " where config_module='" . $module . "'";
		$obj_result = $obj_db->select("SELECT * FROM ".cls_config::DB_PRE."sys_config" . $str_where . " order by config_sort,config_id");
		while( $obj_rs = $obj_db->fetch_array($obj_result) ) {
			if($obj_rs["config_list"]!="")	{
				$obj_rs["config_list"] = tab_sys_config::get_array($obj_rs["config_list"]);
			} else {
				$obj_rs["config_list"] = array();
			}
			if(fun_is::serialized($obj_rs['config_val'])) {
				$obj_rs['config_val'] = unserialize($obj_rs["config_val"]);
			}
			if($obj_rs["config_type"] == 'chk' && !is_array($obj_rs['config_val'])) $obj_rs['config_val'] = array();
			$arr_return["list"][] = $obj_rs;
		}
		return $arr_return;
	}
}