Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Apr 19, 2018
2 parents 1bd8344 + 7bf0cc5 commit 26f6cd3
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 12 deletions.
12 changes: 8 additions & 4 deletions prebuilt_forms/includes/form_generation.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ function get_user_profile_hidden_inputs(&$attributes, $args, $exists, $readAuth)
}

if (isset($args['nameShow']) && $args['nameShow'] == true) {
// Show the attribute with default value.
$attribute['default'] = $value;
// Show the attribute with default value providing we aren't editing, in which case the value should be collected
// from the saved data (even if that data is blank) so we don't want to overwrite it
if (!isset($attribute['default']) && !isset($_GET['sample_id']) && !isset($_GET['occurrence_id']))
$attribute['default'] = $value;
}
else {
// Hide the attribute value
Expand All @@ -251,8 +253,10 @@ function get_user_profile_hidden_inputs(&$attributes, $args, $exists, $readAuth)
}
elseif (strcasecmp($attribute['untranslatedCaption'], 'email') == 0) {
if (isset($args['emailShow']) && $args['emailShow'] == true) {
// Show the email attribute with default value.
$attribute['default'] = hostsite_get_user_field('mail');
// Show the email attribute with default value providing we aren't editing, in which case the value should be collected
// from the saved data (even if that data is blank) so we don't want to overwrite it
if (!isset($attribute['default']) && !isset($_GET['sample_id']) && !isset($_GET['occurrence_id']))
$attribute['default'] = hostsite_get_user_field('mail');
}
else {
// Hide the email value
Expand Down
1 change: 1 addition & 0 deletions prebuilt_forms/includes/language_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function iform_lang_iso_639_2($lang=null) {
switch ($lang) {
case 'en' : return 'eng';
case 'de' : return 'deu';
case 'cs' : return 'cze';
case 'lb' : return 'ltz';
case 'fr' : return 'fra';
}
Expand Down
76 changes: 76 additions & 0 deletions prebuilt_forms/js/verification_5.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,71 @@ indiciaData.rowIdToReselect = false;
html += recorderQueryCommentForm();
popupQueryForm(html);
}

/*
* Saves the authorisation token for the Record Comment Quick Reply page into the database
* so that it is saved against the occurrence id
* @param string authorisationNumber
* @return boolean indicates if database was successfully written to or not
*
*/
function saveAuthorisationNumberToDb(authorisationNumber, occurrenceId) {
var data = {
'website_id': indiciaData.website_id,
'comment_quick_reply_page_auth:occurrence_id': occurrenceId,
'comment_quick_reply_page_auth:token': authorisationNumber,
};
$.post(
indiciaData.ajaxFormPostUrl.replace('occurrence', 'comment_quick_reply_page_auth'),
data,
function (data) {
if (typeof data.error !== "undefined") {
alert(data.error);
}
},
'json'
);
}

// Use an AJAX call to get the server to send the email
function sendEmail() {
var authorisationWriteToDbResult;
var autoRemoveLink =false;
//If the email isn't for an occurrence or the setup options are missing
//then then we won't be writing an auth to the DB, and we will want to remove the link from the email body
if (!indiciaData.commentQuickReplyPageLinkURL||!indiciaData.commentQuickReplyPageLinkLabel||!occurrenceId) {
autoRemoveLink=true;
} else {
//Setup the quick reply page link and get an authorisation number
var personIdentifierParam;
// Note: The quick reply page does actually support supplying a user_id parameter to it, however we don't do that in practice here as
// we don't actually know if the user has an account (we would also have to collect the user_id for the entered email)
personIdentifierParam='&email_address='+email.to;
//Need an authorisation unique string in URL, this is linked to the occurrence.
//Only if correct auth and occurrence_id combination are present does the Record Comment Quick Reply page display
var authorisationNumber = makeAuthNumber();
var authorisationParam='&auth='+authorisationNumber;
var commentQuickReplyPageLink='<a href="'+indiciaData.commentQuickReplyPageLinkURL+'?occurrence_id='+occurrenceId+personIdentifierParam+authorisationParam+'">'+
indiciaData.commentQuickReplyPageLinkLabel+'</a>';
//This returns true if error saving authorisation to the database.
authorisationWriteToDbResult=saveAuthorisationNumberToDb(authorisationNumber, occurrenceId);
}
// To Do: Warn user if the DB authorisation write to the database failed, as we will need to auto remove the link
// Not currently operational as the authorisation write to the database is asynchronous
if (authorisationWriteToDbResult==='failure') {
alert('The email will be sent, however we have not been able to generate the link '+
'to the Occurrence Comment Quick Reply page because of a problem when communicating with the database.\n\n\It will be removed from the the email.')
}
// Replace the text token from the email with the actual link or remove the link if
// A. We couldn't write the authorisation to the database
// B. The system is requesting we remove the link (perhaps the required options are not filled in)
if (authorisationWriteToDbResult!=='failure' && autoRemoveLink===false) {
email.body = email.body
.replace('%commentQuickReplyPageLink%', commentQuickReplyPageLink);
} else {
email.body = email.body
.replace('%commentQuickReplyPageLink%', '');
}
$.post(
indiciaData.ajaxUrl + '/email/' + indiciaData.nid + urlSep,
email,
Expand All @@ -357,6 +419,20 @@ indiciaData.rowIdToReselect = false;
}
);
}

/*
* Create a random authorisation number to pass to the Record Comment Quick Reply page
* (This page sits outside the Warehouse)
* @returns string random authorisation token
*/
function makeAuthNumber() {
var characterSelection = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var authNum = "";
for (var digit = 0; digit < 16; digit++) {
authNum += characterSelection.charAt(Math.floor(Math.random() * characterSelection.length));
}
return authNum;
}

function processEmail() {
// Complete creation of email of record details
Expand Down
5 changes: 5 additions & 0 deletions prebuilt_forms/record_details_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ private static function commonControlPhotos($auth, $args, $options, $settings) {
$r .= "<li class=\"gallery-item\"><audio controls " .
"src=\"$imageFolder$medium[path]\" type=\"audio/mpeg\"/></li>";
}
elseif ($medium['media_type'] === 'Image:iNaturalist') {
$imgLarge = str_replace('/thumb.', '/large.', $medium['path']);
$r .= "<li class=\"gallery-item\"><a href=\"$imgLarge\" class=\"fancybox single\">" .
"<img src=\"$medium[path]\" /></a><br/>$medium[caption]</li>";;
}
else {
$r .= "<li class=\"gallery-item\"><a href=\"$imageFolder$medium[path]\" class=\"fancybox single\">" .
"<img src=\"$imageFolder$options[imageSize]-$medium[path]\" /></a><br/>$medium[caption]</li>";
Expand Down
43 changes: 36 additions & 7 deletions prebuilt_forms/verification_5.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ public static function get_parameters() {
), array(
'name' => 'email_body_send_to_verifier',
'caption' => 'Send to Expert Email Body',
'description' => 'Default body for the send to expert email. Replacements allowed include %taxon%, %id% and %record% which is replaced to give details of the record.',
'description' => 'Default body for the send to expert email. Replacements allowed include %taxon%, %id% and %record% which is replaced to give details of the record. '
. 'Use the %commentQuickReplyPageLink% replacement if you wish the recipient to be able to quickly reply to comments using a linked page, '
. 'setup the options for this using the COMMENT QUICK REPLY PAGE LINK section of this page',
'type' => 'textarea',
'default' => 'We would appreciate your opinion on the following record. Please reply to this mail with "accepted", "not accepted" or "query" '.
'in the email body, followed by any comments you have including the proposed re-identification if relevant on the next line.'.
"\n\n%record%",
'group' => 'Verifier emails',
'group' => 'Verifier emails'
), array(
'name' => 'email_subject_send_to_recorder',
'caption' => 'Send to Recorder Email Subject',
Expand All @@ -262,12 +264,14 @@ public static function get_parameters() {
), array(
'name' => 'email_body_send_to_recorder',
'caption' => 'Send to Recorder Email Body',
'description' => 'Default body for the send to recorder email. Replacements allowed include %taxon%, %id% and %record% which is replaced to give details of the record.',
'description' => 'Default body for the send to recorder email. Replacements allowed include %taxon%, %id% and %record% which is replaced to give details of the record. '
. 'Use the %commentQuickReplyPageLink% replacement if you wish the recipient to be able to quickly reply to queries using a linked page, '
. 'setup the options for this using the COMMENT QUICK REPLY PAGE LINK section of this page',
'type' => 'textarea',
'default' => 'The following record requires confirmation. Please could you reply to this email stating how confident you are that the record is correct '.
'and any other information you have which may help to confirm this.' .
'and any other information you have which may help to confirm this.'.
"\n\n%record%",
'group' => 'Recorder emails',
'group' => 'Recorder emails'
), array(
'name' => 'auto_discard_rows',
'caption' => 'Automatically remove rows',
Expand Down Expand Up @@ -414,6 +418,22 @@ public static function get_parameters() {
]
}',
),
array(
'name' => 'comment_quick_reply_page_link_label',
'caption' => 'Comment quick reply page link label',
'description' => 'Label for the link to the Comment Quick Reply page.',
'type' => 'text_input',
'group' => 'Comment quick reply page link',
'required' => 'false'
),
array(
'name' => 'comment_quick_reply_page_link_url',
'caption' => 'Comment quick reply page link URL',
'description' => 'URL link to the Comment Quick Reply page.',
'type' => 'text_input',
'group' => 'Comment quick reply page link',
'required' => 'false'
)
)
);
// Set default values for the report.
Expand Down Expand Up @@ -835,6 +855,10 @@ public static function get_form($args, $nid, $response) {
)
)
));
if (!empty($args['comment_quick_reply_page_link_label']) && !empty($args['comment_quick_reply_page_link_url'])) {
data_entry_helper::$javascript .= 'indiciaData.commentQuickReplyPageLinkLabel = "' . $args['comment_quick_reply_page_link_label'] . "\";\n";
data_entry_helper::$javascript .= 'indiciaData.commentQuickReplyPageLinkURL = "' . $args['comment_quick_reply_page_link_url'] . "\";\n";
}
$r = str_replace(array('{grid}', '{log}', '{paramsForm}'), array($grid, $log, $params),
self::getTemplateWithMap($args, $auth['read'], $opts['extraParams'], $opts['paramDefaults']));
$link = data_entry_helper::get_reload_link_parts();
Expand Down Expand Up @@ -1339,8 +1363,13 @@ private static function getMediaHtml($media) {
$path = data_entry_helper::get_uploaded_image_folder();
$r .= '<ul class="gallery">';
foreach ($media as $file) {
if (preg_match('/^http(s)?:\/\/(www\.)?([a-z]+)/', $file['path'], $matches)) {
$media = "<a href=\"$file[path]\" class=\"social-icon $matches[3]\"></a>";
if (preg_match('/^https:\/\/static\.inaturalist\.org/', $file['path'])) {
$imgLarge = str_replace('/square.', '/large.', $file['path']);
$media = "<a href=\"$imgLarge\" class=\"inaturalist fancybox\"><img src=\"$file[path]\" /></a>";
}
elseif (preg_match('/^http(s)?:\/\/(www\.)?([a-z+(\.kr)]+)/', $file['path'], $matches)) {
$class = str_replace('.', '', $matches[3]);
$media = "<a href=\"$file[path]\" class=\"social-icon $class\"></a>";
}
elseif (preg_match('/.(wav|mp3)$/', $file['path'])) {
$media = "<audio controls src=\"$path$file[path]\" type=\"audio/mpeg\"/>";
Expand Down
8 changes: 7 additions & 1 deletion report_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,14 @@ public static function report_grid($options) {
$imgclass=count($imgs)>1 ? 'multi' : 'single';
$group=count($imgs)>1 && !empty($options['rowId']) ? ' rel="group-' . $row[$options['rowId']] . '"' : '';
foreach($imgs as $img) {
if (preg_match('/^http(s)?:\/\/(www\.)?(?P<site>[a-z]+)/', $img, $matches)) {
if (preg_match('/^https:\/\/static\.inaturalist\.org/', $img)) {
$imgLarge = str_replace('/square.', '/large.', $img);
$value .= "<a href=\"$imgLarge\" class=\"inaturalist fancybox $imgclass$group\"><img src=\"$img\" /></a>";
}
elseif (preg_match('/^http(s)?:\/\/(www\.)?(?P<site>[a-z]+(\.kr)?)/', $img, $matches)) {
// http, means an external file
// Flickr URLs sometimes have . in them.
$matches['site'] = str_replace('.', '', $matches['site']);
$value .= "<a href=\"$img\" class=\"social-icon $matches[site]\"></a>";
} else {
$value .= "<a href=\"$imagePath$img\" class=\"fancybox $imgclass$group\"><img src=\"$imagePath" . $options['imageThumbPreset'] . "-$img\" /></a>";
Expand Down

0 comments on commit 26f6cd3

Please sign in to comment.