一、流程
#---- 新增商品資料 case "opInsert": $sn = opInsert(); XoopsCache::clear(); redirect_header($_SESSION['return_url'], 3, _BP_SUCCESS); exit;
二、函數
######################################## # 新增、編輯資料 ######################################## function opInsert() { global $xoopsDB,$xoopsUser,$module_name,$xoopsModuleConfig; //---- 過濾資料 -----------------------------------------*/ $myts = &MyTextSanitizer::getInstance(); #標題 $_POST['title'] = $myts->addSlashes($_POST['title']); #youtube id $_POST['youtube'] = $myts->addSlashes($_POST['youtube']); #商品類別 $_POST['kind'] = intval($_POST['kind']); #日期 $_POST['date'] = userTimeToServerTime(strtotime($myts->addSlashes($_POST['date']))); #狀態 $_POST['enable'] = intval($_POST['enable']); #精選 $_POST['choice'] = intval($_POST['choice']); #排序 $_POST['sort'] = intval($_POST['sort']); #單位 $_POST['unit'] = $myts->addSlashes($_POST['unit']); #規格 $_POST['standard'] = $myts->addSlashes($_POST['standard']); #尺寸 $_POST['size'] = $myts->addSlashes($_POST['size']); #內容 $_POST['content'] = $myts->addSlashes($_POST['content']); #摘要 $_POST['summary'] = $myts->addSlashes($_POST['summary']); #sn $_POST['sn'] = intval($_POST['sn']); #價格 //$_POST['price'] = intval($_POST['price']); #數量 //$_POST['amount'] = intval($_POST['amount']); //print_r($_POST);die(); //-------------------------------------------------------*/ $sql = "insert into " . $xoopsDB->prefix("cnu_show_prod") . " (`title`,`youtube`,`kind`,`date`,`enable`,`choice`,`sort`,`unit`,`standard`,`size`,`content`,`summary`) values ('{$_POST['title']}','{$_POST['youtube']}','{$_POST['kind']}','{$_POST['date']}','{$_POST['enable']}','{$_POST['choice']}','{$_POST['sort']}','{$_POST['unit']}','{$_POST['standard']}','{$_POST['size']}','{$_POST['content']}','{$_POST['summary']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 $_POST['sn'] = $xoopsDB->getInsertId(); #處理圖片 #----單圖上傳 $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']; }