* @Copyright (C) 2014 VINADES.,JSC. All rights reserved * @License GNU/GPL version 2 or any later version * @Createdate 2-9-2010 14:43 */ if (!defined('NV_IS_FILE_ADMIN')) { die('Stop!!!'); } $page_title = $lang_module['prounit']; $error = ""; $savecat = 0; $data = array("title" => "", 'note' => ""); $table_name = $db_config['prefix'] . "_" . $module_data . "_units"; $data['id'] = $nv_Request->get_int('id', 'post,get', 0); $savecat = $nv_Request->get_int('savecat', 'post', 0); if (!empty($savecat)) { $field_lang = nv_file_table($table_name); $data['title'] = nv_substr($nv_Request->get_title('title', 'post', '', 1), 0, 255); $data['note'] = $nv_Request->get_title('note', 'post', '', 1); if ($data['id'] == 0) { $listfield = ""; $listvalue = ""; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; $listfield .= ", " . $flang . "_" . $fname; if ($flang == NV_LANG_DATA) { $listvalue .= ", " . $db->quote($data[$fname]); } else { $listvalue .= ", " . $db->quote($data[$fname]); } } $sql = "INSERT INTO " . $table_name . " (id " . $listfield . ") VALUES (NULL " . $listvalue . ")";
function c_shop($mod_name, $nv3_shop) { global $global_config, $db; try { $err = ""; $nv3_table_name = NV3_PREFIX . '_' . $nv3_shop; $nv4_table_name = NV4_PREFIX . '_' . $mod_name; $field_lang = nv_file_table($nv4_table_name . '_catalogs'); $listfield = ''; $listvalue = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; $listfield .= ', ' . $flang . '_' . $fname; $listvalue .= ', :' . $flang . '_' . $fname; } $db->query('TRUNCATE ' . $nv4_table_name . '_catalogs'); $_query = $db->query('SELECT `catid`, `parentid`, `image`, `thumbnail`, `weight`, `order`, `lev`, `viewcat`, `numsubcat`, `subcatid`, `inhome`, `numlinks`, `admins`, `add_time`, `edit_time`, `who_view`, `groups_view`, `vi_title`, `vi_alias`, `vi_description`, `vi_keywords` FROM `' . $nv3_table_name . '_catalogs`'); while ($data = $_query->fetch()) { $data = array_map('unfixdb', $data); $data['newday'] = 3; $data['typeprice'] = 1; $data['form'] = ''; $data['group_price'] = ''; $data['cat_allow_point'] = 0; $data['cat_number_point'] = 0; $data['cat_number_product'] = 0; $sql = "INSERT INTO " . $nv4_table_name . '_catalogs' . " (catid, parentid, image, weight, sort, lev, viewcat, numsubcat, subcatid, inhome, numlinks, newday, typeprice, form, group_price,viewdescriptionhtml, admins, add_time, edit_time, groups_view, cat_allow_point, cat_number_point, cat_number_product " . $listfield . " )\n\t\t\tVALUES (" . $data['catid'] . ", :parentid, :image," . $data['weight'] . ", " . $data['order'] . ", " . $data['lev'] . ", :viewcat, " . $data['numsubcat'] . ", :subcatid, '1', '4', :newday, :typeprice, :form, :group_price, :viewdescriptionhtml,:admins, " . NV_CURRENTTIME . ", " . NV_CURRENTTIME . ", :groups_view, :cat_allow_point, :cat_number_point, :cat_number_product" . $listvalue . ")"; $data_insert = array(); $data_insert['parentid'] = $data['parentid']; $data_insert['image'] = $data['image']; $data_insert['subcatid'] = $data['subcatid']; $data_insert['viewcat'] = 'viewcat_page_list'; $data_insert['newday'] = $data['newday']; $data_insert['typeprice'] = $data['typeprice']; $data_insert['form'] = $data['form']; $data_insert['group_price'] = $data['group_price']; $data_insert['viewdescriptionhtml'] = ''; $data_insert['admins'] = $data['admins']; if ($data['who_view'] == 1) { $data_insert['groups_view'] = '2'; } if ($data['who_view'] == 2) { $data_insert['groups_view'] = '3'; } else { $data_insert['groups_view'] = '6'; } $data_insert['cat_allow_point'] = $data['cat_allow_point']; $data_insert['cat_number_point'] = $data['cat_number_point']; $data_insert['cat_number_product'] = $data['cat_number_product']; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if ($fname == 'descriptionhtml') { $data_insert[$flang . '_' . $fname] = ''; } else { if (!isset($data[$flang . '_' . $fname])) { $data_insert[$flang . '_' . $fname] = $data['vi' . '_' . $fname]; } else { $data_insert[$flang . '_' . $fname] = $data[$flang . '_' . $fname]; } } } $newcatid = intval($db->insert_id($sql, 'catid', $data_insert)); if (empty($newcatid)) { $err .= "Lỗi insert" . $nv4_table_name . '_catalogs' . " </br>"; } } // bang nv3_shops_units $db->query('TRUNCATE ' . $nv4_table_name . '_units'); $field_lang = nv_file_table($nv4_table_name . '_units'); $listfield = ''; $listvalue = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; $listfield .= ', ' . $flang . '_' . $fname; $listvalue .= ', :' . $flang . '_' . $fname; } $_query = $db->query('SELECT id, vi_title, vi_note FROM ' . $nv3_table_name . '_units'); while ($data = $_query->fetch()) { $data['vi_note'] = ''; $sql = "INSERT INTO " . $nv4_table_name . '_units' . " (id " . $listfield . ") VALUES (" . $data['id'] . $listvalue . ")"; $data_insert = array(); foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if (!isset($data[$flang . '_' . $fname])) { $data_insert[$flang . '_' . $fname] = $data['vi' . '_' . $fname]; } else { $data_insert[$flang . '_' . $fname] = $data[$flang . '_' . $fname]; } } $newcatid = intval($db->insert_id($sql, 'id', $data_insert)); if (empty($newcatid)) { $err .= "Lỗi insert" . $nv4_table_name . '_units' . " </br>"; } } // bang nv3_shops_rows $db->query('TRUNCATE ' . $nv4_table_name . '_rows'); $field_lang = nv_file_table($nv4_table_name . '_rows'); $listfield = ''; $listvalue = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if ($fname == 'gift') { $listfield .= ',' . $flang . '_' . $fname . '_content'; $listvalue .= ',:' . $flang . '_' . $fname . '_content'; } else { $listfield .= ',' . $flang . '_' . $fname; $listvalue .= ',:' . $flang . '_' . $fname; } } $_query = $db->query("SELECT id, listcatid, group_id, user_id, source_id, addtime, edittime, status, publtime, exptime, archive, product_number, product_price, product_discounts, money_unit, product_unit, homeimgfile, homeimgthumb, homeimgalt, otherimage, imgposition, copyright, inhome, allowed_comm, allowed_rating, ratingdetail, allowed_send, allowed_print, allowed_save, hitstotal, hitscm, hitslm, showprice, vi_title, vi_alias, vi_description, vi_keywords, vi_note, vi_hometext, vi_bodytext, vi_address, vi_warranty, vi_promotional FROM " . $nv3_table_name . "_rows"); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_rows' . " (id, listcatid, user_id, addtime, edittime,\n\t\tstatus, publtime, exptime, archive, product_code, product_number, product_price,\n\t\tprice_config, money_unit, product_unit, product_weight, weight_unit, discount_id,\n\t\thomeimgfile, homeimgthumb, homeimgalt,otherimage,imgposition, copyright,gift_from,gift_to,\n\t\tinhome,allowed_comm, allowed_rating, ratingdetail, allowed_send, allowed_print,\n\t\tallowed_save, hitstotal, hitscm, hitslm, showprice " . $listfield . ")\n\t\t\tVALUES ( " . $row['id'] . " ,\n\t\t\t:listcatid,\n\t\t\t" . intval($row['user_id']) . ",\n\t\t\t" . intval($row['addtime']) . ",\n\t\t\t" . intval($row['edittime']) . ",\n\t\t\t" . intval($row['status']) . ",\n\t\t\t" . intval($row['publtime']) . ",\n\t\t\t" . intval($row['exptime']) . ",\n\t\t\t" . intval($row['archive']) . ",\n\t\t\t:product_code,\n\t\t\t" . intval($row['product_number']) . ",\n\t\t\t:product_price,\n\t\t\t:price_config,\n\t\t\t:money_unit,\n\t\t\t" . intval($row['product_unit']) . ",\n\t\t\t:product_weight,\n\t\t\t:weight_unit,\n\t\t\t" . intval(0) . ",\n\t\t\t:homeimgfile,\n\t\t\t:homeimgthumb,\n\t\t\t:homeimgalt,\n\t\t\t:otherimage,\n\t\t\t" . intval($row['imgposition']) . ",\n\t\t\t" . intval($row['copyright']) . ",\n\t\t\t" . intval(NV_CURRENTTIME) . ",\n\t\t\t" . intval(NV_CURRENTTIME) . ",\n\t\t\t" . intval($row['inhome']) . ",\n\t\t\t:allowed_comm,\n\t\t\t" . intval($row['allowed_rating']) . ",\n\t\t\t:ratingdetail,\n\t\t\t" . intval($row['allowed_send']) . ",\n\t\t\t" . intval($row['allowed_print']) . ",\n\t\t\t" . intval($row['allowed_save']) . ",\n\t\t\t" . intval($row['hitstotal']) . ",\n\t\t\t" . intval($row['hitscm']) . ",\n\t\t\t" . intval($row['hitslm']) . ",\n\t\t\t" . intval($row['showprice']) . "\n\t\t\t" . $listvalue . "\n\t\t\t)"; $data_insert = array(); $data_insert['listcatid'] = $row['listcatid']; $data_insert['product_code'] = ''; $data_insert['product_price'] = $row['product_price']; $data_insert['price_config'] = ''; $data_insert['product_weight'] = 0; $data_insert['weight_unit'] = ''; $data_insert['money_unit'] = $row['money_unit']; $data_insert['homeimgfile'] = $row['homeimgfile']; $data_insert['homeimgalt'] = $row['homeimgalt']; $data_insert['otherimage'] = $row['otherimage']; $data_insert['ratingdetail'] = $row['ratingdetail']; $data_insert['allowed_comm'] = 6; //kiểm tra ảnh thumb $data_insert['homeimgthumb'] = 0; if (!empty($row['homeimgfile']) and !nv_is_url($row['homeimgfile']) and is_file(NV_DOCUMENT_ROOT . '/uploads/shops/' . $row['homeimgfile'])) { if (file_exists(NV_ROOTDIR . '/' . NV_FILES_DIR . '/shops/' . $row['homeimgfile'])) { $data_insert['homeimgthumb'] = 1; } else { $data_insert['homeimgthumb'] = 2; } } elseif (!empty($row['homeimgfile']) and nv_is_url($row['homeimgfile'])) { $data_insert['homeimgthumb'] = 3; } else { $row['homeimgfile'] = ''; } foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if ($fname == 'gift') { $fname = $fname . '_content'; } if ($fname == 'gift_content') { $data_insert[$flang . '_' . $fname] = ''; } else { if (!isset($data[$flang . '_' . $fname])) { $data_insert[$flang . '_' . $fname] = $row['vi' . '_' . $fname]; } else { $data_insert[$flang . '_' . $fname] = $row[$flang . '_' . $fname]; } } } $contentid = $db->insert_id($sql, 'id', $data_insert); if (empty($contentid)) { $err .= "Lỗi insert" . $nv4_table_name . '_rows' . " </br>"; } } //bảng nv3_shops_block $db->query('TRUNCATE ' . $nv4_table_name . '_block'); // Fetch Assoc $_sql = 'SELECT bid, id, weight FROM ' . $nv3_table_name . '_block'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_block' . " (bid, id, weight) VALUES (:bid,:id,:weight)"; $data_insert = array(); $data_insert['bid'] = $row['bid']; $data_insert['id'] = $row['id']; $data_insert['weight'] = $row['weight']; $contentid = $db->insert_id($sql, 'bid', $data_insert); } //bang nv3_shops_block_cat $db->query('TRUNCATE ' . $nv4_table_name . '_block_cat'); $field_lang = nv_file_table($nv4_table_name . '_block_cat'); $listfield = ''; $listvalue = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; $listfield .= ', ' . $flang . '_' . $fname; $listvalue .= ', :' . $flang . '_' . $fname; } $_sql = 'SELECT bid, adddefault, image, thumbnail, weight, add_time, edit_time, vi_title, vi_alias, vi_description, vi_keywords FROM ' . $nv3_table_name . '_block_cat'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . "_block_cat(bid, adddefault, image, weight, add_time, edit_time " . $listfield . ")\n\t\t\t\tVALUES (:bid,:adddefault,:image,:weight,:add_time,:edit_time" . $listvalue . ")"; $data_insert = array(); $data_insert['bid'] = $row['bid']; $data_insert['adddefault'] = $row['adddefault']; $data_insert['image'] = $row['image']; $data_insert['weight'] = $row['weight']; $data_insert['add_time'] = $row['add_time']; $data_insert['edit_time'] = $row['edit_time']; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if (!isset($data[$flang . '_' . $fname])) { $data_insert[$flang . '_' . $fname] = $row['vi' . '_' . $fname]; } else { $data_insert[$flang . '_' . $fname] = $row[$flang . '_' . $fname]; } } $contentid = $db->insert_id($sql, 'bid', $data_insert); if (empty($contentid)) { $err .= "Lỗi insert" . $nv4_table_name . '_block_cat' . " </br>"; } } //bảng nv3_shops_group $db->query('TRUNCATE ' . $nv4_table_name . '_group'); $field_lang = nv_file_table($nv4_table_name . '_group'); $listfield = ''; $listvalue = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; $listfield .= ', ' . $flang . '_' . $fname; $listvalue .= ', :' . $flang . '_' . $fname; } // Fetch Assoc $_sql = 'SELECT `groupid`, `parentid`, `cateid`, `image`, `thumbnail`, `weight`, `order`, `lev`, `viewgroup`, `numsubgroup`, `subgroupid`, `inhome`, `numlinks`, `admins`, `add_time`, `edit_time`, `who_view`, `groups_view`, `numpro`, `vi_title`, `vi_alias`, `vi_description`, `vi_keywords` FROM `' . $nv3_table_name . '_group`'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_group' . "(groupid, parentid, image, weight, sort, lev, viewgroup, numsubgroup, subgroupid, inhome, indetail, add_time, edit_time, numpro, in_order, is_require" . $listfield . ")\n\t\t\t\tVALUES (:groupid,:parentid,:image,:weight,:sort,:lev,:viewgroup,:numsubgroup,:subgroupid,:inhome,:indetail,:add_time,:edit_time,:numpro,:in_order,:is_require" . $listvalue . ")"; $data_insert = array(); $data_insert['groupid'] = $row['groupid']; $data_insert['parentid'] = $row['parentid']; $data_insert['image'] = $row['image']; $data_insert['weight'] = $row['weight']; $data_insert['sort'] = 0; $data_insert['lev'] = $row['lev']; $data_insert['viewgroup'] = $row['viewgroup']; $data_insert['numsubgroup'] = $row['numsubgroup']; $data_insert['subgroupid'] = $row['subgroupid']; $data_insert['inhome'] = $row['inhome']; $data_insert['indetail'] = 1; $data_insert['add_time'] = $row['add_time']; $data_insert['edit_time'] = $row['edit_time']; $data_insert['numpro'] = $row['numpro']; $data_insert['in_order'] = 1; $data_insert['is_require'] = ''; foreach ($field_lang as $field_lang_i) { list($flang, $fname) = $field_lang_i; if (!isset($data[$flang . '_' . $fname])) { $data_insert[$flang . '_' . $fname] = $row['vi' . '_' . $fname]; } else { $data_insert[$flang . '_' . $fname] = $row[$flang . '_' . $fname]; } } $contentid = $db->insert_id($sql, 'bid', $data_insert); if (empty($contentid)) { $err .= "Lỗi insert" . $nv4_table_name . "_group </br>"; } } //bảng nv3_shops_orders $db->query('TRUNCATE ' . $nv4_table_name . '_orders'); // Fetch Assoc $_sql = 'SELECT * FROM ' . $nv3_table_name . '_orders'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_orders' . " (order_id, order_code, lang,\n\t\t\t\torder_name, order_email, order_phone, order_note, user_id, admin_id,\n\t\t\t\tshop_id, who_is, unit_total, order_total, order_time, edit_time,\n\t\t\t\tpostip, order_view, transaction_status, transaction_id, transaction_count\n\t\t\t\t) VALUES (\n\t\t\t\t:order_id, :order_code,:lang, :order_name, :order_email, :order_phone, :order_note,\n\t\t\t\t:user_id, :admin_id, :shop_id,:who_is, :unit_total, :order_total,\n\t\t\t\t:order_time, :edit_time, :postip, :order_view, :transaction_status, :transaction_id,:transaction_count\n\t\t\t\t)"; $data_insert = array(); $data_insert['order_id'] = $row['order_id']; $data_insert['order_code'] = $row['order_code']; $data_insert['lang'] = $row['lang']; $data_insert['order_name'] = $row['order_name']; $data_insert['order_email'] = $row['order_email']; $data_insert['order_phone'] = $row['order_phone']; $data_insert['order_note'] = $row['order_note']; $data_insert['user_id'] = $row['user_id']; $data_insert['admin_id'] = $row['admin_id']; $data_insert['shop_id'] = $row['shop_id']; $data_insert['who_is'] = $row['who_is']; $data_insert['unit_total'] = $row['unit_total']; $data_insert['order_total'] = $row['order_total']; $data_insert['order_time'] = $row['order_time']; $data_insert['edit_time'] = 0; $data_insert['postip'] = $row['postip']; $data_insert['order_view'] = $row['view']; $data_insert['transaction_status'] = $row['transaction_status']; $data_insert['transaction_id'] = $row['transaction_id']; $data_insert['transaction_count'] = $row['transaction_count']; $order_id = $db->insert_id($sql, 'order_id', $data_insert); if (!empty($order_id)) { // insert vào bảng thông tin đơn hàng $proid = explode('|', $row['listid']); $listnum = explode('|', $row['listnum']); $listprice = explode('|', $row['listprice']); foreach ($proid as $i => $pid) { $listnum_item = $listnum[$i]; $listprice_item = $listprice[$i]; $sql_d = 'INSERT INTO ' . $nv4_table_name . '_orders_id( order_id, proid, num, price, discount_id ) VALUES ( :order_id, :proid, :num, :price, :discount_id )'; $data_insert_d = array(); $data_insert_d['order_id'] = $row['order_id']; $data_insert_d['proid'] = $pid; $data_insert_d['num'] = $listnum_item; $data_insert_d['price'] = $listprice_item; $data_insert_d['discount_id'] = 0; $order_i = $db->insert_id($sql_d, 'id', $data_insert_d); } } else { $err .= "Lỗi insert" . $nv4_table_name . "_orders </br>"; } } // bảng nv3_shops_payment $db->query('TRUNCATE ' . $nv4_table_name . '_payment'); // Fetch Assoc $_sql = 'SELECT * FROM ' . $nv3_table_name . '_payment'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_payment' . "\n\t\t(payment, paymentname, domain, active, weight, config, images_button)\n\t\tVALUES (:payment,:paymentname,:domain,:active,:weight,:config,:images_button)"; $data_insert = array(); $data_insert['payment'] = $row['payment']; $data_insert['paymentname'] = $row['paymentname']; $data_insert['domain'] = $row['domain']; $data_insert['active'] = $row['active']; $data_insert['weight'] = $row['weight']; $data_insert['config'] = $row['config']; $data_insert['images_button'] = $row['images_button']; $contentid = $db->insert_id($sql, 'order_id', $data_insert); } //bảng nv3_shops_transaction $db->query('TRUNCATE ' . $nv4_table_name . '_transaction'); // Fetch Assoc $_sql = 'SELECT * FROM ' . $nv3_table_name . '_transaction'; $_query = $db->query($_sql); while ($row = $_query->fetch()) { $sql = "INSERT INTO " . $nv4_table_name . '_transaction' . "\n\t\t(transaction_id, transaction_time, transaction_status,\n\t\torder_id, userid, payment, payment_id, payment_time,\n\t\tpayment_amount, payment_data)\n\t\tVALUES (:transaction_id,:transaction_time,:transaction_status,:order_id,\n\t\t:userid,:payment,:payment_id,:payment_time,:payment_amount,:payment_data)"; $data_insert = array(); $data_insert['transaction_id'] = $row['transaction_id']; $data_insert['transaction_time'] = $row['transaction_time']; $data_insert['transaction_status'] = $row['transaction_status']; $data_insert['order_id'] = $row['order_id']; $data_insert['userid'] = $row['userid']; $data_insert['payment'] = $row['payment']; $data_insert['payment_id'] = $row['payment_id']; $data_insert['payment_time'] = $row['payment_time']; $data_insert['payment_amount'] = $row['payment_amount']; $data_insert['payment_data'] = $row['payment_data']; $transaction_id = $db->insert_id($sql, 'transaction_id', $data_insert); if (empty($transaction_id)) { $err .= "Lỗi insert" . $nv4_table_name . "_transaction </br>"; } } } catch (PDOException $e) { $err .= $e->getMessage(); //trigger_error( $e->getMessage( ) ); } return $err; }