Solved

This error driving me crazy :(

Posted on 2014-01-08
13
917 Views
Last Modified: 2014-01-08
Hi!

I making a PDF file, but get this error message:

PHP Fatal error:  Cannot redeclare class mPDF in C:\DWASFiles\Sites\AgressionTestMysql\VirtualDirectory0\site\wwwroot\mssql\Reports\MPDF\mpdf.php on line 67


<?php
include_once("../mpdf.php");
require_once('Connect_databse.php');

ini_set('memory_limit', '256M');

session_start();


$table3='Reportform';
$table4 = 'P_SHOW_Transactions';


//$mpdf=new mPDF('c');
$mpdf=new mPDF('win-1252', 'A4', 11, 'DejaVuSansCondensed', 15, 15, 15, 15, 8, 8);
$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
$mpdf->defaultheaderfontsize = 10; /* in pts */
$mpdf->use_kwt = true;
$mpdf->keep_table_proportions = true;
$mpdf->shrink_tables_to_fit=1;
$mpdf->debug = true;
$mpdf->defaultheaderfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultheaderline = 1; /* 1 to include line below header/above footer */
$mpdf->defaultfooterfontsize = 10; /* in pts */
$mpdf->defaultfooterfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultfooterline = 1; /* 1 to include line below header/above footer */
$mpdf->SetHeader('{DATE j-m-Y}||Agreppa Report');
$mpdf->SetFooter('Side:{PAGENO}'); /* defines footer for Odd and Even Pages - placed at Outer margin */
$mpdf->SetFooter(array(
'L' => array(
'content' => 'Text to go on the left',
'font-family' => 'sans-serif',
'font-style' => 'B', /* blank, B, I, or BI */
'font-size' => '10', /* in pts */
),
'C' => array(
'content' => '- {PAGENO} -',
'font-family' => 'serif',
'font-style' => 'BI',
'font-size' => '18', /* gives default */
),
'R' => array(
'content' => 'Printed @ {DATE j-m-Y H:m}',
'font-family' => 'monospace',
'font-style' => '',
'font-size' => '10',
),
'line' => 1, /* 1 to include line below header/above footer */
), 'E' /* defines footer for Even Pages */
);





$html = '
<html>
<head>
<meta charset="utf-8" />
<style>
table.testtabell
{
    border:1px solid #cccccc;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 20px;
  margin-right: 15px;
}
.rapport2_header
{
    background-color: #efefef;
    border:1px solid #cccccc;
  color:#cccccc;
  font-size: 15px;
  font-family: Verdana;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
  padding-top:10px;
}
.rapport1_del8
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-top:10px;
   font-size:12px;
   color:#b2b3c3;
}

.rapport1_del9
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-bottom:8px;
   font-size:12px;
   color:#b2b3c3;
}

.rapport1_del1
{
    background-color: #efefef;
    border:0px solid #cccccc;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
}
.rapport1_del2
{
   background-color: #f8f8f8;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-right:0px solid #cccccc;
   border-collapse: collapse;
   padding-left:10px;
}
.rapport_brukernavn
{
   background-color: #f8f8f8; 
   border-right:1px solid #cccccc;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-collapse: collapse;
   padding-right:10px;
   font-family: Verdana;
   font-size: 11px;
   color:#cccccc;
   text-align:right;
}
.blank_row_noborder {
  height: 20px !important;
  background-color: #FFFFFF;
}
.blank_row {
  height: 20px !important;
  background-color: #FFFFFF;
  border-bottom: 1px solid #cccccc; /* or whatever specific values you prefer */
}
.rapport1_del3
{
   background-color: #ffffff;
   font-size:12px;
    border:0px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
}
.rapport_image1
{
   background-color: #ffffff;
   border: none ! important;
   box-shadow: none ! important;
   padding-right:10px;
}
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
</style>

</head>

<body>
';


$brukerID = $_GET["brukerID"];
$kundeid = $_GET["kundeid"];


echo "MERKE1";
die();


$sql = "SELECT * FROM {$table3} WHERE UserID={$brukerID} and Organisation={$kundeid}";
$resultraptmp = sqlsrv_query($conn,$sql); 

