标签:des style blog color java os io 数据
1、ContributeController.class.php 控制器
<?php /** * Created by PhpStorm. * User: lxd * Date: 14-7-27 * Time: 下午2:43 */ namespace Home\Controller; class ContributeController extends SyController{ /**@author lxd * @description 首页 */ public function index(){ $this->display(); } /** * @description 添加/响应 捐书订单 */ public function addBill(){ if(!IS_GET){ //判断是否已经通过GET变量提交数据 $this->error("提交方式错误!"); return; } if(!validateLogin()){ //判断是否已经登录 $this->error("请先登录"); redirect("/login"); } if($_GET[‘id‘]){ $this->finish = true; $this->bar_code = session("user")[‘id‘]; } $this->display(); } /** * @description 提交献书表单 */ public function finish(){ if(!IS_POST){ $this->error("提交方式错误!"); return; } //1登录验证 Util if(!validateLogin()){ $this->error("请先登录"); redirect("/login"); } //验证数据。9787115240019 9787111075752 9787302254546 $bookDB=D("Book"); $insert = array(); $count = count($_POST[‘name‘]); for($i = 0 ; $i < $count ;$i++ ){ $data[‘name‘] = $_POST[‘name‘][$i]; $data[‘bar_code‘] = $_POST[‘bar_code‘][$i]; $data[‘author‘] = $_POST[‘author‘][$i]; $data[‘translator‘] = $_POST[‘translator‘][$i]; $data[‘publish‘] = $_POST[‘publish‘][$i]; $arr = explode(‘-‘,$_POST[‘publish_time‘][$i]); $time = mktime(0,0,0,$arr[1],$arr[2],$arr[0]); $data[‘publish_time‘] = $time; //date(‘Y-m-d H:i:s‘,$time); $data[‘description‘] = $_POST[‘description‘][$i]; $data[‘contributor_id‘] = session("user")[‘id‘]; $data[‘img_url‘] = $_POST[‘img_url‘][$i]; //$data[‘establish_time‘] = date(‘Y-m-d H:i:s‘,time()); $res = $bookDB->create($data); if($res){ $in_id = $bookDB->add(); $insert[] = $in_id; }else{ if(count($insert)){ while(list($key,$val)=each($insert)){ $bookDB->where(‘id=‘.$val)->delete(); } } $this->error("捐书失败,请重新捐书!".$bookDB->getError()); } } redirect("/contribute/addbill"); //$this->success("捐书成功"); } }
2、Contribute的视图部分:
index.html 输入书籍IBSN码,提交捐书请求:
<extend name="Template:template"/> <block name="head"> <script type="text/javascript" src="/Public/js/Contribute/index.js"></script> </block> <block name="content"> <div class="span12 mb40"> <div class="mt10 offset2"> <h3>欢迎来到思源公益图书馆捐献图书</h3> </div> <div class="mt40 offset1"> <form class="form-horizontal" action="/Contribute/finish" method="post" data-validate="true"> <div class="panels"> </div> <div class="form-group two-btn"> <div class="col-sm-offset-2 col-sm-10"> <a class="btn btn-default addbook">再捐一本</a> <button type="submit" class="btn btn-primary">提交捐书请求</button> </div> </div> </form> </div> </div> <div class="hidden"> <div class="panel-group" id="accordion"> <div class="panel panel-default"> <!--<div class="panel-heading has-success has-feedback">--> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#collapse" class="number-title"> NO.1 </a> <a class="del-style" href="javascript:void(0)">删除</a> <!--<span class="glyphicon glyphicon-ok form-control-feedback"></span>--> </h4> </div> <div id="collapse" class="panel-collapse collapse in"> <div class="panel-body"> <div class="form-group"> <label for="inputibsn" class="col-sm-2 control-label">IBSN号:</label> <div class="col-sm-10"> <input type="number" name="bar_code[]" class="form-control inputIbsn" id="inputibsn" placeholder="IBSN"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="ui-button"> <button type="button" class="btn btn-default sureBook">查看图书</button> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <img src="#" class="bookImage" hidden="true"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkbox"> <label><input type="checkbox" class="checkBtn">书上没有IBSN</label> </div> </div> </div> <div class="form-group"> <label for="inputname" class="col-sm-2 control-label">书名:</label> <div class="col-sm-10"> <input type="text" name="name[]" class="form-control nameInput" id="inputname" placeholder="书名" datatype="*" nullmsg="书名不能为空!" readonly> </div> </div> <div class="form-group"> <label for="inputpublish" class="col-sm-2 control-label">出版社名:</label> <div class="col-sm-10"> <input type="text" name="publish[]" class="form-control publishInput" id="inputpublish" placeholder="出版社" readonly> </div> </div> <div class="form-group"> <label for="inputauthor" class="col-sm-2 control-label">作者:</label> <div class="col-sm-10"> <input type="text" name="author[]" class="form-control authorInput" id="inputauthor" placeholder="作者" readonly> </div> </div> <input type="hidden" class="translator" name="translator[]"> <input type="hidden" class="description" name="description[]"> <input type="hidden" class="publishdate" name="publish_time[]"> <input type="hidden" class="imgurl" name="img_url[]"> </div> </div> </div> </div> </div> </block>
addBill.html 生成书籍对应标识码:
<extend name="Template:template"/> <block name="content"> <if condition="$finish"> <div class="span12 mt40"> <div class="mt10 offset2"> <h3>请将所有的书邮寄到附近的思源公益图书馆,</h3> <h3>并在书上放上一张纸上面抄上下面的数字</h3> </div> <div class="pro-font offset2 mt40 p20"> <h4>{$bar_code}_{$Think.now|substr=0,10}</h4> </div> <div> <a class="btn btn-primary sure-style mt10 sure-btn" href="/">我知道了</a> </div> </div> <else/> <div class="span12 mt40"> <div class="mt10 offset2"> <h3>欢迎来到思源公益图书馆捐献图书</h3> </div> <div class="pro-font offset2 mt40"> <h4>捐书注意事项</h4> <p>非常感谢您在百忙之中抽出时间来为贫困地区捐书。我们会汇聚您的一份爱心,让大家的爱心点亮孩子们的心灵!</p> <p>思源公益</p> </div> <div class="pro-btn-cla offset2"> <a href="/contribute/addbill?id=1" class="btn btn-primary">同意以上协议</a> </div> </div> </if> </block>
公益图书馆-Contribute捐赠-代码学习,布布扣,bubuko.com
标签:des style blog color java os io 数据
原文地址:http://www.cnblogs.com/wingjay/p/3900090.html