示例#1
0
 /**
  * Replace Grid Values
  * The tag @>GRID-NAME to open the grid and @<GRID-NAME to close the grid,
  *
  * @param type String $sContent
  * @param type Array $aFields
  * @return type String
  */
 public function replaceDataGridField($sContent, $aFields, $nl2brRecursive = true)
 {
     $nrt = array("\n", "\r", "\t");
     $nrthtml = array("(n /)", "(r /)", "(t /)");
     $sContent = G::unhtmlentities($sContent);
     $strContentAux = str_replace($nrt, $nrthtml, $sContent);
     $iOcurrences = preg_match_all('/\\@(?:([\\>])([a-zA-Z\\_]\\w*)|([a-zA-Z\\_][\\w\\-\\>\\:]*)\\(((?:[^\\\\\\)]*(?:[\\\\][\\w\\W])?)*)\\))((?:\\s*\\[[\'"]?\\w+[\'"]?\\])+)?/', $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
     if ($iOcurrences) {
         $arrayGrid = array();
         for ($i = 0; $i <= $iOcurrences - 1; $i++) {
             $arrayGrid[] = $arrayMatch1[2][$i][0];
         }
         $arrayGrid = array_unique($arrayGrid);
         foreach ($arrayGrid as $index => $value) {
             if ($value !== "") {
                 $grdName = $value;
                 $strContentAux1 = $strContentAux;
                 $strContentAux = null;
                 $ereg = "/^(.*)@>" . $grdName . "(.*)@<" . $grdName . "(.*)\$/";
                 while (preg_match($ereg, $strContentAux1, $arrayMatch2)) {
                     $strData = null;
                     if (isset($aFields[$grdName]) && is_array($aFields[$grdName])) {
                         foreach ($aFields[$grdName] as $aRow) {
                             if ($nl2brRecursive) {
                                 foreach ($aRow as $sKey => $vValue) {
                                     if (!is_array($vValue)) {
                                         $aRow[$sKey] = str_replace($nrt, $nrthtml, nl2br($aRow[$sKey]));
                                     }
                                 }
                             }
                             $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow);
                         }
                     }
                     $strContentAux1 = $arrayMatch2[1];
                     $strContentAux = $strData . $arrayMatch2[3] . $strContentAux;
                 }
                 $strContentAux = $strContentAux1 . $strContentAux;
             }
         }
     }
     $strContentAux = str_replace($nrthtml, $nrt, $strContentAux);
     $sContent = $strContentAux;
     if ($nl2brRecursive) {
         foreach ($aFields as $sKey => $vValue) {
             if (!is_array($vValue)) {
                 $aFields[$sKey] = nl2br($aFields[$sKey]);
             }
         }
     }
     $sContent = G::replaceDataField($sContent, $aFields);
     return $sContent;
 }
示例#2
0
 /**
  * @covers G::unhtmlentities
  * @todo   Implement testUnhtmlentities().
  */
 public function testUnhtmlentities()
 {
     $response = G::unhtmlentities('&aacute;rbol');
     $this->assertEquals($response, 'árbol');
 }
