How to include a for and multidimensional array in the body of php mailer? - phpmailer

I am using PHP Mailer.
I want to add dynamic content in php to the body but I am not being able to do it.
If I add this on the php mailer body, it works.
$mail->Body="<h3>Dados do 1º Titular</h3><ul><li><b>Nome: </b>".$titular1_name."</li><li><b>Idade: </b>".$titular1_idade."</li><li><b>Estado Civil</b>".$titular1_estado_civil."</li><li><b>Dependentes</b>".$titular1_dependentes."</li><li><b>Rendimento</b>".$titular1_rendimento."</li><li><b>Penhora</b>".$titular1_penhora."</li></ul><h3>Dados do 2º titular</h3><ul><li><b>Nome: </b>".$titular2_name."</li><li><b>Idade: </b>".$titular2_idade."</li><li><b>Estado Civil</b>".$titular2_estado_civil."</li><li><b>Dependentes</b>".$titular2_dependentes."</li><li><b>Rendimento</b>".$titular2_rendimento."</li><li><b>Penhora</b>".$titular2_penhora."</li></ul><h3>Dados de Contacto</h3><ul><li><b>Email: </b>".$titular_email."</li><li><b>Telefone</b>".$titular_phone."</li><li><b>Localidade</b>".$titular_local."</li></ul>";
But I need to add this result:
for ($y = 0; $y <= $numberOfRows; $y++){
for ($x = 0; $x < $maxData; $x++) {
array_push($row, $credito,
$capital_divida, $prestacao,
$bank, $garantias, $situacao);
echo $row[$x]."<br>";
}
array_push($fullData, $row);
}
This is my relevant code for this issue:
$row = array();
$fullData = array();
$maxData = 6;
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$titular_email = htmlspecialchars($_POST["titular-email"]);
$titular_phone = htmlspecialchars($_POST["titular-phone"]);
$titular_local = htmlspecialchars($_POST["titular-local"]);
$titular_message = htmlspecialchars($_POST["titular-message"]);
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$credito = htmlspecialchars(["credito"]);
$capital_divida = htmlspecialchars(["capital_div"]);
$prestacao = htmlspecialchars(["prestacao"]);
$bank = htmlspecialchars(["bank"]);
$garantias = htmlspecialchars(["garantias"]);
$situacao = htmlspecialchars(["situacao"]);
Thank you in advance for all the help

This code doesn't make any sense:
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
It looks like you're missing the name of an array you want to get this value from, for example:
$numberOfRows = htmlspecialchars($_POST["numberOfRowsHTML"]);
Your loop that assembles the array doesn't appear to do anything useful at all - you're getting values from the submission, then assembling an array which you don't use. It would be helpful if you could clarify what it is you're trying to do.

Related

String with multiple lines of weblink images. How to display them?

I've got a String full of weblink image (23 links) :
listItem.text = String(item.movieimage);
If I do trace(String(item.movieimage)); the output is :
http://www.thewebsite.nc/Content/images/AFFICHES/xxx_3.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/vaiana.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/tous_scene.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fits.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/boyfriend.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/sahara2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/resident_evil_final.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/raid_dingue.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/passengers2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/lego_batman.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/grande_muraille.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fille_brest.jpg
Know, I've got 9 UILoader on my stage.
So I would like to do
uiloader1.source = item.movieimage[1];
uiloader2.source = item.movieimage[2];
uiloader3.source = item.movieimage[3];
...etc...
How can I do that ?
Thanks
Assuming they're separated by an indent
//Put all the links in an array
var myItems:Array = listItem_txt.text.split("\n");
//You say you only have nine, so only iterate until the 9th
for (var i:int = 0; i < 9; i++)
{
//Also assuming your "uiloader" is a custom class you made with a .source property
this.getChildByName("uiloader" + i).source = myItems[i];
}

displaying the mismatch into the excel using php

