按条件搜索

来源:互联网 发布:网络曝光暴力捉奸 编辑:程序博客网 时间:2024/05/16 11:11

<?php
/********************************************************************************************
 *任务一:
 *按条件搜索
 ********************************************************************************************/
/******************************** html页面 **************************************************
<form action="" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="xinxian_li">
  <tr style="padding-left:15px; background:#F4FCFF;">

    <td colspan="6">
      关键字:<input name="search_content" type="text" value="<{$search_content}>">

            <select name="search_type">
            <option value="1" <{if $search_type eq 1}>selected<{/if}> >通告标题关键字</option>
            <option value="2" <{if $search_type eq 2}>selected<{/if}> >通告内容关键字</option>
            <!-- 学联会搜索 -->
            <option value="3" <{if $search_type eq 3}>selected<{/if}> >学联会</option>
            <!-- 学联会搜索 -->
            </select>&nbsp;

            添加时间:
            <input type="text" name="start_dt" id="start_dt" value="<{$start_dt}>" />
            到 &nbsp;<input type="text" name="end_dt" id="end_dt" value="<{$end_dt}>" />

        <input name="submit1" id="submit1" type="submit" value="检索">&nbsp;&nbsp;&nbsp;
     </td>

  </tr>
</table>
</form>
 ********************************************************************************************/
//Model
function notice_list($action, $start_num, $per_page, $search_type, $search_content, $user_type=0, $user_priv=0, $start_dt, $end_dt){
        $end_num = $start_num + $per_page;
        if ($action == 'getCount')
            $sql    = "select count(*) as count from t_notice_info where 1=1";

        if ($action == 'getData')
            $sql = "select * from t_notice_info  where 1=1";

  //类型选择 (学联会)
  if ($search_content)
        {
            if ($search_type == 1)
                $sql .= " and title like '%$search_content%'";
            elseif ($search_type == 2)
                $sql .= " and contents like '%$search_content%'";
            //新添加的、、、
            elseif($search_type == 3)
             $sql .= " and schoolclub_name like '%$search_content%'";
        }
        if ($start_dt)
            $sql .= " and create_timer>=".strtotime($start_dt.' 00:00:00');
        if ($end_dt)
            $sql .= " and create_timer<=".strtotime($end_dt.' 23:59:59');


        if ($_SESSION['group_id'])
        {
           $sql .= " and schoolclub_id =".$_SESSION['club'];
        }

 if ($user_type){
    $sql .=" and (schoolclub_id=$user_type or schoolclub_id=0)";
 }
        if ($action == 'getData')
            $sql .= " order by create_timer desc limit ".$start_num.",".$per_page;
        //echo $sql;echo '<br />';
        $query  = $this->db->query($sql);
        $result = array();
        foreach ($query->result_array() as $row)
        {
            $result[] = $row;
        }
        return $result;
 }
//控制器中
    function index()
    {
  //print_r($_POST);
   /* 接受数据 */
   //学联会
   //Array ( [search_content] => b [search_type] => 3 [start_dt] => 2011-01-01 [end_dt] => 2011-03-04 [submit1] => 检索 )
   //处理search_type
        extract(parseRequset());

        //分页
        $this->load->helper('page');
        $param = '/index.php/user/index/?1=1';

        $search_type && $param.= '&search_type='.$search_type;
        $search_content && $param.= '&search_content='.$search_content;

        $user_type && $param.= '&user_type='.$user_type;
        $user_priv && $param.= '&user_priv='.$user_priv;

        $start_dt && $param.= '&start_dt='.$start_dt;
        $end_dt && $param.= '&end_dt='.$end_dt;

  //学联会
  //var_dump($user_priv);

        $this->cismarty->assign('search_type', $search_type);
        $this->cismarty->assign('search_content', $search_content);
        $this->cismarty->assign('user_type', $user_type);
        $this->cismarty->assign('user_priv', $user_priv);
        $this->cismarty->assign('start_dt', $start_dt);
        $this->cismarty->assign('end_dt', $end_dt);

        $per_page || $per_page = $this->config->item('default_per_page');
        $param.= '&per_page='.$per_page;
        $this->cismarty->assign('per_page', $per_page);
        $page || $page = 1;
        $start_num  = ($page-1)*$per_page;

        $result  = $this->NoticeModel->notice_list('getCount', $start_num, $per_page,  $search_type, $search_content, $user_type, $user_priv, $start_dt, $end_dt);
        $count   = $result[0]['COUNT'];

        $this->cismarty->assign('count',$count);

        $pagebar = page_bar($count, $page, $per_page, $param);
        $this->cismarty->assign('pagebar',$pagebar);

        $result  = $this->NoticeModel->notice_list('getData', $start_num, $per_page, $search_type, $search_content, $user_type, $user_priv, $start_dt, $end_dt);


        $this->cismarty->assign('list', $result);
  $this->cismarty->display("admincp/notice_list.html");
 }
/***************************************任务一 * 结束*************************************/

?>