<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
$menumark = 'lesson_list';
switch ($act) {
	//#####################@ 课程增加 @#####################//
	case 'add':
		pe_lead('hook/category.hook.php');
		$category_treelist = category_treelist();

		$seo = pe_seo('发布课程', '', '', 'admin');
		$action = 'admin.php?mod=lesson&act=addsql';
		include(pe_tpl('lesson_add.html'));
	break;
	//#####################@ 课程增加sql @#####################//
	case 'addsql':
		$_p_info['lesson_atime'] = $_p_info['lesson_atime'] ? strtotime($_p_info['lesson_atime']) : time();
		$_p_info['lesson_down'] = strtr($_p_info['lesson_down'], '；', ';');	
		if ($db->pe_insert('lesson', pe_dbhold($_p_info, array('lesson_text')))) {
			pe_success('课程发布成功!', 'admin.php?mod=lesson&act=list');
		}
		else {
			pe_error('课程发布失败...');
		}
	break;
	//#####################@ 课程修改 @#####################//
	case 'edit':
		pe_lead('hook/category.hook.php');
		$category_treelist = category_treelist();

		$info = $db->pe_select('lesson', array('lesson_id'=>$_g_id));

		$seo = pe_seo('修改课程', '', '', 'admin');
		$action = "admin.php?mod=lesson&act=editsql&id={$_g_id}";
		include(pe_tpl('lesson_add.html'));
	break;
	//#####################@ 课程修改sql @#####################//
	case 'editsql':
		if(empty($_p_info['elite']))$_p_info['elite']=0;
		$_p_info['lesson_atime'] = $_p_info['lesson_atime'] ? strtotime($_p_info['lesson_atime']) : time();
		$_p_info['lesson_down'] = strtr($_p_info['lesson_down'], array('；'=>';'));	
		if ($db->pe_update('lesson', array('lesson_id'=>$_g_id), pe_dbhold($_p_info, array('lesson_text')))) {
			pe_success('课程修改成功!', 'admin.php?mod=lesson&act=list');
		}
		else {
			pe_error('课程修改失败...');
		}
	break;
	//#####################@ 课程删除sql @#####################//
	case 'delsql':
		if ($db->pe_delete('lesson', array('lesson_id'=>is_array($_p_lesson_id) ? $_p_lesson_id : $_g_id))) {
			pe_success('课程删除成功!');
		}
		else {
			pe_error('课程删除失败...');
		}
	break;
	//#####################@ 课程置顶sql @#####################//
	case 'statesql':
		if ($db->pe_update('lesson', array('lesson_id'=>is_array($_p_lesson_id) ? $_p_lesson_id : $_g_id), array('lesson_state'=>intval($_g_state)))) {
			pe_success('课程状态更改成功!');
		}
		else {
			pe_error('课程状态更改失败...');
		}
	break;
	//#####################@ 课程列表sql @#####################//
	default :
		$cache_category = cache::get('category');

		//课程分类
		include("{$pe['path_root']}hook/category.hook.php");
		$category_treelist = category_treelist();

		$_g_keyword && $sqlwhere .= " and `lesson_name` like '%{$_g_keyword}%'";
		$_g_category_id && $sqlwhere .= " and `category_id` = '{$_g_category_id}'"; 
		$sqlwhere .= " order by `lesson_id` desc";
		$info_list = $db->pe_selectall('lesson', $sqlwhere, '*', array(20, $_g_page));

		$seo = pe_seo('课程列表', '', '', 'admin');
		include(pe_tpl('lesson_list.html'));
	break;
}
pe_result();
?>