Skip to content

Commit 591591f

Browse files
committed
first commit
0 parents  commit 591591f

26 files changed

+31936
-0
lines changed

config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
define('DB_STR', "mongodb://127.0.0.1:27017");
4+
define('DB_NAME', 'sjm');
5+
6+
define('APP_CHARSET', 'UTF-8');
7+
define('APP_VERSION', '1.0');
8+
define('APP_RELEASE', '20140322');
9+
10+

control/controlbase.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
!defined('IN_APP') && exit('Access Denied');
4+
5+
class controlbase {
6+
7+
public $ip;
8+
public $time;
9+
public $db;//mongodb
10+
public $cache;
11+
public $user = array();
12+
public $setting = array();
13+
protected $get = array();
14+
protected $post = array();
15+
protected $safepost = array('1'=>'分钟','60'=>'小时','1440'=>'');
16+
17+
function __construct( $get, $post) {
18+
$this->time = time();
19+
$this->ip = getip();
20+
$this->get = $get;
21+
$this->post = $post;
22+
$this->init_db();
23+
$this->init_cache();
24+
$this->init_user();
25+
}
26+
27+
/*
28+
$eventlist=$this('event')->findAll();
29+
本特性只在PHP 5.3.0 及以上版本有效。
30+
*/
31+
function __invoke($modelname, $base = NULL) {
32+
$base = $base ? $base : $this;
33+
if (empty($_ENV[$modelname])) {
34+
$modelfile= APP_ROOT.'/model/'.$modelname.'.class.php';
35+
//动态创建model类,一般的通用model无需再创建。
36+
if(false===@include($modelfile)) {
37+
// echo $modelname;
38+
eval('class '.$modelname.'model extends modelbase{}');
39+
}
40+
eval('$_ENV[$modelname] = new ' . $modelname . 'model($base);');
41+
}
42+
return $_ENV[$modelname];
43+
}
44+
45+
function init_db() {
46+
//$m= new Mongo('mongodb://'.DB_USER.':'.DB_PW.'@'.DB_HOST.':'.DB_PORT.'/'.DB_NAME);
47+
//$m= new Mongo('mongodb://'.DB_HOST.':'.DB_PORT.'/'.DB_NAME);
48+
//启用replicaSet,高可用数据,任意一台关机无所谓。
49+
// $m = new Mongo("mongodb://10.0.1.227:27017,10.0.1.167:27018,10.0.1.227:27019,10.0.1.167:27020", array("replicaSet" => "mySet"));
50+
try {
51+
$m = new Mongo(DB_STR);
52+
$this->db = $m->selectDB(DB_NAME);
53+
} catch(MongoConnectionException $e) {
54+
exit("服务器忙,请稍后重试!");
55+
}
56+
//$db->authenticate($username, $password);
57+
//$this->db =$m->mydata;//选择mydata数据库 ,这种写法也行。
58+
}
59+
60+
61+
62+
/* 一旦setting的缓存文件读取失败,则更新所有cache */
63+
64+
function init_cache() {
65+
global $setting;
66+
$this->cache = new cache($this->db);
67+
$setting = $this->setting = $this->cache->load('setting');
68+
//$this->usergroup = $this->cache->load('usergroup', 'id');
69+
}
70+
71+
function init_user() {
72+
@$auth = tcookie('auth');
73+
$user = array('uid'=>0);
74+
@list($uid, $password) = empty($auth) ? array(0, 0) : taddslashes(explode("\t", strcode($auth, $this->setting['auth_key'], 'DECODE')), 1);
75+
if ($uid && $password) {
76+
$finduser = $this('user')->findById(intval($uid));
77+
($password == $finduser['password']) && $user = $finduser;
78+
}
79+
$user['ip'] = $this->ip;
80+
$this->user = $user;
81+
}
82+
83+
/* 权限检测 */
84+
function checkable($regular) {
85+
return 1;
86+
$regulars = explode(',', 'user/login,user/logout,user/code,user/getpass,user/resetpass,index/help,js/view,' . $this->user['regulars']);
87+
return in_array($regular, $regulars);
88+
}
89+
90+
91+
/*中转提示页面
92+
$ishtml=1 表示是跳转到静态网页
93+
*/
94+
function message($message, $url = '') {
95+
$seotitle = '操作提示';
96+
if ('' == $url) {
97+
$redirect = SITE_URL;
98+
} else if ('BACK' == $url) {
99+
$redirect = $url;
100+
} else {
101+
$redirect = SITE_URL . $this->setting['seo_prefix'] . $url;
102+
}
103+
$tpldir = (0 === strpos($this->get['c'], 'admin')) ? 'admin' : $this->setting['tpl_dir'];
104+
include template('tip', $tpldir);
105+
exit;
106+
}
107+
108+
109+
/*提示跳转专用*/
110+
/* function theader($key='succeed',$value=1){
111+
header('location:?c='.$this->get['c'].'&a='.$this->get['a'].'&'.$key.'='.$value);
112+
exit;
113+
}
114+
*/
115+
116+
/* 检查验证码 */
117+
function checkcode() {
118+
if (strtolower(trim($this->post['code'])) != $_SESSION['code']) {
119+
$this->message("验证码错误!", 'BACK');
120+
}
121+
}
122+
123+
124+
125+
126+
}

