Skip to content

Commit e33340b

Browse files
committed
food
1 parent b482dfa commit e33340b

File tree

252 files changed

+43598
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+43598
-5
lines changed

hebtu_food/ShowList.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
require_once 'app/ShowController.class.php';
3+
require ('lib/smarty/Smarty.class.php');
4+
require_once 'app/DBModel.class.php';
5+
require_once 'app/JiSuanModel.class.php';
6+
if($_GET){
7+
$select=$_GET['s'];
8+
$title=$_GET['t'];
9+
10+
}else{
11+
$select="一期食堂一楼";
12+
$title="place1";
13+
14+
}
15+
16+
$sc=new ShowController;
17+
$sc->ShowList($select,$title);

hebtu_food/UploadFood.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
require_once 'app/UploadController.class.php';
3+
require_once 'app/UploadModel.class.php';
4+
require_once 'app/DBModel.class.php';
5+
$UploadControll=new UploadController;
6+
$UploadControll->upfood();

hebtu_food/app/DBModel.class.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
class DBModel{
3+
4+
var $conn;
5+
6+
public function conn(){
7+
$this->conn = mysql_connect('qdm117251480.my3w.com','qdm117251480','051347wxd');
8+
if(!$this->conn){
9+
echo "数据库链接失败";
10+
exit;
11+
}
12+
mysql_select_db('qdm117251480_db');
13+
mysql_query("set names 'utf8'");
14+
return $this->conn;
15+
}
16+
public function DElconn()
17+
{
18+
mysql_close($this->conn);
19+
}
20+
public function SaveFood($name,$price,$time,$pic1,$pic2,$pic3,$pic4,$list1,$list2,$place1){
21+
22+
$sqlR="insert `food_list`(`name`,`price`,`open_time`,`pic1`,`pic2`,`pic3`,`pic4`,`list1`,`list2`,`place1`) values('$name ','$price','$time','$pic1','$pic2','$pic3','$pic4','$list1','$list2','$place1')";
23+
mysql_query($sqlR);
24+
$uid = mysql_insert_id();
25+
return $uid;
26+
27+
28+
}
29+
public function SaveComment($pid,$name,$comment,$time,$score){
30+
31+
$sqlR="insert `food_comment`(`pid`,`name`,`comment`,`waitTime`,`star`) values('$pid','$name','$comment','$time','$score')";
32+
mysql_query($sqlR);
33+
return $pid;
34+
35+
36+
}
37+
38+
public function LoadFood($id){
39+
$sqlR="SELECT * FROM `food_list` WHERE id = ".$id."";
40+
$request=mysql_query($sqlR);
41+
$foodobj=mysql_fetch_object($request);
42+
return $foodobj;
43+
}
44+
public function LoadComment($pid){
45+
$sqlR="SELECT * FROM `food_comment` WHERE pid = ".$pid."";
46+
$request=mysql_query($sqlR);
47+
return $request;
48+
}
49+
public function LoadSelect($select,$title)
50+
{
51+
$sqlR="SELECT * FROM `food_list` WHERE ".$title." = '".$select."'";
52+
$request=mysql_query($sqlR);
53+
return $request;
54+
}
55+
56+
}
57+

