Title1

Title2

Title3

18-4 op_form()函數

  1. op_form
    ########################################
    # 表單
    ########################################
    function op_form($sn="")
    {
      global $mysqli,$smarty;
    
      #抓取預設值
      if($sn)
      {
        #編輯
        $DBV=get_show_prod($sn);//取得單筆記錄
        $DBV['op'] = "op_update";
        $DBV['form_title'] = "編輯商品";
        //print_r($DBV);die();
      }else
      {
        #新增
        $DBV=array();
    
        $DBV['op'] = "op_insert";
        $DBV['form_title'] = "新增商品";
      }
    
      //預設值設定
    
      $DBV['sn']     = (isset($DBV['sn']))     ? $DBV['sn']     : "";
      $DBV['title']  = (isset($DBV['title']))  ? $DBV['title']  : "";
      $DBV['enable'] = (isset($DBV['enable'])) ? $DBV['enable'] : "1";
      $DBV['sort']   = (isset($DBV['sort']))   ? $DBV['sort']   : "";
    
      #商品類別
      $DBV['kind']   = (isset($DBV['kind']))   ? $DBV['kind']   : "";
      $DBV['kind_option'] = get_kind_prod_option($DBV['kind']);
    
      #日期
      $DBV['date']   = (isset($DBV['date']))   ? date("Y-m-d H:i:s" , $DBV['date']) : date("Y-m-d H:i:s");
      $DBV['date']   = "<input type='text' name='date' id='date' class='form-control' value='{$DBV['date']}' onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss' , startDate:'%y-%M-%d %H:%m:%s'})\">";
    
      $DBV['price'] = (isset($DBV['price'])) ? $DBV['price'] : "";
      $DBV['summary']   = (isset($DBV['summary']))   ? $DBV['summary']   : "";
      $DBV['content']   = (isset($DBV['content']))   ? $DBV['content']   : "";
    
    
      #圖片src
      $DBV['file_name'] = (isset($DBV['file_name']))   ? $DBV['file_name']   : "";
    
      $smarty->assign("DBV", $DBV);
      return;
    }

     

  2. get_show_prod()
    ########################################
    #取得單筆商品記錄
    ########################################
    function get_show_prod($sn="")
    {
      global $mysqli,$TBL;
      if(!$sn)redirect_header("index.php",3000,"查詢選單資料錯誤!!");
    
      $sql = "select *
              from `{$TBL['name']}`
              where `sn`='{$sn}'";//die($sql);
      $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
      $DBV = $result->fetch_assoc();
    
      #過濾撈出資料
      $DBV['sn'] = intval($DBV['sn']);
      //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
      $DBV['title'] = htmlspecialchars($DBV['title'], ENT_QUOTES); // 轉換雙引號和單引號
      $DBV['sort'] = intval($DBV['sort']);
      $DBV['enable'] = intval($DBV['enable']);
    
      $DBV['kind'] = intval($DBV['kind']);
      $DBV['price'] = intval($DBV['price']);
      $DBV['date'] = intval($DBV['date']);
      $DBV['counter'] = intval($DBV['counter']);
      $DBV['summary'] = htmlspecialchars($DBV['summary'], ENT_QUOTES); // 轉換雙引號和單引號
    
      #取得圖片src
      $col_name="prod";
      $DBV['file_name'] = get_file_name_src($DBV['sn'],$col_name);
    
      return $DBV;
    }
    

     

  3. get_kind_prod_option()
    ########################################
    # 得到商品類別選項
    ########################################
    function get_kind_prod_option($kind="")
    {
      global $mysqli,$smarty,$TBL;
      $sql = "select sn,title
              from `show_kind`
              where `kind`='{$TBL['kind']}' and `enable`='1' ";
      $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
      $options="";
      while($row = $result->fetch_assoc())
      {
        #過濾撈出資料
        $row['sn'] = intval($row['sn']);
        //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
        $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號
        $selected = ($kind == $row['sn'])?" selected":"";
    
        $options .="<option value='{$row['sn']}'{$selected}>{$row['title']}</option>\n";
      }
      return $options;
    }