/**
  * Return the generated form output.
  * @param array $args List of parameter values passed through to the form depending on how the form has been configured.
  * This array always contains a value for language.
  * @param object $node The Drupal node object.
  * @param array $response When this form is reloading after saving a submission, contains the response from the service call.
  * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data).
  * @return Form HTML.
  * @todo: Implement this method 
  */
 public static function get_form($args, $node, $response = null)
 {
     if (isset($response['error'])) {
         data_entry_helper::dump_errors($response);
     }
     if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'grid' && !isset(data_entry_helper::$validation_errors)) {
         // we have just saved the sample page, so move on to the occurrences list
         return self::get_occurrences_form($args, $node, $response);
     } else {
         return self::get_sample_form($args, $node, $response);
     }
 }
Пример #2
0
 /**
  * Return the generated form output.
  * @param array $args List of parameter values passed through to the form depending on how the form has been configured.
  * This array always contains a value for language.
  * @param object $node The Drupal node object.
  * @param array $response When this form is reloading after saving a submission, contains the response from the service call.
  * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data).
  * @return Form HTML.
  */
 public static function get_form($args, $node, $response = null)
 {
     if (isset($response['error'])) {
         data_entry_helper::dump_errors($response);
     }
     if (isset($_REQUEST['page']) && ($_REQUEST['page'] === 'site' && !isset(data_entry_helper::$validation_errors) || $_REQUEST['page'] === 'occurrences' && isset(data_entry_helper::$validation_errors))) {
         // or we have just saved the occurrences page with errors, so redisplay the occurrences list
         return self::get_occurrences_form($args, $node, $response);
     } else {
         return self::get_sample_form($args, $node, $response);
     }
 }
 /**
  * Return the generated form output.
  * @param array $args List of parameter values passed through to the form depending on how the form has been configured.
  *                    This array always contains a value for language.
  * @param integer $nid The Drupal node object's ID.
  * @param array $response When this form is reloading after saving a submission, contains the response from the service call.
  *                        Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data).
  * @return Form HTML.
  */
 public static function get_form($args, $nid, $response = null)
 {
     global $user;
     //    if (!function_exists('module_exists') || !module_exists('iform_ajaxproxy'))
     //      return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.';
     if (!function_exists('module_exists') || !module_exists('easy_login')) {
         return 'FATAL INTERNAL CONFIGURATION ERROR: This form must be used in Drupal with the Easy Login module enabled.';
     }
     if (!function_exists('module_exists') || !module_exists('species_packages')) {
         return 'FATAL INTERNAL CONFIGURATION ERROR: This form must be used in Drupal with the custom species_packages module enabled.';
     }
     // assuming easy login
     $userId = hostsite_get_user_field('indicia_user_id');
     if (empty($userId)) {
         return '<p>FATAL ERROR: Could not identify user.</p>';
     }
     // something is wrong
     $r = isset($response['error']) ? data_entry_helper::dump_errors($response) : '';
     iform_load_helpers(array('map_helper', 'report_helper'));
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     self::$sampleId = null;
     self::$occurrenceId = false;
     if (isset(data_entry_helper::$entity_to_load['sample:id']) && data_entry_helper::$entity_to_load['sample:id'] != "") {
         // have just posted a (failed) edit to an existing parent sample.
         self::$sampleId = data_entry_helper::$entity_to_load['sample:id'];
     } else {
         if (isset(data_entry_helper::$entity_to_load['sample:survey_id']) && data_entry_helper::$entity_to_load['sample:survey_id'] != "") {
             // have just posted a (failed) edit to a new parent sample.
             self::$sampleId = null;
         } else {
             if (isset($response['outer_id'])) {
                 // have just successfully posted either a new parent sample, or an update to an existing one.
                 self::$sampleId = $response['outer_id'];
                 data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 if (!isset($_POST['force_page_reload'])) {
                     return self::get_success_page($args, $auth, $response['outer_id']);
                 }
                 drupal_set_message(lang::get('The Transect you have just saved specified the Species Package to be used. The Transect has been reloaded below, and the Species tab now contains the Species Grid for the Species Package, which will allow you to enter the species data.'));
             } else {
                 if (isset($_GET['sample_id']) && intval($_GET['sample_id']) == $_GET['sample_id']) {
                     self::$sampleId = $_GET['sample_id'];
                     data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 } else {
                     self::$sampleId = null;
                 }
             }
         }
     }
     if (isset($_GET['occurrence_id']) && intval($_GET['occurrence_id']) == $_GET['occurrence_id']) {
         self::$occurrenceId = $_GET['occurrence_id'];
         if (self::$sampleId == null) {
             // fill in the sample_id from the occurrence if don't already have it
             $occurrence = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => self::$occurrenceId)));
             // this throws an error exception if any error.
             // this gives
             if (count($occurrence) == 1) {
                 $subsample = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $occurrence[0]['sample_id'])));
                 if (count($subsample) == 1) {
                     self::$sampleId = $subsample[0]['parent_id'];
                     data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 }
             }
         }
     }
     if (isset(data_entry_helper::$entity_to_load['sample:survey_id']) && data_entry_helper::$entity_to_load['sample:survey_id'] != $args['survey_id']) {
         drupal_set_message(t('The data entry form you have selected to use is configured for a particular survey:') . ' ID ' . $args['survey_id'] . ' ' . t('The sample you have chosen to view is not assigned to this survey.'), 'error');
         drupal_goto('<front>');
     }
     if (isset(data_entry_helper::$entity_to_load['sample:parent_id']) && data_entry_helper::$entity_to_load['sample:parent_id'] != '' && data_entry_helper::$entity_to_load['sample:parent_id'] !== null) {
         drupal_set_message(t('An attempt has been made to access a non top level sample.'));
         drupal_goto('<front>');
     }
     $survey = data_entry_helper::get_population_data(array('table' => 'survey', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $args['survey_id'], 'website_id' => $args['website_id'])));
     if (count($survey) != 1) {
         return "FATAL INTERNAL CONFIGURATION ERROR: Supplied form survey_id value (" . $args['survey_id'] . ") is not valid survey for this website (" . $args['website_id'] . ").<br/>";
     }
     $surveyTitle = $survey[0]['title'];
     if (self::$sampleId == null) {
         $packages = species_packages_get_packages($user->uid, $args['survey_id']);
         if ($packages === false || is_array($packages) && count($packages) == 0) {
             drupal_set_message(t('You have not yet selected a species package that is compatible with survey') . ' : &quot;' . $surveyTitle . '&quot;', 'error');
             drupal_set_message(str_replace('#link#', '<a href="' . url('user/' . $user->uid . '/edit') . '">' . t('this link') . '</a>', t('You can set the species package on your user account page, which can be accessed using #link#. If you have already selected a species package, and wish to add another or wish to change your selection, please contact your Hub Manager.')));
             drupal_goto('<front>');
         }
         self::$readOnly = false;
     } else {
         self::$readOnly = !isset($response['error']) && data_entry_helper::$entity_to_load['sample:created_by_id'] != hostsite_get_user_field('indicia_user_id') && (empty($args['edit_permission']) || !hostsite_user_has_permission($args['edit_permission']));
     }
     if (self::$readOnly) {
         drupal_set_message(t('In order to save changes to existing records, you must either be the creator of the entry, or have been given the appropriate permission.'));
     }
     // In readonly mode, the forms are replaced by divs and there are no save buttons.
     //    $r .= '<span style="display:none;">'.print_r($packages,true).'</span>';
     //	$r .= '<span style="display:none;">'.print_r(array($user->uid, $args, $packageAttr), true).'</span>' .
     $attributes = data_entry_helper::getAttributes(array('id' => self::$sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $args['transect_level_sample_method_id']));
     $packageAttr = self::extract_package_attr($attributes, true);
     if (!$packageAttr) {
         return "FATAL INTERNAL CONFIGURATION ERROR: This form must be used with a survey which has a &#x22;Species Package&#x22; sample attribute defined for it (integer, required on parent).<br/>";
     }
     self::_remove_options($args);
     $r .= (self::$readOnly ? '<div id="data_entry_form">' : '<form method="post" id="data_entry_form">' . $auth['write']) . '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>' . (isset(data_entry_helper::$entity_to_load['sample:id']) ? '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>' : '') . '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>' . '<input type="hidden" name="sample:sample_method_id" value="' . $args['transect_level_sample_method_id'] . '" />';
     if (isset(data_entry_helper::$entity_to_load['sample:id'])) {
         $r .= "<h2>" . data_entry_helper::$entity_to_load['sample:location_name'] . " on " . data_entry_helper::$entity_to_load['sample:date'] . (self::$readOnly ? ' ' . lang::get('READ ONLY') : '') . "</h2>\n";
     }
     $r .= "<div id=\"tabs\">\n";
     $tabs = array();
     $smpTab = self::get_sample_tab($args, $nid, $auth, $attributes, $packageAttr);
     $mediaTab = self::get_media_tab($args, $nid, $auth);
     $occTab = self::get_occurrences_tab($args, $nid, $auth, $packageAttr);
     // Note this messes with the templates, so done last just in case
     $tabs['#sample'] = t($args['sample_tab_label']);
     if ($occTab != "") {
         $tabs['#occurrences'] = t($args['occurrence_tab_label']);
     }
     if ($mediaTab != "") {
         $tabs['#media'] = t($args['media_tab_label']);
     }
     $r .= data_entry_helper::tab_header(array('tabs' => $tabs));
     data_entry_helper::enable_tabs(array('divId' => 'tabs', 'style' => 'Tabs', 'active' => $occTab != "" && (self::$occurrenceId || self::$sampleId) ? 'occurrences' : 'sample'));
     $r .= $smpTab . $occTab . $mediaTab . '</div>' . (self::$readOnly ? '</div>' : '</form>');
     if (!self::$readOnly) {
         // custom version of enable validation code
         data_entry_helper::$validated_form_id = 'data_entry_form';
         data_entry_helper::$javascript .= "indiciaData.validatedFormId = '" . data_entry_helper::$validated_form_id . "';\n";
         // prevent double submission of the form
         data_entry_helper::$javascript .= "\$('#data_entry_form').submit(function(e) {\r\n  if (typeof \$('#data_entry_form').valid === 'undefined' || \$('#data_entry_form').valid()) {\r\n    if (typeof indiciaData.formSubmitted==='undefined' || !indiciaData.formSubmitted) {\r\n      \$('<p>" . lang::get('Please wait whilst the data is saved.') . "</p>').dialog({ title: '" . lang::get('Saving Data') . "', buttons: { '" . lang::get('OK') . "' : function() { \$( this ).dialog('close'); } } });\r\n      indiciaData.formSubmitted=true;\r\n    } else {\r\n      e.preventDefault();\r\n      return false;\r\n    }\r\n  }\r\n});\n";
         data_entry_helper::add_resource('validation');
     }
     return $r;
 }
