PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/beta/scripts/functions_db.php

https://github.com/justinmc/turkiball.com
PHP | 389 lines | 260 code | 96 blank | 33 comment | 47 complexity | 5aa2df993219ddddc57700b0a220d214 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. // This file contains all of the low level functions that deal directly with the databases, ect.
  3. // Database Data //
  4. $smfserver = "mysql2561int.domain.com";
  5. $smfusername = "u1064984_tbsmf";
  6. $smfpassword = "klein284.iogom";
  7. $smfdb = "db1064984_turkiball_smf";
  8. $server = "mysql2561int.domain.com";
  9. $username = "u1064984_turki";
  10. $password = "ldbdin473:klaonm";
  11. $db = "db1064984_turkiball";
  12. $tableP = "stats_Players"; // Player Stats Table
  13. $tableT = "stats_Team"; // Team Stats Table
  14. $tableN = "News"; // News Table
  15. $tableS = "Season" ; // Season table, with schedule info
  16. $tablePS = "PSeason"; // Post Season table, tournament
  17. // Functions //
  18. function getdb ($index, $table) // Accesses the database, given table at given row
  19. {
  20. global $smfserver, $smfusername, $smfpassword, $smfdb;
  21. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  22. if (!$con)
  23. {
  24. die('Could not connect: ' . mysql_error());
  25. }
  26. mysql_select_db($smfdb);
  27. $QUERY = mysql_query("SELECT * FROM $table WHERE Index = '$index'");
  28. $DATA = mysql_fetch_array($QUERY);
  29. mysql_close($con);
  30. return ($DATA);
  31. }
  32. // Accesses the database, given table at given row
  33. function getdbturk ($index, $table)
  34. {
  35. global $server, $username, $password, $db;
  36. $con = mysql_connect($server, $username, $password);
  37. if (!$con)
  38. {
  39. die('Could not connect: ' . mysql_error());
  40. }
  41. mysql_select_db($db);
  42. $QUERY = mysql_query("SELECT * FROM $table WHERE `Index` = $index");
  43. $DATA = mysql_fetch_array($QUERY);
  44. mysql_close($con);
  45. return ($DATA);
  46. }
  47. // Returns $DATA for the given ID_MSG in the smf_messages table
  48. function getdbpost ($id)
  49. {
  50. global $smfserver, $smfusername, $smfpassword, $smfdb;
  51. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  52. if (!$con)
  53. {
  54. die('Could not connect: ' . mysql_error());
  55. }
  56. mysql_select_db($smfdb);
  57. $QUERY = mysql_query("SELECT * FROM smf_messages WHERE ID_MSG = $id");
  58. $DATA = mysql_fetch_array($QUERY);
  59. mysql_close($con);
  60. return ($DATA);
  61. }
  62. // Returns $DATA for the given ID_MEMBER in the smf_members table
  63. function getdbmember ($id)
  64. {
  65. global $smfserver, $smfusername, $smfpassword, $smfdb;
  66. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  67. if (!$con)
  68. {
  69. die('Could not connect: ' . mysql_error());
  70. }
  71. mysql_select_db($smfdb);
  72. $QUERY = mysql_query("SELECT * FROM smf_members WHERE ID_MEMBER = $id");
  73. $DATA = mysql_fetch_array($QUERY);
  74. mysql_close($con);
  75. return ($DATA);
  76. }
  77. // Guardian Sports ID_GROUP = 14
  78. // Returns an array with the ID_MEMBER for all members whose ID_GROUP or additionalGroups is the given value
  79. // The oldest will have a key of 0, the newest will have the highest number
  80. function getmembers($group)
  81. {
  82. global $smfserver, $smfusername, $smfpassword, $smfdb;
  83. $rows = getrows('smf_members');
  84. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  85. if (!$con)
  86. {
  87. die('Could not connect: ' . mysql_error());
  88. }
  89. mysql_select_db($smfdb);
  90. $count = 1; // Because ID_MEMBER starts at 1, not 0
  91. $found = 0;
  92. $output = array(0 => 'false');
  93. while ($count <= $rows)
  94. {
  95. $QUERY = mysql_query("SELECT * FROM smf_members WHERE ID_MEMBER = $count");
  96. $DATA = mysql_fetch_array($QUERY);
  97. if ((($DATA['ID_GROUP'] == $group) || (strpos($DATA['additionalGroups'], $group) == '0')) && ($DATA['ID_MEMBER']))
  98. { $output[$found] = $count;
  99. $found++;
  100. }
  101. $count++;
  102. }
  103. mysql_close($con);
  104. return ($output);
  105. }
  106. // Events: ID_BOARD = 4
  107. // League News: ID_BOARD = 8
  108. // Turkiball News: ID_BOARD = 9
  109. // Other News: ID_BOARD = 10
  110. // All of the Above: ID_BOARD = 0
  111. // Returns an array of the ID_MSG for each thread with the given ID_BOARD in the smf_messages table
  112. // The oldest will have a key of 0, the newest will have the highest number
  113. function getposts($id)
  114. {
  115. global $smfserver, $smfusername, $smfpassword, $smfdb;
  116. $rows = getrows('smf_messages');
  117. // The plus three is because there are some skipped ID_MSG's, so it wasn't looking at the highest numbers
  118. $rows = $rows + 3;
  119. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  120. if (!$con)
  121. {
  122. die('Could not connect: ' . mysql_error());
  123. }
  124. mysql_select_db($smfdb);
  125. $count = 0;
  126. $found = 0;
  127. $output = array(0 => 'false');
  128. while ($count <= $rows)
  129. {
  130. $QUERY = mysql_query("SELECT * FROM smf_messages WHERE ID_MSG = $count");
  131. $DATA = mysql_fetch_array($QUERY);
  132. // So... that if statement means if we're at the id we want, or, if $id is 0 and we're at any news post at all. AND we're looking at a real post with an ID_MSG. Got it?
  133. if ((($DATA['ID_BOARD'] == $id) || (($id == 0) && (($DATA['ID_BOARD'] == 4) || ($DATA['ID_BOARD'] == 8) || ($DATA['ID_BOARD'] == 9) || ($DATA['ID_BOARD'] == 10 )))) && ($DATA['ID_MSG']))
  134. {
  135. // Keeps out all of the replies! Only threads themselves.
  136. if (!strpos(('indexrestopper' . $DATA['subject']), 'Re:'))
  137. { $output[$found] = $DATA['ID_MSG'];
  138. $found++;
  139. }
  140. }
  141. $count++;
  142. }
  143. mysql_close($con);
  144. return ($output);
  145. }
  146. // Returns the number of replies to a thread given its ID_TOPIC
  147. function getreplies($id)
  148. {
  149. global $smfserver, $smfusername, $smfpassword, $smfdb;
  150. $rows = getrows('smf_messages');
  151. // The plus three is because there are some skipped ID_MSG's, so it wasn't looking at the highest numbers
  152. $rows = $rows + 3;
  153. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  154. if (!$con)
  155. die('Could not connect: ' . mysql_error());
  156. mysql_select_db($smfdb);
  157. $count = 0;
  158. $found = 0;
  159. while ($count <= $rows)
  160. {
  161. $QUERY = mysql_query("SELECT * FROM smf_messages WHERE ID_MSG = $count");
  162. $DATA = mysql_fetch_array($QUERY);
  163. if (($DATA['ID_TOPIC'] == $id) && ($DATA['ID_MSG']))
  164. $found++;
  165. $count++;
  166. }
  167. mysql_close($con);
  168. // Because the algorithm above counted the thread itself, and we need only replies
  169. $found--;
  170. return ($found);
  171. }
  172. // Returns the number of rows in the given table
  173. function getrows ($where)
  174. {
  175. global $smfserver, $smfusername, $smfpassword, $smfdb;
  176. $con = mysql_connect($smfserver, $smfusername, $smfpassword);
  177. if (!$con)
  178. {
  179. die('Could not connect: ' . mysql_error());
  180. }
  181. mysql_select_db("db1064984_turkiball_smf");
  182. $QUERY = mysql_query("SELECT * FROM $where");
  183. $rows = 0;
  184. $rows = mysql_num_rows($QUERY);
  185. mysql_close($con);
  186. return ($rows);
  187. }
  188. // Returns the number of rows in the given table
  189. function getrowsturk ($where)
  190. {
  191. global $server, $username, $password, $db;
  192. $con = mysql_connect($server, $username, $password);
  193. if (!$con)
  194. {
  195. die('Could not connect: ' . mysql_error());
  196. }
  197. mysql_select_db("db1064984_turkiball");
  198. $QUERY = mysql_query("SELECT * FROM $where");
  199. $rows = 0;
  200. $rows = mysql_num_rows($QUERY);
  201. mysql_close($con);
  202. return ($rows);
  203. }
  204. // SMF API function!
  205. // Format a time to make it look purdy.
  206. function smf_formatTime($logTime)
  207. {
  208. global $smf_user_info, $smf_settings;
  209. // Offset the time - but we can't have a negative date!
  210. $time = max($logTime * 3600, 0);
  211. // Format some in caps, and then any other characters..
  212. return strftime(strtr(!empty($smf_user_info['timeFormat']) ? $smf_user_info['timeFormat'] : $smf_settings['time_format'], array('%a' => ucwords(strftime('%a', $time)), '%A' => ucwords(strftime('%A', $time)), '%b' => ucwords(strftime('%b', $time)), '%B' => ucwords(strftime('%B', $time)))), $time);
  213. }
  214. function getname ($filename) // Returns the filename, minus any directory stuff and minus the extension
  215. {
  216. $pos = strlen($filename);
  217. $pos = $pos - 4; // Get past .php
  218. $end = $pos;
  219. while (substr($filename, $pos, 1) != "/")
  220. { $pos--;
  221. }
  222. $pos++; // Jump back on other side of the slash
  223. $filename = substr($filename, $pos, ($end - $pos));
  224. return ($filename);
  225. }
  226. function removehtml($text) // Removes all html tags from the input
  227. { // Used for the newsbar, where we don't want big headings, etc.
  228. $text = "&nbsp;" . $text; // Prevents the whole html at first character returning a 0 problem.
  229. $gow = 1;
  230. while ($gow)
  231. {
  232. $gof = 1;
  233. $here = strpos($text, "<");
  234. if (!$here)
  235. { $gow = 0;
  236. $gof = 0;
  237. }
  238. for ($i = $here; (($gof) && ($i < strlen($text))); $i++)
  239. {
  240. if (substr($text, $i, 1) == '>')
  241. {
  242. $text = substr($text, 0, $here) . substr($text, ($i + 1), strlen($text));
  243. $gof = 0;
  244. }
  245. else
  246. { $gof = 1;
  247. }
  248. }
  249. }
  250. return($text);
  251. }
  252. function echoContent($filename)
  253. {
  254. global $server, $username, $password, $db;
  255. $con = mysql_connect($server, $username, $password);
  256. if (!$con)
  257. {
  258. die('Could not connect: ' . mysql_error());
  259. }
  260. mysql_select_db($db);
  261. $QUERY = mysql_query("SELECT * FROM Content WHERE Address = '$filename'");
  262. $DATA = mysql_fetch_array($QUERY);
  263. echo $DATA['Content'] . "\n\n";
  264. mysql_close($con);
  265. }
  266. // Returns 1 if $param exists in the given $column in the given $table, 0 otherwise
  267. // Turkiball db only
  268. function doesItExist($table, $column, $param)
  269. {
  270. global $server, $username, $password, $db;
  271. $con = mysql_connect($server, $username, $password);
  272. if (!$con)
  273. die('Could not connect: ' . mysql_error());
  274. mysql_select_db($db);
  275. $QUERY = mysql_query("SELECT * FROM $table WHERE $column = '$param'");
  276. $DATA = mysql_fetch_array($QUERY);
  277. mysql_close($con);
  278. if (!$DATA)
  279. return 0;
  280. return 1;
  281. }
  282. // Given a post of $ID_MSG, returns next newest post of given $ID_BOARD
  283. // As in the getposts fn, if $ID_BOARD is 0, all news types will be returned
  284. function getNext($ID_MSG, $ID_BOARD)
  285. {
  286. $choices = getposts($ID_BOARD);
  287. $count = 0;
  288. while ($choices[$count] != $ID_MSG)
  289. $count++;
  290. // Will return 0 if no next exists
  291. return $choices[$count];
  292. }
  293. ?>