This is complete rewrite of SLL's "
[MOD] Email image validation results to the user v1". Since SLL is no longer very active on this forum
I decided create my own mod using his idea, with many new features and most significan change from v1 is that every member will receive only
one email with list of accepted/declined images instead of separate email for each image.
------------ [ Features ] -------------- members receive only one email with list of added/deleted images
- admin can send an individual message (comment) for each added/deleted file
- admin can chose not send any notification emails (per file setting)
- quick select all files to add or delete
- after validation return to validation page (by default it only show result of the validation on a blank page)
- double click on a radio button will remove any sellection (usefull if quick selected all images but then u've changed your mind and decided not add or delete one or more images)
- displays a link to image details page if an image added
The validation page:
And the email member received after validation the three images above:
------------- [ Installation ] --------------If u've installed "
[MOD] Email image validation results to the user v1" by SLL, you'll need to uninstall it before installing this mod...
Step 1Open
admin/validateimages.phpFind:
$image_list = (isset($HTTP_POST_VARS['image_list'])) ? $HTTP_POST_VARS['image_list'] : "";
Insert
below:
/*
MOD VALIDATION RESULT V2
START INSERT
*/
$msg_list = (isset($HTTP_POST_VARS['msg_list'])) ? $HTTP_POST_VARS['msg_list'] : "";
$email_cache = array();
$action = "validateimages";
/*
MOD VALIDATION RESULT V2
END INSERT
*/
Step 1.1Find:
echo $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> (".$image_media_file.")<br />";
Replace it with:
/*
MOD VALIDATION RESULT V2
START ORIGINAL CODE
echo $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> (".$image_media_file.")<br />";
MOD VALIDATION RESULT V2
END ORIGINAL CODE
*/
/*
MOD VALIDATION RESULT V2
START REPLACE
*/
echo $lang['image_add_success'].": <b><a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$image_id)."\" target=\"_blank\">".stripslashes($image_name)."</a></b> (".$image_media_file.")<br />";
$email_cache[$user_id][] = array(
"status" => 1,
"send" => (isset($HTTP_POST_VARS['send'][$key]) && $HTTP_POST_VARS['send'][$key] == 2) ? 1 : 0,
"image_id" => $image_id,
"date" => $image_date,
"image_media_file" => $image_media_file,
"msg" => $msg_list[$key]
);
/*
MOD VALIDATION RESULT V2
END REPLACE
*/
Step 1.2Find:
echo $lang['image_delete_success'].": <b>".stripslashes($image_name)."</b> (".$image_media_file.")<br />";
Insert
below:
/*
MOD VALIDATION RESULT V2
START INSERT
*/
$email_cache[$user_id][] = array(
"status" => 0,
"send" => (isset($HTTP_POST_VARS['send'][$key]) && $HTTP_POST_VARS['send'][$key] == 2) ? 1 : 0,
"image_id" => 0,
"date" => $image_date,
"image_media_file" => $image_media_file,
"msg" => $msg_list[$key]
);
/*
MOD VALIDATION RESULT V2
END INSERT
*/
Step 1.3Find:
}
else {
echo "<b>Just relaxing because you give me nothing to do!</b>";
Insert
above (make sure insert it above the closing bracket "}" above the
else !!!!:
/*
MOD VALIDATION RESULT V2
START INSERT
*/
if (!empty($email_cache))
{
if (!class_exists('Email')) include(ROOT_PATH.'includes/email.php');
$user_ids = implode(",", array_keys($email_cache));
$sql = "SELECT ".get_user_table_field("", "user_id").get_user_table_field(", ", "user_name").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_allowemails")."
FROM ".USERS_TABLE."
WHERE ".get_user_table_field("", "user_id")." IN (".$user_ids.") AND ".get_user_table_field("", "user_level")." > ".GUEST;
$result = $site_db->query($sql);
$email_template = new Template(ROOT_PATH."lang/".$config['language_dir']."/email");
while($row = $site_db->fetch_array($result))
{
if (!$row['user_allowemails']) continue; //comment this line out to disregard member's setting not to receive emails from administrators
$list = "";
$file_list = array();
$site_url = $script_url;
$site_url = preg_replace("#/?admin#", "", $site_url);
// $site_url = "http://yoursite.com/4images"; // uncomment this line and update to the correct domain if your have problem with url in the email message
$email_template->register_vars(array(
"lang_upload_date" => $lang['validate_date'],
"lang_file" => $lang['validate_file'],
"lang_msg" => $lang['validate_msg'],
"lang_status" => $lang['validate_status'],
));
foreach ($email_cache[$row['user_id']] as $info)
{
if (!$info['send']) continue;
$file_list[] = $info['image_media_file'];
// $image_url = ($info['image_id']) ? "( ".$site_sess->url($site_url."/details.php?".URL_IMAGE_ID."=".$info['image_id'], "&")." )" : "";
$image_url = ($info['image_id']) ? "( ".$site_url."/details.php?".URL_IMAGE_ID."=".$info['image_id']." )" : "";
$email_template->register_vars(array(
"status" => ($info['status']) ? $lang['validate_yes'] : $lang['validate_no'],
"image_url" => $image_url,
"image_id" => $info['image_id'],
"date" => format_date($config['date_format']." ".$config['time_format'], $info['date']),
"file" => $info['image_media_file'],
"msg" => stripslashes($info['msg'])
));
$list .= $email_template->parse_template("validation_email_bit");
}
if (empty($list)) continue;
$site_email = new Email();
$site_email->set_to($row['user_email']);
// $site_email->set_from($config['site_email'], $config['site_name']);
$site_email->set_subject($lang['valdiate_title']);
$site_email->register_vars(array(
"recipient_name" => $row['user_name'],
"list" => $site_email->prepare_text($list),
"file_list" => implode(", ", $file_list),
"site_url" => $site_sess->url($site_url, "&"),
"date" => format_date($config['date_format']." ".$config['time_format'], time()),
"site_name" => $config['site_name']
));
$site_email->set_body("validation_email", $config['language_dir']);
$site_email->send_email();
}
}
echo "<br />";
/*
MOD VALIDATION RESULT V2
END INSERT
*/
(make sure that between this block of code and the code u've inserted in previous step are only two (2) closing brackets (
} )!
Step 1.4Find:
echo "<td class=\"tableseparator\">".$lang['validate']."</td>\n<td class=\"tableseparator\">".$lang['delete']."</td>\n<td class=\"tableseparator\"> </td>\n<td class=\"tableseparator\">".$lang['field_image_name']."</td>\n<td class=\"tableseparator\">".$lang['field_category']."</td>\n<td class=\"tableseparator\">".$lang['field_username']."</td>\n<td class=\"tableseparator\">".$lang['field_date']."</td>\n<td class=\"tableseparator\">".$lang['options']."</td>\n</tr>\n";
Replace it with:
/*
MOD VALIDATION RESULT V2
START ORIGINAL CODE
echo "<td class=\"tableseparator\">".$lang['validate']."</td>\n<td class=\"tableseparator\">".$lang['delete']."</td>\n<td class=\"tableseparator\"> </td>\n<td class=\"tableseparator\">".$lang['field_image_name']."</td>\n<td class=\"tableseparator\">".$lang['field_category']."</td>\n<td class=\"tableseparator\">".$lang['field_username']."</td>\n<td class=\"tableseparator\">".$lang['field_date']."</td>\n<td class=\"tableseparator\">".$lang['options']."</td>\n</tr>\n";
MOD VALIDATION RESULT V2
END ORIGINAL CODE
*/
/*
MOD VALIDATION RESULT V2
START REPLACE
*/
show_hidden_input("cat_id", $cat_id);
show_hidden_input("limitnumber", $limitnumber);
echo "<script>
var yes = false;
var no = false;
var send = true;
var rc = new Array();
function CheckAllradio(num, checked) {
for (var i=0;i<document.form.elements.length;i++) {
var e = document.form.elements[i];
if (e.type=='radio' && e.value == num) {
e.checked = checked;
}
}
}
</script>";
echo "<td class=\"tableseparator\">".$lang['validate_msg']."</td>\n<td class=\"tableseparator\" onClick=\"if(send){send=false;CheckAllradio(2, false);CheckAllradio(3, true);}else{send=true;CheckAllradio(2, true); CheckAllradio(3, false);}\">Send</td>\n<td class=\"tableseparator\" onClick=\"if(yes){yes=false;no=false}else{yes=true;no=false;}CheckAllradio(1, yes)\">".$lang['validate']."</td>\n<td class=\"tableseparator\" onClick=\"if(no){no=false;yes=false}else{no=true;yes=false;}CheckAllradio(0, no)\">".$lang['delete']."</td>\n<td class=\"tableseparator\"> </td>\n<td class=\"tableseparator\">".$lang['field_image_name']."</td>\n<td class=\"tableseparator\">".$lang['field_category']."</td>\n<td class=\"tableseparator\">".$lang['field_username']."</td>\n<td class=\"tableseparator\">".$lang['field_date']."</td>\n<td class=\"tableseparator\">".$lang['options']."</td>\n</tr>\n";
/*
MOD VALIDATION RESULT V2
END REPLACE
*/
Step 1.5Find:
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"1\"></td>";
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"0\"></td>";
Replace it with:
/*
MOD VALIDATION RESULT V2
START ORIGINAL CODE
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"1\"></td>";
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"0\"></td>";
MOD VALIDATION RESULT V2
END ORIGINAL CODE
*/
/*
MOD VALIDATION RESULT V2
START REPLACE
*/
echo "<td>".(($image_row['user_id'] != GUEST) ? "<textarea name=\"msg_list[".$image_row['image_id']."]\" rows=\"3\" cols=\"40\">".((isset($HTTP_POST_VARS['msg_list'][$image_row['image_id']])) ? stripslashes($HTTP_POST_VARS['msg_list'][$image_row['image_id']]) : "")."</textarea>" : "")."</td>";
echo "<td>".(($image_row['user_id'] != GUEST) ? "<input type=\"radio\" name=\"send[".$image_row['image_id']."]\" value=\"2\"".(((isset($HTTP_POST_VARS['send'][$image_row['image_id']]) && $HTTP_POST_VARS['send'][$image_row['image_id']] == 2) || !isset($HTTP_POST_VARS['send'][$image_row['image_id']])) ? " checked" : "").">yes <input type=\"radio\" name=\"send[".$image_row['image_id']."]\" value=\"3\"".(((isset($HTTP_POST_VARS['send'][$image_row['image_id']]) && $HTTP_POST_VARS['send'][$image_row['image_id']] == 3)) ? " checked" : "").">no" : " ")."</td>";
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"1\" onDblclick=\"this.checked=false;\"></td>";
echo "<td><input type=\"radio\" name=\"image_list[".$image_row['image_id']."]\" value=\"0\" onDblclick=\"this.checked=false;\"></td>";
/*
MOD VALIDATION RESULT V2
END REPLACE
*/
Step 2Open
lang/<your language>/admin.phpAt the end, just
above closing
?> insert this:
/*
MOD VALIDATION RESULT V2
START INSERT
*/
$lang['valdiate_title'] = "Image Validation Results";
$lang['validate_yes'] = "added";
$lang['validate_no'] = "deleted";
$lang['validate_msg'] = "Message";
$lang['validate_file'] = "File";
$lang['validate_date'] = "Uploaded";
$lang['validate_status'] = "Status";
/*
MOD VALIDATION RESULT V2
END INSERT
*/
Step 3Create a new template:
lang/<your language>/email/validation_email.htmlwith the following code inside:
Dear {recipient_name},
You've uploaded to the "{site_name}" the following file(s):
{file_list}
The validation result is the following:
___________________________________________________
{list}--
Best regards, {site_name}
{site_url}
Step 4Create a new template:
lang/<your language>/email/validation_email_bit.htmlwith the following code inside:
{lang_file}: {file}
{lang_upload_date}: {date}
{lang_status}: {status} {image_url}
{lang_msg}: {msg}
___________________________________________________
------------- [ Appendix ] ----------------The following tags are allowed to be used in
validation_email.html template (Step 3):
{recipient_name} - will show name of the member to whom the email will be sent
{list} - a list of all validated files (parsed
validation_email_bit.html template)
{file_list} - a comma separated list of validated files
{site_name} - site name from the settings
{site_url} - url to your site
{date} - date of validation
The following tags are allowed to be used in
validation_email_bit.html template (Step 4):
{lang_upload_date} - text "Uploaded"
{lang_file} - text "File"
{lang_msg} - text "Message"
{lang_status} - text "Status"
{status} - "added" or "deleted"
{image_url} - a url to the image details (empty if image deleted)
{image_id} - image id
{date} - the date when file was uploaded
{file} - filename of the uploaded file
{msg} - a custom message from admin
--------------- [ FAQ ] ----------------Q: | When someone receive an email the url to the site is broken. Why? |
A: | This might happend on some sertain systems, to fix that, try uncomment this line in admin/validateimages.php // $site_url = "http://yoursite.com/4images"; // uncomment this line and update to the correct domain if your have problem with url in the email message and change yoursite.com/4images to the correct path to your gallery
|
|
|
Q: | Why some members dont receive any emails even though I selected "send" during validation? |
A: | If a member set in their profile "Do not receive emails from administrators" they will not receive validation results either. But you can force email to be sent by commenting out this line: if (!$row['user_allowemails']) continue; //comment this line out to disregard member's setting not to receive emails from administrators |
|
|
Q: | When members receive email, the validation results list is showed in one line, without line breaks. Why? |
A: | When I was writing this mod I've experienced it myself, it turned out that 4images template engine (atleast in v1.7.1) removes line breaks if a template tag placed at the end of line. To fix that, simply add one space after each last template tag on each line |
|
|
Q: | What exactly "Send" column does? |
A: | In some cases (dont ask me what) you might not want the member know if a sertain image was added or deleted, so, by selecting "no" in the "Send" column the file will not be added in the list in the email (if only one file validated and "Send" selected to "no", then no email will be sent at all to that member) |
|
|
Q: | What can I do if I selected a file to be added or deleted and then changed my mind and dont want do any actions to that sertain file? Is page refresh the only way? |
A: | Page refresh is one way, but not the only way. By double click on the "Add" or "Delete" radio button on the specific image it should "unselect" it. Another way is click on the column name on top ("Validate" or "Delete"), ones it selected all files, click that column name again, it will unselect everything. |