admincp_city.inc.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * DZAPP Haodai Admin Control Panel -- City List
  4. *
  5. * @copyright (c) 2013 DZAPP. (http://www.dzapp.cn)
  6. * @author BranchZero <branchzero@gmail.com>
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. include_once DISCUZ_ROOT.'./data/dzapp_haodai_config.php';
  12. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/haodai.api.class.php';
  13. @include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_setting.php';
  14. loadcache('plugin');
  15. $lang = array_merge($lang, $scriptlang['dzapp_haodai']);
  16. $var = $_G['cache']['plugin']['dzapp_haodai'];
  17. if(isset($hd_token)){
  18. if(!submitcheck('submit')){
  19. if(!@include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_city.php' || TIMESTAMP - filemtime(DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_city.php') > $var['refreshtime']){
  20. $client = new HaoDaiClient(HD_AKEY, HD_SKEY, $hd_token['access_token']);
  21. $client->set_debug(0);
  22. $result = $client->get_xindai_zones();
  23. $zonelist = $result['items'];
  24. if(count($zonelist) > 0){
  25. $zones = array();
  26. foreach($zonelist as $value){
  27. if($value['s_EN'] == 'www') continue;
  28. $value['zone_name'] = diconv($value['zone_name'], 'UTF-8', CHARSET);
  29. $value['Province'] = diconv($value['Province'], 'UTF-8', CHARSET);
  30. $value['area'] = diconv($value['area'], 'UTF-8', CHARSET);
  31. $zones[$value['s_EN']] = $value['zone_name'];
  32. $zonesort['provinces'][$value['Province']][$value['s_EN']] = $value['zone_name'];
  33. $zonesort['letter_raw'][$value['letter']][$value['s_EN']] = $value['zone_name'];
  34. $zonesort['area'][$value['area']][$value['s_EN']] = $value['zone_name'];
  35. }
  36. foreach(range('A', 'Z') as $letter) {
  37. if(!empty($zonesort['letter_raw'][$letter])) $zonesort['letter'][$letter] = $zonesort['letter_raw'][$letter];
  38. }
  39. require_once libfile('function/cache');
  40. writetocache('dzapp_haodai_city', getcachevars(array('zones' => $zones)));
  41. writetocache('dzapp_haodai_city_sort', getcachevars(array('zonesort' => $zonesort)));
  42. }else{
  43. cpmsg('callback_error_admin', 'action=plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_callback', 'error');
  44. }
  45. }
  46. $catselect = "<select name=\"CITY\">";
  47. foreach($zones as $key => $value){
  48. $catselect .= "<option value=\"$key\" ".($key == HD_CITY ? 'selected="selected"' : NULL).">$value</option>\n";
  49. }
  50. $catselect .= '</select>';
  51. showformheader('plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_city');
  52. showtableheader($lang['choosecity']);
  53. showsetting($lang['localcity'], '', '', $catselect);
  54. showtablefooter();
  55. showsubmit('submit', 'submit');
  56. showformfooter();
  57. }else{
  58. $config = array();
  59. $config['HD_REF'] = HD_REF;
  60. $config['HD_AKEY'] = HD_AKEY;
  61. $config['HD_SKEY'] = HD_SKEY;
  62. $config['HD_CALLBACK_URL'] = HD_CALLBACK_URL;
  63. $config['HD_API_HOST'] = HD_API_HOST;
  64. $config['HD_CITY'] = $_GET['CITY'];
  65. $config = daddslashes($config);
  66. $configfile = "<?php \r\n";
  67. foreach($config as $key => $value){
  68. $configfile .= "define('$key', '$value');\r\n";
  69. }
  70. $configfile .= "?>";
  71. $file = DISCUZ_ROOT."./data/dzapp_haodai_config.php";
  72. $fp = fopen($file, 'w');
  73. fwrite($fp, $configfile);
  74. fclose($fp);
  75. cpmsg('setting_succeed', 'action=plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_city', 'succeed');
  76. }
  77. }else{
  78. cpmsg('callback_error_admin', 'action=plugins&operation=config&identifier=dzapp_haodai&pmod=admincp_callback', 'error');
  79. }
  80. ?>