<?php
/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
 */
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
$dzzdomain='http://dzz.mawangye.com/';
$refer=dreferer();
$output_buffering=intval(ini_get('output_buffering'));
if($_G['setting']['dzz_sysconfig']){
	$sysconfig=dstripslashes(unserialize(stripslashes($_G['setting']['dzz_sysconfig'])));
}else{
	$sysconfig=DB::fetch_first("select * from ".DB::table('dzz_config')." where id='1'");
}
if(($operation!='dzzsitekey' && $operation!='doctor') &&(!$_G['setting']['dzz_market_status'] || !$_G['setting']['dzz_siteid'] || !$_G['setting']['dzz_sitekey'])) {
				dzz_cpheader();
				$locationUrl =  $_G['siteurl'].ADMINSCRIPT.'?action=dzzsitekey';
				
				cpmsg($lang['dzzmarket_no_open'],'', 'succeed', array(), '<p class="marginbot"><a href="###" onclick="top.location = \''.ADMINSCRIPT.'\'" class="lightlink">'.cplang('message_redirect').'</a></p><script type="text/JavaScript">setTimeout("top.location = \''.$locationUrl.'\'", 3000);</script>');
				dzzfooter();
			}
if($operation=='dzzsitekey'){
		$key=dstripslashes(trim($_GET['key']));
		$op=intval($_GET['op']);
		$sitekey=dstripslashes(trim($_GET['sitekey']));
		if($op){
			dzz_cpheader();
			dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_bind]']);
			
			list($dzz_siteid,$dzz_sitekey)=explode("\t",authcode($sitekey,'DECODE',$key));
			if($dzz_siteid && $dzz_sitekey){
					DB::query("REPLACE INTO ".DB::table('common_setting')." (`skey`, `svalue`)
								VALUES ('dzz_siteid', '$dzz_siteid'), ('dzz_sitekey', '$dzz_sitekey'), ('dzz_market_status', '1')");
					updatecache('setting');
					$locationUrl =  $_G['siteurl'].ADMINSCRIPT.'?action=market';
					cpmsg($lang['menu_dzzmarket'].$lang['succeed'], '', 'succeed', array(), '<p class="marginbot"><a href="###" onclick="top.location = \''.$locationUrl.'\'" class="lightlink">'.cplang('message_redirect').'</a></p><script type="text/JavaScript">setTimeout("top.location = \''.$locationUrl.'\'", 3000);</script>');
			}else{
				cpmsg($lang['dzzmarket_bind_failure'],$_G['siteurl'].ADMINSCRIPT."?action=market&operation=dzzsitekey");
			}
		}else{
			dzz_cpheader();
			dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_bind]']);
			$locationUrl = $_G['siteurl'].ADMINSCRIPT.'?action=market';
			if($_G['setting']['dzz_market_status'] && $_G['setting']['dzz_siteid'] && $_G['setting']['dzz_sitekey']) {
				cpmsg($lang['dzzmarket_bind_before'],'', 'succeed', array(), '<p class="marginbot"><a href="###" onclick="top.location = \''.ADMINSCRIPT.'\'" class="lightlink">'.cplang('message_redirect').'</a></p><script type="text/JavaScript">setTimeout("top.location = \''.$locationUrl.'\'", 3000);</script>');
			}
			
			$api=$dzzdomain.'dzz.php?mod=api&op=service&do=introduction';
			$data1=dzz_file_get_contents($api);
			if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
			$data=json_decode($data1,true);
			if($data['status']=='ok'){
				  foreach($data['cloudIntroduction'] as $key => $value){
					$data['cloudIntroduction'][$key]=diconv($value,'UTF-8');
				  }
				  $data['navSteps']=diconv( $data['navSteps'],'UTF-8');
			}else{
				cpmsg($lang['network_busy'],$refer,'error');
			}
			include dzztemplate('admin/dzz_market');
			dzzfooter();
		}
	
}elseif($operation=='doctor'){
		if(submitcheck('siteidkeysubmit')) {
				dzz_cpheader();
				$siteId = intval(trim($_GET['dzz_siteid']));
				if($siteId && strcmp($_GET['dzz_siteid'], $siteId) !== 0) {
					cpmsg($lang['siteid_warning_tip'], '', 'error');
				}
			
				$_GET['dzz_sitekey'] = trim($_GET['dzz_sitekey']);
				if(empty($_GET['dzz_sitekey'])) {
					$siteKey = '';
				} elseif(strpos($_GET['dzz_sitekey'], '***')) {
					$siteKey = false;
				} elseif(preg_match('/^[0-9a-f]{42}$/', $_GET['dzz_sitekey'])) {
					$siteKey = $_GET['dzz_sitekey'];
				} else {
					cpmsg($lang['sitekey_warning_tip'], '', 'error');
				}
			
				if($siteKey === false) {
					$siteKeySQL = '';
				} else {
					$siteKeySQL = "('dzz_sitekey', '{$siteKey}'), ";
				}
			
				if($_G['setting']['dzz_siteid'] != $siteId || $siteKeySQL || $_G['setting']['dzz_market_status'] != $_GET['dzz_market_status']) {
					$_GET['dzz_market_status'] = intval(trim($_GET['dzz_market_status']));
					DB::query("REPLACE INTO ".DB::table('common_setting')." (`skey`, `svalue`)
								VALUES ('dzz_siteid', '{$siteId}'), $siteKeySQL ('dzz_market_status', '{$_GET['dzz_market_status']}')");
					updatecache('setting');
				}

			$locationUrl = ADMINSCRIPT.'?action=market&operation=doctor';
			cpmsg($lang['siteid_sitekey_success'], '', 'succeed', array(), '<p class="marginbot"><a href="###" onclick="top.location = \''.$locationUrl.'\'" class="lightlink">'.cplang('message_redirect').'</a></p><script type="text/JavaScript">setTimeout("top.location = \''.$locationUrl.'\'", 3000);</script>');
			dzzfooter();
		}
		require_once DISCUZ_ROOT.'./dzz/dzz_version.php';
		dzz_cpheader();
		dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_doctor]']);
		$sitekey=preg_replace('/(\w{2})\w*(\w{2})/', '\\1****\\2', $_G['setting']['dzz_sitekey']);
		$time_start = microtime_float();
		
		if(check_remote_file_exists($dzzdomain.'dzz.php?mod=api&op=service&do=introduction')){
				$connecttodzz=1;
			}
		$time_end = microtime_float();
		$time = number_format(($time_end - $time_start),3,'.','');
		if(@ini_get('allow_url_fopen')){
			$allow_url_fopen='Yes';
		}else{
			$allow_url_fopen='<font color="red">No</font>';
		}
		include dzztemplate('admin/dzz_market');
		dzzfooter();
	
}elseif($operation=='service'){
	dzz_cpheader();
	dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_service]']);
		$apiarr=array(
				'mod'=>'api',
				'op'=>'service',
				'do'=>'services',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				);
		
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		$data=json_decode($data1,true);
		if($data['message']=='success'){
			 $services=$data['services'];
			foreach($services as $key =>$value){
				$services[$key]['name']=diconv($value['name'],'UTF-8');
			 	$services[$key]['desc']=diconv($value['desc'],'UTF-8');
				$services[$key]['icon']=$dzzdomain.$value['icon'];
			 }
		}else{
			$data['message']=diconv($data['message'],'UTF-8');
			
			cpmsg($data['message'],$refer,'error');
		}
		$gets=array(
				'mod'=>'api',
				'op'=>'buy',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				);
		$url=$dzzdomain."dzz.php?".url_implode($gets);
	include dzztemplate('admin/dzz_market');
	dzzfooter();
}elseif($operation=='freeservice'){
	dzz_cpheader();
	dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_service]']);
		$apiarr=array(
				'mod'=>'api',
				'op'=>'buy',
				'do'=>'free',
				'id'=>intval($_GET['id']),
				'refer'=>$refer,
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid']
				);
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		$data=json_decode($data1,true);
		if($data['message']=='success'){
			cpmsg($lang['do_success'],$refer,'succeed');
		}elseif($data['message']=='notfree'){
			header("location: $api");
		}else{
			$data['message']=diconv($data['message'],'UTF-8');
			cpmsg($data['message'],$refer,'error');
		}
		dzzfooter();
}elseif($operation=='myservice'){
	dzz_cpheader();
	dzz_shownav($lang['menu_dzzmarket'],$lang['menu_dzzmarket_siteinfo]']);
	
	if(submitcheck('syncsubmit')) {
		$apiarr=array(
				'mod'=>'api',
				'op'=>'service',
				'do'=>'sycsiteinfo',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl']."\t".diconv($sysconfig['sitename'],CHARSET,'UTF-8'),'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				);
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		$data1=dzz_file_get_contents($api);
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		$data=json_decode($data1,true);
		if($data['message']=='success'){
			cpmsg($lang['do_success'],$refer,'succeed');
		}else{
			cpmsg($lang['do_failure'],$refer,'error');
		}
		
	}elseif(submitcheck('resetsubmit')) {
		$apiarr=array(
				'mod'=>'api',
				'op'=>'service',
				'do'=>'resetsitekey',
				'key'=>authcode($_G['setting']['dzz_sitekey'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				);
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		$data1=dzz_file_get_contents($api);
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		$data=json_decode($data1,true);
		if($data['message']=='success'){
			$sitekey=authcode($data['sitekey'],'DECODE',$_G['setting']['dzz_sitekey']);
			if($sitekey){
				DB::query("REPLACE INTO ".DB::table('common_setting')." (`skey`, `svalue`)
							VALUES ('dzz_sitekey', '$sitekey'), ('dzz_market_status', '1')");
				updatecache('setting');
			cpmsg($lang['do_success'],$refer,'succeed');
			}else{
				cpmsg($lang['do_failure'],$refer,'error');
			}
		}else{
			cpmsg($lang['do_failure'],$refer,'error');
		}
	}else{
		
	}
	include dzztemplate('admin/dzz_market');
	dzzfooter();
}elseif($operation=='setuping'){
	dzz_cpheader();
	dzz_shownav($lang['menu_dzzmarket'],$lang['install_setuping']);
	if(submitcheck('setupsubmit')) {
		$classname=$_POST['classname'];
		$classid=intval($_POST['classid']);
		$appid=intval($_POST['appid']);
		$appname=trim($_POST['appname']);
		$refer=$_POST['refer'];
		$apiarr=array(
				'mod'=>'api',
				'op'=>'market',
				'do'=>'getappinfo',
				'appid'=>$appid,
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				);
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		set_time_limit(0);
		
			$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg('<p style="font-size:12px;color:red">'.$lang['network_busy'].'&nbsp;&nbsp;&nbsp;<a href="javascript:location.href=\''.$refer.'\'">'.$lang['return'].'</a></p>');
		
		$data=json_decode($data1,true);
		
		if(!$data['message']=='success'){
			$data['message']=diconv($data['message'],'UTF-8');
			cpmsg($data['message'],$refer);
		}
		ob_end_flush();//关闭缓存
		echo str_repeat(" ",256); //ie下 需要先发送256个字节
		flush();
		ob_flush();
		echo str_repeat(" ",$output_buffering); 
		flush();
		ob_flush();
		echo '<p style="font-size:14px;color:black">'.$lang['install_setuping'].':'.$appname.'...</p>';
		flush();
		ob_flush();
		
		
		//处理分类相关
		if(!$classid && $classname){
			if(!$classid=DB::result_first("select classid from ".DB::table('dzz_appclass')." where classname='{$classname}'")){
				$classid=DB::insert('dzz_appclass',array('fupid'=>0,'classname'=>daddslashes($classname)),1);
				if($classid) {
					echo '<p style="font-size:12px;color:green">'.$lang['create_appclass_success'].':'.$classname.'...</p>';
					flush();
					ob_flush();
					sleep(1);
				}else{
					echo '<p style="font-size:12px;color:red">'.$lang['create_appclass_success'].'&nbsp;&nbsp;&nbsp;<a href="javascript:location.href=\''.$refer.'\'">'.$lang['return'].'</a></p>';
					flush();
					ob_flush();
					sleep(1);
				}
			}
		}
		if(!$classid){
			echo '<p style="font-size:12px;color:red">'.$lang['no_appclass'].'&nbsp;&nbsp;&nbsp;<a href="javascript:history.go(-1)">'.$lang['return'].'</a></p>';
			flush();
			ob_flush();
			dexit();
		}
	
		echo '<p style="font-size:12px;">'.$lang['prepareing_appinfo'].'</p>';
		flush();
		ob_flush();
		sleep(1);

		$app=$data['app'];
		if($app){
			$app['appname']=diconv($app['appname'],'UTF-8');
			$app['appdesc']=diconv($app['appdesc'],'UTF-8');
			$app['vendor']=diconv($app['vendor'],'UTF-8');
			$app['appurl']=diconv($app['appurl'],'UTF-8');
			
			if($app['appico']){
				echo '<p style="font-size:12px;">'.$lang['start_setup_appico'].'</p>';
				flush();
				ob_flush();
				sleep(1);
				$source=$dzzdomain.$app['appico'];
				if($appico=imagetolocal($source,'appico')){
					$app['appico']=$appico;
					echo '<p style="font-size:12px;color:green;margin-left:20px;">'.$lang['setup_appico_finish'].'</p>';
					flush();
					ob_flush();
					sleep(1);
				}
			}
			$app['classid']=$classid;
			$app['ismarket']=1;
			$app['dateline']=$_G['timestamp'];
			$myappid=DB::insert('dzz_apps',daddslashes($app),1);
			if(!$myappid) {
				echo '<p style="font-size:12px;color:red;margin-left:20px;">'.$lang['setup_appico_finish'].'&nbsp;&nbsp;&nbsp;<a href="javascript:location.href=\''.$refer.'\'">'.$lang['return'].'</a></p>';
				flush();
				ob_flush();
				dexit();
			}
		}else{
			echo '<p style="font-size:12px;">&nbsp;&nbsp;&nbsp;<a href="javascript:location.href=\''.$refer.'\'">'.$lang['return'].'</a></p>';
			flush();
			ob_flush();
		}
			$pics=$data['pics'];
			if($pics){
				echo '<p style="font-size:12px;">'.$lang['setup_appico_finish'].'</p>';
				flush();
				ob_flush();
				foreach($pics as $key=> $value){
					$link=$dzzdomain.$value;
					if(app_image_add($link,$myappid,$value)){
						echo '<p style="font-size:12px;color:green;margin-left:20px;">'.$lang['picture'].' '.($key+1).' '.$lang['setup_success'].'...</p>';
						flush();
						ob_flush();
					}else{
						echo '<p style="font-size:12px;margin-left:20px;">'.$lang['picture'].' '.($key+1).'  '.$lang['setup_failure'].'...</p>';
						flush();
						ob_flush();
					}
				}
			}
		}
		echo '<p style="font-size:12px;color:green">'.$lang['setup_finish'].'&nbsp;&nbsp;&nbsp;<a href="javascript:location.href=\''.$refer.'\'">'.$lang['return'].'</a></p>';
		flush();
		ob_flush();
		dzzfooter();
		dexit();
}elseif($operation=='allsetuping'){
	dzz_cpheader();
	dzz_shownav($lang['menu_dzzmarket'],$lang['batch_setup'],$lang['install_setuping']);
	if(submitcheck('allsetupsubmit')) {
		$gets=array(
				'action'=>$action,
				'operation'=>$operation,
				'starttime'=>$_POST['starttime'] ? strtotime($_POST['starttime']) : 0,
				'endtime'  => $_POST['endtime'] ? strtotime($_POST['endtime']) : 0,
				'classid'  =>intval($_POST['dzzclassid']),
				'persum'   =>intval($_GET['persum'])>50?50:intval($_GET['persum']),
				'cover'    =>intval($_POST['cover']),
				'classarr' =>base64_encode(serialize($_POST['class'])),
			);
		$url=ADMINSCRIPT.'?'.url_implode($gets);
		header("location: $url");
	}else{
		set_time_limit(0);
		$page = empty($_GET['page'])?1:intval($_GET['page']);
		$gets=array(
				'action'=>$action,
				'operation'=>$operation,
				'starttime'=>intval($_GET['starttime']),
				'endtime'  =>intval($_GET['endtime']),
				'classid'  =>intval($_GET['classid']),
				'persum'   =>intval($_GET['persum']),	
				'cover'    =>intval($_GET['cover']),
				'classarr' =>trim($_GET['classarr']),
				'page'=>$page,
			);
		$classarr=unserialize(base64_decode($gets['classarr']));
		$apiarr=array(
				'mod'=>'api',
				'op'=>'market',
				'do'=>'getapps',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				'starttime'=>$gets['starttime'],
				'endtime'  =>$gets['endtime'] ,
				'classid'  =>$gets['classid'],
				'persum'   =>$gets['persum'],	
				'page'     =>$page
				);
		$api=$dzzdomain.'dzz.php?'.url_implode($apiarr);
		
		$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		
		$data=json_decode($data1,true);
		
		if($data['message']=='success'){
			$applist=$data['applist'];
		}else{
			$data['message']=diconv($data['message'],'UTF-8');
			cpmsg($data['message'],$refer,'error');
		}
		$totalpage=ceil($data['count']/$gets['persum']);
		
		ob_end_flush();//关闭缓存
		echo str_repeat(" ",256); //ie下 需要先发送256个字节
		flush();
		ob_flush();
		
		echo str_repeat(" ",$output_buffering); 
		flush();
		ob_flush();
		echo '<p style="font-size:14px;color:green">'.$lang['install_setuping'].$lang['di'].$page.$lang['page'].' , '.$lang['total'].$totalpage.$lang['page'].'</p>';
		flush();
		ob_flush();
		//处理应用
		$applist=$data['applist'];
		foreach($applist as $value){
			//判断本站是否已有此应用
			$app=dstripslashes($value['app']);
			$pics=$value['pics'];
			$appurl=addslashes(diconv($app['appurl'],'UTF-8'));
			if($myappid=DB::result_first("select appid from ".DB::table('dzz_apps')." where appurl='{$appurl}' and ismarket>0")){
				if($gets['cover']){
					$result=download_app($app,$pics,$classarr,$myappid);
					if(true===$result){
						echo '<p style="font-size:12px;color:green">"'.$app['appname'].'"  '.$lang['setup_success'].'</p>';
						flush();
						ob_flush();
					}else{
						echo '<p style="font-size:12px;color:green">"'.$result.'"</p>';
						flush();
						ob_flush();
						continue;
					}
				}else{
						echo '<p style="font-size:12px;color:green">'.$lang['exist_app_skip'].'</p>';
						flush();
						ob_flush();
						continue;
				}
			}else{
				$result=download_app($app,$pics,$classarr,$myappid);
				if(true===$result){
						echo '<p style="font-size:12px;color:green">"'.$app['appname'].'" '.$lang['setup_success'].'</p>';
						flush();
						ob_flush();
					}else{
						echo '<p style="font-size:12px;color:green">"'.$result.'</p>';
						flush();
						ob_flush();
					}
			}
		}
		if($data['isend']){
			cpmsg($lang['batch_setup_success'],$_G['siteurl'].ADMINSCRIPT."?action=$action&operation=allsetup",'succeed');
		}else{
			$gets['page']+=1;
			$url=ADMINSCRIPT.'?'.url_implode($gets);
			sleep(1);
			echo '<script type="text/javascript">location.href=\''.$url.'\';</script>'."\r\n";
			flush();
			ob_flush();
		}
	}
	dzzfooter();
}elseif($operation=='allsetup'){
		dzz_cpheader();
		dzz_shownav($lang['menu_dzzmarket'],$lang['batch_setup'],$lang['batch_setup_option']);
		$appname=$_GET['appname'];
		$classname=$_GET['classname'];
		$appid=$_GET['appid'];
		//站长市场分类
			$apiarr=array(
				'mod'=>'api',
				'op'=>'market',
				'do'=>'getclassinfo',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
			);
		
		$api = $dzzdomain."dzz.php?".url_implode($apiarr);
		$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		$data=json_decode($data1,true);
		if($data['message']=='success'){
			$dzzclass=$data['appclass'];
			//转码
			if(strtoupper(CHARSET)!='UTF8' && strtoupper(CHARSET)!='UTF-8'){
				foreach($dzzclass as $key =>$value){
					$dzzclass[$key]['classname']=diconv($value['classname'],'UTF-8');
				}
			}
		}else{
			$data['message']=diconv($data['message'],'UTF-8');
			cpmsg($data['message'],$refer,'error');
		}
		$appclass=array();
		$query=DB::query("select * from ".DB::table('dzz_appclass')." where fupid=0  order by disp ");
		while($value=DB::fetch($query)){
			$appclass[$value['classid']]=$value;
		}

		include dzztemplate('admin/dzz_market');
		dzzfooter();
			
}elseif($operation=='setup'){
		dzz_cpheader();
		dzz_shownav($lang['menu_dzzmarket'],$lang['menu_app_class']);
		$appname=$_GET['appname'];
		$classname=$_GET['classname'];
		$appid=$_GET['appid'];
		$appclass=array();
		$query=DB::query("select * from ".DB::table('dzz_appclass')." where 1 order by disp ");
		while($value=DB::fetch($query)){
			$appclass[$value['fupid']][]=$value;
		}
		include dzztemplate('admin/dzz_market');
		dzzfooter();
}else{
		dzz_cpheader();
		dzz_shownav($lang['menu_dzzmarket_market']);
		$page = empty($_GET['page'])?1:intval($_GET['page']);
		$classid=intval($_GET['classid']);
		$subclassid=intval($_GET['subclassid']);
		$type=empty($_GET['type'])?'update':$_GET['type'];
		$perpage = 20;
		$start = ($page-1)*$perpage;
		$gets = array(
				'action'=>'market',
				'type' => $type,
				'classid'=>$classid,
				'subclassid'=>$subclassid,
				'vendor'=>trim($_GET['vendor']),
				'srchtxt'=>trim($_GET['srchtxt'])
			);
		$theurl=ADMINSCRIPT."?".url_implode($gets);
		
		//获取数据
		$apiarr=array(
				'mod'=>'api',
				'op'=>'market',
				'key'=>authcode($sysconfig['siteuniqueid']."\t".$_G['siteurl'],'ENCODE',$_G['setting']['dzz_sitekey']),
				'sid'=>$_G['setting']['dzz_siteid'],
				'type' => $type,
				'page'=>$page,
				'classid'=>$classid,
				'subclassid'=>$subclassid,
				'vendor'=>diconv(trim($_GET['vendor']),CHARSET,'UTF-8'),
				'srchtxt'=>diconv(trim($_GET['srchtxt']),CHARSET,'UTF-8'),
			);
		
		$api = $dzzdomain."dzz.php?".url_implode($apiarr);
		//cpmsg($api);
		
		$data1=dzz_file_get_contents($api);
		
		if(empty($data1)) cpmsg($lang['network_busy'],$refer,'error');
		
		$data=json_decode($data1,true);
		
		if($data['message']!='success'){
			$data['message']=diconv($data['message'],'UTF-8');
			cpmsg($data['message'],$refer,'error');
		}
		$count=0;
		$class=$list=array();
		$class=$data['class'];
		$list=$data['applist'];
		foreach($list as $key=>$value){
			$appurl=daddslashes($value['appurl']);
			$list[$key]['issetup']=DB::result_first("select COUNT(*) from ".DB::table('dzz_apps')." where appurl='{$appurl}'");
		}
		$count=$data['pagenum'];
		$multi = multi($count, $perpage, $page, $theurl);
		
		include dzztemplate('admin/dzz_market');
		dzzfooter();

}

?>