本帖最后由 kakashilw 于 2009-7-1 12:39 編輯
因?yàn)楣ぷ髟?,最近又走馬觀花了幾套開(kāi)源產(chǎn)品。。。
在這里分享下走馬觀花shopnc時(shí)的筆記吧。。。
其實(shí)shopnc是半開(kāi)源的產(chǎn)品,它的核心代碼是加密的。。不過(guò)開(kāi)源的部分還不少,而且還有注釋,嘻嘻~~
ready?go!
--------------------------------------------------------------------------------------------------------------------------
1、index.php和index.html 之首頁(yè)靜態(tài)化生成
分析代碼當(dāng)然是從index.php開(kāi)始嘍,貼下代碼
[php]
require ("global.inc.php");
//判斷是否有安裝文件
if (file_exists("install/index.php")){
// if (!is_writable("templates/install/templates_c")){
// echo BasePath."/templates/install/templates_c have no permissions! Please Determine this Folder's write permissions!";
// exit;
// }
header("location:install/index.php");
exit;
}
class ShowIndex extends CommonFrameWork{
function main(){
/**
* 執(zhí)行操作
*/
switch($this->_input['action']){
default:
$this->_showindex();
}
}
/**
* 首頁(yè)顯示
*
*/
function _showindex(){
@header("location:home/index.php");
}
}
$index = new ShowIndex();
$index->main();
unset($index);
[/php]
很簡(jiǎn)單,通過(guò)global.inc.php載入核心類庫(kù),包括框架的核心代碼(個(gè)人猜測(cè)應(yīng)該是大白菜心的php框架吧)
然后跳轉(zhuǎn)到home/index.php中去了。。
index.php中執(zhí)行了
[php]
function main(){
/**
* 創(chuàng)建首頁(yè)和頻道靜態(tài)頁(yè)面對(duì)象
*/
if (!is_object($this->obj_html_channel)){
require_once("../home/html.channel.php"); //dump("eee");
$this->obj_html_channel = new HtmlChannelManage();
}
/**
* 創(chuàng)建商品分類對(duì)象
*/
if (!is_object($this->objProductCate)){
require_once ("productclass.class.php");
$this->objProductCate = new ProductCategoryClass();
}
//return;
/**
* 創(chuàng)建商鋪分類對(duì)象
*/
if (!is_object($this->obj_shop_category)){
require_once("shopcategory.class.php");
$this->obj_shop_category = new ShopCategoryClass();
}
/**
* 設(shè)置模板路徑
*/
$this->setsubtemplates("home");
/**
* 語(yǔ)言包
*/
$this->getlang("index_show");
/**
* 執(zhí)行操作
*/
switch($this->_input['action']){
case "aj_get_class":
$this->_aj_get_class();
break;
case "getQuickLinks":
$this->_getQuickLinks();
break;
case "index_html":
$this->_index_html();
break;
default:
$this->_showindex();
}
}
[/php]
有注釋,看看流程就可以了,具體代碼就不細(xì)究了。。。
然后執(zhí)行到了$this->_index_html();
這個(gè)是關(guān)鍵,就是傳說(shuō)中的【首頁(yè)靜態(tài)化】了。??纯慈思沂钦?xiě)的
這個(gè)函數(shù)中輾轉(zhuǎn)反側(cè)后到了最后這個(gè)方法了。。
[php]
function _make_language_html($language){
//重新加載語(yǔ)言包
unset($this->_lang);
$this->_langType = $language['language_path'];
$this->getlang("common");
$this->getlang("index_show");
$this->getlang("channel");
//頻道頁(yè)面需要加載的內(nèi)容
//搜索中的商品類別
require(BasePath."/cache/ProductClass_show.php");
if (is_array($node_cache)){
foreach ($node_cache as $k => $v){
if ($v[4] == '0') {
$v['id'] = $v[0];
$v['name'] = $v[2];
$SearchProductCateArray[] = $v;
}
}
}
/*取所有頻道*/
$condition["order_by"] = "channel_sort";
$condition["state"] = "0";
$condition["order_sort"] = "asc";
$channel_all = $this->obj_channel->listChannel($condition,$page);
unset($condition);
//取模塊參數(shù)配置文件 default
$path = BasePath."/share/indexparam/";
//模板參數(shù)
$tpl_path = BasePath."/templates/".$this->_configinfo['websit']['templatesname'].'/home/index_tpl/';
//判斷改文件夾是否存在,如果不存在,則報(bào)錯(cuò)
if (!is_dir($path)){
return $this->_lang['langChannelIndexTempDirWrong'];
}
//通過(guò)LOCK標(biāo)識(shí),取模板文件名
require_once("fileoperate.class.php");
$file_array = FileOperate::listDir($tpl_path);
//如果有LOCK后綴的文件,則表示文件名為模板當(dāng)前使用名稱
if (is_array($file_array)){
foreach ($file_array as $k => $v){
if (strstr($v['name'],'.LOCK')){
$template_name = substr($v['name'],0,strlen($v['name'])-5);
if (!file_exists($tpl_path.$template_name)) {
return $this->_lang['langChannelIndexHmtlTempIsNotExists'];
}
$template_name = substr($template_name,0,strlen($template_name)-5);
break;
}
}
}
//判斷是否為空,如果為空,則默認(rèn)
if($template_name == ''){
$template_name = 'default';
}
if (file_exists($path.$this->_configinfo['websit']['templatesname'].".php")){
require($path.$this->_configinfo['websit']['templatesname'].".php");
//參數(shù)數(shù)組 $ChannelParamArray
if (is_array($ChannelParamArray)){
$module = array();/*模塊頁(yè)面代碼*/
//取各模塊的參數(shù) $k 為模塊名稱 下劃線前兩個(gè)單詞為模塊類型
foreach ($ChannelParamArray as $k => $v){
//判斷模塊類型
$line = @explode("_",$k);
$module_name = $line[0].'_'.$line[1];
switch ($module_name){
case "adv_module"://廣告模塊
//如果是安裝時(shí),則判斷是否安裝演示數(shù)據(jù),如果不安裝的話,則不執(zhí)行廣告模塊程序
if (INSTALL_ISDATA == 'no'){//不安裝
break;
}
//判斷是否是flash廣告,如果不是則調(diào)用JS文件,是則調(diào)用模塊模板
//創(chuàng)建廣告對(duì)象
if (!is_object($this->obj_adv)){
require_once ("advertisement.class.php");
$this->obj_adv = new AdvertisementClass();
}
$condition_adv['code'] = $v['code'];
$condition_adv['start_date'] = time();
$condition_adv['end_date'] = time();
$condition_adv['state'] = 0;
$adv_list = $this->obj_adv->listAdv($condition_adv,$page);
if ($adv_list[0]['adv_type'] == 2){//如果是flash
$module[$k] = $this->advFlashHtmlCode($v['code']);
}else {//其他廣告類型,調(diào)用的是JS文件
//判斷廣告的JS文件是否存在
if (file_exists(BasePath."/html/js/".$v['code'].'.js')){
$module[$k] = "<script src='".$this->_configinfo['websit']['site_url'].'/html/js/'.$v['code'].'.js'."'></script>";
}else {
return $this->_lang['langChannelAdvCreaLostPleaseAdvManageCreateFile'];
}
}
break;
case "vote_module"://投票模塊
$module[$k] = $this->voteHtmlCode($v);
break;
case "product_module"://商品模塊
$module[$k] = $this->productHtmlCode($v);
break;
case "shop_module"://商鋪模塊
$module[$k] = $this->shopHtmlCode($v);
break;
case "pclass_module"://商品類別模塊
$module[$k] = $this->pclassHtmlCode($v);
break;
case "shopclass_module"://商鋪類別模塊
$module[$k] = $this->shopclassHtmlCode($v);
break;
}
}
//關(guān)鍵詞模板名稱
$keyword_html_name = BasePath.'/html/keyword/index.html';
/**
* 取得最新成交訂單列表
*/
if (!is_object($this->obj_product_order)){
require_once("order.class.php");
$this->obj_product_order = new ProductOrderClass();
}
$obj_order_condition[order] = "1";
$this->obj_page_channel->pagebarnum(10);
$product_order_array = $this->obj_product_order->getProductOrderList($obj_order_condition, $this->obj_page);
//重新設(shè)置模板路徑和語(yǔ)言包
$this->setsubtemplates("home/index_tpl");
/**
* 頁(yè)面輸出
*/
/*頁(yè)頭導(dǎo)航的樣式判斷*/
$this->output('search_header_sign','1');
//對(duì)模板上的模塊標(biāo)識(shí)符進(jìn)行替換
$this->output("product_order_array",$product_order_array);
$this->output("keyword_html_name",$keyword_html_name);
$this->output("search_cate",$SearchProductCateArray);//搜索中的商品類別
$this->output('channel_all', $channel_all); //導(dǎo)航菜單頻道
$this->output('language_array', $language); //該語(yǔ)言種類
$default_code = $this->fetchpage($template_name);//取輸出到模板上的內(nèi)容
if (is_array($module)){
foreach ($module as $k => $v){
$line = "";
$line = '<module>'.$k.'</module>';
$replacements = $v;
$default_code = @str_replace($line,$replacements,$default_code);
}
}
$this_my_file = @preg_replace('/<module>.*?<[url=]\\/module>/is',"",$default_code[/url]);
require_once("makehtml.class.php");
/*根目錄下生成文件*/
//判斷是否是默認(rèn)語(yǔ)言,如果是則用
if ($language['language_state'] == '1'){
if (file_exists('../index.html')){
@unlink('../index.html');
}
$file_name = '../index.html';
}else {
if (file_exists('../index_'.$language['language_path'].'.html')){
@unlink('../index_'.$language['language_path'].'.html');
}
$file_name = '../index_'.$language['language_path'].'.html';
}
$this_my_file = str_replace("../","",$this_my_file);
$patterns = array (
'/home\\/home\\/category.php/is',
'/href=\\"category.php/is',
'/home\\/home\\/member.php/is',
'/href=\\"member.php/is',
'/home\\/home\\/channel.php/is',
'/href=\\"channel.php/is',
'/home\\/home\\/shop.php/is',
'/href=\\"shop.php/is',
'/home\\/home\\/shop_brand.php/is',
'/href=\\"shop_brand.php/is',
'/home\\/home\\/vote.php/is',
'/=\\"vote.php/is',
"/\\('vote.php/is",
'/home\\/home\\/product.php/is',
'/href=\\"product.php/is',
'/home\\/home\\/productmessage.php/is',
'/href=\\"productmessage.php/is',
'/switcher.swf/is',
'/js_statics_sign=1/is',
"/\\'shop.php/is",
"/\\'product.php/is",
);
$replacements = array (
'home/category.php',
'href="home/category.php',
'home/member.php',
'href="home/member.php',
'home/channel.php',
'href="home/channel.php',
'home/shop.php',
'href="home/shop.php',
'home/shop_brand.php',
'href="home/shop_brand.php',
'home/vote.php',
'="home/vote.php',
"('home/vote.php",
'home/product.php',
'href="home/product.php',
'home/productmessage.php',
'href="home/productmessage.php',
'switcher_html.swf',
'js_statics_sign=3',
"'home/shop.php",
"'home/product.php",
);
$this_my_file = preg_replace($patterns,$replacements,$this_my_file);
//如果使用動(dòng)態(tài)訪問(wèn),則不生成靜態(tài)頁(yè)
if ($this->_configinfo['websit']['index_html'] == '0'){
echo $this_my_file;exit;
}
if (!MakeHtml::tohtmlfile($file_name, $this_my_file)){
return $this->_lang['langChannelIndexCreateLostFile'];
}else {
return true;
}
}
}else {
return $this->_lang['langChannelIndexCreateLostParamFile'];
}
}
[/php]
很復(fù)雜,因?yàn)榘硕嗾Z(yǔ)言,欄目緩存等,不過(guò)就靜態(tài)化的話,關(guān)鍵就是這句了
[php]MakeHtml::tohtmlfile($file_name, $this_my_file)[/php]
這個(gè)類他加密了,不過(guò)據(jù)我的猜測(cè)應(yīng)該是fwrite之類的吧,這樣就生成了index.html了。。
以后先判斷根目錄下有無(wú)這個(gè)文件,有就跳過(guò)去,沒(méi)有則生成。。。
好了,先寫(xiě)這么多了。。。困了。。睡覺(jué)去了。。。
以后有空再寫(xiě)吧。。。。 |
|
|
|
|
|
|
   
