Title1

Title2

Title3

5-4 opUpdate

一、流程

  1. switch
    
      #---- 編輯商品資料
      case "opUpdate":
        $sn = opUpdate($sn);
        XoopsCache::clear();
        redirect_header($_SESSION['return_url'], 3, _BP_SUCCESS);
        exit;

     

二、函數

  1. opUpdate($sn = "")
    
    ########################################
    #  編輯資料
    ########################################
    function opUpdate($sn = "") {
      global $xoopsDB, $xoopsUser,$module_name,$xoopsModuleConfig;
      //---- 過濾資料 -----------------------------------------*/
      $myts = &MyTextSanitizer::getInstance();
      #標題
      $_POST['title'] = $myts->addSlashes($_POST['title']);
      #youtube id
      $_POST['youtube'] = $myts->addSlashes($_POST['youtube']);
      #日期
      $_POST['date'] = userTimeToServerTime(strtotime($myts->addSlashes($_POST['date'])));//把時間改為主機時間搓記
      #精選
      $_POST['choice'] = intval($_POST['choice']);
      #狀態
      $_POST['enable'] = intval($_POST['enable']);
      #商品類別
      $_POST['kind'] = intval($_POST['kind']);
      #排序
      $_POST['sort'] = intval($_POST['sort']);
      #單位
      $_POST['unit'] = $myts->addSlashes($_POST['unit']);
      #規格
      $_POST['standard'] = $myts->addSlashes($_POST['standard']);
      #尺寸
      $_POST['size'] = $myts->addSlashes($_POST['size']);
      #價格
      //$_POST['price'] = intval($_POST['price']);
      #數量
      //$_POST['amount'] = intval($_POST['amount']);
      #內容
      $_POST['content'] = $myts->addSlashes($_POST['content']);
      #摘要
      $_POST['summary'] = $myts->addSlashes($_POST['summary']);
      #sn
      $_POST['sn'] = intval($_POST['sn']);
    
      //print_r($_POST);die();
      //-------------------------------------------------------*/
    
      $sql = "update " . $xoopsDB->prefix("cnu_show_prod") . "
              set
              `title`='{$_POST['title']}',
              `date`='{$_POST['date']}',
              `choice`='{$_POST['choice']}',
              `enable`='{$_POST['enable']}',
              `kind`='{$_POST['kind']}',
              `content`='{$_POST['content']}',
              `summary`='{$_POST['summary']}',
              `sort`='{$_POST['sort']}',
              `unit`='{$_POST['unit']}', 
              `standard`='{$_POST['standard']}', 
              `size`='{$_POST['size']}',                
              `youtube`='{$_POST['youtube']}'
              where `sn`='{$_POST['sn']}'"; //die($sql);
      $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error());
    
     
      #處理圖片
      
      #----單圖上傳  
      $subdir = "prod";                                      //子目錄(前後不要有 / )
      $ugmUpFiles = new ugmUpFiles($module_name, $subdir);   //實體化
      
      $name = "prod";                                        //表單欄位名稱
      $col_name = "prod";                                    //資料表關鍵字
      $col_sn = $_POST['sn'];                                //關鍵字流水號
      $multiple = false;                                     //單檔 or 多檔上傳
      $main_width = 840;                                     //大圖壓縮尺吋,-1則不壓縮
      $thumb_width = 120;                                    //小圖壓縮尺吋
      $ugmUpFiles->upload_file($name,$col_name,$col_sn,$multiple,$main_width,$thumb_width);
      #------------------------------------------------
    
      #上傳pdf型錄  
      #---- 
      $subdir = "prod";                                      //子目錄(前後不要有 / )
      $ugmUpFiles = new ugmUpFiles($module_name, $subdir);   //實體化
      
      $name = "prodPdf";                                     //表單欄位名稱
      $col_name = "prodPdf";                                 //資料表關鍵字
      $col_sn = $_POST['sn'];                                //關鍵字流水號
      $multiple = false;                                     //單檔 or 多檔上傳
      $main_width = "";                                      //大圖壓縮尺吋,-1則不壓縮
      $thumb_width = "";                                     //小圖壓縮尺吋
      $ugmUpFiles->upload_file($name,$col_name,$col_sn,$multiple,$main_width,$thumb_width);
    
      return $_POST['sn'];
    }
    

     

  2.