Following on from the previous address book extension post, I have made a small tweak that will allow me to send mail to an alternate email address for a contact. I have added another field "otheremail" to my contacts table, and as per instructions in the
previous post I have also modified the address book code to allow access to this field when adding/modifying contacts.
There are probably other places to consider, but to simply add this alternate email address to my compose lists I modified program\steps\mail\compose.inc as follows:
Original compose.inc (from line 779)/****** get contacts for this user and add them to client scripts ********/
$sql_result = $DB->query("SELECT name, email
FROM ".get_table_name('contacts')." WHERE user_id=?
AND del<>1",$_SESSION['user_id']);
if ($DB->num_rows($sql_result))
{
$a_contacts = array();
while ($sql_arr = $DB->fetch_assoc($sql_result))
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
$OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
}
Modified compose.inc (line 779)/****** get contacts for this user and add them to client scripts ********/
$sql_result = $DB->query("SELECT name, email, otheremail
FROM ".get_table_name('contacts')." WHERE user_id=?
AND del<>1",$_SESSION['user_id']);
if ($DB->num_rows($sql_result))
{
$a_contacts = array();
while ($sql_arr = $DB->fetch_assoc($sql_result)) {
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
if ($sql_arr['otheremail'])
$a_contacts[] = format_email_recipient($sql_arr['otheremail'], rep_specialchars_output($sql_arr['name'] . ' (2)', 'js'));
}
$OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
}
This will add a contacts alternate email with a '(2)' after the name, as attached.
Cheers!!
Richard