PageRenderTime 58ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/shops/admin/payport.php

http://nukeviet-shop.googlecode.com/
PHP | 189 lines | 162 code | 13 blank | 14 comment | 23 complexity | 3d06789b37ae51780710d78701708cc3 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. $page_title = $lang_module['setup_payment'];
  10. /*load config template payment port in data*/
  11. $array_setting_payment = array();
  12. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_payment` ORDER BY `weight` ASC";
  13. $result = $db->sql_query( $sql );
  14. $all_page = $db->sql_numrows( $result );
  15. while ( $row = $db->sql_fetchrow( $result ) )
  16. {
  17. $array_setting_payment[$row['payment']] = $row;
  18. }
  19. /*load config template payment port in file*/
  20. $check_config_payment = "/^([a-zA-Z0-9\-\_]+)\.config\.ini$/";
  21. $payment_funcs = nv_scandir( NV_ROOTDIR . '/modules/' . $module_file . '/payment', $check_config_payment );
  22. if ( ! empty( $payment_funcs ) )
  23. {
  24. $payment_funcs = preg_replace( $check_config_payment, "\\1", $payment_funcs );
  25. }
  26. $array_setting_payment_key = array_keys( $array_setting_payment );
  27. $array_payment_other = array();
  28. foreach ( $payment_funcs as $payment )
  29. {
  30. $xml = simplexml_load_file( NV_ROOTDIR . '/modules/' . $module_file . '/payment/' . $payment . '.config.ini' );
  31. if ( $xml !== false )
  32. {
  33. $xmlconfig = $xml->xpath( 'config' );
  34. $config = $xmlconfig[0];
  35. $array_config = array();
  36. $array_config_title = array();
  37. foreach ( $config as $key => $value )
  38. {
  39. $config_lang = $value->attributes();
  40. if ( isset( $config_lang[NV_LANG_INTERFACE] ) )
  41. {
  42. $lang = ( string )$config_lang[NV_LANG_INTERFACE];
  43. }
  44. else
  45. {
  46. $lang = $key;
  47. }
  48. $array_config[$key] = trim( $value );
  49. $array_config_title[$key] = $lang;
  50. }
  51. $array_payment_other[$payment] = array(
  52. 'payment' => $payment, 'paymentname' => trim( $xml->name ), 'domain' => trim( $xml->domain ), 'images_button' => trim( $xml->images_button ), 'config' => $array_config, 'titlekey' => $array_config_title
  53. );
  54. unset( $config, $xmlconfig, $xml );
  55. }
  56. }
  57. /*end load*/
  58. /*get data edit*/
  59. $data_pay = array();
  60. $payment = $nv_Request->get_string( 'payment', 'get', '' );
  61. if ( ! empty( $payment ) )
  62. {
  63. //get data have not in database
  64. if ( ! in_array( $payment, $array_setting_payment_key ) )
  65. {
  66. if ( ! empty( $array_payment_other[$payment] ) )
  67. {
  68. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM `" . $db_config['prefix'] . "_" . $module_data . "_payment`" ) );
  69. $weight = intval( $weight ) + 1;
  70. $sql = "REPLACE INTO `" . $db_config['prefix'] . "_" . $module_data . "_payment` (`payment`, `paymentname`, `domain`, `active`, `weight`, `config`,`images_button`) VALUES (" . $db->dbescape_string( $payment ) . ", " . $db->dbescape_string( $array_payment_other[$payment]['paymentname'] ) . ", " . $db->dbescape_string( $array_payment_other[$payment]['domain'] ) . ", '0', '" . $weight . "', '" . nv_base64_encode( serialize( $array_payment_other[$payment]['config'] ) ) . "', " . $db->dbescape_string( $array_payment_other[$payment]['images_button'] ) . ")";
  71. $db->sql_query( $sql );
  72. $data_pay = $array_payment_other[$payment];
  73. }
  74. }
  75. //get data have in database
  76. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_payment` WHERE payment=" . $db->dbescape( $payment );
  77. $result = $db->sql_query( $sql );
  78. $data_pay = $db->sql_fetchrow( $result );
  79. }
  80. /*post setting data*/
  81. if ( $nv_Request->isset_request( 'saveconfigpaymentedit', 'post' ) )
  82. {
  83. $payment = filter_text_input( 'payment', 'post', '', 0 );
  84. $paymentname = filter_text_input( 'paymentname', 'post', '', 0 );
  85. $domain = filter_text_input( 'domain', 'post', '', 0 );
  86. $images_button = filter_text_input( 'images_button', 'post', '', 0 );
  87. $active = $nv_Request->get_int( 'active', 'post', 0 );
  88. $array_config = $nv_Request->get_array( 'config', 'post', array() );
  89. if ( ! nv_is_url( $images_button ) and file_exists( NV_DOCUMENT_ROOT . $images_button ) )
  90. {
  91. $lu = strlen( NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" );
  92. $images_button = substr( $images_button, $lu );
  93. }
  94. elseif ( ! nv_is_url( $images_button ) )
  95. {
  96. $images_button = "";
  97. }
  98. $sql = "UPDATE `" . $db_config['prefix'] . "_" . $module_data . "_payment` SET `paymentname` = " . $db->dbescape_string( $paymentname ) . ", `domain` = " . $db->dbescape_string( $domain ) . ", `active`=" . $active . ", `config` = '" . nv_base64_encode( serialize( $array_config ) ) . "',`images_button`=" . $db->dbescape_string( $images_button ) . " WHERE `payment` = " . $db->dbescape_string( $payment ) . " LIMIT 1";
  99. $db->sql_query( $sql );
  100. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_edit_product', "edit " . $paymentname, $admin_info['userid'] );
  101. nv_del_moduleCache( $module_name );
  102. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op );
  103. }
  104. /*view data*/
  105. $xtpl = new XTemplate( "payport.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  106. $xtpl->assign( 'LANG', $lang_module );
  107. $a = 0;
  108. if ( ! empty( $array_setting_payment ) && empty( $data_pay ))
  109. {
  110. foreach ( $array_setting_payment as $value )
  111. {
  112. $value['link_edit'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&amp;payment=" . $value['payment'];
  113. $value['class'] = ( $a % 2 == 0 ) ? ' class="second"' : '';
  114. $value['active'] = ( $value['active'] == "1" ) ? "checked=\"checked\"" : "";
  115. $value['slect_weight'] = drawselect_number( $value['payment'], 1, $all_page + 1, $value['weight'], "nv_chang_pays('" . $value['payment'] . "',this,url_change_weight,url_back);" );
  116. $xtpl->assign( 'DATA_PM', $value );
  117. $xtpl->parse( 'main.listpay.paymentloop' );
  118. $a ++;
  119. }
  120. $xtpl->assign( 'url_back', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op );
  121. $xtpl->assign( 'url_change', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=changepay" );
  122. $xtpl->assign( 'url_active', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=actpay" );
  123. $xtpl->parse( 'main.listpay' );
  124. }
  125. if ( ! empty( $array_payment_other ) && empty( $data_pay ))
  126. {
  127. $a = 1;
  128. foreach ( $array_payment_other as $pay => $value )
  129. {
  130. if ( ! in_array( $pay, $array_setting_payment_key ) )
  131. {
  132. $value['link_edit'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&amp;payment=" . $value['payment'];
  133. $value['class'] = ( $a % 2 == 0 ) ? ' class="second"' : '';
  134. $value['STT'] = $a;
  135. $xtpl->assign( 'ODATA_PM', $value );
  136. $xtpl->parse( 'main.olistpay.opaymentloop' );
  137. $a ++;
  138. }
  139. }
  140. if ($a>1) $xtpl->parse( 'main.olistpay' );
  141. }
  142. if ( ! empty( $data_pay ) )
  143. {
  144. $xtpl->assign( 'EDITPAYMENT', sprintf( $lang_module['editpayment'], $data_pay['payment'] ) );
  145. $array_config = unserialize( nv_base64_decode( $data_pay['config'] ) );
  146. $arkey_title = array();
  147. if ( ! empty( $array_payment_other[$data_pay['payment']]['titlekey'] ) )
  148. {
  149. $arkey_title = $array_payment_other[$data_pay['payment']]['titlekey'];
  150. }
  151. foreach ( $array_config as $key => $value )
  152. {
  153. if ( isset( $arkey_title[$key] ) )
  154. {
  155. $lang = ( string )$arkey_title[$key];
  156. }
  157. else
  158. {
  159. $lang = $key;
  160. }
  161. $value = $array_config[$key];
  162. $xtpl->assign( 'CONFIG_LANG', $lang );
  163. $xtpl->assign( 'CONFIG_NAME', $key );
  164. $xtpl->assign( 'CONFIG_VALUE', $value );
  165. $xtpl->parse( 'main.paymentedit.config' );
  166. }
  167. $data_pay['active'] = ( $data_pay['active'] == "1" ) ? "checked=\"checked\"" : "";
  168. $xtpl->assign( 'DATA', $data_pay );
  169. $xtpl->parse( 'main.paymentedit' );
  170. }
  171. $xtpl->parse( 'main' );
  172. $contents = $xtpl->text( 'main' );
  173. include ( NV_ROOTDIR . "/includes/header.php" );
  174. echo nv_admin_theme( $contents );
  175. include ( NV_ROOTDIR . "/includes/footer.php" );
  176. ?>