control/exam.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
!defined('IN_APP') && exit('Access Denied');
4+
5+
class examcontrol extends controlbase {
6+
7+
/*显示测试题*/
8+
function ondefault() {
9+
$title='史上最难PHPer笔试题';
10+
include template('exam');
11+
}
12+
13+
//提交考卷
14+
function oncommit() {
15+
16+
if(!isset($this->post['truename'])){
17+
exit('<h1>哥们,等不及可以先加入QQ群:124421692 和PHP高手一起讨论。</h1>');
18+
}
19+
20+
//$this->post['truename']=htmlentities($this->post['truename']);
21+
$this->post['phone']=trim($this->post['phone']);
22+
$this->post['ip']=$this->ip;
23+
$this->post['dateline']=date("Y-m-d H:m:s");
24+
25+
$examid=$this('exam')->add($this->post);
26+
echo $examid;
27+
//$jsonstr=json_encode($this->post)."\n";
28+
29+
//file_put_contents('usersdata.php', $jsonstr, FILE_APPEND);
30+
}
31+
32+
33+
//查看考卷列表
34+
function onlist() {
35+
if(!isset($this->get['pass'])){
36+
exit('<h1>Error!</h1>');
37+
}
38+
$examlist=$this('exam')->findAll();
39+
//$isAndroid = (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Android') );
40+
41+
include template('examlist');
42+
}
43+
44+
//手机端获取用户列表,然后发送短信。
45+
function ongetscore(){
46+
$items = $this('exam')->findAndUpSms();
47+
echo json_encode($items);
48+
}
49+
50+
//设置短信发送状态
51+
function onupsms(){
52+
$id= intval($this->get['id']);
53+
$sendsms= intval($this->get['sendsms']);
54+
$findexam=$this('exam')->updateById($id,array( 'sendsms'=> $sendsms ));
55+
header('location:?c=exam&a=list&pass');
56+
}
57+
58+
//设置邮件发送状态
59+
function onupmail(){
60+
$id= intval($this->get['id']);
61+
$sendmail= intval($this->get['sendmail']);
62+
$findexam=$this('exam')->updateById($id,array( 'sendmail'=> $sendmail ));
63+
header('location:?c=exam&a=list&pass');
64+
}
65+
66+
//删除指定记录
67+
function onremove(){
68+
$id= intval($this->get['id']);
69+
$findexam=$this('exam')->removeById($id);
70+
header('location:?c=exam&a=list&pass');
71+
}
72+
73+
}

