<?php
defined('PP_PATH') or exit;
class promotion_control extends user_control{
	public $_navgroup = 'home';	
	public function index() {
		$this->assign_value('navkey', 'promotion-index');
		$user = &$this->user;
		$where['upid'] = $this->_user['uid'];

		// 初始分页
		$pagenum 		= 20;
		$total 			= $user->find_count($where);
		$maxpage 		= max(1, ceil($total/$pagenum));
		$page 	= min($maxpage, max(1, intval(R('page'))));
		$pages 	= pp_pages($page, $maxpage, 'index.php?u=index-promotion-page-{page}');
		$lists 	= $user->find_fetch($where,array('uid'=>'-1'),($page-1)*$pagenum, $pagenum, $total);

		foreach ($lists as &$v){
			$user->format($v);
			$v['ordernum']	= $this->cms_content_book->find_count(array('uid'=>$v['uid']));
		}

		$this->assign('lists', $lists);
		
		$this->assign('total', $total);
		$this->assign('pages', $pages);
		$this->display('promotion-index.htm');
	}
	public function mylist() {
		$this->assign_value('navkey', 'promotion-mylist');

		// 初始分页
		$where['uid'] = $this->_uid;
		$where['type'] = 4;	
		
		$pagenum = 20;
		$total = $this->record->find_count($where);
		
		$maxpage 	= max(1, ceil($total/$pagenum));
		$page 		= min($maxpage, max(1, intval(R('page'))));
		$pages 		= user_pages($page, $maxpage, 'index.php?u=promotion-mylist-page-{page}');
		$this->assign('total', $total);
		$this->assign('pages', $pages);
		
		$cms_arr = $this->record->list_arr($where, 'id', -1, ($page-1)*$pagenum, $pagenum, $total);
		$this->assign('lists', $cms_arr);
		$this->display('promotion-mylist.htm');
	}
}