#---- 複製商品資料 case "opCopy": opCopy($sn); XoopsCache::clear(); redirect_header($_SESSION['return_url'], 3, "複製成功!!"); exit; ``` 2. 二、函數 1. opCopy($sn = "") ``` ######################################## # 複製商品資料 ######################################## function opCopy($sn = "") { global $xoopsDB, $xoopsTpl, $module_name, $ugmKind, $xoTheme; #強制關除錯 //ugm_module_debug_mode(0); //----------------------------------*/ #得到商品資料 $row = get_ugm_module_tbl($sn, "cnu_show_prod"); $row['date'] = strtotime("now"); $row['enable'] = 1; if($row['sn']){ #複寫商品資料 $sql = "insert into " . $xoopsDB->prefix("cnu_show_prod") . " (`title`,`youtube`,`kind`,`date`,`enable`,`choice`,`sort`,`unit`,`standard`,`size`,`content`,`summary`) values ('{$row['title']}','{$row['youtube']}','{$row['kind']}','{$row['date']}','{$row['enable']}','{$row['choice']}','{$row['sort']}','{$row['unit']}','{$row['standard']}','{$row['size']}','{$row['content']}','{$row['summary']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 $copy_sn = $xoopsDB->getInsertId(); #複製圖片 $col_name = "prod"; $sql = "select * from " . $xoopsDB->prefix("cnu_show_files_center") . " where col_name='{$col_name}' and col_sn='{$sn}'"; //die($sql); $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); $row = $xoopsDB->fetchArray($result); #檢查是否有圖檔 if($row['files_sn']){ #寫入資料庫 $ext = $row['file_type'] == "image/png" ? "png" :"jpg"; $file_name = "prod_{$copy_sn}_1.{$ext}"; $sql = "insert into " . $xoopsDB->prefix("cnu_show_files_center") . " (`col_name` , `col_sn` ,`sort` ,`kind` , `file_name`,`file_type`,`file_size`,`description`,`counter`,`original_filename`,`hash_filename`,`sub_dir`) values ('{$row['col_name']}' ,'{$copy_sn}' ,'{$row['sort']}' , '{$row['kind']}','{$file_name}' ,'{$row['file_type']}','{$row['file_size']}','{$row['description']}',0,'{$row['original_filename']}','{$row['hash_filename']}','{$row['sub_dir']}')";//die($sql); $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 //$pic_sn = $xoopsDB->getInsertId();; #複製實體檔案 copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/{$file_name}"); copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/thumbs/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/thumbs/{$file_name}"); } #複製pdf $col_name = "prodPdf"; $sql = "select * from " . $xoopsDB->prefix("cnu_show_files_center") . " where col_name='{$col_name}' and col_sn='{$sn}'"; //die($sql); $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); $row = $xoopsDB->fetchArray($result); if($row['files_sn']){ #寫入資料庫 $file_name = "prodPdf_{$copy_sn}_1.pdf"; $sql = "insert into " . $xoopsDB->prefix("cnu_show_files_center") . " (`col_name` , `col_sn` ,`sort` ,`kind` , `file_name`,`file_type`,`file_size`,`description`,`counter`,`original_filename`,`hash_filename`,`sub_dir`) values ('{$row['col_name']}' ,'{$copy_sn}' ,'{$row['sort']}' , '{$row['kind']}','{$file_name}' ,'{$row['file_type']}','{$row['file_size']}','{$row['description']}',0,'{$row['original_filename']}','{$row['hash_filename']}','{$row['sub_dir']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 $pdf_sn = $xoopsDB->getInsertId(); #複製實體檔案 if (copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/file/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/file/{$file_name}")) { // 檔案複製成功 } else { // 檔案複製失敗 } } }else{ redirect_header($_SESSION['return_url'], 3, "複製商品失敗"); } return; } ``` 2.
######################################## # 複製商品資料 ######################################## function opCopy($sn = "") { global $xoopsDB, $xoopsTpl, $module_name, $ugmKind, $xoTheme; #強制關除錯 //ugm_module_debug_mode(0); //----------------------------------*/ #得到商品資料 $row = get_ugm_module_tbl($sn, "cnu_show_prod"); $row['date'] = strtotime("now"); $row['enable'] = 1; if($row['sn']){ #複寫商品資料 $sql = "insert into " . $xoopsDB->prefix("cnu_show_prod") . " (`title`,`youtube`,`kind`,`date`,`enable`,`choice`,`sort`,`unit`,`standard`,`size`,`content`,`summary`) values ('{$row['title']}','{$row['youtube']}','{$row['kind']}','{$row['date']}','{$row['enable']}','{$row['choice']}','{$row['sort']}','{$row['unit']}','{$row['standard']}','{$row['size']}','{$row['content']}','{$row['summary']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 $copy_sn = $xoopsDB->getInsertId(); #複製圖片 $col_name = "prod"; $sql = "select * from " . $xoopsDB->prefix("cnu_show_files_center") . " where col_name='{$col_name}' and col_sn='{$sn}'"; //die($sql); $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); $row = $xoopsDB->fetchArray($result); #檢查是否有圖檔 if($row['files_sn']){ #寫入資料庫 $ext = $row['file_type'] == "image/png" ? "png" :"jpg"; $file_name = "prod_{$copy_sn}_1.{$ext}"; $sql = "insert into " . $xoopsDB->prefix("cnu_show_files_center") . " (`col_name` , `col_sn` ,`sort` ,`kind` , `file_name`,`file_type`,`file_size`,`description`,`counter`,`original_filename`,`hash_filename`,`sub_dir`) values ('{$row['col_name']}' ,'{$copy_sn}' ,'{$row['sort']}' , '{$row['kind']}','{$file_name}' ,'{$row['file_type']}','{$row['file_size']}','{$row['description']}',0,'{$row['original_filename']}','{$row['hash_filename']}','{$row['sub_dir']}')";//die($sql); $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 //$pic_sn = $xoopsDB->getInsertId();; #複製實體檔案 copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/{$file_name}"); copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/thumbs/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/thumbs/{$file_name}"); } #複製pdf $col_name = "prodPdf"; $sql = "select * from " . $xoopsDB->prefix("cnu_show_files_center") . " where col_name='{$col_name}' and col_sn='{$sn}'"; //die($sql); $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); $row = $xoopsDB->fetchArray($result); if($row['files_sn']){ #寫入資料庫 $file_name = "prodPdf_{$copy_sn}_1.pdf"; $sql = "insert into " . $xoopsDB->prefix("cnu_show_files_center") . " (`col_name` , `col_sn` ,`sort` ,`kind` , `file_name`,`file_type`,`file_size`,`description`,`counter`,`original_filename`,`hash_filename`,`sub_dir`) values ('{$row['col_name']}' ,'{$copy_sn}' ,'{$row['sort']}' , '{$row['kind']}','{$file_name}' ,'{$row['file_type']}','{$row['file_size']}','{$row['description']}',0,'{$row['original_filename']}','{$row['hash_filename']}','{$row['sub_dir']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error()); //取得最後新增資料的流水編號 $pdf_sn = $xoopsDB->getInsertId(); #複製實體檔案 if (copy(XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/file/{$row['file_name']}", XOOPS_ROOT_PATH."/uploads/{$module_name}/prod/file/{$file_name}")) { // 檔案複製成功 } else { // 檔案複製失敗 } } }else{ redirect_header($_SESSION['return_url'], 3, "複製商品失敗"); } return; } ``` 2.