- 威望
- 5514
- 開(kāi)源幣
- 293
- 注冊(cè)時(shí)間
- 2007-12-7
- 積分
- 11786
- 帖子
- 3015
- 主題
- 694
- UID
- 52443
|
2#
發(fā)表于 2009-7-1 04:24:41
|只看該作者
2、SHOPNC的MVC
本帖最后由 kakashilw 于 2009-7-1 13:58 編輯
SHOPNC的MVC和現(xiàn)在主流框架的MVC還是有些區(qū)別的。。。
最大的不同在于,SHOPNC是多入口的,不同功能一個(gè)入口文件,然后再在main()函數(shù)中分發(fā)。。。
拿一個(gè)商品的展示頁(yè)為例。。。。
[php]
require ("../global.inc.php"); //載入核心類庫(kù),這個(gè)上面提到過(guò)了
class ShowProduct extends CommonFrameWork{ //都集成CommonFrameWork這個(gè)類
...................
function main(){
..............
}
.................
}
$product = new ShowProduct();
$product->main();
unset($product);
[/php]
每個(gè)入口文件大致是 這樣的結(jié)構(gòu)了。。。
OK,看著還是蠻簡(jiǎn)潔明了的。。。。
------------------------------------------------------------------------------------------------------------------------
好了,下面著重分析下main函數(shù),因?yàn)檫@里面包含的是 初始化(類似構(gòu)造函數(shù)的功能) , 路由轉(zhuǎn)發(fā) 這幾步內(nèi)容
基本相當(dāng)于MVC眾的"C"了
(1)初始化,一般都是這種風(fēng)格的。。。
(PS:這里插一句,很佩服大白菜產(chǎn)品的代碼風(fēng)格,非常一致,看來(lái)之前他所說(shuō)的一個(gè)員工拿到另一個(gè)的代碼,最多半小時(shí)就能上手果真不是吹的,呵呵)
[php]
/**
* 創(chuàng)建商品對(duì)象
*/
if (!is_object($this->obj_product)){
require_once("product.class.php");
$this->obj_product = new ProductClass();
}
/**
* 創(chuàng)建驗(yàn)證對(duì)象
*/
if (!is_object($this->objvalidate)){
require_once("commonvalidate.class.php");
$this->objvalidate = new CommonValidate();
}
/**
* 網(wǎng)站提醒操作
*/
if (!is_object($this->obj_remind)){
require_once('remind.class.php');
$this->obj_remind = new RemindClass();
}
/**
* 創(chuàng)建會(huì)員對(duì)象
*/
if (!is_object($this->obj_member)){
require_once("member.class.php");
$this->obj_member = new MemberClass();
}
/**
* 初始化商品品牌類
*/
if (!is_object($this->obj_product_brand)){
require_once("product_brand.class.php");
$this->obj_product_brand = new ProductBrandClass();
}
/**
* 設(shè)置模板路徑
*/
$this->setsubtemplates("home");
/**
* 語(yǔ)言包
*/
$this->getlang("product");
[/php]
(2)路由轉(zhuǎn)發(fā)
[php]
switch ($this->_input['action']){
case "list":
$this->_listproduct();
break;
case "textlist":
$this->_listproduct();
break;
case "view":
$this->_viewproduct();
break;
case "search":
$this->output('InfoSelectorTarget',Common::getTargetMenu("search"));
$this->_searchproduct();
break;
case "compare":
$this->_compareproduct();
break;
case "compareresult":
$this->_compareproductresult();
break;
case "compare_remove":
$this->_compareremove();
break;
case "clean_reviewed":
$this->_cleanreviewedproduct();
break;
case "check_code":
$this->_check_code();
break;
case 'all':
$this->_listproduct();
break;
case "setReview":
$p_code = $this->_input['p_code'];
$this->setReviewed($p_code);
break;
case "ajax_get_attribute":
$this->_ajax_get_attribute();
break;
default:
$this->_listproduct();
break;
}
[/php]
呵呵,有注釋,看著就簡(jiǎn)單多了吧。。。
------------------------------------------------------------------------------------------------------------------
好了,下面看看MVC鐘的"V"是怎樣的。。。
拿_viewproduct()這個(gè)舉例,可以看到函數(shù)的最下端有
[php]
$this->output('pURL',$pURL);
$this->output('pic_array',$pic_array);//商品圖片列表
$this->output('class_level',$class_level);
$this->output("title_message" , $title_p_name); //TITLE內(nèi)容
$this->output("keyword_message", $keyword_p_name); //關(guān)鍵字內(nèi)容
$this->output("ses_login", $_SESSION['s_login']); //登陸信息
$this->output("page_list", $page_list);
$this->output("shop_info", $shop_info);
$this->output("product_row", $product_row);
$this->output("PathLinks", $cate_path);
$this->output("ses_login", $_SESSION['s_login']); //登陸信息
$this->output("message_array", $message_array); //商品留言
$this->output("seller_info", $seller_info); //商家信息
$this->output("have_attribute", $have_attribute);
$this->output("product_attribute", $product_attribute);
$this->output("product_attribute_content", $product_attribute_content);
$this->output("product_have_attribute", $pac_attribute);
$this->output("payment_array", $payment_array);
$this->output("currency_array", $currency_array);
$this->output("product_order_array", $product_order_array);
$this->output("lefttime", $text_left_time);
$this->output("exchange_remark", $exchange_remark);
$this->output("sel_area", $sel_area);
$this->output("sel_brand", $sel_brand);
$this->showpage("product.view");
[/php]
哈哈,用過(guò)smarty或框架的童鞋是不是很熟悉啊,對(duì)了,這個(gè)就是shopnc的模板引擎了。。。 對(duì)應(yīng)的是home目錄下的product.view.html了。。。
- <p><tpl>$langUserStore</tpl>:<tpl> $shop_info.shop_name </tpl></p>
- <p><tpl>$langMerchant</tpl>:<tpl> $seller_info.login_name </tpl></p>
- <p><tpl>$langUserArea</tpl>:<tpl> $shop_info.shop_province </tpl></p>
復(fù)制代碼
類似這種東東,用<tpl></tpl>標(biāo)簽類輸出變量等。。。。
------------------------------------------------------------------------------------------------------------
C和V都講了,只剩"M"了。。
[php]
/**
* 創(chuàng)建商品對(duì)象
*/
if (!is_object($this->obj_product)){
require_once("product.class.php");
$this->obj_product = new ProductClass();
}
...............................
/**
* 取得商品信息
*/
$product_row = $this->obj_product->getProductRow($p_id);
[/php]
哈哈,看明白了吧。。這個(gè)“ProductClass”類就可以理解成M了。。它里面封裝了很多product相關(guān)的業(yè)務(wù)邏輯。。。
好了,就簡(jiǎn)單寫(xiě)這么多吧。。。發(fā)帖子比看代碼累多了。。。
最后贊一句,大白菜的產(chǎn)品的代碼質(zhì)量,規(guī)范等是看了這麼多產(chǎn)品中最好的一款了。。。
其中的權(quán)限控制,多語(yǔ)言,多模板都運(yùn)用的相當(dāng)不錯(cuò)。。。
特別是靜態(tài)化方面,承載一定負(fù)載還是沒(méi)問(wèn)題的。。。 |
|
|
|
|
|
|
   
