<?php
/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: market_ajax.php 1000 2011-6-31 15:41:43 by angelrain $
 */
 /**
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
*/
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
$refer=dreferer();	
$do = empty($_GET['do'])?'':$_GET['do'];

if($do=='score'){
	$id=intval($_GET['id']);
	$star=intval($_GET['star']);
	$idtype=trim($_GET['idtype']);
	if($_G['uid']){
		$scorearr=array(
				'id'=>$id,
				'star'=>$star,
				'idtype'=>$idtype,
				'uid'=>$_G['uid'],
				'username'=>$_G['username'],
				'dateline'=>$_G['timestamp']						
				);
		$arr=array();	
		if($arr=DB::fetch_first("SELECT pid FROM ".DB::table('dzz_score')." where uid='{$_G[uid]}' and idtype='{$idtype}' and  id='{$id}' ")){
				DB::update('dzz_score',daddslashes($scorearr),"pid='{$arr[pid]}'");
		}else{
			DB::insert('dzz_score',daddslashes($scorearr));
		}
		updatescore($scorearr['id'],$idtype);
	}
	include template('common/header_ajax');
	
	include template('common/footer_ajax');
	dexit();
}else{
	$id=intval($_GET['id']);
	$oid=intval($_GET['oid']);
	$type=trim($_GET['type']);
	if(!$id && (!$oid || !$type)) showmessage(dzzlang('system/message','error_canshu'));
	
	//获取ico信息
	if($id && !$icoarr=DB::fetch_first("select * from ".DB::table('dzz_icos')." where icoid='{$id}'")){
		showmessage(dzzlang('system/message','id_not_exist'));
	}
	if(!$icoarr){
		$icoarr=array('type'=>$type,'oid'=>$oid);
	}
	$type=$icoarr['type'];
	switch($type){
		case 'app':
			$appid=intval($icoarr['oid']);
			$appclass=array();
			$query=DB::query("select * from ".DB::table('dzz_appclass')." where 1");
			while($value=DB::fetch($query)){
				$appclass[$value['classid']]=$value;
			}
			//获取应用信息
			$app=array();
			$app=DB::fetch_first("select * from ".DB::table('dzz_apps')." where appid='{$appid}'");
			if(!$app) showmessage(dzzlang('system/message','app_not_exist'));
			if($app['appico']!='dzz/images/default/icodefault.png' && !preg_match("/^(http|ftp|https|mms)\:\/\/(.+?)/i", $app['appico'])){
				$app['appico']=$_G['setting']['attachurl'].$app['appico'];
			}
			$app['dateline']=dgmdate($app['dateline']);
			$app['appurl']=addslashes($app['appurl']);
			$app['classname']=$appclass[$app['classid']]['classname'];
			$app['scorestyle']=$app['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$appid}' and idtype='appid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			//应用截图
			$images=array();
			$imageids=array();
			$wheresql = "id='{$app[appid]}'";
			//showmessage("SELECT * FROM ".DB::table('dzz_pic')." where id='{$app[appid]}' and `checked`>0 ORDER BY viewnum DESC ");
			$query=DB::query("SELECT * FROM ".DB::table('dzz_pic')." where $wheresql ORDER BY viewnum DESC " );
					while($value=DB::fetch($query)){
						$value['pic']=pic_get($value['filepath'], '', $value['thumb'], $value['remote'], 1,1);
						$value['filepath']=pic_get($value['filepath'], '', $value['thumb'], $value['remote'], 0,1);
						$images[]=$value;
						$imageids[]=$value['picid'];
						
					}
			 $imagesum=count($images);
			 $navtitle=$app['appname'];
			 $metakeywords=array($app['appname'],$app['classname']);
			 if($app['vonder']) $metakeywords[]=$app['vonder'];
			 $metakeywords=implode(',',$metakeywords);
			 $metadescription=$app['appdesc'];
			break;
		case 'link':
			$data=array();
			if(!$data=DB::fetch_first("select * from ".DB::table('dzz_link')." where lid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','link_not_exist'));
			}
			$data['scorestyle']=$data['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$icoarr[oid]}' and idtype='lid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			$data['dateline']=dgmdate($data['dateline']);
			$navtitle=$data['title'];
			$metakeywords=implode(',',array($data['title'],$data['username']));
			$metadescription=$data['desc'];
			break;
		case 'image':
			$data=array();
			if(!$data=DB::fetch_first("select * from ".DB::table('dzz_image')." where picid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','image_not_exist'));
			}
			$data['img']=$data['thumb']?getimgthumbname($_G['setting']['attachurl'].$data['filepath']):$_G['setting']['attachurl'].$data['filepath'];
			$data['oimg']=$_G['setting']['attachurl'].$data['filepath'];
			$data['scorestyle']=$data['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$icoarr[oid]}' and idtype='picid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			$data['dateline']=dgmdate($data['dateline']);
			$navtitle=$data['title'];
			$metakeywords=implode(',',array($data['filename'],$data['title'],$data['username']));
			$metadescription=$data['title'];
			break;
		case 'video':
			$data=array();
			if(!$data=DB::fetch_first("select * from ".DB::table('dzz_video')." where vid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','video_not_exist'));
			}
			$data['scorestyle']=$data['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$icoarr[oid]}' and idtype='vid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			$data['dateline']=dgmdate($data['dateline']);
			$navtitle=$data['title'];
			$metakeywords=implode(',',array($data['title'],$data['username']));
			$metadescription=$data['desc'];
			break;
		case 'music':
			$data=array();
			if(!$data=DB::fetch_first("select * from ".DB::table('dzz_music')." where mid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','music_not_exist'));
			}
			$data['scorestyle']=$data['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$icoarr[oid]}' and idtype='mid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			$data['dateline']=dgmdate($data['dateline']);
			$navtitle=$data['title'];
			$metakeywords=implode(',',array($data['title'],$data['username']));
			$metadescription=$data['desc'];
			break;
		case 'attach':
			$data=array();
			if(!$data=DB::fetch_first("select * from ".DB::table('dzz_attach')." where qid='{$icoarr[oid]}'")){
				showmessage(dzzlang('system/message','music_not_exist'));
			}
			$data['filesize']=formatsize($data['filesize']);
			$data['scorestyle']=$data['star']*10;
			if(!$pingjia=DB::fetch_first("SELECT * FROM ".DB::table('dzz_score')." where id='{$icoarr[oid]}' and idtype='qid'  and uid='{$_G[uid]}'  LIMIT 1" )){
				$pingjia=array('star'=>0);	
			}
			
			$data['dateline']=dgmdate($data['dateline']);
			$navtitle=$data['filename'];
			$metakeywords=implode(',',array($data['filename'],$data['username']));
			$metadescription=$data['desc'];
			break;
		
	}
	include dzztemplate('system/system_detail');
}
?>