<?php
define('IN_PHPQUAN', true);
require dirname(__FILE__) . '/include/common.php';
require dirname(__FILE__) . '/include/com.fun.php';
require PHPQUAN_ROOT . 'include/json.class.php';
ini_set('display_errors', 'on');  
$PNG_TEMP_DIR = dirname(__FILE__).'/phpqrcode/'.DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;  
$PNG_WEB_DIR = 'temp/';  
require dirname(__FILE__) . '/phpqrcode/qrlib.php';    // QRcode lib  

$act = $_REQUEST['act'] ? trim($_REQUEST['act']) : 'select' ;
if(!$_userid) {
	showmsg('你还没有登录', 'member.php?act=login&refer='.$PHP_URL);
} else {
	$member = member_info($_userid);
	if($member['status']!=1) showmsg('您尚未通过审核或被锁定！');
}
//check_gid();
$u = com_info('',1);
if($u>0)showmsg('已经登记过店铺了!','member.php');
$ip = get_ip();
if($act == 'select')
{
	$seo['title'] = '选择商家类型';
	$seo['keywords'] = $CFG['keywords'];
	$seo['description'] = $CFG['description'];
	$here = array('title'=>'选择商家类型','url'=>'javascript:history.back()');
	$cats = get_com_cat_list();
	include template('com_select','com');
}
elseif($act == 'post')
{
	$durl="postcom";
	$mappoint = $CFG['map'] ? explode(',', $CFG['map']) : '';
	$catid = intval($_REQUEST['id']);
	if(empty($catid)) {
		showmsg('没有选择分类');
	}
	$com_catinfo = get_com_cat_info($catid);
	if(empty($com_catinfo))showmsg('不存在此分类');
	$seo['title'] = '登记商家信息';
	$seo['keywords'] = $CFG['keywords'];
	$seo['description'] = $CFG['description'];
	$here = array('title'=>$com_catinfo['catname'],'url'=>'javascript:history.back()');
	include template('com_post','com');
}
elseif($act == 'add')
{
	$catid     = $_POST['catid'] ? intval($_POST['catid']) : '';
	$comname   = $_POST['comname'] ? htmlspecialchars(trim($_POST['comname'])) : '';
	$postdate  = time();
	$phone     = $_POST['phone'] ? htmlspecialchars($_POST['phone']) : '';
	$address   = $_POST['address'] ? htmlspecialchars($_POST['address']) : '';
	$is_check  = $CFG['post_check'] == '1' ?  '0' : '1';
    if(empty($comname))showmsg("店铺名必须填写");
    if(empty($phone))showmsg("电话必须填写");
	$com_name = $db->getOne("select comname from {$table}com where comname='$comname' ");
	if(!empty($com_name))showmsg('已经存在此店铺名');
	$com_phone = $db->getOne("select phone from {$table}com where phone='$phone' ");
	if(!empty($com_phone))showmsg('电话已存在！');
	check_words(array($comname, $introduce));
    $sql = "insert into {$table}com (userid,catid,comname,phone,postdate,address,is_check) 
	values ('$_userid','$catid','$comname','$phone','$postdate','$address','$is_check')";
    $res = $db->query($sql);
	$id  = $db->insert_id();
	$datavalue = $CFG['weburl'].'/com.php?act=view&qr=1&id='.$id; // data  qr通过扫码进入
    $ecc = 'H'; // L-smallest, M, Q, H-best  
    $size = 10; // 1-50 
	$filename = $PNG_TEMP_DIR.$id.'.png';  
    QRcode::png($datavalue, $filename, $ecc, $size, 2);  
    chmod($filename, 0777);
	//
	showmsg("登记成功，请等待审核！", "member.php");
}
?>