Voy mejorando pero aun no doy con lo correcto:;
Código PHP:
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
$nreg_abs = mysql_num_rows($sql_abs);
$i=1;
$cols2='';
while($res_abs = mysql_fetch_row($sql_abs)){
if($nreg_abs == $i){
$cols2 .= $res_abs['0']."=>array('justification' => 'left'))";
}else{
$cols2 .= $res_abs['0']."=>array('justification' => 'left'),";
}
$i++;
}
echo "<pre>";
print_r($cols2);
echo "</pre>";
$pdf->ezTable($data,$cols,'',array('fontSize'=>8,
'cols'=>array( 'persona'=> array('justification' => 'left'),
$cols2)
));//-- sortida
$pdf->ezText('',10);
desa manera, Cols2 se me crea de forma correcta pero me sigue lanzando el error de antes.
el impreso de cols2 es el siguiente:
Cita: 12=>array('justification' => 'left'),
20=>array('justification' => 'left'),
21=>array('justification' => 'left'),
26=>array('justification' => 'left'),
28=>array('justification' => 'left'),
29=>array('justification' => 'left'),
30=>array('justification' => 'left'),
31=>array('justification' => 'left'),
32=>array('justification' => 'left'),
34=>array('justification' => 'left'))
MODIFICACiO: SOLUCION POR SI ALGUIEN LE INTERESA....
CODIGO COMPLETO : Crear un PDF con la clase R&OS - con cabeceras dinamicas
Código PHP:
<?
require("../../../../aut_verifica.inc.php");
error_reporting(E_ALL);
include('../../../class/class.ezpdf.php');
$pdf = & new Cezpdf('A4','landscape');
$pdf->selectFont('../../../class/fonts/Helvetica');
$pdf->ezStartPageNumbers(800,10,10,'','{PAGENUM} de {TOTALPAGENUM}',1); /**/
//-------------------------------------
//-- Variable per fer la clausula Where
$WHEREHAN = '';
$WHEREEMPRESA = '';
$ur = '';
if (isset($_GET['id_empresa']) && ($_GET['id_empresa'] > 0)){
$WHEREEMPRESA = " WHERE id_empresa=$_GET[id_empresa]";
$ur .= "&id_empresa=$_GET[id_empresa]";
}else{
$WHEREEMPRESA = " WHERE id_empresa=1 or id_empresa=3";
}
if (isset($_GET['id_seccio']) && ($_GET['id_seccio'] > 0)){
$WHERESECCIO = " AND hores= 1 AND id_seccio=$_GET[id_seccio]";
$ur .= "&id_seccio=$_GET[id_seccio]";
}else{
$WHERESECCIO = " AND hores = 1";
}
if (isset($_GET['cooperativa']) && ($_GET['cooperativa'] != 3)){
$WHEREHAN .= " AND cooperativa = $_GET[cooperativa]";
$ur .= "&cooperativa=$_GET[cooperativa]";
}
if (isset($_GET['desde'])){
$desde = ($_GET['desde']);
$ur .= "&desde=$desde";
}
if(isset($_GET['fins'])){
$fins = ($_GET['fins']);
$ur .= "&fins=$fins";
}
if($_GET['desde'] == $_GET['fins']){
$capcesetmana = "Fecha ".$_GET['desde'];
}else{
$capcesetmana = "Fecha Desde ".$_GET['desde']." - Hasta ".$_GET['fins'];
}
// --------------------------------------------------------------------------------- //
$data = array();
// -- Absencies entre dates --//
$str_abs = "SELECT DISTINCT h.id_tipoabsencia, tipoabsencia
FROM hores h,tipo_absencia ta
WHERE h.id_tipoabsencia != 0 AND ta.situacio = 0 AND festiu=0
AND h.id_tipoabsencia = ta.id_tipoabsencia
AND data >=".$desde." AND data <=".$fins."
GROUP BY h.id_tipoabsencia";
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
$nreg_abs = mysql_num_rows($sql_abs);
// ---------------------------- //
// -- Busquem la empresa ---- //
$str_empresa = "SELECT id_empresa,nom_empresa FROM empresa $WHEREEMPRESA
ORDER BY id_empresa ASC";
$sql_empresa = mysql_query($str_empresa) or die("ERROR SQL EMPRESA: ".mysql_error());
$nreg_empresa = mysql_num_rows($sql_empresa);
if($nreg_empresa != 0){
while($res_empresa = mysql_fetch_row($sql_empresa)){
$idempresa = $res_empresa['0'];
$nomempresa = $res_empresa['1'];
/*
echo $idempresa."<br>";
*/
$pdf->ezText($nomempresa,10,array('justification' => 'center'));
$pdf->ezText('',10);
$str_seccio = "SELECT id_seccio, nom_seccio
FROM seccio WHERE id_empresa = ".$res_empresa['0']."
$WHERESECCIO
ORDER BY nom_seccio ASC";
$sql_seccio = mysql_query($str_seccio) or die("ERROR SQL EMPRESA: ".mysql_error());
$nreg_seccio = mysql_num_rows($sql_seccio);
if($nreg_seccio != 0){
while($res_seccio= mysql_fetch_row($sql_seccio)){
//echo $WHEREHAN;
$str_hores_persona = "SELECT p.id_persona,p.dni, p.nom, p.cognom1, p.cognom2, p.cooperativa
FROM hores h INNER JOIN personal p
ON h.id_persona = p.id_persona
WHERE p.id_seccio=".$res_seccio['0']." AND p.id_persona != ''
AND data >= ".$desde." AND data <= ".$fins." $WHEREHAN
GROUP BY p.dni ORDER BY p.id_seccio,p.dni";
/*
echo $str_hores_persona."<br>";
*/
$sql_hores_persona = mysql_query($str_hores_persona) or die("Error en consulta 1: ".mysql_error());
$nreg_hores_persona = mysql_num_rows($sql_hores_persona);
/*
echo $nreg_hores_persona."<br>";
*/
if ($nreg_hores_persona != 0){
/**/
//-- coloca una linia a dalt i baix a totes les pagines
$all = $pdf->openObject();
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->line(20,20,830,20);
$pdf->line(20,575,830,575);
$pdf->addText(20,580,10,'Horas Semanales por Seccion - Arcadíe España - '.$capcesetmana);
$pdf->addText(750,580,10,'RRHH');
$pdf->addText(730,10,10,'Pagina');
$pdf->restoreState();
$pdf->closeObject();
//-- acaba les lineas
$pdf->addObject($all,'all');
/**/
$cols='';
//-- Aqui es coloca la capçelera de la Taula -- //
$cols = array('persona'=> 'Persona');
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
$nreg_abs = mysql_num_rows($sql_abs);
$cols2= "'persona'=> array('justification' => 'left'),";
while($res_abs = mysql_fetch_row($sql_abs)){
$u = $res_abs['0'];
$cols[$u] = $res_abs['1'];
}
// ------------------------------------------- //
/*
echo "<pre>";
print_r($cols);
echo "</pre>";
/**/
$p = 0;
while ($res_hores_persona = mysql_fetch_row($sql_hores_persona)) {
//nom de la persona
$nomcomplet = $res_hores_persona['3']." ".$res_hores_persona['4'].", ".$res_hores_persona['2'];
$nomcomplet = htmlentities($nomcomplet);
$data[$p] = array('persona' => $nomcomplet);
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
while($res_abs = mysql_fetch_row($sql_abs)){
$str_hores_abs = "SELECT sum(absencia)
FROM hores h INNER JOIN personal p
ON h.id_persona = p.id_persona
WHERE p.id_seccio=".$res_seccio['0']." AND p.id_persona = ".$res_hores_persona['0']."
AND id_tipoabsencia = ".$res_abs['0']." AND data >= ".$desde." AND data <= ".$fins."
GROUP BY p.dni,id_tipoabsencia";
//echo $str_hores_abs."<br>";
$sql_hores_abs = mysql_query($str_hores_abs)or die("Error SQL Horas Ausencia: ".mysql_error());
$nreg_hores_abs = mysql_num_rows($sql_hores_abs);
if($nreg_hores_abs !=0){
$res_hores_abs = mysql_fetch_row($sql_hores_abs);
$hores_abs = $res_hores_abs['0'];
}else{
$hores_abs = 0;
}
$u=$res_abs['0'];
$data[$p][$u] = number_format($hores_abs,2,",",".");
}// -- while($res_abs = mysql_fetch_row($sql_abs)){
$p++;
}// -- while ($res_hores_persona = mysql_fetch_row($sql_hores_persona)) {
}// -- if ($nreg_hores_persona != 0){
/*
echo "<pre>";
print_r($data);
echo "</pre>";
/**/
$sql_abs = mysql_query($str_abs)or die("Error SQL Tipo Ausencia: ".mysql_error());
$nreg_abs = mysql_num_rows($sql_abs);
$i=1;
$cols2= "'persona'=> array('justification' => 'left'),"."<br>";
while($res_abs = mysql_fetch_row($sql_abs)){
if($nreg_abs == $i){
$cols2 .= "'".$res_abs['0']."'=>array('justification' => 'left'))";
}else{
$cols2 .= "'".$res_abs['0']."'=>array('justification' => 'left'),";
}
$i++;
}
/*
echo "<pre>";
print_r($cols2);
echo "</pre>";
/**/
$pdf->ezTable($data,$cols,'',array('fontSize'=>8, 'cols'=>array($cols2)
));//-- sortida
$pdf->ezText('',10);
$data = '';
$cols='';
$cols2='';
}// -- while($res_seccio= mysql_fetch_row($sql_seccio)){
}// -- if($nreg_seccio != 0){
}// -- while($res_empresa = mysql_fetch_row($sql_empresa)){
}// --if($nreg_empresa != 0){
if (isset($d) && $d){
$pdfcode = $pdf->ezOutput(); //-- Necessari xq funcioni ezStartPageNumbers
$pdfcode = str_replace('\n','\n<br>',htmlspecialchars($pdfcode));
echo '<html><body>';
echo trim($pdfcode);
echo '</body></html>';
} else {
$pdf->ezStream(); //Necessari xq funcioni ezStartPageNumbers
}
/*
echo "<pre>";
print_r($data);
echo "</pre>";
/**/
?>