I change SignUp Status Mailer to be functional to write and send e-mail depening on language's user.
First, change database :
File : signup_status_mailer.install
function signup_status_mailer_schema() {
return array(
'signup_status_mailer_settings' => array(
'description' => 'Stores signup status mailer e-mail text templates.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: the {node}.nid that a given message is associated with, or 0 for the site-wide default message templates.',
),
'cid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: the {signup_status_codes}.cid status code ID that a given message is for.',
),
/* BEGIN ADD*/
'lang' => array(
'type' => 'varchar',
'length' => '20',
'not null' => TRUE,
'description' => 'Foreign Key: {languages}.language language of mail ',
),
/* END ADD*/
'action' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'description' => "String that determines what status action the settings apply to, either 'add' when a status is first added to a signup, or 'update' when a status is modified.",
),
'notification' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'description' => "String that determines what kind of message notification to use for the given nid/cid pair. Can be 'none', 'default', or 'custom' for a per-node override.",
),
'body' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'The e-mail body template.',
),
'subject' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'description' => 'The e-mail subject template.',
),
),
/* BEGIN CHANGE*/
'primary key' => array('nid', 'cid','lang', 'action'),
/* END CHANGE*/
),
);
}
AND
function signup_status_mailer_update_6000() {
$ret = array();
$table = array(
'description' => 'Stores signup status mailer e-mail text templates.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: the {node}.nid that a given message is associated with, or 0 for the site-wide default message templates.',
),
'cid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: the {signup_status_codes}.cid status code ID that a given message is for.',
),
/* BEGIN ADD*/
'lang' => array(
'type' => 'varchar',
'length' => '20',
'not null' => TRUE,
'description' => 'Foreign Key: {languages}.language language of mail ',
),
/* END ADD*/
'action' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'description' => "String that determines what status action the settings apply to, either 'add' when a status is first added to a signup, or 'update' when a status is modified.",
),
'notification' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'description' => "String that determines what kind of message notification to use for the given nid/cid pair. Can be 'none', 'default', or 'custom' for a per-node override.",
),
'body' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'The e-mail body template.',
),
'subject' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'description' => 'The e-mail subject template.',
),
),/*BEGIN CHANGE*/
'primary key' => array('nid', 'cid','lang', 'action'),
/*END CHANGE */
);
File : signup_status_mailer.module :
function signup_status_mailer_get_settings($node) {
/* ADD */
global $user ;
$nid = is_numeric($node) ? $node : $node->nid;
static $settings = array();
$get_defaults = empty($settings[0]);
if (empty($settings[$nid])) {
$settings[$nid] = array();
if ($get_defaults && $nid != 0) {
/* CHANGE*/
$where = 'nid IN (0, %d) and lang=\'%s\'';
/* END CHANGE*/
$settings[0] = array();
}
else {
/* BEGIN CHANGE*/
$where = 'nid = %d and lang=\'%s\'';
}
$query = db_query("SELECT nid, cid, action, notification, body, subject FROM {signup_status_mailer_settings} WHERE $where", $nid,$user->language);
/* END CHANGE*/
while ($data = db_fetch_array($query)) {
$tmp_nid = $data['nid'];
$cid = $data['cid'];
$action = $data['action'];
unset($data['nid'], $data['cid'], $data['action']);
$settings[$tmp_nid][$cid][$action]= $data;
}
}
return $settings[$nid];
}
File : signup_status_mailer.settings.inc :
function _signup_status_mailer_settings_form($status, $node, $site_setting = array(), $node_setting = array()) {
$form = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array('id' => 'status-settings-cid-' . $status['cid']),
);
if (empty($node)) {
// Site-wide defaults.
$form['#title'] = t("Default notification settings for status '@status'", array('@status' => $status['name']));
// On the site-wide settings, the notification options are always the same.
$notification_options = array(
'none' => t('Disabled'),
'default' => t('Enabled'),
);
}
else {
// Per-node settings.
$form['#title'] = t("Notification settings for status '@status'", array('@status' => $status['name']));
}
// Save the status CID as a value in the form.
$form['cid'] = array(
'#type' => 'value',
'#value' => $status['cid'],
);
/*BEGIN ADD*/
// Save the status lang as a value in the form.
$form['lang'] = array(
'#type' => 'value',
'#value' => $status['lang'],
);
/*END ADD*/
foreach (array('add', 'update') as $action) {
$form[$action] = array(
'#prefix' => '<div class="signup-status-mailer-action">',
'#suffix' => '</div>',
);
AND
function signup_status_mailer_settings_submit($form, $form_state) {
//ADD
global $user;
foreach ($form_state['values'] as $key => $status_values) {
if (substr($key, 0, 21) == 'signup_status_mailer_') {
foreach (array('add', 'update') as $action) {
if (!empty($status_values[$action])) {
$values = $status_values[$action];
$values['action'] = $action;
/*ADD*/
$values['lang'] = $user->language;
/*END ADD*/
if (strpos($values['notification'], 'default-')) {
$values['notification'] = 'default';
}
AND
function _signup_status_mailer_save_settings($values, $include_text = TRUE) {
$is_new = FALSE;
if ($include_text) {
/*CHANGE*/
db_query("UPDATE {signup_status_mailer_settings} SET notification = '%s', body = '%s', subject = '%s' WHERE nid = %d AND cid = %d AND action = '%s' AND lang='%s'", $values['notification'], $values['email']['body'], $values['email']['subject'], $values['nid'], $values['cid'], $values['action'],$values['lang']);
if (!db_affected_rows()) {
db_query("INSERT INTO {signup_status_mailer_settings} (nid, cid, lang, action, notification, body, subject) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s')", $values['nid'], $values['cid'],$values['lang'], $values['action'], $values['notification'], $values['email']['body'], $values['email']['subject']);
/*END CHANGE*/
$is_new = TRUE;
}
}
else {
/*BEGIN CHANGE*/
db_query("UPDATE {signup_status_mailer_settings} SET notification = '%s' WHERE nid = %d AND cid = %d AND action = '%s' AND lang='%s'", $values['notification'], $values['nid'], $values['cid'], $values['action'],$values['lang']);
if (!db_affected_rows()) {
db_query("INSERT INTO {signup_status_mailer_settings} (nid, cid, lang, action, notification) VALUES (%d, %d, '%s', '%s', '%s')", $values['nid'], $values['cid'],$values['lang'], $values['action'], $values['notification']);
/*END CHANGE*/
$is_new = TRUE;
}
}
return $is_new;
}