Finally, I found a solution to this problem that works locally on my specific datas. I have to present a solution rapidly so that is the solution I implement for the moment. I hope to have time to think about a more robust solution.
Some contextual informations are necessary to understand :
- the informations about persons are stored in a table named "personnes";
- the persons have to register to formations and informations about formations are stored in the "sessions" table and the join between the two is a relation called "inscrits" where the person identifier is "id_personne".
My aim is to present the "sessions" table with relation "inscrits" and possibility to check some participants and send them an email.
Here is my solution :
In the actions.ini of the "sessions" table, I added the following code :
- Code: Select all
[email_selected]
label="Mail manuel"
url="javascript:emailSelected('relatedList')"
description= "Envoyer un message personnalise aux personnes selectionnees."
category=selected_related_result_actions
icon="{$dataface_url}/images/mail_icon.gif"
permission=email
That will create the button and call a special javascript function with the right form name.
Here is my "fiddle" script that was added using the <a> procedure to add a custom javascript </a> :
- Code: Select all
function emailSelected(tableid){
var ids = getSelectedIds(tableid);
if ( ids.length == 0 )
{
alert("Please first check boxes beside the records you wish to copy, and then press 'Copy'.");
return;
}
selected_ids_url="";
selected_ids=ids.join(",");
selected_ids+=",";
while (selected_ids.indexOf("personne_id")!= -1)
{
ind_ps=selected_ids.indexOf("personne_id");
ind_or=selected_ids.indexOf(",");
sub=selected_ids.substring(ind_ps+11,ind_or);
alert(sub);
selected_ids_url=selected_ids_url+ sub +" OR ";
selected_ids=selected_ids.replace("personne_id","");
selected_ids=selected_ids.replace(",","");
}
ind_lo=selected_ids_url.lastIndexOf(" OR ");
selected_ids_urlf=selected_ids_url.substring(0,ind_lo);
alert(selected_ids_urlf);
new_url="index.php?-action=email&-table=personnes&id"+selected_ids_urlf;
window.location.replace(new_url);
}
Each entry of the table "ids" looks like "session_id=3&personne_id=91" and the script makes creates the right url to send an email to right persons : "index.php?action=email&-table=personnes&id =91 OR =101".
I am sure it is possible to make it better, and do not hesitate to make suggestions about it. It would be interresting for me to better understand how the email module works.
Zabelle