Salve, sto customizzando un plugin per joomla, in attesa che venga reso disponibile già fatto da qualche sito.
Il mio problema è questo, devo inviare una mail formattata in un certo modo mantenendo su di questa alcuni dati presi da un database.
Dispongo di questi due file che parlano tra loro.
Il primo struttura i dati e li passa al secondo che invia la mail. Non riesco a capire però come potere formattare (o usare un altra soluzione) un textbox precompilato.
File 1: Default.php
Codice PHP:
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
?>
<style>
#emailtable ul{
list-style:none;
}
#emailtable li{
background-image:none;
margin-top:15px;
}
</style>
<div id="emailtable-content">
<form method="post" enctype="multipart/form-data" action="<?php echo JURI::base();?>index.php" name="emailtable" id="emailtable">
<?php echo JText::sprintf('EMAIL %s RECORDS', $this->recordcount) ?></p>
<ul>
[*]
<label>
<?php echo JText::_('TO') ?>
<?php echo $this->fieldList ?>
</label>
[*]
<label>
<?php echo JText::_('SUBJECT') ?>
<input class="inputbox fabrikinput" type="text" name="subject" id="subject" value="" size="20" />
</label>
[*]
<label>
<?php echo JText::_('MESSAGE') ?>
<textarea name='message' id='message' type="text/html">
I.B.O. Italia
>ASSOCIAZIONE ITALIANA SOCI COSTRUTTORI
I.B.O. Italia
ASSOCIAZIONE ITALIANA SOCI COSTRUTTORI
SCHEDA VOLONTARIO {RegistrazioneCampiIta___Nomeita} {RegistrazioneCampiIta___Cognomeita} {RegistrazioneCampiEU___NomeEU} {RegistrazioneCampiEU___CognomeEU} {RegistrazioneCampiINT___NomeINT} {RegistrazioneCampiINT___CognomeINT}
DATI ANAGRAFICI
Luogo di nascita: {RegistrazioneCampiIta___ComunedinascitaITA} {RegistrazioneCampiEU___ComunedinascitaEU} {RegistrazioneCampiINT___ComunedinascitaINT}
Data di nascita: {RegistrazioneCampiIta___Datadinascitaita} {RegistrazioneCampiEU___DatadinascitaEU} {RegistrazioneCampiINT___DatadinascitaINT}
Residenza: {RegistrazioneCampiIta___Indirizzoita} - {RegistrazioneCampiIta___CAPita} - {RegistrazioneCampiIta___Cittaita} ({RegistrazioneCampiIta___Provita})
{RegistrazioneCampiEU___IndirizzoEU} - {RegistrazioneCampiEU___CAPEU} - {RegistrazioneCampiEU___CittaEU} ({RegistrazioneCampiEU___ProvEU})
{RegistrazioneCampiINT___IndirizzoINT} - {RegistrazioneCampiINT___CAPINT} - {RegistrazioneCampiINT___CittaINT} ({RegistrazioneCampiINT___ProvINT})
Telefono: {RegistrazioneCampiIta___Cellulareita} {RegistrazioneCampiEU___CellulareEU} {RegistrazioneCampiINT___CellulareINT}
E-mail: {RegistrazioneCampiIta___MailITA} {RegistrazioneCampiEU___MailEU} {RegistrazioneCampiINT___MailINT}
DATI PERSONALI
Professione: {RegistrazioneCampiIta___ProfessioneITA} {RegistrazioneCampiEU___ProfessioneEU} {RegistrazioneCampiINT___ProfessioneINT}
Lingue parlate: {RegistrazioneCampiIta___LingueparlateITA} {RegistrazioneCampiEU___LingueparlateEU} {RegistrazioneCampiINT___LingueparlateINT}
Come sei venuto a conoscenza dell'I.B.O. Italia?
{RegistrazioneCampiIta___FeedbackITA} {RegistrazioneCampiEU___FeedbackEU} {RegistrazioneCampiINT___FeedbackINT}
Hai fatto altri campi di lavoro I.B.O. Italia?
{RegistrazioneCampiIta___EsperienzeITA} {RegistrazioneCampiEU___EsperienzeEU} {RegistrazioneCampiINT___EsperienzeINT}
Quali sono per te le componenti più importanti nella scelta di un campo?
{RegistrazioneCampiIta___MotivazioniITA} {RegistrazioneCampiEU___MotivazioniEU} {RegistrazioneCampiINT___MotivazioniINT}
Come puoi contribuire alla buona riuscita del campo?
{RegistrazioneCampiIta___PreparazioneITA} {RegistrazioneCampiEU___PreparazioneEU} {RegistrazioneCampiINT___PreparazioneINT}
Quali sono le motivazioni che ti spingono a fare questa esperienza?
{RegistrazioneCampiIta___SolidarietaITA} {RegistrazioneCampiEU___SolidarietaEU} {RegistrazioneCampiINT___SolidarietaINT}
Autorizza IBOItalia al trattamento dei miei dati personali.
<?php $valore="{RegistrazioneCampiIta___Richiestasocioita}" ;
if ($valore === "SI" ) echo "Richiede di diventare socio IBOItalia.";
else if ($valore === "No" ) {echo "Non Richiede di diventare socio IBOItalia.";}
else echo "" ?>
<?php $valore="{RegistrazioneCampiEU___RichiestasocioEU }" ;
if ($valore === "SI" ) echo "Richiede di diventare socio IBOItalia.";
else if ($valore === "No" ) echo "Non Richiede di diventare socio IBOItalia.";
else echo ""?>
<?php $valore="{RegistrazioneCampiINT___RichiestasocioINT }" ;
if ($valore === "SI" ) echo "Richiede di diventare socio IBOItalia.";
else if ($valore === "No" ) echo "Non Richiede di diventare socio IBOItalia.";
else echo ""?>
DATA
____________________
FIRMA
___________________________________________________
(in caso di minorenni firma di un genitore o di chi ne fa le veci)
</textarea>
</label>
[*]
<label>
<?php echo JText::_('ATTACHMENT') ?>
<input class="inputbox fabrikinput" name="attachement" type="file" id="attachement" />
</label>
[*]
<input type="button" id="submit" value="<?php echo JText::_('SEND') ?>" class="button" />
[/list]
<input type="hidden" name="option" value="com_fabrik" />
<input type="hidden" name="controller" value="table.emailtable" />
<input type="hidden" name="task" value="doemail" />
<input type="hidden" name="id" value="<?php echo $this->tableid ?>" />
<input type="hidden" name="recordids" value="<?php echo $this->recordids ?>" />
</form>
</div>
<script type="text/javascript">
myFunc = function(){
$('submit').addEvent('click', function(e){
var event = new Event(e).stop();
var err = '';
if($('order_by').getValue() == '' || $('order_by').getValue() == '-'){
err += ('<?php echo JText::_('PLEASE SELECT THE FIELD CONTAINING THE EMAIL ADDRESSES YOU WISH TO MAIL'); ?>' + "\n");
}
if($('subject').getValue() == ''){
err += ('<?php echo JText::_('PLEASE ENTER A SUBJECT'); ?>');
}
if(err != ''){
alert(err)
}else{
new Ajax('<?php echo JURI::base();?>index.php?&tmpl=component&' + $('emailtable').toQueryString()
, {
'data':{
'recordids':'<?php echo $this->recordids ?>'
},
'onComplete':function(r){
$('emailtable-content').setHTML(r);
}
}).request();
}
});
}
window.addEvent('domready', function(){
(myFunc).delay(200);
}
);
</script>
File 2: Controller/emailtable.php
Codice PHP:
<?php
/**
* @package Joomla
* @subpackage Fabrik
* @copyright Copyright (C) 2005 Rob Clayburn. All rights reserved.
* @license [url]http://www.gnu.org/copyleft/gpl.html[/url] GNU/GPL, see LICENSE.php
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport( 'joomla.application.component.controller' );
require_once( COM_FABRIK_FRONTEND.DS.'helpers'.DS.'params.php' );
require_once( COM_FABRIK_FRONTEND.DS.'helpers'.DS.'string.php' );
require_once( COM_FABRIK_FRONTEND.DS.'helpers'.DS.'parent.php' );
/**
* Contact Component Controller
*
* @static
* @package Joomla
* @subpackage Contact
* @since 1.5
*/
class FabrikControllerTableemailtable extends JController
{
/** @var string path of uploaded file */
var $filepath = null;
/**
* default display mode
*
* @return unknown
*/
function display()
{
echo "display";
}
/**
* set up the popup window containing the form to create the
* email message
*
* @return string html
*/
function popupwin()
{
$document =& JFactory::getDocument();
$viewName = 'popupwin';
$viewType = $document->getType();
// Set the default view name from the Request
$view = &$this->getView( $viewName, $viewType );
$tableModel =& $this->getModel( 'Table' );
$tableModel->setId(JRequest::getVar('id', 0));
$formModel =& $tableModel->getForm();
// Push a model into the view
$model = &$this->getModel( 'emailtable' );
if (!JError::isError( $model )) {
$view->setModel( $model, true );
}
$view->setModel( $tableModel );
$view->setModel( $formModel );
$pluginManager =& $this->getModel( 'PluginManager' );
$pluginManager->_loadPaths( 'table', 'emailtable' );
// Display the view
$view->assign( 'error', $this->getError() );
return $view->display();
}
/**
* upload the attachments to the server
* @access private
*
* @return bol success/fail
*/
function _upload()
{
jimport('joomla.filesystem.file');
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
$file = JRequest::getVar( 'attachement', '', 'files' );
$folder = JPATH_ROOT.DS.'images'.DS.'stories';
$this->filepath = '';
if($file['name'] == ''){
return true;
}
$this->filepath = $folder.DS.strtolower($file['name']);
if (!JFile::upload($file['tmp_name'], $this->filepath)) {
JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
return false;
} else {
return true;
}
}
function doemail()
{
jimport('joomla.mail.helper');
if (!$this->_upload()) {
return false;
}
$to = str_replace('.', '___', JRequest::getVar('order_by'));
$subject = JRequest::getVar('subject');
$message = JRequest::getVar('message');
$recordids = explode(',', JRequest::getVar('recordids'));
$tableModel =& $this->getModel( 'Table' );
$tableModel->setId(JRequest::getVar('id', 0));
$w = new FabrikWorker();
$config =& JFactory::getConfig();
$email_from = "Iboitalia";
$cc = null;
$bcc = null;
$sent = 0;
$notsent = 0;
foreach ($recordids as $id) {
$row = $tableModel->getRow($id);
$mailto = $row->$to;
if ( JMailHelper::isEmailAddress($mailto)) {
$thissubject = $w->parseMessageForPlaceholder( $subject, $row );
$thismessage = $w->parseMessageForPlaceholder( $message, $row );
$res = JUtility::sendMail( $email_from, $email_from, $mailto, $thissubject, $thismessage, 1, $cc, $bcc, $this->filepath );
if ($res) {
$sent ++;
} else {
$notsent ++;
}
} else {
$notsent ++;
}
}
global $mainframe;
$mainframe->enqueueMessage( JText::sprintf('%s emails sent', $sent));
if ($notsent != 0) {
JError::raiseWarning(E_NOTICE, JText::sprintf('%s emails not sent', $notsent));
}
}
}
?>
Grazie per eventuali aiuti, i valori tra { } sono dei placeholder che vanno ad indetificare un valore nel database.