Advertisement
Guest User

Action import_students da classe Event.php

a guest
Aug 22nd, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.57 KB | None | 0 0
  1. public function action_import_students($idEvent)
  2. {
  3. try {
  4. $data["idEvent"] = $idEvent;
  5. $data["pageTitle"] = "Importar alunos";
  6. $data["header"]["title"] = SITE_NAME . $data["pageTitle"];
  7. $data["header"]["menuSide"] = array(
  8. "header" => array(
  9. "user-img" => STATIC_URL . "images/" . Session::get("user-img"),
  10. "user-name" => Session::get("user-name"),
  11. "user-office" => Session::get("user-office")
  12. ),
  13. array(
  14. "dashboard" => ADM_URL
  15. ),
  16. array(
  17. "Alunos" => array(
  18. "class-icon" => ICON_LEADER,
  19. "url" => ADM_URL . "aluno",
  20. "scd-level" => array(
  21. "Novo" => ADM_URL . "aluno/novo",
  22. "Listar" => ADM_URL . "aluno/listar"
  23. )
  24. )
  25. ),
  26. array(
  27. "Produtos" => array(
  28. "class-icon" => ICON_PRODUCT,
  29. "url" => ADM_URL . "produto",
  30. "scd-level" => array(
  31. "Novo" => ADM_URL . "produto/novo",
  32. "Listar" => ADM_URL . "produto/listar"
  33. )
  34. )
  35. ),
  36. array(
  37. "Análises" => array(
  38. "class-icon" => ICON_ANALYSIS,
  39. "url" => ADM_URL . "analise",
  40. "scd-level" => array(
  41. "Novo" => ADM_URL . "analise/novo",
  42. "Listar" => ADM_URL . "analise/listar"
  43. )
  44. )
  45. ),
  46. array(
  47. "Competências" => array(
  48. "class-icon" => ICON_SKILL,
  49. "url" => ADM_URL . "competencia",
  50. "scd-level" => array(
  51. "Novo" => ADM_URL . "competencia/novo",
  52. "Listar" => ADM_URL . "competencia/listar"
  53. )
  54. )
  55. ),
  56. array(
  57. "Eventos" => array(
  58. "class-icon" => ICON_EVENT,
  59. "url" => ADM_URL . "evento",
  60. "scd-level%in" => array(
  61. "Novo" => ADM_URL . "evento/novo",
  62. "Listar" => ADM_URL . "evento/listar"
  63. )
  64. )
  65. ),
  66. array(
  67. "Inscrições" => array(
  68. "class-icon" => ICON_INSCRIPTION,
  69. "url" => ADM_URL . "inscricao",
  70. "scd-level" => array(
  71. "Pendentes" => ADM_URL . "inscricao/listar/pendentes",
  72. "Ativas" => ADM_URL . "inscricao/listar/ativas",
  73. "Finalizadas" => ADM_URL . "inscricao/listar/finalizadas"
  74. )
  75. )
  76. ),
  77. array(
  78. "Questões Objetivas" => array(
  79. "class-icon" => ICON_OBJQ,
  80. "url" => ADM_URL . "questao-objetiva",
  81. "scd-level" => array(
  82. "Novo" => ADM_URL . "questao-objetiva/novo",
  83. "Listar" => ADM_URL . "questao-objetiva/listar"
  84. )
  85. )
  86. ),
  87. array(
  88. "Questões Subjetivas" => array(
  89. "class-icon" => ICON_SBJQ,
  90. "url" => ADM_URL . "questao-subjetiva",
  91. "scd-level" => array(
  92. "Novo" => ADM_URL . "questao-subjetiva/novo",
  93. "Listar" => ADM_URL . "questao-subjetiva/listar"
  94. )
  95. )
  96. ),
  97. array(
  98. "Usuários" => array(
  99. "class-icon" => ICON_USER,
  100. "url" => ADM_URL . "usuario",
  101. "scd-level" => array(
  102. "Novo" => ADM_URL . "usuario/novo",
  103. "Listar" => ADM_URL . "usuario/listar"
  104. )
  105. )
  106. )
  107. );
  108.  
  109. $data["header"]["menuTop"] = array(
  110. "user-name" => Session::get("user-name")
  111. );
  112.  
  113. $data["header"]["moduleTitle"] = "Eventos";
  114.  
  115. $data["header"]["breadcrumbs"] = array(
  116. "Home" => ADM_URL,
  117. "Evento" => ADM_URL . "evento/editar/" . $idEvent,
  118. "Importar Alunos%active" => null
  119. );
  120.  
  121. if (Common::isEmpty($idEvent)) {
  122. Common::redir("gestor/evento/listar");
  123. }
  124.  
  125. if ((isset($_FILES) && !Common::isEmpty($_FILES)) && (isset($_POST) && !Common::isEmpty($_POST))) {
  126. set_time_limit(0);
  127.  
  128. $rset = $this->event->getById($idEvent);
  129.  
  130. if ($rset["ativo"] == "0") {
  131. throw new \Exception("Não é possível fazer inscrições ou importações de alunos em eventos desativados.");
  132. }
  133.  
  134. if (Common::isEmpty($_FILES["inscriptions"]["tmp_name"])) {
  135. throw new \Exception("Por favor, faça upload de algum arquivo.");
  136. }
  137.  
  138. $file = $_FILES["inscriptions"];
  139. $filenameEx = explode(".", $file["name"]);
  140.  
  141. $ext = $filenameEx[1];
  142.  
  143. if ($ext !== "csv") {
  144. throw new \Exception("O arquivo não possui um formato (extensão) aceito pelo sistema.");
  145. }
  146.  
  147. $tmpName = $_FILES['inscriptions']['tmp_name'];
  148.  
  149. $fileToStr = file_get_contents($tmpName);
  150.  
  151. $csv = explode(PHP_EOL, $fileToStr);
  152.  
  153. $count = (count($csv) - 1);
  154.  
  155. foreach ($csv as $pos => $line) {
  156. if ($pos == $count) {
  157. unset($csv[$pos]);
  158.  
  159. break;
  160. }
  161.  
  162. if ($pos == 0) {
  163. if (strstr($line, ',')) {
  164. $delimiter = ",";
  165. } elseif (strstr($line, ';')) {
  166. $delimiter = ";";
  167. }
  168. }
  169.  
  170. $csv[$pos] = explode($delimiter, $line);
  171. }
  172.  
  173. $spreadsheetType = $_POST["type"];
  174.  
  175. switch ($spreadsheetType) {
  176. case 2:{
  177. $addedUpColumnsLeader = array();
  178. $addedUpColumnsInscription = array(
  179. "evento_id" => $idEvent,
  180. "status" => "1",
  181. "situacao" => "1"
  182. );
  183.  
  184. $cpfs = array();
  185. $emails = array();
  186. $data["log"] = array();
  187.  
  188. foreach ($csv as $key => $row) {
  189. if (($key == 0)) {
  190. unset($csv[$key]);
  191. continue;
  192. }
  193.  
  194. if ($key > 0) {
  195. $line = $key + 1;
  196. $data["log"][$line]["status"] = "";
  197. $data["log"][$line]["error"] = "";
  198.  
  199. foreach ($row as $cn => $record) {
  200. switch ($cn) {
  201. case '8':{
  202. $addedUpColumnsInscription["valor"] = $record;
  203.  
  204. break;
  205. }
  206. case '14':{
  207. $addedUpColumnsInscription["parcela"] = $record;
  208.  
  209. break;
  210. }
  211. case '19':{
  212. $data["log"][$line]["nome"] = $record;
  213.  
  214. if (empty($record)) {
  215. $data["log"][$line]["error"] .= "Campo obrigatório 'Nome' não foi preenchido.<br />";
  216. }
  217.  
  218. $addedUpColumnsLeader["nome"] = $record;
  219.  
  220. break;
  221. }
  222. case '20':{
  223. if (preg_match("/^\d{3}\.\d{3}\.\d{3}-\d{2}$/", $record)) {
  224. $data["log"][$line]["cpf"] = $record;
  225.  
  226. if (!Common::validateCPF($record)) {
  227. $data["log"][$line]["error"] .= "CPF inválido.<br />";
  228. }
  229.  
  230. if (in_array($record, $cpfs)) {
  231. $data["log"][$line]["error"] .= "CPF repetido.<br />";
  232. }
  233.  
  234. $cpfs[$key] = $record;
  235.  
  236. $addedUpColumnsLeader["cpf"] = $record;
  237. } else {
  238. $data["log"][$line]["cpf"] = "";
  239.  
  240. if (preg_match("/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/", $record)) {
  241. $addedUpColumnsLeader["cnpj"] = $record;
  242. } else {
  243. $addedUpColumnsLeader["rg"] = $record;
  244. }
  245. }
  246.  
  247. break;
  248. }
  249. case '21':{
  250. $data["log"][$line]["email"] = $record;
  251.  
  252. if (empty($record)) {
  253. $data["log"][$line]["error"] .= "Campo obrigatório 'Email' não foi preenchido.<br />";
  254. }
  255.  
  256. if (!filter_var($record, FILTER_VALIDATE_EMAIL)) {
  257. $data["log"][$line]["error"] .= "Email inválido.<br />";
  258. }
  259.  
  260. if (in_array($record, $emails)) {
  261. $data["log"][$line]["error"] .= "Email repetido.<br />";
  262. }
  263.  
  264. $emails[$key] = $record;
  265.  
  266. $addedUpColumnsLeader["email"] = $record;
  267.  
  268. break;
  269. }
  270. case '23':{
  271. if (preg_match("/^([0-9]{4,5})([0-9]{4})$/", $record, $matches)) {
  272. $addedUpColumnsLeader["telefone"] = "(" . $row[22] . ")" . $matches[1] . "-" . $matches[2];
  273. }
  274.  
  275. break;
  276. }
  277. case '37':{
  278. switch ($record) {
  279. case 'CartaoDeCredito':
  280. $addedUpColumnsInscription["forma_pagto"] = "CC";
  281. break;
  282. case 'DebitoBancario':
  283. $addedUpColumnsInscription["forma_pagto"] = "CD";
  284. break;
  285. case 'BoletoBancario':
  286. $addedUpColumnsInscription["forma_pagto"] = "BB";
  287. break;
  288. }
  289.  
  290. break;
  291. }
  292. }
  293. }
  294.  
  295. if ($data["log"][$line]["error"] !== "") {
  296. $data["log"][$line]["status"] .= "Não cadastrado";
  297.  
  298. continue;
  299. }
  300.  
  301. if (isset($addedUpColumnsLeader["cpf"]) && $addedUpColumnsLeader["cpf"] !== "") {
  302. $referenceColumns = array(
  303. "cpf" => $addedUpColumnsLeader["cpf"]
  304. );
  305. } else {
  306. $referenceColumns = array(
  307. "email" => $addedUpColumnsLeader["email"]
  308. );
  309. }
  310.  
  311. $rset = $this->leader->get($referenceColumns);
  312.  
  313. if ($rset) {
  314. $idLeader = (int) $rset["id"];
  315.  
  316. $referenceColumns = array(
  317. "id" => $idLeader
  318. );
  319.  
  320. $setableColumns = $addedUpColumnsLeader;
  321.  
  322. $this->leader->update($referenceColumns, $setableColumns);
  323.  
  324. $data["log"][$line]["status"] .= "Aluno atualizado.<br />";
  325. } else {
  326. $idLeader = $this->leader->create($addedUpColumnsLeader);
  327.  
  328. $data["log"][$line]["status"] .= "Aluno cadastrado.<br />";
  329. }
  330.  
  331. if (is_numeric($idLeader)) {
  332. $referenceColumns = array(
  333. "id" => $idLeader
  334. );
  335.  
  336. $rset = $this->leader->get($referenceColumns);
  337.  
  338. $email = $rset["email"];
  339.  
  340. $referenceColumns = array(
  341. "evento_id" => $idEvent,
  342. "lider_id" => $idLeader
  343. );
  344.  
  345. $rset = $this->inscription->get($referenceColumns);
  346.  
  347. if ($rset) {
  348. $data["log"][$line]["status"] .= "Inscrição existente.<br />";
  349.  
  350. continue;
  351. }
  352.  
  353. $addedUpColumnsInscription["lider_id"] = $idLeader;
  354. $addedUpColumnsInscription["chave"] = md5(time() . $email);
  355. $addedUpColumnsInscription["observacao"] = "Hotmart";
  356.  
  357. $id = $this->inscription->create($addedUpColumnsInscription);
  358.  
  359. if (is_numeric($id)) {
  360. $data["log"][$line]["status"] .= "Inscrição cadastrada.<br />";
  361.  
  362. $referenceColumns = array(
  363. "id" => $idEvent
  364. );
  365.  
  366. $rset = $this->event->get($referenceColumns);
  367.  
  368. if ($rset) {
  369. $analise_id = $rset["analise_id"];
  370. }
  371.  
  372. $referenceColumns = array(
  373. "analise_id" => $analise_id,
  374. "categoria" => "1",
  375. "ativo" => "1"
  376. );
  377.  
  378. $email_template = $this->email_template->get($referenceColumns);
  379.  
  380. if ($email_template) {
  381. $referenceColumns = array(
  382. "evento_id" => $idEvent,
  383. "lider_id" => $idLeader,
  384. "analise_id" => $analise_id,
  385. "inscricao_id" => $id
  386. );
  387.  
  388. $rset = $this->inscription->queryJoin(
  389. $referenceColumns,
  390. "SELECT
  391. i.chave, a.analise, l.nome, l.email, e.evento, p.produto
  392. FROM
  393. inscricoes i
  394. INNER JOIN
  395. eventos e
  396. ON
  397. e.id = i.evento_id
  398. INNER JOIN
  399. lideres l
  400. ON
  401. l.id = i.lider_id
  402. INNER JOIN
  403. analises a
  404. ON
  405. a.id = e.analise_id
  406. INNER JOIN
  407. produtos p
  408. ON
  409. p.id = a.produto_id
  410. WHERE
  411. e.id = :evento_id
  412. AND
  413. l.id = :lider_id
  414. AND
  415. a.id = :analise_id
  416. AND
  417. i.id = :inscricao_id
  418. "
  419. );
  420.  
  421. $assunto = $email_template["assunto"];
  422.  
  423. $mail = new \PHPMailer();
  424. $mail->setLanguage("pt");
  425.  
  426. $from = MAIL_FROM;
  427. $fromName = MAIL_FROMNAME;
  428.  
  429. $host = MAIL_HOST;
  430. $username = MAIL_USERNAME;
  431. $password = MAIL_PASSWORD;
  432. $port = MAIL_PORT;
  433. $secure = MAIL_SECURE;
  434.  
  435. $mail->isSMTP();
  436. $mail->Host = $host;
  437. $mail->SMTPAuth = true;
  438. $mail->Username = $username;
  439. $mail->Password = $password;
  440. $mail->SMTPSecure = $secure;
  441. $mail->Port = $port;
  442.  
  443. $mail->From = $from;
  444. $mail->FromName = $fromName;
  445. $mail->addReplyTo($from, $fromName);
  446.  
  447. $mail->addAddress($rset["email"], $rset["nome"]);
  448. $mail->isHTML(true);
  449. $mail->CharSet = 'UTF-8';
  450. $mail->WordWrap = 70;
  451.  
  452. $mail->Subject = $assunto;
  453.  
  454. $src_img = STATIC_URL . "images/logo.jpg";
  455.  
  456. $body = <<<EOD
  457. <style type="text/css">
  458. a{
  459. color: #FFF;
  460. text-decoration: none;
  461. }
  462. </style>
  463.  
  464. <table width="785" border="0" cellpadding="0" cellspacing="0" style="background:#F1F1F1;">
  465. <tr>
  466. <td height="496" valign="top">
  467. <table width="570" border="0" align="center" cellpadding="0" cellspacing="0" style=" background:#FFFFFF;">
  468. <tr>
  469. <td colspan="2" style="background:#F1F1F1;">&nbsp;</td>
  470. </tr>
  471. <tr>
  472. <td width="204" height="75" style="padding-left:5px;">
  473. <img src="$src_img" height="40">
  474. </td>
  475. <td width="366" align="center"><strong><span style="margin-top:20px; font-family:Tahoma, Geneva, sans-serif;font-size:14px;color:#095BA6;">{{produto}}: {{assunto}}</span></strong></td>
  476. </tr>
  477. <tr>
  478. <td colspan="2" style="background:#F1F1F1;">&nbsp;</td>
  479. </tr>
  480. <tr>
  481. <td height="334" colspan="2" valign="top" style="padding-left:10px; padding-right:10px; font-family:Tahoma, Geneva, sans-serif;font-size:12px;color:#333;">
  482. <br/>
  483. EOD;
  484.  
  485. if (strstr($body, "{{produto}}") && isset($rset["produto"])) {
  486. $body = str_replace("{{produto}}", $rset["produto"], $body);
  487. }
  488.  
  489. if (strstr($body, "{{assunto}}") && isset($assunto)) {
  490. $body = str_replace("{{assunto}}", $assunto, $body);
  491. }
  492.  
  493. $body .= $email_template["corpo"];
  494.  
  495. if (strstr($body, "{{nome}}") && isset($rset["nome"])) {
  496. $body = str_replace("{{nome}}", $rset["nome"], $body);
  497. }
  498.  
  499. if (strstr($body, "{{evento}}") && isset($rset["evento"])) {
  500. $body = str_replace("{{evento}}", $rset["evento"], $body);
  501. }
  502.  
  503. if (strstr($body, "{{analise}}") && isset($rset["analise"])) {
  504. $body = str_replace("{{analise}}", $rset["analise"], $body);
  505. }
  506.  
  507. if (strstr($body, "{{aceita}}") && isset($rset["chave"])) {
  508. $url = SITE_URL . "questionario/aluno/" . $rset["chave"];
  509.  
  510. $buttonConfirm = <<<EOD
  511. <table width="170" style="text-align:center; padding:3px; background:#4D90FE; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px;">
  512. <tr>
  513. <td><a href="$url" style="color:white;">Acesse aqui sua pesquisa!</a></td>
  514. </tr>
  515. </table><br/>
  516. EOD;
  517.  
  518. $body = str_replace("{{aceita}}", $buttonConfirm, $body);
  519. }
  520.  
  521. if (strstr($body, "{{data}}")) {
  522. $body = str_replace("{{data}}", date("d/m/Y"), $body);
  523. }
  524.  
  525. $body .= <<<EOD
  526. <br/>
  527. </td>
  528. </tr>
  529. </table>
  530. </td>
  531. </tr>
  532. <tr>
  533. <td height="20" valign="top">&nbsp;</td>
  534. </tr>
  535. </table>
  536. EOD;
  537.  
  538. $mail->Body = $body;
  539.  
  540. $send = $mail->Send();
  541.  
  542. if ($send) {
  543. $data["log"][$line]["status"] .= "Email enviado.<br />";
  544. } else {
  545. $data["log"][$line]["status"] .= "Email não enviado.<br />";
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552.  
  553. break;
  554. }
  555. default:{
  556. $addedUpColumnsLeader = array();
  557. $addedUpColumnsInscription = array(
  558. "evento_id" => $idEvent,
  559. "status" => "1",
  560. "situacao" => "1"
  561. );
  562.  
  563. $cpfs = array();
  564. $emails = array();
  565. $data["log"] = array();
  566.  
  567. foreach ($csv as $key => $row) {
  568. if ($key <= 1) {
  569. unset($csv[$key]);
  570. continue;
  571. }
  572.  
  573. if ($key > 1) {
  574. $line = $key + 1;
  575. $data["log"][$line]["status"] = "";
  576. $data["log"][$line]["error"] = "";
  577.  
  578. foreach ($row as $cn => $record) {
  579. switch ($cn) {
  580. case '0':{
  581. $data["log"][$line]["nome"] = $record;
  582.  
  583. if (empty($record)) {
  584. $data["log"][$line]["error"] .= "Campo obrigatório 'Nome' não foi preenchido.<br />";
  585. }
  586.  
  587. $addedUpColumnsLeader["nome"] = $record;
  588. break;
  589. }
  590. case '1':{
  591. $addedUpColumnsLeader["data_nascimento"] = Common::format("localeToDate", $record);
  592. break;
  593. }
  594. case '2':{
  595. $addedUpColumnsLeader["telefone"] = $record;
  596. break;
  597. }
  598. case '3':{
  599. $addedUpColumnsLeader["celular"] = $record;
  600. break;
  601. }
  602. case '4':{
  603. $data["log"][$line]["email"] = $record;
  604.  
  605. if (empty($record)) {
  606. $data["log"][$line]["error"] .= "Campo obrigatório 'Email' não foi preenchido.<br />";
  607. }
  608.  
  609. if (!filter_var($record, FILTER_VALIDATE_EMAIL)) {
  610. $data["log"][$line]["error"] .= "Email inválido.<br />";
  611. }
  612.  
  613. if (in_array($record, $emails)) {
  614. $data["log"][$line]["error"] .= "Email repetido.<br />";
  615. }
  616.  
  617. $emails[$key] = $record;
  618.  
  619. $addedUpColumnsLeader["email"] = $record;
  620. break;
  621. }
  622. case '5':{
  623. $data["log"][$line]["cpf"] = $record;
  624.  
  625. if (empty($record)) {
  626. $data["log"][$line]["error"] .= "Campo obrigatório 'CPF' não foi preenchido.<br />";
  627. }
  628.  
  629. if (!Common::validateCPF($record)) {
  630. $data["log"][$line]["error"] .= "CPF inválido.<br />";
  631. }
  632.  
  633. if (in_array($record, $cpfs)) {
  634. $data["log"][$line]["error"] .= "CPF repetido.<br />";
  635. }
  636.  
  637. $cpfs[$key] = $record;
  638.  
  639. $addedUpColumnsLeader["cpf"] = $record;
  640. break;
  641. }
  642. case '6':{
  643. $addedUpColumnsLeader["rg"] = $record;
  644. break;
  645. }
  646. case '7':{
  647. $addedUpColumnsLeader["empresa"] = $record;
  648. break;
  649. }
  650. case '8':{
  651. $addedUpColumnsLeader["cnpj"] = $record;
  652. break;
  653. }
  654. case '9':{
  655. $addedUpColumnsLeader["cargo"] = $record;
  656. break;
  657. }
  658. case '10':{
  659. $data["log"][$line]["nota_fiscal"] = $record;
  660.  
  661. if (empty($record)) {
  662. $data["log"][$line]["error"] .= "Campo obrigatório 'Nota Fiscal' não foi preenchido.<br />";
  663. }
  664.  
  665. if (($record == "F") || ($record == "f")) {
  666. $addedUpColumnsInscription["nota_fiscal"] = "F";
  667. } elseif (($record == "J") || ($record == "j")) {
  668. $addedUpColumnsInscription["nota_fiscal"] = "J";
  669. }
  670. break;
  671. }
  672. }
  673. }
  674.  
  675. if ($data["log"][$line]["error"] !== "") {
  676. $data["log"][$line]["status"] .= "Não cadastrado";
  677.  
  678. continue;
  679. }
  680.  
  681. $referenceColumns = array(
  682. "cpf" => $addedUpColumnsLeader["cpf"]
  683. );
  684.  
  685. $rset = $this->leader->get($referenceColumns);
  686.  
  687. if ($rset) {
  688. $idLeader = (int) $rset["id"];
  689.  
  690. $referenceColumns = array(
  691. "id" => $idLeader
  692. );
  693.  
  694. $setableColumns = $addedUpColumnsLeader;
  695.  
  696. $this->leader->update($referenceColumns, $setableColumns);
  697.  
  698. $data["log"][$line]["status"] .= "Aluno atualizado.<br />";
  699. } else {
  700. $idLeader = $this->leader->create($addedUpColumnsLeader);
  701.  
  702. $data["log"][$line]["status"] .= "Aluno cadastrado.<br />";
  703. }
  704.  
  705. if (is_numeric($idLeader)) {
  706. $referenceColumns = array(
  707. "id" => $idLeader
  708. );
  709.  
  710. $rset = $this->leader->get($referenceColumns);
  711.  
  712. $email = $rset["email"];
  713.  
  714. $referenceColumns = array(
  715. "evento_id" => $idEvent,
  716. "lider_id" => $idLeader
  717. );
  718.  
  719. $rset = $this->inscription->get($referenceColumns);
  720.  
  721. if ($rset) {
  722. $data["log"][$line]["status"] .= "Inscrição existente.<br />";
  723.  
  724. continue;
  725. }
  726.  
  727. $addedUpColumnsInscription["lider_id"] = $idLeader;
  728. $addedUpColumnsInscription["chave"] = md5(time() . $email);
  729.  
  730. $id = $this->inscription->create($addedUpColumnsInscription);
  731.  
  732. if (is_numeric($id)) {
  733. $data["log"][$line]["status"] .= "Inscrição cadastrada.<br />";
  734.  
  735. $referenceColumns = array(
  736. "id" => $idEvent
  737. );
  738.  
  739. $rset = $this->event->get($referenceColumns);
  740.  
  741. if ($rset) {
  742. $analise_id = $rset["analise_id"];
  743. }
  744.  
  745. $referenceColumns = array(
  746. "analise_id" => $analise_id,
  747. "categoria" => "1",
  748. "ativo" => "1"
  749. );
  750.  
  751. $email_template = $this->email_template->get($referenceColumns);
  752.  
  753. if ($email_template) {
  754. $referenceColumns = array(
  755. "evento_id" => $idEvent,
  756. "lider_id" => $idLeader,
  757. "analise_id" => $analise_id,
  758. "inscricao_id" => $id
  759. );
  760.  
  761. $rset = $this->inscription->queryJoin(
  762. $referenceColumns,
  763. "SELECT
  764. i.chave, a.analise, l.nome, l.email, e.evento, p.produto
  765. FROM
  766. inscricoes i
  767. INNER JOIN
  768. eventos e
  769. ON
  770. e.id = i.evento_id
  771. INNER JOIN
  772. lideres l
  773. ON
  774. l.id = i.lider_id
  775. INNER JOIN
  776. analises a
  777. ON
  778. a.id = e.analise_id
  779. INNER JOIN
  780. produtos p
  781. ON
  782. p.id = a.produto_id
  783. WHERE
  784. e.id = :evento_id
  785. AND
  786. l.id = :lider_id
  787. AND
  788. a.id = :analise_id
  789. AND
  790. i.id = :inscricao_id
  791. "
  792. );
  793.  
  794. $assunto = $email_template["assunto"];
  795.  
  796. $mail = new \PHPMailer();
  797. $mail->setLanguage("pt");
  798.  
  799. $from = MAIL_FROM;
  800. $fromName = MAIL_FROMNAME;
  801.  
  802. $host = MAIL_HOST;
  803. $username = MAIL_USERNAME;
  804. $password = MAIL_PASSWORD;
  805. $port = MAIL_PORT;
  806. $secure = MAIL_SECURE;
  807.  
  808. $mail->isSMTP();
  809. $mail->Host = $host;
  810. $mail->SMTPAuth = true;
  811. $mail->Username = $username;
  812. $mail->Password = $password;
  813. $mail->SMTPSecure = $secure;
  814. $mail->Port = $port;
  815.  
  816. $mail->From = $from;
  817. $mail->FromName = $fromName;
  818. $mail->addReplyTo($from, $fromName);
  819.  
  820. $mail->addAddress($rset["email"], $rset["nome"]);
  821. $mail->isHTML(true);
  822. $mail->CharSet = 'UTF-8';
  823. $mail->WordWrap = 70;
  824.  
  825. $mail->Subject = $assunto;
  826.  
  827. $src_img = STATIC_URL . "images/logo.jpg";
  828.  
  829. $body = <<<EOD
  830. <style type="text/css">
  831. a{
  832. color: #FFF;
  833. text-decoration: none;
  834. }
  835. </style>
  836.  
  837. <table width="785" border="0" cellpadding="0" cellspacing="0" style="background:#F1F1F1;">
  838. <tr>
  839. <td height="496" valign="top">
  840. <table width="570" border="0" align="center" cellpadding="0" cellspacing="0" style=" background:#FFFFFF;">
  841. <tr>
  842. <td colspan="2" style="background:#F1F1F1;">&nbsp;</td>
  843. </tr>
  844. <tr>
  845. <td width="204" height="75" style="padding-left:5px;">
  846. <img src="$src_img" height="40">
  847. </td>
  848. <td width="366" align="center"><strong><span style="margin-top:20px; font-family:Tahoma, Geneva, sans-serif;font-size:14px;color:#095BA6;">{{produto}}: {{assunto}}</span></strong></td>
  849. </tr>
  850. <tr>
  851. <td colspan="2" style="background:#F1F1F1;">&nbsp;</td>
  852. </tr>
  853. <tr>
  854. <td height="334" colspan="2" valign="top" style="padding-left:10px; padding-right:10px; font-family:Tahoma, Geneva, sans-serif;font-size:12px;color:#333;">
  855. <br/>
  856. EOD;
  857.  
  858. if (strstr($body, "{{produto}}") && isset($rset["produto"])) {
  859. $body = str_replace("{{produto}}", $rset["produto"], $body);
  860. }
  861.  
  862. if (strstr($body, "{{assunto}}") && isset($assunto)) {
  863. $body = str_replace("{{assunto}}", $assunto, $body);
  864. }
  865.  
  866. $body .= $email_template["corpo"];
  867.  
  868. if (strstr($body, "{{nome}}") && isset($rset["nome"])) {
  869. $body = str_replace("{{nome}}", $rset["nome"], $body);
  870. }
  871.  
  872. if (strstr($body, "{{evento}}") && isset($rset["evento"])) {
  873. $body = str_replace("{{evento}}", $rset["evento"], $body);
  874. }
  875.  
  876. if (strstr($body, "{{analise}}") && isset($rset["analise"])) {
  877. $body = str_replace("{{analise}}", $rset["analise"], $body);
  878. }
  879.  
  880. if (strstr($body, "{{aceita}}") && isset($rset["chave"])) {
  881. $url = SITE_URL . "questionario/aluno/" . $rset["chave"];
  882.  
  883. $buttonConfirm = <<<EOD
  884. <table width="170" style="text-align:center; padding:3px; background:#4D90FE; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px;">
  885. <tr>
  886. <td><a href="$url" style="color:white;">Acesse aqui sua pesquisa!</a></td>
  887. </tr>
  888. </table><br/>
  889. EOD;
  890.  
  891. $body = str_replace("{{aceita}}", $buttonConfirm, $body);
  892. }
  893.  
  894. if (strstr($body, "{{data}}")) {
  895. $body = str_replace("{{data}}", date("d/m/Y"), $body);
  896. }
  897.  
  898. $body .= <<<EOD
  899. <br/>
  900. </td>
  901. </tr>
  902. </table>
  903. </td>
  904. </tr>
  905. <tr>
  906. <td height="20" valign="top">&nbsp;</td>
  907. </tr>
  908. </table>
  909. EOD;
  910.  
  911. $mail->Body = $body;
  912.  
  913. $send = $mail->Send();
  914.  
  915. if ($send) {
  916. $data["log"][$line]["status"] .= "Email enviado.<br />";
  917. } else {
  918. $data["log"][$line]["status"] .= "Email não enviado.<br />";
  919. }
  920. }
  921. }
  922. }
  923. }
  924. }
  925.  
  926. break;
  927. }
  928. }
  929.  
  930. $this->loadView(ADM_VIEW_PATH, "event/import_log", $data);
  931. }
  932.  
  933. $data["action"] = ADM_URL . "evento/importar-alunos/" . $idEvent;
  934.  
  935. $this->loadView(ADM_VIEW_PATH, "event/import_students", $data);
  936. } catch (\Exception $e) {
  937. Session::set("error", array(
  938. "type" => "alert-warning",
  939. "msg" => $e->getMessage()
  940. ));
  941.  
  942. Common::redir("gestor/evento/importar-alunos/" . $idEvent);
  943. }
  944. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement