#---- 商品表單
case "opForm":
opForm($sn);
break;
########################################
# 函數說明
# 外部變數請用參數傳值方式或global
########################################
function opForm($sn = "") {
global $xoopsDB,$xoopsTpl,$module_name,$ugmKind,$xoTheme;
//----------------------------------*/
//抓取預設值
if (!empty($sn)) {
$row = get_ugm_module_tbl($sn, "cnu_show_prod");//取得某筆記錄資料
$pre = _EDIT;
$row['op'] = "opUpdate";//在表單中表示接下來流程
} else {
$row = array();
$pre = _ADD;
$row['op'] = "opInsert";//在表單中表示接下來流程
}
$row['form_title'] = $pre . _MD_CNUSHOW_PROD;
//預設值設定
$row['sn'] = (!isset($row['sn'])) ? "" : $row['sn'];
$row['kind'] = (!isset($row['kind'])) ? "" : $row['kind'];
$row['kind_option'] = $ugmKind->get_kindOption($row['kind']);
$row['title'] = (!isset($row['title'])) ? "" : $row['title'];
$row['youtube'] = (!isset($row['youtube'])) ? "" : $row['youtube'];
$row['summary'] = (!isset($row['summary'])) ? "" : $row['summary'];
$row['price'] = (!isset($row['price'])) ? "" : $row['price'];
#排序,新增取得最大排序,編輯則按資料庫決定
$row['sort'] = (!isset($row['sort'])) ? get_ugm_module_max_sort("sort", "cnu_show_prod"):$row['sort'];
//$row['amount'] = (!isset($row['amount'])) ? "" : $row['amount'];
$row['choice'] = (!isset($row['choice'])) ? "0" : $row['choice'];
$row['enable'] = (!isset($row['enable'])) ? "1" : $row['enable'];
$row['date'] = !isset($row['date']) ? date("Y-m-d H:i:s", xoops_getUserTimestamp(strtotime("now"))) : date("Y-m-d H:i:s", xoops_getUserTimestamp($row['date']));
//strtotime("now"):為目前主機的時間磋記,xoops_getUserTimestamp(strtotime("now"))):將時間磋記改為會員的時間磋記
$row['content'] = (!isset($row['content'])) ? "" : $row['content'];
//內容#資料放「content」
# ======= ckedit====
//$UserPtah="config"
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/ck.php")) {
redirect_header("http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50", 3, _TAD_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/ck.php";
#---- 檢查資料夾
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck");
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck/image");
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck/flash");
$dir_name = $module_name . "/fck";
#----
$ck = new CKEditor($dir_name, "content", $row['content'], $module_name);
$ck->setHeight(300);
$row['content_editor'] = $ck->render();
#-------------------------------------
#上傳單張圖片
#----單檔圖片上傳
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir);//實體化
$name = "prod"; //表單欄位名稱
$col_name = "prod"; //資料表關鍵字
$col_sn = $row['sn']; //關鍵字流水號
$multiple = false; //單檔 or 多檔上傳
$accept = "image/*"; //可接受副檔名
$row['prod'] = $ugmUpFiles->upform($name,$col_name,$col_sn,$multiple,$accept);
#-----------------------------------
#上傳pdf型錄
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir);//實體化
$name = "prodPdf"; //表單欄位名稱
$col_name = "prodPdf"; //資料表關鍵字
$col_sn = $row['sn']; //關鍵字流水號
$multiple = false; //單檔 or 多檔上傳
$accept = "application/pdf"; //可接受副檔名
$row['prodPdf'] = $ugmUpFiles->upform($name,$col_name,$col_sn,$multiple,$accept);
//-------------------------------*/
//----- 驗證碼 -----------------*/
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/formValidator.php")) {
redirect_header("index.php", 3, _TAD_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/formValidator.php";
$formValidator = new formValidator("#myForm", true);
$formValidator_code = $formValidator->render();
//-------------------------------*/
#小月曆
$xoTheme->addScript('modules/tadtools/My97DatePicker/WdatePicker.js');
$xoopsTpl->assign('row', $row);
}
<{if $op == "opForm"}>
<div class='container-fluid'>
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title"><{$row.form_title}></h3></div>
<div class="panel-body">
<form role="form" action="main.php" method="post" id="myForm" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-8">
<div class="row">
<!--標題-->
<div class="col-sm-8">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_TITLE}></label>
<input type="text" class="form-control validate[required]" name="title" id="title" value="<{$row.title}>">
</div>
</div>
<!--標題-->
<div class="col-sm-4">
<div class="form-group">
<label>YOUTUBE ID</label>
<input type="text" class="form-control" name="youtube" id="youtube" value="<{$row.youtube}>">
</div>
</div>
</div>
<div class="row">
<!--類別-->
<div class="col-sm-4">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_KIND}></label>
<select name="kind" class="form-control" size="1">
<{$row.kind_option}>
</select>
</div>
</div>
<!--日期-->
<div class="col-sm-4">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_DATE}></label>
<input type="text" name="date" id="date" class="form-control " value="<{$row.date}>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss' , startDate:'%y-%M-%d %H:%m:%s'})">
</div>
</div>
<!--狀態-->
<div class="col-sm-2">
<div class="form-group">
<label style="display:block;"><{$smarty.const._MD_UGMMODULE_ENABLE}></label>
<input type='radio' name='enable' id='enable_1' value='1' <{if $row.enable==1}>checked<{/if}>>
<label for='enable_1'><{$smarty.const._MD_UGMMODULE_ENABLE_1}></label>
<input type='radio' name='enable' id='enable_0' value='0' <{if $row.enable==0}>checked<{/if}>>
<label for='enable_0'><{$smarty.const._MD_UGMMODULE_ENABLE_0}></label>
</div>
</div>
<!--精選-->
<div class="col-sm-2">
<div class="form-group">
<label style="display:block;"><{$smarty.const._MD_UGMMODULE_CHOICE}></label>
<input type='radio' name='choice' id='choice_1' value='1' <{if $row.choice==1}>checked<{/if}>>
<label for='choice_1'><{$smarty.const._MD_UGMMODULE_ENABLE_1}></label>
<input type='radio' name='choice' id='choice_0' value='0' <{if $row.choice==0}>checked<{/if}>>
<label for='choice_0'><{$smarty.const._MD_UGMMODULE_ENABLE_0}></label>
</div>
</div>
</div>
<div class="row">
<!--圖片-->
<div class="col-sm-4">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_PIC}><span>(840x840)</span></label>
<{$row.prod}>
</div>
</div>
<!--PDF-->
<div class="col-sm-4">
<div class="form-group">
<label>PDF</label>
<{$row.prodPdf}>
</div>
</div>
<!--排序-->
<div class="col-sm-2">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_SORT}></label>
<input type="text" class="form-control text-right" name="sort" id="sort" value="<{$row.sort}>" >
</div>
</div>
<!--單位-->
<div class="col-sm-2">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_UNIT}></label>
<input type="text" class="form-control" name="unit" id="unit" value="<{$row.unit}>" >
</div>
</div>
</div>
<div class="row">
<!--規格-->
<div class="col-sm-6">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_STANDARD}></label>
<input type="text" class="form-control" name="standard" id="standard" value="<{$row.standard}>">
</div>
</div>
<!--尺寸-->
<div class="col-sm-6">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_SIZE}></label>
<input type="text" class="form-control" name="size" id="size" value="<{$row.size}>">
</div>
</div>
</div>
</div>
<!-- 摘要-->
<div class="col-sm-4">
<div class="form-group">
<label><{$smarty.const._MD_UGMMODULE_SUMMARY}></label>
<textarea class="form-control" rows="12" id="summary" name="summary"><{$row.summary}></textarea>
</div>
</div>
</div>
<!--內容-->
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="content"><{$smarty.const._MD_UGMMODULE_CONTENT}></label>
<{$row.content_editor}>
</div>
</div>
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary"><{$smarty.const._SUBMIT}></button>
<{if !$row.sn}>
<button type="reset" class="btn btn-danger"><{$smarty.const._RESET}></button>
<{/if}>
<button type="button" class="btn btn-warning" onclick="location.href='<{$smarty.session.return_url}>'"><{$smarty.const._BACK}></button>
<input type='hidden' name='op' value='<{$row.op}>'>
<input type='hidden' name='sn' value='<{$row.sn}>'>
</div>
</form>
</div>
</div>
</div>
<{/if}>