2
0

event.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. class event
  3. {
  4. public static function getFiche(int $_id)
  5. {
  6. db::query("SELECT * FROM " . DB_T_EVENTS . " WHERE id = :id");
  7. db::bind(':id', $_id);
  8. return db::single();
  9. }
  10. public static function getFicheByMd5(string $_md5)
  11. {
  12. db::query("SELECT * FROM " . DB_T_EVENTS . " WHERE md5 = :md5");
  13. db::bind(':md5', $_md5);
  14. return db::single();
  15. }
  16. public static function getQRCode(int $_id, $_width = 50, string $_link = NULL)
  17. {
  18. db::query("SELECT md5 FROM " . DB_T_EVENTS . " WHERE id = :id");
  19. db::bind(':id', $_id);
  20. $md5 = db::single()["md5"];
  21. $link = base64_encode("https://" . DOMAIN_EVENTS . "/?e=" . $md5);
  22. if ($_link == NULL) {
  23. echo '<img src="/qrcode.php?q= ' . $link . '" width="' . $_width . '" >';
  24. } else {
  25. echo '<a href="https://' . DOMAIN_EVENTS . '/qrcode.php?q=' . $link . '" target="_blank"><img src="/qrcode.php?q= ' . $link . '" width="' . $_width . '" ></a>';
  26. }
  27. }
  28. public static function getEvents()
  29. {
  30. db::query("SELECT "
  31. . "" . DB_T_EVENTS . ".id, "
  32. . "" . DB_T_EVENTS . ".md5, "
  33. . "" . DB_T_EVENTS . ".titre, "
  34. . "" . DB_T_EVENTS . ".description, "
  35. . "" . DB_T_EVENTS . ".startDate, "
  36. . "COUNT(" . DB_T_EVENTS_INSCRITS . ".id_salarie) AS m_global, "
  37. . "COUNT(" . DB_T_EVENTS_INSCRITS . ".present) AS m_inscrit, "
  38. . "" . DB_T_EVENTS . ".endDate, "
  39. . "IF(" . DB_T_EVENTS . ".type_emargement = 1, 'Contôle', IF(" . DB_T_EVENTS . ".type_emargement = 2, 'Autonome', 'Contrôle & Autonome')) AS type_emargement, "
  40. . "IF(" . DB_T_EVENTS . ".type_inscription = 1, 'Incription', 'Libre') AS type_inscription, "
  41. . "" . DB_T_EVENTS . ".actif, "
  42. . "" . DB_T_EVENTS . ".cree, "
  43. . "" . DB_T_EVENTS . ".maj, "
  44. . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' "
  45. . "FROM " . DB_T_EVENTS . " "
  46. . "LEFT JOIN " . DB_T_EVENTS_INSCRITS . " ON " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . DB_T_EVENTS . ".id "
  47. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_EVENTS . ".id_user = " . DB_T_USER . ".id "
  48. . "GROUP BY 1");
  49. return db::resultset();
  50. }
  51. public static function connectSalarie(array $_post)
  52. {
  53. if (empty($_post["ident"])) {
  54. return FALSE;
  55. } elseif (empty($_post["date"])) {
  56. return FALSE;
  57. }
  58. if (is_int($_post["ident"])) {
  59. $login = intval($_post["ident"]);
  60. } else {
  61. $login = $_post["ident"];
  62. }
  63. $date = new DateTime($_post["date"]);
  64. $date = $date->format('Y-m-d H:i:s');
  65. db::query("SELECT "
  66. . "id, "
  67. . "sel, "
  68. . "nom, "
  69. . "prenom, "
  70. . "actif, "
  71. . "contrat, "
  72. . "jourEntree "
  73. . "FROM " . DB_T_SALARIES . " "
  74. . "WHERE loginId = :login OR idLocal = :login");
  75. db::bind(':login', $login);
  76. $salarie = db::single();
  77. if (isset($salarie["id"])) {
  78. if ($salarie["actif"] == 0) {
  79. return FALSE;
  80. } elseif ($salarie["jourEntree"] != $date) {
  81. return FALSE;
  82. } else {
  83. $_SESSION["salarie"] = array(
  84. "id" => $salarie["id"],
  85. "sel" => $salarie["sel"],
  86. "nom" => $salarie["nom"],
  87. "prenom" => $salarie["prenom"]
  88. );
  89. return TRUE;
  90. }
  91. } else {
  92. return FALSE;
  93. }
  94. return FALSE;
  95. }
  96. public static function lastEvenement()
  97. {
  98. db::query("SELECT MAX(id) AS id FROM " . DB_T_EVENTS);
  99. return db::single()["id"];
  100. }
  101. public static function getIdEvenementByMd5(string $_md5)
  102. {
  103. db::query("SELECT id FROM " . DB_T_EVENTS . " WHERE md5 = :md5");
  104. db::bind(':md5', $_md5);
  105. return db::single()["id"];
  106. }
  107. public static function presentEvenement(int $_idSalarie)
  108. {
  109. db::query("SELECT "
  110. . "" . DB_T_EVENTS . ".id, "
  111. . "" . DB_T_EVENTS . ".md5, "
  112. . "" . DB_T_EVENTS . ".titre, "
  113. . "" . DB_T_EVENTS . ".startDate, "
  114. . "" . DB_T_EVENTS . ".endDate, "
  115. . "" . DB_T_EVENTS . ".type_emargement, "
  116. . "" . DB_T_EVENTS_INSCRITS . ".sel, "
  117. . "" . DB_T_EVENTS_INSCRITS . ".present "
  118. . "FROM " . DB_T_EVENTS . " "
  119. . "LEFT JOIN " . DB_T_EVENTS_INSCRITS . " ON " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . DB_T_EVENTS . ".id AND " . DB_T_EVENTS_INSCRITS . ".id_salarie = :id_salarie "
  120. . "WHERE " . DB_T_EVENTS . ".startDate <= CURRENT_TIMESTAMP() "
  121. . "AND " . DB_T_EVENTS . ".endDate >= CURRENT_TIMESTAMP() "
  122. . "AND ((" . DB_T_EVENTS . ".type_inscription = 1 AND " . DB_T_EVENTS_INSCRITS . ".id_salarie = :id_salarie) OR (" . DB_T_EVENTS . ".type_inscription = 0))"
  123. . "AND " . DB_T_EVENTS . ".actif = 1");
  124. db::bind(':id_salarie', $_idSalarie);
  125. $row = db::resultset();
  126. return $row;
  127. }
  128. public static function deleteEvenement(int $_id)
  129. {
  130. db::query("DELETE FROM " . DB_T_EVENTS . " WHERE id = :id");
  131. db::bind(':id', $_id);
  132. return db::execute();
  133. }
  134. public static function deleteInscriptionEvenement(int $_idEvenement)
  135. {
  136. db::query("DELETE FROM " . DB_T_EVENTS_INSCRITS . " WHERE id_evenement = :id_evenement");
  137. db::bind(':id_evenement', $_idEvenement);
  138. return db::execute();
  139. }
  140. public static function checkUrl(string $_url)
  141. {
  142. return parse_url($_url)["host"];
  143. }
  144. public static function getEvenementbyQRCode(string $_QRCode)
  145. {
  146. $query = parse_url($_QRCode)["query"];
  147. parse_str($query, $params);
  148. return $params;
  149. }
  150. public static function checkEmargement(int $_id_evenement)
  151. {
  152. db::query("SELECT "
  153. . "COUNT(present) AS nb "
  154. . "FROM " . DB_T_EVENTS_INSCRITS . " "
  155. . "WHERE " . DB_T_EVENTS_INSCRITS . ".id_evenement = :id_evenement");
  156. db::bind(':id_evenement', $_id_evenement);
  157. $nb = db::single()["nb"];
  158. return $nb;
  159. }
  160. public static function getInscriptionEvenementById(int $_id_evenement, int $_id_salarie)
  161. {
  162. db::query("SELECT "
  163. . "" . DB_T_EVENTS_INSCRITS . ".id_salarie, "
  164. . "" . DB_T_EVENTS_INSCRITS . ".present, "
  165. . "" . DB_T_EVENTS . ".titre "
  166. . "FROM " . DB_T_EVENTS_INSCRITS . " "
  167. . "INNER JOIN " . DB_T_EVENTS . " ON " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . DB_T_EVENTS . ".id "
  168. . "WHERE " . DB_T_EVENTS_INSCRITS . ".id_salarie = :id_salarie AND " . DB_T_EVENTS_INSCRITS . ".id_evenement = :id_evenement");
  169. db::bind(':id_salarie', $_id_salarie);
  170. db::bind(':id_evenement', $_id_evenement);
  171. $inscription = db::single();
  172. return $inscription;
  173. }
  174. public static function checkEvenementBySalarie(string $_md5)
  175. {
  176. $return = array();
  177. $now = time();
  178. db::query("SELECT "
  179. . "" . DB_T_SALARIES . ".id, "
  180. . "" . DB_T_SALARIES . ".actif, "
  181. . "" . DB_T_SALARIES . ".contrat "
  182. . "FROM " . DB_T_SALARIES . " "
  183. . "WHERE " . DB_T_SALARIES . ".id = :id");
  184. db::bind(':id', session::getId("salarie"));
  185. $salarie = db::single();
  186. db::query("SELECT "
  187. . "" . DB_T_EVENTS_INSCRITS . ".id_salarie, "
  188. . "" . DB_T_EVENTS_INSCRITS . ".present "
  189. . "FROM " . DB_T_EVENTS . " "
  190. . "LEFT JOIN " . DB_T_EVENTS_INSCRITS . " ON " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . DB_T_EVENTS . ".id "
  191. . "WHERE " . DB_T_EVENTS_INSCRITS . ".id_salarie = :id_salarie AND " . DB_T_EVENTS . ".md5 = :md5");
  192. db::bind(':id_salarie', session::getId("salarie"));
  193. db::bind(':md5', $_md5);
  194. $inscription = db::single();
  195. db::query("SELECT "
  196. . "" . DB_T_EVENTS . ".id, "
  197. . "" . DB_T_EVENTS . ".md5, "
  198. . "" . DB_T_EVENTS . ".titre, "
  199. . "" . DB_T_EVENTS . ".startDate, "
  200. . "" . DB_T_EVENTS . ".endDate, "
  201. . "" . DB_T_EVENTS . ".type_emargement, "
  202. . "" . DB_T_EVENTS . ".type_inscription, "
  203. . "" . DB_T_EVENTS . ".actif "
  204. . "FROM " . DB_T_EVENTS . " "
  205. . "WHERE " . DB_T_EVENTS . ".md5 = :md5");
  206. db::bind(':md5', $_md5);
  207. $evenement = db::single();
  208. // print_r($inscription); echo "<br />";
  209. // print_r($evenement); echo "<br />";
  210. if ($salarie["id"] == NULL) {
  211. $return["result"] = FALSE;
  212. $return["description"] = "Vous n'êtes pas un salarié rattaché à notre CSE";
  213. } elseif ($salarie["actif"] == 0) {
  214. $return["result"] = FALSE;
  215. $return["description"] = "Vous n'êtes plus un salarié rattaché à notre CSE";
  216. } elseif ($evenement["actif"] == 0) {
  217. $return["result"] = FALSE;
  218. $return["description"] = "Cet évènement n'est pas activée";
  219. } elseif ($evenement["type_inscription"] == 1 and $inscription["id_salarie"] == NULL) {
  220. $return["result"] = FALSE;
  221. $return["description"] = "Vous n'êtes pas inscrit à cet évènement";
  222. } elseif ($now < strtotime($evenement["startDate"])) {
  223. $return["result"] = FALSE;
  224. $return["description"] = "Cet évènement n'a pas encore commencé";
  225. } elseif ($now > (strtotime($evenement["endDate"]) + EMEMARGEMENT_END)) {
  226. $return["result"] = FALSE;
  227. $return["description"] = "Cet évènement est terminé";
  228. } elseif (isset($inscription["present"])) {
  229. $return["result"] = FALSE;
  230. $return["description"] = "Votre émargement a déjà été pris en compte<br />le " . core::convertDate($inscription["present"]);
  231. } else {
  232. $return["result"] = TRUE;
  233. $return["description"] = "Votre émargement a été pris en compte";
  234. }
  235. $return["evenement"] = $evenement["titre"];
  236. return $return;
  237. }
  238. public static function emargementEvenement(int $_idEvenement, int $_idSalarie)
  239. {
  240. $inscription = self::getInscriptionEvenementById($_idEvenement, $_idSalarie);
  241. $evenement = self::getFiche($_idEvenement);
  242. if (!isset($inscription["present"]) or empty($inscription["present"])) {
  243. if (isset($inscription["id_salarie"])) {
  244. db::query("UPDATE " . DB_T_EVENTS_INSCRITS . " SET present = CURRENT_TIMESTAMP() WHERE id_evenement = :id_evenement AND id_salarie = :id_salarie");
  245. db::bind(':id_evenement', $_idEvenement);
  246. db::bind(':id_salarie', $_idSalarie);
  247. db::execute();
  248. $return["result"] = TRUE;
  249. $return["evenement"] = $evenement["titre"];
  250. $return["description"] = "L'émargement a été pris en compte";
  251. } else {
  252. db::query("INSERT INTO " . DB_T_EVENTS_INSCRITS . " (id_evenement, id_salarie, present) "
  253. . "VALUES (:id_evenement, :id_salarie, CURRENT_TIMESTAMP())");
  254. db::bind(':id_evenement', $_idEvenement);
  255. db::bind(':id_salarie', $_idSalarie);
  256. db::execute();
  257. $return["result"] = TRUE;
  258. $return["evenement"] = $evenement["titre"];
  259. $return["description"] = "L'émargement a été pris en compte";
  260. }
  261. } else {
  262. $return["result"] = FALSE;
  263. $return["description"] = "Emargement déjà pris en compte le " . core::convertDate($inscription["present"]);
  264. }
  265. return $return;
  266. }
  267. public static function emargementEvenementByQRCode()
  268. {
  269. $idSalarie = core::getGet("s");
  270. $md5Evenement = core::getGet("e");
  271. $key = core::getGet("k");
  272. $salarie = salaries::get_salarieById($idSalarie);
  273. $constructKey = md5($md5Evenement . $salarie["sel"]);
  274. if ($constructKey == $key) {
  275. $checkEmarge = self::emargementEvenement(self::getIdEvenementByMd5($md5Evenement), $salarie["id"]);
  276. return $checkEmarge;
  277. } else {
  278. $return["result"] = FALSE;
  279. $return["description"] = "Le QR-Code n'est pas valide";
  280. return $return;
  281. }
  282. }
  283. public static function printEventBouton(array $_array)
  284. {
  285. switch ($_array["nb"]) {
  286. case 0:
  287. $class_fadeIn = "first";
  288. break;
  289. case 1:
  290. $class_fadeIn = "second";
  291. break;
  292. case 2:
  293. $class_fadeIn = "third";
  294. break;
  295. case 3:
  296. $class_fadeIn = "fourth";
  297. break;
  298. default:
  299. $class_fadeIn = "fifth";
  300. break;
  301. }
  302. if ($_array["type_emargement"] == 1) {
  303. $explication = '<p class="card-text">
  304. <div>[ QRCode à présenter à votre arrivée ]</div>
  305. <br />
  306. <div><span data-feather="maximize"></span></div>
  307. </p>';
  308. $meta = 'data-toggle="modal" data-target="#QRCodeModal" data-qrr-qrcode-regexp="^https?:\/\/" data-sel="' . $_array["url_qrcode"] . '" data-titre="' . $_array["titre"] . '"';
  309. $class_card = 'showQRCode';
  310. $txt["footer"] = "Cliquez ici pour afficher votre QRCode";
  311. } else {
  312. $explication = '<p class="card-text">
  313. <div>[ QRCode à flasher vous même ]</div>
  314. <br />
  315. <div><span data-feather="camera"></span></div>
  316. </p>';
  317. $meta = 'data-event="' . $_array["md5"] . '" data-qrr-target="#QRCodeRead" ';
  318. $class_card = 'qrcodeReader';
  319. $txt["footer"] = "Cliquez ici pour scanner le QRCode";
  320. }
  321. if (isset($_array["present"])) {
  322. $meta = "";
  323. $explication = '<p class="card-text">Votre émargement a bien été pris en compte</p>';
  324. $class["card-text"] = "text-success";
  325. $class["card"] = "";
  326. $txt["footer"] = "Emargement réalisé le " . core::convertDate($_array["present"]);
  327. } else {
  328. $class["card-text"] = "text-dark";
  329. $class["card"] = $class_card;
  330. }
  331. echo ' <div ' . $meta . ' class="card mb-3 text-center ' . $class["card"] . ' ' . $class["card-text"] . ' fadeIn ' . $class_fadeIn . '">
  332. <div class="card-header"><small>Du ' . core::convertDate($_array["startDate"]) . ' au ' . core::convertDate($_array["endDate"]) . '</small></div>
  333. <div class="card-body">
  334. <h5 class="card-title">' . $_array["titre"] . '</h5>
  335. ' . $explication . '
  336. </div>
  337. <div class="card-footer"><small>' . $txt["footer"] . '</small></div>
  338. </div>';
  339. }
  340. public static function printIconeResultFlash(string $_result)
  341. {
  342. if ($_result == 1) {
  343. echo ' <div class="swal2-icon swal2-success swal2-animate-success-icon" style="display: flex;">
  344. <div class="swal2-success-circular-line-left" style="background-color: rgb(255, 255, 255);"></div>
  345. <span class="swal2-success-line-tip"></span>
  346. <span class="swal2-success-line-long"></span>
  347. <div class="swal2-success-ring"></div>
  348. <div class="swal2-success-fix" style="background-color: rgb(255, 255, 255);"></div>
  349. <div class="swal2-success-circular-line-right" style="background-color: rgb(255, 255, 255);"></div>
  350. </div>';
  351. } else {
  352. echo ' <div class="swal2-icon swal2-error swal2-animate-error-icon" style="display: flex;">
  353. <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>
  354. </div>';
  355. }
  356. }
  357. }