public function GeraCertificadoParticipante($idParticipante, $idPalestra, $replace = false, $ehPalestrante = false) { // Requer permissão de acesso $this->RequirePermission(Usuario::$P_ADMIN, 'SecureExample.LoginForm', 'Autentique-se para acessar esta página', 'Você não possui permissão para acessar essa página ou sua sessão expirou'); //Palestra $palestra = $this->Phreezer->Get('Palestra', $idPalestra); //Evento $evento = $this->Phreezer->Get('Evento', $palestra->IdEvento); //SE FOR PALESTRANTE OU SE FOR PARTICIPANTE if ($ehPalestrante) { //PalestraParticipante require_once 'Model/PalestraPalestrante.php'; $criteria = new PalestraPalestranteCriteria(); $criteria->IdPalestra_Equals = $idPalestra; $criteria->IdPalestrante_Equals = $idParticipante; $palestrante = $this->Phreezer->GetByCriteria('PalestraPalestranteReporter', $criteria); //Certificado $certificado = $this->Phreezer->Get('Certificado', $palestrante->IdCertificado); } else { //PalestraPalestrante require_once 'Model/PalestraPalestrante.php'; $criteria = new PalestraPalestranteCriteria(); $criteria->IdPalestra_Equals = $idPalestra; $palestrantes = $this->Phreezer->Query('PalestraPalestranteReporter', $criteria)->ToObjectArray(true, $this->SimpleObjectParams()); //PalestraParticipante require_once 'Model/PalestraParticipante.php'; $criteria = new PalestraParticipanteCriteria(); $criteria->IdPalestra_Equals = $idPalestra; $criteria->IdParticipante_Equals = $idParticipante; $participante = $this->Phreezer->GetByCriteria('PalestraParticipanteReporter', $criteria); //Certificado $certificado = $this->Phreezer->Get('Certificado', $participante->IdCertificado); } //Modelo Certificado $modeloCertificado = $this->Phreezer->Get('ModeloCertificado', $palestra->IdModeloCertificado); $dadosModeloCertificado = $modeloCertificado->Elementos; if ($ehPalestrante) { $textoParticipante = json_decode($modeloCertificado->TextoPalestrante); } else { $textoParticipante = json_decode($modeloCertificado->TextoParticipante); } //print_r( $textoParticipante); //Carrega HTML // $obj = new DOMDocument(); // $obj->loadHTML($dadosModeloCertificado); // $obj->preserveWhiteSpace = false; //echo $obj->saveHTML(); //Orientacao $orientacao = preg_match("/A4portrait/", $dadosModeloCertificado, $matches); if ($orientacao) { $orientacao = 'portrait'; } else { $orientacao = 'landscape'; } //só pegar os 2 primeiros palestrantes se for retrato, ou 3 se for paisagem if ($ehPalestrante == false) { if ($orientacao == 'portrait') { $palestrantes = array_slice($palestrantes, 0, 2); } else { $palestrantes = array_slice($palestrantes, 0, 3); } } //exibe assinatura do particcipante removendo o hide if ($ehPalestrante == false) { $dadosModeloCertificado = preg_replace('/hide-palestrante(\\ hide)?/i', '', $dadosModeloCertificado); } ///REMOVER ISSO!!! //echo '<link rel="stylesheet" type="text/css" media="screen,print" href="'. GlobalConfig::$ROOT_URL. '/styles/certificados/padrao.css" />'; $classePalestrante = ''; $tableStyle = ''; if ($ehPalestrante) { $classePalestrante = 'palestrante'; $tableStyle = ''; } if ($orientacao === 'portrait') { $tableStyle = 'style="margin-top:10mm!important;"'; } $htmlAssinaturas = ''; //REMOVE ASSINATURAS ESTÁTICAS E COLOCA DINÂMICAS $htmlAssinaturas .= '<table class="assinaturas ' . $classePalestrante . ' dinamico justifyleft" ' . $tableStyle . '> <tbody><tr>'; if ($ehPalestrante) { //print_r($palestrante); $totalPalestrantes = 0; //vai somar +1 para dar 100%; $htmlAssinaturas .= '<td align="center" valign="bottom" style="width:' . 100 / ($totalPalestrantes + 1) . '%!important; margin:0px 10mm; vertical-align:bottom;">'; if ($palestrante->ImagemAssinatura) { $htmlAssinaturas .= '<img style="width:auto; height:22mm;" id="AssinaturaPalestrante" class="assinatura" src="' . GlobalConfig::$ROOT_URL . 'images/uploads/logos/small/' . $palestrante->ImagemAssinatura . '">'; } $htmlAssinaturas .= '</td>'; } else { $totalPalestrantes = sizeof($palestrantes); foreach ($palestrantes as $palestrante) { $htmlAssinaturas .= '<td align="center" valign="bottom" style="width:' . 100 / ($totalPalestrantes + 1) . '%!important; margin:0px 10mm; vertical-align:bottom;">'; if ($palestrante->imagemAssinatura) { $htmlAssinaturas .= '<img style="width:auto; height:22mm;" id="AssinaturaPalestrante" class="assinatura" src="' . GlobalConfig::$ROOT_URL . 'images/uploads/logos/small/' . $palestrante->imagemAssinatura . '">'; } $htmlAssinaturas .= '</td>'; } } $htmlAssinaturas .= '<td style="height:20mm; vertical-align:bottom;"></td> </tr> <tr>'; if (!$ehPalestrante) { foreach ($palestrantes as $palestrante) { $htmlAssinaturas .= '<td style="width:' . 100 / ($totalPalestrantes + 1) . '%!important;"><hr style="0 margin:20px!important;"></td>'; } } $htmlAssinaturas .= ' <td valign="bottom"><hr></td> </tr> <tr>'; if ($ehPalestrante) { //remove assinatura do participante $dadosModeloCertificado = preg_replace('/<td class="hide-palestrante">(.*?)<\\/td>/s', '', $dadosModeloCertificado); $htmlAssinaturas .= '<td align="center" valign="top"><small><strong>' . $palestrante->NomePalestrante . '</strong><br>' . $palestrante->CargoPalestrante . '</small></td>'; } else { foreach ($palestrantes as $palestrante) { $htmlAssinaturas .= '<td align="center" valign="top"><small><strong>' . $palestrante->nomePalestrante . '</strong><br>' . $palestrante->cargoPalestrante . '</small></td>'; } $htmlAssinaturas .= '<td align="center" valign="top" style="width:' . 100 / ($totalPalestrantes + 1) . '%!important;"><small><strong>' . $participante->NomeParticipante . '</strong><br>Participante</small></td>'; } $htmlAssinaturas .= '</tr> </tbody></table>'; $dadosModeloCertificado = preg_replace('/<table class="assinaturas(.*?)"(.*?)>(.*?)<\\/table>/s', $htmlAssinaturas, $dadosModeloCertificado); //$dadosModeloCertificado = preg_replace('/\<[\/]?(table|tr|td)([^\>]*)\>/i', '', $dadosModeloCertificado); //preg_match_all('/(<table[^>]*>(?:.|\n)*(?=<\/table>))/', // echo '--------------------------------------'; // print_r($dadosModeloCertificado); // echo '--------------------------------------'; //PEGA A COR DOS ELEMENTOS DINAMICOS $cor = preg_match('/id="(nomeParticipante|nomePalestrante|nomeAtividade|cargaHoraria)".*?style="color:\\ (.*?)"/', $dadosModeloCertificado, $corArr); $corValue = $cor ? $corArr[2] : ''; $styleCor = ''; if ($corValue != '') { $styleCor = 'color: ' . $corValue . ';'; } //echo '<Br>~~~ ~~~~~~'.$corValue.'********<br>'; if (preg_match('/id="(nomeParticipante|nomePalestrante)" class="(.*?)"/', $dadosModeloCertificado, $centralizarTextoArr)) { } $centralizarTexto = $centralizarTextoArr ? $centralizarTextoArr[2] : ''; $classCenter = ''; if (strpos($centralizarTexto, 'center-block') !== false) { $classCenter = 'center-block'; } //echo '<Br>************'.$classCenter.'********<br>'; //SUBSTITUI PELO TEXTO DO PARTICIPANTE $tagsFinal = ''; foreach ($textoParticipante as $tag) { $join = ' '; if (is_string($tag)) { $tag = trim($tag); if (preg_match('/(,|\\.|;|\\?)(\\ |^$)/i', $tag)) { $join = ''; } } else { if (preg_match('/(,|\\.|;|\\?)(\\ |^$)/i', $tag->label)) { $join = ''; } $textCenter = ''; if ($tag->label == 'Nome do Participante' || $tag->label == 'Nome do Palestrante') { $textCenter = $classCenter; } $tag = '<span class="dbItemCertificado ' . $tag->class . ' ' . $textCenter . '" style="' . $styleCor . '">' . $tag->label . '</span>'; } $tagsFinal .= $join . $tag; } //print_r($tagsFinal); $novoTexto = $textoParticipante; //substitui texto dinamico $dadosModeloCertificado = preg_replace('/<div id="containerDinamico">(.+?)<\\/div>/i', '<div id="containerDinamico">' . $tagsFinal . '</div>', $dadosModeloCertificado); //substitui imagem do logotipo $dadosModeloCertificado = preg_replace('/(<img id="ImagemLogo" src=)(.+?)"/i', '$1"' . GlobalConfig::$ROOT_URL . '/images/uploads/logos/small/' . $this->Configuracao->ImagemLogo . '"', $dadosModeloCertificado); $antigo = array('Nome da Atividade', 'Local da Atividade', 'Data da Atividade', 'Duração do Evento', 'Carga Horária', 'Registro nº 9081/15 folha 86 do livro nº 2', 'validar-certificado/', 'http://localhost:85/tcc/'); $novo = array($palestra->Nome, $evento->Local, date('d/m/Y', strtotime($palestra->Data)), $evento->Duracao, date('H:i', strtotime($palestra->CargaHoraria)), 'Registro nº ' . $certificado->Codigo . '/' . date('y', strtotime($certificado->DataEmissao)) . ' folha ' . $certificado->Folha . ' do livro nº ' . $certificado->Livro, 'validar-certificado/' . $certificado->IdCertificado . '/', GlobalConfig::$ROOT_URL); if ($ehPalestrante) { array_push($antigo, 'Nome do Palestrante'); array_push($novo, $palestrante->NomePalestrante); } else { array_push($antigo, 'Nome do Participante'); array_push($novo, $participante->NomeParticipante); } $dadosModeloCertificado = str_replace($antigo, $novo, $dadosModeloCertificado); //echo '&&&begin&&&&&&&&&'.$htmlAssinaturas.'&&&&&end&&&&&&'; $nomeArquivoModeloCertificado = 'padrao.css'; $bgOrientacao = null; if ($orientacao === 'portrait') { $bgOrientacao = '-portrait'; } $html = ' <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta charset="utf8"/> <style> html { margin:0; } .page-break { page-break-after: always; } .page-break:last-child { page-break-after: initial; } .fixed-pdf { position:fixed!important; } .containerCertificado { background:url(' . GlobalConfig::$ROOT_URL . 'styles/certificados/images/moldura-padrao' . $bgOrientacao . '.png); } </style> <link rel="stylesheet" type="text/css" media="screen,print" href="' . GlobalConfig::$ROOT_URL . '/styles/certificados/' . $nomeArquivoModeloCertificado . '" /> </head> <body class="pdf"> <div class="containerCertificado"> ' . $dadosModeloCertificado . ' </div> </body> </html>'; //echo $html; if ($ehPalestrante) { $arquivo = 'palestrante' . $palestrante->IdPalestrante . '.pdf'; } else { $arquivo = 'palestra' . $participante->IdParticipante . '.pdf'; } $caminho = '/certificados-gerados/' . AppBaseController::ParseUrl($palestra->Nome) . '-' . $palestra->IdPalestra . '/'; if ($replace or !file_exists(GlobalConfig::$APP_ROOT . $caminho . $arquivo)) { AppBaseController::geraPDF($arquivo, GlobalConfig::$APP_ROOT . $caminho, $html, 'a4', $orientacao); } //echo $html; //echo '<embed id="iwc" name="iwc" src="'.GlobalConfig::$ROOT_URL.$caminho.$arquivo.'" width="100%" height="300" wmode="transparent" type="application/pdf" style="display:block; margin:0 auto;">'; //$this->DownloadCertificadoParticipante($palestra->IdPalestra, $participante->IdParticipante); //----->RENDER JSON !IMPORTANTE // $this->RenderJSON(array('success'=>true)); }