PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/nukeviet/install/update.php

http://nuke-viet.googlecode.com/
PHP | 2032 lines | 1504 code | 283 blank | 245 comment | 236 complexity | ed2ebb15627f8021f49961f75f2f94ea MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES.,JSC. All rights reserved
  6. * @Createdate 29-03-2012 03:29
  7. */
  8. define( 'NV_SYSTEM', true );
  9. define( 'NV_IS_UPDATE', true );
  10. //Ket noi den mainfile.php nam o thu muc goc.
  11. $realpath_mainfile = '';
  12. $temp_dir = str_replace( DIRECTORY_SEPARATOR, '/', dirname( __file__ ) );
  13. $temp_path = "/../";
  14. for( $i = 0; $i < 10; ++$i )
  15. {
  16. $realpath_mainfile = @realpath( $temp_dir . $temp_path . 'mainfile.php' );
  17. if( ! empty( $realpath_mainfile ) ) break;
  18. $temp_path .= "../";
  19. }
  20. unset( $temp_dir, $temp_path );
  21. if( empty( $realpath_mainfile ) ) die();
  22. require ( $realpath_mainfile );
  23. unset( $realpath_mainfile );
  24. // Kiem tra tu cach admin
  25. if( ! defined( 'NV_IS_GODADMIN' ) )
  26. {
  27. Header( 'Location:' . nv_url_rewrite( NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA ) );
  28. die();
  29. }
  30. // Kiem tra ton tai goi update
  31. if( ! file_exists( NV_ROOTDIR . '/install/update_data.php' ) )
  32. {
  33. Header( 'Location:' . nv_url_rewrite( NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA ) );
  34. die();
  35. }
  36. require ( NV_ROOTDIR . '/install/update_data.php' );
  37. if( empty( $nv_update_config ) )
  38. {
  39. Header( 'Location:' . nv_url_rewrite( NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA ) );
  40. die();
  41. }
  42. // Ham cua admin
  43. define( 'NV_ADMIN', true );
  44. include_once ( NV_ROOTDIR . "/includes/core/admin_functions.php" );
  45. // Xac dinh ngon ngu cap nhat
  46. $dirs = nv_scandir( NV_ROOTDIR . "/language", "/^([a-z]{2})/" );
  47. $languageslist = array();
  48. foreach( $dirs as $file )
  49. {
  50. if( is_file( NV_ROOTDIR . '/language/' . $file . '/install.php' ) )
  51. {
  52. $languageslist[] = $file;
  53. }
  54. }
  55. $data_update_lang = array_keys( $nv_update_config['lang'] );
  56. $array_lang_update = array_intersect( $data_update_lang, $languageslist );
  57. $nv_update_config['allow_lang'] = $array_lang_update;
  58. $cookie_lang = $nv_Request->get_string( 'update_lang', 'cookie', '' );
  59. $update_lang = $nv_Request->get_string( NV_LANG_VARIABLE, 'get,post', '' );
  60. if( ! empty( $update_lang ) and ( in_array( $update_lang, $array_lang_update ) ) and file_exists( NV_ROOTDIR . "/language/" . $update_lang . "/global.php" ) )
  61. {
  62. if( $update_lang != $cookie_lang ) $nv_Request->set_Cookie( 'update_lang', $update_lang, NV_LIVE_COOKIE_TIME );
  63. }
  64. elseif( preg_match( "/^[a-z]{2}$/", $cookie_lang ) and ( in_array( $cookie_lang, $array_lang_update ) ) and file_exists( NV_ROOTDIR . "/language/" . $cookie_lang . "/global.php" ) )
  65. {
  66. $update_lang = $cookie_lang;
  67. }
  68. elseif( in_array( NV_LANG_DATA, $array_lang_update ) )
  69. {
  70. $update_lang = NV_LANG_DATA;
  71. $nv_Request->set_Cookie( 'update_lang', $update_lang, NV_LIVE_COOKIE_TIME );
  72. }
  73. else
  74. {
  75. $update_lang = $array_lang_update[0];
  76. $nv_Request->set_Cookie( 'update_lang', $update_lang, NV_LIVE_COOKIE_TIME );
  77. }
  78. define( 'NV_LANG_UPDATE', $update_lang );
  79. unset( $dirs, $languageslist, $file, $data_update_lang, $array_lang_update, $cookie_lang, $update_lang );
  80. if( NV_LANG_UPDATE != NV_LANG_DATA ) unset( $lang_module, $lang_global );
  81. require( NV_ROOTDIR . "/language/" . NV_LANG_UPDATE . "/global.php" );
  82. require( NV_ROOTDIR . "/language/" . NV_LANG_UPDATE . "/admin_global.php" );
  83. require( NV_ROOTDIR . "/language/" . NV_LANG_UPDATE . "/install.php" );
  84. $lang_module = array_merge( $lang_module, $nv_update_config['lang'][NV_LANG_UPDATE] );
  85. unset( $nv_update_config['lang'] );
  86. /**
  87. * NvUpdate
  88. *
  89. * @package NukeViet
  90. * @author VINADES.,JSC
  91. * @copyright VINADES.,JSC
  92. * @version 2012
  93. * @access public
  94. */
  95. class NvUpdate
  96. {
  97. private $db;
  98. private $lang;
  99. private $glang;
  100. private $config;
  101. /**
  102. * NvUpdate::__construct()
  103. *
  104. * @param mixed $nv_update_config
  105. * @return
  106. */
  107. public function __construct( $nv_update_config )
  108. {
  109. global $db, $lang_module, $lang_global;
  110. $this->db = $db;
  111. $this->lang = $lang_module;
  112. $this->glang = $lang_global;
  113. $this->config = $nv_update_config;
  114. }
  115. /**
  116. * NvUpdate::check_package()
  117. *
  118. * @return
  119. */
  120. public function check_package()
  121. {
  122. if( ! isset( $this->config['release_date'] ) ) return false;
  123. elseif( ! isset( $this->config['author'] ) ) return false;
  124. elseif( ! isset( $this->config['support_website'] ) ) return false;
  125. elseif( ! isset( $this->config['to_version'] ) ) return false;
  126. elseif( ! isset( $this->config['allow_old_version'] ) ) return false;
  127. elseif( ! isset( $this->config['type'] ) ) return false;
  128. elseif( ! isset( $this->config['packageID'] ) ) return false;
  129. elseif( ! isset( $this->config['tasklist'] ) ) return false;
  130. return true;
  131. }
  132. /**
  133. * NvUpdate::build_full_ver()
  134. *
  135. * @param mixed $version
  136. * @param mixed $revision
  137. * @return
  138. */
  139. public function build_full_ver( $version, $revision )
  140. {
  141. return $version . '.r' . $revision;
  142. }
  143. /**
  144. * NvUpdate::list_data_update()
  145. *
  146. * @return
  147. */
  148. public function list_data_update()
  149. {
  150. if( empty( $this->config['tasklist'] ) ) return array();
  151. global $global_config, $nv_update_config;
  152. $tasklist = array();
  153. foreach( $this->config['tasklist'] as $task )
  154. {
  155. // Neu la nang cap module
  156. if( ! empty( $this->config['formodule'] ) )
  157. {
  158. if( nv_version_compare( $task['r'], $nv_update_config['updatelog']['old_version'] ) > 0 )
  159. {
  160. $tasklist[$task['f']] = array( 'langkey' => $task['l'], 'require' => $task['rq'] );
  161. }
  162. }
  163. else
  164. {
  165. if( $task['r'] > $global_config['revision'] )
  166. {
  167. $tasklist[$task['f']] = array( 'langkey' => $task['l'], 'require' => $task['rq'] );
  168. }
  169. }
  170. }
  171. return $tasklist;
  172. }
  173. /**
  174. * NvUpdate::list_all_file()
  175. *
  176. * @param string $dir
  177. * @param string $base_dir
  178. * @return
  179. */
  180. public function list_all_file( $dir = '', $base_dir = '' )
  181. {
  182. if( empty( $dir ) ) $dir = NV_ROOTDIR . '/install/update';
  183. $file_list = array();
  184. if( is_dir( $dir ) )
  185. {
  186. $array_filedir = scandir( $dir );
  187. foreach( $array_filedir as $v )
  188. {
  189. if( $v == '.' or $v == '..' ) continue;
  190. if( is_dir( $dir . '/' . $v ) )
  191. {
  192. foreach( $this->list_all_file( $dir . '/' . $v, $base_dir . '/' . $v ) as $file )
  193. {
  194. $file_list[] = $file;
  195. }
  196. }
  197. else
  198. {
  199. // if( $base_dir == '' and ( $v == 'index.html' or $v == 'index.htm' ) ) continue; // Khong di chuyen index.html
  200. $file_list[] = preg_replace( '/^\//', '', $base_dir . '/' . $v );
  201. }
  202. }
  203. }
  204. return $file_list;
  205. }
  206. /**
  207. * NvUpdate::set_data_log()
  208. *
  209. * @param mixed $data
  210. * @return
  211. */
  212. public function set_data_log( $data )
  213. {
  214. $content_config = "<?php\n\n";
  215. $content_config .= NV_FILEHEAD . "\n\n";
  216. $content_config .= "if( ! defined( 'NV_IS_UPDATE' ) ) die( 'Stop!!!' );\n\n";
  217. $content_config .= "\$nv_update_config['updatelog'] = " . var_export( $data, true ) . ";";
  218. $content_config .= "\n\n";
  219. $content_config .= "?>";
  220. $return = file_put_contents( NV_ROOTDIR . "/" . NV_DATADIR . "/config_update_" . $this->config['packageID'] . ".php", $content_config, LOCK_EX );
  221. if( $return === false )
  222. {
  223. $message = sprintf( $this->lang['update_error_log_data'], NV_DATADIR );
  224. $contents = $this->call_error( $message );
  225. include ( NV_ROOTDIR . "/includes/header.php" );
  226. echo $this->template( $contents );
  227. include ( NV_ROOTDIR . "/includes/footer.php" );
  228. exit();
  229. }
  230. }
  231. /**
  232. * NvUpdate::move_file()
  233. *
  234. * @param mixed $nv_update_config
  235. * @param mixed $files
  236. * @return
  237. */
  238. public function move_file( $nv_update_config, $files )
  239. {
  240. if( empty( $files ) ) return true;
  241. global $global_config;
  242. $is_ftp = false;
  243. if( $global_config['ftp_check_login'] == 1 )
  244. {
  245. $ftp_server = nv_unhtmlspecialchars( $global_config['ftp_server'] );
  246. $ftp_port = intval( $global_config['ftp_port'] );
  247. $ftp_user_name = nv_unhtmlspecialchars( $global_config['ftp_user_name'] );
  248. $ftp_user_pass = nv_unhtmlspecialchars( $global_config['ftp_user_pass'] );
  249. $ftp_path = nv_unhtmlspecialchars( $global_config['ftp_path'] );
  250. include_once ( NV_ROOTDIR . '/includes/class/ftp.class.php' );
  251. $ftp = new NVftp( $ftp_server, $ftp_user_name, $ftp_user_pass, array( 'timeout' => 20 ), $ftp_port );
  252. if( empty( $ftp->error ) and $ftp->chdir( $ftp_path ) )
  253. {
  254. $is_ftp = true;
  255. }
  256. }
  257. // Nhat ki
  258. $logs_message = array();
  259. $logs_status = array();
  260. // Bat dau tao thu muc
  261. foreach ( $files as $file_i )
  262. {
  263. $cp = "";
  264. $e = explode( "/", $file_i );
  265. foreach ( $e as $p )
  266. {
  267. if ( ! empty( $p ) and is_dir( NV_ROOTDIR . '/install/update/' . $cp . $p ) and ! is_dir( NV_ROOTDIR . '/' . $cp . $p ) )
  268. {
  269. // Neu khong tao thu muc theo cach thong thuong thi tao bang FTP (neu co)
  270. if( ( @mkdir( NV_ROOTDIR . '/' . $cp . $p ) == false ) and $is_ftp === true )
  271. {
  272. $ftp->mkdir( $cp . $p );
  273. }
  274. if ( ! is_dir( NV_ROOTDIR . '/' . $cp . $p ) )
  275. {
  276. // Nhat ki that bai
  277. $logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
  278. $logs_status[] = false;
  279. // Luu nhat ki
  280. $this->log( $nv_update_config, $logs_message, $logs_status );
  281. if( $is_ftp === true ) $ftp->close();
  282. return $this->lang['update_error_creat_dir'] . ' ' . $cp . $p;
  283. }
  284. // Nhat ki thanh cong
  285. $logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
  286. $logs_status[] = true;
  287. }
  288. $cp .= $p . '/';
  289. }
  290. }
  291. // Di chuyen cac file
  292. foreach ( $files as $file_i )
  293. {
  294. if ( is_file( NV_ROOTDIR . '/install/update/' . $file_i ) )
  295. {
  296. // Neu ton tai thi xoa truoc
  297. if ( file_exists( NV_ROOTDIR . '/' . $file_i ) )
  298. {
  299. if( @unlink( NV_ROOTDIR . '/' . $file_i ) == false and $is_ftp === true )
  300. {
  301. // Dung ftp de xoa
  302. $ftp->unlink( $file_i );
  303. }
  304. }
  305. // Di chuyen bang cach doi ten duong dan
  306. if( @rename( NV_ROOTDIR . '/install/update/' . $file_i, NV_ROOTDIR . '/' . $file_i ) == false and $is_ftp === true )
  307. {
  308. // Dung ftp di chuyen
  309. $ftp->rename( 'install/update/' . $file_i, $file_i );
  310. }
  311. if ( file_exists( NV_ROOTDIR . '/install/update/' . $file_i ) )
  312. {
  313. // Nhat ki that bai
  314. $logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
  315. $logs_status[] = false;
  316. // Luu nhat ki
  317. $this->log( $nv_update_config, $logs_message, $logs_status );
  318. if( $is_ftp === true ) $ftp->close();
  319. return $this->lang['update_error_move_file'] . ' ' . $file_i;
  320. }
  321. // Nhat ki thanh cong
  322. $logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
  323. $logs_status[] = true;
  324. }
  325. }
  326. // Luu nhat ki
  327. $this->log( $nv_update_config, $logs_message, $logs_status );
  328. return true;
  329. }
  330. /**
  331. * NvUpdate::template()
  332. *
  333. * @param mixed $contents
  334. * @return
  335. */
  336. public function template( $contents )
  337. {
  338. global $language_array;
  339. $xtpl = new XTemplate( "updatetheme.tpl", NV_ROOTDIR . "/install/tpl" );
  340. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  341. $xtpl->assign( 'LANG_VARIABLE', NV_LANG_VARIABLE );
  342. $xtpl->assign( 'NV_LANG_UPDATE', NV_LANG_UPDATE );
  343. $xtpl->assign( 'LANG', $this->lang );
  344. $xtpl->assign( 'CONFIG', $this->config );
  345. if( ! empty( $this->config['formodule'] ) ) // Lay module_file lam tieu de luon
  346. {
  347. $xtpl->assign( 'SITE_TITLE', $this->config['type'] == 1 ? sprintf( $this->lang['updatemod_title_update'], $this->config['formodule'] ) : sprintf( $this->lang['updatemod_title_upgrade'], $this->config['formodule'] ) );
  348. }
  349. else
  350. {
  351. $xtpl->assign( 'SITE_TITLE', $this->config['type'] == 1 ? $this->lang['update_site_title_update'] : $this->lang['update_site_title_upgrade'] );
  352. }
  353. $xtpl->assign( 'CONTENT_TITLE', $this->lang['update_step_title_' . $this->config['step'] ] );
  354. $xtpl->assign( 'MODULE_CONTENT', $contents );
  355. $xtpl->assign( 'LANGTYPESL', NV_LANG_UPDATE );
  356. $langname = $language_array[NV_LANG_UPDATE]['name'];
  357. $xtpl->assign( 'LANGNAMESL', $langname );
  358. foreach( $this->config['allow_lang'] as $languageslist_i )
  359. {
  360. if( ! empty( $languageslist_i ) and ( NV_LANG_UPDATE != $languageslist_i ) )
  361. {
  362. $xtpl->assign( 'LANGTYPE', $languageslist_i );
  363. $langname = $language_array[$languageslist_i]['name'];
  364. $xtpl->assign( 'LANGNAME', $langname );
  365. $xtpl->parse( 'main.looplang' );
  366. }
  367. }
  368. $step_bar = array( $this->lang['update_step_1'], $this->lang['update_step_2'], $this->lang['update_step_3'] );
  369. foreach( $step_bar as $i => $step_bar_i )
  370. {
  371. $n = $i + 1;
  372. $class = "";
  373. if( $this->config['step'] >= $n )
  374. {
  375. $class = " class=\"";
  376. $class .= ( $this->config['step'] > $n ) ? 'passed_step' : '';
  377. $class .= ( $this->config['step'] == $n ) ? 'current_step' : '';
  378. $class .= "\"";
  379. }
  380. $xtpl->assign( 'CLASS_STEP', $class );
  381. $xtpl->assign( 'STEP_BAR', $step_bar_i );
  382. $xtpl->assign( 'NUM', $n );
  383. $xtpl->parse( 'main.step_bar.loop' );
  384. }
  385. $xtpl->parse( 'main.step_bar' );
  386. $xtpl->parse( 'main' );
  387. return $xtpl->text( 'main' );
  388. }
  389. /**
  390. * NvUpdate::step1()
  391. *
  392. * @param mixed $array
  393. * @return
  394. */
  395. public function step1( $array )
  396. {
  397. global $global_config;
  398. $xtpl = new XTemplate( "updatestep1.tpl", NV_ROOTDIR . "/install/tpl" );
  399. $xtpl->assign( 'LANG', $this->lang );
  400. $xtpl->assign( 'CONFIG', $this->config );
  401. $xtpl->assign( 'DATA', $array );
  402. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  403. $xtpl->assign( 'URL_DELETE', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=webtools&amp;' . NV_OP_VARIABLE . '=deleteupdate&amp;checksess=' . md5( $global_config['sitekey'] . session_id() ) );
  404. $xtpl->assign( 'URL_RETURN', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=siteinfo' );
  405. $xtpl->assign( 'RELEASE_DATE', ! empty( $this->config['release_date'] ) ? nv_date( 'd/m/Y H:i:s', $this->config['release_date'] ) : "N/A" );
  406. $xtpl->assign( 'ALLOW_OLD_VERSION', ! empty( $this->config['allow_old_version'] ) ? implode( ', ', $this->config['allow_old_version'] ) : "N/A" );
  407. $xtpl->assign( 'UPDATE_AUTO_TYPE', isset( $this->config['update_auto_type'] ) ? $this->lang['update_auto_type_' . $this->config['update_auto_type']] : "N/A" );
  408. if( ! empty( $this->config['formodule'] ) and empty( $array['module_exist'] ) )
  409. {
  410. $xtpl->parse( 'main.notexistmod' );
  411. }
  412. else
  413. {
  414. if( $array['isupdate_allow'] )
  415. {
  416. $xtpl->parse( 'main.infoupdate.canupdate' );
  417. }
  418. else
  419. {
  420. $xtpl->parse( 'main.infoupdate.cannotupdate' );
  421. }
  422. $xtpl->parse( 'main.infoupdate' );
  423. }
  424. $xtpl->parse( 'main' );
  425. return $xtpl->text( 'main' );
  426. }
  427. /**
  428. * NvUpdate::step2()
  429. *
  430. * @param mixed $array
  431. * @param mixed $substep
  432. * @return
  433. */
  434. public function step2( $array, $substep )
  435. {
  436. global $global_config;
  437. $xtpl = new XTemplate( "updatestep2.tpl", NV_ROOTDIR . "/install/tpl" );
  438. $xtpl->assign( 'LANG', $this->lang );
  439. $xtpl->assign( 'CONFIG', $this->config );
  440. $xtpl->assign( 'DATA', $array );
  441. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  442. if( $substep == 1 ) // Back up cac file de phong bat trac
  443. {
  444. $checksess = md5( $global_config['sitekey'] . session_id() );
  445. if( $array['data_backuped'] ) // Thong bao da backup CSDL vao luc
  446. {
  447. $xtpl->assign( 'DATA_MESSAGE', sprintf( $this->lang['update_data_backuped'], nv_date( 'H:i d/m/Y', $array['data_backuped'] ) ) );
  448. $xtpl->parse( 'main.step1.data_backuped' );
  449. }
  450. if( $array['is_data_backup'] ) // Cho phep backup CSDL
  451. {
  452. $xtpl->assign( 'URL_DUMP_DB_BACKUP', NV_BASE_SITEURL . "install/update.php?step=" . $this->config['step'] . "&amp;substep=" . $substep . "&amp;dump&amp;checksess=" . $checksess );
  453. $xtpl->parse( 'main.step1.is_data_backup' );
  454. }
  455. else // Thong bao khong cho backup CSDL nua
  456. {
  457. $xtpl->parse( 'main.step1.no_data_backup' );
  458. }
  459. if( $array['file_backuped'] ) // Thong bao da backup CODE vao luc
  460. {
  461. $xtpl->assign( 'FILE_MESSAGE', sprintf( $this->lang['update_file_backuped'], nv_date( 'H:i d/m/Y', $array['file_backuped'] ) ) );
  462. $xtpl->parse( 'main.step1.file_backuped' );
  463. }
  464. if( $array['is_file_backup'] ) // Cho phep backup CODE
  465. {
  466. $xtpl->assign( 'URL_DUMP_FILE_BACKUP', NV_BASE_SITEURL . "install/update.php?step=" . $this->config['step'] . "&substep=" . $substep . "&amp;dumpfile&amp;checksess=" . $checksess );
  467. $xtpl->parse( 'main.step1.is_file_backup' );
  468. }
  469. $xtpl->parse( 'main.step1' );
  470. }
  471. elseif( $substep == 2 )
  472. {
  473. if( $this->config['update_auto_type'] == 0 )
  474. {
  475. $xtpl->parse( 'main.step2.manual' );
  476. }
  477. else
  478. {
  479. if( $array['is_move_file'] )
  480. {
  481. $xtpl->parse( 'main.step2.automatic.semiautomatic' );
  482. }
  483. elseif( $this->config['update_auto_type'] == 1 )
  484. {
  485. $xtpl->parse( 'main.step2.automatic.fullautomatic' );
  486. }
  487. else
  488. {
  489. $xtpl->parse( 'main.step2.automatic.info' );
  490. }
  491. // Cong viec lien quan CSDL
  492. if( ! empty( $array['data_list'] ) )
  493. {
  494. foreach( $array['data_list'] as $w )
  495. {
  496. $w['title'] = isset( $this->lang[$w['langkey']] ) ? $this->lang[$w['langkey']] : "N/A";
  497. $xtpl->assign( 'ROW', $w );
  498. $xtpl->parse( 'main.step2.automatic.data.loop' );
  499. }
  500. $xtpl->parse( 'main.step2.automatic.data' );
  501. }
  502. else
  503. {
  504. $xtpl->parse( 'main.step2.automatic.nodata' );
  505. }
  506. // Cong viec lien quan cac file
  507. if( ! empty( $array['file_list'] ) )
  508. {
  509. foreach( $array['file_list'] as $w )
  510. {
  511. $xtpl->assign( 'ROW', $w );
  512. $xtpl->parse( 'main.step2.automatic.file.loop' );
  513. }
  514. $xtpl->parse( 'main.step2.automatic.file' );
  515. }
  516. else
  517. {
  518. $xtpl->parse( 'main.step2.automatic.nofile' );
  519. }
  520. $xtpl->parse( 'main.step2.automatic' );
  521. }
  522. $xtpl->parse( 'main.step2' );
  523. }
  524. elseif( $substep == 3 )
  525. {
  526. if( ! empty( $array['errorStepMoveFile'] ) )
  527. {
  528. $xtpl->parse( 'main.step3.error' );
  529. }
  530. else
  531. {
  532. // Viet cac tien trinh
  533. foreach( $array['task'] as $task )
  534. {
  535. $xtpl->assign( 'ROW', $task );
  536. $xtpl->parse( 'main.step3.data.loop' );
  537. }
  538. if( ! empty( $array['stopprocess'] ) ) // Dung cong viec do loi
  539. {
  540. $xtpl->assign( 'ERROR_MESSAGE', sprintf( $this->lang['update_task_error_message'], $array['stopprocess']['title'] ) );
  541. $xtpl->parse( 'main.step3.data.errorProcess' );
  542. }
  543. elseif( $array['AllPassed'] == true ) // Hoan tat cong viec va chuyen sang buoc tiep theo
  544. {
  545. $xtpl->parse( 'main.step3.data.AllPassed' );
  546. }
  547. else // Tiep tuc khoi chay tien trinh
  548. {
  549. $xtpl->parse( 'main.step3.data.ConStart' );
  550. }
  551. if( $array['AllPassed'] == true and empty( $array['stopprocess'] ) )
  552. {
  553. $xtpl->parse( 'main.step3.data.next_step' );
  554. }
  555. $xtpl->parse( 'main.step3.data' );
  556. }
  557. $xtpl->parse( 'main.step3' );
  558. }
  559. elseif( $substep == 4 )
  560. {
  561. global $sys_info, $nv_update_config;
  562. if( ! $array['getcomplete'] and ! empty( $array['file_list'] ) )
  563. {
  564. if( substr( $sys_info['os'], 0, 3 ) == 'WIN' )
  565. {
  566. $xtpl->parse( 'main.step4.win' );
  567. }
  568. if( $array['FTP_nosupport'] )
  569. {
  570. $xtpl->parse( 'main.step4.FTP_nosupport' );
  571. }
  572. elseif( $array['check_FTP'] )
  573. {
  574. $xtpl->assign( 'ACTIONFORM', NV_BASE_SITEURL . "install/update.php?step=" . $this->config['step'] . "&amp;substep=" . $substep );
  575. if( ! empty( $array['ftpdata']['error'] ) and $array['ftpdata']['show_ftp_error'] )
  576. {
  577. $xtpl->parse( 'main.step4.check_FTP.errorftp' );
  578. }
  579. $xtpl->parse( 'main.step4.check_FTP' );
  580. }
  581. }
  582. $xtpl->assign( 'OK_MESSAGE', sprintf( $this->lang['update_move_complete'], sizeof( $nv_update_config['updatelog']['file_list'] ) ) );
  583. if( empty( $array['file_list'] ) )
  584. {
  585. $xtpl->parse( 'main.step4.complete' );
  586. $xtpl->parse( 'main.step4.next_step' );
  587. }
  588. else
  589. {
  590. $xtpl->assign( 'PROCESS_MESSAGE', sprintf( $this->lang['update_move_num'], sizeof( $array['file_list'] ), sizeof( $nv_update_config['updatelog']['file_list'] ) ) );
  591. $xtpl->parse( 'main.step4.process' );
  592. }
  593. // Danh sach cac file se bi tac dong
  594. foreach( $nv_update_config['updatelog']['file_list'] as $fileID => $fileName )
  595. {
  596. $xtpl->assign( 'ROW', array( 'id' => $fileID, 'name' => $fileName, 'status' => in_array( $fileName, $array['file_list'] ) ? '' : ' iok' ) );
  597. $xtpl->parse( 'main.step4.loop' );
  598. }
  599. $xtpl->parse( 'main.step4' );
  600. }
  601. elseif( $substep == 5 )
  602. {
  603. if( $array['error'] )
  604. {
  605. $xtpl->parse( 'main.step5.error' );
  606. }
  607. else
  608. {
  609. $xtpl->parse( 'main.step5.guide' );
  610. }
  611. $xtpl->parse( 'main.step5' );
  612. }
  613. $xtpl->parse( 'main' );
  614. return $xtpl->text( 'main' );
  615. }
  616. /**
  617. * NvUpdate::step3()
  618. *
  619. * @param mixed $array
  620. * @return
  621. */
  622. public function step3( $array )
  623. {
  624. global $global_config;
  625. $xtpl = new XTemplate( "updatestep3.tpl", NV_ROOTDIR . "/install/tpl" );
  626. $xtpl->assign( 'LANG', $this->lang );
  627. $xtpl->assign( 'CONFIG', $this->config );
  628. $xtpl->assign( 'DATA', $array );
  629. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  630. $xtpl->assign( 'URL_DELETE', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=webtools&amp;' . NV_OP_VARIABLE . '=deleteupdate&amp;checksess=' . md5( $global_config['sitekey'] . session_id() ) );
  631. $xtpl->assign( 'URL_GOHOME', NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA );
  632. $xtpl->assign( 'URL_GOADMIN', NV_BASE_ADMINURL );
  633. if( empty( $this->config['formodule'] ) )
  634. {
  635. $xtpl->parse( 'main.typefull' );
  636. }
  637. else
  638. {
  639. $xtpl->parse( 'main.typemodule' );
  640. }
  641. $xtpl->parse( 'main' );
  642. return $xtpl->text( 'main' );
  643. }
  644. /**
  645. * NvUpdate::PackageErrorTheme()
  646. *
  647. * @return
  648. */
  649. public function PackageErrorTheme()
  650. {
  651. global $global_config;
  652. $xtpl = new XTemplate( "packageerror.tpl", NV_ROOTDIR . "/install/tpl" );
  653. $xtpl->assign( 'LANG', $this->lang );
  654. $xtpl->assign( 'CONFIG', $this->config );
  655. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  656. $xtpl->assign( 'URL_DELETE', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=webtools&amp;' . NV_OP_VARIABLE . '=deleteupdate&amp;checksess=' . md5( $global_config['sitekey'] . session_id() ) );
  657. $xtpl->assign( 'URL_RETURN', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=siteinfo' );
  658. $xtpl->parse( 'main' );
  659. return $xtpl->text( 'main' );
  660. }
  661. /**
  662. * NvUpdate::version_info()
  663. *
  664. * @param mixed $array
  665. * @return
  666. */
  667. public function version_info( $array )
  668. {
  669. $xtpl = new XTemplate( "updatestep3.tpl", NV_ROOTDIR . "/install/tpl" );
  670. $xtpl->assign( 'LANG', $this->lang );
  671. $xtpl->assign( 'CONFIG', $this->config );
  672. $xtpl->assign( 'DATA', $array );
  673. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  674. if( $array['checkversion'] )
  675. {
  676. $xtpl->parse( 'version_info.checkversion' );
  677. }
  678. $xtpl->parse( 'version_info' );
  679. echo( $xtpl->text( 'version_info' ) );
  680. exit();
  681. }
  682. /**
  683. * NvUpdate::module_info()
  684. *
  685. * @param mixed $onlineModules
  686. * @param mixed $userModules
  687. * @return
  688. */
  689. public function module_info( $onlineModules, $userModules )
  690. {
  691. global $global_config;
  692. $xtpl = new XTemplate( "updatestep3.tpl", NV_ROOTDIR . "/install/tpl" );
  693. $xtpl->assign( 'LANG', $this->lang );
  694. $xtpl->assign( 'CONFIG', $this->config );
  695. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  696. $i = 0;
  697. foreach( $userModules as $mod )
  698. {
  699. if( $mod['mode'] != 'sys' )
  700. {
  701. $mod['note'] = $this->lang['update_mod_othermod'];
  702. }
  703. else
  704. {
  705. $mod['note'] = $this->lang['update_mod_uptodate'];
  706. }
  707. $mod['class'] = $i ++ % 2 ? 'specalt' : 'spec';
  708. $mod['time'] = nv_date( 'd/m/y H:i', $mod['time'] );
  709. $xtpl->assign( 'ROW', $mod );
  710. $xtpl->parse( 'module_info.loop' );
  711. }
  712. $xtpl->parse( 'module_info' );
  713. echo( $xtpl->text( 'module_info' ) );
  714. exit();
  715. }
  716. /**
  717. * NvUpdate::module_com_info()
  718. *
  719. * @param mixed $onlineModules
  720. * @return
  721. */
  722. public function module_com_info( $onlineModules )
  723. {
  724. global $global_config;
  725. $xtpl = new XTemplate( "updatestep3.tpl", NV_ROOTDIR . "/install/tpl" );
  726. $xtpl->assign( 'LANG', $this->lang );
  727. $xtpl->assign( 'CONFIG', $this->config );
  728. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  729. $lastest_version = "N/A";
  730. if( ! isset( $onlineModules[$this->config['formodule']] ) )
  731. {
  732. $xtpl->parse( 'commodule.notcertified' );
  733. }
  734. else
  735. {
  736. $lastest_version = isset( $onlineModules[$this->config['formodule']]['version'] ) ? ( string ) $onlineModules[$this->config['formodule']]['version'] : "N/A";
  737. if( nv_version_compare( $lastest_version, $this->config['to_version'] ) > 0 )
  738. {
  739. $xtpl->parse( 'commodule.checkversion' );
  740. }
  741. }
  742. $xtpl->assign( 'LASTEST_VERSION', $lastest_version );
  743. $xtpl->parse( 'commodule' );
  744. echo( $xtpl->text( 'commodule' ) );
  745. exit();
  746. }
  747. /**
  748. * NvUpdate::log()
  749. *
  750. * @param mixed $nv_update_config
  751. * @param mixed $content
  752. * @param mixed $status
  753. * @return
  754. */
  755. public function log( $nv_update_config, $content, $status )
  756. {
  757. global $client_info;
  758. // Danh dau phien bat dau khoi tao
  759. if( ! isset( $nv_update_config['updatelog']['starttime'] ) )
  760. {
  761. $nv_update_config['updatelog']['starttime'] = NV_CURRENTTIME;
  762. $this->set_data_log( $nv_update_config['updatelog'] );
  763. }
  764. $file_log = 'log-update-' . nv_date( 'H-i-s-d-m-Y', $nv_update_config['updatelog']['starttime'] ) . '-' . $client_info['session_id'] . '.log';
  765. $time = nv_date( 'H:i:s_d-m-Y' );
  766. if( ! is_array( $content ) )
  767. {
  768. $content = array( 0 => $content );
  769. $status = array( 0 => $status );
  770. }
  771. $contents = '';
  772. foreach( $content as $key => $mess )
  773. {
  774. $st = empty( $status[$key] ) ? 'FAILURE' : 'SUCCESS';
  775. $contents .= $time . ' | ' . $client_info['ip'] . ' | ' . $mess . ' | ' . $st . "\n";
  776. }
  777. if( ! file_exists( NV_ROOTDIR . "/" . NV_LOGS_DIR . "/data_logs/" . $file_log ) )
  778. {
  779. $contents = $this->lang['update_log_start'] . ': ' . $time . "\n" . $contents;
  780. }
  781. file_put_contents( NV_ROOTDIR . "/" . NV_LOGS_DIR . "/data_logs/" . $file_log, $contents, FILE_APPEND );
  782. }
  783. /**
  784. * NvUpdate::call_error()
  785. *
  786. * @param mixed $message
  787. * @return
  788. */
  789. public function call_error( $message )
  790. {
  791. $xtpl = new XTemplate( "updateerror.tpl", NV_ROOTDIR . "/install/tpl" );
  792. $xtpl->assign( 'LANG', $this->lang );
  793. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  794. $xtpl->assign( 'MESSAGE', $message );
  795. $xtpl->parse( 'main' );
  796. return $xtpl->text( 'main' );
  797. }
  798. }
  799. // Load lai phien lam viec
  800. $nv_update_config['updatelog'] = array();
  801. if( file_exists( NV_ROOTDIR . "/" . NV_DATADIR . "/config_update_" . $nv_update_config['packageID'] . ".php" ) )
  802. {
  803. include ( NV_ROOTDIR . "/" . NV_DATADIR . "/config_update_" . $nv_update_config['packageID'] . ".php" );
  804. }
  805. // Buoc nang cap
  806. $nv_update_config['step'] = $nv_Request->get_int( 'step', 'get', 1 );
  807. if( $nv_update_config['step'] < 1 or ! isset( $nv_update_config['updatelog']['step'] ) or $nv_update_config['step'] > 3 or $nv_update_config['updatelog']['step'] < ( $nv_update_config['step'] - 1 ) )
  808. {
  809. $nv_update_config['step'] = 1;
  810. }
  811. $NvUpdate = new NvUpdate( $nv_update_config );
  812. // Goi $site_mod neu cap nhat module
  813. if( ! empty( $nv_update_config['formodule'] ) ) $site_mods = nv_site_mods();
  814. // Trang chinh
  815. $contents = "";
  816. if( $nv_update_config['step'] == 1 ) // Kiem tra phien ban va tuong thich du lieu
  817. {
  818. if( $NvUpdate->check_package() === false ) // Kiem tra chuan goi cap nhat
  819. {
  820. $contents = $NvUpdate->PackageErrorTheme();
  821. }
  822. else
  823. {
  824. $array = array();
  825. // Kiem tra ton tai module can nang cap neu kieu nang cap module
  826. if( ! empty( $nv_update_config['formodule'] ) )
  827. {
  828. $array['module_exist'] = false;
  829. foreach( $site_mods as $mod )
  830. {
  831. if( $mod['module_file'] == $nv_update_config['formodule'] )
  832. {
  833. $array['module_exist'] = true;
  834. break;
  835. }
  836. }
  837. if( $array['module_exist'] )
  838. {
  839. // Lay phien ban module
  840. $sql = "SELECT `mod_version` FROM `" . $db_config['prefix'] . "_setup_modules` WHERE `module_file`=" . $db->dbescape( $nv_update_config['formodule'] );
  841. $result = $db->sql_query( $sql );
  842. $row = $db->sql_fetchrow( $result );
  843. $v = "";
  844. $d = 0;
  845. if ( preg_match( "/^([^\s]+)\s+([\d]+)$/", $row['mod_version'], $matches ) )
  846. {
  847. $v = ( string )$matches[1];
  848. $d = ( int )$matches[2];
  849. }
  850. $array['current_version'] = trim( $v );
  851. }
  852. else
  853. {
  854. $array['current_version'] = "";
  855. }
  856. }
  857. else
  858. {
  859. $array['current_version'] = $NvUpdate->build_full_ver( $global_config['version'], $global_config['revision'] );
  860. }
  861. // Kiem tra ho tro phien ban nang cap
  862. if( in_array( $array['current_version'], $nv_update_config['allow_old_version'] ) )
  863. {
  864. $array['ability'] = $lang_module['update_ability_1'];
  865. $array['isupdate_allow'] = true;
  866. }
  867. else
  868. {
  869. $array['ability'] = $lang_module['update_ability_0'];
  870. $array['isupdate_allow'] = false;
  871. }
  872. // Kiem tra va ghi log data
  873. $step = ( $array['isupdate_allow'] ) ? 1 : 0;
  874. if( $step == 0 or ! isset( $nv_update_config['updatelog']['step'] ) or $nv_update_config['updatelog']['step'] < $step )
  875. {
  876. $nv_update_config['updatelog']['step'] = $step;
  877. $nv_update_config['updatelog']['old_version'] = $array['current_version'];
  878. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  879. }
  880. unset( $step );
  881. $contents = $NvUpdate->step1( $array );
  882. }
  883. }
  884. elseif( $nv_update_config['step'] == 2 ) // Buoc nang cap: Backup => List cong viec => Cap nhat CSDL => Di chuyen file => Nang cap bang tay.
  885. {
  886. $array = array();
  887. $set_log = false;
  888. // Kiem tra thu tu cac buoc con
  889. $nv_update_config['substep'] = $nv_Request->get_int( 'substep', 'get', 1 );
  890. if( $nv_update_config['substep'] < 1 or ! isset( $nv_update_config['updatelog']['substep'] ) or $nv_update_config['substep'] > 5 or $nv_update_config['updatelog']['substep'] < ( $nv_update_config['substep'] - 1 ) )
  891. {
  892. $nv_update_config['substep'] = 1;
  893. }
  894. if( $nv_update_config['substep'] == 1 ) // Backup CSDL va CODE
  895. {
  896. // Backup CSDL
  897. if( $nv_Request->isset_request( 'dump', 'get' ) )
  898. {
  899. $checksess = filter_text_input( 'checksess', 'get', '' );
  900. if( $checksess != md5( $global_config['sitekey'] . session_id() ) ) die( 'Error!!!' );
  901. $type = filter_text_input( 'type', 'get', '' );
  902. $current_day = mktime( 0, 0, 0, date( "n", NV_CURRENTTIME ), date( "j", NV_CURRENTTIME ), date( "Y", NV_CURRENTTIME ) );
  903. $contents = array();
  904. $contents['savetype'] = ( $type == "sql" ) ? "sql" : "gz";
  905. $file_ext = ( $contents['savetype'] == "sql" ) ? "sql" : "sql.gz";
  906. $log_dir = NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup";
  907. $contents['filename'] = $log_dir . "/" . md5( nv_genpass( 10 ) . $client_info['session_id'] ) . "_" . $current_day . "." . $file_ext;
  908. if( ! file_exists( $contents['filename'] ) )
  909. {
  910. $contents['tables'] = array();
  911. $res = $db->sql_query( "SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'" );
  912. while( $item = $db->sql_fetchrow( $res ) )
  913. {
  914. $contents['tables'][] = $item[0];
  915. }
  916. $db->sql_freeresult( $res );
  917. $contents['type'] = "all";
  918. include ( NV_ROOTDIR . "/includes/core/dump.php" );
  919. $dump = nv_dump_save( $contents );
  920. // Ghi log
  921. $NvUpdate->log( $nv_update_config, $lang_module['update_dump'] . ' ' . $contents['savetype'], $dump );
  922. if( $dump == false )
  923. {
  924. die( $lang_module['update_dump_error'] );
  925. }
  926. else
  927. {
  928. $file = str_replace( NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup/", "", $dump[0] );
  929. // Danh dau da sao luu CSDL
  930. $nv_update_config['updatelog']['data_backuped'] = NV_CURRENTTIME;
  931. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  932. die( $lang_module['update_dump_ok'] . ' ' . nv_convertfromBytes( $dump[1] ) . '<br /><a href="' . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=database&amp;" . NV_OP_VARIABLE . "=getfile&amp;filename=" . $file. "&amp;checkss=" . md5( $file . $client_info['session_id'] . $global_config['sitekey'] ) . '" title="' . $lang_module['update_dump_download'] . '">' . $lang_module['update_dump_download'] . '</a>' );
  933. }
  934. }
  935. else
  936. {
  937. die( $lang_module['update_dump_exist'] );
  938. }
  939. }
  940. // Download CODE thay doi
  941. if( $nv_Request->isset_request( 'downfile', 'get' ) )
  942. {
  943. $checksess = filter_text_input( 'checksess', 'get', '' );
  944. if( $checksess != md5( $global_config['sitekey'] . session_id() ) ) die( 'Error!!!' );
  945. $file = filter_text_input( 'downfile', 'get', '' );
  946. if( ! file_exists( NV_ROOTDIR . '/' . NV_LOGS_DIR . '/data_logs/' . $file ) )
  947. {
  948. $NvUpdate->log( $nv_update_config, $lang_module['update_log_dump_file_down'], false );
  949. die('Error Access!!!');
  950. }
  951. else
  952. {
  953. $NvUpdate->log( $nv_update_config, $lang_module['update_log_dump_file_down'], true );
  954. //Download file
  955. require_once ( NV_ROOTDIR . '/includes/class/download.class.php' );
  956. $download = new download( NV_ROOTDIR . '/' . NV_LOGS_DIR . '/data_logs/' . $file, NV_ROOTDIR . '/' . NV_LOGS_DIR . '/data_logs', 'backup_update_' . date( 'Y_m_d' ) . '.zip' );
  957. $download->download_file();
  958. exit();
  959. }
  960. }
  961. // Sao luu file thay doi
  962. if( $nv_Request->isset_request( 'dumpfile', 'get' ) )
  963. {
  964. $zip_file_backup = array();
  965. // Sao luu file thay doi
  966. if( ! empty( $nv_update_config['updatelog']['file_list'] ) )
  967. {
  968. foreach ( $nv_update_config['updatelog']['file_list'] as $file_i )
  969. {
  970. if ( is_file( NV_ROOTDIR . '/' . $file_i ) )
  971. {
  972. $zip_file_backup[] = NV_ROOTDIR . '/' . $file_i;
  973. }
  974. }
  975. }
  976. // Sao luu tat ca cac file | Cu de nhung tam thoi co le khong dung duoc
  977. if( empty( $zip_file_backup ) )
  978. {
  979. $file_list = $NvUpdate->list_all_file( NV_ROOTDIR );
  980. foreach( $file_list as $file_i )
  981. {
  982. if( ! preg_match( '/^install\/update\/(.*)$/', $file_i ) )
  983. {
  984. $zip_file_backup[] = NV_ROOTDIR . '/' . $file_i;
  985. }
  986. }
  987. }
  988. if ( ! empty( $zip_file_backup ) )
  989. {
  990. $file_src = 'backup_update_' . date( 'Y_m_d' ) . '_' . md5( $global_config['sitekey'] . session_id() ) . '.zip';
  991. // Kiem tra file ton tai
  992. $filename2 = $file_src;
  993. $i = 1;
  994. while( file_exists( NV_ROOTDIR . '/' . NV_LOGS_DIR . '/data_logs/' . $filename2 ) )
  995. {
  996. $filename2 = preg_replace( '/(.*)(\.[a-zA-Z0-9]+)$/', '\1_' . $i . '\2', $file_src );
  997. $i++;
  998. }
  999. require_once NV_ROOTDIR . '/includes/class/pclzip.class.php';
  1000. $zip = new PclZip( NV_ROOTDIR . '/' . NV_LOGS_DIR . '/data_logs/' . $filename2 );
  1001. $return = $zip->add( $zip_file_backup, PCLZIP_OPT_REMOVE_PATH, NV_ROOTDIR );
  1002. if ( empty( $return ) )
  1003. {
  1004. // Ghi Log
  1005. $NvUpdate->log( $nv_update_config, $lang_module['update_log_dump_file'], false );
  1006. die( $lang_module['update_file_backup_error'] );
  1007. }
  1008. else
  1009. {
  1010. // Ghi log
  1011. $NvUpdate->log( $nv_update_config, $lang_module['update_log_dump_file'], true );
  1012. // Danh dau da sao luu
  1013. $nv_update_config['updatelog']['file_backuped'] = NV_CURRENTTIME;
  1014. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1015. die( '<a href="' . NV_BASE_SITEURL . 'install/update.php?step=2&amp;substep=4&downfile=' . $filename2 . '&checksess=' . md5( $global_config['sitekey'] . session_id() ) . '" title="' . $lang_module['update_log_dump_file_down'] . '">' . $lang_module['update_file_backup_ok'] . '</a>' );
  1016. }
  1017. }
  1018. }
  1019. // Cong viec di chuyen file
  1020. if( ! isset( $nv_update_config['updatelog']['file_list'] ) )
  1021. {
  1022. $file_list = $NvUpdate->list_all_file();
  1023. $nv_update_config['updatelog']['file_list'] = $file_list;
  1024. $set_log = true;
  1025. }
  1026. // Cong viec nang cap CSDL
  1027. if( ! isset( $nv_update_config['updatelog']['data_list'] ) )
  1028. {
  1029. $data_list = $NvUpdate->list_data_update();
  1030. $nv_update_config['updatelog']['data_list'] = $data_list;
  1031. $set_log = true;
  1032. }
  1033. // Kiem tra va backup
  1034. $array['is_file_backup'] = true;
  1035. $array['file_backuped'] = isset( $nv_update_config['updatelog']['file_backuped'] ) ? $nv_update_config['updatelog']['file_backuped'] : 0;
  1036. if( isset( $nv_update_config['updatelog']['is_start_move_file'] ) ) // Bat dau di chuyen file roi thi khong backup
  1037. {
  1038. $array['is_file_backup'] = false;
  1039. }
  1040. elseif( empty( $nv_update_config['updatelog']['file_list'] ) )
  1041. {
  1042. $array['is_file_backup'] = false;
  1043. }
  1044. $array['is_data_backup'] = true;
  1045. $array['data_backuped'] = isset( $nv_update_config['updatelog']['data_backuped'] ) ? $nv_update_config['updatelog']['data_backuped'] : 0;
  1046. if( isset( $nv_update_config['updatelog']['is_start_up_db'] ) ) // Da cap nhat CSDL roi thi khong backup
  1047. {
  1048. $array['is_data_backup'] = false;
  1049. }
  1050. // Luu lai cong viec se thuc hien
  1051. if( ! isset( $nv_update_config['updatelog']['substep'] ) or $nv_update_config['updatelog']['substep'] < 1 )
  1052. {
  1053. $nv_update_config['updatelog']['substep'] = 1; // Buoc nay co the bo qua do do luu de sang buoc 2
  1054. $set_log = true;
  1055. }
  1056. // Ghi data log
  1057. if( $set_log )
  1058. {
  1059. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1060. }
  1061. // Kiem tra va chuyen huong neu khong co thay doi CSDL va FILE
  1062. if( empty( $nv_update_config['updatelog']['file_list'] ) and empty( $nv_update_config['updatelog']['data_list'] ) )
  1063. {
  1064. if( $nv_update_config['update_auto_type'] == 0 ) // Neu la nang cap thu cong thi kiem tra file va dieu huong
  1065. {
  1066. if( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1067. {
  1068. // Chuyen buoc 2/2 - Nang cap thu cong
  1069. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=2&substep=2' );
  1070. exit();
  1071. }
  1072. else
  1073. {
  1074. // Chuyen buoc 3
  1075. $nv_update_config['updatelog']['step'] = 2;
  1076. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1077. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=3' );
  1078. exit();
  1079. }
  1080. }
  1081. elseif( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) ) // Neu nguoc lai kiem tra file ton tai chuyen buoc 5/2
  1082. {
  1083. $nv_update_config['updatelog']['substep'] = 4;
  1084. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1085. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=2&substep=5' );
  1086. exit();
  1087. }
  1088. else // Chuyen buoc 3
  1089. {
  1090. $nv_update_config['updatelog']['step'] = 2;
  1091. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1092. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=3' );
  1093. exit();
  1094. }
  1095. }
  1096. }
  1097. elseif( $nv_update_config['substep'] == 2 ) // Kiem tra va thong ke cac cong viec se thuc hien
  1098. {
  1099. // Nang cap bang tay
  1100. if( $nv_update_config['update_auto_type'] == 0 )
  1101. {
  1102. $array['guide'] = "N/A";
  1103. // Co file huong dan thi goi ra
  1104. if( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1105. {
  1106. $array['guide'] = file_get_contents( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' );
  1107. }
  1108. // Khong co file huong dan thi chuyen sang buoc 3
  1109. else
  1110. {
  1111. $nv_update_config['updatelog']['step'] = 2;
  1112. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1113. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=3' );
  1114. exit();
  1115. }
  1116. // Ghi lai data log
  1117. if( $nv_update_config['updatelog']['step'] < 2 )
  1118. {
  1119. $nv_update_config['updatelog']['step'] = 2;
  1120. $set_log = true;
  1121. }
  1122. }
  1123. // Nang cap tu dong/Nua tu dong
  1124. else
  1125. {
  1126. // De den duoc day thi bat buoc phai co mot trong hai cong viec ben duoi
  1127. // Danh dau buoc nay de den buoc tiep theo
  1128. if( $nv_update_config['updatelog']['substep'] < 2 )
  1129. {
  1130. $nv_update_config['updatelog']['substep'] = 2;
  1131. $set_log = true;
  1132. }
  1133. // Xac dinh phai di chuyen cac file thu cong
  1134. $array['is_move_file'] = false;
  1135. if( $nv_update_config['update_auto_type'] == 2 and ! empty( $nv_update_config['updatelog']['file_list'] ) )
  1136. {
  1137. $array['is_move_file'] = true;
  1138. }
  1139. $array['file_list'] = $nv_update_config['updatelog']['file_list'];
  1140. $array['data_list'] = $nv_update_config['updatelog']['data_list'];
  1141. }
  1142. if( $set_log === true )
  1143. {
  1144. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1145. }
  1146. }
  1147. elseif( $nv_update_config['substep'] == 3 ) // Buoc cap nhat CSDL
  1148. {
  1149. // Kiem tra loi neu buoc cap nhat nua tu dong
  1150. $array['errorStepMoveFile'] = false;
  1151. if( $nv_update_config['update_auto_type'] == 2 )
  1152. {
  1153. $check_list_file = $NvUpdate->list_all_file();
  1154. if( ! empty( $check_list_file ) )
  1155. {
  1156. $array['errorStepMoveFile'] = true;
  1157. }
  1158. elseif( ! isset( $nv_update_config['updatelog']['is_start_move_file'] ) )
  1159. {
  1160. // Danh dau da di chuyen cac file roi
  1161. $nv_update_config['updatelog']['is_start_move_file'] = NV_CURRENTTIME;
  1162. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1163. }
  1164. // Neu khong co cong viec nang cap CSDL nao va kieu nang cap nua tu dong thi chuyen den buoc 3 neu khong co huong dan nang cap
  1165. if( empty( $nv_update_config['updatelog']['data_list'] ) and ! file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1166. {
  1167. $nv_update_config['updatelog']['step'] = 2;
  1168. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1169. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=3' );
  1170. exit();
  1171. }
  1172. // Chuyen den buoc 5 de xem huong dan nang cap
  1173. elseif( empty( $nv_update_config['updatelog']['data_list'] ) )
  1174. {
  1175. $nv_update_config['updatelog']['substep'] = 4;
  1176. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1177. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=2&substep=5' );
  1178. exit();
  1179. }
  1180. }
  1181. // Neu khong co cong viec nang cap CSDL nao thi chuyen den buoc 4
  1182. if( empty( $nv_update_config['updatelog']['data_list'] ) )
  1183. {
  1184. $nv_update_config['updatelog']['substep'] = 3;
  1185. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1186. Header( 'Location:' . NV_BASE_SITEURL . 'install/update.php?step=2&substep=4' );
  1187. exit();
  1188. }
  1189. if( ! $array['errorStepMoveFile'] )
  1190. {
  1191. // Tien trinh bat dau chay
  1192. if( $nv_Request->isset_request( 'load', 'get' ) )
  1193. {
  1194. $func = filter_text_input( 'load', 'get', '' );
  1195. $nv_update_baseurl = NV_BASE_SITEURL . 'install/update.php?step=2&substep=3&load=' . $func;
  1196. $old_module_version = $nv_update_config['updatelog']['old_version'];
  1197. /*
  1198. Chuan hoa tra ve cho Ajax
  1199. status|funcname|functitle|url|lang|message|stop|allcomplete
  1200. status:
  1201. - 0: That bai
  1202. - 1: Thanh cong
  1203. funcname: Ten ham tiep theo thuc hien
  1204. functitle: Ten cong viec tiep theo se thuc hien
  1205. url: Duong dan tiep theo duoc load
  1206. lang: Cac ngon ngu bi loi
  1207. message: Thong tin (duoc add vao functitle sau dau -)
  1208. stop: Dung tien trinh
  1209. allcomplete: Hoan tat tat ca tien trinh
  1210. */
  1211. $return = array(
  1212. 'status' => '0',
  1213. 'funcname' => 'NO',
  1214. 'functitle' => 'NO',
  1215. 'url' => 'NO',
  1216. 'lang' => 'NO',
  1217. 'message' => 'NO',
  1218. 'stop' => '1',
  1219. 'allcomplete' => '0',
  1220. );
  1221. if( ! isset( $nv_update_config['updatelog']['data_list'][$func] ) ) $return['stop'] = '1';
  1222. if( ! nv_function_exists( $func ) ) $return['stop'] = '1';
  1223. $check_return = call_user_func( $func ); // Goi ham thuc hien nang cap
  1224. // Trang thai thuc hien
  1225. $return['status'] = $check_return['status'] ? '1' : '0';
  1226. $return['stop'] = ( $check_return['status'] == 0 and $nv_update_config['updatelog']['data_list'][$func]['require'] == 2 ) ? '1' : '0';
  1227. $return['message'] = $check_return['message'];
  1228. $last_task = end( $nv_update_config['updatelog']['data_list'] );
  1229. $last_task_key = key( $nv_update_config['updatelog']['data_list'] );
  1230. // Kiem tra ket thuc tien trinh
  1231. if( $last_task_key == $func and $return['stop'] == '0' )
  1232. {
  1233. $return['allcomplete'] = '1';
  1234. // Ghi lai de chuyen sang buoc tiep theo
  1235. if( $nv_update_config['update_auto_type'] == 2 )
  1236. {
  1237. if( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1238. {
  1239. $nv_update_config['updatelog']['substep'] = 4;
  1240. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1241. }
  1242. else
  1243. {
  1244. $nv_update_config['updatelog']['step'] = 2;
  1245. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1246. }
  1247. }
  1248. else
  1249. {
  1250. $nv_update_config['updatelog']['substep'] = 3;
  1251. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1252. }
  1253. }
  1254. if( $return['allcomplete'] != '1' and $return['stop'] != '1' )
  1255. {
  1256. // Kiem tra tiep tuc, neu tiep tuc thi khong can URL
  1257. if( $check_return['next'] )
  1258. {
  1259. $is_get_next = false;
  1260. foreach( $nv_update_config['updatelog']['data_list'] as $k => $v )
  1261. {
  1262. if( $is_get_next == true )
  1263. {
  1264. $return['funcname'] = $k;
  1265. $v['title'] = isset( $lang_module[$v['langkey']] ) ? $lang_module[$v['langkey']] : "N/A";
  1266. $return['functitle'] = $v['title'];
  1267. break;
  1268. }
  1269. if( $k == $func ) $is_get_next = true;
  1270. }
  1271. unset( $is_get_next, $k, $v );
  1272. }
  1273. else
  1274. {
  1275. $return['url'] = $check_return['link'];
  1276. $return['funcname'] = $func;
  1277. $langkey = $nv_update_config['updatelog']['data_list'][$func]['langkey'];
  1278. $return['functitle'] = isset( $lang_module[$langkey] ) ? $lang_module[$langkey] : "N/A";
  1279. unset( $langkey );
  1280. }
  1281. }
  1282. // Danh dau log passed
  1283. if( $check_return['complete'] == 1 )
  1284. {
  1285. $nv_update_config['updatelog']['data_passed'][$func] = $check_return['status'] ? 1 : 2;
  1286. }
  1287. if( ! isset( $nv_update_config['updatelog']['is_start_up_db'] ) )
  1288. {
  1289. $nv_update_config['updatelog']['is_start_up_db'] = NV_CURRENTTIME;
  1290. }
  1291. // Ghi log data
  1292. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1293. // Ghi logs
  1294. $langkey = $nv_update_config['updatelog']['data_list'][$func]['langkey'];
  1295. $functitle = isset( $lang_module[$langkey] ) ? $lang_module[$langkey] : "N/A";
  1296. $log_message = $functitle . ( $check_return['message'] ? ( ' - ' . $check_return['message'] ) : '' );
  1297. $NvUpdate->log( $nv_update_config, $log_message, $check_return['status'] );
  1298. die( implode( '|', $return ) );
  1299. }
  1300. $array['task'] = array();
  1301. $array['started'] = false; // Da bat dau chua
  1302. $array['nextfunction'] = ''; // Ham tiep theo se thuc hien
  1303. $array['nextftitle'] = ''; // Ten cong viec tiep theo se thuc hien
  1304. $array['stopprocess'] = array(); // Dung tien trinh
  1305. $array['AllPassed'] = false; // Da hoan tat toan bo cac cong viec
  1306. $get_next_func = false;
  1307. $num_passed = 0;
  1308. foreach( $nv_update_config['updatelog']['data_list'] as $funcsname => $task )
  1309. {
  1310. // Xuat tieu de
  1311. $task['title'] = isset( $lang_module[$task['langkey']] ) ? $lang_module[$task['langkey']] : "N/A";
  1312. // Khoi tao ham tiep theo thuc hien
  1313. if( empty( $array['nextfunction'] ) )
  1314. {
  1315. $array['nextfunction'] = $funcsname;
  1316. $array['nextftitle'] = $task['title'];
  1317. }
  1318. // Danh dau ham tiep theo se thuc hien
  1319. if( $get_next_func == true )
  1320. {
  1321. $array['nextfunction'] = $funcsname;
  1322. $array['nextftitle'] = $task['title'];
  1323. $get_next_func = false;
  1324. }
  1325. // $passed:
  1326. // - 0: Chua thuc hien
  1327. // - 1: Da hoan thanh
  1328. // - 2: That bai
  1329. $passed = isset( $nv_update_config['updatelog']['data_passed'][$funcsname] ) ? $nv_update_config['updatelog']['data_passed'][$funcsname] : 0;
  1330. switch( $passed )
  1331. {
  1332. case 0: $class = ''; break;
  1333. case 1: $class = ' iok'; break;
  1334. default: $class = ( ( $task['require'] == 0 ) ? ' iok' : ( ( $task['require'] == 1 ) ? ' iwarn' : ' ierror' ) );
  1335. }
  1336. $class_trim = trim( $class );
  1337. // Da thuc hien thi danh dau da thuc hien
  1338. if( $array['started'] == false and $passed > 0 ) $array['started'] = true;
  1339. // Tinh toan ham tiep theo se thuc hien, them vao danh dach cac cong viec da thuc hien (du thanh cong hay that bai)
  1340. if( $passed > 0 )
  1341. {
  1342. $get_next_func = true;
  1343. $num_passed = $num_passed + 1;
  1344. }
  1345. // Dung tien trinh
  1346. if( $class_trim == 'ierror' and empty( $array['stopprocess'] ) )
  1347. {
  1348. $array['stopprocess'] = array(
  1349. 'id' => $funcsname,
  1350. 'title' => $task['title']
  1351. );
  1352. }
  1353. $status_title = $lang_module['update_task' . $class_trim ];
  1354. $array['task'][$funcsname] = array(
  1355. 'id' => $funcsname,
  1356. 'title' => $task['title'],
  1357. 'require' => $task['require'],
  1358. 'class' => $class,
  1359. 'status' => $status_title,
  1360. );
  1361. }
  1362. // Kiem tra hoan tat
  1363. if( $num_passed == sizeof( $array['task'] ) )
  1364. {
  1365. $array['AllPassed'] = true;
  1366. // Danh dau hoan tat de tiep tuc buoc di chuyen file (neu KHONG xay ra loi)
  1367. if( empty( $array['stopprocess'] ) )
  1368. {
  1369. if( $nv_update_config['update_auto_type'] == 2 )
  1370. {
  1371. if( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1372. {
  1373. $nv_update_config['updatelog']['substep'] = 4;
  1374. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1375. }
  1376. else
  1377. {
  1378. $nv_update_config['updatelog']['step'] = 2;
  1379. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1380. }
  1381. }
  1382. else
  1383. {
  1384. $nv_update_config['updatelog']['substep'] = 3;
  1385. $NvUpdate->set_data_log( $nv_update_config['updatelog'] );
  1386. }
  1387. }
  1388. }
  1389. // Kiem tra buoc tiep theo
  1390. if( $nv_update_config['update_auto_type'] == 2 )
  1391. {
  1392. if( file_exists( NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html' ) )
  1393. {
  1394. $array['NextStepUrl'] = NV_BASE_SITEURL . 'install/update.php?step=2&amp;substep=5';
  1395. }
  1396. else
  1397. {
  1398. $array['NextStepUrl'] = NV_BASE_SITEURL . 'install/update.php?step=3';
  1399. }
  1400. }
  1401. else
  1402. {
  1403. $array['NextStepUrl'] = NV_BASE_SITEURL . 'install/update.php?step=2&amp;substep=4'

Large files files are truncated, but you can click here to view the full file