示例#3
0
 /**
  * Show dynaform column
  *
  * @author Fernando Ontiveros Lira <*****@*****.**>
  * @access public
  * @param $intPos
  * @param $strClass
  * @param $strClassLink
  * @param $number
  * @param $renderTD   if this value = 1, this function will include the TD tags
  * @return void
  */
 function RenderColumn($intPos = 0, $strClass = "tblCell", $strClassLink = "tblCellA", $number = 0, $renderTD = 1)
 {
     if (!defined('ENABLE_ENCRYPT')) {
         define('ENABLE_ENCRYPT', 'no');
     }
     global $G_DATE_FORMAT;
     global $G_TABLE_DATE_FORMAT;
     $col = $this->Columns[$intPos];
     switch (substr($col['Name'], 0, 1)) {
         case '=':
             // Si empieza con '=' entonces se toma como valor constante
             $val = substr($col['Name'], 1, strlen($col['Name']) - 1);
             break;
         case '%':
             // Si empieza con '%' entonces traducir/convertir el valor
             $fieldname = substr($col['Name'], 1, strlen($col['Name']) - 1);
             $val = $this->_row_values[$fieldname];
             $val = $this->translateValue($this->_contexto, $val, SYS_LANG);
             break;
         default:
             $fieldname = $col['Name'];
             $val = isset($this->_row_values[$fieldname]) ? $this->_row_values[$fieldname] : '';
     }
     $res = "";
     if ($this->show_nummbers and $intPos == 0) {
         $res = "<td>{$number}</td>";
     }
     if (!(stristr($val, "script") === false)) {
         $val = htmlentities($val, ENT_QUOTES, 'utf-8');
     }
     if ($renderTD == 1) {
         $res .= "<td class=\"{$strClass}\" align=\"" . $col["Align"] . "\" height=\"25\"";
         if ($col["Width"] > 0) {
             $res .= " width=\"" . $col["Width"] . "\"";
         }
         $res .= ">&nbsp;";
     }
     switch ($col["Type"]) {
         case 'hidden':
             return '';
             break;
         case "text":
             if ($val != "") {
                 $res .= G::unhtmlentities($val, ENT_QUOTES, 'utf-8');
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "text-dontSearch":
             if ($val != "") {
                 $res .= G::unhtmlentities($val);
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "html":
             if ($val != "") {
                 $res .= $val;
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "textPlain":
             if ($val != "") {
                 $res .= $this->ParsingFromHtml(G::unhtmlentities($val), "300");
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "currency":
             if ($val != "") {
                 $aux = explode(' ', $val);
                 $format = number_format((double) $aux[0], 2, ".", ",");
                 $res .= htmlentities($format . ' ' . (isset($aux[1]) ? $aux[1] : ''), ENT_QUOTES, 'utf-8');
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "currency2":
             if ($val != "") {
                 $res .= G::NumberToCurrency($val);
             } else {
                 $res .= "\$ 0.00";
             }
             break;
         case "percentage2":
             if ($val != "") {
                 $res .= G::NumberToPercentage($val);
             } else {
                 $res .= "0.00 %";
             }
             break;
         case "percentage":
             if ($val != "") {
                 $res .= htmlentities(number_format((double) $val, 2, ".", ",") . " %", ENT_QUOTES, 'utf-8');
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "date":
             if ($val != "" && $val != '0000-00-00 00:00:00') {
                 $part = explode(' ', $val);
                 $aux = explode('-', $part[0]);
                 switch ($G_DATE_FORMAT) {
                     case 'DD/MM/AAAA':
                         $res .= formatDate('$d/$m/$Y $H:$i:$s', $val);
                         break;
                     case 'MM/DD/AAAA':
                         $res .= formatDate('$m/$d/$Y $H:$i:$s <small>EST</small>', $val);
                         break;
                     case 'AAAA/MM/DD':
                         $res .= formatDate('$Y/$m/$d $H:$i:$s', $val);
                         break;
                     case 'LITERAL':
                         $res .= formatDate('$M $d $Y', $val);
                         break;
                 }
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "email":
             if ($val != "") {
                 $res .= "<a href=\"mailto:" . $val . "\">";
                 $res .= $val;
                 $res .= "</a>";
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "ifpdf":
             if ($val == '1') {
                 $image = "<img border=0 src='/images/pdf.gif'>";
                 //valor
                 $tlabel = substr($col["Content"], 0, 1);
                 $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                 $lval = $this->_row_values[$vname];
                 //$res .= "<a href='" . $col["Target"] . "/" . $lval . "' target='_new' > $image</a> "; //It open a new window... better the other way By JHL 16/11/06
                 $res .= "<a href='" . $col["Target"] . "/" . $lval . "'  > {$image}</a> ";
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "ifimg":
             $image = "<img border=0 src='" . $col['Extra'] . "' >";
             if ($val == '1') {
                 //valor
                 $tlabel = substr($col["Content"], 0, 1);
                 $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                 $lval = $this->_row_values[$vname];
                 $res .= "<a href='" . $col["Target"] . "/" . $lval . "' > {$image}</a> ";
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "ifrtf":
             if ($val == '1') {
                 $image = "<img border=0 src='/images/word.gif'>";
                 //valor
                 $tlabel = substr($col["Content"], 0, 1);
                 $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                 $lval = $this->_row_values[$vname];
                 //$res .= "<a href='" . $col["Target"] . $lval . "' target='_new' > $image</a> "; //It open a new window... better the other way By JHL 16/11/06
                 $res .= "<a href='" . $col["Target"] . $lval . "' > {$image}</a> ";
             } else {
                 $res .= "&nbsp;";
             }
             break;
         case "image":
             if (is_array($col["Condition"])) {
                 $field_compare = $col["Condition"]['field'];
                 $tlabel = substr($field_compare, 0, 1);
                 switch ($tlabel) {
                     case "&":
                         $vname = substr($field_compare, 1, strlen($field_compare) - 1);
                         $field_val = $this->_row_values[$vname];
                         break;
                 }
             } else {
                 $val = "<img border=0 src='{$fieldname}'>";
             }
             //      break;
         //      break;
         case "textimage":
             $AAS = $col['Extra'];
             $val1 = " <img border=0 src='{$AAS}' align='middle'>";
             //      break;
         //      break;
         case "image-text":
             if (is_array($col['Content']) && $col['Content'] != "") {
                 // Hay mas de un valor para el link
                 $values = $col['Content'];
                 $n = count($values);
                 $res .= "<a class='{$txtin3}' {$title} href=\"" . (ENABLE_ENCRYPT == 'yes' ? G::encryptUrl(urldecode($col["Target"]), URL_KEY) : $col["Target"]) . "/";
                 for ($i = 0; $i < $n; $i++) {
                     $element = $values[$i];
                     $tlabel = substr($element, 0, 1);
                     switch ($tlabel) {
                         case "&":
                             $vname = substr($element, 1, strlen($element) - 1);
                             $lval = $this->_row_values[$vname];
                             $res .= $i == $n - 1 ? $lval : $lval . "/";
                             break;
                     }
                 }
                 $res .= "\"><span class='txtin3'>" . strtoupper($fieldname) . "{$val}</span></a>";
             } else {
                 $val2 = "<span class='txtin3'>" . strtoupper($fieldname) . "</span>";
             }
             //      break;
         //      break;
         case "link":
             if ($val == "") {
                 $res .= "&nbsp;";
             }
             $title = '';
             if ($col["Type"] == 'link' && trim(isset($this->_row_values['TOOLTIP']) ? $this->_row_values['TOOLTIP'] : '')) {
             }
             $title = isset($this->_row_values['TOOLTIP']) ? "title=\" " . $this->_row_values['TOOLTIP'] . " \"" : '';
             if (is_array($col['Content']) && $col['Content'] != "") {
                 // Hay mas de un valor para el link
                 $values = $col['Content'];
                 $n = count($values);
                 $res .= "<a class='{$strClassLink}' {$title} href=\"" . (ENABLE_ENCRYPT == 'yes' ? G::encryptUrl(urldecode($col["Target"]), URL_KEY) : $col["Target"]) . "/";
                 for ($i = 0; $i < $n; $i++) {
                     $element = $values[$i];
                     $tlabel = substr($element, 0, 1);
                     switch ($tlabel) {
                         case "&":
                             $vname = substr($element, 1, strlen($element) - 1);
                             $lval = $this->_row_values[$vname];
                             $res .= $i == $n - 1 ? $lval : $lval . "/";
                             break;
                     }
                 }
                 $res .= "\">{$val}</a>";
             } elseif ($col["Content"] != "" && !is_array($col['Content'])) {
                 $tlabel = substr($col["Content"], 0, 1);
                 switch ($tlabel) {
                     case "&":
                         $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                         $lval = $this->_row_values[$vname];
                         if (ENABLE_ENCRYPT == 'yes') {
                             //$encoded = G::encrypt ( $col["Target"] . "/" . $lval . ".html", URL_KEY );
                             $encoded = G::encryptUrl($col["Target"] . "/" . $lval . ".html", URL_KEY);
                             $res .= "<a class='{$strClassLink}' {$title} href=\"" . $encoded . "\" " . $col['Extra'] . ">";
                             if ($col["Type"] == "textimage") {
                                 $res .= $val1;
                                 $val = " (" . $val . ")";
                             }
                             if ($col["Type"] == "image-text") {
                                 $res .= $val2;
                             }
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                         } else {
                             $res .= "<a class='{$strClassLink}' {$title} href=\"" . $col["Target"] . "/" . $lval . ".html\" " . $col['Extra'] . ">";
                             if ($col["Type"] == "textimage") {
                                 $res .= $val1;
                                 $val = " (" . $val . ")";
                             }
                             if ($col["Type"] == "image-text") {
                                 $res .= $val2;
                             }
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                         }
                         break;
                     case "\$":
                         $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                         $lval = $HTTP_SESSION_VARS[$vname];
                         $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $lval . ".html\" " . $col['Extra'] . ">";
                         $res .= $val;
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                     default:
                         $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" " . $col['Extra'] . ">";
                         $res .= $col["Content"];
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                 }
             } else {
                 $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" " . $col['Extra'] . ">";
                 $res .= $val;
                 $res .= "</a" . $col['Extra'] . ">";
             }
             break;
         case "linknew":
             if ($val == "") {
                 $res .= "&nbsp;";
             }
             if ($col["Content"] != "") {
                 $tlabel = substr($col["Content"], 0, 1);
                 switch ($tlabel) {
                     case "&":
                         if (ENABLE_ENCRYPT == 'yes') {
                             $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                             $lval = $this->_row_values[$vname];
                             //$encoded = G::encryptUrl ( $col["Target"] , URL_KEY ). "/" . $lval . ".html";
                             $encoded = G::encryptUrl($col["Target"] . "/" . $lval . "", URL_KEY);
                             $res .= "<a class='{$strClassLink}' href=\"" . $encoded . "\" " . " target=\"_new\"" . $col['Extra'] . ">";
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                         } else {
                             $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                             $lval = $this->_row_values[$vname];
                             $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $lval . "\" target=\"_new\"" . $col['Extra'] . ">";
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                         }
                         break;
                     case "\$":
                         $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                         $lval = $HTTP_SESSION_VARS[$vname];
                         $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $lval . ".html\" target=\"_new\"" . $col['Extra'] . ">";
                         $res .= $val;
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                     default:
                         $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" target=\"_new\"" . $col['Extra'] . ">";
                         $res .= $col["Content"];
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                 }
             } else {
                 $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" target=\"_new\"" . $col['Extra'] . ">";
                 $res .= $val;
                 $res .= "</a" . $col['Extra'] . ">";
             }
             break;
         case "iflink":
             if ($col["Content"] != "") {
                 $tlabel = substr($col["Content"], 0, 1);
                 if ($val != "") {
                     switch ($tlabel) {
                         case "&":
                             $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                             $lval = $this->_row_values[$vname];
                             $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $lval . ".html\" " . $col['Extra'] . ">";
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                             break;
                         case "\$":
                             $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                             $lval = $HTTP_SESSION_VARS[$vname];
                             $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $lval . ".html\" " . $col['Extra'] . ">";
                             $res .= $val;
                             $res .= "</a" . $col['Extra'] . ">";
                             break;
                         default:
                             $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" " . $col['Extra'] . ">";
                             $res .= $col["Content"];
                             $res .= "</a" . $col['Extra'] . ">";
                             break;
                     }
                 } else {
                     $res .= "&nbsp;";
                 }
             } else {
                 $res .= "<a class='{$strClassLink}' href=\"" . $col["Target"] . "/" . $val . ".html\" " . $col['Extra'] . ">";
                 $res .= $val;
                 $res .= "</a" . $col['Extra'] . ">";
             }
             break;
         case "jsimglink":
             $val = "<img border=0 src='{$fieldname}'>";
         case "jslink":
             if ($val == "") {
                 $val .= "<span class='txtin3'> " . $col['Name'] . '<span>';
             }
             if ($val == "") {
                 $res .= "&nbsp;";
             }
             if ($col["Content"] != "") {
                 $tlabel = substr($col["Content"], 0, 1);
                 switch ($tlabel) {
                     case "&":
                         $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                         $lval = $this->_row_values[$vname];
                         $res .= "<a class='{$strClassLink}' href=\"javascript:" . $col["Target"] . "('" . $lval . "')\"" . $col['Extra'] . ">";
                         $res .= $val;
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                     case "\$":
                         $vname = substr($col["Content"], 1, strlen($col["Content"]) - 1);
                         $lval = $HTTP_SESSION_VARS[$vname];
                         $res .= "<a class='{$strClassLink}' href=\"javascript:" . $col["Target"] . "('" . $lval . "')\"" . $col['Extra'] . ">";
                         $res .= $val;
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                     case '_':
                         $Values = explode(',', substr($col['Content'], 1, strlen($col['Content'])));
                         $res .= "<a class='{$strClassLink}' href=\"javascript:" . $col["Target"] . "(";
                         foreach ($Values as $Value) {
                             if (substr($Value, 0, 1) == '&') {
                                 if (is_numeric($Value)) {
                                     $res .= $this->_row_values[substr($Value, 1, strlen($Value))] . ',';
                                 } else {
                                     $res .= "'" . $this->_row_values[substr($Value, 1, strlen($Value))] . "',";
                                 }
                             } else {
                                 $res .= $Value . ',';
                             }
                         }
                         $res = substr($res, 0, strlen($res) - 1);
                         $res .= ")\"" . $col['Extra'] . ">";
                         $res .= $val;
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                     default:
                         $res .= "<a class='{$strClassLink}' href=\"javascript:" . $col["Target"] . "('" . $val . "')\"" . $col['Extra'] . ">";
                         $res .= $col["Content"];
                         $res .= "</a" . $col['Extra'] . ">";
                         break;
                 }
             } else {
                 $res .= "<a  class='{$strClassLink}' href=\"javascript:" . $col["Target"] . "(" . $val . ")\"" . $col['Extra'] . ">";
                 $res .= $val;
                 $res .= "</a" . $col['Extra'] . ">";
             }
             break;
         case "checkbox":
             $res .= "<input type='checkbox' name=\"form[" . $fieldname . "][" . $val . "]\" ";
             if ($val == '1' || $val == 'TRUE' || $val == 'yes') {
                 $res .= " checked ";
             }
             $res .= " disabled='disabled' >";
             break;
     }
     if ($renderTD == 1) {
         $res .= "</td>\n";
     }
     return $res;
     //return $res . $strClass;
 }
 /**
  * TemplatePower::__outputContent()
  *
  * @param string $blockname
  * @return void
  * @access private
  */
 public function __outputContent($blockname)
 {
     $numrows = sizeof($this->content[$blockname]);
     for ($i = 0; $i < $numrows; $i++) {
         $defblockname = $this->content[$blockname][$i][0];
         for (reset($this->defBlock[$defblockname]); $k = key($this->defBlock[$defblockname]); next($this->defBlock[$defblockname])) {
             if ($k[1] == 'C') {
                 print $this->defBlock[$defblockname][$k];
             } elseif ($k[1] == 'V') {
                 $defValue = $this->defBlock[$defblockname][$k];
                 if (!isset($this->content[$blockname][$i]["_V:" . $defValue])) {
                     if (isset($this->globalvars[$defValue])) {
                         $value = $this->globalvars[$defValue];
                     } else {
                         //Verify if $defValue is like
                         //                            "xmlfile:ID_LABEL"
                         //if it is load an xml label.
                         //if not continues with non assigned value.
                         if (preg_match("/(.+):(.+)/", $defValue, $xmlreg)) {
                             $value = G::LoadTranslation($xmlreg[2]);
                         } else {
                             if ($this->showUnAssigned) {
                                 //$value = '{'. $this->defBlock[ $defblockname ][$k] .'}';
                                 $value = '{' . $defValue . '}';
                             } else {
                                 $value = '';
                             }
                         }
                     }
                 } else {
                     $value = $this->content[$blockname][$i]["_V:" . $defValue];
                 }
                 if ($this->unhtmlentities) {
                     $value = G::unhtmlentities($value);
                 }
                 print $value;
             } elseif ($k[1] == 'B') {
                 if (isset($this->content[$blockname][$i][$k])) {
                     $this->__outputContent($this->content[$blockname][$i][$k]);
                 }
             }
         }
     }
 }
    public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array())
    {
        if ($sUID != '' && is_array($aFields) && $sPath != '') {
            $nrt = array("\n", "\r", "\t");
            $nrthtml = array("(n /)", "(r /)", "(t /)");
            $sContent = G::unhtmlentities($sContent);
            $strContentAux = str_replace($nrt, $nrthtml, $sContent);
            $iOcurrences = preg_match_all('/\\@(?:([\\>])([a-zA-Z\\_]\\w*)|([a-zA-Z\\_][\\w\\-\\>\\:]*)\\(((?:[^\\\\\\)]*(?:[\\\\][\\w\\W])?)*)\\))((?:\\s*\\[[\'"]?\\w+[\'"]?\\])+)?/', $strContentAux, $arrayMatch1, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
            if ($iOcurrences) {
                $arrayGrid = array();
                for ($i = 0; $i <= $iOcurrences - 1; $i++) {
                    $arrayGrid[] = $arrayMatch1[2][$i][0];
                }
                $arrayGrid = array_unique($arrayGrid);
                foreach ($arrayGrid as $index => $value) {
                    $grdName = $value;
                    $strContentAux1 = $strContentAux;
                    $strContentAux = null;
                    $ereg = "/^(.*)@>" . $grdName . "(.*)@<" . $grdName . "(.*)\$/";
                    while (preg_match($ereg, $strContentAux1, $arrayMatch2)) {
                        $strData = null;
                        if (isset($aFields[$grdName]) && is_array($aFields[$grdName])) {
                            foreach ($aFields[$grdName] as $aRow) {
                                foreach ($aRow as $sKey => $vValue) {
                                    if (!is_array($vValue)) {
                                        $aRow[$sKey] = nl2br($aRow[$sKey]);
                                    }
                                }
                                $strData = $strData . G::replaceDataField($arrayMatch2[2], $aRow);
                            }
                        }
                        $strContentAux1 = $arrayMatch2[1];
                        $strContentAux = $strData . $arrayMatch2[3] . $strContentAux;
                    }
                    $strContentAux = $strContentAux1 . $strContentAux;
                }
            }
            $strContentAux = str_replace($nrthtml, $nrt, $strContentAux);
            $sContent = $strContentAux;
            foreach ($aFields as $sKey => $vValue) {
                if (!is_array($vValue)) {
                    $aFields[$sKey] = nl2br($aFields[$sKey]);
                }
            }
            $sContent = G::replaceDataField($sContent, $aFields);
            G::verifyPath($sPath, true);
            //Start - Create .doc
            $oFile = fopen($sPath . $sFilename . '.doc', 'wb');
            $size = array();
            $size["Letter"] = "216mm  279mm";
            $size["Legal"] = "216mm  357mm";
            $size["Executive"] = "184mm  267mm";
            $size["B5"] = "182mm  257mm";
            $size["Folio"] = "216mm  330mm";
            $size["A0Oversize"] = "882mm  1247mm";
            $size["A0"] = "841mm  1189mm";
            $size["A1"] = "594mm  841mm";
            $size["A2"] = "420mm  594mm";
            $size["A3"] = "297mm  420mm";
            $size["A4"] = "210mm  297mm";
            $size["A5"] = "148mm  210mm";
            $size["A6"] = "105mm  148mm";
            $size["A7"] = "74mm   105mm";
            $size["A8"] = "52mm   74mm";
            $size["A9"] = "37mm   52mm";
            $size["A10"] = "26mm   37mm";
            $size["Screenshot640"] = "640mm  480mm";
            $size["Screenshot800"] = "800mm  600mm";
            $size["Screenshot1024"] = "1024mm 768mm";
            $sizeLandscape["Letter"] = "279mm  216mm";
            $sizeLandscape["Legal"] = "357mm  216mm";
            $sizeLandscape["Executive"] = "267mm  184mm";
            $sizeLandscape["B5"] = "257mm  182mm";
            $sizeLandscape["Folio"] = "330mm  216mm";
            $sizeLandscape["A0Oversize"] = "1247mm 882mm";
            $sizeLandscape["A0"] = "1189mm 841mm";
            $sizeLandscape["A1"] = "841mm  594mm";
            $sizeLandscape["A2"] = "594mm  420mm";
            $sizeLandscape["A3"] = "420mm  297mm";
            $sizeLandscape["A4"] = "297mm  210mm";
            $sizeLandscape["A5"] = "210mm  148mm";
            $sizeLandscape["A6"] = "148mm  105mm";
            $sizeLandscape["A7"] = "105mm  74mm";
            $sizeLandscape["A8"] = "74mm   52mm";
            $sizeLandscape["A9"] = "52mm   37mm";
            $sizeLandscape["A10"] = "37mm   26mm";
            $sizeLandscape["Screenshot640"] = "480mm  640mm";
            $sizeLandscape["Screenshot800"] = "600mm  800mm";
            $sizeLandscape["Screenshot1024"] = "768mm  1024mm";
            if (!isset($aProperties['media'])) {
                $aProperties['media'] = 'Letter';
            }
            if ($sLandscape) {
                $media = $sizeLandscape[$aProperties['media']];
            } else {
                $media = $size[$aProperties['media']];
            }
            $marginLeft = '15';
            if (isset($aProperties['margins']['left'])) {
                $marginLeft = $aProperties['margins']['left'];
            }
            $marginRight = '15';
            if (isset($aProperties['margins']['right'])) {
                $marginRight = $aProperties['margins']['right'];
            }
            $marginTop = '15';
            if (isset($aProperties['margins']['top'])) {
                $marginTop = $aProperties['margins']['top'];
            }
            $marginBottom = '15';
            if (isset($aProperties['margins']['bottom'])) {
                $marginBottom = $aProperties['margins']['bottom'];
            }
            fwrite($oFile, '<html xmlns:v="urn:schemas-microsoft-com:vml"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:w="urn:schemas-microsoft-com:office:word"
            xmlns="http://www.w3.org/TR/REC-html40">
            <head>
            <meta http-equiv=Content-Type content="text/html; charset=utf-8">
            <meta name=ProgId content=Word.Document>
            <meta name=Generator content="Microsoft Word 9">
            <meta name=Originator content="Microsoft Word 9">
            <!--[if !mso]>
            <style>
            v\\:* {behavior:url(#default#VML);}
            o\\:* {behavior:url(#default#VML);}
            w\\:* {behavior:url(#default#VML);}
            .shape {behavior:url(#default#VML);}
            </style>
            <![endif]-->
            <!--[if gte mso 9]><xml>
             <w:WordDocument>
              <w:View>Print</w:View>
              <w:DoNotHyphenateCaps/>
              <w:PunctuationKerning/>
              <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
              <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
             </w:WordDocument>
            </xml><![endif]-->

            <style>
            <!--
            @page WordSection1
             {size:' . $media . ';
             margin-left:' . $marginLeft . 'mm;
             margin-right:' . $marginRight . 'mm;
             margin-bottom:' . $marginBottom . 'mm;
             margin-top:' . $marginTop . 'mm;
             mso-header-margin:35.4pt;
             mso-footer-margin:35.4pt;
             mso-paper-source:0;}
            div.WordSection1
             {page:WordSection1;}
            -->
            </style>
            </head>
            <body>
            <div class=WordSection1>');
            fwrite($oFile, $sContent);
            fwrite($oFile, "\n</div></body></html>\n\n");
            fclose($oFile);
            /* End - Create .doc */
            if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') {
                $oFile = fopen($sPath . $sFilename . '.html', 'wb');
                fwrite($oFile, $sContent);
                fclose($oFile);
                /* Start - Create .pdf */
                if (isset($aProperties['report_generator'])) {
                    switch ($aProperties['report_generator']) {
                        case 'TCPDF':
                            $this->generateTcpdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                            break;
                        case 'HTML2PDF':
                        default:
                            $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                            break;
                    }
                } else {
                    $this->generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape, $aProperties);
                }
            }
            //end if $sTypeDocToGener
            /* End - Create .pdf */
        } else {
            return PEAR::raiseError(null, G_ERROR_USER_UID, null, null, 'You tried to call to a generate method without send the Output Document UID, fields to use and the file path!', 'G_Error', true);
        }
    }
示例#6
0
 public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array())
 {
     if ($sUID != '' && is_array($aFields) && $sPath != '') {
         $sContent = G::unhtmlentities($sContent);
         $iAux = 0;
         $iOcurrences = preg_match_all('/\\@(?:([\\>])([a-zA-Z\\_]\\w*)|([a-zA-Z\\_][\\w\\-\\>\\:]*)\\(((?:[^\\\\\\)]*(?:[\\\\][\\w\\W])?)*)\\))((?:\\s*\\[[\'"]?\\w+[\'"]?\\])+)?/', $sContent, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
         if ($iOcurrences) {
             for ($i = 0; $i < $iOcurrences; $i++) {
                 preg_match_all('/@>' . $aMatch[2][$i][0] . '([\\w\\W]*)' . '@<' . $aMatch[2][$i][0] . '/', $sContent, $aMatch2, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
                 $sGridName = $aMatch[2][$i][0];
                 $sStringToRepeat = $aMatch2[1][0][0];
                 if (isset($aFields[$sGridName])) {
                     if (is_array($aFields[$sGridName])) {
                         $sAux = '';
                         foreach ($aFields[$sGridName] as $aRow) {
                             foreach ($aRow as $sKey => $vValue) {
                                 if (!is_array($vValue)) {
                                     $aRow[$sKey] = nl2br($aRow[$sKey]);
                                 }
                             }
                             $sAux .= G::replaceDataField($sStringToRepeat, $aRow);
                         }
                     }
                 }
                 $sContent = str_replace('@>' . $sGridName . $sStringToRepeat . '@<' . $sGridName, $sAux, $sContent);
             }
         }
         foreach ($aFields as $sKey => $vValue) {
             if (!is_array($vValue)) {
                 $aFields[$sKey] = nl2br($aFields[$sKey]);
             }
         }
         $sContent = G::replaceDataField($sContent, $aFields);
         G::verifyPath($sPath, true);
         /* Start - Create .doc */
         $oFile = fopen($sPath . $sFilename . '.doc', 'wb');
         $size = array();
         $size["Letter"] = "216mm  279mm";
         $size["Legal"] = "216mm  357mm";
         $size["Executive"] = "184mm  267mm";
         $size["B5"] = "182mm  257mm";
         $size["Folio"] = "216mm  330mm";
         $size["A0Oversize"] = "882mm  1247mm";
         $size["A0"] = "841mm  1189mm";
         $size["A1"] = "594mm  841mm";
         $size["A2"] = "420mm  594mm";
         $size["A3"] = "297mm  420mm";
         $size["A4"] = "210mm  297mm";
         $size["A5"] = "148mm  210mm";
         $size["A6"] = "105mm  148mm";
         $size["A7"] = "74mm   105mm";
         $size["A8"] = "52mm   74mm";
         $size["A9"] = "37mm   52mm";
         $size["A10"] = "26mm   37mm";
         $size["Screenshot640"] = "640mm  480mm";
         $size["Screenshot800"] = "800mm  600mm";
         $size["Screenshot1024"] = "1024mm 768mm";
         $sizeLandscape["Letter"] = "279mm  216mm";
         $sizeLandscape["Legal"] = "357mm  216mm";
         $sizeLandscape["Executive"] = "267mm  184mm";
         $sizeLandscape["B5"] = "257mm  182mm";
         $sizeLandscape["Folio"] = "330mm  216mm";
         $sizeLandscape["A0Oversize"] = "1247mm 882mm";
         $sizeLandscape["A0"] = "1189mm 841mm";
         $sizeLandscape["A1"] = "841mm  594mm";
         $sizeLandscape["A2"] = "594mm  420mm";
         $sizeLandscape["A3"] = "420mm  297mm";
         $sizeLandscape["A4"] = "297mm  210mm";
         $sizeLandscape["A5"] = "210mm  148mm";
         $sizeLandscape["A6"] = "148mm  105mm";
         $sizeLandscape["A7"] = "105mm  74mm";
         $sizeLandscape["A8"] = "74mm   52mm";
         $sizeLandscape["A9"] = "52mm   37mm";
         $sizeLandscape["A10"] = "37mm   26mm";
         $sizeLandscape["Screenshot640"] = "480mm  640mm";
         $sizeLandscape["Screenshot800"] = "600mm  800mm";
         $sizeLandscape["Screenshot1024"] = "768mm  1024mm";
         if (!isset($aProperties['media'])) {
             $aProperties['media'] = 'Letter';
         }
         if ($sLandscape) {
             $media = $sizeLandscape[$aProperties['media']];
         } else {
             $media = $size[$aProperties['media']];
         }
         $marginLeft = '15';
         if (isset($aProperties['margins']['left'])) {
             $marginLeft = $aProperties['margins']['left'];
         }
         $marginRight = '15';
         if (isset($aProperties['margins']['right'])) {
             $marginRight = $aProperties['margins']['right'];
         }
         $marginTop = '15';
         if (isset($aProperties['margins']['top'])) {
             $marginTop = $aProperties['margins']['top'];
         }
         $marginBottom = '15';
         if (isset($aProperties['margins']['bottom'])) {
             $marginBottom = $aProperties['margins']['bottom'];
         }
         fwrite($oFile, '<html xmlns:v="urn:schemas-microsoft-com:vml"
   xmlns:o="urn:schemas-microsoft-com:office:office"
   xmlns:w="urn:schemas-microsoft-com:office:word"
   xmlns="http://www.w3.org/TR/REC-html40">
   <head>
   <meta http-equiv=Content-Type content="text/html; charset=utf-8">
   <meta name=ProgId content=Word.Document>
   <meta name=Generator content="Microsoft Word 9">
   <meta name=Originator content="Microsoft Word 9">
   <!--[if !mso]>
   <style>
   v\\:* {behavior:url(#default#VML);}
   o\\:* {behavior:url(#default#VML);}
   w\\:* {behavior:url(#default#VML);}
   .shape {behavior:url(#default#VML);}
   </style>
   <![endif]-->
   <!--[if gte mso 9]><xml>
    <w:WordDocument>
     <w:View>Print</w:View>
     <w:DoNotHyphenateCaps/>
     <w:PunctuationKerning/>
     <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
     <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
    </w:WordDocument>
   </xml><![endif]-->
   
   <style>
   <!--
   @page WordSection1
   	{size:' . $media . ';
   	margin-left:' . $marginLeft . 'mm; 
   	margin-right:' . $marginRight . 'mm;
   	margin-bottom:' . $marginBottom . 'mm; 
   	margin-top:' . $marginTop . 'mm;
   	mso-header-margin:35.4pt;
   	mso-footer-margin:35.4pt;
   	mso-paper-source:0;}
   div.WordSection1
   	{page:WordSection1;}
   -->
   </style>
   </head>
   <body> 
   <div class=WordSection1>');
         fwrite($oFile, $sContent);
         fwrite($oFile, "\n</div></body></html>\n\n");
         fclose($oFile);
         /* End - Create .doc */
         if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') {
             /* Start - Create .pdf */
             $oFile = fopen($sPath . $sFilename . '.html', 'wb');
             fwrite($oFile, $sContent);
             fclose($oFile);
             define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/');
             G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true);
             require_once PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php';
             require_once PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php';
             parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config');
             $GLOBALS['g_config'] = array('cssmedia' => 'screen', 'media' => 'Letter', 'scalepoints' => false, 'renderimages' => true, 'renderfields' => true, 'renderforms' => false, 'pslevel' => 3, 'renderlinks' => true, 'pagewidth' => 800, 'landscape' => $sLandscape, 'method' => 'fpdf', 'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15), 'encoding' => '', 'ps2pdf' => false, 'compress' => false, 'output' => 2, 'pdfversion' => '1.3', 'transparency_workaround' => false, 'imagequality_workaround' => false, 'draw_page_border' => isset($_REQUEST['pageborder']), 'debugbox' => false, 'html2xhtml' => true, 'mode' => 'html', 'smartpagebreak' => true);
             $GLOBALS['g_config'] = array_merge($GLOBALS['g_config'], $aProperties);
             $g_media = Media::predefined($GLOBALS['g_config']['media']);
             $g_media->set_landscape($GLOBALS['g_config']['landscape']);
             $g_media->set_margins($GLOBALS['g_config']['margins']);
             $g_media->set_pixels($GLOBALS['g_config']['pagewidth']);
             if (isset($GLOBALS['g_config']['pdfSecurity'])) {
                 if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) && $GLOBALS['g_config']['pdfSecurity']['openPassword'] != "") {
                     $GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['openPassword'], $sUID);
                 }
                 if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) && $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != "") {
                     $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['ownerPassword'], $sUID);
                 }
                 $g_media->set_security($GLOBALS['g_config']['pdfSecurity']);
                 require_once HTML2PS_DIR . 'pdf.fpdf.encryption.php';
             }
             $pipeline = new Pipeline();
             if (extension_loaded('curl')) {
                 require_once HTML2PS_DIR . 'fetcher.url.curl.class.php';
                 $pipeline->fetchers = array(new FetcherURLCurl());
                 if (isset($proxy)) {
                     if ($proxy != '') {
                         $pipeline->fetchers[0]->set_proxy($proxy);
                     }
                 }
             } else {
                 require_once HTML2PS_DIR . 'fetcher.url.class.php';
                 $pipeline->fetchers[] = new FetcherURL();
             }
             $pipeline->data_filters[] = new DataFilterDoctype();
             $pipeline->data_filters[] = new DataFilterUTF8($GLOBALS['g_config']['encoding']);
             if ($GLOBALS['g_config']['html2xhtml']) {
                 $pipeline->data_filters[] = new DataFilterHTML2XHTML();
             } else {
                 $pipeline->data_filters[] = new DataFilterXHTML2XHTML();
             }
             $pipeline->parser = new ParserXHTML();
             $pipeline->pre_tree_filters = array();
             $header_html = '';
             $footer_html = '';
             $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html);
             $pipeline->pre_tree_filters[] = $filter;
             if ($GLOBALS['g_config']['renderfields']) {
                 $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
             }
             if ($GLOBALS['g_config']['method'] === 'ps') {
                 $pipeline->layout_engine = new LayoutEnginePS();
             } else {
                 $pipeline->layout_engine = new LayoutEngineDefault();
             }
             $pipeline->post_tree_filters = array();
             if ($GLOBALS['g_config']['pslevel'] == 3) {
                 $image_encoder = new PSL3ImageEncoderStream();
             } else {
                 $image_encoder = new PSL2ImageEncoderStream();
             }
             switch ($GLOBALS['g_config']['method']) {
                 case 'fastps':
                     if ($GLOBALS['g_config']['pslevel'] == 3) {
                         $pipeline->output_driver = new OutputDriverFastPS($image_encoder);
                     } else {
                         $pipeline->output_driver = new OutputDriverFastPSLevel2($image_encoder);
                     }
                     break;
                 case 'pdflib':
                     $pipeline->output_driver = new OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']);
                     break;
                 case 'fpdf':
                     $pipeline->output_driver = new OutputDriverFPDF();
                     break;
                 case 'png':
                     $pipeline->output_driver = new OutputDriverPNG();
                     break;
                 case 'pcl':
                     $pipeline->output_driver = new OutputDriverPCL();
                     break;
                 default:
                     die('Unknown output method');
             }
             if (isset($GLOBALS['g_config']['watermarkhtml'])) {
                 $watermark_text = $GLOBALS['g_config']['watermarkhtml'];
             } else {
                 $watermark_text = '';
             }
             $pipeline->output_driver->set_watermark($watermark_text);
             if ($watermark_text != '') {
                 $dispatcher =& $pipeline->getDispatcher();
             }
             if ($GLOBALS['g_config']['debugbox']) {
                 $pipeline->output_driver->set_debug_boxes(true);
             }
             if ($GLOBALS['g_config']['draw_page_border']) {
                 $pipeline->output_driver->set_show_page_border(true);
             }
             if ($GLOBALS['g_config']['ps2pdf']) {
                 $pipeline->output_filters[] = new OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']);
             }
             if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') {
                 $pipeline->output_filters[] = new OutputFilterGZip();
             }
             if (!isset($GLOBALS['g_config']['process_mode'])) {
                 $GLOBALS['g_config']['process_mode'] = '';
             }
             if ($GLOBALS['g_config']['process_mode'] == 'batch') {
                 $filename = 'batch';
             } else {
                 $filename = $sFilename;
             }
             switch ($GLOBALS['g_config']['output']) {
                 case 0:
                     $pipeline->destination = new DestinationBrowser($filename);
                     break;
                 case 1:
                     $pipeline->destination = new DestinationDownload($filename);
                     break;
                 case 2:
                     $pipeline->destination = new DestinationFile($filename);
                     break;
             }
             copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
             $status = $pipeline->process((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $_SESSION['APPLICATION'] . '/outdocs/' . $sFilename . '.html', $g_media);
             copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf');
             unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf');
             unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html');
         }
         //end if $sTypeDocToGener
         /* End - Create .pdf */
     } else {
         return PEAR::raiseError(null, G_ERROR_USER_UID, null, null, 'You tried to call to a generate method without send the Output Document UID, fields to use and the file path!', 'G_Error', true);
     }
 }