control/index.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
!defined('IN_APP') && exit('Access Denied');
3+
define('DAY', 86400);
4+
5+
class indexcontrol extends controlbase {
6+
7+
function ondefault() {
8+
/* $query=array('endtime'=>array('$gte'=>$this->time) );
9+
$myMemList = $this('mem')->findIdNames($this->user['uid'],2);
10+
11+
$newsList=$this('news')->find(array(),0,8);
12+
13+
14+
$onlineMemList = $this('mem')->findAll(array('isonline'=>1));
15+
$msgList = $this('message')->find(array(),0,13);
16+
17+
18+
$friendLinks=$this('friendlink')->findAll();*/
19+
$title='';
20+
$problems = $this('blog')->findProblems();
21+
include template('index');
22+
}
23+
24+
function onindex() {
25+
$this->ondefault();
26+
}
27+
28+
function oncourse() {
29+
$title='培训课程_';
30+
include template('course');
31+
}
32+
33+
function onteacher() {
34+
$title='专家讲师_';
35+
include template('teacher');
36+
}
37+
38+
function ongoal() {
39+
$title='就业目标_';
40+
include template('goal');
41+
}
42+
43+
44+
function onapply() {
45+
$title='报名须知_';
46+
include template('apply');
47+
}
48+
49+
function oncontact() {
50+
$title='联系我们_';
51+
include template('contact');
52+
}
53+
54+
/*function oneveryday() {
55+
$title='每日一题';
56+
include template('everyday');
57+
}*/
58+
59+
60+
61+
62+
63+
64+
}

favicon.ico

7.19 KB
Binary file not shown.

index.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/*the app entrance */
3+
//ini_set('display_errors', 'on');
4+
error_reporting(7);
5+
date_default_timezone_set('PRC');
6+
//session_start();
7+
#set_magic_quotes_runtime(0);
8+
$mtime = explode(' ', microtime());
9+
$starttime = $mtime[1] + $mtime[0];
10+
define('IN_APP', TRUE);
11+
define('APP_ROOT', dirname(__FILE__));
12+
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
13+
define('SITE_URL','http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,-10) );
14+
15+
require APP_ROOT.'/config.php';
16+
require APP_ROOT.'/lib/global.func.php';
17+
require APP_ROOT.'/lib/cache.class.php';
18+
require APP_ROOT.'/control/controlbase.php';
19+
require APP_ROOT.'/model/modelbase.class.php';
20+
21+
header('Content-type: text/html; charset=UTF-8');
22+
23+
/*$get=taddslashes($_GET);
24+
$post=taddslashes($_POST);
25+
*/
26+
$get=$_GET;
27+
$post=$_POST;
28+
unset($GLOBALS, $_ENV, $_GET, $_POST);
29+
30+
empty($get['c']) && $get['c']='index';
31+
empty($get['a']) && $get['a']='default';
32+
define('ACTION', $get['a']);
33+
define('REGULAR', $get['c'].'/'.$get['a']);
34+
//load control...
35+
$controlfile=APP_ROOT.'/control/'.$get['c'].'.php';
36+
37+
38+
if(false===@include($controlfile)) {
39+
notfound('control file "'.$controlfile.'" not found!');
40+
}
41+
42+
$controlname=$get['c'].'control';
43+
$control = new $controlname($get,$post);
44+
$method=strtolower('on'.$get['a']);
45+
if(method_exists($control, $method)) {
46+
$isajax=(0===strpos($get['a'],'ajax'));
47+
if($control->checkable(REGULAR) || $isajax) {
48+
$control->$method();
49+
}else {
50+
$querystring=strcode($_SERVER["QUERY_STRING"], '', 'ENCODE');
51+
tcookie('querystring', $querystring, 86400);
52+
$control->message('您无权进行当前操作,原因如下:<br/> 您所在的用户组('.$control->user['title'].')无法进行此操作。','c=user&a=login');
53+
}
54+
}else {
55+
notfound('control "'.$controlname.'" method "'.$method.'" not found!');
56+
}
57+
58+
59+

0 commit comments

Comments
 (0)