PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/shops/admin/content.php

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