// Hent parametere som er valgt for utvalget til rapporten
while($row3 = sqlsrv_fetch_array($resultraptmp)){

      $datofra = $row3['Datefrom'];
      $datotil = $row3['Dateto'];
      $kontr = $row3['Controllername'];
      $brukere = $row3['Username'];
      $svarsp = $row3['Answer'];
      $vilkenrapport = $row3['Report'];
      $organisasjon = $row3['OrganisationName'];
      $antsider = $row3['Pages'];
      $rec_count = $row3['Numberrecords'];
      $antrader = $row3['NumRows'];
      $datobrukes = 1;
      $side = $row3['Page'];

} 

if ($vilkenrapport=="Enkel rapport"){    
$html .= '<table width="100%" align="left" class="testtabell">'; 
$html .= '<tr>';
$html .= '<th class="rapport2_header" height="40px" align="left">Kontroller</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Lokasjon</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Dato</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Spørsmål</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Svar</th>';
      
$html .= '</tr>';  
}  
     

$sql = "SELECT Name,ControlName,LocationID,Location,ControlID,Organisation,Question,Note,CreatedDate,Answer,UserID,IsScale,Object,TransactionID,Organisationname FROM {$table4}";


$sql = $sql." Where CreatedDate between '{$datofra}' AND '{$datotil}'";


$substr = "Alle kontrollere";
if (strpos($kontr, $substr) === false) {
  $sql = $sql." and ControlName='{$kontr}'";
}

$substr = "Alle brukere";
if (strpos($brukere, $substr) === false) {

  
  // Hent UserID    
   $tsql_callSP = "{call GET_UserID( ?, ?)}";
   $params = array( 
                 array($brukere, SQLSRV_PARAM_IN),
                 array($brID, SQLSRV_PARAM_INOUT)
               );

/* Execute the query. */
   $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
   if( $stmt3 === false )
   {
       echo "Error in executing statement 1.\n";
       die( print_r( sqlsrv_errors(), true));
   }
   else
   {sqlsrv_free_stmt( $stmt3);}


  $sql = $sql." and UserID='{$brID}'";
}

if ($svarsp=="Ja"){
  $sql = $sql." and Answer='Ja'";
}

if ($svarsp=="Nei"){
  $sql = $sql." and Answer='Nei'";
}

if ($svarsp=="Avvik"){
  $sql = $sql." and Answer='Avvik'";
}

if ($svarsp=="Scale"){
  $sql = $sql." and Answer<>'Ja' and Answer<>'Nei' and Answer<>'Avvik' ";
}
  
$sql = $sql." and Organisationname='{$organisasjon}'";

$sql = $sql." ORDER BY ControlID,CreatedDate";

$retval = sqlsrv_query($conn,$sql); 

if( $retval === false )
{
       echo "Error in executing statement 12.\n";
       die( print_r( sqlsrv_errors(), true));
}

$TMP_KID=0;
$forstekontroller = 1;
$TMP_LOK=0;
$farge1="#ffffff";
$farge2="#d9eefa";
$valgfarge="#ccc";
$byttfarge = 1;
$antrader=1;
$antraderMAX= 20;



