2
0

proweb.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. class proweb
  3. {
  4. public static function getBase()
  5. {
  6. db::query("SELECT *,
  7. IF(contrat = 1, 'Actif', 'Désactivé') AS texteContrat,
  8. IF(actif = 1, 'Actif', 'Désactivé') AS texteActif,
  9. IF(RHBase = 1, 'Présent', 'Absent') AS texteRHBase,
  10. IF(error = 1, 'Erreur', 'Valide') AS texteError
  11. FROM " . DB_T_SALARIES_PROWEB);
  12. return db::resultset();
  13. }
  14. public static function getExcelById(int $_id)
  15. {
  16. db::query("SELECT * FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
  17. db::bind(':id', $_id);
  18. return db::single();
  19. }
  20. public static function deleteExcel(int $_id)
  21. {
  22. $tmp = self::getExcelById($_id);
  23. file::delete($tmp["md5"]);
  24. db::query("DELETE FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
  25. db::bind(':id', $_id);
  26. try {
  27. db::execute();
  28. return TRUE;
  29. } catch (Exception $ex) {
  30. return FALSE;
  31. }
  32. }
  33. public static function getExcel()
  34. {
  35. db::query("SELECT * FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1");
  36. return db::single();
  37. }
  38. public static function convertDateMoisAn(string $datetime)
  39. {
  40. $pieces = explode(" ", $datetime);
  41. $pieces2 = explode("-", $pieces[0]);
  42. return $pieces2[0] . $pieces2[1];
  43. }
  44. public static function convertDateMoisAnJour(string $datetime)
  45. {
  46. $pieces = explode(" ", $datetime);
  47. return $pieces[0];
  48. }
  49. public static function archiveExcelValues(array $_array)
  50. {
  51. $_return["error"] = 0;
  52. $_return["errorJson"] = array();
  53. // ----
  54. $_return["idProweb"] = $_array[0];
  55. $_return["nom"] = self::archiveExcelValuesNom($_array[1]);
  56. $_return["prenom"] = self::archiveExcelValuesPrenom($_array[2]);
  57. $_return["sexe"] = self::archiveExcelValuesSexe($_array[3]);
  58. $_return["dateNaissance"] = self::archiveExcelValuesDate($_array[4]);
  59. $_return["jourEntree"] = self::archiveExcelValuesDate($_array[5]);
  60. $_return["jourSortie"] = self::archiveExcelValuesDate($_array[6]);
  61. $_return["meyclubSubv"] = self::archiveExcelValuesActif($_array[7]);
  62. $_return["meyclubAccess"] = self::archiveExcelValuesActif($_array[8]);
  63. $_return["Webaccess"] = self::archiveExcelValuesActif($_array[9]);
  64. $_return["lieu"] = self::archiveExcelValuesLieu($_array[10]);
  65. $_return["loginId"] = self::archiveExcelValuesloginId($_array[11]);
  66. $verifRH = self::checksalarieByLoginId($_return["loginId"], $_return["nom"], $_return["prenom"]);
  67. if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
  68. $dateDataRH = intval(self::convertDateMoisAn(self::getExcel()["dateData"]));
  69. $dateDataProWeb = intval(self::convertDateMoisAn($_return["jourEntree"]));
  70. } else {
  71. $dateDataRH = $dateDataProWeb = 0;
  72. }
  73. if (empty($verifRH["id"]) and $_return["jourSortie"] == "N/A" and $dateDataRH > $dateDataProWeb) {
  74. $_return["contrat"] = $_return["actif"] = $_return["RHBase"] = $_return["loginIdRH"] = $_return["jourEntreeRH"] = "N/A";
  75. array_push($_return["errorJson"], "absent");
  76. } else {
  77. $_return["loginIdRH"] = (empty($verifRH["loginId"]) or $verifRH["loginId"] == $_return["loginId"]) ? NULL : $verifRH["loginId"];
  78. $_return["jourEntreeRH"] = (empty($verifRH["jourEntree"]) or self::convertDateMoisAnJour($verifRH["jourEntree"]) == $_return["jourEntree"]) ? NULL : self::convertDateMoisAnJour($verifRH["jourEntree"]);
  79. $_return["jourSortie"] = (isset($verifRH["jourSortie"])) ? $verifRH["jourSortie"] : $_return["jourSortie"];
  80. $_return["RHBase"] = (isset($verifRH["jourSortie"]) or empty($verifRH["id"])) ? 0 : 1;
  81. $_return["actif"] = ($_return["meyclubSubv"] == 1 or $_return["meyclubAccess"] == 1 or $_return["Webaccess"] == 1) ? 1 : 0;
  82. $_return["contrat"] = (isset($verifRH["contrat"])) ? $verifRH["contrat"] : 0;
  83. // ----
  84. if (!self::checkValuesNom($_return["nom"])) {
  85. $_return["error"] = 1;
  86. array_push($_return["errorJson"], "nom");
  87. }
  88. if (!self::checkValuesPrenom($_return["prenom"])) {
  89. $_return["error"] = 1;
  90. array_push($_return["errorJson"], "prenom");
  91. }
  92. if (!self::checkValuesloginId($_return["loginId"], $_return["loginIdRH"])) {
  93. $_return["error"] = 1;
  94. array_push($_return["errorJson"], "loginId");
  95. }
  96. if (!self::checkValuesNaissance($_return["dateNaissance"])) {
  97. $_return["error"] = 1;
  98. array_push($_return["errorJson"], "dateNaissance");
  99. }
  100. if (!self::checkValuesJourEntree($_return["jourEntree"])) {
  101. $_return["error"] = 1;
  102. array_push($_return["errorJson"], "jourEntree");
  103. }
  104. if ($_return["jourEntreeRH"] != NULL and $_return["jourEntree"] != "N/A") {
  105. $_return["error"] = 1;
  106. array_push($_return["errorJson"], "jourEntree");
  107. }
  108. if ($_return["jourSortie"] != "N/A" and $_return["RHBase"] == 1) {
  109. $_return["error"] = 1;
  110. array_push($_return["errorJson"], "jourSortie");
  111. }
  112. if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
  113. if ($dateDataRH > $dateDataProWeb) {
  114. if (!self::checkValuesRHBase($_return["RHBase"], $_return["actif"])) {
  115. $_return["error"] = 1;
  116. array_push($_return["errorJson"], "RHBase");
  117. }
  118. }
  119. }
  120. }
  121. $_return["errorJson"] = (!empty($_return["errorJson"][0])) ? json_encode($_return["errorJson"]) : NULL;
  122. return $_return;
  123. }
  124. // Les initialisations
  125. private static function archiveExcelValuesDate(string $_string)
  126. {
  127. if(!isset($_string) or $_string == "00-00-0000"){
  128. return "N/A";
  129. } else {
  130. return str_replace(" 00:00:00", "", $_string);
  131. }
  132. }
  133. private static function archiveExcelValuesSexe(string $_string)
  134. {
  135. return (empty($_string)) ? "N/A" : $_string;
  136. }
  137. private static function archiveExcelValuesloginId(string $_string)
  138. {
  139. return core::cleanAccent($_string);
  140. }
  141. private static function archiveExcelValuesNom(string $_string)
  142. {
  143. return core::cleanAccent($_string);
  144. }
  145. private static function archiveExcelValuesPrenom(string $_string)
  146. {
  147. return core::cleanAccent($_string);
  148. }
  149. private static function archiveExcelValuesActif(string $_string)
  150. {
  151. if ($_string == "O") {
  152. return 1;
  153. } elseif ($_string == "N") {
  154. return 0;
  155. } else {
  156. return "N/A";
  157. }
  158. }
  159. private static function archiveExcelValuesLieu(string $_string)
  160. {
  161. return (empty($_string)) ? "N/A" : $_string;
  162. }
  163. // Les checks
  164. public static function checkSalarieByLoginId(string $_loginId, string $_nom = NULL, string $_prenom = NULL)
  165. {
  166. // Récupération des données de l'excel au format Json
  167. if ($_nom == NULL) {
  168. db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId");
  169. } else {
  170. db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId OR (nom = :nom AND prenom = :prenom)");
  171. db::bind(':nom', $_nom);
  172. db::bind(':prenom', $_prenom);
  173. }
  174. db::bind(':loginId', $_loginId);
  175. return db::single();
  176. }
  177. private static function checkValuesActif(string $_string)
  178. {
  179. return ($_string == "N/A") ? FALSE : TRUE;
  180. }
  181. private static function checkValuesloginId(string $_idLogin, string $_idLoginRH = NULL)
  182. {
  183. if ($_idLoginRH != NULL) {
  184. if (empty(self::checkSalarieByLoginId($_idLogin)["id"])) {
  185. return FALSE;
  186. } elseif (core::checkStringOnly($_idLogin)) {
  187. return FALSE;
  188. } elseif (strlen($_idLogin) > 10) {
  189. return FALSE;
  190. } elseif (empty($_idLogin)) {
  191. return FALSE;
  192. } else {
  193. return TRUE;
  194. }
  195. } else {
  196. return TRUE;
  197. }
  198. }
  199. private static function checkValuesRHBase(int $_RH, int $_actif)
  200. {
  201. return ($_RH == 0 and $_actif == 1) ? FALSE : TRUE;
  202. }
  203. private static function checkValuesJourEntree(string $_string)
  204. {
  205. return ($_string == "N/A") ? FALSE : TRUE;
  206. }
  207. private static function checkValuesJourSortie(string $_string, int $_actif)
  208. {
  209. return ($_string != "N/A" and $_actif == 1) ? FALSE : TRUE;
  210. }
  211. private static function checkValuesNom(string $_string)
  212. {
  213. return (empty($_string)) ? FALSE : TRUE;
  214. }
  215. private static function checkValuesPrenom(string $_string)
  216. {
  217. return (empty($_string)) ? FALSE : TRUE;
  218. }
  219. private static function checkValuesSexe(string $_string)
  220. {
  221. return ($_string == NULL or ($_string != "M." and $_string != "Mme")) ? FALSE : TRUE;
  222. }
  223. private static function checkValuesLieu(string $_string)
  224. {
  225. return (empty($_string)) ? FALSE : TRUE;
  226. }
  227. private static function checkValuesNaissance(string $_string)
  228. {
  229. if(empty($_string) OR $_string == "N/A") {
  230. return FALSE;
  231. } elseif(self::calculAge($_string) > core::getConfig("AGE_MAX_ERROR")) {
  232. return FALSE;
  233. } else {
  234. return TRUE;
  235. }
  236. }
  237. private static function calculAge(string $_date)
  238. {
  239. $pieces = explode(" ", $_date);
  240. $birthDate = explode("-", $pieces[0]);
  241. return (date("md", date("U", mktime(0, 0, 0, $birthDate[2], $birthDate[1], $birthDate[0]))) > date("md")
  242. ? ((date("Y") - $birthDate[0]) - 1)
  243. : (date("Y") - $birthDate[0]));
  244. }
  245. public static function downloadExcel(int $_id, string $_file)
  246. {
  247. $data = base64_decode(self::getExcelById($_id)["file"]);
  248. $fileTemp = fopen(DIR_TEMP . $_file, "w");
  249. file_put_contents(DIR_TEMP . $_file, $data);
  250. fclose($fileTemp);
  251. return DIR_TEMP . $_file;
  252. }
  253. }