FirmaController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class FirmaController extends CI_Controller {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. //$this->load->model("FirmaModel");
  8. }
  9. /**
  10. * Index Page for this controller.
  11. *
  12. * Maps to the following URL
  13. * http://example.com/index.php/welcome
  14. * - or -
  15. * http://example.com/index.php/welcome/index
  16. * - or -
  17. * Since this controller is set as the default controller in
  18. * config/routes.php, it's displayed at http://example.com/
  19. *
  20. * So any other public methods not prefixed with an underscore will
  21. * map to /index.php/welcome/<method_name>
  22. * @see https://codeigniter.com/user_guide/general/urls.html
  23. */
  24. /** Comentario sobre data_file():
  25. * ESTA FUNCION REGRESA LA DIRECCION DEL ARCHIVO EXCEL QUE SE ESTÁ LEYENDO PARA GENERAR LAS FIRMAS
  26. */
  27. private function data_file(){
  28. return 'C:\xampp\htdocs\firmasCI\system_files\datos_firmas.xlsx';
  29. }
  30. public function index()
  31. {
  32. $File = $this->data_file();
  33. $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
  34. $spreadsheet= $reader->load($File);
  35. $sheet = $spreadsheet->getActiveSheet();
  36. $fila_maxima = $sheet->getHighestDataRow();
  37. #obteniendo headers
  38. $headers=[];
  39. foreach($sheet->getRowIterator(1,1) as $row){
  40. $cellIterator = $row->getCellIterator();
  41. $cellIterator->setIterateOnlyExistingCells(false);
  42. foreach($cellIterator as $cell){
  43. $headers[] = $cell->getCalculatedValue();
  44. }
  45. }
  46. #obteniendo datos de las personas
  47. $personal =[];
  48. foreach($sheet->getRowIterator(2,$fila_maxima) as $row){
  49. $cellIterator = $row->getCellIterator();
  50. $cellIterator->setIterateOnlyExistingCells(false);
  51. $i=0;
  52. $data=[];
  53. foreach($cellIterator as $cell){
  54. $data[$headers[$i]] = $cell->getCalculatedValue();
  55. $i++;
  56. }
  57. $personal[]=$data;
  58. }
  59. $data = ['headers'=>$headers,'personal'=>$personal];
  60. $this->load->view('lista',$data);
  61. }
  62. public function generarVistaPrevia($id){
  63. $persona = $this->consultarPersonal($id);
  64. if(isset($persona)){
  65. list($site,$type,$identifier) = explode("/",$persona['LinkedIn']);
  66. list($email_id,$email_domain) = explode("@",$persona['Correo']);
  67. $data=['persona'=>$persona,'site'=>$site,'type'=>$type,'identifier'=>$identifier,'email_id'=>$email_id,'email_domain'=>$email_domain];
  68. //llamada a la vista
  69. $this->load->view($persona['Plantilla'],$data);
  70. /*
  71. *
  72. *Todas las plantillas de firma en html se han llamado igual que como están en el excel
  73. *si desea cambiar el nombre de las plantillas debe descomentar el siguiente algoritmo y
  74. *extenderlo si es necesario.
  75. *
  76. if($persona['Plantilla']=='MER'){
  77. $this->load->view('MER',$data);
  78. }elseif($persona['Plantilla']=='INVER'){
  79. $this->load->view('INVER',$data);
  80. }elseif($persona['Plantilla']=='INVERSOL'){
  81. $this->load->view('INVERSOL',$data);
  82. }elseif($persona['Plantilla']=='METCO'){
  83. $this->load->view('METCO',$data);
  84. }else{
  85. print("NO ESTA ASIGNADO A NINGUNA PLANTILLA, REVISE LOS DATOS");
  86. }
  87. */
  88. }else{
  89. print("NO EXISTE EL ID ".$id." REGISTRADO EN LA HOJA DE EXCEL,POR FAVOR REVISE LOS DATOS");
  90. }
  91. }
  92. public function consultarPersonal($id){
  93. $File = 'C:\xampp\htdocs\firmasCI\system_files\datos_firmas.xlsx';
  94. $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
  95. $spreadsheet= $reader->load($File);
  96. $sheet = $spreadsheet->getActiveSheet();
  97. $fila_maxima = $sheet->getHighestDataRow();
  98. #obteniendo headers
  99. $headers=[];
  100. foreach($sheet->getRowIterator(1,1) as $row){
  101. $cellIterator = $row->getCellIterator();
  102. $cellIterator->setIterateOnlyExistingCells(false);
  103. foreach($cellIterator as $cell){
  104. $headers[] = $cell->getCalculatedValue();
  105. }
  106. }
  107. #obteniendo datos
  108. foreach($sheet->getRowIterator(2,$fila_maxima) as $row){
  109. $cellIterator = $row->getCellIterator();
  110. $cellIterator->setIterateOnlyExistingCells(false);
  111. $i=0;
  112. $data=[];
  113. foreach($cellIterator as $cell){
  114. $data[$headers[$i]] = $cell->getCalculatedValue();
  115. $i++;
  116. if($data['N']!=$id){
  117. break;
  118. }else{
  119. $persona=$data;
  120. }
  121. }
  122. if(isset($persona)){
  123. return $persona;
  124. }
  125. }
  126. return null;
  127. }
  128. /* Comentario sobre generarZIP($id):
  129. *ESTA FUNCION GENERA UN ZIP CON LOS ELEMENTOS DE CADA FIRMA
  130. *DESCARGA LAS IMAGENES, EL TIPO DE FUENTE Y LA VISTA EN HTML DE LA FIRMA.
  131. *EL CSS ESTÁ SIENDO INCRUSTADO EN LA VISTA, DENTRO DE LA FUNCIÓN generarHTML
  132. *LA FUNCION generarHTML GENERA LA VISTA DE LA FIRMA DE MODO QUE CONSUMA FUENTE E IMAGENES
  133. *DESDE UN SERVIDOR, POR LO TANTO DEBERÁ MODIFICARSE LA VISTA PARA QUE TRABAJE DE FORMA LOCAL
  134. *UNA VEZ LOS ARCHIVOS ESTÉN DESCARGADOS.
  135. */
  136. public function generarZIP($id){
  137. $persona = $this->consultarPersonal($id);
  138. if(isset($persona)){
  139. $persona_name = $persona['Primer Nombre']."_".$persona['Primer Apellido'];
  140. $file_name = $this->generarHTML($persona);
  141. $zip = new ZipArchive();
  142. $zip_name = $persona_name."_".$persona['Plantilla'].".zip";
  143. $zip->open($zip_name,ZipArchive::CREATE);
  144. $public_folder_dir = "C:/XAMPP/htdocs/firmasCI/public";
  145. $imagenes_folder = $public_folder_dir."/Imagenes";
  146. $css_folder = $public_folder_dir."/css";
  147. $tipograf_folder =$public_folder_dir."/Tipografias";
  148. $carpetas=[];
  149. $carpetas['Imagenes']=$imagenes_folder;
  150. //$carpetas['css']=$css_folder;
  151. $carpetas['Tipografias']=$tipograf_folder;
  152. $dir = 'public';
  153. $zip->addEmptyDir($dir);
  154. $zip->addFile($file_name,$persona_name.".html");
  155. foreach($carpetas as $key => $dir_folder){
  156. $curr_dest_folder=$dir."/".$key;
  157. $zip->addEmptyDir($curr_dest_folder);
  158. foreach(array_diff(scandir($dir_folder), array('..', '.','fichas_style.css')) as $file){
  159. $source_dir=$dir_folder."/".$file;
  160. $dest_folder=$curr_dest_folder."/".$file;
  161. $zip->addFile($source_dir,$dest_folder);
  162. }
  163. }
  164. $zip->close();
  165. // Creamos las cabezeras que forzaran la descarga del archivo como archivo zip.
  166. header("Content-type: application/octet-stream");
  167. header("Content-disposition: attachment; filename=".$zip_name);
  168. // leemos el archivo creado
  169. readfile($zip_name);
  170. // Por último eliminamos el archivo temporal creado
  171. unlink($zip_name);//Destruye el archivo temporal
  172. }else{
  173. print("NO EXISTE EL ID ".$id." REGISTRADO EN LA HOJA DE EXCEL,POR FAVOR REVISE LOS DATOS");
  174. }
  175. }
  176. /**
  177. * comentario sobre la funcion descargarHTML($id)
  178. */
  179. public function descargarHTML($id){
  180. $persona = $this->consultarPersonal($id);
  181. if(isset($persona)){
  182. $file_name = $this->generarHTML($persona);
  183. // Creamos las cabezeras que forzaran la descarga del archivo como archivo zip.
  184. header("Content-type: application/octet-stream");
  185. header("Content-disposition: attachment; filename=".$persona['Plantilla']."_".$persona['Nombre Completo'].".html");
  186. // leemos el archivo creado
  187. readfile($file_name);
  188. }else{
  189. print("ERROR AL CONSULTAR EL EXCEL, REVISE LOS DATOS");
  190. }
  191. }
  192. /**
  193. * comentario sobre generarHTML($persona):
  194. * ESTA FUNCION GENERA LAS VISTAS HTML PARA DESCARGAR, DE CADA FIRMA ELECTRONICA
  195. * NECESITA COMO PARAMETRO UNA PERSONA EN ESPECIFICO PARA LA QUE SE GENERARÁ LA VISTA
  196. * RETORNA LA UBICACION Y EL NOMBRE DEL ARCHIVO CREADO.
  197. * SE DA POR ALUDIDO QUE LAS IMAGENES Y FUENTE QUE CONSUME LA VISTA, SE ENCUENTRAN EN
  198. * UN SERVIDOR EN LINEA,LISTO PARA SERVIRLOS.
  199. */
  200. public function generarHTML($persona){
  201. $persona_name = $persona['Primer Nombre']."_".$persona['Primer Apellido'];
  202. $path='system_files/firmas_generadas/';
  203. $main_directory = $path.$persona['N']."_".$persona_name;
  204. $sub_directory = $main_directory."/".$persona['N']."_".$persona_name."_".date("d-m-Y_H_i_s");
  205. $file_name = $sub_directory."/".$persona_name.".html";
  206. if(!file_exists($main_directory)){
  207. mkdir($main_directory);
  208. }
  209. if(!file_exists($sub_directory)){
  210. mkdir($sub_directory);
  211. }
  212. list($site,$type,$identifier) = explode("/",$persona['LinkedIn']);
  213. list($email_id,$email_domain) = explode("@",$persona['Correo']);
  214. $firma = fopen($file_name,"a") or die("Error al crear el archivo");
  215. if($persona['Plantilla']=='MER'){
  216. $style ="
  217. @font-face{
  218. font-family:HelveticaNeueLTStd-Lt;
  219. src:url(../Tipografias/HelveticaNeueLTStd-Lt.otf);
  220. }
  221. font{
  222. font-family: Helvetica, sans-serif;
  223. }
  224. td{
  225. font-family: Helvetica, sans-serif;
  226. }
  227. .merelec_name_yellow{
  228. font-family: Helvetica, sans-serif;
  229. color: #FCB122;
  230. font-size: 14pt;
  231. font-weight: bold;
  232. }
  233. .merelec_name_gray{
  234. font-family: Helvetica, sans-serif;
  235. color: #80888F;
  236. font-size: 14pt;
  237. font-weight: bold;
  238. }
  239. .merelec_puesto{
  240. font-family: Helvetica, sans-serif;
  241. color: #80888F;
  242. font-size: 14pt;
  243. }
  244. .merelec_yellow_text{
  245. color: #FCB122;
  246. font-size: 12pt;
  247. font-weight: bold;
  248. }
  249. .merelec_gray_text{
  250. color: #80888F;
  251. font-size: 12pt;
  252. }
  253. ";
  254. $body = " <table>
  255. <tbody>
  256. <tr>
  257. <td colspan=\"2\">
  258. <span class=\"merelec_name_yellow\">".$persona['Primer Nombre']."</span> <span class=\"merelec_name_gray\">".$persona['Primer Apellido']."</span>
  259. <p style=\"margin-top:1%\"><span class=\"merelec_puesto\">".$persona['Puesto']."</span></p>
  260. </td>
  261. </tr>
  262. <tr height=\"10\"></tr>
  263. <tr>
  264. <td width=\"200\" style=\"border-right:2px solid #80888F;\">
  265. <img src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_MER_Logo.png\" width=\"200\" height=\"83\">
  266. </td>
  267. <td width=\"900\" style=\"margin-left:2px;\">
  268. <table>
  269. <tbody>
  270. <tr align=\"left\">
  271. <td>
  272. <span style=\"color: #80888F\"><span class=\"merelec_yellow_text\">T.</span><span class=\"merelec_gray_text\">".$persona['Telefono']."</span> &nbsp;
  273. <span class=\"merelec_yellow_text\">C.</span><span class=\"merelec_gray_text\">".$persona['Celular']."</span></span>
  274. </td>
  275. </tr>
  276. <tr>
  277. <td>
  278. <a href=\"mailto:".$persona['Correo']."\"><span class=\"merelec_yellow_text\">".$email_id."</span><span class=\"merelec_gray_text\">@".$email_domain."</span></a>
  279. </td>
  280. </tr>
  281. <tr>
  282. <td>
  283. <a href=\"https://www.".$persona['LinkedIn']."\"> <span class=\"merelec_gray_text\">".$site."/".$type."/"."</span><span class=\"merelec_yellow_text\">".$identifier."</span></a>
  284. </td>
  285. </tr>
  286. <tr>
  287. <td>
  288. <table>
  289. <tr>
  290. <td>
  291. <a class=\"social_media\" href=\"https://www.linkedin.com/company/mercados-electricos-centroamerica/\">
  292. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_MER_Linkedin.png\">
  293. </a>
  294. </td>
  295. <td>
  296. <a class=\"social_media\" href=\"https://www.facebook.com/MercadosElectricosCentroamerica/\">
  297. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_MER_Facebook.png\">
  298. </a>
  299. </td>
  300. <td>
  301. <a class=\"social_media\" href=\"https://www.mercadoselectricos.com.sv\">
  302. <span class=\"merelec_gray_text\">www.</span><span class=\"merelec_yellow_text\">mercadoselectricos</span><span class=\"merelec_gray_text\">.com.sv</span>
  303. </a>
  304. </td>
  305. </tr>
  306. </table>
  307. </td>
  308. </tr>
  309. </tbody>
  310. </table>
  311. </td>
  312. </tr>
  313. </tbody>
  314. </table>
  315. </body>
  316. </html>";
  317. }elseif($persona['Plantilla']=='INVER'){
  318. $style = "@font-face{
  319. font-family:HelveticaNeueLTStd-Lt;
  320. src:url(../Tipografias/HelveticaNeueLTStd-Lt.otf);
  321. }
  322. .inverlec_name_blue{
  323. font-family: Helvetica, sans-serif;
  324. color: #00ABE7;
  325. font-size: 16px;
  326. font-weight:bold;
  327. }
  328. .inverlec_name_black{
  329. font-family: Helvetica, sans-serif;
  330. color: black;
  331. font-size: 16px;
  332. font-weight:bold;
  333. }
  334. .inverlec_puesto{
  335. font-family: Helvetica, sans-serif;
  336. color: black;
  337. font-size: 16px;
  338. }
  339. td{
  340. font-family: Helvetica, sans-serif;
  341. }
  342. .inverlec_blue_text{
  343. color: #00ABE7;
  344. font-family: Helvetica, sans-serif;
  345. font-size: 15px;
  346. font-weight:bold;
  347. }
  348. .inverlec_black_text{
  349. color: black;
  350. font-family: Helvetica, sans-serif;
  351. font-size: 15px;
  352. }
  353. ";
  354. $body="<table>
  355. <tbody>
  356. <tr>
  357. <td colspan=\"2\">
  358. <span class=\"inverlec_name_blue\">".$persona['Primer Nombre']."</span> <span class=\"inverlec_name_black\">".$persona['Primer Apellido']."</span>
  359. <p style=\"margin-top:1%\"><span class=\"inverlec_puesto\">".$persona['Puesto']."</span></p>
  360. </td>
  361. </tr>
  362. <tr height=\"10\"></tr>
  363. <tr>
  364. <td width=\"160\" style=\"border-right:2px solid #00ABE7;\">
  365. <img src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVER_Logo.png\" width=\"160\" height=\"90\">
  366. </td>
  367. <td width=\"900\" style=\"margin-left:2px;\" >
  368. <table>
  369. <tbody>
  370. <tr align=\"left\">
  371. <td>
  372. <span style=\"color: #80888F\"><span class=\"inverlec_blue_text\">T.</span><span class=\"inverlec_black_text\">".$persona['Telefono']."</span>
  373. <span class=\"inverlec_blue_text\">C.</span><span class=\"inverlec_black_text\">".$persona['Celular']."</span></span>
  374. </td>
  375. </tr>
  376. <tr>
  377. <td>
  378. <a href=\"mailto:".$persona['Correo']."\"><span class=\"inverlec_blue_text\">".$email_id."</span><span class=\"inverlec_black_text\">@".$email_domain."</span></a>
  379. </td>
  380. </tr>
  381. <tr>
  382. <td>
  383. <a href=\"https://www.".$persona['LinkedIn']."\"> <span class=\"inverlec_black_text\">".$site."/".$type."/"."</span><span class=\"inverlec_blue_text\">".$identifier."</span></a>
  384. </td>
  385. </tr>
  386. <tr>
  387. <td>
  388. <table>
  389. <tr>
  390. <td>
  391. <a class=\"social_media\" href=\"https://www.linkedin.com/company/inverlecsv/\">
  392. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVER_Linkedin.png\">
  393. </a>
  394. </td>
  395. <td>
  396. <a class=\"social_media\" href=\"https://www.facebook.com/Inverlecsv/\">
  397. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVER_Facebook.png\">
  398. </a>
  399. </td>
  400. <td>
  401. <a class=\"social_media\" href=\"https://www.inverlec.com.sv\">
  402. <span class=\"inverlec_black_text\">www.</span><span class=\"inverlec_blue_text\">inverlec</span><span class=\"inverlec_black_text\">.com.sv</span>
  403. </a>
  404. </td>
  405. </tr>
  406. </table>
  407. </td>
  408. </tr>
  409. </tbody>
  410. </table>
  411. </td>
  412. </tr>
  413. </tbody>
  414. </table>
  415. </body>
  416. </html>
  417. ";
  418. }elseif($persona['Plantilla']=='INVERSOL'){
  419. $style = "
  420. @font-face{
  421. font-family:HelveticaNeueLTStd-Lt;
  422. src:url(../Tipografias/HelveticaNeueLTStd-Lt.otf);
  423. }
  424. .inversol_name_yellow{
  425. font-family: Helvetica, sans-serif;
  426. color: #F78D27;
  427. font-size: 16px;
  428. font-weight: bold;
  429. }
  430. .inversol_name_black{
  431. font-family: Helvetica, sans-serif;
  432. color: black;
  433. font-size: 16px;
  434. font-weight: bold;
  435. }
  436. .inversol_puesto{
  437. font-family: Helvetica, sans-serif;
  438. color: black;
  439. font-size: 16px;
  440. }
  441. td{
  442. font-family: Helvetica, sans-serif;
  443. }
  444. .inversol_yellow_text{
  445. color: #F78D27;
  446. font-family: Helvetica, sans-serif;
  447. font-size: 15px;
  448. font-weight: bold;
  449. }
  450. .inversol_black_text{
  451. color: black;
  452. font-family: Helvetica, sans-serif;
  453. font-size: 15px;
  454. }
  455. ";
  456. $body = "<table>
  457. <tbody>
  458. <tr>
  459. <td colspan=\"2\">
  460. <span class=\"inversol_name_yellow\">".$persona['Primer Nombre']."</span> <span class=\"inversol_name_black\">".$persona['Primer Apellido']."</span>
  461. <p style=\"margin-top:1%\"><span class=\"inversol_puesto\">".$persona['Puesto']."</span></p>
  462. </td>
  463. </tr>
  464. <tr height=\"10\"></tr>
  465. <tr>
  466. <td width=\"160\" style=\"border-right:2px solid #FBAB20;\">
  467. <img src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVERSOL_Logo.png\" width=\"160\" height=\"100\">
  468. </td>
  469. <td width=\"900\" style=\"margin-left:2px;\">
  470. <table>
  471. <tbody>
  472. <tr align=\"left\">
  473. <td>
  474. <span style=\"color: #80888F\"><span class=\"inversol_yellow_text\">T.</span><span class=\"inversol_black_text\">".$persona['Telefono']."</span>
  475. <span class=\"inversol_yellow_text\">C.</span><span class=\"inversol_black_text\">".$persona['Celular']."</span></span>
  476. </td>
  477. </tr>
  478. <tr>
  479. <td>
  480. <a href=\"mailto:".$persona['Correo']."\"><span class=\"inversol_yellow_text\">".$email_id."</span><span class=\"inversol_black_text\">@".$email_domain."</span></a>
  481. </td>
  482. </tr>
  483. <tr>
  484. <td>
  485. <a href=\"https://www.".$persona['LinkedIn']."\"> <span class=\"inversol_black_text\">".$site."/".$type."/"."</span><span class=\"inversol_yellow_text\">".$identifier."</span></a>
  486. </td>
  487. </tr>
  488. <tr>
  489. <td>
  490. <table>
  491. <tr>
  492. <td>
  493. <a class=\"social_media\" href=\"https://www.linkedin.com/company/inverlecsolar/\">
  494. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVERSOL_Linkedin.png\">
  495. </a>
  496. </td>
  497. <td>
  498. <a class=\"social_media\" href=\"https://www.facebook.com/inverlec/\">
  499. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_INVERSOL_Facebook.png\">
  500. </a>
  501. </td>
  502. <td>
  503. <a class=\"social_media\" href=\"https://www.inverlec.solar\">
  504. <span class=\"inversol_black_text\">www.</span><span class=\"inversol_yellow_text\">inverlec</span><span class=\"inversol_black_text\">.solar</span>
  505. </a>
  506. </td>
  507. </tr>
  508. </table>
  509. </td>
  510. </tr>
  511. </tbody>
  512. </table>
  513. </td>
  514. </tr>
  515. </tbody>
  516. </table>
  517. </body>
  518. </html>
  519. ";
  520. }elseif($persona['Plantilla']=='METCO'){
  521. $style = "@font-face{
  522. font-family:HelveticaNeueLTStd-Lt;
  523. src:url(../Tipografias/HelveticaNeueLTStd-Lt.ttf);
  524. }
  525. @font-face{
  526. font-family:VAGRoundedStd-Light;
  527. src:url(../Tipografias/VAGRoundedStd-Light.otf);
  528. }
  529. .metco_name_yellow{
  530. font-family: Helvetica, sans-serif;
  531. color: #DE8C33;
  532. font-size: 15pt;
  533. font-weight: bold;
  534. }
  535. .metco_name_black{
  536. font-family: Helvetica, sans-serif;
  537. color: black;
  538. font-size: 15pt;
  539. font-weight: bold;
  540. }
  541. .metco_puesto{
  542. font-family: Helvetica, sans-serif;
  543. color: black;
  544. font-size: 15pt;
  545. }
  546. td{
  547. font-family: HelveticaNeueLTStd-Lt;
  548. }
  549. .metco_yellow_text{
  550. color: #DE8C33;
  551. font-size: 11pt;
  552. font-family: Helvetica, sans-serif;
  553. font-weight: bold;
  554. }
  555. .metco_gray_text{
  556. color: black;
  557. font-size: 11pt;
  558. font-family: Helvetica, sans-serif;
  559. }
  560. ";
  561. $body =" <table>
  562. <tbody>
  563. <tr>
  564. <td colspan=\"2\">
  565. <span class=\"metco_name_yellow\">".$persona['Primer Nombre']."</span> <span class=\"metco_name_black\">".$persona['Primer Apellido']."</span>
  566. <p style=\"margin-top:1%\"><span class=\"metco_puesto\">".$persona['Puesto']."</span></p>
  567. </td>
  568. </tr>
  569. <tr height=\"10\"></tr>
  570. <tr>
  571. <td width=\"200\" style=\"border-right:2px solid #DE8C33;\">
  572. <img src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_METCO_Logo.png\" width=\"200\" height=\"80\">
  573. </td>
  574. <td width=\"900\" style=\"margin-left:2px;\">
  575. <table>
  576. <tbody>
  577. <tr align=\"left\">
  578. <td>
  579. <span style=\"color: #80888F\"><span class=\"metco_yellow_text\">T.</span><span class=\"metco_gray_text\">".$persona['Telefono']."</span> &nbsp;
  580. <span class=\"metco_yellow_text\">C.</span><span class=\"metco_gray_text\">".$persona['Celular']."</span></span>
  581. </td>
  582. </tr>
  583. <tr>
  584. <td>
  585. <a href=\"mailto:".$persona['Correo']."\"><span class=\"metco_yellow_text\">".$email_id."</span><span class=\"metco_gray_text\">@".$email_domain."</span></a>
  586. </td>
  587. </tr>
  588. <tr>
  589. <td>
  590. <a href=\"https://www.".$persona['LinkedIn']."\"> <span class=\"metco_gray_text\">".$site."/".$type."/"."</span><span class=\"metco_yellow_text\">".$identifier."</span></a>
  591. </td>
  592. </tr>
  593. <tr>
  594. <td>
  595. <table>
  596. <tr>
  597. <td>
  598. <a class=\"social_media\" href=\"https://www.linkedin.com/company/mexicanenergytradingco/\">
  599. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_METCO_Logo-02.png\">
  600. </a>
  601. </td>
  602. <td>
  603. <a class=\"social_media\" href=\"https://www.facebook.com/MexicanEnergyTradingCo/\">
  604. <img width=\"20\" height=\"20\" src=\"https://www.mercadoselectricos.com.sv/wp-content/uploads/2019/12/IMG_METCO_Logo-03.png\">
  605. </a>
  606. </td>
  607. <td>
  608. <a class=\"social_media\" href=\"http://www.mexicantradingco.com.mx\">
  609. <span class=\"metco_gray_text\">www.</span><span class=\"metco_yellow_text\">mexicantradingco</span><span class=\"metco_gray_text\">.com.mx</span>
  610. </a>
  611. </td>
  612. </tr>
  613. </table>
  614. </td>
  615. </tr>
  616. </tbody>
  617. </table>
  618. </td>
  619. </tr>
  620. </tbody>
  621. </table>
  622. </body>
  623. </html>
  624. ";
  625. }else{
  626. $body = "";
  627. print("NO ESTA ASIGNADO A NINGUNA PLANTILLA, REVISE LOS DATOS");
  628. }
  629. $general_style ="
  630. a {
  631. text-decoration: none;
  632. display:table-cell;
  633. vertical-align:middle;
  634. }
  635. .social_media{
  636. padding-right:4px;
  637. }
  638. ";
  639. $html_header ="<html>
  640. <head>
  641. </head>
  642. <body>
  643. <style> "." ".$style.$general_style."
  644. </style>";
  645. fwrite($firma,$html_header.$body);
  646. return $file_name;
  647. }
  648. /**
  649. * comentario sobre generarTodas():
  650. * ESTA FUNCION GENERA TODAS LAS FIRMAS EN HTML Y LAS AGREGA A UN ARCHIVO ZIP
  651. * SE DA POR ALUDIDO QUE LAS IMAGENES Y FUENTE QUE CONSUME CADA VISTA, SE ENCUENTRAN EN
  652. * UN SERVIDOR EN LINEA,LISTO PARA SERVIRLOS.
  653. */
  654. public function generarTodas(){
  655. $File = $this->data_file();
  656. $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
  657. $spreadsheet= $reader->load($File);
  658. $sheet = $spreadsheet->getActiveSheet();
  659. $fila_maxima = $sheet->getHighestDataRow();
  660. #obteniendo headers
  661. $headers=[];
  662. foreach($sheet->getRowIterator(1,1) as $row){
  663. $cellIterator = $row->getCellIterator();
  664. $cellIterator->setIterateOnlyExistingCells(false);
  665. foreach($cellIterator as $cell){
  666. $headers[] = $cell->getCalculatedValue();
  667. }
  668. }
  669. #obteniendo datos de las personas
  670. $file_names=[];
  671. $file_dirs=[];
  672. foreach($sheet->getRowIterator(2,$fila_maxima) as $row){
  673. $cellIterator = $row->getCellIterator();
  674. $cellIterator->setIterateOnlyExistingCells(false);
  675. $i=0;
  676. $persona=[];
  677. foreach($cellIterator as $cell){
  678. $persona[$headers[$i]] = $cell->getCalculatedValue();
  679. $i++;
  680. }
  681. $file_names[]=$persona['Plantilla']."_".$persona['Nombre Completo'].".html";
  682. $file_dirs[]=$this->generarHTML($persona);
  683. }
  684. $i=0;
  685. $zip = new ZipArchive();
  686. $zip_name = "paquete_firmas.zip";
  687. $zip->open($zip_name,ZipArchive::CREATE);
  688. foreach($file_dirs as $file){
  689. $zip->addFile($file,$file_names[$i]);
  690. $i++;
  691. }
  692. $zip->close();
  693. // Creamos las cabezeras que forzaran la descarga del archivo como archivo zip.
  694. header("Content-type: application/octet-stream");
  695. header("Content-disposition: attachment; filename=".$zip_name);
  696. // leemos el archivo creado
  697. readfile($zip_name);
  698. // Por último eliminamos el archivo temporal creado
  699. unlink($zip_name);//Destruye el archivo temporal
  700. }
  701. /*
  702. *método para guardar en una base de datos
  703. public function guardar()
  704. {
  705. if ($_POST){
  706. $this->FirmaModel->guardar($_POST);
  707. $ruta = base_url();
  708. echo "<script>
  709. window.location = '{$ruta}';
  710. </script>";
  711. }
  712. }*/
  713. }