PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/checkdata.php

https://bitbucket.org/verax/to-ladder
PHP | 493 lines | 444 code | 37 blank | 12 comment | 52 complexity | 9d068d1325c31c3e0b46c373f55765f6 MD5 | raw file
  1. <?
  2. // +CHECKS
  3. //AGE AND POLICY AGREE
  4. function check_agrees($errormessage, $agree_age, $agree_policy){
  5. global $site, $url, $misc;
  6. if(($misc[joinage]) && (!$agree_age)){
  7. $errormessage=$errormessage."Debes tener al menos $misc[joinage] a&nacute;os de edad para participar en $site[shortname].<br>";
  8. }
  9. if(($url[policy]) && (!$agree_policy)){
  10. $errormessage=$errormessage."Debes leer y estar de acuerdo con las pol&iacute;ticas de $site[shortname] antes de participar.<br>";
  11. }
  12. return($errormessage);
  13. }
  14. //REQUIRED USER INFORMATION FIELDS
  15. function check_requsernfo($errormessage, $n_fname, $n_mname, $n_lname, $n_addrs, $n_city, $n_state, $n_zip, $n_phone, $n_bdaym, $n_bdayd, $n_bdayy, $n_occup){
  16. if(($n_fname=="") || ($n_mname=="") || ($n_lname=="") || ($n_addrs=="") || ($n_city=="") || ($n_state=="") || ($n_zip=="") || ($n_phone=="") || ($n_bdaym=="") || ($n_bdayd=="") || ($n_bdayy=="") || ($n_occup=="")){
  17. $errormessage=$errormessage."All User Information Fields Are Required.<br>";
  18. }
  19. return($errormessage);
  20. }
  21. //CHECK FOR FIELD MATCHES
  22. function check_matching($errormessage, $matcha, $matchb, $customerror){
  23. if($matcha!="$matchb"){
  24. $errormessage=$errormessage."$customerror<br>";
  25. }
  26. return("$errormessage");
  27. }
  28. //CHECK FOR VALID LENGTHS
  29. function check_validlength($errormessage, $text, $minlength, $maxlength, $customerror){
  30. if ((strlen($text) < $minlength) || (strlen($text) > $maxlength)){
  31. $errormessage=$errormessage."$customerror<br>";
  32. }
  33. return($errormessage);
  34. }
  35. //CHECK IF USERS INFO ALREADY EXIST UNVALIDATED
  36. function check_unvalusersinfoexist($errormessage, $alias, $email, $ip){
  37. global $misc;
  38. if($ip==""){
  39. $ip=getenv("REMOTE_ADDR");
  40. }
  41. if (mysql_num_rows(mysql_query("select alias from validate where alias='$alias'")) > 0){
  42. $errormessage=$errormessage."Your Player Alias is already in use on an Unvalidated Account.<br>";
  43. }
  44. if (mysql_num_rows(mysql_query("select email from validate where email='$email'")) > 0){
  45. $errormessage=$errormessage."Your Email Address is already in use on an Unvalidated Account.<br>";
  46. }
  47. if (mysql_num_rows(mysql_query("select ipaddress from validate where ipaddress='$ip'")) > 0){
  48. $errormessage=$errormessage."Your IP Address is already in use on an Unvalidated Account.<br>";
  49. }
  50. return($errormessage);
  51. }
  52. //CHECK IF USERS INFO ALREADY EXIST
  53. function check_usersinfoexist($errormessage, $alias, $email, $ip){
  54. global $misc;
  55. if($ip==""){
  56. $ip=getenv("REMOTE_ADDR");
  57. }
  58. if (mysql_num_rows(mysql_query("select alias from users where alias='$alias'")) > 0){
  59. $errormessage=$errormessage."Your Player Alias is already in use.<br>";
  60. }
  61. if (mysql_num_rows(mysql_query("select email from users where email='$email'")) > 0){
  62. $errormessage=$errormessage."Your Email Address is already in use.<br>";
  63. }
  64. if($misc[multipleip]!="yes"){
  65. if($ip!="x"){
  66. if (mysql_num_rows(mysql_query("select ipaddress from users where ipaddress='$ip'")) > 0){
  67. $errormessage=$errormessage."Your IP Address is already in use.<br>";
  68. }
  69. }
  70. }
  71. return($errormessage);
  72. }
  73. //CHECK IF USERS INFO ALREADY EXIST ON ANOTHER ACCOUNT
  74. function check_usersinfoexistother($errormessage, $id, $alias, $email, $ip){
  75. if($ip==""){
  76. $ip=getenv("REMOTE_ADDR");
  77. }
  78. if (mysql_num_rows(mysql_query("select alias from users where alias='$alias' AND id!='$id'")) > 0){
  79. $errormessage=$errormessage."Your Player Alias is already in use on another account.<br>";
  80. }
  81. if (mysql_num_rows(mysql_query("select email from users where email='$email' AND id!='$id'")) > 0){
  82. $errormessage=$errormessage."Your Email Address is already in use on another account.<br>";
  83. }
  84. if($ip!="x"){
  85. if (mysql_num_rows(mysql_query("select ipaddress from users where ipaddress='$ip' AND id!='$id'")) > 0){
  86. $errormessage=$errormessage."Your IP Address is already in use on another account.<br>";
  87. }
  88. }
  89. return($errormessage);
  90. }
  91. //CHECK IF TEAM NAME ALREADY EXIST
  92. function check_teamexist($errormessage, $alias){
  93. if (mysql_num_rows(mysql_query("select teamname from teams where teamname='$alias'")) > 0){
  94. $errormessage=$errormessage."That Name is already in use.<br>";
  95. }
  96. return($errormessage);
  97. }
  98. //CHECK IF CLAN NAME ALREADY EXIST ON OTHER ACCOUNT
  99. function check_clanexistother($errormessage,$alias,$clansid){
  100. if (mysql_num_rows(mysql_query("select clanname from clans where clanname='$alias' AND id!='$clansid'")) > 0){
  101. $errormessage=$errormessage."That Clan Name is already in use.<br>";
  102. }
  103. return($errormessage);
  104. }
  105. //BAN CHECK
  106. function check_ban($errormessage, $alias, $email, $ip){
  107. global $email, $misc;
  108. if($misc[dobans]){
  109. $cuip=getenv("REMOTE_ADDR");
  110. if($ip==""){
  111. $ip="$cuip";
  112. }
  113. $splitip=split("\.", $ip);
  114. $emaildomain=split("@", $email);
  115. $baninfo=mysql_query("SELECT id,text,type,displayreason FROM bancensor ORDER by id");
  116. while(list($id, $text, $type, $reason)=mysql_fetch_row($baninfo)){
  117. if(($type=="0") && ($text=="$alias")){
  118. $errormessage=$errormessage."Your Alias has been Banned for the Folowing Reason<br>
  119. <b>$reason</b><br>For more information on this matter send an email to
  120. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  121. <br>make sure to include the Following Code: bcode$id<hr>";
  122. }
  123. if(($type=="1") && ($newword=eregi("$text","$alias"))){
  124. $errormessage=$errormessage."Your Alias has been Banned for the Folowing Reason:<br>
  125. <b>$reason</b><br>For more information on this matter send an email to
  126. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  127. <br>make sure to include the Following Code: bcode$id<hr>";
  128. }
  129. if(($type=="2") && ($text=="$email")){
  130. $errormessage=$errormessage."Your Email has been Banned for the Folowing Reason:<br>
  131. <b>$reason</b><br>For more information on this matter send an email to
  132. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  133. <br>make sure to include the Following Code: bcode$id<hr>";
  134. }
  135. if(($type=="3") && ($text=="$emaildomain[0]")){
  136. $errormessage=$errormessage."Your Email Username has been Banned for the Folowing Reason:<br>
  137. <b>$reason</b><br>For more information on this matter send an email to
  138. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  139. <br>make sure to include the Following Code: bcode$id<hr>";
  140. }
  141. if(($type=="4") && ($text=="$emaildomain[1]")){
  142. $errormessage=$errormessage."Your Email's Server has been Banned for the Folowing Reason:<br>
  143. <b>$reason</b><br>For more information on this matter send an email to
  144. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  145. <br>make sure to include the Following Code: bcode$id<hr>";
  146. }
  147. if(($type=="5") && ($text=="$ip")){
  148. $errormessage=$errormessage."Your IP has been Banned for the Folowing Reason:<br>
  149. <b>$reason</b><br>For more information on this matter send an email to
  150. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  151. <br>make sure to include the Following Code: bcode$id<hr>";
  152. }
  153. if($type=="6"){
  154. $splittext=split("\.", $text);
  155. if($splittext[0]=="$splitip[0]"){
  156. if(($splittext[1]=="*") && ($splittext[2]=="*") && ($splittext[3]=="*")){
  157. $errormessage=$errormessage."Your IP Block ($splittext[0].*.*.*) has been Banned for the Folowing Reason:<br>
  158. <b>$reason</b><br>For more information on this matter send an email to
  159. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  160. <br>make sure to include the Following Code: bcode$id<hr>";
  161. }
  162. if(($splittext[1]=="$splitip[1]") && ($splittext[2]=="*") && ($splittext[3]=="*")){
  163. $errormessage=$errormessage."Your IP Block ($splittext[0].$splittext[1].*.*) has been Banned for the Folowing Reason:<br>
  164. <b>$reason</b><br>For more information on this matter send an email to
  165. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$email[banhelp]</a>.
  166. <br>make sure to include the Following Code: bcode$id<hr>";
  167. }
  168. if(($splittext[1]=="$splitip[1]") && ($splittext[2]=="$splitip[2]") && ($splittext[3]=="*")){
  169. $errormessage=$errormessage."Your IP Block ($splittext[0].$splittext[1].$splittext[2].*) has been Banned for the Folowing Reason:<br>
  170. <b>$reason</b><br>For more information on this matter send an email to
  171. <a href='mailto:$email[banhelp]?subject=banhelp&body=bcode:$id'>$bannedhelp</a>.
  172. <br>make sure to include the Following Code: bcode$id<hr>";
  173. }
  174. }
  175. }
  176. }
  177. return($errormessage);
  178. }
  179. }
  180. function check_staffexist($errormessage, $name){
  181. if (mysql_num_rows(mysql_query("select displayname from staff where displayname='$name'")) > 0){
  182. $errormessage=$errormessage."That Staff Display Name is already In Use.<br>";
  183. }
  184. return($errormessage);
  185. }
  186. function check_staffexistother($errormessage, $name, $id){
  187. if (mysql_num_rows(mysql_query("select id from staff where displayname='$name' AND id !='$id'")) > 0){
  188. $errormessage=$errormessage."That Staff Display Name is already In Use.<br>";
  189. }
  190. return($errormessage);
  191. }
  192. function check_givestaffrights($errormessage, $accesslevel){
  193. global $admn;
  194. if($accesslevel > $admn[access]){
  195. $errormessage=$errormessage."Your Access Level is only $admn[access],<br>
  196. You cannot give an Access Level of $accesslevel to another Staff Member.<br>";
  197. }
  198. return($errormessage);
  199. }
  200. function check_givestaffgames($errormessage, $gamearray){
  201. global $admn;
  202. $result=mysql_query("SELECT games FROM staff WHERE id='$admn[id]'");
  203. $resrow=mysql_fetch_array($result);
  204. $admnlgs=$resrow[games];
  205. $admnlgs=split("-",$admnlgs);
  206. $gameid=array($gamearray);
  207. while (list($i)=each($gameid)){
  208. while (list($lid,$laccess)=each($leagueid[$i])){
  209. if ((!in_array ("$lid", $admnlgs)) && ($laccess=="Y")){
  210. $errormessage=$errormessage."Cannot Add Staff to Game ID: $lid.<br>";
  211. }
  212. }
  213. }
  214. return($errormessage);
  215. }
  216. //CHECK DATA FORMAT
  217. function check_datetimefields($errormessage, $datetime, $customerror){
  218. if (!ereg ("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$", $datetime)){
  219. $errormessage=$errormessage."$customerror<br>";
  220. }
  221. return($errormessage);
  222. }
  223. //CHECK IF GAME NAME OR ABREVIATION EXIST
  224. function check_gameexist($errormessage, $name, $abrv){
  225. if (mysql_num_rows(mysql_query("select id from games where gamename='$name'")) > 0){
  226. $errormessage=$errormessage."That Game Name Already Exist.<br>";
  227. }
  228. if (mysql_num_rows(mysql_query("select id from games where abbreviation='$abrv'")) > 0){
  229. $errormessage=$errormessage."That Game Abreviation Already Exist.<br>";
  230. }
  231. return($errormessage);
  232. }
  233. //CHECK IF OTHER GAMES NAME OR ABREVIATION EXIST
  234. function check_gameexistother($errormessage, $name, $abrv, $gameid){
  235. if (mysql_num_rows(mysql_query("select id from games where gamename='$name' AND id!='$gameid'")) > 0){
  236. $errormessage=$errormessage."That Game Name Already Exist.<br>";
  237. }
  238. if (mysql_num_rows(mysql_query("select id from games where abbreviation='$name' AND id!='$gameid'")) > 0){
  239. $errormessage=$errormessage."That Game Abreviation Already Exist.<br>";
  240. }
  241. return($errormessage);
  242. }
  243. //CHECK IF LADDER NAME OR ABREVIATION EXIST
  244. function check_ladderexist($errormessage, $name, $abrv){
  245. if (mysql_num_rows(mysql_query("select id from ladders where laddername='$name'")) > 0){
  246. $errormessage=$errormessage."That Ladder Name Already Exist.<br>";
  247. }
  248. if (mysql_num_rows(mysql_query("select id from ladders where abbreviation='$abrv'")) > 0){
  249. $errormessage=$errormessage."That Ladder Abreviation Already Exist.<br>";
  250. }
  251. return($errormessage);
  252. }
  253. //CHECK IF OTHER LADDER NAME OR ABREVIATION EXIST
  254. function check_ladderexistother($errormessage, $name, $abrv, $ladderid){
  255. if (mysql_num_rows(mysql_query("select id from ladders where laddername='$name' AND id!='$ladderid'")) > 0){
  256. $errormessage=$errormessage."That Ladder Name Already Exist.<br>";
  257. }
  258. if (mysql_num_rows(mysql_query("select id from ladders where abbreviation='$abrv' AND id!='$ladderid'")) > 0){
  259. $errormessage=$errormessage."That Ladder Abreviation Already Exist.<br>";
  260. }
  261. return($errormessage);
  262. }
  263. //CHECK IF OTHER LADDER NAME OR ABREVIATION EXIST
  264. function check_emailaddress($email){
  265. if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2}[mtgvu]?$", $email)){
  266. $errormessage=$errormessage."That Email address is invalid.<br>";
  267. }
  268. return($errormessage);
  269. }
  270. // +CHANGES
  271. //CHANGE URLS THAT FORGOT THE http://
  272. function change_url($url){
  273. if(($url) && (!(eregi('(^(f|ht)tp[s]*:[/]+)(.*)', $url)))){
  274. $url = "http://" . $url;
  275. }
  276. return("$url");
  277. }
  278. // STRIP LEADING,TRAILING,DOUBLE AND WHITE SPACES
  279. function strip_whitespace($text){
  280. $text=trim($text);
  281. $text=eregi_replace("( ){2,}", " ", $text);
  282. return($text);
  283. }
  284. // STRIP ALL SPACES
  285. function strip_allspace($text){
  286. $text=trim($text);
  287. $text=eregi_replace("( ){2,}", "", $text);
  288. return($text);
  289. }
  290. //CHANGE CHARACTERS / STRIP HTML
  291. function change_charecters($text){
  292. $text=trim($text);
  293. $text=eregi_replace("( ){2,}", " ", $text);
  294. // ⁄$text=str_replace(",", "", $text);
  295. $text=str_replace(";", "", $text);
  296. $text=htmlspecialchars("$text");
  297. $text=str_replace("#", "", $text);
  298. $text=str_replace("|", "l", $text);
  299. $text=str_replace("'", "&acute;", $text);
  300. return($text);
  301. }
  302. //CHANGE CHARACTERS / STRIP HTML
  303. function unchange_charecters($text){
  304. $text=ereg_replace('&gt;', '>', $text);
  305. $text=ereg_replace('&lt;', '<', $text);
  306. $text=ereg_replace('&quot;', "\"", $text);
  307. $text=ereg_replace('&amp;', '&', $text);
  308. return($text);
  309. }
  310. //CHANGE TO BCODE CHARACTERS FROM HTML CODE
  311. function change_tolinebreaks($text){
  312. $text=str_replace("<br>", "\n", $text);
  313. return($text);
  314. }
  315. //CHANGE BCODE CHARACTERS TO HTML CODE
  316. function change_fromlinebreaks($text){
  317. $text=str_replace("\n", "{br}", $text);
  318. return($text);
  319. }
  320. //CHANGE BCODE CHARACTERS TO HTML CODE
  321. function change_tocharectercode($text){
  322. $text=str_replace("{img=", "<img src=", $text);
  323. $text=str_replace("{/img", "", $text);
  324. $text=str_replace("{font", "<font", $text);
  325. $text=str_replace("{/font", "</font", $text);
  326. $text=str_replace("{br", "<br", $text);
  327. $text=str_replace("{b", "<b", $text);
  328. $text=str_replace("{/b", "</b", $text);
  329. $text=str_replace("}", ">", $text);
  330. return($text);
  331. }
  332. //CHANGE TO BCODE CHARACTERS FROM HTML CODE
  333. function change_fromcharectercode($text){
  334. $text=str_replace("<img src=", "{img=", $text);
  335. $text=str_replace("<font", "{font", $text);
  336. $text=str_replace("</font", "{/font", $text);
  337. $text=str_replace("<br", "{br", $text);
  338. $text=str_replace("<b", "{b", $text);
  339. $text=str_replace("</b", "{/b", $text);
  340. $text=str_replace(">", "}", $text);
  341. return($text);
  342. }
  343. //CUTS OFF AT A NON-NUMERIC CHARECTER:
  344. function change_numbersonly($value){
  345. if($value!="0"){
  346. $value=trim($value);
  347. $value=eregi_replace("( ){2,}", " ", $value);
  348. $value=str_replace("-", "", $value);
  349. $value=intval($value);
  350. if($value=="0"){
  351. $value="";
  352. }
  353. }
  354. return($value);
  355. }
  356. //ENCODE
  357. function encrypt_word($word){
  358. $word=base64_encode($word);
  359. return($word);
  360. }
  361. //DECODE
  362. function decrypt_word($word){
  363. $word=base64_decode($word);
  364. return($word);
  365. }
  366. //CENSOR
  367. function change_censor($word){
  368. global $misc;
  369. $bannedwords=mysql_query("SELECT text FROM bancensor WHERE type='7' or type='8'");
  370. while(list($val)=mysql_fetch_row($bannedwords)){
  371. $word=trim(eregi_replace($val,ban_censorchar($misc[censorschar],strlen($val))," $word "));
  372. }
  373. return($word);
  374. }
  375. //REPEAT CENSOR CHARECTER
  376. function ban_censorchar($char, $times) {
  377. $counter=0;
  378. while ($counter++<$times) {
  379. $retstring.=$char;
  380. }
  381. return($retstring);
  382. }
  383. // CHECK AND RETURN ERROR
  384. function error_check($errormessage){
  385. global $dir;
  386. if ($errormessage){
  387. include("$dir[func]/error.php");
  388. display_error($errormessage);
  389. }
  390. }
  391. ?>