PageRenderTime 58ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/applicationlib.php

https://github.com/sportsynergy/clubpro
PHP | 6486 lines | 4237 code | 1169 blank | 1080 comment | 521 complexity | fbe1054208d01d13503510492a4b7040 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /* ====================================================================
  4. * GNU Lesser General Public License
  5. * Version 2.1, February 1999
  6. *
  7. * <one line to give the library's name and a brief idea of what it does.>
  8. *
  9. * Copyright (C) 2001~2012 Adam Preston
  10. *
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. * $Id:$
  26. */
  27. /*
  28. Gets the possible outcomes for a match
  29. */
  30. function mysqli_result($res, $row, $field=0) {
  31. $res->data_seek($row);
  32. $datarow = $res->fetch_array();
  33. return $datarow[$field];
  34. }
  35. function getMatchScores($reservationid){
  36. $query = "SELECT gameswon,gameslost
  37. FROM tblMatchScore
  38. INNER JOIN tblCourts ON tblMatchScore.courttypeid = tblCourts.courttypeid
  39. INNER JOIN tblReservations ON tblCourts.courtid = tblReservations.courtid
  40. WHERE tblReservations.reservationid = $reservationid";
  41. return db_query($query);
  42. }
  43. function get_site_password($siteid){
  44. $sitePasswordQuery = "SELECT sites.password FROM tblClubSites sites WHERE sites.siteid = $siteid";
  45. $sitePasswordResult = db_query($sitePasswordQuery);
  46. $sitePasswordResultArray = mysqli_fetch_array($sitePasswordResult);
  47. return $sitePasswordResultArray[0];
  48. }
  49. /*
  50. Use send grid to send out emails from the admin
  51. */
  52. function sendgrid_clubmail($subject, $to_emails, $content, $category ){
  53. if (isDebugEnabled(1)) {
  54. logMessage("applicationlib.sendgrid_clubmail: sending email with subject $subject with a size " . count($to_emails) );
  55. }
  56. if( count($to_emails) == 0){
  57. if (isDebugEnabled(1)) {
  58. logMessage("applicationlib.sendgrid_clubmail: there is a problem with sending mail for $subject, exiting..." );
  59. }
  60. return;
  61. }
  62. $apiKey = $_SESSION["CFG"]["sendgrid_api"];
  63. $sendgrid = new SendGrid($apiKey);
  64. $mail = new SendGrid\Mail();
  65. foreach ($to_emails as $k=>$v){
  66. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: sending email to: $k with subject $subject and category $category" );
  67. $personalization = new SendGrid\Personalization();
  68. $email = new SendGrid\Email($v['name'], $k);
  69. $personalization->addTo($email);
  70. $personalization->addSubstitution("%firstname%", $v['name']);
  71. if ( array_key_exists('url', $v) ){
  72. $personalization->addSubstitution("%signupurl%", $v['url']);
  73. }
  74. else {
  75. $personalization->addSubstitution("%signupurl%","");
  76. }
  77. $mail->addPersonalization($personalization);
  78. }
  79. $file_contents = file_get_contents($_SESSION["CFG"]["templatedir"]."/email/blank.email.html");
  80. $template = str_replace("%sitecode%", get_sitecode(), $file_contents);
  81. $template = str_replace("%content%", $content->line1, $template);
  82. $template = str_replace("%dns%", $_SESSION["CFG"]["dns"], $template);
  83. $template = str_replace("%app_root%", $_SESSION["CFG"]["wwwroot"], $template);
  84. $html_content = new SendGrid\Content("text/html", $template);
  85. $from_email = new SendGrid\Email(get_userfullname(), get_email() );
  86. $mail->setFrom($from_email);
  87. $mail->setSubject($subject);
  88. $mail->addCategory("Club Email");
  89. $mail->addCategory($content->clubname);
  90. $mail->addContent($html_content);
  91. try {
  92. $response = $sendgrid->client->mail()->send()->post($mail);
  93. } catch (Exception $e) {
  94. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: Caught exception: " );
  95. }
  96. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: mail was sent with status ". $response->statusCode() ." number of emails sent: ". count($personalization->getTos()) );
  97. }
  98. /*
  99. Uses sendgrid to send out system generated emails. Check out Sendgrid.com
  100. */
  101. function sendgrid_email($subject, $to_emails, $content, $category){
  102. if (isDebugEnabled(1)) {
  103. logMessage("applicationlib.sendgrid_email: sending email with subject $subject with a size " . count($to_emails) );
  104. }
  105. if( count($to_emails) == 0){
  106. if (isDebugEnabled(1)) {
  107. logMessage("applicationlib.sendgrid_email: there is a problem with sending mail for $subject, exiting..." );
  108. }
  109. return;
  110. }
  111. $apiKey = $_SESSION["CFG"]["sendgrid_api"];
  112. $sendgrid = new SendGrid($apiKey);
  113. $file_contents = file_get_contents($_SESSION["CFG"]["templatedir"]."/email/standard.email.html");
  114. $template = str_replace("%clubname%", $content->clubname, $file_contents);
  115. $template = str_replace("%sitecode%", get_sitecode(), $template);
  116. $template = str_replace("%content%", $content->line1, $template);
  117. $template = str_replace("%dns%", $_SESSION["CFG"]["dns"], $template);
  118. $template = str_replace("%app_root%", $_SESSION["CFG"]["wwwroot"], $template);
  119. $mail = new SendGrid\Mail();
  120. foreach ($to_emails as $k=>$v){
  121. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: sending email to: $k with subject $subject and category $category and ".$v['name'] );
  122. $personalization = new SendGrid\Personalization();
  123. $email = new SendGrid\Email($v['name'], $k);
  124. $personalization->addTo($email);
  125. $personalization->addSubstitution("%firstname%", $v['name']);
  126. if ( array_key_exists('url', $v) ){
  127. $personalization->addSubstitution("%signupurl%", $v['url']);
  128. }
  129. else {
  130. $personalization->addSubstitution("%signupurl%","");
  131. }
  132. $mail->addPersonalization($personalization);
  133. }
  134. $from_email = new SendGrid\Email("Sportsynergy", $_SESSION["CFG"]["mailer.email"]);
  135. $html_content = new SendGrid\Content("text/html", $template);
  136. $mail->setFrom($from_email);
  137. $mail->setSubject($subject);
  138. $mail->addCategory($category);
  139. $mail->addCategory($content->clubname);
  140. $mail->addContent($html_content);
  141. try {
  142. $response = $sendgrid->client->mail()->send()->post($mail);
  143. } catch (Exception $e) {
  144. echo 'Caught exception: ', $e->getMessage(), "\n";
  145. }
  146. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: mail was sent with status ". $response->statusCode() );
  147. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: number of emails sent: ". count($personalization->getTos()) );
  148. if (isDebugEnabled(1)) logMessage("applicationlib.sendgrid_email: response body: ". $response->body() );
  149. }
  150. /**
  151. * Calls the PostageApp
  152. *
  153. * @param $subject
  154. * @param $to_email
  155. * @param $to_name
  156. * @param $content an array of line1, line2, line3
  157. */
  158. function send_email($subject, $to_emails, $from_email, $content, $template) {
  159. if (isDebugEnabled(1)) {
  160. logMessage("applicationlib.send_email: sending email with subject $subject with a size " . count($to_emails) . " from $from_email");
  161. }
  162. $variables = array(
  163. 'line1' => $content->line1,
  164. 'clubname' => $content->clubname
  165. );
  166. // Setup some headers
  167. $header = array(
  168. 'From' => $from_email,
  169. 'Reply-to' => $from_email
  170. );
  171. // Send it all
  172. $ret = PostageApp::mail($to_emails, $subject, $template, $header, $variables);
  173. // Checkout the response
  174. if ($ret->response->status == 'ok') {
  175. if (isDebugEnabled(1)) logMessage("applicationlib.send_email: SUCCESS An email was sent and the following response was received ".$ret->response->message);
  176. } else {
  177. if (isDebugEnabled(1)) logMessage("applicationlib.send_email: ERROR sending your email: ".$ret->response->status );
  178. }
  179. //return $response;
  180. }
  181. /**
  182. *
  183. * @param $dateString
  184. */
  185. function formatDate($dateString) {
  186. return date("Y-n-d G:i:s", $dateString);
  187. }
  188. /**
  189. * Logs in user
  190. *
  191. * One very interesting thing here is that anyone can use a superpassword to login.
  192. *
  193. * @param String $username
  194. * @param String $password
  195. * @param bool $encodedpassword
  196. */
  197. function verify_login($username, $password, $encodedpassword) {
  198. /* verify the username and password. if it is a valid login, return an array
  199. * with the username, firstname, lastname, and email address of the user */
  200. $superpassword = "20ffeee869abfadb176a66075c5f1816";
  201. if ($encodedpassword) {
  202. $password = md5($password);
  203. }
  204. if (isDebugEnabled(1)) logMessage("applicationlib.verify_login: Logging in $username");
  205. $loginQuery = "SELECT users.userid, users.username, users.firstname, users.lastname, users.email, clubuser.roleid, club.clubname
  206. FROM tblUsers users, tblClubUser clubuser, tblClubs club
  207. WHERE users.username = '$username'
  208. AND users.userid = clubuser.userid
  209. AND clubuser.clubid='" . get_clubid() . "'
  210. AND club.clubid = clubuser.clubid
  211. AND users.password = '$password'
  212. AND clubuser.enable='y'
  213. AND clubuser.enddate IS NULL";
  214. $loginResult = db_query($loginQuery);
  215. // If the login fails see if the superpassword was used
  216. if (mysqli_num_rows($loginResult) == 0) {
  217. //encode the superpassword
  218. // If they used the superpassword, then just get the user.
  219. if ($superpassword == $password) {
  220. $loginQuery = "SELECT users.userid, users.username, users.firstname, users.lastname, users.email, clubuser.roleid, club.clubname
  221. FROM tblUsers users, tblClubUser clubuser, tblClubs club
  222. WHERE users.username = '$username'
  223. AND users.userid = clubuser.userid
  224. AND clubuser.clubid='" . get_clubid() . "'
  225. AND club.clubid = clubuser.clubid
  226. AND clubuser.enable='y'
  227. AND clubuser.enddate IS NULL";
  228. $loginResult = db_query($loginQuery);
  229. }
  230. }
  231. return db_fetch_array($loginResult);
  232. }
  233. /**
  234. * Loads user (logs in with no password)
  235. * @param
  236. */
  237. function load_user($userid) {
  238. $loginQuery = "SELECT users.userid, users.username, users.firstname, users.lastname, users.email, clubuser.clubid, clubuser.roleid, club.clubname
  239. FROM tblUsers users, tblClubUser clubuser, tblClubs club
  240. WHERE users.userid = clubuser.userid
  241. AND clubuser.clubid
  242. AND clubuser.clubid='" . get_clubid() . "'
  243. AND users.userid = '$userid'
  244. AND clubuser.enable='y'
  245. AND club.clubid = clubuser.clubid
  246. AND clubuser.enddate IS NULL ";
  247. $loginResult = db_query($loginQuery);
  248. return db_fetch_array($loginResult);
  249. }
  250. /**
  251. * Returns all users with the given username.
  252. * @param unknown_type $username
  253. * @param unknown_type $clubid
  254. */
  255. function getAllUsersWithIdResult($username, $clubid) {
  256. $usersQuery = "SELECT users.userid, users.firstname, users.lastname
  257. FROM tblUsers users, tblClubUser clubuser
  258. WHERE users.username = '$username'
  259. AND users.userid = clubuser.userid
  260. AND clubuser.clubid='" . get_clubid() . "'
  261. AND clubuser.enddate IS NULL";
  262. return db_query($usersQuery);
  263. }
  264. /**
  265. * This determines if the user is valid for a sport.
  266. *
  267. * @param unknown_type $siteid
  268. * @return boolean
  269. */
  270. function amiValidForSite($siteid) {
  271. $amiauthforsiteQuery = "SELECT tblkupSiteAuth.userid, tblkupSiteAuth.siteid
  272. FROM tblkupSiteAuth
  273. WHERE (((tblkupSiteAuth.userid)=" . get_userid() . ") AND ((tblkupSiteAuth.siteid)=$siteid))";
  274. $amiauthforsiteResult = db_query($amiauthforsiteQuery);
  275. if (mysqli_num_rows($amiauthforsiteResult) == 0) {
  276. if (isDebugEnabled(1)) logMessage("applicationlib.amiValidForSite: " . get_userid() . " is NOT valid for $siteid");
  277. return FALSE;
  278. } else {
  279. if (isDebugEnabled(1)) logMessage("applicationlib.amiValidForSite: " . get_userid() . " is valid for $siteid");
  280. return TRUE;
  281. }
  282. }
  283. /**
  284. * This determines if the user is valid for a site.
  285. * @param unknown_type $courttypeid
  286. * @param unknown_type $userid
  287. * @return boolean Returns either TRUE or FALSE
  288. */
  289. function isValidForCourtType($courttypeid, $userid) {
  290. $amiauthforCourtTypeQuery = "SELECT tblUserRankings.courttypeid
  291. FROM tblUserRankings
  292. WHERE tblUserRankings.userid=$userid
  293. AND tblUserRankings.courttypeid=$courttypeid
  294. AND tblUserRankings.usertype=0";
  295. $amiauthforCourtTypeResult = db_query($amiauthforCourtTypeQuery);
  296. if (mysqli_num_rows($amiauthforCourtTypeResult) == 0) {
  297. if (isDebugEnabled(1)) logMessage("applicationlib.amiValidForCourtType: $userid is NOT valid for $courttypeid");
  298. return FALSE;
  299. } else {
  300. if (isDebugEnabled(1)) logMessage("applicationlib.amiValidForCourtType: $userid is valid for $courttypeid");
  301. return TRUE;
  302. }
  303. }
  304. /**
  305. * Check to see if I am a buddy
  306. * @param unknown_type $userid
  307. */
  308. function amIaBuddyOf($userid) {
  309. $imabuddy = FALSE;
  310. $imabuddyQuery = "SELECT buddyid FROM tblBuddies WHERE userid=$userid";
  311. $imabuddyResult = db_query($imabuddyQuery);
  312. while ($imabuddyArray = mysqli_fetch_array($imabuddyResult)) {
  313. if ($imabuddyArray['buddyid'] == get_userid()) {
  314. $imabuddy = TRUE;
  315. }
  316. }
  317. return $imabuddy;
  318. }
  319. /**
  320. * Checks to see if this person is a buddy.
  321. * @param unknown_type $buddyid
  322. * @return boolean
  323. */
  324. function isABuddyOfMine($buddyid) {
  325. $isABuddy = FALSE;
  326. $imabuddyQuery = "SELECT buddyid FROM tblBuddies WHERE userid=" . get_userid();
  327. $imabuddyResult = db_query($imabuddyQuery);
  328. while ($imabuddyArray = mysqli_fetch_array($imabuddyResult)) {
  329. if ($imabuddyArray['buddyid'] == $buddyid) {
  330. $isABuddy = TRUE;
  331. }
  332. }
  333. return $isABuddy;
  334. }
  335. /**
  336. * This is used to quickly set a match type. Right now as far as I know there are 4 possible match types:
  337. * 0 practice match
  338. * 1 box league match
  339. * 2 challenge match
  340. * 3 buddy match
  341. * @param unknown_type $resid
  342. * @param unknown_type $matchtype
  343. */
  344. function markMatchType($resid, $matchtype) {
  345. $markMatchTypeQuery = "Update tblReservations SET matchtype=$matchtype WHERE reservationid=$resid AND enddate IS NULL";
  346. $markMatchTypeResult = db_query($markMatchTypeQuery);
  347. }
  348. /**
  349. * This will find out if the calling user is in a box of the
  350. * courttype fo the court passed in as the argument.
  351. * Not very fancy here, true if they are false if they are not.
  352. *
  353. * @param unknown_type $courtid
  354. * @param unknown_type $userid
  355. */
  356. function is_inabox($courtid, $userid) {
  357. $amIinThisBox = FALSE;
  358. $courtTypeId = get_courtTypeForCourt($courtid);
  359. $amiinaboxquery = "SELECT boxleagues.courttypeid, boxleaguedetails.userid
  360. FROM tblBoxLeagues boxleagues, tblkpBoxLeagues boxleaguedetails
  361. WHERE boxleagues.boxid = boxleaguedetails.boxid
  362. AND boxleagues.courttypeid=$courtTypeId
  363. AND boxleaguedetails.userid=$userid";
  364. // run the query on the database
  365. $amiinaboxresult = db_query($amiinaboxquery);
  366. if (mysqli_num_rows($amiinaboxresult) > 0) {
  367. $amIinThisBox = TRUE;
  368. }
  369. return $amIinThisBox;
  370. }
  371. /**
  372. * returns the match type for the given reservationid
  373. *
  374. * @param unknown_type $resid
  375. * @return unknown
  376. */
  377. function getMatchType($resid) {
  378. $matchtypequery = "SELECT matchtype FROM `tblReservations` WHERE reservationid=$resid";
  379. $matchtyperesult = db_query($matchtypequery);
  380. $matchtypevalueArray = mysqli_fetch_array($matchtyperesult);
  381. $matchtypevalue = $matchtypevalueArray[0];
  382. return $matchtypevalue;
  383. }
  384. /**
  385. * When you need to just get the first and last name of a user and you only
  386. * seem to have there userid handy then this is the function for you.
  387. *
  388. * @param unknown_type $tid
  389. * @return string
  390. */
  391. function get_partnerbytid($tid) {
  392. $firstandlastquery = "SELECT users.firstname, users.lastname
  393. FROM tblkpTeams teamdetails, tblUsers users
  394. WHERE teamdetails.userid = users.userid
  395. AND teamdetails.teamid=$tid
  396. AND users.userid !=" . get_userid();
  397. $firstandlastresult = db_query($firstandlastquery);
  398. $firstandlastarray = mysqli_fetch_array($firstandlastresult);
  399. return "$firstandlastarray[0] $firstandlastarray[1]";
  400. }
  401. /**
  402. * Figuers out if this user is in this league.
  403. *
  404. * @param unknown_type $userid
  405. * @param unknown_type $courttypeid
  406. * @param unknown_type $clubid
  407. */
  408. function isUserInClubLadder($userid, $courttypeid, $clubid) {
  409. $query = "SELECT 1 FROM tblClubLadder ladder WHERE ladder.userid = $userid AND ladder.courttypeid = $courttypeid AND ladder.clubid = $clubid";
  410. $result = db_query($query);
  411. if (mysqli_num_rows($result) > 0) {
  412. return true;
  413. } else {
  414. return false;
  415. }
  416. }
  417. /**
  418. * Does not look at the reservation match type but only if the two players
  419. * are in a box together and that haven't recorded the score yet.
  420. *
  421. * @param unknown_type $reservationid
  422. * @return boolean Returns true if this is an unscore box league.
  423. */
  424. function isUnscoredBoxLeagueReservation($reservationid) {
  425. //Check reservation History
  426. $query = "SELECT * FROM tblBoxHistory history, tblkpUserReservations reservationdetails
  427. WHERE history.reservationid = $reservationid
  428. AND reservationdetails.reservationid = history.reservationid
  429. AND reservationdetails.outcome = 0";
  430. $results = db_query($query);
  431. //If reservation hasnt't been scored
  432. if (mysqli_num_rows($results) == 2) {
  433. return true;
  434. }
  435. return false;
  436. }
  437. /**
  438. * Called by the court reservation page to valiidate that
  439. * the the user is actually in a box leage with this opponent.
  440. *
  441. * @param unknown_type $playerOneId
  442. * @param unknown_type $playerTwoId
  443. */
  444. function getBoxIdTheseTwoGuysAreInTogether($playerOneId, $playerTwoId) {
  445. if( empty($playerOneId) || empty($playerTwoId) ){
  446. return false;
  447. }
  448. $playeronequery = "SELECT boxleagues.boxid, boxleaguedetails.userid
  449. FROM tblBoxLeagues boxleagues, tblkpBoxLeagues boxleaguedetails
  450. WHERE boxleagues.boxid = boxleaguedetails.boxid
  451. AND boxleaguedetails.userid=$playerOneId";
  452. // run the query on the database
  453. $playeroneresult = db_query($playeronequery);
  454. $p1stack = array();
  455. $p2stack = array();
  456. //Put all boxes for the user in an array
  457. while ($playeronearray = db_fetch_array($playeroneresult)) {
  458. array_push($p1stack, $playeronearray[0]);
  459. }
  460. $playertwoquery = "SELECT boxleagues.boxid, boxleaguedetails.userid
  461. FROM tblBoxLeagues boxleagues, tblkpBoxLeagues boxleaguedetails
  462. WHERE boxleagues.boxid = boxleaguedetails.boxid
  463. AND boxleaguedetails.userid=$playerTwoId";
  464. // run the query on the database
  465. $playertworesult = db_query($playertwoquery);
  466. //Put all boxes for the user in an array
  467. while ($playertwoarray = db_fetch_array($playertworesult)) {
  468. array_push($p2stack, $playertwoarray[0]);
  469. }
  470. $playersintersect = array_intersect($p1stack, $p2stack);
  471. return $playersintersect[0];
  472. }
  473. /**
  474. * Returns the box id when of the box that the players share. This function is called by
  475. * the court reservation page to validate that the the user is actually in a
  476. * box leage with this opponent
  477. * @param $playerone
  478. * @param $playertwo
  479. */
  480. function are_boxplayers($playerone, $playertwo) {
  481. if( empty($playerone) || empty($playertwo) ){
  482. return false;
  483. }
  484. $playeronequery = "SELECT boxleagues.boxid, boxleaguedetails.userid
  485. FROM tblBoxLeagues boxleagues, tblkpBoxLeagues boxleaguedetails
  486. WHERE boxleagues.boxid = boxleaguedetails.boxid
  487. AND boxleaguedetails.userid=$playerone";
  488. // run the query on the database
  489. $playeroneresult = db_query($playeronequery);
  490. $p1stack = array();
  491. $p2stack = array();
  492. //Put all boxes for the user in an array
  493. while ($playeronearray = db_fetch_array($playeroneresult)) {
  494. array_push($p1stack, $playeronearray[0]);
  495. }
  496. $playertwoquery = "SELECT boxleagues.boxid, boxleaguedetails.userid
  497. FROM tblBoxLeagues boxleagues, tblkpBoxLeagues boxleaguedetails
  498. WHERE boxleagues.boxid = boxleaguedetails.boxid
  499. AND boxleaguedetails.userid=$playertwo";
  500. // run the query on the database
  501. $playertworesult = db_query($playertwoquery);
  502. //Put all boxes for the user in an array
  503. while ($playertwoarray = db_fetch_array($playertworesult)) {
  504. array_push($p2stack, $playertwoarray[0]);
  505. }
  506. $playersintersect = array_intersect($p1stack, $p2stack);
  507. if (count($playersintersect) > 0) {
  508. return true;
  509. } else {
  510. return false;
  511. }
  512. }
  513. /**
  514. * this function will return true if the user has logged in. a user is logged
  515. * in if the $_SESSION["user"] is set (by the login.php page) and also if the
  516. * remote IP address matches what we saved in the session ($_SESSION["ip"])
  517. * from login.php -- this is not a robust or secure check by any means, but it
  518. * will do for now
  519. */
  520. function is_logged_in() {
  521. return isset($_SESSION) && isset($_SESSION["user"]);
  522. }
  523. /**
  524. * this function checks to see if the user is logged in. if not, it will show
  525. * the login screen before allowing the user to continue
  526. */
  527. function require_login() {
  528. if (!is_logged_in()) {
  529. $_SESSION["wantsurl"] = qualified_me();
  530. redirect($_SESSION["CFG"]["wwwroot"] . "/login.php");
  531. }
  532. }
  533. /**
  534. * this function checks to see if the user is logged in. if not, it will show
  535. * the login screen before allowing the user to continue
  536. */
  537. function require_loginwq() {
  538. if (!is_logged_in()) {
  539. // For clubsites set to auto login, look for username and password REQUEST parameters to
  540. // use for logging in.
  541. if( isSiteAutoLogin() ){
  542. $url_parts = parse_url(qualified_mewithq());
  543. parse_str($url_parts['query'], $params);
  544. if( isset($params['username']) && isset($params['password']) ){
  545. if (isDebugEnabled(1)) logMessage("applicationlib.require_loginwq: logging in autologin user: ". $params['username']);
  546. $user = verify_login( $params['username'],$params['password'], false );
  547. if( $user ){
  548. if (isDebugEnabled(1)) logMessage("applicationlib.require_loginwq: valid user");
  549. $_SESSION["user"] = $user;
  550. } else{
  551. redirect($_SESSION["CFG"]["wwwroot"] . "/login.php");
  552. }
  553. } else{
  554. redirect($_SESSION["CFG"]["wwwroot"] . "/login.php");
  555. }
  556. } else {
  557. $_SESSION["wantsurl"] = qualified_mewithq();
  558. redirect($_SESSION["CFG"]["wwwroot"] . "/login.php");
  559. }
  560. }
  561. }
  562. /**
  563. * this function simply returns the clubid.
  564. */
  565. function get_tzdelta() {
  566. return $_SESSION["siteprefs"]["timezone"] * 3600;
  567. }
  568. /**
  569. * this function simply returns the clubid.
  570. */
  571. function get_clubid() {
  572. return $_SESSION["siteprefs"]["clubid"];
  573. }
  574. /**
  575. * this function simply returns the siteid.
  576. */
  577. function get_siteid() {
  578. return $_SESSION["siteprefs"]["siteid"];
  579. }
  580. /**
  581. * this function simply returns the autologin status
  582. */
  583. function isSiteAutoLogin() {
  584. return $_SESSION["siteprefs"]["enableautologin"] == 'y' ? true : false;
  585. }
  586. /**
  587. * this function simply returns whether or not the recent activity should be displayed
  588. * @return boolean
  589. */
  590. function isDisplayRecentActivity() {
  591. return $_SESSION["siteprefs"]["displayrecentactivity"] == 'y' ? true : false;
  592. }
  593. /**
  594. * this function simply returns the daysahead or the parameter that defines how far in advance users can make.
  595. */
  596. function get_displaytime() {
  597. return $_SESSION["siteprefs"]["displaytime"];
  598. }
  599. /**
  600. * this function simply returns the whether or not the site has solo reservations enabled.
  601. * @return boolean
  602. */
  603. function isSoloReservationEnabled() {
  604. return $_SESSION["siteprefs"]["allowsoloreservations"] == 'y' ? true : false;
  605. }
  606. function isLadderRankingScheme() {
  607. /* this function simply returns the whether or not the site has solo reservations enabled. */
  608. return $_SESSION["siteprefs"]["rankingscheme"] == 'ladder' ? true : false;
  609. }
  610. function getChallengeRange() {
  611. /* this function simply returns the challenge range*/
  612. return $_SESSION["siteprefs"]["challengerange"];
  613. }
  614. function isPointRankingScheme() {
  615. /* this function simply returns the whether or not the site has solo reservations enabled. */
  616. return $_SESSION["siteprefs"]["rankingscheme"] == 'point' ? true : false;
  617. }
  618. function isSelfScoreEnabled() {
  619. /* this function simply returns the whether or not the site has self score enabled. */
  620. return $_SESSION["siteprefs"]["allowselfscore"] == 'y' ? true : false;
  621. }
  622. function isSiteEnabled() {
  623. /* this function simply returns the whether or not the site is enabled. */
  624. return $_SESSION["siteprefs"]["enable"] == 'y' ? true : false;
  625. }
  626. function getRankingAdjustment() {
  627. /* this function simply returns the site ranking adjustment. */
  628. return $_SESSION["siteprefs"]["rankingadjustment"];
  629. }
  630. function isSiteGuestReservationEnabled() {
  631. /* this function simply returns the siteid. */
  632. return $_SESSION["siteprefs"]["enableguestreservation"] == 'y' ? true : false;
  633. }
  634. function get_daysahead() {
  635. /* this function simply returns the daysahead or the parameter that defines how far in advance users can make. */
  636. return $_SESSION["siteprefs"]["daysahead"];
  637. }
  638. function get_facebookurl() {
  639. /* this function simply returns the the url. This is optional. */
  640. return $_SESSION["siteprefs"]["facebookurl"];
  641. }
  642. function isLiteVersion() {
  643. /* this function returns if the site is the free version. */
  644. return $_SESSION["siteprefs"]["isliteversion"] == 'y' ? true : false;
  645. }
  646. function isAllowAllSiteAdvertising() {
  647. return $_SESSION["siteprefs"]["allowallsiteadvertising"] == 'y' ? true : false;
  648. }
  649. function isNearRankingAdvertising() {
  650. return $_SESSION["siteprefs"]["allownearrankingadvertising"] == 'y' ? true : false;
  651. }
  652. function isDisplaySiteNavigation() {
  653. return $_SESSION["siteprefs"]["displaysitenavigation"] == 'y' ? true : false;
  654. }
  655. function isAllowPlayerslooking() {
  656. return $_SESSION["siteprefs"]["allowplayerslooking "] == 'y' ? true : false;
  657. }
  658. function get_reminders() {
  659. return $_SESSION["siteprefs"]["reminders"];
  660. }
  661. function isDisplayCourtTypeName() {
  662. return $_SESSION["siteprefs"]["displaycourttype"];
  663. }
  664. function isShowPlayerNames() {
  665. return $_SESSION["siteprefs"]["showplayernames"] == 'y' ? true : false;
  666. }
  667. function isRequireLogin() {
  668. return $_SESSION["siteprefs"]["requirelogin"] == 'y' ? true : false;
  669. }
  670. // Getter
  671. function get_roleid() {
  672. /* this function simply returns the roleid. */
  673. if( isset($_SESSION["user"]) ){
  674. return $_SESSION["user"]["roleid"];
  675. }
  676. return;
  677. }
  678. // Getter
  679. function get_userid() {
  680. /* this function simply returns the userid. */
  681. if( isset($_SESSION["user"]) ){
  682. return $_SESSION["user"]["userid"];
  683. }
  684. return;
  685. }
  686. function get_email() {
  687. /* this function simply returns the email. */
  688. return $_SESSION["user"]["email"];
  689. }
  690. function get_userfullname() {
  691. /* this function simply returns the logged in users first and last name. */
  692. return $_SESSION["user"]["firstname"] . " " . $_SESSION["user"]["lastname"];
  693. }
  694. function get_userfirstname() {
  695. /* this function simply returns the logged in users first and last name. */
  696. return $_SESSION["user"]["firstname"];
  697. }
  698. /*
  699. * this function simply returns the club name
  700. *
  701. * */
  702. function get_clubname() {
  703. return $_SESSION["siteprefs"]["clubname"];
  704. }
  705. function require_priv($roleid) {
  706. /* this function checks to see if the user has the privilege $roleid. if not,
  707. * it will display an Insufficient Privileges page and stop */
  708. if ($_SESSION["user"]["roleid"] != $roleid) {
  709. include ($_SESSION["CFG"]["templatedir"] . "/insufficient_privileges.php");
  710. die;
  711. }
  712. }
  713. function require_priv_user($userid) {
  714. /* just make sure current userid and specified user are in the same club */
  715. $my_site = $_SESSION["siteprefs"]["siteid"];
  716. $query = "SELECT * FROM tblkupSiteAuth WHERE userid = $userid AND siteid = $my_site";
  717. $result = db_query($query);
  718. if (mysqli_num_rows($result) == 0) {
  719. include ($_SESSION["CFG"]["templatedir"] . "/insufficient_privileges.php");
  720. die;
  721. }
  722. }
  723. function require_priv_reservation($reservationid) {
  724. /* just make sure current userid and specified user are in the same club */
  725. $my_site = $_SESSION["siteprefs"]["siteid"];
  726. $query = "SELECT 1 FROM tblReservations reservations
  727. INNER JOIN tblCourts courts ON reservations.courtid = courts.courtid
  728. WHERE reservations.reservationid = $reservationid
  729. AND courts.siteid = $my_site";
  730. $result = db_query($query);
  731. if (mysqli_num_rows($result) == 0) {
  732. if (isDebugEnabled(1)) logMessage("require_priv_reservation not allowed with site: $my_site and reservationid: $reservationid");
  733. include ($_SESSION["CFG"]["templatedir"] . "/insufficient_privileges.php");
  734. die;
  735. }
  736. }
  737. function require_priv_box($boxid) {
  738. /* just make sure current user and specified boxid are in the same club */
  739. $query = "SELECT siteid from tblBoxLeagues where boxid = $boxid";
  740. $result = db_query($query);
  741. $box_siteArray = mysqli_fetch_array($result);
  742. $box_site = $box_siteArray[0];
  743. if ($_SESSION["siteprefs"]["siteid"] != $box_site) {
  744. include ($_SESSION["CFG"]["templatedir"] . "/insufficient_privileges.php");
  745. die;
  746. }
  747. }
  748. function has_priv($roleid) {
  749. /* returns true if the user has the privilege $priv */
  750. if (isset($_SESSION["user"])) {
  751. return $_SESSION["user"]["roleid"] == $roleid;
  752. }
  753. }
  754. function atleastof_priv($roleid) {
  755. /* returns true if the user has the privilege $priv */
  756. return $_SESSION["user"]["roleid"] >= $roleid;
  757. }
  758. function err(&$errorvar) {
  759. /* if $errorvar is set, then print an error marker << */
  760. if (isset($errorvar)) {
  761. echo "<font color=#ff0000>&lt;&lt;</font>";
  762. }
  763. }
  764. function err2(&$errorvar) {
  765. /* like err(), but prints the marker >> */
  766. if (isset($errorvar)) {
  767. echo "<font color=#ff0000>&gt;&gt;</font>";
  768. }
  769. }
  770. function username_exists($username) {
  771. /* returns the true if the username exists */
  772. $qid = db_query("SELECT 1 FROM tblUsers users, tblClubUser clubuser
  773. WHERE users.username = '$username'
  774. AND users.userid = clubuser.userid
  775. AND clubuser.enddate IS NULL
  776. AND clubuser.clubid = " . get_clubid() . "");
  777. return db_num_rows($qid);
  778. }
  779. /**
  780. * Used to see if there is another one.
  781. */
  782. function username_already_exists($username, $userid) {
  783. /* returns the true if the username exists */
  784. $qid = db_query("SELECT users.username, users.userid FROM tblUsers users, tblClubUser clubuser
  785. WHERE users.username = '$username'
  786. AND users.userid = clubuser.userid
  787. AND clubuser.enddate IS NULL
  788. AND clubuser.clubid = " . get_clubid() . "");
  789. $userArray = db_fetch_array($qid);
  790. //If no rows are returned or if the username/userid is unique then the username is unique.
  791. if (db_num_rows($qid) == 0 || ($userArray['username'] == $username && $userArray['userid'] == $userid)) {
  792. return false;
  793. } else {
  794. return true;
  795. }
  796. }
  797. function email_exists($email) {
  798. /* returns true the email address exists */
  799. $query = "SELECT 1 FROM tblUsers users
  800. WHERE users.email = '$email'
  801. AND users.enddate IS NULL";
  802. $qid = db_query($query);
  803. return db_num_rows($qid);
  804. }
  805. /*
  806. *******************************************************************************************************
  807. ** makeTeamForCurrentUser
  808. creates a team, assigns a reanking and returns the new teamid for the current user
  809. *******************************************************************************************************
  810. */
  811. function makeTeamForCurrentUser($sportname, $partnerid) {
  812. global $dbh;
  813. /* Set the team identifier */
  814. $setteamquery = "INSERT INTO tblTeams (
  815. courttypeid
  816. ) VALUES (
  817. '$sportname')";
  818. // run the query on the database
  819. $setteamresult = db_query($setteamquery);
  820. /* Get the team id */
  821. $lastinsert = mysqli_insert_id($dbh);
  822. $addselfquery = "INSERT INTO tblkpTeams (
  823. teamid, userid
  824. ) VALUES ( $lastinsert
  825. ,'" . get_userid() . "')";
  826. // run the query on the database
  827. $addselfresult = db_query($addselfquery);
  828. /* Now add partner */
  829. // add self to new team
  830. $addpartnerquery = "INSERT INTO tblkpTeams (
  831. teamid, userid
  832. ) VALUES ( $lastinsert
  833. ,$partnerid)";
  834. // run the query on the database
  835. $addpartnerresult = db_query($addpartnerquery);
  836. // Finally update the rankings for the new team
  837. //Get the users doubles ranking for each team member
  838. $usersrankquery = "SELECT tblUserRankings.ranking
  839. FROM tblUserRankings
  840. WHERE (((tblUserRankings.userid)=" . get_userid() . "
  841. Or (tblUserRankings.userid)=$partnerid)
  842. AND ((tblUserRankings.courttypeid)=$sportname)
  843. AND ((tblUserRankings.usertype)=0))";
  844. $usersrankresult = db_query($usersrankquery);
  845. $rank1Array = mysqli_fetch_array($usersrankresult);
  846. $rank1 = $rank1Array[0];
  847. $usersrankresult = db_query($usersrankquery);
  848. $rank2Array = mysqli_fetch_array($usersrankresult);
  849. $rank2 = $rank2Array[0];
  850. $averagerank = ($rank1 + $rank2) / 2;
  851. $rankquery = "INSERT INTO tblUserRankings (
  852. userid, courttypeid, ranking, usertype
  853. ) VALUES (
  854. '$lastinsert'
  855. ,'$sportname'
  856. ,'$averagerank'
  857. ,1)";
  858. $rankresult = db_query($rankquery);
  859. $teaminfoarray = array(
  860. $averagerank,
  861. $lastinsert
  862. );
  863. return $teaminfoarray;
  864. }
  865. /*
  866. *******************************************************************************************************
  867. ** makeTeamForPlayers
  868. creates a team, assigns a reanking and returns the new teamid for two different players
  869. *******************************************************************************************************
  870. */
  871. function makeTeamForPlayers($sportname, $player1id, $player2id) {
  872. global $dbh;
  873. /* Set the team identifier */
  874. $setteamquery = "INSERT INTO tblTeams (
  875. courttypeid
  876. ) VALUES (
  877. '$sportname')";
  878. // run the query on the database
  879. $setteamresult = db_query($setteamquery);
  880. /* Get the team id */
  881. $lastinsert = mysqli_insert_id($dbh);
  882. $addselfquery = "INSERT INTO tblkpTeams (
  883. teamid, userid
  884. ) VALUES ( $lastinsert
  885. ,$player1id)";
  886. // run the query on the database
  887. $addselfresult = db_query($addselfquery);
  888. /* Now add partner */
  889. // add self to new team
  890. $addpartnerquery = "INSERT INTO tblkpTeams (
  891. teamid, userid
  892. ) VALUES ( $lastinsert
  893. ,$player2id)";
  894. // run the query on the database
  895. $addpartnerresult = db_query($addpartnerquery);
  896. // Finally update the rankings for the new team
  897. //Get the users doubles ranking for each team member
  898. $usersrankquery = "SELECT tblUserRankings.ranking
  899. FROM tblUserRankings
  900. WHERE (((tblUserRankings.userid)=$player1id
  901. Or (tblUserRankings.userid)=$player2id)
  902. AND ((tblUserRankings.courttypeid)=$sportname)
  903. AND ((tblUserRankings.usertype)=0))";
  904. $usersrankresult = db_query($usersrankquery);
  905. $rank1Array = mysqli_fetch_array($usersrankresult);
  906. $rank1 = $rank1Array[0];
  907. $usersrankresult = db_query($usersrankquery);
  908. $rank2Array = mysqli_fetch_array($usersrankresult);
  909. $rank2 = $rank2Array[0];
  910. $averagerank = ($rank1 + $rank2) / 2;
  911. $rankquery = "INSERT INTO tblUserRankings (
  912. userid, courttypeid, ranking, usertype
  913. ) VALUES (
  914. '$lastinsert'
  915. ,'$sportname'
  916. ,'$averagerank'
  917. ,1)";
  918. $rankresult = db_query($rankquery);
  919. $teaminfoarray = array(
  920. $averagerank,
  921. $lastinsert
  922. );
  923. return $teaminfoarray;
  924. }
  925. /**
  926. * This is really just an array funnction that will return the first element that is a duplication in the list
  927. */
  928. function findSelfTeam($array) {
  929. while ($teamid = array_pop($array)) {
  930. if (in_array($teamid, $array)) {
  931. return $teamid;
  932. }
  933. }
  934. }
  935. /**
  936. *
  937. * Enter description here ...
  938. * @param unknown_type $resid
  939. * @param unknown_type $emailType
  940. */
  941. function email_players($resid, $emailType) {
  942. if (isDebugEnabled(1)) logMessage("applicationlib.email_players: emailing Players about reservation id: $resid for a $emailType kind of email");
  943. //Check to see if the reservation is for a doubles court
  944. $usertypequery = "SELECT usertype FROM tblReservations WHERE reservationid=$resid";
  945. $usertyperesult = db_query($usertypequery);
  946. $usertypevalArray = mysqli_fetch_array($usertyperesult);
  947. $usertypeval = $usertypevalArray[0];
  948. if ($usertypeval == 0) {
  949. //email about a singles court
  950. $rquery = "SELECT courts.courtname, courts.courtid, reservations.time, users.userid, users.firstname, users.lastname, courttype.courttypeid, rankings.ranking, users.email, users.homephone, users.cellphone, users.workphone, matchtype.name
  951. FROM tblCourts courts, tblReservations reservations, tblUsers users, tblCourtType courttype, tblUserRankings rankings, tblkpUserReservations reservationdetails, tblMatchType matchtype
  952. WHERE users.userid = rankings.userid
  953. AND reservations.courtid = courts.courtid
  954. AND reservationdetails.reservationid = reservations.reservationid
  955. AND courttype.courttypeid = rankings.courttypeid
  956. AND courts.courttypeid = courttype.courttypeid
  957. AND reservationdetails.userid = users.userid
  958. AND matchtype.id = reservations.matchtype
  959. AND reservations.reservationid = $resid
  960. AND rankings.usertype=0";
  961. $rresult = db_query($rquery);
  962. $robj = mysqli_fetch_object($rresult);
  963. $var = new Object;
  964. if (isDebugEnabled(1)) logMessage("applicationlib.emailplayers: courtid " . $robj->courtid);
  965. /* email the user with the new account information */
  966. $var->userid = $robj->userid;
  967. $var->firstname = $robj->firstname;
  968. $var->lastname = $robj->lastname;
  969. $var->email = $robj->email;
  970. $var->homephone = $robj->homephone;
  971. $var->cellphone = $robj->cellphone;
  972. $var->workphone = $robj->workphone;
  973. $var->ranking = $robj->ranking;
  974. $var->courtname = $robj->courtname;
  975. $var->courtid = $robj->courtid;
  976. $var->matchtype = $robj->name;
  977. $var->time = gmdate("l F j g:i a", $robj->time);
  978. $var->timestamp = $robj->time;
  979. $var->dns = $_SESSION["CFG"]["dns"];
  980. $var->wwwroot = $_SESSION["CFG"]["wwwroot"];
  981. $var->fullname = $robj->firstname . " " . $robj->lastname;
  982. $var->support = $_SESSION["CFG"]["support"];
  983. //Set the URL
  984. $rawurl = "http://" . $var->dns . "" . $var->wwwroot . "/users/court_reservation.php?time=" . $var->timestamp . "&courtid=" . $var->courtid . "&userid=" . $var->userid;
  985. $emailbody = read_template($_SESSION["CFG"]["templatedir"] . "/email/singles_wanted.php", $var);
  986. $emailbody = nl2br($emailbody);
  987. if ($emailType == "3") {
  988. $emailidquery = "SELECT DISTINCTROW users.firstname, users.lastname, users.email, clubuser.memberid, users.password
  989. FROM tblUsers users, tblUserRankings rankings, tblClubUser clubuser
  990. WHERE users.userid = rankings.userid
  991. AND users.userid = clubuser.userid
  992. AND clubuser.clubid=" . get_clubid() . "
  993. AND clubuser.recemail='y'
  994. AND rankings.courttypeid=$robj->courttypeid
  995. AND rankings.usertype = 0
  996. AND users.userid != " . get_userid() . "
  997. AND clubuser.enable= 'y'
  998. AND clubuser.enddate IS NULL";
  999. } elseif ($emailType == "2") {
  1000. $emailidquery = "SELECT users.firstname, users.lastname, users.email, clubuser.memberid, users.password
  1001. FROM tblUsers users, tblBuddies buddies, tblClubUser clubuser, tblUserRankings rankings
  1002. WHERE users.userid = buddies.buddyid
  1003. AND users.userid = clubuser.userid
  1004. AND clubuser.clubid=" . get_clubid() . "
  1005. AND buddies.userid=" . get_userid() . "
  1006. AND rankings.courttypeid=$robj->courttypeid
  1007. AND rankings.usertype = 0
  1008. AND users.userid = rankings.userid
  1009. AND clubuser.enable= 'y'
  1010. AND clubuser.enddate IS NULL";
  1011. } elseif ($emailType == "1") {
  1012. //Get the rankdev of the club
  1013. $rankdevquery = "SELECT rankdev FROM tblClubs WHERE clubid=" . get_clubid() . "";
  1014. // run the query on the database
  1015. $rankdevresult = db_query($rankdevquery);
  1016. $rankdevvalArray = mysqli_fetch_array($rankdevresult);
  1017. $rankdevval = $rankdevvalArray[0];
  1018. $highrange = $robj->ranking + $rankdevval;
  1019. $lowrange = $robj->ranking - $rankdevval;
  1020. //Now get all players who receive players wanted notifications at the club and are within
  1021. //the set skill range
  1022. $emailidquery = "SELECT DISTINCTROW users.firstname, users.lastname, users.email, clubuser.memberid, users.password
  1023. FROM tblUsers users, tblUserRankings rankings, tblClubUser clubuser
  1024. WHERE users.userid = rankings.userid
  1025. AND users.userid = clubuser.userid
  1026. AND clubuser.clubid=" . get_clubid() . "
  1027. AND rankings.ranking>$lowrange
  1028. AND rankings.ranking<$highrange
  1029. AND clubuser.recemail='y'
  1030. AND rankings.courttypeid=$robj->courttypeid
  1031. AND rankings.usertype = 0
  1032. AND users.userid != " . get_userid() . "
  1033. AND clubuser.enable='y'
  1034. AND clubuser.enddate IS NULL";
  1035. }
  1036. // run the query on the database
  1037. $emailidresult = db_query($emailidquery);
  1038. if (isDebugEnabled(1)) logMessage("applicationlib.emailplayers query: $emailidquery");
  1039. $to_emails = array();
  1040. while ($emailidrow = db_fetch_row($emailidresult)) {
  1041. // Append username and password to signup url
  1042. if( isSiteAutoLogin() ){
  1043. //guard
  1044. if( empty($emailidrow[3]) || empty($emailidrow[4]) ){
  1045. if (isDebugEnabled(1)) logMessage("applicationlib.emailplayers: problems sending email to autologin user: ".$emailidrow[2]);
  1046. continue;
  1047. }
  1048. $rawurl .= "&username=$emailidrow[3]&password=$emailidrow[4]";
  1049. }
  1050. $signupurl = "<a href=\"$rawurl\">here</a>.";
  1051. if( !empty($emailidrow[0]) && !empty($emailidrow[1]) && !empty($emailidrow[2])){
  1052. $to_email = "$emailidrow[2]";
  1053. $to_emails[$to_email] = array(
  1054. 'name' => $emailidrow[0],
  1055. 'url' => $signupurl
  1056. );
  1057. } else {
  1058. if (isDebugEnabled(1)) logMessage("applicationlib.emailplayers: ".get_userfullname()." not sending to $emailidrow[0] because of incomplete information");
  1059. }
  1060. }
  1061. $content = new Object;
  1062. $content->line1 = $emailbody;
  1063. $content->clubname = get_clubname();
  1064. $template = get_sitecode();
  1065. $subject = "Player's Market Place - ". get_clubname();
  1066. //Send the email
  1067. sendgrid_email($subject, $to_emails, $content, "Players Wanted");
  1068. }
  1069. //email about a doubles court
  1070. else {
  1071. $rquery = "SELECT
  1072. courts.courtname,
  1073. courts.courttypeid,
  1074. reservations.time,
  1075. users.firstname,
  1076. users.lastname,
  1077. courts.courtid,
  1078. users.userid,
  1079. matchtype.name,
  1080. teamdetails.teamid
  1081. FROM
  1082. tblReservations reservations,
  1083. tblkpUserReservations reservationdetails,
  1084. tblkpTeams teamdetails,
  1085. tblUsers users,
  1086. tblCourts courts,
  1087. tblMatchType matchtype,
  1088. tblClubUser clubuser
  1089. WHERE reservationdetails.reservationid = reservations.reservationid
  1090. AND teamdetails.teamid = reservationdetails.userid
  1091. AND reservationdetails.usertype = 1
  1092. AND users.userid = teamdetails.userid
  1093. AND courts.courtid = reservations.courtid
  1094. AND matchtype.id = reservations.matchtype
  1095. AND reservationdetails.reservationid=$resid
  1096. AND users.userid = clubuser.userid
  1097. AND clubuser.clubid =" . get_clubid();
  1098. $rresult = db_query($rquery);
  1099. $robj = mysqli_fetch_object($rresult);
  1100. $extraPlayerQuery = "SELECT reservationdetails.userid
  1101. FROM tblReservations reservations, tblkpUserReservations reservationdetails
  1102. WHERE reservations.reservationid = reservationdetails.reservationid
  1103. AND reservationdetails.reservationid=$resid
  1104. AND reservationdetails.usertype=0
  1105. ORDER BY reservationdetails.userid";
  1106. $extraPlayerResult = db_query($extraPlayerQuery);
  1107. $extraPlayerArray = mysqli_fetch_array($extraPlayerResult);
  1108. //Get Court Type. The reason this is done here is that in the cases of partial
  1109. //reservations, this is empty in the query above.
  1110. $ctQuery = "SELECT courts.courttypeid
  1111. FROM tblReservations reservations, tblCourts courts
  1112. WHERE reservations.reservationid=$resid
  1113. AND reservations.courtid = courts.courtid";
  1114. $ctResult = db_query($ctQuery);
  1115. $courtTypeArray = mysqli_fetch_array($ctResult);
  1116. $courtType = $courtTypeArray[0];
  1117. $player1 = $robj->userid;
  1118. $var = new Object;
  1119. /* email the user with the new account information */
  1120. $var->firstname1 = $robj->firstname;
  1121. $var->lastname1 = $robj->lastname;
  1122. $var->fullname1 = $robj->firstname . " " . $robj->lastname;
  1123. $var->teamid = $robj->teamid;
  1124. //Get the next result
  1125. $robj = mysqli_fetch_object($rresult);
  1126. $player2 = $robj->userid;
  1127. $var->firstname2 = $robj->firstname;
  1128. $var->lastname2 = $robj->lastname;
  1129. $var->fullname2 = $robj->firstname . " " . $robj->lastname;
  1130. $var->courtid = $robj->courtid;
  1131. $var->courtname = $robj->courtname;
  1132. $var->matchtype = $robj->name;
  1133. $var->time = gmdate("l F j g:i a", $robj->time);
  1134. $var->timestamp = $robj->time;
  1135. $var->dns = $_SESSION["CFG"]["dns"];
  1136. $var->wwwroot = $_SESSION["CFG"]["wwwroot"];
  1137. $var->support = $_SESSION["CFG"]["support"];
  1138. $clubfullname = get_clubname();
  1139. $var->clubfullname = $clubfullname;
  1140. $var->clubadminemail = "Sportsynergy <player.mailer@sportsynergy.net>";
  1141. /* if this reservation is made with a player looking for a partner, something will
  1142. be set in the extraPlayerQuery, if so display a different email message .
  1143. $extraPlayerobj->userid will be 0 when taking a player removes himself
  1144. from a reservation where he was looking for a match.
  1145. */
  1146. $extraPlayerUserId = 0;
  1147. //Check for three players wanted
  1148. if (db_num_rows($extraPlayerResult) == 2 && $extraPlayerArray['userid'] == 0) {
  1149. if (isDebugEnabled(1)) logMessage("applicationlib.emailplayers: three players are wanted");
  1150. //Obtain the court and matchtype information
  1151. $rquery = "SELECT courts.courtname, matchtype.name, reservations.time, courts.courtid
  1152. FROM tblMatchType matchtype, tblCourts courts, tblReservations reservations
  1153. WHERE reservations.reservationid=$resid
  1154. AND reservations.courtid = courts.courtid
  1155. AND matchtype.id = reservations.matchtype";
  1156. $rresult = db_query($rquery);
  1157. $robj = my

Large files files are truncated, but you can click here to view the full file