PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/clan_convertor_tool/rivals_clan_convertor.php

https://github.com/titanfallpug/phprivals
PHP | 221 lines | 163 code | 26 blank | 32 comment | 20 complexity | 9be5270b84875714dce4d42aadc3ed07 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @package RivalsMod
  5. * @version $Id$
  6. * @copyright (c) 2011 Soshen <nipponart.org> based on Rivals by Tyler N. King <aibotca@yahoo.ca>
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. // Initilize the phpBB sessions.
  18. $user->session_begin();
  19. $auth->acl($user->data);
  20. $user->setup('mods/lang_rivals');
  21. // Include Rivals' classes.
  22. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  23. include($phpbb_root_path . 'rivals/classes/class_group.' . $phpEx);
  24. include($phpbb_root_path . 'rivals/functions.' . $phpEx);
  25. // Start the output.
  26. page_header($user->lang['RIVALS_TITLE']);
  27. $theclans = array();
  28. $themembers = array();
  29. $siteimgid = $config['avatar_salt'];
  30. // check that is the first time that you import clan in 2.0
  31. $result = $db->sql_query("SELECT COUNT(group_id) as clans FROM " . CLANS_TABLE);
  32. $justclans = (int) $db->sql_fetchfield('clans');
  33. $db->sql_freeresult($result);
  34. // check for permission acl
  35. if (!$auth->acl_getf_global('a_'))
  36. {
  37. trigger_error('NOT_AUTHORISED');
  38. }
  39. else if ($auth->acl_getf_global('a_') && $justclans > 0)
  40. {
  41. trigger_error('ALREADY_CLAN_IN_NEW_TABLE');
  42. }
  43. else
  44. {
  45. $submit = (!empty($_POST['submit'])) ? true : false;
  46. if ($submit)
  47. {
  48. // Load in a array all old clan data
  49. $sql = "SELECT * FROM " . GROUPS_TABLE . " WHERE group_type = 2";
  50. $result = $db->sql_query($sql);
  51. while ($row = $db->sql_fetchrow($result))
  52. {
  53. if (strpos($row['group_name'], '::') !== false)
  54. {
  55. $theclans[] = array($row['group_id'], $row['group_name'], $row['group_desc'], $row['group_desc_bitfield'], $row['group_desc_options'], $row['group_desc_uid'], $row['group_avatar'], $row['group_avatar_type'], $row['group_avatar_width'], $row['group_avatar_height'], $row['group_sito']);
  56. $realclans[] = $row['group_id'];
  57. }
  58. }
  59. $db->sql_freeresult($result);
  60. // process each clan for copying
  61. foreach ($theclans AS $clan)
  62. {
  63. // copy the clan logo to new folder if there are one
  64. if (!empty($clan[6]))
  65. {
  66. $ext = substr(strrchr($clan[6], '.'), 1);
  67. $logo = ("{$phpbb_root_path}images/avatars/upload/{$siteimgid}_g{$clan[0]}.{$ext}");
  68. if (is_file($logo))
  69. {
  70. $newdir = ("{$phpbb_root_path}images/rivals/clanlogo/logofclan{$clan[0]}.{$ext}");
  71. rename($logo, $newdir);
  72. }
  73. }
  74. else
  75. {
  76. $ext = 'jpg';
  77. }
  78. // GET STATS
  79. $result = $db->sql_query("SELECT COUNT(match_id) as total_winsA, match_winner, match_confirmed FROM " . MATCHES_TABLE . " WHERE match_winner = {$clan[0]} AND match_confirmed > 0");
  80. $total_wins = (int) $db->sql_fetchfield('total_winsA');
  81. $db->sql_freeresult($result);
  82. $result = $db->sql_query("SELECT COUNT(match_id) as total_lossesA, match_loser, match_confirmed FROM " . MATCHES_TABLE . " WHERE match_loser = {$clan[0]} AND match_confirmed > 0");
  83. $total_losses = (int) $db->sql_fetchfield('total_lossesA');
  84. $db->sql_freeresult($result);
  85. $result = $db->sql_query("SELECT COUNT(match_id) as total_drawsA, match_winner, match_confirmed FROM " . MATCHES_TABLE . " WHERE (match_challenger = {$clan[0]} OR match_challengee = {$clan[0]}) AND match_winner = '9999999' AND match_confirmed > 0");
  86. $total_draws = (int) $db->sql_fetchfield('total_drawsA');
  87. $db->sql_freeresult($result);
  88. $fixname = explode('::', $clan[1]);
  89. // insert clan in the new table
  90. $sql_array = array(
  91. 'group_id' => $clan[0],
  92. 'group_name' => $fixname[1],
  93. 'group_desc' => $clan[2],
  94. 'clan_logo_name' => (!empty($clan[6])) ? "logofclan{$clan[0]}.{$ext}" : "nologo.jpg",
  95. 'clan_logo_ext' => $ext,
  96. 'clan_logo_width' => $clan[8],
  97. 'clan_logo_height' => $clan[9],
  98. 'group_tournaments' => 'N/A',
  99. 'group_sito' => $clan[10],
  100. 'clan_alltime_wins' => $total_wins,
  101. 'clan_alltime_losses' => $total_losses,
  102. 'clan_alltime_pareggi' => $total_draws,
  103. 'clan_level' => 0,
  104. 'clan_creation_date' => time(),
  105. 'clan_target_10streak' => 0,
  106. 'clan_target_ladderwin' => 0,
  107. 'clan_favouritemap' => '',
  108. 'clan_favouriteteam' => '',
  109. 'clan_closed' => 0,
  110. 'rth_chicken' => 0,
  111. 'rth_powner' => 0,
  112. 'clan_rep_value' => 5,
  113. 'clan_rep_time' => 1,
  114. );
  115. // Add it.
  116. $sql = "INSERT INTO " . CLANS_TABLE . " " . $db->sql_build_array('INSERT', $sql_array);
  117. $db->sql_query($sql);
  118. }
  119. /**
  120. * Import the clan members
  121. **/
  122. // Load in a array all old clan data
  123. $sql = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE group_id > 7"; /* groups from 1 to 7 are all default system groups */
  124. $result = $db->sql_query($sql);
  125. while ($row = $db->sql_fetchrow($result))
  126. {
  127. if (in_array($row['group_id'], $realclans)) /* process only groups that are clan for sure */
  128. {
  129. $themembers[] = array($row['group_id'], $row['user_id'], $row['group_leader'], $row['user_pending'], $row['mvp_utente']);
  130. }
  131. }
  132. $db->sql_freeresult($result);
  133. foreach ($themembers AS $member)
  134. {
  135. // insert member in new clan-user table
  136. $sql_array = array(
  137. 'group_id' => $member[0],
  138. 'user_id' => $member[1],
  139. 'group_leader' => $member[2],
  140. 'user_pending' => $member[3],
  141. 'mvp_utente' => $member[4],
  142. 'kills' => 0,
  143. 'deads' => 0,
  144. 'assists' => 0,
  145. 'agoals' => 0,
  146. 'fgoals' => 0,
  147. );
  148. // Add it.
  149. $sql = "INSERT INTO " . USER_CLAN_TABLE . " " . $db->sql_build_array('INSERT', $sql_array);
  150. $db->sql_query($sql);
  151. }
  152. /*************************************
  153. *** CONVERT MATCHES
  154. ********************************/
  155. $sql = "SELECT * FROM " . MATCHES_TABLE . " ORDER BY match_id ASC";
  156. $result = $db->sql_query($sql);
  157. while ($row = $db->sql_fetchrow($result))
  158. {
  159. //1) C&amp;D 2) Cat. Bandiera 3) Demolizione
  160. $modes[] = explode(") ", $row['ordine_modi']);
  161. $mode1 = str_replace('1', '', $modes[1]);
  162. $mode2 = str_replace('2', '', $modes[2]);
  163. $mode3 = str_replace('3', '', $modes[3]);
  164. $sql_array2 = array(
  165. 'match_challanger_score' => ($row['match_winner'] == $row['match_challenger']) ? $row['match_winnerscore'] : $row['match_loserscore'],
  166. 'match_challangee_score' => ($row['match_winner'] == $row['match_challengee']) ? $row['match_winnerscore'] : $row['match_loserscore'],
  167. 'match_challanger_score_mode1' => ($row['match_winner'] == $row['match_challenger']) ? $row['match_winnerscore_ced'] : $row['match_loserscore_ced'],
  168. 'match_challangee_score_mode1' => ($row['match_winner'] == $row['match_challengee']) ? $row['match_winnerscore_ced'] : $row['match_loserscore_ced'],
  169. 'match_challanger_score_mode2' => ($row['match_winner'] == $row['match_challenger']) ? $row['match_winnerscore_dom'] : $row['match_loserscore_dom'],
  170. 'match_challangee_score_mode2' => ($row['match_winner'] == $row['match_challengee']) ? $row['match_winnerscore_dom'] : $row['match_loserscore_dom'],
  171. 'match_challanger_score_mode3' => ($row['match_winner'] == $row['match_challenger']) ? $row['match_winnerscore_flag'] : $row['match_loserscore_flag'],
  172. 'match_challangee_score_mode3' => ($row['match_winner'] == $row['match_challengee']) ? $row['match_winnerscore_flag'] : $row['match_loserscore_flag'],
  173. 'mappa_mode1' => $row['mappa_ced'],
  174. 'mappa_mode2' => $row['mappa_dom'],
  175. 'mappa_mode3' => $row['mappa_flag'],
  176. 'mode1' => $mode1,
  177. 'mode2' => $mode2,
  178. 'mode3' => $mode3,
  179. 'match_reported' => (!empty($row['conferma_win'])) ? $row['conferma_win'] : $row['match_challenger'],
  180. 'match_confirmed' => (!empty($row['conferma_los'])) ? $row['conferma_los'] : $row['match_challengee'],
  181. );
  182. $sql = "UPDATE " . MATCHES_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_array2) . " WHERE match_id = " . $row['match_id'];
  183. $db->sql_query($sql);
  184. }
  185. $db->sql_freeresult($result);
  186. $url = append_sid("{$phpbb_admin_path}index.$phpEx", "i=rivals&amp;mode=main");
  187. trigger_error(sprintf($user->lang['IMPORTATION_FINISHED'], $url));
  188. }
  189. }
  190. $template->assign_vars(array(
  191. 'U_ACTION' => '',
  192. ));
  193. $template->set_filenames(array('body' => 'rivals/rivals_clan_convertor.html'));
  194. page_footer();
  195. ?>