Hello,
This is the pdf export file of my site (i didnt write the code, but i'm trying to fix the multiple values problem).
From here all the fields are displaying correctly on the pdf execept the multiple-select fields. They only Display the first value. (but all the values are correctly saved in DB)
Here i can't use the code
Code:
<?php foreach ($this->item->positions['pres-secteur'] as $field) : ?>
<?php echo $field->label; ?><br />
<?php echo $field->display; ?>
<?php endforeach; ?>
I guess because $field is not define on this file so the ->display doesnt show nothing.(?)
I see that the value is directly call from the database with (line 160)
Code:
<?php echo $pres_secteur;?>
pres_secteur is a multiple select field in flexicontent
i tryed to add $pres_secteur
[] to display all the values but it didnt work. I tryed a foreach spin and lot a tips found on google about displaying multiple selected values but it seems i'm stuck. It still display only ONE of the values selected (or nothing...).
Is the previous code not working because there is no 'positions' on my pdf export file?
I simply want to display a list of my selected values on my export.
Could you please guide me on this?
Best regards,
Shinji
Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('default_charset', 'UTF-8');
iconv_set_encoding("input_encoding", "UTF-8");
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
mb_internal_encoding("UTF-8");
//echo JPATH_BASE;exit;
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', dirname(__FILE__).(DS.'..'.DS.'..') );
//echo JPATH_BASE;exit;
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );
//echo ."<br/>";
if($_SERVER['SERVER_NAME'] == "xxxxx" || $_SERVER['SERVER_NAME'] == "xxxxx"){
$uri_root = "xxxxxxx";
}else{
if($_SERVER['SERVER_NAME'] == "xxxxx" || $_SERVER['SERVER_NAME'] == "xxxxxxxx")
$uri_root = "xxxxxx";
else
$uri_root = "xxxxxxxx";
}
$uri_root = JURI::base();
$id = JRequest::getInt('id');
$extra = JRequest::getInt('extra');
//if(id == 0)
//require_once('../../libraries/joomla/database/table.php');
//JTable::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'tables');
function htmlallentities($str){
$res = '';
$strlen = strlen($str);
for($i=0; $i<$strlen; $i++){
$byte = ord($str[$i]);
if($byte < 128) // 1-byte char
$res .= $str[$i];
elseif($byte < 192); // invalid utf8
elseif($byte < 224) // 2-byte char
$res .= '&#'.((63&$byte)*64 + (63&ord($str[++$i]))).';';
elseif($byte < 240) // 3-byte char
$res .= '&#'.((15&$byte)*4096 + (63&ord($str[++$i]))*64 + (63&ord($str[++$i]))).';';
elseif($byte < 248) // 4-byte char
$res .= '&#'.((15&$byte)*262144 + (63&ord($str[++$i]))*4096 + (63&ord($str[++$i]))*64 + (63&ord($str[++$i]))).';';
}
return $res;
}
$tmp_query = JFactory::getdbo();
$db =& $tmp_query;
$q = "
SELECT
`c`.`introtext` as `description`, `c`.`title` as `title`
FROM `#__content` as `c`
WHERE `id` = '{$id}'";
$db->setQuery($q);
$article = $db->loadObjectList();
foreach ($article[0] as $key => $value) {
$$key = utf8_decode($value);
}
$q = "
SELECT
`fir`.`value` as `value`,
`ff`.`name` as `field_name`, `ff`.`label` as `field_label`,
`fil`.`filename` as `filename`, `fil`.`description` as `file_description`
FROM `#__flexicontent_fields_item_relations` as `fir`
INNER JOIN `#__flexicontent_fields` as `ff` ON `fir`.`field_id` = `ff`.`id`
LEFT JOIN `#__flexicontent_files` as `fil` ON `fir`.`value` = `fil`.`id`
WHERE `fir`.`item_id` = '{$id}'
";
$db->setQuery($q);
$flexi_infos = $db->loadObjectList();
/*echo "<pre>";
print_r($flexi_infos);exit;*/
foreach ($flexi_infos as $item) {
$var_name = $item->field_name;
//echo htmlallentities($item->value);
$$var_name = htmlallentities($item->value);
if(!empty($item->filename) && $item->field_name != 'pres_realisation' && $item->field_name != 'pres_superficie' && $item->field_name != 'pres_chiffres' && $item->field_name != 'honoraires' && $item->field_name != 'cp' && $item->field_name != 'adresse' && $item->field_name != 'ville' && $item->field_name != 'patenaires' && $item->field_name != 'pres_ouvre' && $item->field_name != 'pres_secteur'){
$$var_name = $item->filename;
}
}
//exit;
ini_set('memory_limit','256M');
$save_pdf = true;
$euro_sign = "€";//iconv("UTF-8", "cp1250", '€');
if ($save_pdf) ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>OTCE</title>
<meta name="title" content="" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" />
</head>
<!--[if lt IE 7]> <body class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]> <body class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <body class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <body class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <body> <![endif]-->
<!--[if !IE]><!--> <body> <!--<![endif]-->
<div class="wrap">
<div id="center">
<form id="pdf-form" action="" method="post">
<div class="pdf-header">
<p align='left' class='top_text' style='text-transform:uppercase;color:#394f8f;'><strong><div class="top_desc_title"><?php echo $title;?></div></strong><br/><div class="top_sub"><?php echo $pres_nom;?></div><div class="top_desc"><?php echo $description;?></div></p>
</div>
<div class="position">
<div class="pdf-image">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<?php if(isset($slider_img1)){ ?>
<img src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img1; ?>" width="500" height="310" alt="" />
<?php } ?>
</td>
<td align="right">
<?php if(isset($slider_img2)){ ?>
<img src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img2; ?>" width="245" height="150" alt="" />
<?php } ?>
<br/>
<?php if(isset($slider_img3)){ ?>
<img style="padding-top:8px;" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img3; ?>" width="245" alt="" height="156" />
<?php } ?>
</td>
</tr>
</table>
</div>
<br/>
<table width="752" class="pdf-content" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="40%" style="padding-left:25px;">
<?php if(isset($pres_secteur)){ ?>
<h1>Secteur</h1>
<p><?php echo $pres_secteur;?></p>
<br/>
<?php }?>
<?php if(isset($pres_lieu)){ ?>
<h1>Lieu de réalisation</h1>
<p><?php echo $pres_lieu; ?></p>
<br/>
<?php } ?>
<?php if(isset($pres_ouvrage)){ ?>
<h1>Maîtrise d'ouvrage</h1>
<p><?php echo $pres_ouvrage; ?></p>
<br/>
<?php }?>
<?php if(isset($pres_ouvre)){ ?>
<h1>Missions</h1>
<p><?php echo $pres_ouvre; ?></p>
<br/>
<?php } ?>
<?php if(isset($pres_chiffres)){ ?>
<h1>Chiffres clés</h1>
<span class="chcl">Montant des travaux :</span><?php echo $pres_chiffres; ?>
<br/>
<br/>
<?php } ?>
<?php if(isset($pres_superficie)){ ?>
<span class="chcl">Superficie :</span><?php echo nl2br($pres_superficie); ?>
<br/>
<?php } ?>
<br/>
<?php if(isset($pres_calendrier)){ ?>
<h3>Calendrier : </h3>
<p><?php echo nl2br($pres_calendrier); ?></p>
<br/>
<?php } ?>
<br/>
<?php if(isset($pres_operation)){ ?>
<?php
//$pres_operation = str_replace('?','’',$pres_operation);
?>
<h1>Opération</h1>
<?php
//$pres_operation = mb_convert_encoding($pres_operation, 'HTML-ENTITIES', 'UTF-8');
?>
<p><?php echo $pres_operation; ?></p>
<br/>
<?php } ?>
</td>
<td width="40%" style="padding-left:0px;">
<?php if(isset($pres_specificites )){ ?>
<h1>Spécificités</h1>
<p><?php echo $pres_specificites ; ?></p>
<br/>
<?php } ?>
<br/>
<?php if(isset($pres_efficacite_logo) || isset($pres_efficacite_image)){ ?>
<h1>Efficacité énergétique</h1>
<?php } ?>
<?php if(isset($pres_efficacite_texte )){ ?>
<p><?php echo $pres_efficacite_texte ; ?></p>
<?php }?>
<?php if(isset($pres_efficacite_logo)){ ?>
<p><img width="80" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$pres_efficacite_logo; ?>" alt="" /></p>
<?php } ?>
<br/>
<?php if(isset($pres_efficacite_image)){ ?>
<p><img width="350" styles="height:100%; width:100%; max-height:160px; max-width:350px;" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$pres_efficacite_image; ?>" alt="" /></p>
<?php } ?>
</td>
</tr>
</table>
<br/>
<div class="pdf-footer">
<img width="752" height="92" src="<?php echo $uri_root."templates/otce/images/pdf-footer.png";?>" alt=""/>
</div>
<?php if($extra == 1){ ?>
<br/>
<div class="extra-admin">
<?php if(isset($architectes)){ ?>
<h1>Architectes</h1>
<p><?php echo $architectes; ?></p>
<br/>
<?php } ?>
<?php if(isset($field50)){ ?>
<h1>AMO</h1>
<p><?php echo $field50; ?></p>
<br/>
<?php } ?>
<?php if(isset($nom_contact_technique)){ ?>
<h1>Contact technique MO</h1>
<p><?php echo $nom_contact_technique; ?></p>
<br/>
<?php } ?>
<?php if(isset($adresse)){ ?>
<h1>Adresse MO</h1>
<p><?php echo $adresse; ?></p>
<br/>
<?php } ?>
<?php if(isset($ville)){ ?>
<h1>Tél MO</h1>
<p><?php echo $ville; ?></p>
<br/>
<?php } ?>
<?php if(isset($cp)){ ?>
<h1>Contact MO</h1>
<p><?php echo $cp; ?></p>
<br/>
<?php } ?>
<?php if(isset($patenaires)){ ?>
<h1>Partenaires MOE</h1>
<p><?php echo $patenaires; ?></p>
<br/>
<?php } ?>
<?php if(isset($honoraires)){ ?>
<h1>Honoraires OTCE</h1>
<p><?php echo $honoraires; ?></p>
<br/>
<?php } ?>
<?php if(isset($filiale_realisation)){ ?>
<h1>Filiale OTCE qui a suivi la réalisation</h1>
<p><?php echo $filiale_realisation; ?></p>
<br/>
<?php } ?>
<?php if(isset($creation)){ ?>
<h1>Date de création</h1>
<p><?php echo $creation; ?></p>
<br/>
<?php } ?>
<?php if(isset($date_mise_jour)){ ?>
<h1>Date de mise à jour</h1>
<p><?php echo $date_mise_jour; ?></p>
<br/>
<?php } ?>
<?php if(isset($chef_projet)){ ?>
<h1>Chef de projet</h1>
<p><?php echo $chef_projet; ?></p>
<br/>
<?php } ?>
<?php if(isset($redacteur)){ ?>
<h1>Rédacteur</h1>
<p><?php echo $redacteur; ?></p>
<br/>
<?php } ?>
<?php if(isset($titre_champ_perso)){ ?>
<h1><?php echo $titre_champ_perso; ?></h1>
<?php } ?>
<?php if(isset($champ_perso)){ ?>
<p><?php echo $champ_perso; ?></p>
<br/>
<?php } ?>
</div>
<br/>
<div class="pdf-footer">
<img width="752" height="92" src="<?php echo $uri_root."templates/otce/images/pdf-footer.png";?>" alt=""/>
</div>
<?php } ?>
</div>
</form>
<!--<div class="img"<?php echo (!$save_pdf) ? " style='position:relative;bottom:0;'" : "";?>>
<img class="change_img" src="images/img1.png" width="752" height="180" alt=""/>
</div>-->
</div>
</div><!-- /.wrap -->
<script src="js/jquery-latest.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/script.js" type="text/javascript" charset="utf-8"></script>
</body>
</html><?
if ($save_pdf) {
$html = ob_get_contents();
$html = str_replace("images/img1.png","images/img".$_REQUEST['select_img'].".png",$html);
ob_end_clean();
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_paper( array(0,0, 564, 800), "portrait" );
$dompdf->load_html(utf8_encode($html));
$dompdf->render();
$uniqname = uniqid();
$uniqname = "sample";
file_put_contents('generated/'.$uniqname.'.pdf', $dompdf->output());
echo $uri_root.'templates/otce/generated/'.$uniqname.'.pdf?v='.time();
}