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

/admin/armory_data.php

http://wowroster.googlecode.com/
PHP | 289 lines | 228 code | 36 blank | 25 comment | 17 complexity | 27e8dc0e0b155bedc3ed53b23abe5c0a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * WoWRoster.net WoWRoster
  4. *
  5. * Roster upload rule config
  6. *
  7. *
  8. * @copyright 2002-2011 WoWRoster.net
  9. * @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
  10. * @version SVN: $Id: armory_data.php 2394 2012-02-15 22:05:03Z ulminia@gmail.com $
  11. * @link http://www.wowroster.net
  12. * @since File available since Release 1.8.0
  13. * @package WoWRoster
  14. * @subpackage RosterCP
  15. */
  16. if( !defined('IN_ROSTER') || !defined('IN_ROSTER_ADMIN') )
  17. {
  18. exit('Detected invalid access to this file!');
  19. }
  20. if (isset($_POST['process']) && $_POST['process'] == 'process')
  21. {
  22. $count=1;
  23. // aprint($_POST);
  24. $classid = (isset($_POST['class_id']) ? $_POST['class_id'] : $_GET['class']);
  25. echo '<br>--[ '.$classid.' ]--<br>';
  26. $talents = $roster->api->Talents->getTalentInfo($classid);
  27. $querystr = "DELETE FROM `" . $roster->db->table('talents_data') . "` WHERE `class_id` = '" . $classid . "';";
  28. if (!$roster->db->query($querystr))
  29. {
  30. $roster->set_message('Talent Data Table could not be emptied.', '', 'error');
  31. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  32. return;
  33. }
  34. $querystr = "DELETE FROM `" . $roster->db->table('talenttree_data') . "` WHERE `class_id` = '" . $classid . "';";
  35. if (!$roster->db->query($querystr))
  36. {
  37. $roster->set_message('Talent Tree Data Table could not be emptied.', '', 'error');
  38. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  39. return;
  40. }
  41. //talent_mastery
  42. $querystr = "DELETE FROM `" . $roster->db->table('talent_mastery') . "` WHERE `class_id` = '" . $classid . "';";
  43. if (!$roster->db->query($querystr))
  44. {
  45. $roster->set_message('Talent Tree Data Table could not be emptied.', '', 'error');
  46. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  47. return;
  48. }
  49. $treenum = 1;
  50. foreach ($talents['talentData']['talentTrees'] as $a => $treedata)
  51. {
  52. foreach ($treedata['talents'] as $t => $talent)
  53. {
  54. $lvl = 1;
  55. foreach ($talent['ranks'] as $r => $ranks)
  56. {
  57. $values = array(
  58. 'talent_id' => $talent['id'],
  59. 'talent_num' => $t,
  60. 'tree_order' => $treenum,
  61. 'class_id' => $classid,
  62. 'name' => $talent['name'],
  63. 'tree' => $treedata['name'],
  64. 'tooltip' => tooltip($ranks['description']),
  65. 'texture' => $talent['icon'],
  66. 'isspell' => ( !$talent['keyAbility'] ? false : true ),
  67. 'row' => ($talent['y'] + 1),
  68. 'column' => ($talent['x'] + 1),
  69. 'rank' => $lvl
  70. );
  71. $lvl++;
  72. $querystr = "INSERT INTO `" . $roster->db->table('talents_data') . "` "
  73. . $roster->db->build_query('INSERT', $values) . ";";
  74. $result = $roster->db->query($querystr);
  75. $count++;
  76. }
  77. }
  78. $role = '';
  79. foreach ($treedata['roles'] as $name => $h)
  80. {
  81. if ($h == 1)
  82. {
  83. $role = $name;
  84. }
  85. }
  86. $values = array(
  87. 'tree' => $treedata['name'],
  88. 'order' => $treenum,
  89. 'class_id' => $classid,
  90. 'background' => strtolower($treedata['backgroundFile']),
  91. 'icon' => $treedata['icon'],
  92. 'roles' => $role,
  93. 'desc' => $treedata['description'],
  94. 'tree_num' => $treenum
  95. );
  96. $masterys = array(
  97. 'class_id' => $classid,
  98. 'tree' => $treedata['name'],
  99. 'tree_num' => $treenum,
  100. 'icon' => $treedata['masteries'][0]['icon'],
  101. 'name' => $treedata['masteries'][0]['name'],
  102. 'desc' => $treedata['masteries'][0]['description'],
  103. 'spell_id' => $treedata['masteries'][0]['spellId']
  104. );
  105. $mquerystr = "INSERT INTO `" . $roster->db->table('talent_mastery') . "` "
  106. . $roster->db->build_query('INSERT', $masterys) . "
  107. ;";
  108. $mresult = $roster->db->query($mquerystr);
  109. $querystr = "INSERT INTO `" . $roster->db->table('talenttree_data') . "` "
  110. . $roster->db->build_query('INSERT', $values) . "
  111. ;";
  112. $result = $roster->db->query($querystr);
  113. $count++;
  114. $treenum++;
  115. }
  116. $roster->set_message(sprintf($roster->locale->act['adata_update_class'], $roster->locale->act['id_to_class'][$classid]));
  117. $roster->set_message(sprintf($roster->locale->act['adata_update_row'], $count));
  118. }
  119. if (isset($_GET['parse']) && $_GET['parse'] == 'all'){
  120. $classes = array('1','2','3','4','5','6','7','8','9','11','0');
  121. foreach ($classes as $tid)
  122. {
  123. //$tid = $_GET['classid'];
  124. $i = $tid;
  125. $talents = $roster->api->Talents->getTalentInfo(''.$tid.'');
  126. $querystr = "DELETE FROM `" . $roster->db->table('talents_data') . "` WHERE `class_id` = '" . $tid . "';";
  127. if (!$roster->db->query($querystr))
  128. {
  129. $roster->set_message('Talent Data Table could not be emptied.', '', 'error');
  130. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  131. return;
  132. }
  133. $querystr = "DELETE FROM `" . $roster->db->table('talenttree_data') . "` WHERE `class_id` = '" . $tid . "';";
  134. if (!$roster->db->query($querystr))
  135. {
  136. $roster->set_message('Talent Tree Data Table could not be emptied.', '', 'error');
  137. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  138. return;
  139. }
  140. $count = 1;
  141. $treenum = 1;
  142. //$i=$tid;
  143. foreach ($talents['talentData']['talentTrees'] as $a => $treedata)
  144. {
  145. foreach ($treedata['talents'] as $t => $talent)
  146. {
  147. $lvl = 1;
  148. foreach ($talent['ranks'] as $r => $ranks)
  149. {
  150. $values = array(
  151. 'talent_id' => $talent['id'],
  152. 'talent_num' => $t,
  153. 'tree_order' => $treenum,
  154. 'class_id' => $i,
  155. 'name' => $talent['name'],
  156. 'tree' => $treedata['name'],
  157. 'tooltip' => tooltip($ranks['description']),
  158. 'texture' => $talent['icon'],
  159. 'row' => ($talent['y'] + 1),
  160. 'column' => ($talent['x'] + 1),
  161. 'rank' => $lvl
  162. );
  163. $lvl++;
  164. $querystr = "INSERT INTO `" . $roster->db->table('talents_data') . "` "
  165. . $roster->db->build_query('INSERT', $values) . ";";
  166. $result = $roster->db->query($querystr);
  167. $count++;
  168. }
  169. }
  170. $values = array(
  171. 'tree' => $treedata['name'],
  172. 'order' => $treenum,
  173. 'class_id' => $i,
  174. 'background' => strtolower($treedata['backgroundFile']),
  175. 'icon' => $treedata['icon'],
  176. 'tree_num' => $treenum
  177. );
  178. $querystr = "INSERT INTO `" . $roster->db->table('talenttree_data') . "` "
  179. . $roster->db->build_query('INSERT', $values) . "
  180. ;";
  181. $result = $roster->db->query($querystr);
  182. $count++;
  183. $treenum++;
  184. }
  185. $roster->set_message(sprintf($roster->locale->act['adata_update_class'], $roster->locale->act['id_to_class'][$_POST['class_id']]));
  186. $roster->set_message(sprintf($roster->locale->act['adata_update_row'], $count));
  187. }
  188. }
  189. //echo 'will have update information for talents';
  190. $array1 = $roster->locale->act['class_to_id'];
  191. $array2 = array('Pets' => 0);
  192. $classes = array_merge($array1, $array2);
  193. foreach ($classes as $class => $num)
  194. {
  195. $querystra = $classr = $resulta = 0;
  196. $querystra = "SELECT * FROM `" . $roster->db->table('talents_data') . "` WHERE `class_id` = '" . $num . "';";
  197. $resulta = $roster->db->query($querystra);
  198. $classr = $roster->db->num_rows($resulta);
  199. $i = 0;
  200. $roster->tpl->assign_block_vars('classes', array(
  201. 'NAME' => $class,
  202. 'ID' => $num,
  203. 'UPDATELINK' => makelink('&amp;class=' . $num),
  204. 'ROWS' => $classr,
  205. 'ROW' => (($i % 2) + 1)
  206. )
  207. );
  208. }
  209. $queryx = "SELECT * FROM `" . $roster->db->table('api_usage') . "` ORDER BY `date` DESC LIMIT 0,150;";
  210. $resultx = $roster->db->query($queryx);
  211. $usage = array();
  212. while ($row = $roster->db->fetch($resultx))
  213. {
  214. $usage[$row['date']][$row['type']]['total']=$row['total'];
  215. }
  216. foreach($usage as $date => $x)
  217. {
  218. $roster->tpl->assign_block_vars('apiusage', array(
  219. 'DATE' => $date
  220. )
  221. );
  222. foreach($x as $type => $d)
  223. {
  224. $roster->tpl->assign_block_vars('apiusage.type', array(
  225. 'TYPE' => $type,
  226. 'REQ' => $d['total'],
  227. 'PERCENT' => ($d['total']/3000*100).'% (Based on daily limit of 3000 with no API key)',
  228. 'ROW_CLASS' => (($i % 2) + 1)
  229. )
  230. );
  231. }
  232. }
  233. $roster->tpl->set_filenames(array('body' => 'admin/armory_data.html'));
  234. $body = $roster->tpl->fetch('body');
  235. /**
  236. * Format tooltips for insertion to the db
  237. *
  238. * @param mixed $tipdata
  239. * @return string
  240. */
  241. function tooltip( $tipdata )
  242. {
  243. $tooltip = '';
  244. if( is_array($tipdata) )
  245. {
  246. $tooltip = implode("\n",$tipdata);
  247. }
  248. else
  249. {
  250. $tooltip = str_replace('<br>',"\n",$tipdata);
  251. }
  252. return $tooltip;
  253. }