- 威望
- 5514
- 開(kāi)源幣
- 293
- 注冊(cè)時(shí)間
- 2007-12-7
- 積分
- 11786
- 帖子
- 3015
- 主題
- 694
- UID
- 52443
|
3#
發(fā)表于 2009-7-1 04:24:44
|只看該作者
3、用戶輸入之檢測(cè)
本帖最后由 kakashilw 于 2009-7-2 13:38 編輯
(1)前端
- <script language="JavaScript" type="text/javascript" src="<tpl> $site_url </tpl>/js/jquery/jquery.validate.js"></script>
-
- $(function(){
- $("#ownaddproduct").validate({
- errorClass: "wrong",
- rules: {
- txtPname: {required:true},
- txtPstorage: {
- required:true,
- number:true,
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return 5;
- }else{
- return 1;
- }
- }
- },
- minimumBid: {
- required: "#radioSelltype0:checked",
- number: true,
- min: function(){
- if($("#radioSelltype0").attr('checked')==true){
- return 0.01;
- }else{
- return 0;
- }
- }
- },
- price_step: {
- required: "#radioSelltype0:checked",
- number: true,
- min: function(){
- if($("#radioSelltype0").attr('checked')==true && $("#inc2").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- txtPprice: {required: "#radioSelltype1:checked",number: true,min: 0.01},
- txtGroupprice: {required:"#radioSelltype2:checked",number:true,min: 0.01},
- txtPoldprice: {required: "#radioSelltype2:checked",number: true,min: function(){return $("#txtGroupprice").val();}},
- txtGroupmincount: {
- required: "#radioSelltype2:checked",
- number: true,
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return 5;
- }else{
- return 0;
- }
- },
- max:function(){
- if($("#radioSelltype2").attr('checked')==true){
- if($("#txtPstorage").val() >= 100){
- return 100;
- }else{
- return $("#txtPstorage").val();
- }
- }else{
- return 10000000;
- }
- }
- },
- area_id: {required: true},
- pyTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- kdTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- emsTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- slValiddays: {
- required: true,
- number: true,
- min: 1,
- max: 30
- }
- },
- messages: {
- txtPname: {required: "<tpl> $errProductNameEmpty </tpl>"},
- txtPstorage: {
- required: "<tpl> $errPstorage </tpl>",
- number: "<tpl> $errPstorage </tpl>",
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return "<tpl> $errPstorageByGroup </tpl>";
- }else{
- return "<tpl> $errPstorage </tpl>";
- }
- }
- },
- minimumBid: {required: "<tpl> $errMinimumbidWrong </tpl>",number: "<tpl> $errMinimumbidWrong </tpl>",min: "<tpl> $errMinimumbidWrong </tpl>"},
- price_step: {required: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>",number: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>",min: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>"},
- txtPprice: {required: "<tpl> $errPprice </tpl>",number: "<tpl> $errPprice </tpl>",min: "<tpl> $errPprice </tpl>"},
- txtGroupprice: {required: "<tpl> $errGroupprice </tpl>",number: "<tpl> $errGroupprice </tpl>",min: "<tpl> $errGroupprice </tpl>"},
- txtPoldprice: {required: "<tpl> $errPoldprice </tpl>",number: "<tpl> $errPoldprice </tpl>",min: "<tpl> $errPoldprice </tpl>"},
- txtGroupmincount: {required: "<tpl> $errGroupmincount </tpl>",number: "<tpl> $errGroupmincount </tpl>",min:"<tpl> $errGroupmincount </tpl>",max:"<tpl> $errGroupmincount </tpl>"},
- area_id: {required:"<tpl> $errProvince </tpl>"},
- pyTF: {required: "<tpl> $langProductPyTFIsEmpty </tpl>",number: "<tpl> $langProductPyTFIsEmpty </tpl>",min: "<tpl> $langProductPyTFIsEmpty </tpl>"},
- kdTF: {required: "<tpl> $langProductKdTFIsEmpty </tpl>",number: "<tpl> $langProductKdTFIsEmpty </tpl>",min: "<tpl> $langProductKdTFIsEmpty </tpl>"},
- emsTF: {required: "<tpl> $langProductEMSTFIsEmpty </tpl>",number: "<tpl> $langProductEMSTFIsEmpty </tpl>",min: "<tpl> $langProductEMSTFIsEmpty </tpl>"},
- slValiddays: {required: "<tpl> $errPSValiddays </tpl>",number: "<tpl> $errPSValiddays </tpl>",min: "<tpl> $errPSValiddays </tpl>",max: "<tpl> $errPSValiddays </tpl>"}
- },
- submitHandler: function() {
- var check_sign = false;//貨幣選擇狀態(tài)標(biāo)識(shí)
- var payment_check = false;//支付方式選擇狀態(tài)標(biāo)識(shí)
- var predeposit_check = false;//預(yù)存款選擇狀態(tài)標(biāo)識(shí)
- var payment_alert_sign = false;//支付方式是否拋出錯(cuò)誤信息標(biāo)識(shí)
-
- //判斷預(yù)存款選擇狀態(tài)
- if($('#pay_predeposit').attr('checked') == true){
- predeposit_check = true;
- }
- //驗(yàn)證支付方式的復(fù)選驗(yàn)證,是否全選,選中的支付方式是否選擇了支付貨幣種類
- $("#ownaddproduct input[@type=hidden]").each(function(){
- if(this.name.indexOf('payment_cur_') == 0){
- //判斷支付方式是否被選擇
- str = this.name.split('payment_cur_');//取支付方式名稱 str[1]
- if($('#txtPayment_'+str[1]).attr('checked') == true){
- //取該支付方式的貨幣種類字符串
- str2 = $('#payment_cur_'+str[1]).val().split('|');
- payment_check = true;//標(biāo)識(shí)有選擇的支付方式
- //判斷該選中的支付方式起碼有一個(gè)支持的貨幣種類被選擇
- for(i=0;i<str2.length;i++){
- if($('#currency_'+str2[i]).attr('checked') == true){
- check_sign = true;
- break;
- }
- }
- if(check_sign == false){//沒(méi)有選擇貨幣
- payment_alert_sign = true;
- }
- }
- }
- check_sign = false;
- });
-
- if(predeposit_check == true){//選擇預(yù)付款
- if(payment_alert_sign == false){//判斷是否有錯(cuò)誤拋出:沒(méi)有
- var oEditor = FCKeditorAPI.GetInstance('txtPinfo');
- $('#txtPinfo').val(oEditor.GetXHTML(true));
- if($('#txtPinfo').val() != ''){
- document.getElementById('ownaddproduct').submit();
- }else{
- alert('<tpl> $errPSInfoEmpty </tpl>');
- return false;
- }
- }else{
- alert('<tpl> $errPaymentSelCur </tpl>');
- return false;
- }
- }else{//沒(méi)有選擇預(yù)存款
- if(payment_alert_sign == false && payment_check == true){//判斷是否有錯(cuò)誤拋出并且選擇了起碼一種支付方式:沒(méi)有
- var oEditor = FCKeditorAPI.GetInstance('txtPinfo');
- $('#txtPinfo').val(oEditor.GetXHTML(true));
- if($('#txtPinfo').val() != ''){
- document.getElementById('ownaddproduct').submit();
- }else{
- alert('<tpl> $errPSInfoEmpty </tpl>');
- return false;
- }
- }else{
- alert('<tpl> $errPaymentSelCur </tpl>');
- return false;
- }
- }
- }
- });
- });
復(fù)制代碼
(2)后端
[php]
$this->objvalidate->validateparam = array(
array("input"=>$this->_input["txtPname"],"require"=>"true","message"=>$this->_lang['errPSNameEmpty']),
array("input"=>$this->_input["slPCId"],"require"=>"true","message"=>$this->_lang['errPcidEmpty']),
array("input"=>$this->_input["txtPinfo"],"require"=>"true","message"=>$this->_lang['errPSInfoEmpty']),
array("input"=>$this->_input["radioSelltype"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSSelltype']),
array("input"=>$this->_input["radioType"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSType']),
array("input"=>$this->_input["txtPstorage"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSstorage']),
//array("input"=>$this->_input["txtPprice"],"validator"=>"Currency","message"=>$this->_lang['errPSprice']),
array("input"=>$this->_input["txtGroupprice"],"validator"=>"Currency","message"=>$this->_lang['errPSGroupprice']),
array("input"=>$this->_input["txtPoldprice"],"validator"=>"Currency","message"=>$this->_lang['errPsPoldprice']),
array("input"=>$this->_input["txtPoldprice"],"validator"=>"Compare","operator"=>">=","to"=>$this->_input["txtGroupprice"],"message"=>$this->_lang['errPSPriceNoGroupPrice']),
array("input"=>$this->_input["txtGroupmincount"],"validator"=>"Number","message"=>$this->_lang['errPSGroupmincount']),
array("input"=>$this->_input["area_id"],"require"=>"true","message"=>$this->_lang['errPProductAreaIsEmpty']),
array("input"=>$this->_input["radioTransfee"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSTransfee']),
array("input"=>$this->_input["radioInvoices"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSInvoices']),
array("input"=>$this->_input["radioWarranty"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSWarranty']),
array("input"=>$this->_input["slValiddays"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSValiddays']),
array("input"=>$this->_input["chxAutopublish"],"validator"=>"Integer","message"=>$this->_lang['errPSAutopublish']),
array("input"=>$this->_input["chxRecommended"],"validator"=>"Integer","message"=>$this->_lang['errPSRecommended']));
$error = $this->objvalidate->validate();
if($error != ""){
$this->redirectPath("error","",$error);
}
[/php] |
|
|
|
|
|
|
|