hebtu_food/app/JiSuanModel.class.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
class JiSuanModel{
3+
4+
public function star($id)
5+
6+
{
7+
$DB=new DBModel;
8+
$DB->conn();
9+
$sum=0;
10+
$i=0;
11+
$Comment_R=$DB->LoadComment($id);
12+
$DB->DElconn();
13+
if($Comment_R){
14+
while($row = mysql_fetch_array($Comment_R,MYSQL_ASSOC)){
15+
$sum+=$row['star'];
16+
$i+=1;
17+
}
18+
return $sum/$i ;
19+
}else return '';
20+
21+
}
22+
23+
public function waittime($id)
24+
{
25+
$DB=new DBModel;
26+
$DB->conn();
27+
$sum=0;
28+
$i=0;
29+
$Comment_R=$DB->LoadComment($id);
30+
$DB->DElconn();
31+
if($Comment_R){
32+
while($row = mysql_fetch_array($Comment_R,MYSQL_ASSOC)){
33+
$sum+=$row['waitTime'];
34+
$i+=1;
35+
}
36+
return $sum/$i ;
37+
}else return '';
38+
}
39+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
4+
class ShowController{
5+
public function init(){
6+
$smarty = new Smarty();
7+
$smarty->left_delimiter = "{";
8+
$smarty->right_delimiter = "}";
9+
$smarty->template_dir = "tpl";
10+
$smarty->compile_dir = "template_c";
11+
$smarty->cache_dir = "cache";
12+
return $smarty;
13+
}
14+
15+
16+
public function showFood($id){
17+
//实例化并链接数据库
18+
$DB=new DBModel;
19+
$DB->conn();
20+
//实例化计算模型
21+
$j= new JiSuanModel;
22+
//实例化smarty,并初始化。
23+
$smarty=$this->init();
24+
//取数据
25+
$FoodObj=$DB->LoadFood($id);
26+
$Comment_R=$DB->LoadComment($id);
27+
$star=$j->star($id)?$j->star($id):3;
28+
$waittime=$j->waittime($id);
29+
// 循环遍历,取到数组中。
30+
while($row = mysql_fetch_array($Comment_R,MYSQL_ASSOC)){
31+
$comment[]= $row;
32+
}
33+
$smarty->assign('star',$star);
34+
$smarty->assign('waittime',$waittime);
35+
36+
$smarty->assign('comment',$comment);
37+
$smarty->assign('FoodObj',$FoodObj);
38+
$DB->DElconn();
39+
$smarty->display('food.html');
40+
41+
42+
}
43+
public function ShowList($select,$title)
44+
{
45+
$DB=new DBModel;
46+
// $j= new JiSuanModel;
47+
$DB->conn();
48+
$smarty=$this->init();
49+
50+
$FoodList=$DB->LoadSelect($select,$title);
51+
while($row = mysql_fetch_array($FoodList,MYSQL_ASSOC)){
52+
$Food[]= $row;
53+
// $isw_r[]=$row['id'];
54+
// $isw_r[]=$j->star($row['id']);
55+
// $isw_r[]=$j->waittime($row['id']);
56+
// $isw[]=$isw_r;
57+
}
58+
if(empty($Food)){
59+
$Food="";
60+
}
61+
$smarty->assign('Food',$Food);
62+
$DB->DElconn();
63+
$smarty->display('FoodList.html');
64+
}
65+
public function ShowIndex()
66+
{
67+
# code...
68+
$smarty=$this->init();
69+
$list=array('第一餐厅','第二餐厅','第三餐厅','第四餐厅','第五餐厅','清真餐厅');
70+
$smarty->assign('list',$list);
71+
$smarty->display('index.html');
72+
}
73+
}

hebtu_food/app/UploadComment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$UploadControll=new UploadController;
3+
$UploadControll->upcomment();
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
error_reporting(E_ALL & ~E_DEPRECATED);
3+
header("Content-type:text/html;charset=utf-8");
4+
class UploadController{
5+
6+
public function upfood()
7+
{
8+
$UP=new UploadModel;
9+
$DB=new DBModel;
10+
$DB->conn();
11+
if($_POST){
12+
13+
$name=$UP->SEC($_POST['name']);
14+
$price=$UP->SEC($_POST['price']);
15+
$opentime=$UP->SEC($_POST['opentime']);
16+
$place1=$UP->SEC($_POST['place']);
17+
$list1=$UP->SEC($_POST['list1']);
18+
$list2=$UP->SEC($_POST['list2']);
19+
20+
21+
if(!empty($_FILES['pic1']['tmp_name'])) $pic1=$UP->Img($_FILES['pic1']);
22+
else $pic1='';
23+
24+
if(!empty($_FILES['pic2']['tmp_name'])) $pic2=$UP->Img($_FILES['pic2']);
25+
else $pic2='';
26+
27+
if(!empty($_FILES['pic3']['tmp_name'])) $pic3=$UP->Img($_FILES['pic3']);
28+
else $pic3='';
29+
30+
if(!empty($_FILES['pic4']['tmp_name'])) $pic4=$UP->Img($_FILES['pic4']);
31+
else $pic4='';
32+
33+
34+
$foodUid=$DB->SaveFood($name,$price,$opentime,$pic1,$pic2,$pic3,$pic4,$list1,$list2,$place1);
35+
$DB->DElconn();
36+
echo "<script> var r=confirm(\"提交成功!<\br>是否继续添加?\");if (r==true){window.location.href=\"../tpl/foodupload.html\";}else{window.location.href=\"showfood.php?p=".$foodUid."\";};</script>";
37+
38+
}
39+
else{
40+
echo "啥都没有!";
41+
}
42+
}
43+
public function upcomment(){
44+
$UP=new UploadModel;
45+
$DB=new DBModel;
46+
$DB->conn();
47+
if($_POST){
48+
$pid=$UP->SEC($_POST['pid']);
49+
$name=$UP->SEC($_POST['name']);
50+
$comment=$UP->SEC($_POST['comment']);
51+
$waittime=$UP->SEC($_POST['waittime']);
52+
$score=$UP->SEC($_POST['score']);
53+
54+
$DB->SaveComment($pid,$name,$comment,$waittime,$score);
55+
$DB->DElconn();
56+
echo "<script>alert('successful');window.location.href='showfood.php?p=".$pid."';</script>";
57+
58+
// echo $pid.'<br>'.$name.'<br>'.$comment.'<br>'.$waittime.'<br>'.$score;
59+
60+
}
61+
else{
62+
$DB->DElconn();
63+
echo "<h1 align=\"center\">好像我把你的评论弄丢了。<br/>可不可以帮我再写一份<br/>委屈状。</h1>";
64+
}
65+
}
66+
}
67+
68+

hebtu_food/app/UploadModel.class.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
class UploadModel{
3+
4+
public function Img($fileInfo,$uploadPath = '../upload/img',$flag=true,$allowExt=array('jpeg','jpg','gif','png'),$maxSize = 2097152){
5+
// 判断错误号
6+
if ($fileInfo ['error'] > 0) {
7+
switch ($fileInfo ['error']) {
8+
case 1 :
9+
$mes = '上传文件超过了PHP配置文件中upload_max_filesize选项的值';
10+
break;
11+
case 2 :
12+
$mes = '超过了表单MAX_FILE_SIZE限制的大小';
13+
break;
14+
case 3 :
15+
$mes = '文件部分被上传';
16+
break;
17+
case 4 :
18+
$mes = '没有选择上传文件';
19+
break;
20+
case 6 :
21+
$mes = '没有找到临时目录';
22+
break;
23+
case 7 :
24+
case 8 :
25+
$mes = '系统错误';
26+
break;
27+
}
28+
echo ( $mes );
29+
return false;
30+
}
31+
$ext = pathinfo ( $fileInfo ['name'], PATHINFO_EXTENSION );
32+
// $allowExt = array (
33+
// 'jpeg',
34+
// 'jpg',
35+
// 'png',
36+
// 'gif'
37+
// );
38+
if(!is_array($allowExt)){
39+
exit('系统错误');
40+
}
41+
// 检测上传文件的类型
42+
if (! in_array ( $ext, $allowExt )) {
43+
exit ( '非法文件类型' );
44+
}
45+
//$maxSize = 2097152; // 2M
46+
// 检测上传文件大小是否符合规范
47+
if ($fileInfo ['size'] > $maxSize) {
48+
exit ( '上传文件过大' );
49+
}
50+
//检测图片是否为真实的图片类型
51+
//$flag=true;
52+
if($flag){
53+
if(!getimagesize($fileInfo['tmp_name'])){
54+
exit('不是真实图片类型');
55+
}
56+
}
57+
// 检测文件是否是通过HTTP POST方式上传上来
58+
if (! is_uploaded_file ( $fileInfo ['tmp_name'] )) {
59+
exit ( '文件不是通过HTTP POST方式上传上来的' );
60+
}
61+
//$uploadPath = 'uploads';
62+
if (! file_exists ( $uploadPath )) {
63+
mkdir ( $uploadPath, 0777, true );
64+
chmod ( $uploadPath, 0777 );
65+
}
66+
$uniName = md5 ( uniqid ( microtime ( true ), true ) ) . '.' . $ext;
67+
$destination = $uploadPath . '/' . $uniName;
68+
if (! @move_uploaded_file ( $fileInfo ['tmp_name'], $destination )) {
69+
exit ( '文件移动失败' );
70+
}
71+
72+
//echo '文件上传成功';
73+
// return array(
74+
// 'newName'=>$destination,
75+
// 'size'=>$fileInfo['size'],
76+
// 'type'=>$fileInfo['type']
77+
// );
78+
// echo "http://rb.5am3.com/".$destination;
79+
return '/' . $uniName;
80+
}
81+
82+
public function SEC($data){
83+
$data=trim($data);#去除首尾多余的空白符
84+
$data=stripcslashes($data);#去除用户输入的反斜杠
85+
$data=htmlspecialchars($data);#转化为html实体
86+
return $data;
87+
88+
}
89+
90+
91+
}

hebtu_food/app/_notes/dwsync.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<dwsync>
3+
<file name="UploadController.class.php" server="qxu2148080193.my3w.com//htdocs/" local="131385968758865600" remote="131385708600000000" Dst="0" />
4+
<file name="UploadModel.class.php" server="qxu2148080193.my3w.com//htdocs/" local="131385671436139952" remote="131385383400000000" Dst="0" />
5+
<file name="DBModel.class.php" server="qxu2148080193.my3w.com//htdocs/" local="131385835579369451" remote="131385547200000000" Dst="0" />
6+
<file name="ShowController.class.php" server="qxu2148080193.my3w.com//htdocs/" local="131385919123532553" remote="131385648000000000" Dst="0" />
7+
<file name="UploadComment.php" server="qxu2148080193.my3w.com//htdocs/" local="131385704328189673" remote="131385416400000000" Dst="0" />
8+
<file name="JiSuanModel.class.php" server="qxu2148080193.my3w.com//htdocs/" local="131385873315921929" remote="131385587400000000" Dst="0" />
9+
</dwsync>

0 commit comments

Comments
 (0)