[ PHPXref.com ] [ Generated: Sun Jul 20 19:53:36 2008 ] [ PHPReports 0.4.7 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> PHPReportsUtil.php (source)

   1  <?php
   2      /******************************************************************************
   3      *                                                                                                        *
   4      *    Useful functions and classes to deal with PHPReports stuff.                        *
   5      *    This file is part of the standard PHPReports package.                                *
   6      *                                                                                                        *
   7      ******************************************************************************/    
   8  
   9      /******************************************************************************
  10      *                                                                                                        *
  11      *    This function will return if there is a PHPReports path in the PHP            *
  12      *    ini_get("include_path").                                                                    *
  13      *                                                                                                        *
  14      ******************************************************************************/
  15  	function getPHPReportsIncludePath(){
  16          $aPaths = explode((stristr(PHP_OS,"WIN")?";":":"),ini_get("include_path"));
  17          foreach($aPaths as $sPath)
  18              if(stristr($sPath,"phpreports"))
  19                  return $sPath;
  20          return null;
  21      }
  22  
  23      /******************************************************************************
  24      *                                                                                                        *
  25      *    Returns the temporary file path. It's up to your operational system to        *
  26      *    return that. In most cases, on Linux it will return /tmp and on                *
  27      *    Windows c:\temp                                                                                *
  28      *                                                                                                        *
  29      ******************************************************************************/
  30  	function getPHPReportsTmpPath(){
  31          $sPath = tempnam(null,"check");
  32          unlink($sPath);
  33          return realpath(dirname($sPath));
  34      }
  35  
  36      /******************************************************************************
  37      *                                                                                                        *
  38      *    This function will return the file path where the PHPReports classes            *
  39      *    are.                                                                                                * 
  40      *                                                                                                        *
  41      ******************************************************************************/
  42  	function getPHPReportsFilePath(){
  43          $sPath = getPHPReportsIncludePath();
  44          if(!is_null($sPath))
  45              return $sPath;
  46          // put your distro path here
  47          return "/var/htdocs/phpreports/"; 
  48      }
  49  
  50      /******************************************************************************
  51      *                                                                                                        *
  52      *    XSLTProcessorClass                                                                            *
  53      *    This class is used as base for XSLT process.                                            *
  54      *                                                                                                        *
  55      ******************************************************************************/    
  56      class XSLTProcessorClass{
  57          var $_sXML;
  58          var $_sXSLT;
  59          var $_sOutput;
  60          var $_aParms;
  61  
  62          /**
  63              Constructor
  64          */
  65  		function XSLTProcessorClass(){
  66              $this->_sXML    =null;
  67              $this->_sXSLT    =null;
  68              $this->_sOutput=null;
  69              $this->_aParms    =null;
  70          }
  71  
  72          /**
  73              Sets the XML data file path
  74          */            
  75  		function setXML($sXML_=null){
  76              $this->_sXML=$sXML_;
  77          }
  78          
  79          /**
  80              Returns the XML data file path
  81          */
  82  		function getXML(){
  83              return $this->_sXML;
  84          }
  85          
  86          /**
  87              Sets the style sheet file path
  88          */
  89  		function setXSLT($sXSLT_=null){
  90              $this->_sXSLT=$sXSLT_;
  91          }
  92  
  93          /**
  94              Returns the style sheet file path
  95          */
  96  		function getXSLT(){
  97              return $this->_sXSLT;
  98          }
  99          
 100          /**
 101              Specify the output file path
 102              A null just returns the result on the run method
 103          */
 104  		function setOutput($sOutput_=null){
 105              $this->_sOutput=$sOutput_;
 106          }
 107  
 108          /**
 109              Return the output file path
 110          */        
 111  		function getOutput(){
 112              return $this->_sOutput;
 113          }
 114  
 115          /**
 116              Specify the parameters array
 117          */
 118  		function setParms($aParms_=null){
 119              if(is_null($aParms_))
 120                  return;
 121              if(!is_array($aParms_))
 122                  return;    
 123              $this->_aParms=$aParms_;    
 124          }
 125          
 126          /**
 127              Insert a parameter
 128              sParm_ - parameter name
 129              oVal_  - parameter value
 130          */            
 131  		function setParm($sParm_=null,$oVal_=null){
 132              if(is_null($sParm_))
 133                  return;
 134              $this->_aParms[$sParm_]=$oVal_;
 135          }
 136  
 137          /**
 138              Returns a parameter value
 139              sParm_ - parameter name
 140          */
 141  		function getParm($sParm_){
 142              if(!array_key_exists($sParm_))
 143                  return null;
 144              return $this->_aParms[$sParm_];
 145          }
 146          
 147          /**
 148              Remove a parameter
 149              sParm_ - parameter name
 150          */
 151  		function removeParm($sParm_=null){
 152              if(is_null($sParm_))
 153                  return;
 154              if(!array_key_exists($sParm_,$this->_aParms))
 155                  return;                    
 156              unset($this->_aParms[$sParm_]);                    
 157          }
 158  
 159          /**
 160              This method MUST be overwritten on every subclass to reflect
 161              the behaviour of the desired XSLT processor.
 162              It MUST return the result, and if defined an output, save it.
 163          */
 164  		function run(){
 165          }
 166      }
 167      
 168      /******************************************************************************
 169      *                                                                                                        *
 170      *    Sablotron processor                                                                            *
 171      *    http://www.gingerall.com/charlie/ga/xml/p_sab.xml                                    *
 172      *    http://www.php.net/manual/en/ref.xslt.php                                                *
 173      *    Used on PHP4 or installed from the PECL modules.                                    *
 174      *                                                                                                        *
 175      ******************************************************************************/
 176      class Sablotron_xp extends XSLTProcessorClass{
 177  		function run(){
 178              if(is_null($this->_sXML)){
 179                  print "ERROR: no XML file specified";
 180                  return;
 181              }
 182              if(is_null($this->_sXSLT)){
 183                  print "ERROR: no XSLT file specified";
 184                  return;
 185              }
 186              $oXSLT = xslt_create();
 187              $sRst     = xslt_process($oXSLT,$this->_sXML,$this->_sXSLT,$this->_sOutput,null,$this->_aParms);
 188              xslt_free($oXSLT);                    
 189              return $sRst;
 190          }
 191      }
 192  
 193      /******************************************************************************
 194      *                                                                                                        *
 195      *    PHP5 XSL processing                                                                            *
 196      *    Uses libxslt                                                                                    *
 197      *    http://www.php.net/manual/en/ref.xsl.php                                                *
 198      *                                                                                                        *
 199      ******************************************************************************/
 200      class PHPXSL_xp extends XSLTProcessorClass{
 201  		function run(){
 202              // xml document
 203              $oXML = new DomDocument();
 204              $oXML->load($this->_sXML);
 205              $oXML->xinclude();
 206  
 207              // xslt document
 208              $oXSL = new DomDocument();
 209              $oXSL->load($this->_sXSLT);
 210  
 211              // xslt processor
 212              $oProc = new XSLTProcessor();
 213              $oProc->importStyleSheet($oXSL);
 214              
 215              // set all the parameters
 216              if(!is_null($this->_aParms)){
 217                  foreach($this->_aParms as $k => $v)
 218                      $oProc->setParameter("",$k,$v);
 219              }    
 220  
 221              // make the transformation                
 222              $sRst = $oProc->transformToXML($oXML);
 223              unset($oProc);
 224              unset($oXSL);
 225              unset($oXML);
 226  
 227              // if output is not null, save the result there
 228              if(!is_null($this->_sOutput)){
 229                  $fHand = @fopen($this->_sOutput,"w");
 230                  @fputs($fHand,$sRst);
 231                  @fclose($fHand);
 232              }
 233              return $sRst;
 234          }
 235      }
 236      
 237      /******************************************************************************
 238      *                                                                                                        *
 239      *    XSLT Processor factory                                                                        *
 240      *    Returns a XSLT processor based on the current environment                        *
 241      *    or the user choice (need to hack the code below).                                    *
 242      *                                                                                                        *
 243      ******************************************************************************/
 244      class XSLTProcessorFactory{
 245  		function get(){
 246              // PHP major version number
 247              $iVer = intval(substr(phpversion(),0,1));
 248  
 249              // if PHP4 and Sablotron is installed
 250              if($iVer<=4 && function_exists("xslt_create"))
 251                  return new Sablotron_xp();
 252              // if PHP5 and Sablotron is installed                
 253              else if($iVer>=5 && function_exists("xslt_create"))
 254                  return new Sablotron_xp();    
 255              // if PHP5, Sablotron is not installed    and XSL support is compiled            
 256              else if($iVer>=5 && !function_exists("xslt_create") && class_exists("XSLTProcessor"))
 257                  return new PHPXSL_xp();
 258              // there is no XSLT processor installed!                
 259              else
 260                  return null;                
 261          }
 262      }
 263  
 264      /******************************************************************************
 265      *                                                                                                        *
 266      *    PHPReportsError                                                                                *
 267      *    Process error messages                                                                        *
 268      *                                                                                                        *
 269      ******************************************************************************/
 270      class PHPReportsError{
 271  		function PHPReportsError($sMsg_=null,$sURL_=null){
 272              if(is_null($sMsg_))
 273                  return;
 274                  
 275              print "<p style='width:400px;background-color:#F5F5F5;border-style:solid;border-width:2;border-color:#CCCCCC;padding:10px 10px 10px 10px;margin:20px;font-family:verdana,arial,helvetica,sans-serif;color:#505050;font-size:12px;'>";
 276              print "<span style='font-size:18px;color:#FF0000;font-weight:bold;'>OOOOPS, THERE'S AN ERROR HERE.</span><br/><br/>";
 277              print $sMsg_."<br/><br/>";
 278              
 279              if(!is_null($sURL_))
 280                  print "<a href='$sPath/help/$sURL_'>More about this error here.</a><br/><br/>";
 281  
 282              print "<span style='font-size:10px;font-weight:bold;'>This error message was generated by PHPReports</span>";
 283              print "</p>";
 284              exit();                
 285          }
 286      }
 287  
 288      class PHPReportsErrorTr {
 289          var $_aMsgs;
 290          
 291  		function PHPReportsErrorTr(){
 292              $this->_aMsgs = Array();
 293  
 294              // default English messages
 295              $this->_aMsgs["OPS"]["default"]                = "OOOOPS, THERE'S AN ERROR HERE.";
 296              $this->_aMsgs["ERROR"]["default"]            = "This error message was generated by phpReports.";
 297              $this->_aMsgs["NODATA"]["default"]            = "No data was found.";
 298              $this->_aMsgs["NOPAGE"]["default"]            = "No PAGE element was found on your XML file.";
 299              $this->_aMsgs["NOIF"]["default"]                = "No database interface '%s' available.";
 300              $this->_aMsgs["REFUSEDCON"]["default"]        = "Connection refused.";
 301              $this->_aMsgs["QUERYERROR"]["default"]        = "There's an error on your SQL query.";
 302              $this->_aMsgs["NOCOLUMNS"]["default"]        = "No columns returned from your query.";
 303              $this->_aMsgs["PAGEPARSER"]["default"]        = "Could not copy the temporary page parser to the temporary directory.";
 304              $this->_aMsgs["DYNLINK"]["default"]            = "Specified a dynamic link but no COLUMN element found";
 305              $this->_aMsgs["EXPLINK"]["default"]            = "Specified an expression link but no COLUMN element found";
 306              $this->_aMsgs["NOFIELD"]["default"]            = "You're trying to retrieve the <b>VALUE</b> of a field called <b>%s</b>, but it is not on your SQL query. Please check your query.";
 307              $this->_aMsgs["NOFIELDSUM"]["default"]        = "You're trying to retrieve the <b>SUM</b> of a field called <b>%s</b>, but it is not on your SQL query. Please check your query.";
 308              $this->_aMsgs["NOFIELDMAX"]["default"]        = "You're trying to retrieve the <b>MAX VALUE</b> of a field called <b>%s</b>, but it is not on your SQL query. Please check your query.";
 309              $this->_aMsgs["NOFIELDMIN"]["default"]        = "You're trying to retrieve the <b>MIN VALUE</b> of a field called <b>%s</b>, but it is not on your SQL query. Please check your query.";
 310              $this->_aMsgs["NOFIELDAVG"]["default"]        = "You're trying to retrieve the <b>AVERAGE</b> of a field called <b>%s</b>, but it is not on your SQL query. Please check your query.";
 311              $this->_aMsgs["CANTWRITEPAGE"]["default"]    = "Can't write file <b>%s</b> to the disk. Check your disk quota/space and rights.";
 312              $this->_aMsgs["DYNBOOK"]["default"]            = "Specified a dynamic bookmark but no COLUMN element found";
 313              $this->_aMsgs["EXPBOOK"]["default"]            = "Specified an expression bookmark but no COLUMN element found";
 314              $this->_aMsgs["NOXMLTRANS"]["default"]        = "COL parameter <b>%s</b> not found on XML translation.";
 315              $this->_aMsgs["NOXSLT"]["default"]            = "There is no XSLT processor available. Check if you compiled PHP with <b>--enable-xslt</b> and the <a href=\"http://www.gingerall.com/charlie/ga/xml/p_sab.xml\">Sablotron</a> library (for <a href=\"http://www.php.net/manual/en/ref.xslt.php\">PHP4</a>) or with <b>--enable-xsl</b> (for <a href=\"http://www.php.net/manual/en/ref.xsl.php\">PHP5</a>).";
 316              $this->_aMsgs["NOPATH"]["default"]            = "Seems that you didn't specified the phpReports path on the PHP <b>include_path</b> statement or <b>php.ini</b>. I don't know there the classes are.";
 317              $this->_aMsgs["NOCODE"]["default"]            = "Could not create the output code to run your report. Please check if the webserver user have rights to write in your <b>%s</b> directory.";
 318              $this->_aMsgs["NOXML"]["default"]            = "Could not find the XML file with your data (<b>%s</b>) to run your report. Please check the filename and if the webserver user have rights to write in your temporary directory.";
 319              $this->_aMsgs["NOXMLSET"]["default"]        = "The XML input file <b>%s</b> was not found.";
 320              $this->_aMsgs["NOXSLTSET"]["default"]        = "The XSLT input file <b>%s</b> was not found.";
 321              $this->_aMsgs["NOPLUGIN"]["default"]        = "There is no <b>%s</b> output plugin (<b>%s</b>).";
 322              $this->_aMsgs["NOLOAD"]["default"]            = "Could not find file <b>%s</b> for report loading.";
 323              $this->_aMsgs["NOTEMPLATE"]["default"]        = "The template file <b>%s</b> was not found.";
 324  
 325              // Brazilian Portuguese messages
 326              $this->_aMsgs["OPS"]["pt_BR"]                    = "OOOOPS, OCORREU UM ERRO AQUI.";
 327              $this->_aMsgs["ERROR"]["pt_BR"]                = "Essa mensagem de erro foi gerada pelo phpReports.";
 328              $this->_aMsgs["NODATA"]["pt_BR"]                = "Não foram encontrados dados.";
 329              $this->_aMsgs["NOPAGE"]["pt_BR"]                = "Não há um elemento PAGE (página) no seu relatório.";
 330              $this->_aMsgs["NOIF"]["pt_BR"]                = "Não há disponível a interface '%s' para banco de dados.";
 331              $this->_aMsgs["REFUSEDCON"]["pt_BR"]        = "Conexão recusada.";
 332              $this->_aMsgs["QUERYERROR"]["pt_BR"]        = "Erro na consulta SQL.";
 333              $this->_aMsgs["NOCOLUMNS"]["pt_BR"]            = "Não foram retornados colunas de dados na sua consulta.";
 334              $this->_aMsgs["PAGEPARSER"]["pt_BR"]        = "Não consegui copiar o conversor de páginas para o diretório temporário.";
 335              $this->_aMsgs["DYNLINK"]["pt_BR"]            = "Foi especificado um link dinâmico mas não existe um elemento COLUMN.";
 336              $this->_aMsgs["EXPLINK"]["pt_BR"]            = "Foi especificado um link com uma expressão mas não existe um elemento COLUMN.";
 337              $this->_aMsgs["NOFIELD"]["pt_BR"]            = "Você está tentando recuperar o <b>VALOR</b> de um campo chamado <b>%s</b>, mas ele não existe na sua consulta. Por favor revise sua consulta.";
 338              $this->_aMsgs["NOFIELDSUM"]["pt_BR"]        = "Você está tentando recuperar a <b>SOMA</b> de um campo chamado <b>%s</b>, mas ele não existe na sua consulta. Por favor revise sua consulta.";
 339              $this->_aMsgs["NOFIELDMAX"]["pt_BR"]        = "Você está tentando recuperar o <b>VALOR MÁXIMO</b> de um campo chamado <b>%s</b>, mas ele não existe na sua consulta. Por favor revise sua consulta.";
 340              $this->_aMsgs["NOFIELDMIN"]["pt_BR"]        = "Você está tentando recuperar o <b>VALOR MÍNIMO</b> de um campo chamado <b>%s</b>, mas ele não existe na sua consulta. Por favor revise sua consulta.";
 341              $this->_aMsgs["NOFIELDAVG"]["pt_BR"]        = "Você está tentando recuperar o <b>VALOR MÉDIO</b> de um campo chamado <b>%s</b>, mas ele não existe na sua consulta. Por favor revise sua consulta.";
 342              $this->_aMsgs["CANTWRITEPAGE"]["pt_BR"]    = "Não consegui escrever o arquivo <b>%s</b> no disco. Verifique suas permissões e espaço em disco.";
 343              $this->_aMsgs["DYNBOOK"]["pt_BR"]            = "Foi especificado um bookmark dinâmico mas não existe um elemento COLUMN.";
 344              $this->_aMsgs["EXPBOOK"]["pt_BR"]            = "Foi especificado um bookmark com uma expressão mas não existe um elemento COLUMN.";
 345              $this->_aMsgs["NOXMLTRANS"]["pt_BR"]        = "O parâmetro <b>%s</b> de COL não foi encontrado na tradução para XML.";
 346              $this->_aMsgs["NOXSLT"]["pt_BR"]                = "Não há um processador XSLT disponível. Verifique se você compilou o PHP com <b>--enable-xslt</b> e a library <a href=\"http://www.gingerall.com/charlie/ga/xml/p_sab.xml\">Sablotron</a> (para o <a href=\"http://www.php.net/manual/en/ref.xslt.php\">PHP4</a>) ou com <b>--enable-xsl</b> (para o <a href=\"http://www.php.net/manual/en/ref.xsl.php\">PHP5</a>).";
 347              $this->_aMsgs["NOPATH"]["pt_BR"]                = "Parece que você não especificou o path do phpReports com o comando <b>include_path</b> ou no <b>php.ini</b>. Não sei onde as classes estão.";
 348              $this->_aMsgs["NOCODE"]["pt_BR"]                = "Não pude criar o código de saída para rodar seu relatório. Por favor verifique se o usuário do servidor web tem direitos para escrever no diretório <b>%s</b>.";
 349              $this->_aMsgs["NOXML"]["pt_BR"]                = "Não pude encontrar o arquivo XML com seus dados (<b>%s</b>) para rodar seu relatório. Por favor verifique o nome do arquivo e se o usuário do servidor web tem direitos de escrita no seu diretório de arquivos temporários.";
 350              $this->_aMsgs["NOXMLSET"]["pt_BR"]            = "O arquivo XML de entrada <b>%s</b> não foi encontrado.";
 351              $this->_aMsgs["NOXSLTSET"]["pt_BR"]            = "O arquivo XSLT de entrada <b>%s</b> não foi encontrado.";
 352              $this->_aMsgs["NOPLUGIN"]["pt_BR"]            = "O plugin de saída <b>%s</b> não existe (<b>%s</b>).";
 353              $this->_aMsgs["NOLOAD"]["pt_BR"]                = "Não encontrei o arquivo <b>%s</b> para carregar o relatório.";
 354              $this->_aMsgs["NOTEMPLATE"]["pt_BR"]        = "O arquivo de template <b>%s</b> não foi encontrado.";
 355          }
 356  
 357  		function showMsg($sMsg_=null,$oParms_=null){
 358              if(!sMsg_)
 359                  return;
 360              if($_SESSION["phpReportsLanguage"])
 361                  $sLang = $_SESSION["phpReportsLanguage"];
 362              else
 363                  $sLang = $GLOBALS["phpReportsLanguage"];
 364              if(!$sLang)
 365                  $sLang = "default";
 366  
 367              $sTitle    = $this->_aMsgs["OPS"][$sLang];
 368              $sError    = $this->_aMsgs["ERROR"][$sLang];
 369              $sMsg        = $this->_aMsgs[$sMsg_][$sLang];
 370  
 371              // if the message have no translation
 372              if(!$sMsg)
 373                  $sMsg = $this->_aMsgs[$sMsg_]["default"];
 374              // if the message is still null ...
 375              if(!$sMsg)
 376                  $sMsg = "$sMsg_?";
 377              
 378              if($oParms_)
 379                  $sMsg = vsprintf($sMsg,$oParms_);
 380              
 381              print "<p style='width:400px;background-color:#F5F5F5;border-style:solid;border-width:2;border-color:#CCCCCC;padding:10px 10px 10px 10px;margin:20px;font-family:verdana,arial,helvetica,sans-serif;color:#505050;font-size:12px;'>";
 382              print "<span style='font-size:18px;color:#FF0000;font-weight:bold;'>$sTitle</span><br/><br/>";
 383              print "$sMsg<br/><br/>";
 384              print "<span style='font-size:10px;font-weight:bold;'>$sError</span>";
 385              print "</p>";
 386              exit();                
 387          }
 388      }
 389  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]