Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. <?php
  2.  
  3. require_once __DIR__.'/config.php';
  4.  
  5.  
  6. function countTotalEvent()
  7. {
  8. $total = db()->table('match_event')->select('count(*) as total');
  9.  
  10. $total = json_decode($total);
  11.  
  12. return $total[0]->total;
  13. }
  14.  
  15. function getGroupName($group_id) {
  16.  
  17. $condition = 'where id = ?';
  18. $queryParameterValue = array($group_id);
  19. $result = db()->table('groups')->select('name',$condition,$queryParameterValue);
  20.  
  21. $result = json_decode($result);
  22.  
  23. return $result[0]->name;
  24. }
  25.  
  26. function getGroupScoreByEvent($event_id,$group_id)
  27. {
  28. $condition = 'where match_event_id = ? AND group_id = ?';
  29. $queryParameterValue = array($event_id,$group_id);
  30. $result = db()->table('match_score')->select('score',$condition,$queryParameterValue);
  31.  
  32. $result = json_decode($result);
  33.  
  34. if (count($result) > 0) {
  35.  
  36. return $result[0]->score;
  37. }
  38. else {
  39.  
  40. return "No Score Found Yet";
  41. }
  42. }
  43.  
  44. function loginAdmin($username,$password)
  45. {
  46. $condition = 'where username = ? AND password = ?';
  47. $queryParameterValue = array($username,md5($password));
  48.  
  49. // First check if the record exist based on the given credential
  50. $checkIfExist = db()->table('users')->select('count(*) as total',$condition,$queryParameterValue);
  51. $checkIfExist = json_decode($checkIfExist);
  52.  
  53. if ($checkIfExist[0]->total > 0) {
  54.  
  55. //After we check the record exist, then we create the session and allow the admin to enter the system.
  56. $getAdminDetails = db()->table('users')->select('id,username,role',$condition,$queryParameterValue);
  57. $getAdminDetails = json_decode($getAdminDetails);
  58.  
  59. $_SESSION['admin'] = array(
  60. 'id' => $getAdminDetails[0]->id,
  61. 'username' => $getAdminDetails[0]->username,
  62. 'role' => $getAdminDetails[0]->role
  63. );
  64.  
  65. return true;
  66. }
  67. else {
  68.  
  69. return false;
  70. }
  71. }
  72.  
  73. function authenticate()
  74. {
  75. if (isset($_SESSION['admin'])) {
  76.  
  77. return true;
  78. }
  79. else {
  80.  
  81. header("Location: index.php");
  82. }
  83. }
  84.  
  85. function addNewGroup($name,$school_name)
  86. {
  87. $queryParameterValue = array($name,$school_name);
  88. $insert = db()->table('groups')->insert('name,school_name',$queryParameterValue);
  89.  
  90. if ($insert) {
  91.  
  92. return true;
  93. }
  94. else {
  95.  
  96. return false;
  97. }
  98. }
  99.  
  100. function getListGroups()
  101. {
  102. $listGroups = db()->table('groups')->select('id,name');
  103. $listGroups = json_decode($listGroups);
  104.  
  105. return $listGroups;
  106. }
  107.  
  108. function addNewParticipant($fullname,$group_id)
  109. {
  110. $queryParameterValue = array($fullname,$group_id);
  111. $insert = db()->table('users')->insert('fullname,group_id',$queryParameterValue);
  112.  
  113. if ($insert) {
  114.  
  115. return true;
  116. }
  117. else {
  118.  
  119. return false;
  120. }
  121. }
  122.  
  123.  
  124. //baru tambah
  125. function getAllListParticipant()
  126. {
  127. $condition = 'where role = student';
  128. $queryParameterValue = array($fullname,$group_id);
  129. $result = db()->table('users')->select('fullname','group_id',$condition,$queryParameterValue);
  130. $result=json_decode($result);
  131.  
  132. return $result;
  133. }
  134.  
  135. function addNewEventMatch($date_match,$home_group_id,$away_group_id,$name)
  136. {
  137. $queryParameterValue = array($home_group_id,$away_group_id,$date_match,$name);
  138.  
  139. $checkIfEventNameExist = db()->table('match_event')->select('count(*) as total','where name = ? limit 1',array($name));
  140. $checkIfEventNameExist = json_decode($checkIfEventNameExist);
  141.  
  142. if ($checkIfEventNameExist[0]->total > 0) {
  143.  
  144. return false;
  145. }
  146. else {
  147.  
  148. $insert = db()->table('match_event')->insert('home_group_id,away_group_id,date_match,name',$queryParameterValue);
  149.  
  150. if ($insert) {
  151.  
  152. return true;
  153. }
  154. else {
  155.  
  156. return false;
  157. }
  158. }
  159. }
  160.  
  161. function getListEventMatch()
  162. {
  163. $listAllMatchEvent = db()->table('match_event')->select('id,name');
  164. $listAllMatchEvent = json_decode($listAllMatchEvent);
  165.  
  166. return $listAllMatchEvent;
  167. }
  168.  
  169. function getEventMatchName($match_event_id)
  170. {
  171. $condition = 'where id = ?';
  172. $queryParameterValue = array($match_event_id);
  173. $matchEventName = db()->table('match_event')->select('name',$condition,$queryParameterValue);
  174. $matchEventName = json_decode($matchEventName);
  175.  
  176. return $matchEventName[0]->name;
  177. }
  178.  
  179. function addNewEventMatchScore($match_event_id,$group_id,$score)
  180. {
  181. $queryParameterValue = array($match_event_id,$group_id,$score);
  182. $insert = db()->table('match_score')->insert('match_event_id,group_id,score',$queryParameterValue);
  183.  
  184. if ($insert) {
  185.  
  186. return true;
  187. }
  188. else {
  189.  
  190. return false;
  191. }
  192. }
  193.  
  194. function getListEventMatchScore()
  195. {
  196. $listAllMatchEventScore = db()->table('match_score')->select('id,match_event_id,group_id');
  197. $listAllMatchEventScore = json_decode($listAllMatchEventScore);
  198.  
  199. $temp = array();
  200.  
  201. foreach ($listAllMatchEventScore as $key => $value) {
  202.  
  203. $temp[] = (object) array(
  204. 'id' => $listAllMatchEventScore[$key]->id,
  205. 'name' => getEventMatchName($listAllMatchEventScore[$key]->match_event_id)." ( ".getGroupName($listAllMatchEventScore[$key]->group_id)." )"
  206. );
  207. }
  208.  
  209. return $temp;
  210. }
  211.  
  212. function getDetailsEventMatchScoreByID($id)
  213. {
  214. $condition = 'where id = ? limit 1';
  215. $queryParameterValue = array($id);
  216. $result = db()->table('match_score')->select('id,match_event_id,group_id,score',$condition,$queryParameterValue);
  217. $result = json_decode($result);
  218.  
  219. return $result[0];
  220. }
  221.  
  222. function updateEventMatchScore($match_score_id,$match_event_id,$group_id,$score)
  223. {
  224. $condition = 'where id = ?';
  225. $queryParameterValue = array($match_event_id,$group_id,$score,$match_score_id);
  226. $update = db()->table('match_score')->update('match_event_id = ?,group_id = ?,score = ?',$condition,$queryParameterValue);
  227.  
  228. if ($update) {
  229.  
  230. return true;
  231. }
  232. else {
  233.  
  234. return false;
  235. }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement