/** * Return the Indicia form code * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); global $user; $r = ''; $presetList = explode("\n", $args['param_presets']); $presets = array(); foreach ($presetList as $param) { $tokens = explode('=', $param); if (count($tokens) == 2) { $presets[$tokens[0]] = $tokens[1]; } else { $r .= '<div class="page-notice ui-widget ui-widget-content ui-corner-all ui-state-error">' . 'Some of the preset parameters defined for this page are not of the form param=value.</div>'; } } $reportOptions = array('id' => 'report-grid', 'class' => '', 'thClass' => '', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => array(), 'itemsPerPage' => 20, 'autoParamsForm' => $args['auto_params_form'], 'extraParams' => $presets); // Add a download link $r .= '<a href="' . data_entry_helper::get_report_data(array_merge($reportOptions, array('linkOnly' => true))) . '&mode=csv">Download this report</a>'; // now the grid $r .= data_entry_helper::report_grid($reportOptions); // Set up a page refresh for dynamic update of the report at set intervals if ($args['refresh_timer'] !== 0 && is_numeric($args['refresh_timer'])) { // is_int prevents injection if (isset($args['load_on_refresh']) && !empty($args['load_on_refresh'])) { data_entry_helper::$javascript .= "setTimeout('window.location=\"" . $args['load_on_refresh'] . "\";', " . $args['refresh_timer'] . "*1000 );\n"; } else { data_entry_helper::$javascript .= "setTimeout('window.location.reload( false );', " . $args['refresh_timer'] . "*1000 );\n"; } } return $r; }
/** * When viewing the list of locations for this user, get the grid to insert into the page. * Filtering of locations is by Indicia User ID stored in the user profile. * Enable Easy Login module to achieve this function. */ protected static function getLocationListGrid($args, $node, $auth) { global $user; // User must be logged in before we can access their records. if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } // get the Indicia User ID attribute so we can filter the grid to this user if (function_exists('hostsite_get_user_field')) { $iUserId = hostsite_get_user_field('indicia_user_id'); } if (!isset($iUserId) || !$iUserId) { return lang::get('LANG_No_User_Id'); } // Subclassed forms may provide a getLocationListGridPreamble function if (method_exists(self::$called_class, 'getLocationListGridPreamble')) { $r = call_user_func(array(self::$called_class, 'getLocationListGridPreamble')); } else { $r = ''; } $extraParams = array('website_id' => $args['website_id'], 'iUserID' => $iUserId); if (!$args['list_all_locations']) { // The option to list all locations is denied so enforce selection of own data. $extraParams['ownData'] = '1'; } $r .= data_entry_helper::report_grid(array('id' => 'locations-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(self::$called_class, 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => $extraParams, 'paramDefaults' => array('ownData' => '1'))); $r .= '<form>'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Location') . '" ' . 'onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">'; $r .= '</form>'; return $r; }
/** * Return the Indicia form code. * Expects there to be a sample attribute with caption 'Email' containing the email * address. * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { global $user, $indicia_templates; // put each param control in a div, which makes it easier to layout with CSS $indicia_templates['prefix'] = '<div id="container-{fieldname}" class="param-container">'; $indicia_templates['suffix'] = '</div>'; $indicia_user_id = self::get_indicia_user_id($args); $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $r = ''; if ($_POST) { // dump out any errors that occurred on verification if (data_entry_helper::$validation_errors) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>' . implode('</p></p>', array_values(data_entry_helper::$validation_errors)) . '</p></div>'; } else { if (isset($_POST['email']) && !isset($response['error'])) { // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $user->mail . PHP_EOL . "\r\n"; $headers .= 'Return-Path: ' . $user->mail . "\r\n"; if (isset($_POST['photoHTML'])) { $emailBody = str_replace('[photo]', '<br/>' . $_POST['photoHTML'], $_POST['email_content']); } else { $emailBody = $_POST['email_content']; } $emailBody = str_replace("\n", "<br/>", $emailBody); // Send email. Depends upon settings in php.ini being correct $success = mail($_POST['email_to'], $_POST['email_subject'], wordwrap($emailBody, 70), $headers); if ($success) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>An email was sent to ' . $_POST['email_to'] . '.</p></div>'; } else { $r .= '<div class="page-notice ui-widget-content ui-corner-all ui-state-highlight left">The webserver is not correctly configured to send emails. Please send the following email manually: <br/>' . '<div id="manual-email"><span>To:</span><div>' . $_POST['email_to'] . '</div>' . '<span>Subject:</span><div>' . $_POST['email_subject'] . '</div>' . '<span>Content:</span><div>' . $emailBody . '</div>' . '</div></div><div style="clear: both">'; } } else { if (isset($_POST['occurrence:record_status']) && isset($response['success']) && $args['emails_enabled']) { $r .= self::get_notification_email_form($args, $response, $auth); } } } if (isset($_POST['action']) && $_POST['action'] == 'send_to_verifier' && $args['log_send_to_verifier']) { $comment = str_replace(array('%email%', '%date%', '%user%'), array($_POST['email_to'], date('jS F Y'), $user->name), $args['log_send_to_verifier_comment']); } elseif (isset($_POST['action']) && ($_POST['action'] = 'general_comment')) { $comment = $_POST['comment']; } // If there is a comment to save, add it to the occurrence comments if (isset($comment)) { // get our own write tokens for this submission, as the main ones are used in the JavaScript form. $loggingAuth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $sub = data_entry_helper::wrap(array('comment' => $comment, 'occurrence_id' => $_POST['occurrence:id'], 'created_by_id' => $indicia_user_id), 'occurrence_comment'); $logResponse = data_entry_helper::forward_post_to('occurrence_comment', $sub, $loggingAuth['write_tokens']); if (!array_key_exists('success', $logResponse)) { $r .= data_entry_helper::dump_errors($response, false); } } } //extract fixed parameters for report grid. $params = explode(",", $args['fixed_params']); foreach ($params as $param) { $keyvals = explode("=", $param); $key = trim($keyvals[0]); $val = trim($keyvals[1]); $extraParams[$key] = $val; } // plus defaults which are not fixed $params = explode("\n", $args['param_defaults']); foreach ($params as $param) { $keyvals = explode("=", $param); $key = trim($keyvals[0]); $val = trim($keyvals[1]); $paramDefaults[$key] = $val; } $actions = array(); if ($args['send_for_verification']) { // store authorisation details as a global in js, since some of the JavaScript needs to be able to access Indicia data data_entry_helper::$javascript .= 'auth=' . json_encode($auth) . ';'; $actions[] = array('caption' => str_replace(' ', ' ', lang::get('Send to verifier')), 'class' => 'send_for_verification_btn', 'javascript' => 'indicia_send_to_verifier(\'{taxon}\', {occurrence_id}, ' . $user->uid . ', ' . $args['website_id'] . '); return false;'); $r .= self::get_send_for_verification_form(); } $actions[] = array('caption' => str_replace(' ', ' ', lang::get('Verify')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, true, ' . $user->uid . '); return false;'); $actions[] = array('caption' => str_replace(' ', ' ', lang::get('Reject')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, false, ' . $user->uid . '); return false;'); $actions[] = array('caption' => str_replace(' ', ' ', lang::get('Comments')), 'javascript' => 'indicia_comments(\'{taxon}\', {occurrence_id}, ' . $user->uid . ', \'' . $auth['read']['nonce'] . '\', \'' . $auth['read']['auth_token'] . '\'); return false;'); if (isset($args['path_to_record_details_page']) && $args['path_to_record_details_page']) { $actions[] = array('caption' => str_replace(' ', ' ', lang::get('View details')), 'url' => '{rootFolder}' . $args['path_to_record_details_page'], 'urlParams' => array('occurrence_id' => '{occurrence_id}')); } // default columns behaviour is to just include anything returned by the report plus add an actions column $columns = array(array('display' => 'Actions', 'actions' => $actions)); // this can be overridden if (isset($args['columns_config']) && !empty($args['columns_config'])) { $columns = array_merge(json_decode($args['columns_config'], true), $columns); } $r .= data_entry_helper::report_grid(array('id' => 'verification-grid', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => $columns, 'rowId' => 'occurrence_id', 'itemsPerPage' => 10, 'autoParamsForm' => $args['auto_params_form'], 'extraParams' => $extraParams, 'paramDefaults' => $paramDefaults)); // Put in a blank form, which lets JavaScript set the values and post the data. $r .= ' <form id="verify" method="post" action=""> ' . $auth['write'] . ' <input type="hidden" id="occurrence:id" name="occurrence:id" value="" /> <input type="hidden" id="occurrence:record_status" name="occurrence:record_status" value="" /> <input type="hidden" id="occurrence_comment:comment" name="occurrence_comment:comment" value="" /> <input type="hidden" name="occurrence_comment:created_by_id" value="' . $indicia_user_id . '" /> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="occurrence:verified_by_id" name="occurrence:verified_by_id" value="" /> </form> '; drupal_add_js(' var indicia_user_id = ' . $indicia_user_id . '; var url = ' . json_encode(data_entry_helper::get_reload_link_parts()) . '; var svc = "' . data_entry_helper::$base_url . 'index.php/services/data/"; var email_subject_send_to_verifier = "' . $args['email_subject_send_to_verifier'] . '"; var email_body_send_to_verifier = "' . str_replace(array("\r", "\n"), array('', '\\n'), $args['email_body_send_to_verifier']) . '"; ', 'inline'); /*.'; ');*/ return $r; }
/** * Return the Indicia form code * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { global $user; $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $r = ''; if ($_POST) { // dump out any errors that occurred on verification if (data_entry_helper::$validation_errors) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>' . implode('</p></p>', array_values(data_entry_helper::$validation_errors)) . '</p></div>'; } else { if (isset($_POST['email'])) { // Send email. Depends upon settings in php.ini being correct $success = mail($_POST['email_to'], $_POST['email_subject'], wordwrap($_POST['email_body'], 70), 'From: ' . $user->mail . PHP_EOL . 'Return-Path: ' . $user->mail); } else { if (isset($_POST['occurrence:record_status']) && isset($response['success']) && $args['emails_enabled']) { // Provide a send email form to allow the user to send a verification email if ($_POST['occurrence:record_status'] == 'V') { $action = 'verified'; } elseif ($_POST['occurrence:record_status'] == 'R') { $action = 'rejected'; } else { $action = ''; } if ($action) { $occ = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('id' => $response['outer_id'], 'view' => 'detail'))); $occ = $occ[0]; $email_attr = data_entry_helper::get_population_data(array('table' => 'sample_attribute_value', 'extraParams' => $auth['read'] + array('caption' => 'Email', 'sample_id' => $occ['sample_id']))); $verified_taxa_taxon_list_id = $_POST['occAttr:' . $args['occ_attr_id']]; if ($action == 'verified' && $verified_taxa_taxon_list_id != $occ['taxa_taxon_list_id']) { $action = 'misidentified'; $verified_taxon = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $auth['read'] + array('id' => $verified_taxa_taxon_list_id))); $occ = array_merge($occ, array('verified_taxon' => $verified_taxon[0]['taxon'])); } $subject = self::get_email_component('subject', $action, $occ, $args); $body = self::get_email_component('body', $action, $occ, $args); if (!empty($email_attr[0]['value'])) { $r .= ' <form id="email" action="" method="post"> <fieldset> <legend>Send a notification email to the recorder.</legend> <label>To: <input type="text" name="email_to" size="80" value="' . $email_attr[0]['value'] . '"></label><br /> <label>Subject: <input type="text" name="email_subject" size="80" value="' . $subject . '"></label><br /> <label>Body: <textarea name="email_body" rows="5" cols="80">' . $body . '</textarea></label><br /> <input type="hidden" name="email" value="1"> <input type="button" value="Send Email" onclick=" $(\'form#email\').attr(\'action\', submit_to()); $(\'form#email\').submit(); "> </fieldset> </form> '; } else { $r .= '<div class="page-notice ui-state-highlight ui-corner-all">The record has been ' . $action . '. The recorder did not leave an email address so cannot be notified.</div>'; } } } } } } //extract fixed parameters for report grid. $params = explode(",", $args['fixed_params']); foreach ($params as $param) { $keyvals = explode("=", $param); $key = trim($keyvals[0]); $val = trim($keyvals[1]); $extraParams[$key] = $val; } $columns = array(array('display' => 'Actions', 'actions' => array(array('caption' => 'Verify', 'javascript' => 'indicia_verify({occurrence_id}, true, ' . $user->uid . '); return false;'), array('caption' => 'Reject', 'javascript' => 'indicia_verify({occurrence_id}, false, ' . $user->uid . '); return false;')))); //create a list of species to choose from with a hidden field indicating which to preselect //with javascript $taxon_list = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $auth['read'] + array('taxon_list_id' => $args['taxon_list_id'], 'orderby' => 'taxon_id'))); $species = '<select id="species-{occurrence_id}">'; foreach ($taxon_list as $taxon) { $species .= '<option value="' . $taxon['id'] . '">' . $taxon['taxon'] . '</opton>'; } $species .= '</select>'; $species .= '<input type="hidden" value="{taxa_taxon_list_id}" />'; $columns = array_merge($columns, array(array('display' => 'Taxon', 'template' => $species))); $r .= data_entry_helper::report_grid(array('id' => 'verification-grid', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => $columns, 'itemsPerPage' => 10, 'autoParamsForm' => $args['auto_params_form'], 'extraParams' => $extraParams, 'callback' => 'indicia_verification_2_species_init')); $r .= ' <form id="verify" method="post" action=""> ' . $auth['write'] . ' <input type="hidden" id="occurrence:id" name="occurrence:id" value="" /> <input type="hidden" id="occurrence:record_status" name="occurrence:record_status" value="" /> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="occurrence:verified_by_id" name="occurrence:verified_by_id" value="" /> <input type="hidden" id="occAttr:' . $args['occ_attr_id'] . '" name="occAttr:' . $args['occ_attr_id'] . '" value="" /> </form> '; drupal_add_js(' var verifiers_mapping = "' . $args['verifiers_mapping'] . '"; var url = ' . json_encode(data_entry_helper::get_reload_link_parts()) . '; var verified_species = "occAttr:' . $args['occ_attr_id'] . '";', 'inline'); return $r; }
* * @package Core * @subpackage Views * @author Indicia Team * @license http://www.gnu.org/licenses/gpl.html GPL * @link http://code.google.com/p/indicia/ */ require_once DOCROOT . 'client_helpers/data_entry_helper.php'; $readAuth = data_entry_helper::get_read_auth(0 - $_SESSION['auth_user']->id, kohana::config('indicia.private_key')); ?> <form class="iform" action="<?php echo url::site() . 'trigger/save'; ?> " method="post"> <fieldset> <legend>Enter the parameters for the trigger</legend> <?php // dump out the previous page form's values foreach ($_POST as $key => $value) { if ($key != 'submit' && substr($key, 0, 6) != 'param-') { echo "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\"/>\n"; } } // Ask the report grid code to build us a parameters form. echo data_entry_helper::report_grid(array('id' => 'params', 'paramsOnly' => true, 'dataSource' => $_POST['trigger:trigger_template_file'], 'readAuth' => $readAuth, 'ignoreParams' => array('date'), 'completeParamsForm' => false, 'paramDefaults' => $other_data['defaults'])); ?> </fieldset> <?php echo html::form_buttons(true); ?> </form>
/** * When viewing the list of samples for this user, get the grid to insert into the page. */ protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // get the CMS User ID attribute so we can filter the grid to this user if ($user->uid === 0) { return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false); if (!$userIdAttr) { return lang::get('This form must be used with a survey that has the CMS User ID attribute associated with it so records can be tagged against their creator.'); } $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false); if (!$userNameAttr) { return lang::get('This form must be used with a survey that has the CMS User Name attribute associated with it so records can be tagged against their creator.'); } $passageAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Passage', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false); if (!$passageAttr) { return lang::get('This form must be used with a survey that has the Passage attribute associated with it.'); } if (isset($args['grid_report'])) { $reportName = $args['grid_report']; } else { // provide a default in case the form settings were saved in an old version of the form $reportName = 'reports_for_prebuilt_forms/MNHNL/mnhnl_butterflies'; } $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 25, 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => iform_loctools_checkaccess($node, 'superuser') ? -1 : $user->uid, 'userName_attr_id' => $userNameAttr, 'passage_attr_id' => $passageAttr))); $r .= '<form>'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; $r .= "</form>\n<div style=\"display:none\" />\n <form id=\"form-delete-survey\" method=\"POST\">" . parent::$auth['write'] . "\n <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n </form>\n</div>"; data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n if(confirm(\"" . lang::get('LANG_ConfirmSurveyDelete') . " \"+sampleID)){\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n jQuery('#form-delete-survey').submit();\n }});\n };\n};"; return $r; }
* $body - gridview_table object. */ require_once DOCROOT . 'client_helpers/data_entry_helper.php'; $readAuth = data_entry_helper::get_read_auth(0 - $_SESSION['auth_user']->id, kohana::config('indicia.private_key')); $colDefs = array(); foreach ($columns as $fieldname => $title) { if (!isset($orderby)) { $orderby = $fieldname; } $def = array('fieldname' => $fieldname, 'display' => empty($title) ? str_replace('_', ' ', ucfirst($fieldname)) : $title); if ($fieldname == 'path') { $def['img'] = true; } $colDefs[] = $def; } $actions = $this->get_action_columns(); foreach ($actions as &$action) { if (substr($action['url'], 0, 4) != 'http') { $action['url'] = url::base(true) . $action['url']; } } if (count($actions) > 0) { $colDefs[] = array('display' => 'Actions', 'actions' => $actions); } echo data_entry_helper::report_grid(array('id' => $id, 'mode' => 'direct', 'dataSource' => $source, 'view' => 'gv', 'readAuth' => $readAuth, 'includeAllColumns' => false, 'columns' => $colDefs, 'extraParams' => array('orderby' => $orderby), 'filters' => $filter, 'itemsPerPage' => kohana::config('pagination.default.items_per_page'))); data_entry_helper::link_default_stylesheet(); // No need to re-link to jQuery data_entry_helper::$dumped_resources[] = 'jquery'; data_entry_helper::$dumped_resources[] = 'jquery_ui'; data_entry_helper::$dumped_resources[] = 'fancybox'; echo data_entry_helper::dump_javascript();
/** * When viewing the list of samples for this user, get the grid to insert into the page. */ protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // get the CMS User ID attribute so we can filter the grid to this user $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID'); if (!$userIdAttr) { return lang::get('This form must be used with a survey that has the CMS User ID attribute associated with it so records can be tagged against their creator.'); } $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username'); if (!$userNameAttr) { return lang::get('This form must be used with a survey that has the CMS User Name attribute associated with it so records can be tagged against their creator.'); } $targetSpeciesIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', $args['targetSpeciesAttr']); if (!$targetSpeciesIdAttr) { return lang::get('This form must be used with a survey that has the ' . $args['targetSpeciesAttr'] . ' attribute associated with it.'); } if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } if (isset($args['grid_report'])) { $reportName = $args['grid_report']; } else { // provide a default in case the form settings were saved in an old version of the form $reportName = 'reports_for_prebuilt_forms/MNHNL/mnhnl_reptiles'; } $extraParams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => iform_loctools_checkaccess($node, 'superuser') ? -1 : $user->uid, 'userName_attr_id' => $userNameAttr, 'userName' => $user->name, 'target_species_attr_id' => $targetSpeciesIdAttr); if (isset($args['filterAttrs']) && $args['filterAttrs'] != '') { global $custom_terms; $filterAttrs = explode(',', $args['filterAttrs']); $idxN = 1; foreach ($filterAttrs as $idx => $filterAttr) { $filterAttr = explode(':', $filterAttr); switch ($filterAttr[0]) { case 'Display': break; case 'Parent': $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[1]); $custom_terms['attr_' . $idxN] = lang::get($filterAttr[1]); $idxN++; break; default: $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[0]); $custom_terms['attr_' . $idxN] = lang::get($filterAttr[0]); $idxN++; break; } } } $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 25, 'autoParamsForm' => true, 'extraParams' => $extraParams)); $r .= '<form>'; if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new&gridmode')) . '\'">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; } $r .= '</form> <div style="display:none" /> <form id="form-delete-survey" action="' . iform_mnhnl_getReloadPath() . '" method="POST">' . $auth['write'] . ' <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:deleted" value="t" /> </form> </div> <div style="display:none" /> <form id="form-delete-survey-location" action="' . iform_mnhnl_getReloadPath() . '" method="POST">' . $auth['write'] . ' <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:deleted" value="t" /> <input type="hidden" name="location:id" value="" /> <input type="hidden" name="location:deleted" value="t" /> </form> </div>'; data_entry_helper::$javascript .= "\r\ndeleteSurvey = function(sampleID){\r\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\r\n \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\r\n \"&callback=?\", function(data) {\r\n if (data.length>0) {\r\n jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\r\n jQuery('#form-delete-survey-location').find('[name=sample\\:id]').val(data[0].id);\r\n jQuery('#form-delete-survey-location').find('[name=location\\:id]').val(data[0].location_id);\r\n // next get the location ID from sample, count the samples that are attached to that location\r\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample?location_id=\"+data[0].location_id +\r\n \"&parent_id=NULL&mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\r\n \"&callback=?\", function(sdata) {\r\n if (sdata.length==1) {\r\n var dialog = \$('<p>" . lang::get('The site only has this survey associated with it. Do you wish to delete the site as well?') . "</p>').\r\n dialog({ title: 'Delete Location Data?',\r\n width: 400,\r\n buttons: {\r\n 'Cancel': function() { dialog.dialog('close'); },\r\n 'Survey Only': function() {\r\n dialog.dialog('close');\r\n jQuery('#form-delete-survey').submit();\r\n },\r\n 'Site and Survey': function() {\r\n dialog.dialog('close');\r\n jQuery('#form-delete-survey-location').submit();\r\n }}});\r\n } else if (sdata.length > 1) {\r\n if(confirm(\"" . lang::get('Are you sure you wish to delete survey ') . "\"+sampleID)){\r\n jQuery('#form-delete-survey').submit();\r\n }\r\n }\r\n });\r\n }\r\n });\r\n};\n"; return $r; }
protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; if ($user->uid === 0) { return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID'); if (!$userIdAttr) { return lang::get('This form must be used with a survey that has the CMS User ID sample attribute associated with it so records can be tagged against their creator.'); } $usernameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username'); if (!$usernameAttr) { return lang::get('This form must be used with a survey that has the CMS Username sampleattribute associated with it so records can be tagged against their creator.'); } $villageAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Village'); if (!$villageAttr) { $villageAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'VillageDD'); } if (!$villageAttr) { return lang::get('This form must be used with a survey that has either the Village or VillageDD location attributes associated with it.'); } $communeAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Commune'); if (!$communeAttr) { return lang::get('This form must be used with a survey that has the Commune location attribute associated with it.'); } $reportName = $args['grid_report']; if (method_exists(get_called_class(), 'getSampleListGridPreamble')) { $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); } else { $r = ''; } $isAdmin = isset($args['edit_permission']) && $args['edit_permission'] != "" && user_access($args['edit_permission']); $isExpert = isset($args['ro_permission']) && $args['ro_permission'] != "" && user_access($args['ro_permission']); $extraparams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'username_attr_id' => $usernameAttr, 'village_attr_id' => $villageAttr, 'commune_attr_id' => $communeAttr); if ($isAdmin || $isExpert) { $extraparams['userID'] = -1; } else { $extraparams['userID'] = $user->uid; } $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => $args['grid_num_rows'], 'autoParamsForm' => true, 'extraParams' => $extraparams)); $r .= '<form>'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; $r .= "</form>\n<div style=\"display:none\" />\n <form id=\"form-delete-survey\" action=\"" . iform_mnhnl_getReloadPath() . "\" method=\"POST\">" . parent::$auth['write'] . "\n <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n </form>\n</div>"; if (!(function_exists('hostsite_get_user_field') && data_entry_helper::$entity_to_load['sample:created_by_id'] != 1 && data_entry_helper::$entity_to_load['sample:created_by_id'] !== ($userID = hostsite_get_user_field('indicia_user_id')))) { $userID = 1; } data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n if(" . ($isExpert ? 0 : 1) . " || data[0].created_by_id == " . $userID . "){\n if(confirm(\"" . lang::get('Are you sure you wish to delete survey') . " \"+sampleID+\"?\")){\n jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n jQuery('#form-delete-survey').submit();\n }\n } else\n alert(\"" . lang::get('You do not have permissions to delete survey') . " \"+sampleID+\". " . lang::get('You only have read only permissions on this survey.') . "\");\n }\n });\n};"; return $r; }
protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // get the CMS User ID attribute so we can filter the grid to this user $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false); if (!$userIdAttr) { return lang::get('getSampleListGrid function: This form must be used with a survey that has the CMS User ID sample attribute associated with it, so records can be tagged against their creator.'); } $extraParams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => user_access($args['edit_permission']) ? -1 : $user->uid); // use -1 if admin - non logged in will not get this far. $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false); if ($userNameAttr) { $extraParams['userName_attr_id'] = $userNameAttr; } if (isset($args['targetSpeciesAttr']) && $args['targetSpeciesAttr'] != "") { $targetSpeciesIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', $args['targetSpeciesAttr'], $args['target_species_subsample_method_id']); $extraParams['target_species_attr_id'] = $targetSpeciesIdAttr; } if (isset($args['filterAttrs']) && $args['filterAttrs'] != '') { global $custom_terms; $filterAttrs = explode(',', $args['filterAttrs']); $idxN = 1; foreach ($filterAttrs as $idx => $filterAttr) { $filterAttr = explode(':', $filterAttr); switch ($filterAttr[0]) { case 'Parent': $custom_terms['location name'] = lang::get('location name'); break; case 'Shape': $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[1]); $custom_terms['attr_' . $idxN] = lang::get($filterAttr[1]); $idxN++; break; default: $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[0]); $custom_terms['attr_' . $idxN] = lang::get($filterAttr[0]); $idxN++; break; } } } $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 25, 'autoParamsForm' => true, 'extraParams' => $extraParams)); $r .= '<form>'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; $r .= '</form> <div style="display:none" /> <form id="form-delete-survey" action="' . iform_mnhnl_getReloadPath() . '" method="POST">' . $auth['write'] . ' <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:deleted" value="t" /> </form> </div>'; data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n if(confirm(\"Are you sure you wish to delete survey \"+sampleID)){\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n jQuery('#form-delete-survey').submit();\n }});\n };\n};"; return $r; }
/** * Override function to add the report parameter for the ID of the custom attribute which holds the linked sample. * Depends upon a report existing that uses the parameter e.g. npms_sample_occurrence_samples */ protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // User must be logged in before we can access their records. if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => array('destination=node/' . $node->nid))) . '">login</a> to the website.'); } // Get the Indicia User ID to filter on. if (function_exists('hostsite_get_user_field')) { $iUserId = hostsite_get_user_field('indicia_user_id'); if (isset($iUserId)) { $filter = array('survey_id' => $args['survey_id'], 's1AttrID' => $args['survey_1_attr'], 'iUserID' => $iUserId); } } // Return with error message if we cannot identify the user records if (!isset($filter)) { return lang::get('LANG_No_User_Id'); } $r = data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => self::getReportActions(), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => $filter)); $r .= '<form>'; if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new'))) . '\'">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new&gridmode'))) . '\'">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => ''))) . '\'">'; } $r .= '</form>'; return $r; }
/** * Return the Indicia form code. * Expects there to be a sample attribute with caption 'Email' containing the email * address. * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { if (isset($_POST['enable'])) { module_enable(array('iform_ajaxproxy')); drupal_set_message(lang::get('The Indicia AJAX Proxy module has been enabled.', 'info')); } elseif (!defined('IFORM_AJAXPROXY_PATH')) { $r = '<p>' . lang::get('The Indicia AJAX Proxy module must be enabled to use this form. This lets the form save verifications to the ' . 'Indicia Warehouse without having to reload the page.') . '</p>'; $r .= '<form method="post">'; $r .= '<input type="hidden" name="enable" value="t"/>'; $r .= '<input type="submit" value="' . lang::get('Enable Indicia AJAX Proxy') . '"/>'; $r .= '</form>'; return $r; } if (function_exists('drupal_add_js')) { drupal_add_js('misc/collapse.js'); } iform_load_helpers(array('data_entry_helper', 'map_helper')); // fancybox for popup comment forms etc data_entry_helper::add_resource('fancybox'); data_entry_helper::add_resource('validation'); global $user, $indicia_templates; $indicia_user_id = self::get_indicia_user_id($args); $auth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); //extract fixed parameters for report grid. $params = explode("\n", $args['param_presets']); foreach ($params as $param) { $keyvals = explode("=", $param); $key = trim($keyvals[0]); $val = trim($keyvals[1]); $extraParams[$key] = $val; } // plus defaults which are not fixed $params = explode("\n", $args['param_defaults']); foreach ($params as $param) { $keyvals = explode("=", $param); $key = trim($keyvals[0]); $val = trim($keyvals[1]); $paramDefaults[$key] = $val; } $opts = array('id' => 'verification-grid', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth, 'rowId' => 'occurrence_id', 'itemsPerPage' => 10, 'autoParamsForm' => true, 'extraParams' => $extraParams, 'paramDefaults' => $paramDefaults, 'fieldsetClass' => 'collapsible collapsed'); if (!empty($args['columns_config'])) { $opts['columns'] = json_decode($args['columns_config'], true); } $grid = data_entry_helper::report_grid($opts); $r = str_replace(array('{grid}'), array($grid), self::get_template_grid_left($args, $auth)); $link = data_entry_helper::get_reload_link_parts(); global $user; data_entry_helper::$javascript .= 'indiciaData.username = "******"\";\n"; data_entry_helper::$javascript .= 'indiciaData.rootUrl = "' . $link['path'] . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.website_id = ' . $args['website_id'] . ";\n"; data_entry_helper::$javascript .= 'indiciaData.ajaxFormPostUrl="' . iform_ajaxproxy_url($node, 'occurrence') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/verification_3') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.autoDiscard = ' . $args['auto_discard_rows'] . ";\n"; // output some translations for JS to use data_entry_helper::$javascript .= "indiciaData.popupTranslations = {};\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.title="' . lang::get('Add {1} comment') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.save="' . lang::get('Save and {1}') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.verbV="' . lang::get('verify') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.verbR="' . lang::get('reject') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.V="' . lang::get('Verification') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.R="' . lang::get('Rejection') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.emailTitle="' . lang::get('Email record details for checking') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.sendEmail="' . lang::get('Send Email') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.emailSent="' . lang::get('The email was sent successfully.') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.popupTranslations.requestManualEmail="' . lang::get('The webserver is not correctly configured to send emails. Please send the following email usual your email client:') . "\";\n"; data_entry_helper::$javascript .= "indiciaData.statusTranslations = {};\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.V = "' . lang::get('Verified') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.R = "' . lang::get('Rejected') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.I = "' . lang::get('In progress') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.T = "' . lang::get('Test record') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.S = "' . lang::get('Sent for verification') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.statusTranslations.C = "' . lang::get('Awaiting verification') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.email_subject_send_to_verifier = "' . $args['email_subject_send_to_verifier'] . "\";\n"; $body = str_replace(array("\r", "\n"), array('', '\\n'), $args['email_body_send_to_verifier']); data_entry_helper::$javascript .= 'indiciaData.email_body_send_to_verifier = "' . $body . "\";\n"; return $r; }
/** * Get the grid of subsamples. */ protected static function get_control_subsamplegrid($auth, $args, $tabalias, $options) { if (!array_key_exists('sample:id', data_entry_helper::$entity_to_load) || !data_entry_helper::$entity_to_load['sample:id']) { return 'You have to save a new supersample before you can access aubsamples/occurrences for it.<br/>'; } $r = "<div id=\"subSampleList\">"; $r .= data_entry_helper::report_grid(array('id' => 'subsample-grid', 'dataSource' => $options['grid_report'], 'mode' => 'report', 'readAuth' => self::$auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getSubsampleReportActions')), 'itemsPerPage' => $options['grid_rows'], 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'parent_id' => data_entry_helper::$entity_to_load['sample:id']))); if ($args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_SubSample_Single') . '" id="new-subsample-button">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_SubSample_Grid') . '" id="new-subsample-button-grid">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_SubSample') . '" id="new-subsample-button">'; } $r .= "</div>\n"; data_entry_helper::$onload_javascript .= "\njQuery('#new-subsample-button').click(function(e) {\n var form = jQuery('<form>');\n form.attr('action', '" . self::$currentUrl . "');\n form.attr('method', 'POST');\n var addParam = function(paramName, paramValue){\n var input = \$('<input type=\"hidden\">');\n input.attr({ 'id': paramName,\n 'name': paramName,\n 'value': paramValue });\n form.append(input);\n };\n addParam('newsample_parent_id', " . data_entry_helper::$entity_to_load['sample:id'] . ");\n addParam('newsample_date', jQuery('[name=sample:date]').val());\n // Submit the form, then remove it from the page\n form.appendTo(document.body);\n form.submit();\n form.remove(); \n});\njQuery('#new-subsample-button-grid').click(function(e) {\n var form = jQuery('<form>');\n form.attr('action', '" . self::$currentUrl . "');\n form.attr('method', 'POST');\n var addParam = function(paramName, paramValue){\n var input = \$('<input type=\"hidden\">');\n input.attr({ 'id': paramName,\n 'name': paramName,\n 'value': paramValue });\n form.append(input);\n };\n addParam('newsample_parent_id', " . data_entry_helper::$entity_to_load['sample:id'] . ");\n addParam('newsample_date', jQuery('[name=sample:date]').val());\n addParam('gridmode', 'YES');\n // Submit the form, then remove it from the page\n form.appendTo(document.body);\n form.submit();\n form.remove(); \n});"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { global $user; $logged_in = $user->uid > 0; $r = ''; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; $mode = 0; // default mode : display survey selector // mode 1: display new sample // mode 2: display existing sample $loadID = null; $displayThisOcc = true; // when populating from the DB rather than POST we have to be // careful with selection object, as geom in wrong format. if ($_POST) { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = 2; // errors with new sample, entity poulated with post, so display this data. } // else valid save, so go back to gridview: default mode 0 } else { if (array_key_exists('sample_id', $_GET)) { $mode = 2; $loadID = $_GET['sample_id']; } else { if (array_key_exists('newSample', $_GET)) { $mode = 1; data_entry_helper::$entity_to_load = array(); } } // else default to mode 0 } /////////////////////////////////////////////////////////////////// // default mode 0 : display survey selector /////////////////////////////////////////////////////////////////// if ($mode == 0) { $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => 'reports_for_prebuilt_forms/simple_sample_list_1', 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => array(array('display' => 'Actions', 'actions' => array(array('caption' => 'Edit', 'url' => '{currentUrl}', 'urlParams' => array('sample_id' => '{sample_id}'))))), 'itemsPerPage' => 10, 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'userID_attr_id' => $args['uid_attr_id'], 'userID' => $user->uid))); $r .= '<form><input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'"></form>'; return $r; } /////////////////////////////////////////////////////////////////// data_entry_helper::$javascript .= "\n// Create vector layers: one to display the location onto, and another for the occurrence list\n// the default edit layer is used for the occurrences themselves\nlocStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Green\",\n strokeColor: \"Black\",\n fillOpacity: 0.3,\n strokeWidth: 1\n })\n });\nlocationLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Location_Layer") . "\",\n {styleMap: locStyleMap});\n"; if ($loadID) { // Can't cache these as data may have just changed data_entry_helper::$entity_to_load['occurrence:record_status'] = 'I'; $url = $svcUrl . '/data/sample/' . $loadID; $url .= "?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); // Attributes should be loaded by get_attributes. data_entry_helper::$entity_to_load = array(); foreach ($entity[0] as $key => $value) { data_entry_helper::$entity_to_load['sample:' . $key] = $value; } $url = $svcUrl . '/data/occurrence'; $url .= "?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&sample_id=" . $loadID . "&deleted=FALSE"; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); foreach ($entities as $entity) { data_entry_helper::$entity_to_load['occurrence:record_status'] = $entity['record_status']; data_entry_helper::$entity_to_load['sc:' . $entity['taxa_taxon_list_id'] . ':' . $entity['id'] . ':present'] = true; } data_entry_helper::$entity_to_load['sample:geom'] = ''; // value received from db is not WKT, which is assumed by all the code. data_entry_helper::$entity_to_load['sample:date'] = data_entry_helper::$entity_to_load['sample:date_start']; // bit of a bodge to get around vague dates. } $defAttrOptions = array('extraParams' => $auth['read']); // $r .= "<h1>MODE = ".$mode."</h1>"; // $r .= "<h2>readOnly = ".$readOnly."</h2>"; $r = "<form method=\"post\" id=\"entry_form\">\n"; // Insert authorisation tokens to update the Warehouse. $r .= $auth['write']; $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } // request automatic JS validation data_entry_helper::enable_validation('entry_form'); $attributes = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'])); if ($logged_in) { // If logged in, output some hidden data about the user $uid = $user->uid; $email = $user->mail; $username = $user->name; $uid_attr_id = $args['uid_attr_id']; $email_attr_id = $args['email_attr_id']; $username_attr_id = $args['username_attr_id']; // This assumes that we have the following attributes : no built in error checking. $r .= "<input type=\"hidden\" name=\"" . $attributes[$uid_attr_id]['fieldname'] . "\" value=\"{$uid}\" />\n"; $r .= "<input type=\"hidden\" name=\"" . $attributes[$email_attr_id]['fieldname'] . "\" value=\"{$email}\" />\n"; $r .= "<input type=\"hidden\" name=\"" . $attributes[$username_attr_id]['fieldname'] . "\" value=\"{$username}\" />\n"; } $r .= "<div id=\"controls\">\n"; if ($args['interface'] != 'one_page') { $r .= "<ul>\n"; if (!$logged_in) { $r .= ' <li><a href="#about_you"><span>' . lang::get('LANG_About_You_Tab') . "</span></a></li>\n"; } $r .= ' <li><a href="#species"><span>' . lang::get('LANG_Species_Tab') . "</span></a></li>\n"; $r .= ' <li><a href="#place"><span>' . lang::get('LANG_Place_Tab') . "</span></a></li>\n"; $r .= ' <li><a href="#other"><span>' . lang::get('LANG_Other_Information_Tab') . "</span></a></li>\n"; $r .= "</ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'])); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!$logged_in) { $r .= "<div id=\"about_you\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_About_You_Tab_Instructions') . "</p>"; $defAttrOptions['class'] = 'control-width-4'; $r .= data_entry_helper::outputAttribute($attributes[$args['first_name_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['surname_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['email_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['phone_attr_id']], $defAttrOptions); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'first')); } unset($defAttrOptions['class']); $r .= "</div>\n"; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// global $indicia_templates; $indicia_templates['taxon_label'] = '<div class="biota"><span class="nobreak sci binomial"><em>{taxon}</em></span> {authority}</div>'; $r .= "<div id=\"species\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Species_Tab_Instructions') . "</p>"; $species_list_args = array('listId' => $args['list_id'], 'label' => lang::get('occurrence:taxa_taxon_list_id'), 'columns' => 1, 'view' => 'detail', 'occAttrs' => explode(',', $args['checklist_attributes']), 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); if ($args['extra_list_id']) { $species_list_args['lookupListId'] = $args['extra_list_id']; } $r .= data_entry_helper::species_checklist($species_list_args); $r .= "<label for=\"sample:comment\">" . lang::get('LANG_Sample_Comment_Label') . "</label><input type=\"text\" id=\"sample:comment\" name=\"sample:comment\" value=\"" . data_entry_helper::$entity_to_load['sample:comment'] . "\" />\n"; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $user->id == 0 ? 'first' : 'middle')); } $r .= "</div>\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $r .= "<div id=\"place\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Place_Tab_Instructions') . "</p>"; // Build the array of spatial reference systems into a format Indicia can use. $systems = array(); $list = explode(',', str_replace(' ', '', $args['spatial_systems'])); foreach ($list as $system) { $systems[$system] = lang::get($system); } $r .= data_entry_helper::sref_and_system(array('label' => lang::get('LANG_SRef_Label'), 'systems' => $systems)); $location_list_args = array('label' => lang::get('LANG_Location_Label'), 'view' => 'detail', 'extraParams' => array_merge(array('view' => 'detail', 'orderby' => 'name'), $auth['read'])); $r .= call_user_func(array('data_entry_helper', $args['location_ctrl']), $location_list_args); $r .= data_entry_helper::georeference_lookup(iform_map_get_georef_options($args, $auth['read'])); $options = iform_map_get_map_options($args, $auth['read']); $options['layers'][] = 'locationLayer'; $olOptions = iform_map_get_ol_options($args); $r .= data_entry_helper::map_panel($options, $olOptions); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls')); } $r .= "</div>\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $r .= "<div id=\"other\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Other_Information_Tab_Instructions') . "</p>"; $r .= data_entry_helper::date_picker(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date')); $r .= data_entry_helper::outputAttribute($attributes[$args['biotope_attr_id']], $defAttrOptions); $values = array('I', 'C'); // not initially doing V=Verified $r .= '<label for="occurrence:record_status">' . lang::get('LANG_Record_Status_Label') . '</label><select id="occurrence:record_status" name="occurrence:record_status">'; foreach ($values as $value) { $r .= '<option value="' . $value . '"'; if (isset(data_entry_helper::$entity_to_load['occurrence:record_status'])) { if (data_entry_helper::$entity_to_load['occurrence:record_status'] == $value) { $r .= ' selected="selected"'; } } $r .= '>' . lang::get('LANG_Record_Status_' . $value) . '</option>'; } $r .= '</select>'; // TODO image upload - not sure how to do this as images are attached to occurrences, and occurrences // are embedded in the species list. // $r .= "<label for='occurrence:image'>".lang::get('LANG_Image_Label')."</label>\n". // data_entry_helper::image_upload('occurrence:image'); $r .= '<br/><br/>'; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'last')); } else { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $r .= "</div>\n"; $r .= "</div>\n"; if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; // may need to keep following code for location change functionality data_entry_helper::$onload_javascript .= "\n \nlocationChange = function(obj){\n\tlocationLayer.destroyFeatures();\n\tif(obj.value != ''){\n\t\tjQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location/\"+obj.value +\n\t\t\t\"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n\t\t\t\"&callback=?\", function(data) {\n if (data.length>0) {\n \tvar parser = new OpenLayers.Format.WKT();\n \tfor (var i=0;i<data.length;i++)\n\t\t\t\t{\n\t \t\t\tif(data[i].centroid_geom){\n\t\t\t\t\t\tfeature = parser.read(data[i].centroid_geom);\n\t\t\t\t\t\tcentre = feature.geometry.getCentroid();\n\t\t\t\t\t\tcentrefeature = new OpenLayers.Feature.Vector(centre, {}, {label: data[i].name});\n\t\t\t\t\t\tlocationLayer.addFeatures([feature, centrefeature]); \n\t\t\t\t\t}\n\t\t\t\t\tif(data[i].boundary_geom){\n\t\t\t\t\t\tfeature = parser.read(data[i].boundary_geom);\n\t\t\t\t\t\tfeature.style = {strokeColor: \"Blue\",\n \t \tstrokeWidth: 2,\n \t\t\t\t\t\t\tlabel: (data[i].centroid_geom ? \"\" : data[i].name)};\n\t\t\t\t\t\tlocationLayer.addFeatures([feature]);\n \t\t\t\t\t}\n \t\t\t\tlocationLayer.map.zoomToExtent(locationLayer.getDataExtent());\n \t\t\t\t}\n\t\t\t}\n\t\t});\n }\n};\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n\tlocationChange(this);\n});\n// upload location & sref initial values into map.\njQuery('#imp-location').change();\njQuery('#imp-sref').change();\n\n"; return $r; }
$svcUrl = data_entry_helper::$base_url . 'index.php/services'; ?> <head> <title>Report Grid Demo</title> <style type="text/css"> #charts .ui-widget-header { margin: 0.2em; padding: 0.2em; } #charts .ui-widget { margin: 1em; } </style> </head> <body> <?php data_entry_helper::link_default_stylesheet(); $readAuth = data_entry_helper::get_read_auth($config['website_id'], $config['password']); echo data_entry_helper::report_grid(array('dataSource' => 'occurrences_by_survey', 'mode' => 'report', 'readAuth' => $readAuth, 'columns' => array(array('fieldname' => 'survey', 'display' => 'Survey Title'), array('fieldname' => 'count', 'display' => 'Number of Occurrences'), array('display' => 'Custom column', 'template' => '{survey} has {count} occurrences')), 'includeAllColumns' => false, 'itemsPerPage' => 5, 'extraParams' => array('survey' => 'A'))); echo "<div id=\"charts\">\n"; echo data_entry_helper::report_chart(array('title' => 'Bar chart of record count per survey', 'id' => 'barChart', 'dataSource' => 'occurrences_by_survey', 'mode' => 'report', 'readAuth' => $readAuth, 'chartType' => 'bar', 'yValues' => 'count', 'xLabels' => 'survey', 'width' => 600, 'axesOptions' => array('yaxis' => array('min' => 0, 'max' => '3', 'tickInterval' => 1)))); echo data_entry_helper::report_chart(array('title' => 'Demonstration line chart (y=survey website id, x=survey id)', 'id' => 'lineChart', 'dataSource' => array('survey', 'term'), 'mode' => 'direct', 'readAuth' => $readAuth, 'chartType' => 'line', 'yValues' => array('website_id', 'language_id'), 'xValues' => 'id', 'width' => 600, 'legendOptions' => array('show' => true))); echo data_entry_helper::report_chart(array('title' => 'Demonstration pie chart of occurrences per survey', 'id' => 'pieChart', 'dataSource' => 'occurrences_by_survey', 'mode' => 'report', 'readAuth' => $readAuth, 'chartType' => 'pie', 'yValues' => 'count', 'xLabels' => 'survey', 'legendOptions' => array('show' => true), 'width' => 500)); echo "</div>"; echo data_entry_helper::dump_javascript(); ?> </body> </html>
/** * When viewing the list of samples for this user, get the grid to insert into the page. */ protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // User must be logged in before we can access their records. if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => array('destination' => 'node/' . $node->nid))) . '">login</a> to the website.'); } $filter = array(); // Get the CMS User ID attribute so we can filter the grid to this user foreach ($attributes as $attrId => $attr) { if (strcasecmp($attr['caption'], 'CMS User ID') == 0) { $filter = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $attr['attributeId'], 'userID' => $user->uid, 'iUserID' => 0); break; } } // Alternatively get the Indicia User ID and use that instead if (function_exists('hostsite_get_user_field')) { $iUserId = hostsite_get_user_field('indicia_user_id'); if (isset($iUserId) && $iUserId != false) { $filter = array('survey_id' => $args['survey_id'], 'userID_attr_id' => 0, 'userID' => 0, 'iUserID' => $iUserId); } } // Return with error message if we cannot identify the user records if (!isset($filter)) { return lang::get('LANG_No_User_Id'); } // An option for derived classes to add in extra html before the grid if (method_exists(self::$called_class, 'getSampleListGridPreamble')) { $r = call_user_func(array(self::$called_class, 'getSampleListGridPreamble')); } else { $r = ''; } $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(self::$called_class, 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => $filter)); $r .= '<form>'; if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1', 'gridmode' => '1'))) . '\'">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">'; } $r .= '</form>'; return $r; }
/** * When viewing the list of samples for this user, get the grid to insert into the page. */ protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID'); if (!$userIdAttr) { return lang::get('This form must be used with a survey that has the CMS User ID sample attribute associated with it.'); } $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username'); if (!$userNameAttr) { return lang::get('This form must be used with a survey that has the CMS Username sample attribute associated with it.'); } $observerAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Observer'); if (!$observerAttr) { return lang::get('This form must be used with a survey that has the Observer sample attribute associated with it.'); } if (isset($args['grid_report'])) { $reportName = $args['grid_report']; } else { // provide a default in case the form settings were saved in an old version of the form $reportName = 'reports_for_prebuilt_forms/MNHNL/mnhnl_butterflies'; } $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => iform_loctools_checkaccess($node, 'superuser') ? -1 : $user->uid, 'userName_attr_id' => $userNameAttr, 'userName' => $user->name, 'observer_attr_id' => $observerAttr))); $r .= '<form>'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">'; $r .= '</form>'; return $r; }
/** * Return the Indicia form code * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $r = ''; if ($_POST) { // dump out any errors that occurred on verification if (data_entry_helper::$validation_errors) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all"><p>' . implode('</p></p>', array_values(data_entry_helper::$validation_errors)) . '</p></div>'; } else { if (isset($_POST['occurrence:record_status']) && isset($response['success']) && $args['emails_enabled']) { // Provide a send email form to allow the user to send a verification email if ($_POST['occurrence:record_status'] == 'V') { $action = 'verified'; } elseif ($_POST['occurrence:record_status'] == 'R') { $action = 'rejected'; } else { $action = ''; } if ($action) { $occ = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('id' => $response['outer_id'], 'view' => 'detail'))); $email_attr = data_entry_helper::get_population_data(array('table' => 'sample_attribute_value', 'extraParams' => $auth['read'] + array('caption' => 'Email', 'sample_id' => $occ[0]['sample_id']))); $subject = self::get_email_component('subject', $action, $occ[0], $args); $body = self::get_email_component('body', $action, $occ[0], $args); if (!empty($email_attr[0]['value'])) { $r .= ' <form id="email-form" action="mailto:' . $email_attr[0]['value'] . '?subject=' . $subject . '&body=' . $body . '" method="post" enctype="text/plain"> <fieldset> <legend>Send a notification email to the recorder.</legend> <input type="submit" value="Send Email"> </fieldset> </form> '; } else { $r .= '<div class="page-notice ui-state-highlight ui-corner-all">The record has been ' . $action . '. The recorder did not leave an email address so cannot be notified.</div>'; } } } } } global $user; $r .= data_entry_helper::report_grid(array('id' => 'verification-grid', 'dataSource' => $args['report_name'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => array(array('display' => 'Actions', 'actions' => array(array('caption' => 'Verify', 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, true, ' . $user->uid . '); return false;'), array('caption' => 'Reject', 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, false, ' . $user->uid . '); return false;')))), 'itemsPerPage' => 10, 'autoParamsForm' => $args['auto_params_form'], 'extraParams' => array())); $r .= ' <form id="verify" method="post" action=""> ' . $auth['write'] . ' <input type="hidden" id="occurrence:id" name="occurrence:id" value="" /> <input type="hidden" id="occurrence:record_status" name="occurrence:record_status" value="" /> <input type="hidden" id="website7_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="occurrence:verified_by_id" name="occurrence:verified_by_id" value="" /> </form> '; drupal_add_js(' var verifiers_mapping = "' . $args['verifiers_mapping'] . '"; var url = ' . json_encode(data_entry_helper::get_reload_link_parts()) . '; function indicia_verify(taxon, id, valid, cmsUser){ var action; if (valid) { $("#occurrence\\\\:record_status").attr("value", "V"); action = "verify"; } else { $("#occurrence\\\\:record_status").attr("value", "R"); action = "reject"; } if (confirm("Are you sure you want to " + action + " this record of " + taxon + "?")) { $("#occurrence\\\\:id").attr(\'value\', id); if (verifiers_mapping.indexOf("=")==-1) { verifier = verifiers_mapping; } else { var verifierMaps = verifiers_mapping.split(","); var keyval, verifiersArr = new Array(); $.each(verifierMaps, function(idx, map) { keyval = map.split("="); if (parseInt(keyval[0].trim())==cmsUser) { verifier = keyval[1].trim(); } }); } $("#occurrence\\\\:verified_by_id").attr(\'value\', verifier); // We need to dynamically build the submitTo so we get the correct sort order var submitTo = ""; // access globals created by the report grid to get the current state of pagination and sort as a result of AJAX calls url.params["page-verification-grid"] = report_grid_page; if (report_grid_orderby!="") { url.params["orderby-verification-grid"] = report_grid_orderby; } else { delete url.params["orderby-verification-grid"]; } if (report_grid_sortdir!="") { url.params["sortdir-verification-grid"] = report_grid_sortdir; } else { delete url.params["sortdir-verification-grid"] } $.each(url.params, function(field, value) { submitTo += (submitTo ==="" ? "?" : "&"); submitTo += field + "=" + value; }); submitTo = url.path + submitTo; $("form#verify").attr("action", submitTo); $("form#verify").submit(); } } ', 'inline'); return $r; }
/** * When viewing the list of samples for this user, get the grid to insert into the page. */ private static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // get the CMS User ID attribute so we can filter the grid to this user foreach ($attributes as $attrId => $attr) { if (strcasecmp($attr['caption'], 'CMS User ID') == 0) { $userIdAttr = $attrId; break; } } if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } if (!isset($userIdAttr)) { return lang::get('This form must be used with a survey that has the CMS User ID attribute associated with it so records can ' . 'be tagged against the user.'); } if (isset($args['grid_report'])) { $reportName = $args['grid_report']; } else { // provide a default in case the form settings were saved in an old version of the form $reportName = 'reports_for_prebuilt_forms/simple_sample_list_1'; } if (method_exists(get_called_class(), 'getSampleListGridPreamble')) { $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); } else { $r = ''; } $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => 10, 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => $user->uid))); $r .= '<form>'; if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample&gridmode')) . '\'">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'">'; } $r .= '</form>'; return $r; }
protected static function getSampleListGrid($args, $node, $auth, $attributes) { global $user; // get the CMS User ID attribute so we can filter the grid to this user foreach ($attributes as $attrId => $attr) { if (strcasecmp($attr['caption'], 'CMS User ID') == 0) { $userIdAttr = $attrId; } else { if (strcasecmp($attr['caption'], 'CMS Username') == 0) { $usernameAttr = $attrId; } } } $locAttributes = data_entry_helper::getAttributes(array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'])); foreach ($locAttributes as $attrId => $attr) { if (strcasecmp($attr['untranslatedCaption'], 'village') == 0) { $villageAttr = $attrId; } else { if (strcasecmp($attr['untranslatedCaption'], 'commune') == 0) { $communeAttr = $attrId; } } } if ($user->uid === 0) { // Return a login link that takes you back to this form when done. return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } if (!isset($userIdAttr)) { return lang::get('This form must be used with a survey that has the CMS User ID attribute associated with it so records can ' . 'be tagged against the user.'); } if (!isset($usernameAttr)) { return lang::get('This form must be used with a survey that has the CMS Username attribute associated with it so records can ' . 'be tagged against the user.'); } if (!isset($villageAttr)) { return lang::get('This form must be used with a survey that has the Village Location attribute associated with it.'); } if (!isset($communeAttr)) { return lang::get('This form must be used with a survey that has the Commune Location attribute associated with it.'); } if (isset($args['grid_report'])) { $reportName = $args['grid_report']; } else { // provide a default in case the form settings were saved in an old version of the form $reportName = 'reports_for_prebuilt_forms/simple_sample_list_1'; } if (method_exists(get_called_class(), 'getSampleListGridPreamble')) { $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble')); } else { $r = ''; } $isAdmin = user_access('IForm n' . $node->nid . ' admin'); $extraparams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'username_attr_id' => $usernameAttr, 'village_attr_id' => $villageAttr, 'commune_attr_id' => $communeAttr); if ($isAdmin) { $extraparams['userID'] = -1; } else { $extraparams['userID'] = $user->uid; } $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => 25, 'autoParamsForm' => true, 'extraParams' => $extraparams)); $r .= '<form>'; if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'">'; $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample&gridmode')) . '\'">'; } else { $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'">'; } $r .= "</form>\n<div style=\"display:none\" />\n <form id=\"form-delete-survey\" action=\"" . $reloadPath . "\" method=\"POST\">" . self::$auth['write'] . "\n <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n <input type=\"hidden\" name=\"sample:date\" value=\"2010-01-01\"/>\n <input type=\"hidden\" name=\"sample:location_id\" value=\"\" />\n <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n </form>\n</div>"; data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n if(confirm(\"Are you sure you wish to delete survey \"+sampleID)){\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n jQuery('#form-delete-survey').find('[name=sample\\:date]').val(data[0].date_start);\n jQuery('#form-delete-survey').find('[name=sample\\:location_id]').val(data[0].location_id);\n jQuery('#form-delete-survey').submit();\n }});\n };\n};"; return $r; }