I have setup OpenTBS to generate dynamically from my contacts database. Now I want to setup the actual content of the email to come from a MySQL table created using CKeditor or another WYSISYG JS editor.
I have been able to get the content to display on the outputted docx file but it is coming this as a straing with the html tags, I somehow need this to format so it comes though as it was put in by the client. I am only going to allow them to use the basics, paragrahs, bold, italics and maybe a few other tags.
Is this someway I can convert this html string to word copy / text? Or somehow have a different WYSIWYG editor to save it in MySQL as word code rather then html code.
Thanks
It's not really relevant but below is the function that generates the OpenTBS document from a template and the database (I am using CakePHP) MailMerge.description is the body with the html code at the moment.
// FUNCTION EXPORT MAIL MERGE
// -------------------------------------------------------------->
function mail_merge()
{
Configure::write('debug',2);
$this->layout = null;
$this->autoRender = FALSE;
// GET THE CONTACTS
// ------------------------------------------------------------->
$contacts = $this->Contact->find('all', array('limit' => 20, 'contain' => FALSE));
$this->loadModel('MailMerge');
$content = $this->MailMerge->find('first', array(
'conditions' => array('MailMerge.id' => 1),
'fields' => array('MailMerge.description')
));
// Get a new instance of TBS with the OpenTBS plug-in
// ------------------------------------------------------------->
$otbs = $this->Tbs->getOpenTbs();
// Load the template file
// ------------------------------------------------------------->
$otbs->LoadTemplate(APP . DS . WEBROOT_DIR . '/files/data_files/enquiry_letter_sample_redcliffe.docx');
// Merge data in the template
// ------------------------------------------------------------->
$otbs->MergeBlock('r', $contacts);
$otbs->MergeBlock('content', $content);
// End the merge and export
// ------------------------------------------------------------->
$file_name = 'export.docx';
$otbs->Show(OPENTBS_DOWNLOAD, $file_name);
}
Related
I'm trying to generate an excel file using PHPExcel Module in the action_info function with the following code :
function mymodule_export_data_action(&$object, $context = array()) {
if (isset($object->uid)) {
$uid = $object->uid;
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
}
if ($uid) {
module_load_include('inc', 'phpexcel');
$filename = 'mymodule--download-' . uniqid() . '.xls';
$filepath = variable_get('file_public_path', conf_path() . '/files') . '/' . $filename;
$result = phpexcel_export(
array('Nom', 'Prenom', 'Date de naissance', 'Adresse email'),
array(
array('A1', 'B1'),
array('A2', 'B2'),
), $filepath);
if ($result === PHPEXCEL_SUCCESS) {
drupal_set_message(l('Click to download', $filepath));
}
else {
}
}
}
This is working pretty fine when having just one node, but when there's more than one it generates a new file for each one, which also good but my purpose is to have one file for all nodes. It has been days and I really hope for someone to put me in the right direction.
Thank you in advance
Here is the solution by using views module, views_data_export module, 2 lines of PHP code and some lines of jQuery.
Just follow these steps:
1st Install views and views_data_export modules
2nd (a) Create views page and data export, this video
will help you to export the data according to the
filter(s)
2nd (b) Don't forget to add nid field in the views page that will use to get NIDs
2nd (c) Now, create one more views data export (that again starts here, if you need) and create exporting PATH different than the first data export (created on step 2nd (a)) but keep remember you don't have to update Attach to option under the DATA EXPORT SETTINGS section, it should looks like this Attach to: none.
2nd (d) Now, add nid as contextual filter in the views and choose Provide default value = Content ID from URL like this and check the checkbox Allow multiple values like this
3rd Add two lines of PHP code somewhere in the template.php OR top of the tpl of views page if you have already created (by the way I did it with the tpl named as views-view--export-multiple-rows--page.tpl.php).
if($_SERVER['REQUEST_METHOD'] == 'POST') {
drupal_goto("export_selected/".implode(',', $_POST['export']));
}
4th Add below jQuery code in the JS file that will be render on this page like custom.js and **change classes **
jQuery(function($){
jQuery('.feed-icon a:first-child').text('Export All');
jQuery('td.views-field-nid').each(function() { //class of NID added in step 2nd (b)
var t = jQuery(this);
var id = jQuery.trim(t.text());
t.html('<input type="checkbox" name="export[]" value="" />');
t.find('input').val(id);
});
//Below .view-export-multiple-rows class is of views class (main views page)
$('.view-export-multiple-rows').wrap('<form method="POST" class="export-form"></form>');
$('.export-form .view-content').append('<input type="submit" value="Export Selected" name="submit" />');
});
If you follow all these steps properly, I believe you have done with:
To export all rows
To export filtered rows
To export specific rows
I hope this will help you or at least give you an idea.
Thanks
Can I add new nodes to mustache template at run-time in PHP? Let's say below is a code where ProductDetails will contain few single products:
{{#ProductDetails}}
{{#SingleProduct}}
{{OldDetail}}
{{/SingleProduct}}
{{/ProductDetails}}
I want to add a new node like {{NewDetail}} just after {{OldDetail}} through some function in run-time(i.e just before I am compiling the template as these templates have been shipped to customers in such a way that only code to compile can be changed but not the template)? I don't want to do string manipulation(customers created few new templates with above parameters present at least but the spacing may change & few new entries can be added by them around nodes). Does mustache library provide any functions for that?
If I were you, I will try Lambdas.
Template.mustache will be like this:
{{#ProductDetails}}
{{#SingleProduct}}
{{OldDetail}}
{{/SingleProduct}}
{{/ProductDetails}}
And codes will be like:
$Mustache = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader($YOUR_TEMPLATE_FOLDER),]);
$Template = $Mustache->loadTemplate('Template');
$OriginalOldDetail = '<h1>this is old detail</h1>';
echo $Template->Render([
'ProductDetails' => true,
'SingleProduct' => true,
'OldDetail' => function($text, Mustache_LambdaHelper $helper){
// Render your original view first.
$result = $helper->render($text);
// Now you got your oldDetail, let's make your new detail.
#do somthing and get $NewDetail;
$NewDetail = $YourStuff;
// If your NewDetail is some mustache format content and need to be render first.
$result .= $help->render($NewDetail);
// If is some content which not need to be render ? just apend on it.
$result .= $NewDetail;
return $result;
}
]);
Hope that will help.
(English is not my first language so hope you can understand what I'm talking about.)
I'm using FPDF to generate PDF. I use a PDF template created on Adobe Acrobat that include form inputs.
I've been using the following code to generate my pdf :
<?php
***************************
Sample using a PHP array
****************************/
require('fpdm.php');
$fields = array(
'date' => '07/07/2017',
'names' => 'Something',
);
$pdf = new FPDM('Singlepage.pdf');
$pdf->Load($fields, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output();
?>
It's working perfectly but now i'd like to add multiples lines to my "names" form. Something like 'names' => 'Someone1 \n Someone2But I can't figure out how to do it.
On my pdf template, I added the "multiples lines" to the text input.
Do you have any idea ?
And then i'd like to format this text, so I could add bold, italic etc to the text
The problem are the single quotes, change to double quotes and it will work (if the field is multi-line, of course):
$fields = array(
'date' => '07/07/2017',
'names' => "Something \n more",
);
I have a simple function that all content on my website is filtered through to capitilize the company's name. Here is the function:
function brand_capitilize($content) {
$content = str_replace("Brand", "BRAND", $content);
return $content;
}
I need to modify this to ignore the word "Brand" if it's in a url. For example, I do not want the word 'Brand' to be capitalized in the following situation:
View PDF
If I feed this through brand_capitilize() right now, I end up with:
View PDF
iam using ckeditor in my website to add the content to the pages.
But I'm not able to understand how I get this content in ckeditor for editing it later...
How to load content into the ckeditor? Iam using the following code to load the editor:
if ( !#file_exists( '../../ckeditor/ckeditor.php' ) )
{
if ( #file_exists('../../ckeditor/ckeditor.js') || #file_exists('../../../ckeditor/ckeditor_source.js') )
printNotFound('CKEditor 3.1+');
else
printNotFound('CKEditor');
}
include_once '../../ckeditor/ckeditor.php';
include_once '../../ckfinder/ckfinder.php';
// This is a check for the CKEditor class. If not defined, the paths in lines 57 and 70 must be checked.
if (!class_exists('CKEditor'))
{
printNotFound('CKEditor');
}
else
{
$ckeditor = new CKEditor();
$ckeditor->basePath = '../../ckeditor/';
$ckfinder = new CKFinder();
$ckfinder->BasePath = '../../ckfinder/'; // Note: BasePath property in CKFinder class starts with capital letter
$ckfinder->SetupCKEditorObject($ckeditor);
$ckeditor->editor('message');
}
One way is to pre-populate the <textarea> field with the appropriate (htmlentities() processed) HTML content. CKEditor will automatically fetch the data, and insert it into the WYSIWYG editor.
See the Integration chapter in the developers guide
For those who not found the answer, the "editor" method of ckeditor allow to load default value
public function editor($name, $value = "", $config = array(), $events = array())
Just pass your default value in the second parameters.