I am importing the the csv data into the database, records which are not matching with the dtdc are the mismatch are mismatched records . I am exporting those records into excel.Below is the else condition which we are taking the mismatch records
else{
$mismarchrows_dtdc[] = $row['Postcode'];
$mismatchcount_dtdc = $mismatchcount_dtdc+1;
}
Here i am writing the mismatched records into excel
$fileName_dtdc = 'uploads/csv/already_exist_customer_dtdc-'.time().'.xls';
$fp = fopen($fileName_dtdc, 'w');
$newLineSeparator = "\r\n";
$line1_dtdc = 'postcode'.$newLineSeparator;
fwrite($fp,$line1_dtdc);
foreach($mismarchrows_dtdc as $mrow){
$line2_dtdc = $mrow;
fwrite($fp,$line2_dtdc);
}
now only one column called postcode is only exported into excel, but i 5 more columns like firstname,lastname,middlename in to the excel with data
I tried by keeping like this, But coming in only one column
else{
$mismarchrows_dtdc[] = $row['Postcode'];
$mismarchrows_dtdc1[] .= $row['State'];
$mismatchcount_dtdc = $mismatchcount_dtdc + 1;
}
can anyone help with this !!!!!!!!!!!!!!!!!
I don't know your exact needs, but maybe this will help?
$csv_lines = array();
foreach($mismarchrows_dtdc as $mrow) {
$keys = array_keys($mrow);
$data = array();
foreach ($keys as $key) {
$data[] = $mrow[$key];
}
$csv_lines[] = implode(',',$data);
}
$fileName_dtdc = 'uploads/csv/already_exist_customer_dtdc-'.time().'.xls';
file_put_contents($fileName_dtdc,implode("\r\n",$csv_lines));

What is the closest function to INDEX( ,MATCH( in Google Apps?

I have a master spreadsheet which has the excel function:
=INDEX(D2:D4,MATCH(F11,B2:B4,0))
How would you express this in Google Apps or is there anything close to it?
Here is the part of the code which needs to be modified:
var link = masterSheet.getRange('F11').getValues();//here is the problem
//=INDEX(D2:D4,MATCH(F11,B2:B4,0))
var ss = SpreadsheetApp.openById(link);
If you are wanting to achieve the same functionality in Google Apps Script, and if I'm understanding correctly:
var lookup = masterSheet.getRange('F11').getValue();
var range = masterSheet.getRange('B2:D4').getValues();
var lookupRange = [];
for (var i = 0; i < range.length; i++) lookupRange.push(range[i][0]);
var index = lookupRange.indexOf(lookup);
if (index == -1) {
//error, not found
}
else {
var link = range[index][2];
var ss = SpreadsheetApp.openById(link);
//etc
}
Caveat: if you are searching for dates and/or times, this will fail. You will need to convert the date objects into something else that can be found with indexOf. Post back if this is the case.
That same formula should work equally well in both Excel and google spreadsheets, doesn't it work? VLOOKUP could also be used in both to do the same, i.e.
=vlookup(F11,B2:D4,3,0)

Insert image into a specified location

I have a Google Apps script which replaces placeholders in a copy of a template document with some text by calling body.replaceText('TextA', 'TextB');.
Now I want to extend it to contain images. Does anybody have idea how to do this?
Thank you,
Andrey
EDIT: Just to make it clear what my script does. I have a Google form created in a spreadsheet. I've created a script which runs upon form submission, traverses a sheet corresponding to the form, find unprocessed rows, takes values from corresponding cells and put them into a copy of a Google document.
Some fields in the Google form are multi-line text fields, that's where '\r\r' comes from.
Here's a workaround I've come up with by now, not elegant, but it works so far:
// replace <IMG src="URL"> with the image fetched from URL
function processIMG_(Doc) {
var totalElements = Doc.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
if (type =='PARAGRAPH'){
var par_text = element.getText();
var start = par_text.search(new RegExp('<IMG'));
var end = par_text.search(new RegExp('>'));
if (start==-1)
continue;
// Retrieve an image from the web.
var url = getURL_(par_text.substring(start,end));
if(url==null)
continue;
// Before image
var substr = par_text.substring(0,start);
var new_par = Doc.insertParagraph(++j, substr);
// Insert image
var resp = UrlFetchApp.fetch(url);
new_par.appendInlineImage(resp.getBlob());
// After image
var substr = par_text.substring(end+1);
Doc.insertParagraph(++j, substr);
element.removeFromParent();
j -= 2; // one - for latter increment; another one - for increment in for-loop
totalElements = Doc.getNumChildren();
}
}
}
Here is a piece of code that does (roughly) what you want.
(there are probably other ways to do that and it surely needs some enhancements but the general idea is there)
I have chosen to use '###" in the doc to mark the place where the image will be inserted, the image must be in your google drive (or more accurately in 'some' google drive ).
The code below uses a document I shared and an image I shared too so you can try it.
here is the link to the doc, don't forget to remove the image and to put a ### somewhere before testing (if ever someone has run the code before you ;-)
function analyze() { // just a name, I used it to analyse docs
var Doc = DocumentApp.openById('1INkRIviwdjMC-PVT9io5LpiiLW8VwwIfgbq2E4xvKEo');
var image = DocsList.getFileById('0B3qSFd3iikE3cF8tSTI4bWxFMGM')
var totalElements = Doc.getNumChildren();
var el=[]
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
Logger.log(j+" : "+type);// to see doc's content
if (type =='PARAGRAPH'){
el[j]=element.getText()
if(el[j]=='###'){element.removeFromParent();// remove the ###
Doc.insertImage(j, image);// 'image' is the image file as blob
}
}
}
}
EDIT : for this script to work the ### string MUST be alone in its paragraph, no other character before nor after... remember that each time one forces a new line with ENTER the Document creates a new paragraph.