while($row3 = sqlsrv_fetch_array($retval)){
   
   $kontrollernavn = $row3['ControlName'];
   $lokasjonnr = $row3['LocationID'];
   $K_ID = $row3['ControlID'];
   $kunde_ID = $row3['Organisation'];
   $lokasjonnavn = $row3['Location']; 
   $sporsmal = $row3['Question'];
   $kommentar = $row3['Note'];
   $transdato = $row3['Location'];
   $svar = $row3['Answer']; 
   $usID = $row3['UserID'];  
   $scaleant = $row3['IsScale'];
   $bilderef="";     // Midligtidig satt til blank
   $brukernavn= $row3['Name'];

if ($vilkenrapport=="Enkel rapport"){  
    
    
$html .= '<tr>';
                                                     
if ($byttfarge==1){
   $valgfarge=$farge2;
   $byttfarge=2;
}
else
{ 
   $byttfarge=1;
   $valgfarge=$farge1;
}   

$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $kontrollernavn . '</td>'; 
$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $lokasjonnavn .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $transdato .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $sporsmal .'</td>'; 
      
if($svar=="Ja"){ 
   $html .= '<td colspan="2" class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/jasvar.png" alt="Smiley face"></td>';
}

if($svar=="Nei"){ 
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/neisvar.png" alt="Smiley face"></td>';
}

 if($svar<>"Ja" and $svar<>"Nei"){
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/scale.png" alt="Smiley face"></td>';
}


}    
     
if ($vilkenrapport=="Standard rapport"){   
   
   if ($forstekontroller==1)
    {
       $forstekontroller=0;
     $TMP_KID = $K_ID;
     $TMP_LOK = $lokasjonnr;
     
        $html .='<table width="100%" align="center" class="testtabell"  style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" height="40px" colspan="4">' . $kontrollernavn .'</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn . '</td>';
        $html .='<td class="rapport_brukernavn" >' . $brukernavn .'</td>';      
      $html .='</tr>';

    }
  

  
   if ((($TMP_KID<>$K_ID) or ($TMP_LOK<>$lokasjonnr)) and $forstekontroller==2)
   {
      if ($TMP_KID<>$K_ID) {$TMP_KID = $K_ID;}
    if ($TMP_LOK<>$lokasjonnr) {$TMP_LOK = $lokasjonnr;}
        $html .='</table>';
        $html .='<table width="100%" align="center" class="testtabell" style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" colspan="4" height="40px">' . $kontrollernavn . '</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn .'</td>';
    $html .='<td class="rapport_brukernavn">' . $brukernavn .'</td>';
      $html .='</tr>';   
  
   }
   
    $html .='<tr class="blank_row_noborder">';
    $html .='<td colspan="4"></td>';
    $html .='</tr>';  
  
  $html .='<tr>';  
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Sporsmål: </td>';
  $html .='<td class="rapport1_del3" valign="top" width="380px">' . $sporsmal . '</td>';
    
  if ($bilderef=="")
    { 
    $html .='<td class="rapport1_del3" valign="top"></td>';
      $html .='<td valign="top" class="rapport_image1" rowspan="4"><img src="../../../images/ingen.png" height="160" width="150px" /></td>';
  }
  else
  {
    $html .='<td class="rapport1_del3" valign="top"></td>'; 
    $html .='<td valign="top" class="rapport_image1" rowspan="4"><img src="../../../uploads/' . $bilderef .'" height="160" width="150px" /></td>';
    }
  $html .='</tr>';  
  $html .='<tr>';
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Dato: </td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $transdato .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Svar:</td>'; 
     
      if (($svar=="Ja") or ($svar=="Nei"))
    { 
         $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $svar .'</td>';
    
    }
    else {
    
       $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $svar . ' av ' . $scaleant .'</td>';
     }
  $html .='<td class="rapport1_del3" valign="top"></td>'; 
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Kommentar:</td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $kommentar .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>'; 
  
  $html .='<tr class="blank_row">';
    $html .='<td colspan="4"></td>';
    $html .='</tr>';  
   
   $forstekontroller=2;
}}

$html .= '</table>';
$html .= '</body>';
$html .= '</html>';

echo $html;
die();

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML($html);

$mpdf->Output();
exit;

?>

Open in new window



I dont know why this is happening ?????
0
Comment
Question by:team2005
  • 5
  • 5
  • 2
13 Comments
 
LVL 8

Expert Comment

by:Surrano
ID: 39764636
Perhaps if you could include mpdf.php as well...
but
have you tried "require_once" instead of "include_once"?
0
 
LVL 2

Author Comment

by:team2005
ID: 39764659
Hi!

Dident work ?

Try to include the mpdf.php, but i cant ?
Maby to big ?
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39764747
Can you post the first 70 lines of mpdf.php? Error should be on line 67...
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 2

Author Comment

by:team2005
ID: 39764774
Hi!

<?php

// ******************************************************************************
// Software: mPDF, Unicode-HTML Free PDF generator                              *
// Version:  5.7     based on                                                   *
//           FPDF by Olivier PLATHEY                                            *
//           HTML2FPDF by Renato Coelho                                         *
// Date:     2013-07-14                                                         *
// Author:   Ian Back <ianb@bpm1.com>                                           *
// License:  GPL                                                                *
//                                                                              *
// Changes:  See changelog.txt                                                  *
// ******************************************************************************


