2
0

event.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 = core::base64_url_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 getInscription(int $_id_event){
  175. db::query("SELECT "
  176. . "" . DB_T_SALARIES . ".id, "
  177. . "" . DB_T_SALARIES . ".loginId, "
  178. . "" . DB_T_SALARIES . ".nom, "
  179. . "" . DB_T_SALARIES . ".prenom, "
  180. . "" . DB_T_SALARIES . ".sexe, "
  181. . "" . DB_T_SALARIES . ".contrat, "
  182. . "" . DB_T_SALARIES . ".lieu, "
  183. . "" . DB_T_SALARIES . ".actif, "
  184. . "" . DB_T_EVENTS_INSCRITS . ".id_evenement, "
  185. . "" . DB_T_EVENTS_INSCRITS . ".present "
  186. . "FROM " . DB_T_SALARIES . " "
  187. . "INNER JOIN " . DB_T_EVENTS_INSCRITS . " ON " . DB_T_EVENTS_INSCRITS . ".id_salarie = " . DB_T_SALARIES . ".id "
  188. . "WHERE " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . $_id_event);
  189. return db::resultset();
  190. }
  191. public static function checkEvenementBySalarie(string $_md5)
  192. {
  193. $return = array();
  194. $now = time();
  195. db::query("SELECT "
  196. . "" . DB_T_SALARIES . ".id, "
  197. . "" . DB_T_SALARIES . ".actif, "
  198. . "" . DB_T_SALARIES . ".contrat "
  199. . "FROM " . DB_T_SALARIES . " "
  200. . "WHERE " . DB_T_SALARIES . ".id = :id");
  201. db::bind(':id', session::getId("salarie"));
  202. $salarie = db::single();
  203. db::query("SELECT "
  204. . "" . DB_T_EVENTS_INSCRITS . ".id_salarie, "
  205. . "" . DB_T_EVENTS_INSCRITS . ".present "
  206. . "FROM " . DB_T_EVENTS . " "
  207. . "LEFT JOIN " . DB_T_EVENTS_INSCRITS . " ON " . DB_T_EVENTS_INSCRITS . ".id_evenement = " . DB_T_EVENTS . ".id "
  208. . "WHERE " . DB_T_EVENTS_INSCRITS . ".id_salarie = :id_salarie AND " . DB_T_EVENTS . ".md5 = :md5");
  209. db::bind(':id_salarie', session::getId("salarie"));
  210. db::bind(':md5', $_md5);
  211. $inscription = db::single();
  212. db::query("SELECT "
  213. . "" . DB_T_EVENTS . ".id, "
  214. . "" . DB_T_EVENTS . ".md5, "
  215. . "" . DB_T_EVENTS . ".titre, "
  216. . "" . DB_T_EVENTS . ".startDate, "
  217. . "" . DB_T_EVENTS . ".endDate, "
  218. . "" . DB_T_EVENTS . ".type_emargement, "
  219. . "" . DB_T_EVENTS . ".type_inscription, "
  220. . "" . DB_T_EVENTS . ".actif "
  221. . "FROM " . DB_T_EVENTS . " "
  222. . "WHERE " . DB_T_EVENTS . ".md5 = :md5");
  223. db::bind(':md5', $_md5);
  224. $evenement = db::single();
  225. // print_r($inscription); echo "<br />";
  226. // print_r($evenement); echo "<br />";
  227. if ($salarie["id"] == NULL) {
  228. $return["result"] = FALSE;
  229. $return["description"] = "Vous n'êtes pas un salarié rattaché à notre CSE";
  230. } elseif ($salarie["actif"] == 0) {
  231. $return["result"] = FALSE;
  232. $return["description"] = "Vous n'êtes plus un salarié rattaché à notre CSE";
  233. } elseif ($evenement["actif"] == 0) {
  234. $return["result"] = FALSE;
  235. $return["description"] = "Cet évènement n'est pas activée";
  236. } elseif ($evenement["type_inscription"] == 1 and $inscription["id_salarie"] == NULL) {
  237. $return["result"] = FALSE;
  238. $return["description"] = "Vous n'êtes pas inscrit à cet évènement";
  239. } elseif ($now < strtotime($evenement["startDate"])) {
  240. $return["result"] = FALSE;
  241. $return["description"] = "Cet évènement n'a pas encore commencé";
  242. } elseif ($now > (strtotime($evenement["endDate"]) + EMEMARGEMENT_END)) {
  243. $return["result"] = FALSE;
  244. $return["description"] = "Cet évènement est terminé";
  245. } elseif (isset($inscription["present"])) {
  246. $return["result"] = FALSE;
  247. $return["description"] = "Votre émargement a déjà été pris en compte<br />le " . core::convertDate($inscription["present"]);
  248. } else {
  249. $return["result"] = TRUE;
  250. $return["description"] = "Votre émargement a été pris en compte";
  251. }
  252. $return["evenement"] = $evenement["titre"];
  253. return $return;
  254. }
  255. public static function emargementEvenement(int $_idEvenement, int $_idSalarie)
  256. {
  257. $inscription = self::getInscriptionEvenementById($_idEvenement, $_idSalarie);
  258. $evenement = self::getFiche($_idEvenement);
  259. if (!isset($inscription["present"]) or empty($inscription["present"])) {
  260. if (isset($inscription["id_salarie"])) {
  261. db::query("UPDATE " . DB_T_EVENTS_INSCRITS . " SET present = CURRENT_TIMESTAMP() WHERE id_evenement = :id_evenement AND id_salarie = :id_salarie");
  262. db::bind(':id_evenement', $_idEvenement);
  263. db::bind(':id_salarie', $_idSalarie);
  264. db::execute();
  265. $return["result"] = TRUE;
  266. $return["evenement"] = $evenement["titre"];
  267. $return["description"] = "L'émargement a été pris en compte";
  268. } else {
  269. db::query("INSERT INTO " . DB_T_EVENTS_INSCRITS . " (id_evenement, id_salarie, present) "
  270. . "VALUES (:id_evenement, :id_salarie, CURRENT_TIMESTAMP())");
  271. db::bind(':id_evenement', $_idEvenement);
  272. db::bind(':id_salarie', $_idSalarie);
  273. db::execute();
  274. $return["result"] = TRUE;
  275. $return["evenement"] = $evenement["titre"];
  276. $return["description"] = "L'émargement a été pris en compte";
  277. }
  278. } else {
  279. $return["result"] = FALSE;
  280. $return["description"] = "Emargement déjà pris en compte le " . core::convertDate($inscription["present"]);
  281. }
  282. return $return;
  283. }
  284. public static function emargementEvenementByQRCode()
  285. {
  286. $idSalarie = core::getGet("s");
  287. $md5Evenement = core::getGet("e");
  288. $key = core::getGet("k");
  289. $salarie = salaries::get_salarieById($idSalarie);
  290. $constructKey = md5($md5Evenement . $salarie["sel"]);
  291. if ($constructKey == $key) {
  292. $checkEmarge = self::emargementEvenement(self::getIdEvenementByMd5($md5Evenement), $salarie["id"]);
  293. return $checkEmarge;
  294. } else {
  295. $return["result"] = FALSE;
  296. $return["description"] = "Le QR-Code n'est pas valide";
  297. return $return;
  298. }
  299. }
  300. public static function printEventBouton(array $_array)
  301. {
  302. switch ($_array["nb"]) {
  303. case 0:
  304. $class_fadeIn = "first";
  305. break;
  306. case 1:
  307. $class_fadeIn = "second";
  308. break;
  309. case 2:
  310. $class_fadeIn = "third";
  311. break;
  312. case 3:
  313. $class_fadeIn = "fourth";
  314. break;
  315. default:
  316. $class_fadeIn = "fifth";
  317. break;
  318. }
  319. if ($_array["type_emargement"] == 1) {
  320. $explication = '<p class="card-text">
  321. <div>[ QRCode à présenter à votre arrivée ]</div>
  322. <br />
  323. <div><span data-feather="maximize"></span></div>
  324. </p>';
  325. $meta = 'data-toggle="modal" data-target="#QRCodeModal" data-qrr-qrcode-regexp="^https?:\/\/" data-sel="' . $_array["url_qrcode"] . '" data-titre="' . $_array["titre"] . '"';
  326. $class_card = 'showQRCode';
  327. $txt["footer"] = "Cliquez ici pour afficher votre QRCode";
  328. } else {
  329. $explication = '<p class="card-text">
  330. <div>[ QRCode à flasher vous même ]</div>
  331. <br />
  332. <div><span data-feather="camera"></span></div>
  333. </p>';
  334. $meta = 'data-event="' . $_array["md5"] . '" data-qrr-target="#QRCodeRead" ';
  335. $class_card = 'qrcodeReader';
  336. $txt["footer"] = "Cliquez ici pour scanner le QRCode";
  337. }
  338. if (isset($_array["present"])) {
  339. $meta = "";
  340. $explication = '<p class="card-text">Votre émargement a bien été pris en compte</p>';
  341. $class["card-text"] = "text-success";
  342. $class["card"] = "";
  343. $txt["footer"] = "Emargement réalisé le " . core::convertDate($_array["present"]);
  344. } else {
  345. $class["card-text"] = "text-dark";
  346. $class["card"] = $class_card;
  347. }
  348. echo ' <div ' . $meta . ' class="card mb-3 text-center ' . $class["card"] . ' ' . $class["card-text"] . ' fadeIn ' . $class_fadeIn . '">
  349. <div class="card-header"><small>Du ' . core::convertDate($_array["startDate"]) . ' au ' . core::convertDate($_array["endDate"]) . '</small></div>
  350. <div class="card-body">
  351. <h5 class="card-title">' . $_array["titre"] . '</h5>
  352. ' . $explication . '
  353. </div>
  354. <div class="card-footer"><small>' . $txt["footer"] . '</small></div>
  355. </div>';
  356. }
  357. public static function printIconeResultFlash(string $_result)
  358. {
  359. if ($_result == 1) {
  360. echo ' <div class="swal2-icon swal2-success swal2-animate-success-icon" style="display: flex;">
  361. <div class="swal2-success-circular-line-left" style="background-color: rgb(255, 255, 255);"></div>
  362. <span class="swal2-success-line-tip"></span>
  363. <span class="swal2-success-line-long"></span>
  364. <div class="swal2-success-ring"></div>
  365. <div class="swal2-success-fix" style="background-color: rgb(255, 255, 255);"></div>
  366. <div class="swal2-success-circular-line-right" style="background-color: rgb(255, 255, 255);"></div>
  367. </div>';
  368. } else {
  369. echo ' <div class="swal2-icon swal2-error swal2-animate-error-icon" style="display: flex;">
  370. <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>
  371. </div>';
  372. }
  373. }
  374. }