Adobe InDesign hangs indefinitely when I try to duplicate pages using ExtendScript

I have a very simple ExtendScript script which creates a new document out of a subset of the current active document:
var sourceDocument = app.activeDocument;
var i, j;
for(i = 0; i < sourceDocument.layers.length; i++) {
sourceDocument.layers.item(i).locked = false;
}
for(i = 0; i < sourceDocument.spreads.length; i++) {
for(j = 0; j < sourceDocument.spreads.item(i).textFrames.length; j++) {
if(sourceDocument.spreads.item(i).textFrames.item(j).locked) {
sourceDocument.spreads.item(i).textFrames.item(j).locked = false;
}
}
}
var destDocument = app.documents.add();
var firstPageIndex = 0; // In the actual script, this is chosen by the user.
var lastPageIndex = 5; // In the actual script, this is chosen by the user.
destDocument.importStyles(ImportFormat.paragraphStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.importStyles(ImportFormat.characterStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.viewPreferences.horizontalMeasurementUnits = sourceDocument.viewPreferences.horizontalMeasurementUnits;
destDocument.viewPreferences.verticalMeasurementUnits = sourceDocument.viewPreferences.verticalMeasurementUnits;
destDocument.documentPreferences.facingPages = sourceDocument.documentPreferences.facingPages;
destDocument.documentPreferences.pageHeight = sourceDocument.documentPreferences.pageHeight;
destDocument.documentPreferences.pageWidth = sourceDocument.documentPreferences.pageWidth;
destDocument.documentPreferences.pageSize = sourceDocument.documentPreferences.pageSize;
destDocument.documentPreferences.allowPageShuffle = true;
var range = sourceDocument.pages.itemByRange(firstPageIndex, lastPageIndex);
range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);
destDocument.pages[0].remove(); // An empty spread containing an empty page is added when the new document is created and we cannot remove it before other pages are inserted (Documents must have at least one page)
This script works perfectly on many documents. But when I execute it against one particular document (let's call it foo.indd), InDesign becomes unresponsive when executing the duplication: range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);. From then on, the only thing I can do is force InDesign to quit.
Is this an InDesign bug? How can I find which part of this particular document is creating the problem?
I can't really say what's wrong in your example but if indesign hangs, that might caused by the loops ( to infinity and beyond :) )
So you may try to avoid issues by outputting the loop limit to avoid InDesign re-calculation
var limit = …
for ( i = 0; i<limit ; i++)…
Additionally you could try to write info on the console to get info where InDesign is actually being stuck. So write informations on the fly on a report file and you might finally identify the issue area.
Also, you can try to interrogate every key items to see if the file has some issue.
Last but not least, try a manual export to idml of this file, re open and run again the script. Sometimes files become clunky and passing by idml fix most of them.
Give this script a try onto your probleamtic file. If it fails, please have a look at the report it should have generated onto the desktop.
http://www.loicaigon.com/downloads/cloneDocument.jsx
Loic
http://www.loicaigon.com

Resources