Пример #4
0
$occurrences = data_entry_helper::wrap_species_checklist($data);
// Add the occurrences in as submodels
$sampleMod['subModels'] = $occurrences;
// and link in the attributes of the sample
$sampleMod['metaFields']['smpAttributes']['value'] = $smpAttrs;
// Wrap submission and submit
$submission = array('submission' => array('entries' => array(array('model' => $sampleMod))));
$response = data_entry_helper::forward_post_to('save', $submission);
if (array_key_exists('success', $response)) {
    // on success, redirect to the thank you page
    header('Location:success.php');
    die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Saving data</title>
<link rel="stylesheet" href="advanced.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../media/css/default_site.css" type="text/css" media="screen">
</head>
<body>
<div id="wrap">
<!-- We shouldn't get this far as a success causes redirection -->
<h1>An error occurred</h1>
<?php 
echo data_entry_helper::dump_errors($response, false);
?>
</div>
</body>
</html>
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/gpl.html.
 *
 * @package	Core
 * @subpackage Views
 * @author	Indicia Team
 * @license	http://www.gnu.org/licenses/gpl.html GPL
 * @link 	http://code.google.com/p/indicia/
 */
$id = html::initial_value($values, 'location_medium:id');
require_once DOCROOT . 'client_helpers/data_entry_helper.php';
require_once DOCROOT . 'client_helpers/form_helper.php';
if (isset($_POST)) {
    data_entry_helper::dump_errors(array('errors' => $this->model->getAllErrors()));
}
?>
<p>This page allows you to specify the details of an location media file.</p>
<form class="cmxform" action="<?php 
echo url::site() . 'location_medium/save';
?>
" method="post" 
      enctype="multipart/form-data" id="location-medium-edit">
<?php 
echo $metadata;
?>
<fieldset>
<?php 
echo data_entry_helper::hidden_text(array('fieldname' => 'location_medium:id', 'default' => $id));
echo data_entry_helper::hidden_text(array('fieldname' => 'location_medium:location_id', 'default' => html::initial_value($values, 'location_medium:location_id')));
Пример #6
0
    /**
     * 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(' ', '&nbsp;', 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(' ', '&nbsp;', lang::get('Verify')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, true, ' . $user->uid . '); return false;');
        $actions[] = array('caption' => str_replace(' ', '&nbsp;', lang::get('Reject')), 'javascript' => 'indicia_verify(\'{taxon}\', {occurrence_id}, false, ' . $user->uid . '); return false;');
        $actions[] = array('caption' => str_replace(' ', '&nbsp;', 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(' ', '&nbsp;', 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;
    }