PageRenderTime 46ms CodeModel.GetById 3ms RepoModel.GetById 0ms app.codeStats 0ms

/dkp_wizard/testdir/uploaddkp.php

http://wowroster-addons.googlecode.com/
PHP | 440 lines | 367 code | 45 blank | 28 comment | 56 complexity | 64b79ae55eb184e32c57e366bdebb9bb MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /******************************
  3. * WoWRoster.net Roster
  4. * Copyright 2002-2006
  5. * Licensed under the Creative Commons
  6. * "Attribution-NonCommercial-ShareAlike 2.5" license
  7. *
  8. * Short summary
  9. * http://creativecommons.org/licenses/by-nc-sa/2.5/
  10. *
  11. * Full license information
  12. * http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode
  13. * -----------------------------
  14. *
  15. * $Id: uploaddkp.php 64 2007-02-11 23:36:30Z mathos $
  16. *
  17. ******************************/
  18. session_start();
  19. require('../config/siteSettings.php');
  20. require('../config/site.php');
  21. require('config/adminClass.php');
  22. $ndkp = new nurfedAdmin;
  23. if($_GET[logout] == 'xxx') {
  24. $ndkp->logOut();
  25. }
  26. $ndkp->dbUser=$dbUser;
  27. $ndkp->dbPassword=$dbPassword;
  28. $ndkp->dbServer=$dbServer;
  29. $ndkp->dBase=$dBase;
  30. $ndkp->vars=$_GET;
  31. $ndkp->displayhtml('header');
  32. $bosskills = array();
  33. $lootlog = array();
  34. $attlog = array();
  35. $raiddata = array();
  36. $eventlog = array();
  37. $unknown_player = array();
  38. $unknown_item = array();
  39. $meta_attend = array();
  40. $alt_lookup = array();
  41. $ifbuf = array();
  42. if (count($_FILES) > 0)
  43. {
  44. foreach ($_FILES as $filefield => $file)
  45. {
  46. $filename = $file['tmp_name'];
  47. if (strtolower($file['name']) == 'ordo_dkp.lua')
  48. {
  49. $ifbuf = file($filename);
  50. }
  51. else
  52. {
  53. print("No Valid File Received<br>");
  54. exit;
  55. }
  56. }
  57. //$ifbuf = file('Ordo_DKP.lua');
  58. $block = '';
  59. $ts = 0;
  60. $maxts = 0;
  61. foreach($ifbuf as $buf) {
  62. if(preg_match('/^ORDO_SAVED_([A-Z]+) = {/', $buf, $matches)) {
  63. $block = strtolower($matches[1]);
  64. } elseif(preg_match('/^\t\["?(\d+)"?\] = {/', $buf, $matches)) {
  65. $ts = $matches[1];
  66. if($ts > $maxts) { $maxts = $ts; }
  67. $store = '$' . $block . '[] = "' . $ts . '";';
  68. #print "<pre>$store</pre>\n";
  69. eval($store);
  70. } elseif(preg_match('/^\t\["(.+)"\] = \"(.+)\",/', $buf, $matches)) {
  71. $name = $matches[1];
  72. $data = $matches[2];
  73. $raiddata[$block][$name] = $data;
  74. # print "<p>" . $block . ":" . $name . " = " . $raiddata[$block][$name] . "</p>";
  75. } elseif(preg_match('/^\t\t\["?([^"\]]+)"?\] = "?([^"\]]+)"?,/', $buf, $matches)) {
  76. $fieldname = $matches[1];
  77. $data = $matches[2];
  78. # print "<pre>\$raiddata[$block][$ts][$fieldname] = $data</pre>\n";
  79. $raiddata[$block][$ts][$fieldname] = $data;
  80. if($fieldname == 'player') {
  81. if(!player_exists($data)) {
  82. $unknown_player[] = $data;
  83. }
  84. }
  85. if($fieldname == 'item') {
  86. if(!item_exists($data)) {
  87. $unknown_item[] = $data;
  88. }
  89. }
  90. if($fieldname == 'playerlist') {
  91. $pbuf = split(" ",$data);
  92. foreach($pbuf as $p) {
  93. if($p != '') {
  94. if(!player_exists($p)) {
  95. $unknown_player[] = $p;
  96. } else {
  97. $meta_attend[] = $p;
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. $maxts++;
  105. sort($bosskills);
  106. sort($lootlog);
  107. sort($attlog);
  108. $playercount = update_alts();
  109. for($i=0; $i<count($meta_attend); $i++) {
  110. $meta_attend[$i] = alt_map_to_main($meta_attend[$i]);
  111. }
  112. sort($unknown_player);
  113. sort($unknown_item);
  114. sort($meta_attend);
  115. $unknown_player = array_unique($unknown_player);
  116. $unknown_item = array_unique($unknown_item);
  117. $meta_attend = array_unique($meta_attend);
  118. $attlog[] = $maxts;
  119. $raiddata['attlog'][$maxts]['location'] = 'Meta Snapshot';
  120. $raiddata['attlog'][$maxts]['comments'] = 'Smart snapshot auto-generated by sDKP';
  121. $raiddata['attlog'][$maxts]['playerlist'] = '';
  122. foreach($meta_attend as $player) {
  123. $raiddata['attlog'][$maxts]['playerlist'] .= $player . ' ';
  124. }
  125. ?>
  126. <table id="mainpage">
  127. <tr><td valign="top">
  128. <div id='maincontent'>
  129. <h1 class="titles">Unknown Members (<?php print count($unknown_player) ?>)</h1>
  130. <div style="margin-left: 30px;">
  131. <?php list_unknown_players(); ?>
  132. </div>
  133. <h1 class="titles">Unknown Items (<?php print count($unknown_item) ?>)</h1>
  134. <div style="margin-left: 30px;">
  135. <?php list_unknown_items(); ?>
  136. </div>
  137. <h1><?php print $playercount; ?> Players Mapped</h1>
  138. <div class="break"></div>
  139. <h1 class="titles">Attendance Records (<?php print count($attlog); ?>)</h1>
  140. <div style="margin-left: 30px;">
  141. <?php list_attlogs(); ?>
  142. </div>
  143. <div class="break"></div>
  144. <h1 class="titles">Boss Kills (<?php print count($bosskills); ?>)</h1>
  145. <div style="margin-left: 30px;">
  146. <?php list_bosskills(); ?>
  147. </div>
  148. <div class="break"></div>
  149. </div>
  150. <td valign="top">
  151. <div id='rightcontent'>
  152. <?php include('../includes/newsitems.php'); ?>
  153. <div class="break"></div>
  154. <?php include('../includes/moreNDKP.php'); ?>
  155. </div>
  156. </td>
  157. </tr>
  158. </table>
  159. </div>
  160. <div id="footer">
  161. Brought to you by <a href="http://slacker.com/~nugget/projects/slackerdkp/">SlackerDKP</a>
  162. </div>
  163. <?php
  164. }
  165. else
  166. {
  167. echo '<form enctype="multipart/form-data" method="post"><input name="dkpfile" type="file"><br><input type="submit"></form>';
  168. }
  169. function alt_map_to_main($name) {
  170. global $alt_lookup;
  171. if($alt_lookup[$name]) {
  172. return $alt_lookup[$name];
  173. } else {
  174. return $name;
  175. }
  176. }
  177. function update_alts() {
  178. global $raiddata, $alt_lookup;
  179. $sql = "update NDKP_members set alt_of = 0";
  180. $result = mysql_query($sql);
  181. $playercount = 0;
  182. while (list($key,$val) = each($raiddata)) {
  183. # print "<p>$key</p>";
  184. if($key == 'alts') {
  185. while (list($alt,$main) = each($val)) {
  186. $sql = "select player_id from NDKP_members where name = '$main'";
  187. $result = mysql_fetch_assoc(mysql_query($sql));
  188. $main_id = $result['player_id'];
  189. $sql = "update NDKP_members set alt_of = '$main_id' where name = '$alt'";
  190. mysql_query($sql);
  191. $alt_lookup[$alt] = $main;
  192. $playercount++;
  193. }
  194. }
  195. }
  196. return $playercount;
  197. }
  198. function player_exists($name) {
  199. $sql = "select player_id from NDKP_members where name = '$name'";
  200. $result = mysql_query($sql);
  201. if(mysql_affected_rows()>0) {
  202. //print $sql.'<BR>';
  203. $result = mysql_fetch_assoc($result);
  204. $result = $result["player_id"];
  205. }else{
  206. $sql = "select player_id from NDKP_alternates where altname = '$name'";
  207. $result = mysql_query($sql);
  208. if(mysql_affected_rows()>0) {
  209. //print $sql.'<BR>';
  210. $result = mysql_fetch_assoc($result);
  211. $result = $result["player_id"];
  212. }
  213. }
  214. return $result;
  215. }
  216. function list_unknown_players() {
  217. global $unknown_player, $raiddata;
  218. print "<ol>\n";
  219. foreach($unknown_player as $player) {
  220. print "<li style=\"color: red;\">$player";
  221. if($raiddata[classes][$player]) {
  222. print '<form action="modules/addPlayer.php" method="post">';
  223. print '<input type="hidden" name="player" value="' . $player . '"/>';
  224. print '<input type="hidden" name="class" value="' . $raiddata[classes][$player] . '"/>';
  225. print '<input type="submit" value="Add"/>';
  226. print '</form>';
  227. }
  228. print "</li>\n";
  229. }
  230. print "</ol>\n";
  231. }
  232. function item_exists($name) {
  233. $name = addslashes($name);
  234. $sql = "select item_id from NDKP_items where name = '$name'";
  235. $result = mysql_query($sql);
  236. if($result) {
  237. $result = mysql_fetch_assoc($result);
  238. $result = $result["item_id"];
  239. }
  240. return $result;
  241. }
  242. function list_unknown_items() {
  243. global $unknown_item;
  244. print "<ol>\n";
  245. foreach($unknown_item as $item) {
  246. print "<li style=\"color: red;\">$item</li>\n";
  247. }
  248. print "</ol>\n";
  249. }
  250. function list_attlogs() {
  251. global $raiddata;
  252. global $attlog;
  253. print "<ol>\n";
  254. foreach($attlog as $attrec) {
  255. $ts = strftime("%m/%d/%y %H:%M:%S",$attrec);
  256. $plist = str_replace(' ', "\n", $raiddata[attlog][$attrec][playerlist]);
  257. $type = 'start';
  258. if($raiddata[attlog][$attrec][comments] == 'Meta Snapshot') {
  259. $type = 'end';
  260. }
  261. print "<li>";
  262. print $raiddata[attlog][$attrec][location] . " at " . $ts;
  263. if($record = att_exists($attrec)) {
  264. att_edit_form($record);
  265. } else {
  266. att_add_form($ts,$type,$raiddata[attlog][$attrec][comments],$plist);
  267. }
  268. print "</li>\n";
  269. }
  270. print "</ol>\n";
  271. }
  272. function att_add_form($ts,$type,$comments,$playerlist) {
  273. $comments = addslashes($comments);
  274. print '<form action="modules/attendance.php" method="post">';
  275. print '<input type="hidden" name="raiddate" value="' . $ts . '">';
  276. print '<input type="hidden" name="type" value="' . $type . '">';
  277. print '<input type="hidden" name="notes" value="' . $comments . '">';
  278. print '<input type="hidden" name="attendance" value="' . $playerlist . '">';
  279. print '<input style="width: 200px" name="submit" value="Add Attendance" type="submit">';
  280. print '</form>';
  281. }
  282. function att_edit_form($record) {
  283. # print '<form action="edit-timeClock.php" method="get">';
  284. # print '<input type="hidden" name="id" value="' . $record . '">';
  285. # print '<input style="width: 200px" name="submit" value="Edit Attendance" type="submit">';
  286. # print '</form>';
  287. print '<br /><i>This record has already been added</i> ';
  288. print ' [<a href="edit-timeClock.php?id=' . $record . '">edit</a>]';
  289. }
  290. function att_exists($attrec) {
  291. $ts = strftime("%Y-%m-%d %H:%M:%S",$attrec);
  292. $sql = "select id from NDKP_attendancetype where date = '$ts'";
  293. $result = mysql_query($sql);
  294. if($result) {
  295. $result = mysql_fetch_assoc($result);
  296. $result = $result["id"];
  297. }
  298. return $result;
  299. }
  300. function list_bosskills() {
  301. global $raiddata;
  302. global $bosskills;
  303. print "<ol>\n";
  304. for($i=0; $i<count($bosskills); $i++) {
  305. $bossrec = $bosskills[$i];
  306. $nextrec = $bosskills[$i+1];
  307. if(!$nextrec) {
  308. $nextrec = 9999999999;
  309. }
  310. $ts = strftime("%m/%d/%y %H:%M:%S",$bossrec);
  311. $plist = str_replace(' ', "\n", $raiddata[bosskills][$bossrec][playerlist]);
  312. print "<li>";
  313. print $raiddata[bosskills][$bossrec][bossname] . " at " . $ts;
  314. if($record = boss_exists($bossrec)) {
  315. boss_edit_form($record);
  316. } else {
  317. boss_add_form($bossrec,$nextrec,$ts,
  318. $raiddata[bosskills][$bossrec][bossname],
  319. $raiddata[bosskills][$bossrec][location],
  320. $raiddata[bosskills][$bossrec][comments],
  321. $plist);
  322. }
  323. print "</li>\n";
  324. }
  325. print "</ol>\n";
  326. }
  327. function boss_add_form($epochlow,$epochhigh,$ts,$bossname,$location,$comments,$playerlist) {
  328. $comments = addslashes($comments);
  329. $location = addslashes($location);
  330. $bossname = addslashes($bossname);
  331. print '<form action="modules/addRaid.php" method="post">';
  332. print '<input type="hidden" name="raiddate" value="' . $ts . '">';
  333. print '<input type="hidden" name="newdungeon" value="' . $location . '">';
  334. print '<input type="hidden" name="newboss" value="' . $bossname . '">';
  335. print '<input type="hidden" name="notes" value="' . $comments . '">';
  336. print '<input type="hidden" name="attendance" value="' . $playerlist . '">';
  337. print '<input style="width: 200px" name="submit" value="Add Raid" type="submit">';
  338. boss_loot_fields($epochlow,$epochhigh);
  339. print '</form>';
  340. }
  341. function boss_loot_fields($low,$high) {
  342. global $lootlog;
  343. global $raiddata;
  344. global $eventlog;
  345. $items = 0; $known_items = 0;
  346. $thiskill = 0;
  347. for ($i=0; $i<=count($eventlog); $i++) {
  348. $ets = $raiddata[eventlog][$i][ts];
  349. $etype = $raiddata[eventlog][$i][type];
  350. if($etype == 'BOSSKILL') {
  351. if($ets == $low) {
  352. $thiskill = 1;
  353. } else {
  354. if($thiskill == 1) {
  355. $thiskill = 0;
  356. }
  357. }
  358. }
  359. if($etype == 'LOOT') {
  360. $ltype = 'bid';
  361. if(isset($raiddata[lootlog][$ets][type])) {
  362. $ltype = $raiddata[lootlog][$ets][type];
  363. }
  364. if(($thiskill == 1) and ($ltype != 'DE') and ($ltype != 'bank')) {
  365. $items++;
  366. if($item_id = item_exists($raiddata[lootlog][$ets][item])) {
  367. $known_items++;
  368. print "\n\n";
  369. print '<input type="hidden" name="looters[]" value="' . player_exists($raiddata[lootlog][$ets][player]) . '">';
  370. print '<input type="hidden" name="items[]" value="' . $item_id . '">';
  371. print '<input type="hidden" name="fullprice[]" value="1">';
  372. print "\n\n";
  373. }
  374. }
  375. }
  376. }
  377. print "<i>$items items ($known_items known)</i>";
  378. }
  379. function boss_edit_form($record) {
  380. print '<br /><i>This record has already been added (raid #' . $record . ')</i> ';
  381. # print ' [<a href="editRaid.php?id=' . $record . '">edit</a>]';
  382. }
  383. function boss_exists($bossrec) {
  384. $ts = strftime("%Y-%m-%d %H:%M:%S",$bossrec);
  385. $sql = "select raid_id from NDKP_raids where raid_date = '$ts'";
  386. $result = mysql_query($sql);
  387. if($result) {
  388. $result = mysql_fetch_assoc($result);
  389. $result = $result["raid_id"];
  390. }
  391. return $result;
  392. }
  393. ?>
  394. </body>
  395. </html>