PageRenderTime 30ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/NukeViet3.3/modules/shops/admin/content.php

http://nuke-viet.googlecode.com/
PHP | 705 lines | 644 code | 42 blank | 19 comment | 94 complexity | a7be01f94b8d59a6c172069f016b67f6 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-9-2010 14:43
  7. */
  8. if (!defined('NV_IS_FILE_ADMIN'))
  9. die('Stop!!!');
  10. if (defined('NV_EDITOR'))
  11. {
  12. require_once (NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php');
  13. }
  14. $table_name = $db_config['prefix'] . "_" . $module_data . "_rows";
  15. $month_dir_module = nv_mkdir(NV_UPLOADS_REAL_DIR . '/' . $module_name, date("Y_m"), true);
  16. $contents = "";
  17. $array_block_cat_module = array();
  18. $id_block_content = array();
  19. $sql = "SELECT bid, adddefault, " . NV_LANG_DATA . "_title FROM `" . $db_config['prefix'] . "_" . $module_data . "_block_cat` ORDER BY `weight` ASC";
  20. $result = $db->sql_query($sql);
  21. while (list($bid_i, $adddefault_i, $title_i) = $db->sql_fetchrow($result))
  22. {
  23. $array_block_cat_module[$bid_i] = $title_i;
  24. if ($adddefault_i)
  25. {
  26. $id_block_content[] = $bid_i;
  27. }
  28. }
  29. $catid = $nv_Request->get_int('catid', 'get', 0);
  30. $parentid = $nv_Request->get_int('parentid', 'get', 0);
  31. $sql = "SELECT numsubcat FROM `" . $db_config['prefix'] . "_" . $module_data . "_catalogs` WHERE catid=" . $db->dbescape($parentid) . "";
  32. $result = $db->sql_query($sql);
  33. list($subcatid) = $db->sql_fetchrow($result);
  34. if ($subcatid > 0)
  35. {
  36. Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name);
  37. die();
  38. }
  39. $rowcontent = array("id" => 0, "listcatid" => $catid, "group_id" => "", "user_id" => $admin_info['admin_id'], "source_id" => 0, 'shopcat_id' => 0, 'com_id' => 0, "addtime" => NV_CURRENTTIME, "edittime" => NV_CURRENTTIME, "status" => 0, "publtime" => NV_CURRENTTIME, "exptime" => 0, "archive" => 1, "product_code" => "", "product_number" => 1, "product_price" => 1, "product_discounts" => 0, "money_unit" => "", "product_unit" => "", "homeimgfile" => "", "homeimgthumb" => "", "homeimgalt" => "", "imgposition" => 0, "copyright" => 0, "inhome" => 1, "allowed_comm" => "", "allowed_rating" => 1, "ratingdetail" => "0", "allowed_send" => 1, "allowed_print" => 1, "allowed_save" => 1, "hitstotal" => 0, "hitscm" => 0, "hitslm" => 0, "showprice" => 1, "com_id" => 0, "title" => "", "alias" => "", "hometext" => "", "bodytext" => "", "note" => "", "keywords" => "", "address" => "", "description" => "");
  40. $rowcontent['sourcetext'] = "";
  41. $page_title = $lang_module['content_add'];
  42. $error = "";
  43. $groups_list = nv_groups_list();
  44. $rowcontent['id'] = $nv_Request->get_int('id', 'get,post', 0);
  45. if ($nv_Request->get_int('save', 'post') == 1)
  46. {
  47. $field_lang = nv_file_table($table_name);
  48. $id_block_content = array_unique($nv_Request->get_typed_array('bids', 'post', 'int', array()));
  49. $rowcontent['listcatid'] = $nv_Request->get_int('catid', 'post', 0);
  50. $group_id = array_unique($nv_Request->get_typed_array('groupids', 'post', 'int', array()));
  51. $rowcontent['group_id'] = implode(",", $group_id);
  52. if (!empty($rowcontent['group_id']))
  53. $rowcontent['group_id'] = $rowcontent['group_id'] . ',';
  54. $rowcontent['author'] = filter_text_input('author', 'post', '', 1);
  55. $rowcontent['source_id'] = $nv_Request->get_int('sourceid', 'post', 0);
  56. $rowcontent['showprice'] = $nv_Request->get_int('showprice', 'post', 0);
  57. $rowcontent['showorder'] = $nv_Request->get_int('showorder', 'post', 0);
  58. if ($rowcontent['source_id'] == 0)
  59. {
  60. $rowcontent['sourcetext'] = filter_text_input('sourcetext', 'post', '');
  61. if (!empty($rowcontent['sourcetext']))
  62. {
  63. list($rowcontent['source_id']) = $db->sql_fetchrow($db->sql_query("SELECT `sourceid` FROM `" . $db_config['prefix'] . "_" . $module_data . "_sources` WHERE `" . NV_LANG_DATA . "_title`=" . $db->dbescape($rowcontent['sourcetext']) . ""));
  64. }
  65. }
  66. if (intval($rowcontent['source_id']) > 0)
  67. $rowcontent['sourcetext'] = "";
  68. $publ_date = filter_text_input('publ_date', 'post', '');
  69. $exp_date = filter_text_input('exp_date', 'post', '');
  70. if (!empty($publ_date) and preg_match("/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/", $publ_date, $m))
  71. {
  72. $phour = $nv_Request->get_int('phour', 'post', 0);
  73. $pmin = $nv_Request->get_int('pmin', 'post', 0);
  74. $rowcontent['publtime'] = mktime($phour, $pmin, 0, $m[2], $m[1], $m[3]);
  75. }
  76. else
  77. {
  78. $rowcontent['publtime'] = NV_CURRENTTIME;
  79. }
  80. if (!empty($exp_date) and preg_match("/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/", $exp_date, $m))
  81. {
  82. $ehour = $nv_Request->get_int('ehour', 'post', 0);
  83. $emin = $nv_Request->get_int('emin', 'post', 0);
  84. $rowcontent['exptime'] = mktime($ehour, $emin, 0, $m[2], $m[1], $m[3]);
  85. }
  86. else
  87. {
  88. $rowcontent['exptime'] = 0;
  89. }
  90. $rowcontent['archive'] = $nv_Request->get_int('archive', 'post', 0);
  91. if ($rowcontent['archive'] > 0)
  92. {
  93. $rowcontent['archive'] = ($rowcontent['exptime'] > NV_CURRENTTIME) ? 1 : 2;
  94. }
  95. $rowcontent['title'] = filter_text_input('title', 'post', '', 1);
  96. $rowcontent['note'] = filter_text_input('note', 'post', '', 1);
  97. $alias = filter_text_input('alias', 'post', '');
  98. $rowcontent['alias'] = ($alias == "") ? change_alias($rowcontent['title']) : change_alias($alias);
  99. $rowcontent['hometext'] = filter_text_input('hometext', 'post', '');
  100. $rowcontent['product_code'] = change_alias($nv_Request->get_string('product_code', 'post', 0));
  101. $rowcontent['product_number'] = $nv_Request->get_int('product_number', 'post', 0);
  102. $rowcontent['product_price'] = $nv_Request->get_string('product_price', 'post', 0);
  103. $rowcontent['product_price'] = preg_replace('/([^0-9\.])/', '', $rowcontent['product_price']);
  104. $rowcontent['product_discounts'] = $nv_Request->get_int('product_discounts', 'post', 0);
  105. $rowcontent['money_unit'] = $nv_Request->get_string('money_unit', 'post', "");
  106. $rowcontent['product_unit'] = $nv_Request->get_int('product_unit', 'post', 0);
  107. $rowcontent['homeimgfile'] = filter_text_input('homeimg', 'post', '');
  108. $rowcontent['homeimgalt'] = filter_text_input('homeimgalt', 'post', '', 1);
  109. $rowcontent['address'] = filter_text_input('address', 'post', '', 1);
  110. $bodytext = $nv_Request->get_string('bodytext', 'post', '');
  111. $rowcontent['bodytext'] = defined('NV_EDITOR') ? nv_nl2br($bodytext, '') : nv_nl2br(nv_htmlspecialchars(strip_tags($bodytext)), '<br />');
  112. $sourcetext = filter_text_input('sourcetext', 'post', '', 1);
  113. $rowcontent['copyright'] = ( int )$nv_Request->get_bool('copyright', 'post');
  114. $rowcontent['inhome'] = ( int )$nv_Request->get_bool('inhome', 'post');
  115. $rowcontent['allowed_comm'] = $nv_Request->get_int('allowed_comm', 'post', 0);
  116. $rowcontent['allowed_rating'] = ( int )$nv_Request->get_bool('allowed_rating', 'post');
  117. $rowcontent['allowed_send'] = ( int )$nv_Request->get_bool('allowed_send', 'post');
  118. $rowcontent['allowed_print'] = ( int )$nv_Request->get_bool('allowed_print', 'post');
  119. $rowcontent['allowed_save'] = ( int )$nv_Request->get_bool('allowed_save', 'post');
  120. $rowcontent['keywords'] = filter_text_input('keywords', 'post', '', 1);
  121. if (empty($rowcontent['title']))
  122. {
  123. $error = $lang_module['error_title'];
  124. }
  125. elseif (empty($rowcontent['listcatid']))
  126. {
  127. $error = $lang_module['error_cat'];
  128. }
  129. elseif (trim(strip_tags($rowcontent['bodytext'])) == "")
  130. {
  131. $error = $lang_module['error_bodytext'];
  132. }
  133. elseif ($rowcontent['product_unit'] == 0)
  134. {
  135. $error = $lang_module['error_product_unit'];
  136. }
  137. elseif ($rowcontent['product_price'] <= 0 or !preg_match("/^([0-9]+)(\.[0-9]+)?$/", $rowcontent['product_price']))
  138. {
  139. $error = $lang_module['error_product_price'];
  140. }
  141. elseif ($rowcontent['product_discounts'] < 0)
  142. {
  143. $error = $lang_module['error_product_discounts'];
  144. }
  145. else
  146. {
  147. if (!empty($rowcontent['sourcetext']))
  148. {
  149. list($weight) = $db->sql_fetchrow($db->sql_query("SELECT max(`weight`) FROM `" . $db_config['prefix'] . "_" . $module_data . "_sources`"));
  150. $weight = intval($weight) + 1;
  151. $datasource['title'] = $rowcontent['sourcetext'];
  152. $field_lang_source = nv_file_table($db_config['prefix'] . "_" . $module_data . "_sources");
  153. $listfield = "";
  154. $listvalue = "";
  155. foreach ($field_lang_source as $field_lang_i)
  156. {
  157. list($flang, $fname) = $field_lang_i;
  158. $listfield .= ", `" . $flang . "_" . $fname . "`";
  159. if ($flang == NV_LANG_DATA)
  160. {
  161. $listvalue .= ", " . $db->dbescape($datasource[$fname]);
  162. }
  163. else
  164. {
  165. $listvalue .= ", " . $db->dbescape($datasource[$fname]);
  166. }
  167. }
  168. $query = "INSERT INTO `" . $db_config['prefix'] . "_" . $module_data . "_sources` (`sourceid`, `link`, `logo`, `weight`, `add_time`, `edit_time` " . $listfield . ") VALUES (NULL, '', '', " . $db->dbescape($weight) . ", UNIX_TIMESTAMP( ), UNIX_TIMESTAMP( ) " . $listvalue . ")";
  169. $rowcontent['source_id'] = $db->sql_query_insert_id($query);
  170. }
  171. if ($rowcontent['keywords'] == "")
  172. {
  173. if ($rowcontent['hometext'] != "")
  174. {
  175. $rowcontent['keywords'] = nv_content_keywords($rowcontent['hometext']);
  176. }
  177. else
  178. {
  179. $rowcontent['keywords'] = nv_content_keywords($rowcontent['bodytext']);
  180. }
  181. }
  182. $rowcontent['status'] = ($nv_Request->isset_request('status1', 'post')) ? 1 : 0;
  183. // Xu ly anh minh ha
  184. $rowcontent['homeimgthumb'] = "";
  185. if (!nv_is_url($rowcontent['homeimgfile']) and file_exists(NV_DOCUMENT_ROOT . $rowcontent['homeimgfile']))
  186. {
  187. $lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/");
  188. $rowcontent['homeimgfile'] = substr($rowcontent['homeimgfile'], $lu);
  189. }
  190. elseif (!nv_is_url($rowcontent['homeimgfile']))
  191. {
  192. $rowcontent['homeimgfile'] = "";
  193. }
  194. $check_thumb = false;
  195. if ($rowcontent['id'] > 0)
  196. {
  197. list($homeimgfile, $homeimgthumb) = $db->sql_fetchrow($db->sql_query("SELECT `homeimgfile`, `homeimgthumb` FROM `" . $db_config['prefix'] . "_" . $module_data . "_rows` WHERE `id`=" . $rowcontent['id'] . ""));
  198. if ($rowcontent['homeimgfile'] != $homeimgfile)
  199. {
  200. $check_thumb = true;
  201. if ($homeimgthumb != "" and $homeimgthumb != "|")
  202. {
  203. $rowcontent['homeimgthumb'] = "";
  204. $homeimgthumb_arr = explode("|", $homeimgthumb);
  205. foreach ($homeimgthumb_arr as $homeimgthumb_i)
  206. {
  207. if (file_exists(NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $homeimgthumb_i))
  208. {
  209. nv_deletefile(NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $homeimgthumb_i);
  210. }
  211. }
  212. }
  213. }
  214. else
  215. {
  216. $rowcontent['homeimgthumb'] = $homeimgthumb;
  217. }
  218. }
  219. elseif (!empty($rowcontent['homeimgfile']))
  220. {
  221. $check_thumb = true;
  222. }
  223. $homeimgfile = NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $rowcontent['homeimgfile'];
  224. if ($check_thumb and file_exists($homeimgfile))
  225. {
  226. require_once (NV_ROOTDIR . "/includes/class/image.class.php");
  227. $basename = basename($homeimgfile);
  228. $image = new image($homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT);
  229. $thumb_basename = $basename;
  230. $i = 1;
  231. while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb/' . $thumb_basename))
  232. {
  233. $thumb_basename = preg_replace('/(.*)(\.[a-zA-Z]+)$/', '\1_' . $i . '\2', $basename);
  234. ++$i;
  235. }
  236. $image->resizeXY($pro_config['homewidth'], $pro_config['homeheight']);
  237. $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb', $thumb_basename);
  238. $image_info = $image->create_Image_info;
  239. $thumb_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']);
  240. $block_basename = $basename;
  241. $i = 1;
  242. while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/block/' . $block_basename))
  243. {
  244. $block_basename = preg_replace('/(.*)(\.[a-zA-Z]+)$/', '\1_' . $i . '\2', $basename);
  245. ++$i;
  246. }
  247. $image->resizeXY($pro_config['blockwidth'], $pro_config['blockheight']);
  248. $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/block', $block_basename);
  249. $image_info = $image->create_Image_info;
  250. $block_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']);
  251. $image->close();
  252. $rowcontent['homeimgthumb'] = $thumb_name . "|" . $block_name;
  253. }
  254. $listfield = "";
  255. $listvalue = "";
  256. foreach ($field_lang as $field_lang_i)
  257. {
  258. list($flang, $fname) = $field_lang_i;
  259. $listfield .= ", `" . $flang . "_" . $fname . "`";
  260. if ($flang == NV_LANG_DATA)
  261. {
  262. $listvalue .= ", " . $db->dbescape($rowcontent[$fname]);
  263. }
  264. else
  265. {
  266. $listvalue .= ", " . $db->dbescape($rowcontent[$fname]);
  267. }
  268. }
  269. if ($rowcontent['id'] == 0)
  270. {
  271. $rowcontent['publtime'] = ($rowcontent['publtime'] > NV_CURRENTTIME) ? $rowcontent['publtime'] : NV_CURRENTTIME;
  272. $query = "INSERT INTO `" . $db_config['prefix'] . "_" . $module_data . "_rows` (`id` ,`listcatid` ,`group_id` ,`user_id`, `com_id`,`shopcat_id` ,`source_id` ,`addtime` ,`edittime` ,`status` ,`publtime` ,`exptime` ,`archive`, `product_code`, `product_number` ,`product_price`,`product_discounts` ,`money_unit` , `product_unit` ,`homeimgfile` ,`homeimgthumb` ,`homeimgalt`,`imgposition` ,`copyright` ,`inhome` ,`allowed_comm` ,`allowed_rating` ,`ratingdetail` ,`allowed_send` ,`allowed_print` ,`allowed_save` ,`hitstotal` ,`hitscm` ,`hitslm`,`showprice` " . $listfield . ")
  273. VALUES ( NULL , " . $db->dbescape_string($rowcontent['listcatid']) . ",
  274. " . $db->dbescape_string($rowcontent['group_id']) . ",
  275. " . intval($rowcontent['user_id']) . ",
  276. " . intval($data_content['com_id']) . ",
  277. " . intval($data_content['shopcat_id ']) . ",
  278. " . intval($rowcontent['source_id']) . ",
  279. " . intval($rowcontent['addtime']) . ",
  280. " . intval($rowcontent['edittime']) . ",
  281. " . intval($rowcontent['status']) . ",
  282. " . intval($rowcontent['publtime']) . ",
  283. " . intval($rowcontent['exptime']) . ",
  284. " . intval($rowcontent['archive']) . ",
  285. " . $db->dbescape_string($rowcontent['product_code']) . ",
  286. " . intval($rowcontent['product_number']) . ",
  287. '" . $rowcontent['product_price'] . "',
  288. " . intval($rowcontent['product_discounts']) . ",
  289. " . $db->dbescape_string($rowcontent['money_unit']) . ",
  290. " . intval($rowcontent['product_unit']) . ",
  291. " . $db->dbescape_string($rowcontent['homeimgfile']) . ",
  292. " . $db->dbescape_string($rowcontent['homeimgthumb']) . ",
  293. " . $db->dbescape_string($rowcontent['homeimgalt']) . ",
  294. " . intval($rowcontent['imgposition']) . ",
  295. " . intval($rowcontent['copyright']) . ",
  296. " . intval($rowcontent['inhome']) . ",
  297. " . intval($rowcontent['allowed_comm']) . ",
  298. " . intval($rowcontent['allowed_rating']) . ",
  299. " . $db->dbescape_string($rowcontent['ratingdetail']) . ",
  300. " . intval($rowcontent['allowed_send']) . ",
  301. " . intval($rowcontent['allowed_print']) . ",
  302. " . intval($rowcontent['allowed_save']) . ",
  303. " . intval($rowcontent['hitstotal']) . ",
  304. " . intval($rowcontent['hitscm']) . ",
  305. " . intval($rowcontent['hitslm']) . ",
  306. " . intval($rowcontent['showprice']) . "
  307. " . $listvalue . ")";
  308. $rowcontent['id'] = $db->sql_query_insert_id($query);
  309. if ($rowcontent['id'] > 0)
  310. {
  311. nv_insert_logs(NV_LANG_DATA, $module_name, 'log_add_product', "id " . $rowcontent['id'], $admin_info['userid']);
  312. }
  313. else
  314. {
  315. $error = $lang_module['errorsave'];
  316. }
  317. $db->sql_freeresult();
  318. }
  319. else
  320. {
  321. $rowcontent_old = $db->sql_fetchrow($db->sql_query("SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_rows` where `id`=" . $rowcontent['id'] . ""));
  322. $rowcontent['user_id'] = $rowcontent_old['user_id'];
  323. if ($rowcontent_old['status'] == 1)
  324. {
  325. $rowcontent['status'] = 1;
  326. }
  327. $query = "UPDATE `" . $db_config['prefix'] . "_" . $module_data . "_rows` SET
  328. `listcatid`=" . $db->dbescape_string($rowcontent['listcatid']) . ",
  329. `group_id`=" . $db->dbescape_string($rowcontent['group_id']) . ",
  330. `user_id`=" . intval($rowcontent['user_id']) . ",
  331. `source_id`=" . intval($rowcontent['source_id']) . ",
  332. `status`=" . intval($rowcontent['status']) . ",
  333. `publtime`=" . intval($rowcontent['publtime']) . ",
  334. `exptime`=" . intval($rowcontent['exptime']) . ",
  335. `edittime`=UNIX_TIMESTAMP( ) ,
  336. `archive`=" . intval($rowcontent['archive']) . ",
  337. `product_code`=" . $db->dbescape_string($rowcontent['product_code']) . ",
  338. `product_number` = `product_number` + " . intval($rowcontent['product_number']) . ",
  339. `product_price` = '" . $rowcontent['product_price'] . "',
  340. `product_discounts` = " . intval($rowcontent['product_discounts']) . ",
  341. `money_unit` = " . $db->dbescape_string($rowcontent['money_unit']) . ",
  342. `product_unit` = " . intval($rowcontent['product_unit']) . ",
  343. `homeimgfile`=" . $db->dbescape_string($rowcontent['homeimgfile']) . ",
  344. `homeimgalt`=" . $db->dbescape_string($rowcontent['homeimgalt']) . ",
  345. `homeimgthumb`=" . $db->dbescape_string($rowcontent['homeimgthumb']) . ",
  346. `imgposition`=" . intval($rowcontent['imgposition']) . ",
  347. `copyright`=" . intval($rowcontent['copyright']) . ",
  348. `inhome`=" . intval($rowcontent['inhome']) . ",
  349. `allowed_comm`=" . intval($rowcontent['allowed_comm']) . ",
  350. `allowed_rating`=" . intval($rowcontent['allowed_rating']) . ",
  351. `allowed_send`=" . intval($rowcontent['allowed_send']) . ",
  352. `allowed_print`=" . intval($rowcontent['allowed_print']) . ",
  353. `allowed_save`=" . intval($rowcontent['allowed_save']) . ",
  354. `showprice` = " . intval($rowcontent['showprice']) . ",
  355. `" . NV_LANG_DATA . "_title`=" . $db->dbescape_string($rowcontent['title']) . ",
  356. `" . NV_LANG_DATA . "_alias`=" . $db->dbescape_string($rowcontent['alias']) . ",
  357. `" . NV_LANG_DATA . "_hometext`=" . $db->dbescape_string($rowcontent['hometext']) . ",
  358. `" . NV_LANG_DATA . "_bodytext`=" . $db->dbescape_string($rowcontent['bodytext']) . ",
  359. `" . NV_LANG_DATA . "_address`=" . $db->dbescape_string($rowcontent['address']) . ",
  360. `" . NV_LANG_DATA . "_note`=" . $db->dbescape_string($rowcontent['note']) . ",
  361. `" . NV_LANG_DATA . "_keywords`=" . $db->dbescape_string($rowcontent['keywords']) . "
  362. WHERE `id` =" . $rowcontent['id'] . "";
  363. $db->sql_query($query);
  364. if ($db->sql_affectedrows() > 0)
  365. {
  366. nv_insert_logs(NV_LANG_DATA, $module_name, 'log_edit_product', "id " . $rowcontent['id'], $admin_info['userid']);
  367. }
  368. else
  369. {
  370. $error = $lang_module['errorsave'];
  371. }
  372. $db->sql_freeresult();
  373. }
  374. if ($error == "")
  375. {
  376. if ($rowcontent['publtime'] > NV_CURRENTTIME or $rowcontent['exptime'] > 0)
  377. {
  378. $rowcontent['exptime'] = ($rowcontent['exptime'] > 0) ? $rowcontent['exptime'] : NV_CURRENTTIME + 26000000;
  379. $catid = $rowcontent['listcatid'];
  380. list($del_cache_time) = $db->sql_fetchrow($db->sql_query("SELECT `del_cache_time` FROM `" . $db_config['prefix'] . "_" . $module_data . "_catalogs` WHERE `catid` =" . $catid . ""));
  381. $del_cache_time = min($rowcontent['publtime'], $rowcontent['exptime'], $del_cache_time);
  382. $db->sql_query("UPDATE `" . $db_config['prefix'] . "_" . $module_data . "_catalogs` SET `del_cache_time`=" . $db->dbescape($del_cache_time) . " WHERE `catid`=" . $catid . "");
  383. }
  384. foreach ($id_block_content as $bid_i)
  385. {
  386. $db->sql_query("INSERT INTO `" . $db_config['prefix'] . "_" . $module_data . "_block` (`bid`, `id`, `weight`) VALUES ('" . $bid_i . "', '" . $rowcontent['id'] . "', '0')");
  387. }
  388. $id_block_content[] = 0;
  389. $db->sql_query("DELETE FROM `" . $db_config['prefix'] . "_" . $module_data . "_block` WHERE `id` = " . $rowcontent['id'] . " AND `bid` NOT IN (" . implode(",", $id_block_content) . ")");
  390. foreach ($array_block_cat_module as $bid_i)
  391. {
  392. nv_news_fix_block($bid_i);
  393. }
  394. nv_del_moduleCache($module_name);
  395. Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=items");
  396. die();
  397. }
  398. nv_del_moduleCache($module_name);
  399. }
  400. }
  401. elseif ($rowcontent['id'] > 0)
  402. {
  403. $rowcontent = $db->sql_fetch_assoc($db->sql_query("SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_rows` where `id`=" . $rowcontent['id'] . ""));
  404. $rowcontent['title'] = $rowcontent[NV_LANG_DATA . '_title'];
  405. $rowcontent['alias'] = $rowcontent[NV_LANG_DATA . '_alias'];
  406. $rowcontent['hometext'] = $rowcontent[NV_LANG_DATA . '_hometext'];
  407. $rowcontent['bodytext'] = $rowcontent[NV_LANG_DATA . '_bodytext'];
  408. $rowcontent['note'] = $rowcontent[NV_LANG_DATA . '_note'];
  409. $rowcontent['keywords'] = $rowcontent[NV_LANG_DATA . '_keywords'];
  410. $rowcontent['address'] = $rowcontent[NV_LANG_DATA . '_address'];
  411. $page_title = $lang_module['content_edit'];
  412. $rowcontent['sourcetext'] = "";
  413. $id_block_content = array();
  414. $sql = "SELECT bid FROM `" . $db_config['prefix'] . "_" . $module_data . "_block` where `id`='" . $rowcontent['id'] . "' ";
  415. $result = $db->sql_query($sql);
  416. while (list($bid_i) = $db->sql_fetchrow($result))
  417. {
  418. $id_block_content[] = $bid_i;
  419. }
  420. }
  421. if (!empty($rowcontent['bodytext']))
  422. $rowcontent['bodytext'] = nv_htmlspecialchars($rowcontent['bodytext']);
  423. if (!empty($rowcontent['homeimgfile']) and file_exists(NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $rowcontent['homeimgfile']))
  424. {
  425. $rowcontent['homeimgfile'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $rowcontent['homeimgfile'];
  426. }
  427. $sql = "SELECT sourceid, `" . NV_LANG_DATA . "_title` FROM `" . $db_config['prefix'] . "_" . $module_data . "_sources` ORDER BY `weight` ASC";
  428. $result = $db->sql_query($sql);
  429. $array_source_module = array();
  430. $array_source_module[0] = $lang_module['sources_sl'];
  431. while (list($sourceid_i, $title_i) = $db->sql_fetchrow($result))
  432. {
  433. $array_source_module[$sourceid_i] = $title_i;
  434. }
  435. $tdate = date("H|i", $rowcontent['publtime']);
  436. $publ_date = date("d/m/Y", $rowcontent['publtime']);
  437. list($phour, $pmin) = explode("|", $tdate);
  438. if ($rowcontent['exptime'] == 0)
  439. {
  440. $emin = $ehour = 0;
  441. $exp_date = "";
  442. }
  443. else
  444. {
  445. $exp_date = date("d/m/Y", $rowcontent['exptime']);
  446. $tdate = date("H|i", $rowcontent['exptime']);
  447. list($ehour, $emin) = explode("|", $tdate);
  448. }
  449. $temp = explode(".", $rowcontent['product_price']);
  450. if (sizeof($temp) == 2)
  451. {
  452. $rowcontent['product_price'] = number_format($rowcontent['product_price'], strlen($temp[1]), '.', ' ');
  453. }
  454. else
  455. {
  456. $rowcontent['product_price'] = number_format($rowcontent['product_price'], 0, '.', ' ');
  457. }
  458. $xtpl = new XTemplate("content.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file);
  459. $xtpl->assign('LANG', $lang_module);
  460. $xtpl->assign('rowcontent', $rowcontent);
  461. $xtpl->assign('NV_BASE_ADMINURL', NV_BASE_ADMINURL);
  462. $xtpl->assign('NV_NAME_VARIABLE', NV_NAME_VARIABLE);
  463. $xtpl->assign('NV_OP_VARIABLE', NV_OP_VARIABLE);
  464. $xtpl->assign('module_name', $module_name);
  465. if ($error != "")
  466. {
  467. $xtpl->assign('error', $error);
  468. $xtpl->parse('main.error');
  469. }
  470. if ($rowcontent['status'] == 1)
  471. {
  472. $xtpl->parse('main.status');
  473. }
  474. else
  475. {
  476. $xtpl->parse('main.status0');
  477. }
  478. /////// List catalogs ////////
  479. $sql = "SELECT catid," . NV_LANG_DATA . "_title, lev,numsubcat FROM `" . $db_config['prefix'] . "_" . $module_data . "_catalogs` ORDER BY `order` ASC";
  480. $result_cat = $db->sql_query($sql);
  481. if ($db->sql_numrows($result_cat) == 0)
  482. {
  483. Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat");
  484. die();
  485. }
  486. while (list($catid_i, $title_i, $lev_i, $numsubcat_i) = $db->sql_fetchrow($result_cat))
  487. {
  488. $xtitle_i = "";
  489. if ($lev_i > 0)
  490. {
  491. for ($i = 1; $i <= $lev_i; ++$i)
  492. {
  493. $xtitle_i .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  494. }
  495. }
  496. $select = ($catid_i == $rowcontent['listcatid']) ? " selected=\"selected\"" : "";
  497. $xtpl->assign('xtitle_i', $xtitle_i);
  498. $xtpl->assign('title_i', $title_i);
  499. $xtpl->assign('catid_i', $catid_i);
  500. $xtpl->assign('select', $select);
  501. $xtpl->parse('main.rowscat');
  502. }
  503. /////// List group ////////
  504. if (!empty($rowcontent['group_id']))
  505. {
  506. $array_groupid_in_row = explode(",", $rowcontent['group_id']);
  507. }
  508. else
  509. {
  510. $array_groupid_in_row = array();
  511. }
  512. $sql = "SELECT groupid," . NV_LANG_DATA . "_title, lev,numsubgroup FROM `" . $db_config['prefix'] . "_" . $module_data . "_group` ORDER BY `order` ASC";
  513. $result_group = $db->sql_query($sql);
  514. $temp = "";
  515. while (list($groupid_i, $title_i, $lev_i, $numsubcat_i) = $db->sql_fetchrow($result_group))
  516. {
  517. $xtitle_i = "";
  518. if ($lev_i > 0)
  519. {
  520. for ($i = 1; $i <= $lev_i; ++$i)
  521. {
  522. $xtitle_i .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  523. }
  524. }
  525. $ch = "";
  526. if (in_array($groupid_i, $array_groupid_in_row))
  527. {
  528. $ch .= " checked=\"checked\"";
  529. }
  530. $temp .= "<li>" . $xtitle_i . "<input class=\"news_checkbox\" type=\"checkbox\" name=\"groupids[]\" value=\"" . $groupid_i . "\"" . $ch . " />" . $title_i . "</li>";
  531. }
  532. if (!empty($temp))
  533. {
  534. $xtpl->assign('listgroupid', $temp);
  535. $xtpl->parse('main.listgroup');
  536. }
  537. ///////////time update////////////
  538. $xtpl->assign('publ_date', $publ_date);
  539. $select = "";
  540. for ($i = 0; $i <= 23; ++$i)
  541. {
  542. $select .= "<option value=\"" . $i . "\"" . (($i == $phour) ? " selected=\"selected\"" : "") . ">" . str_pad($i, 2, "0", STR_PAD_LEFT) . "</option>\n";
  543. }
  544. $xtpl->assign('phour', $select);
  545. $select = "";
  546. for ($i = 0; $i < 60; ++$i)
  547. {
  548. $select .= "<option value=\"" . $i . "\"" . (($i == $pmin) ? " selected=\"selected\"" : "") . ">" . str_pad($i, 2, "0", STR_PAD_LEFT) . "</option>\n";
  549. }
  550. $xtpl->assign('pmin', $select);
  551. /////////// time exp //////////////////////////////////////////
  552. $xtpl->assign('exp_date', $exp_date);
  553. $select = "";
  554. for ($i = 0; $i <= 23; ++$i)
  555. {
  556. $select .= "<option value=\"" . $i . "\"" . (($i == $ehour) ? " selected=\"selected\"" : "") . ">" . str_pad($i, 2, "0", STR_PAD_LEFT) . "</option>\n";
  557. }
  558. $xtpl->assign('ehour', $select);
  559. $select = "";
  560. for ($i = 0; $i < 60; ++$i)
  561. {
  562. $select .= "<option value=\"" . $i . "\"" . (($i == $emin) ? " selected=\"selected\"" : "") . ">" . str_pad($i, 2, "0", STR_PAD_LEFT) . "</option>\n";
  563. }
  564. $xtpl->assign('emin', $select);
  565. //////// allowed ////////////////
  566. $select = "";
  567. while (list($commid_i, $commid_title_i) = each($array_allowed_comm))
  568. {
  569. $comm_sl = ($commid_i == $rowcontent['allowed_comm']) ? " selected=\"selected\"" : "";
  570. $select .= "<option value=\"" . $commid_i . "\" " . $comm_sl . ">" . $commid_title_i . "</option>\n";
  571. }
  572. $xtpl->assign('allowed_comm', $select);
  573. /////////// source //////////////////////////
  574. $select = "";
  575. while (list($sourceid_i, $source_title_i) = each($array_source_module))
  576. {
  577. $source_sl = ($sourceid_i == $rowcontent['source_id']) ? " selected=\"selected\"" : "";
  578. $select .= "<option value=\"" . $sourceid_i . "\" " . $source_sl . ">" . $source_title_i . "</option>\n";
  579. }
  580. $xtpl->assign('sourceid', $select);
  581. ////////////////////////////////////////////////////////////////////////////////////
  582. if (defined('NV_EDITOR') and function_exists('nv_aleditor'))
  583. {
  584. $edits = nv_aleditor('bodytext', '100%', '300px', $rowcontent['bodytext']);
  585. }
  586. else
  587. {
  588. $edits = "<textarea style=\"width: 100%\" name=\"bodytext\" id=\"bodytext\" cols=\"20\" rows=\"15\">" . $rowcontent['bodytext'] . "</textarea>";
  589. }
  590. ///////////////////////////////////////////////////////////////////////////////////////////
  591. $shtm = "";
  592. if (sizeof($array_block_cat_module))
  593. {
  594. foreach ($array_block_cat_module as $bid_i => $bid_title)
  595. {
  596. $ch = in_array($bid_i, $id_block_content) ? " checked=\"checked\"" : "";
  597. $shtm .= "<input class=\"news_checkbox\" type=\"checkbox\" name=\"bids[]\" value=\"" . $bid_i . "\"" . $ch . ">" . $bid_title . "<br />\n";
  598. }
  599. $xtpl->assign('row_block', $shtm);
  600. $xtpl->parse('main.block_cat');
  601. }
  602. /////// List pro_unit ////////
  603. $sql = "SELECT id," . NV_LANG_DATA . "_title FROM `" . $db_config['prefix'] . "_" . $module_data . "_units`";
  604. $result_unit = $db->sql_query($sql);
  605. if ($db->sql_numrows($result_unit) == 0)
  606. {
  607. Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=prounit");
  608. die();
  609. }
  610. while (list($unitid_i, $title_i) = $db->sql_fetchrow($result_unit))
  611. {
  612. $xtpl->assign('utitle', $title_i);
  613. $xtpl->assign('uid', $unitid_i);
  614. $uch = ($rowcontent['product_unit'] == $unitid_i) ? "selected=\"selected\"" : "";
  615. $xtpl->assign('uch', $uch);
  616. $xtpl->parse('main.rowunit');
  617. }
  618. //////////////////////////////////////////////////////////////////
  619. $archive_checked = ($rowcontent['archive']) ? " checked=\"checked\"" : "";
  620. $xtpl->assign('archive_checked', $archive_checked);
  621. $inhome_checked = ($rowcontent['inhome']) ? " checked=\"checked\"" : "";
  622. $xtpl->assign('inhome_checked', $inhome_checked);
  623. $allowed_rating_checked = ($rowcontent['allowed_rating']) ? " checked=\"checked\"" : "";
  624. $xtpl->assign('allowed_rating_checked', $allowed_rating_checked);
  625. $allowed_send_checked = ($rowcontent['allowed_send']) ? " checked=\"checked\"" : "";
  626. $xtpl->assign('allowed_send_checked', $allowed_send_checked);
  627. $allowed_print_checked = ($rowcontent['allowed_print']) ? " checked=\"checked\"" : "";
  628. $xtpl->assign('allowed_print_checked', $allowed_print_checked);
  629. $allowed_save_checked = ($rowcontent['allowed_save']) ? " checked=\"checked\"" : "";
  630. $xtpl->assign('allowed_save_checked', $allowed_save_checked);
  631. $showprice_checked = ($rowcontent['showprice']) ? " checked=\"checked\"" : "";
  632. $xtpl->assign('ck_showprice', $showprice_checked);
  633. if (!empty($money_config))
  634. {
  635. foreach ($money_config as $code => $info)
  636. {
  637. $info['select'] = ($rowcontent['money_unit'] == $code) ? "selected=\"selected\"" : "";
  638. $xtpl->assign('MON', $info);
  639. $xtpl->parse('main.money_unit');
  640. }
  641. }
  642. ////////////////////////////////////////////////////////////////////////////////
  643. $xtpl->assign('edit_bodytext', $edits);
  644. ///////////////////////////////////////////////////////////////////////////////////
  645. if ($rowcontent['id'] > 0)
  646. {
  647. $xtpl->parse('main.edit');
  648. }
  649. else
  650. {
  651. $xtpl->parse('main.add');
  652. }
  653. if (empty($rowcontent['alias']))
  654. {
  655. $xtpl->parse('main.getalias');
  656. }
  657. $xtpl->assign('CURRENT', NV_UPLOADS_DIR . '/' . $module_name . '/' . date("Y_m"));
  658. $xtpl->parse('main');
  659. $contents .= $xtpl->text('main');
  660. include (NV_ROOTDIR . "/includes/header.php");
  661. echo nv_admin_theme($contents);
  662. include (NV_ROOTDIR . "/includes/footer.php");
  663. ?>