<?php

/**
 * secuestro actions.
 *
 * @package    cobro_coactivo
 * @subpackage secuestro
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class secuestroActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executePdf(sfWebRequest $request) {

        //Revisar que sea post
        //$this->forward404Unless($request->isMethod('post'));
        //Guardar los parametros del request en el log
        $this->logMessage("---BEGIN Logging request");
        foreach ($request->getPostParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("--------------------------------------------------* Ip: " . $_SERVER['REMOTE_ADDR']);
        foreach ($request->getGetParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("---END Logging request");

        $id_secuestro = $request['id_secuestro'];

        $pdf = new CDPDF('P', 'mm', 'letter');
        
        $pdf->SetFont('Times', '', 10);
        $pdf->SetFillColor(255);
        $pdf->SetTextColor(0);
        $pdf->setTipo(1);
        
        $pdf->setTitulo("OFICINA ASESORA JURÍDICA<br/>GRUPO COBRO COACTIVO");         
	$pdf->AddPage();
        
        $consul = Doctrine_Manager::getInstance()->connection();

        $sql = "select tab0.* from cbr_secuestro tab0 where tab0.id_secuestro=" . $id_secuestro;
        $st = $consul->execute($sql);
        $datos = $st->fetchAll();
        
        $detalle = $datos[0]['DETALLE_PLANTILLA'];
        
        $html='<table cellpadding="2"><tr><td>'.$this->htmlClear($detalle).'</td></tr></table>';
        
        //echo $html;
        
        $pdf->writeHTML($html, true, false, true, false, '');

        $pdf->Output("secuestro", "D");
        
        
  }
  
  
      private function htmlClear($string) {
        
        $string = str_replace('<p>', '<p align="justify">', $string);
        $string = str_replace('<br>', '<br/>', $string);
        $string = str_replace('class=', '', $string);
        $string = str_replace('<img', '', $string);
        $string = str_replace('<td>X</td>', '<td align="center">X</td>', $string);
        //$string = str_replace('<td align="top">', '<td align="justify">', $string);
        //$string = str_replace('<td align="justify">X</td>', '<td align="center">X</td>', $string);
        $string = str_replace('<td rowspan="2">', '<td rowspan="2" align="justify">', $string);

        $string = str_replace('<font size="2">', '<font size="10">', $string);
        $string = str_replace('<font size="3">', '<font size="12">', $string);
        $string = str_replace('<font size="4">', '<font size="14">', $string);
        $string = str_replace('<font size="5">', '<font size="18">', $string);
        $string = str_replace('<font size="6">', '<font size="24">', $string);
        $string = str_replace('<font size="7">', '<font size="36">', $string);
	$string = str_replace('<table ', '<center><table ', $string);
        $string = str_replace('</table> ', '</table></center>', $string);
        $string = str_replace('<table ', '<table border="1"', $string);
        
        $string = str_replace('size="2"', 'size="8"', $string);
        $string = str_replace('size="2"', 'size="10"', $string);
        $string = str_replace('size="3"', 'size="12"', $string);
        $string = str_replace('size="4"', 'size="14"', $string);
        $string = str_replace('size="5"', 'size="18"', $string);
        $string = str_replace('size="6"', 'size="24"', $string);
        $string = str_replace('size="7"', 'size="36"', $string);

	$string = str_replace('border="0"', 'border="1"', $string);
        
        
        $string = str_replace('<div>', '<div align="justify">', $string);
	$string = str_replace('&amp;amp;amp;nbsp;', ' ', $string);
        $string = str_replace('&amp;amp;nbsp;', '', $string);
        $string = str_replace('<style type="text/css">P { margin-bottom: 0.08in; direction: ltr; color: rgb(0, 0, 0); line-height: 100%; text-align: justify; widows: 2; orphans: 2; }P.western { font-family: "Tahoma",sans-serif; font-size: 11pt; }P.cjk { font-family: "Times New Roman",serif; font-size: 11pt; }P.ctl { font-family: "Tahoma",sans-serif; font-size: 11pt; }A:link { color: rgb(0, 0, 255); }</style>', ' ', $string);

        $string = str_replace('<td colspan="2">', '<td colspan="2" align="justify">', $string);
        $string = str_replace('<td rowspan="3">', '<td rowspan="3" align="justify">', $string);
        $string = str_replace('<td colspan="3">', '<td colspan="3" align="justify">', $string);
        $string = str_replace('<td rowspan="4">', '<td rowspan="4" align="justify">', $string);
        $string = str_replace('<td colspan="4">', '<td colspan="4" align="justify">', $string);
        $string = str_replace('  ', ' ', $string);
        $string = str_replace('   ', ' ', $string);
        $string = str_replace('    ', ' ', $string);
        $string = str_replace('	    ', ' ', $string);
        $string = str_replace('		    ', ' ', $string);
        $string = str_replace('<span lang="ES-TRAD">', '', $string);
        $string = str_replace('<span lang="ES-COL">', '', $string);
        $string = str_replace('<!-- @page { size: 21cm 29.7cm; margin: 2cm } P { margin-bottom: 0.21cm } -->', '', $string);
        $string = str_replace('<p lang="es-MX" align="justify">', '', $string);
        $string = str_replace('<span>', '', $string);
        //$string = str_replace('</span>', '', $string); #Este es el que MAS jode :::::::::::::::::
        $string = str_replace('valign', 'align', $string);
        ;
        $string = str_replace('width=', '', $string);
        //    $string = str_replace('&nbsp;', '', $string);
        //      $string = str_replace('cellspacing=', '', $string);
        //      $string = str_replace('cellpadding=', '', $string);
        $string = str_replace('bordercolor=', '', $string);
        $string = str_replace('<td>', '<td align="justify">', $string);
        $string = str_replace('<li>', '<li align="justify">', $string);
        $string = str_replace('style=', '', $string);

        return trim($string);
    }
}