define('mPDF_VERSION','5.7');

//Scale factor
define('_MPDFK', (72/25.4));

/*-- HTML-CSS --*/
define('AUTOFONT_CJK',1);
define('AUTOFONT_THAIVIET',2);
define('AUTOFONT_RTL',4);
define('AUTOFONT_INDIC',8);
define('AUTOFONT_ALL',15);

define('_BORDER_ALL',15);
define('_BORDER_TOP',8);
define('_BORDER_RIGHT',4);
define('_BORDER_BOTTOM',2);
define('_BORDER_LEFT',1);
/*-- END HTML-CSS --*/

if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/');
if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH);

require_once(_MPDF_PATH.'includes/functions.php');
require_once(_MPDF_PATH.'config_cp.php');

if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/'); 

if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/');

if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); }
if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); }

$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_NOTICE);

//error_reporting(E_ALL);

if(function_exists("date_default_timezone_set")) {
	if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); }
}
if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }

if (!defined('PHP_VERSION_ID')) {
    $version = explode('.', PHP_VERSION);
    define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
// Machine dependent number of bytes used to pack "double" into binary (used in cacheTables)
$test = pack("d", 134455.474557333333666);
define("_DSIZE", strlen($test));

class mPDF
{

///////////////////////////////
// EXTERNAL (PUBLIC) VARIABLES
// Define these in config.php
///////////////////////////////

Open in new window

0
 
LVL 8

Expert Comment

by:Surrano
ID: 39764893
Well it looks ok for me.
I definitely think that there's another include or require in the recursive set of included files that is not *_once and still includes this file. Maybe if you add the error_reporting *before* this include_once line then we'll see some useful warnings.

<?php
$old_er = error_reporting(63);
include_once("../mpdf.php");
require_once('Connect_databse.php');
error_reporting($old_er);
...

Open in new window

0
 
LVL 2

Author Comment

by:team2005
ID: 39764906
Hi!

Only get a blank page ???
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39764914
??? without error_reporting set to max you get an error but if you set it to max you get an empty page and no errors, not even warnings? I certainly assume you left the remainder of the file in place...
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39765155
PHP Fatal error:  Cannot redeclare class says that somewhere in the program (script) text you have a second statement that uses the Class keyword to define the class named MPDF.  Class names are like function names - case-insensitive.  You can only have one class of each name in the script file.
<?php // RAY_temp_team2005.php
error_reporting(E_ALL);

class foo {}
class foo {} // FATAL ERROR HERE

Open in new window

The script file will include not only the script you execute, but any other scripts brought in by include().

The usual approach to an issue like this one is to use a code scanner, like the TextPad "find in files" function, to search the source library for instances of 'MPDF.'

Where did you get the template that you're starting from?  The reason I ask is this set of instructions.  That looks technically incompetent to me and I would avoid depending on anything that could not be run with error_reporting(E_ALL)!!
$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_NOTICE);

//error_reporting(E_ALL);

Open in new window

0
 
LVL 2

Author Comment

by:team2005
ID: 39765438
Hi!

Changed som names for database connections, and now i get this error message:

Output has already been sent from the script - PDF file generation aborted.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39765504
Hi, team2005.  It looks like the errors are all over the map, and that makes it very, very difficult to get good results.  If I were dealing with this application, I would start over and reduce it to the SSCCE, which is the minimum kind of "Hello World" example that proves you have the scripts in the right places, and the MPDF script can produce a usable PDF file.

Once you have that part working, begin adding additional functionality one step at a time, testing each addition.  When something "breaks" you will know that it was caused by the last incremental addition, and you can debug that small part of the application, instead of wondering where things are going wrong.  By doing this step-by-step you will get accurate results much faster than if you try to do it all at once, I promise!
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39765527
This latter part may be caused by some premature input. Some functions like session_start() expect that nothing (no debug echos, no error messages, nothing) had been echoed previously. There must be some similar restriction in mPDF as well, so comment the high error_reporting settings and the debug lines (e.g. echo "MERKE1";)
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 39767343
Hi!

Fixed the error now, i just renamed som variables for database-file.

Then everything works fine :)

Probebly som issue about conflict with som classes in MPDF-file ?
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question