/** * List of methods that assist with handling recording groups. * @package Client * @subpackage PrebuiltForms. */ function group_authorise_form($args, $readAuth) { if (!empty($args['limit_to_group_id']) && $args['limit_to_group_id'] !== (empty($_GET['group_id']) ? '' : $_GET['group_id'])) { // page owned by a different group, so throw them out hostsite_show_message(lang::get('This page is a private recording group page which you cannot access.'), 'alert'); hostsite_goto_page('<front>'); } if (!empty($_GET['group_id'])) { // loading data into a recording group. Are they a member or is the page public? // @todo: consider performance - 2 web services hits required to check permissions. if (hostsite_get_user_field('indicia_user_id')) { $gu = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id')), 'nocache' => true)); } else { $gu = array(); } $gp = data_entry_helper::get_population_data(array('table' => 'group_page', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'path' => drupal_get_path_alias($_GET['q'])))); if (count($gp) === 0) { hostsite_show_message(lang::get('You are trying to access a page which is not available for this group.'), 'alert'); hostsite_goto_page('<front>'); } elseif (count($gu) === 0 && $gp[0]['administrator'] !== NULL) { // not a group member, so throw them out hostsite_show_message(lang::get('You are trying to access a page for a group you do not belong to.'), 'alert'); hostsite_goto_page('<front>'); } } }
public static function link_to_parent($auth, $args, $tabalias, $options, $path) { if (empty($_GET['table']) || $_GET['table'] !== 'sample' || empty($_GET['id'])) { throw new exception('paths_editor.link_to_parent control needs to be called from a form that saves a sample'); } // construct a query to pull back the parent sample and any existing child samples in one go $samples = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('query' => json_encode(array('where' => array('id', $_GET['id']), 'orwhere' => array('parent_id', $_GET['id']))), 'view' => 'detail'), 'caching' => false)); $childGeoms = array(); $r = ''; foreach ($samples as $sample) { if ($sample['id'] === $_GET['id']) { // found the parent sample. Send to JS so it can be shown on the map data_entry_helper::$javascript .= "indiciaData.showParentSampleGeom = '{$sample['geom']}';\n"; $r = data_entry_helper::hidden_text(array('fieldname' => 'sample:date', 'default' => $sample['date_start'])); } else { // found an already input child sample $childGeoms[] = "'{$sample['geom']}'"; } } // Output some instructions to the user which will depend on whether we are on the first // child sample or not. if (!empty($options['outputInstructionsTo'])) { $instruct = empty($childGeoms) ? $options['firstInstructions'] : $options['otherInstructions']; data_entry_helper::$javascript .= "\$('#{$options['outputInstructionsTo']}').html('{$instruct}');\n"; } $childGeoms = implode(',', $childGeoms); data_entry_helper::$javascript .= "indiciaData.showChildSampleGeoms = [{$childGeoms}];\n"; $r .= data_entry_helper::hidden_text(array('fieldname' => 'sample:parent_id', 'default' => $_GET['id'])); 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']); 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; }
public static function site_description($auth, $args, $tabalias, $options, $path) { if (!empty($_GET[$options['urlParameter']])) { $locationCommentData = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('id' => $_GET[$options['urlParameter']], 'view' => 'detail'))); $r = '<div><h2>' . $locationCommentData[0]['name'] . '</h2><p>' . $locationCommentData[0]['comment'] . '</p></div>'; return $r; } }
/** * Return the generated form output. * @return Form HTML. * @todo: Implement this method */ public static function get_form($args) { global $user; $lang = isset($user) ? iform_lang_iso_639_2($user->lang) : 'eng'; if (function_exists('iform_load_helpers')) { iform_load_helpers(array('map_helper')); } else { require_once dirname(dirname(__FILE__)) . '/map_helper.php'; } $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $r = ''; // setup the map options $options = iform_map_get_map_options($args, $readAuth); $olOptions = iform_map_get_ol_options($args); if (array_key_exists('table', $_GET) && $_GET['table'] == 'sample') { // Use a cUrl request to get the data from Indicia which contains the value we need to filter against // Read the record that was just posted. $fetchOpts = array('dataSource' => 'reports_for_prebuilt_forms/my_dot_map/occurrences_list', 'mode' => 'report', 'readAuth' => $readAuth, 'extraParams' => array('sample_id' => $_GET['id'], 'language' => $lang)); // @todo Error handling on the response $occurrence = data_entry_helper::get_report_data($fetchOpts); self::prepare_layer_titles($args, $occurrence); // Add the 3 distribution layers if present. Reverse the order so 1st layer is topmost $layerName = self::build_distribution_layer(3, $args, $occurrence); if ($layerName) { $options['layers'][] = $layerName; } $layerName = self::build_distribution_layer(2, $args, $occurrence); if ($layerName) { $options['layers'][] = $layerName; } $layerName = self::build_distribution_layer(1, $args, $occurrence); if ($layerName) { $options['layers'][] = $layerName; } if ($layerName) { $options['layers'][] = $layerName; } // This is not a map used for input $options['editLayer'] = false; if ($args['hide_grid'] == false) { // Now output a grid of the occurrences that were just saved. $r .= "<table class=\"submission\"><thead><tr><th>" . lang::get('Species') . "</th><th>" . lang::get('Latin Name') . "</th><th>" . lang::get('Date') . "</th><th>" . lang::get('Spatial Ref') . "</th></tr></thead>\n"; $r .= "<tbody>\n"; foreach ($occurrence as $record) { $r .= '<tr class="biota"><td>' . $record['lt4_taxon'] . '</td><td class="binomial"><em>' . $record['lt7_taxon'] . '</em></td><td>' . $record['lt0_date_start'] . '</td><td>' . $record['lt0_entered_sref'] . "</td></tr>\n"; } $r .= "</tbody></table>\n"; } } $r .= '<div id="mapandlegend">'; $r .= map_helper::layer_list(array('id' => 'legend', 'includeSwitchers' => false, 'includeHiddenLayers' => false, 'includeIcons' => true, 'layerTypes' => array('overlay'))); $r .= map_helper::map_panel($options, $olOptions); $r .= '</div>'; return $r; }
/** * <p>Generates a flickr linked photo selector control. This requires a call to flickr_helper::auth * to have been made first and the user to have followed the login process to Flickr, otherwise a * normal image upload box will be displayed.<p> * <p>In order to get the flickr_select control working, you need to first obtain a Flickr API key from * http://www.flickr.com/services/api/. When you register for the key you will also be given a * "secret" - a second code that you need to supply to the Indicia data entry helpers. Once you * have the keys, go to your client_helpers/helper_config.php file and enter them into the $flickr_api_key * and $flickr_api_secret values.</p> * <p>In addition to specifying the api key and secret, you also need to tell Flickr where to * link to on your website after authenticating the user (the callback URL). There is a ready-made * PHP script in the Indicia code which you can use - client_helpers/flickr_auth.php. So, if your * code is running on a page at http://www.example.com/data_entry.php, with your client helpers * in a sub-folder, you will have a callback URL of http://www.example.com/client_helpers/flickr_auth.php. * You can list your API keys at http://www.flickr.com/services/api/keys/, then click the Edit key * details for the key you have registered. Now enter your callback URL in the respective field and * then save the key.</p> * * @param string $div_id Name and id of the div element that is generated. Defaults to Flickr. * @return string HTML to insert into the web-page for the Flickr control. */ public static function flickr_selector($div_id = 'flickr') { data_entry_helper::add_resource('flickr'); if (array_key_exists('phpFlickr_auth_token', $_SESSION) && !empty($_SESSION['phpFlickr_auth_token'])) { data_entry_helper::$javascript .= "(function(\$) {\n \$(document).ready(function(){\n \$('div#{$div_id}').indiciaFlickr();\n });\n })(jQuery);\n"; return '<div id="' . $div_id . '"></div>'; } else { require_once 'data_entry_helper.php'; // Flickr authentication failed. Output a normal image upload box. return "<label for='occurrence_image'>Image Upload:</label>\n" . data_entry_helper::image_upload('occurrence:image') . '<br/>'; } }
/** * Override the sensitivity control to create a simple select with default value * set by user profile. */ protected static function get_control_sensitivity($auth, $args, $tabAlias, $options) { // Obtain the default value for the user. global $user; $user = user_load($user->uid); $field_values = field_get_items('user', $user, 'field_icpveg_permission'); $default_value = $field_values[0]['value']; if ($default_value == 0) { // Where Drupal stores 0, we want the Warehouse field to be NULL to indicate // no blurring of detail. $default_value = ''; } return data_entry_helper::select(array_merge(array('fieldname' => 'occurrence:sensitivity_precision', 'label' => lang::get('ICPVeg Sensitivity'), 'lookupValues' => array('50000' => lang::get('ICPVeg Sensitivity 50km')), 'blankText' => lang::get('ICPVeg Sensitivity blankText'), 'default' => $default_value), $options)); }
/** * 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 (empty($_GET['group_id'])) { return 'This page needs a group_id URL parameter.'; } global $base_url; global $user; iform_load_helpers(array('data_entry_helper')); data_entry_helper::$javascript .= "indiciaData.nodeId=" . $node->nid . ";\n"; data_entry_helper::$javascript .= "indiciaData.baseUrl='" . $base_url . "';\n"; data_entry_helper::$javascript .= "indiciaData.currentUsername='******';\n"; //Translations for the comment that goes into occurrence_comments when a record is verified or rejected. data_entry_helper::$javascript .= 'indiciaData.verifiedTranslation = "' . lang::get('Verified') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.rejectedTranslation = "' . lang::get('Rejected') . "\";\n"; self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); group_authorise_form($args, self::$auth['read']); $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => self::$auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; hostsite_set_page_title("{$group['title']}: {$node->title}"); $def = json_decode($group['filter_definition'], true); $defstring = ''; // reconstruct this as a string to feed into dynamic report explorer foreach ($def as $key => $value) { if ($key) { $value = is_array($value) ? json_encode($value) : $value; $defstring .= "{$key}={$value}\n"; if ($key === 'indexed_location_id' || $key === 'indexed_location_list' || $key === 'location_id' || $key === 'location_list') { $args['location_boundary_id'] = $value; } elseif (($key === 'taxon_group_id' || $key === 'taxon_group_list') && strpos($value, ',') === FALSE) { // if the report is locked to a single taxon group, then we don't need taxonomy columns. $args['skipped_report_columns'] = array('taxon_group', 'taxonomy'); } } } if (empty($_GET['implicit'])) { // no need for a group user filter $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring)); } else { // filter to group users - either implicitly, or only if they explicitly submitted to the group $prefix = $_GET['implicit'] === 'true' || $_GET['implicit'] === 't' ? 'implicit_' : ''; // add the group parameters to the preset parameters passed to all reports on this page $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring, "{$prefix}group_id=" . $_GET['group_id'])); } $args['param_presets'] .= "\n"; if (!empty($args['hide_standard_param_filter'])) { data_entry_helper::$javascript .= "\$('#standard-params').hide();\n"; } return parent::get_form($args, $node); }
/** * List of methods that can be used for a prebuilt form control generation. * @package Client * @subpackage PrebuiltForms. * @param array $attributes * @param array $args * @param array $defAttrOptions * @param array $outerFilter * @param array $blockOptions Associative array of control names that have non-default options. Each entry * is keyed by the control name and has an array of the options and values to override. * @param array $idPrefix Optional prefix to give to IDs (e.g. for fieldsets) to allow you to ensure they remain unique. */ function get_attribute_html($attributes, $args, $defAttrOptions, $outerFilter = null, $blockOptions = null, $idPrefix = '') { $lastOuterBlock = ''; $lastInnerBlock = ''; $r = ''; foreach ($attributes as $attribute) { // Apply filter to only output 1 block at a time. Also hide controls that have already been handled. if (($outerFilter === null || strcasecmp($outerFilter, $attribute['outer_structure_block']) == 0) && !isset($attribute['handled'])) { if (empty($outerFilter) && $lastOuterBlock != $attribute['outer_structure_block']) { if (!empty($lastInnerBlock)) { $r .= '</fieldset>'; } if (!empty($lastOuterBlock)) { $r .= '</fieldset>'; } if (!empty($attribute['outer_structure_block'])) { $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['outer_structure_block']) . '</legend>'; } if (!empty($attribute['inner_structure_block'])) { $r .= '<fieldset id="' . get_fieldset_id($attribute['outer_structure_block'], $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>'; } } elseif ($lastInnerBlock != $attribute['inner_structure_block']) { if (!empty($lastInnerBlock)) { $r .= '</fieldset>'; } if (!empty($attribute['inner_structure_block'])) { $r .= '<fieldset id="' . get_fieldset_id($lastOuterBlock, $attribute['inner_structure_block'], $idPrefix) . '"><legend>' . lang::get($attribute['inner_structure_block']) . '</legend>'; } } $lastInnerBlock = $attribute['inner_structure_block']; $lastOuterBlock = $attribute['outer_structure_block']; $options = $defAttrOptions + get_attr_validation($attribute, $args); if (isset($blockOptions[$attribute['fieldname']])) { $options = array_merge($options, $blockOptions[$attribute['fieldname']]); } $r .= data_entry_helper::outputAttribute($attribute, $options); $attribute['handled'] = true; } } if (!empty($lastInnerBlock)) { $r .= '</fieldset>'; } if (!empty($lastOuterBlock) && strcasecmp($outerFilter, $lastOuterBlock) !== 0) { $r .= '</fieldset>'; } 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) { iform_load_helpers(array('import_helper')); $auth = import_helper::get_read_write_auth($args['website_id'], $args['password']); group_authorise_form($args, $auth['read']); if ($args['model'] == 'url') { if (!isset($_GET['type'])) { return "This form is configured so that it must be called with a type parameter in the URL"; } $model = $_GET['type']; } else { $model = $args['model']; } if (isset($args['presetSettings'])) { $presets = get_options_array_with_user_data($args['presetSettings']); $presets = array_merge(array('website_id' => $args['website_id'], 'password' => $args['password']), $presets); } else { $presets = array('website_id' => $args['website_id'], 'password' => $args['password']); } if (!empty($_GET['group_id'])) { // loading data into a recording group. $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; $presets['sample:group_id'] = $_GET['group_id']; hostsite_set_page_title(lang::get('Import data into the {1} group', $group['title'])); // if a single survey specified for this group, then force the data into the correct survey $filterdef = json_decode($group['filter_definition'], true); if (!empty($filterdef['survey_list_op']) && $filterdef['survey_list_op'] === 'in' && !empty($filterdef['survey_list'])) { $surveys = explode(',', $filterdef['survey_list']); if (count($surveys) === 1) { $presets['survey_id'] = $surveys[0]; } } } try { $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets)); } catch (Exception $e) { hostsite_show_message($e->getMessage(), 'warning'); $reload = import_helper::get_reload_link_parts(); unset($reload['params']['total']); unset($reload['params']['uploaded_csv']); $reloadpath = $reload['path'] . '?' . import_helper::array_to_query_string($reload['params']); $r = "<p>" . lang::get('Would you like to ') . "<a href=\"{$reloadpath}\">" . lang::get('import another file?') . "</a></p>"; } return $r; }
public function register() { try { $this->authenticate('write'); self::string_validate_mandatory('email'); self::string_validate_mandatory('surname'); self::int_key_validate_mandatory('website_id'); self::boolean_validate('alert_on_entry'); self::boolean_validate('alert_on_verify'); self::int_key_validate('location_id'); if (!empty($_GET['user_id'])) { $userId = $_GET['user_id']; } else { // User was not logged in when subscribing, so use their details to find or create a warehouse user id. $emailIdentifierObject = new stdClass(); $emailIdentifierObject->type = "email"; $emailIdentifierObject->identifier = $_GET["email"]; $userIdentificationData['identifiers'] = json_encode(array($emailIdentifierObject)); //Also pass through these fields so if a new user is required then the system can fill in the database details $userIdentificationData['surname'] = $_GET["surname"]; $userIdentificationData['first_name'] = $_GET["first_name"]; //Call existing user identifier code that will either fetch an existing user for that email, or create a new one. $userDetails = user_identifier::get_user_id($userIdentificationData, $_GET["website_id"]); if (!empty($userDetails['userId'])) { $userId = $userDetails['userId']; } else { $userId = $userDetails['possibleMatches'][0]['user_id']; } } //Store the species alert for the user (which is either a new or existing user as determined by get_user_id) self::store_species_alert($userId); //Automatically register the user to receive email notifications if they have never had any settings at all try { $readAuth = data_entry_helper::get_read_auth(0 - $userId, kohana::config('indicia.private_key')); $freqSettingsData = data_entry_helper::get_report_data(array('dataSource' => 'library/user_email_notification_settings/user_email_notification_settings_inc_deleted', 'readAuth' => $readAuth, 'extraParams' => array('user_id' => $userId))); if (empty($freqSettingsData)) { self::store_user_email_notification_setting($userId); } } catch (exception $e) { kohana::log('debug', "Unable to register user " . $userId . " for email notifications, perhaps that module is not installed?."); } } catch (Exception $e) { $this->handle_error($e); } }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { if (empty($_GET['occurrence_id'])) { return 'This form requires an occurrence_id parameter in the URL.'; } $r = "<form method=\"post\">\n"; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); data_entry_helper::load_existing_record($auth['read'], 'occurrence', $_GET['occurrence_id']); data_entry_helper::load_existing_record($auth['read'], 'sample', data_entry_helper::$entity_to_load['occurrence:sample_id']); $r .= $auth['write']; $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . $_GET['occurrence_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"occurrence:sample_id\" name=\"occurrence:sample_id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; $r .= "<div id=\"controls\">\n"; $r .= "<table>\n"; $r .= "<tr><td><strong>Date</strong></td><td>" . data_entry_helper::$entity_to_load['sample:date'] . "</td></tr>\n"; $r .= "<tr><td><strong>Spatial Reference</strong></td><td>" . data_entry_helper::$entity_to_load['sample:entered_sref'] . "</td></tr>\n"; $siteLabels = array(); if (!empty(data_entry_helper::$entity_to_load['sample:location'])) { $siteLabels[] = data_entry_helper::$entity_to_load['sample:location']; } if (!empty(data_entry_helper::$entity_to_load['sample:location_name'])) { $siteLabels[] = data_entry_helper::$entity_to_load['sample:location_name']; } $r .= "<tr><td><strong>Site</strong></td><td>" . implode(' | ', $siteLabels) . "</td></tr>\n"; $smpAttrs = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'extraParams' => $auth['read'], 'survey_id' => data_entry_helper::$entity_to_load['occurrence:survey_id'])); $occAttrs = data_entry_helper::getAttributes(array('id' => $_GET['occurrence_id'], 'valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'extraParams' => $auth['read'], 'survey_id' => data_entry_helper::$entity_to_load['occurrence:survey_id'])); $attributes = array_merge($smpAttrs, $occAttrs); foreach ($attributes as $attr) { $r .= "<tr><td><strong>" . $attr['caption'] . "</strong></td><td>" . $attr['displayValue'] . "</td></tr>\n"; } $extraParams = $auth['read'] + array('taxon_list_id' => $args['list_id']); if ($args['preferred']) { $extraParams += array('preferred' => 't'); } $species_list_args = array('itemTemplate' => 'select_species', 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'extraParams' => $extraParams); // Dynamically generate the species selection control required. $r .= '<tr/><td><strong>Species</strong></td><td>' . call_user_func(array('data_entry_helper', $args['species_ctrl']), $species_list_args) . "</td></tr>\n"; $r .= "</table>\n"; $r .= "</div>\n"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; $r .= "</form>"; return $r; }
public function breadcrumb($auth, $args, $tabalias, $options) { global $base_url; $breadCrumbLocationNamesArray = array(); //The location ids to display in the breadcrumb are held in the URL if the user //is returning from another page. $breadCrumbLocationIdsArray = explode(',', $_GET['breadcrumb']); $locationRecords = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'], 'nocache' => true)); //Get the names associated with the ids foreach ($breadCrumbLocationIdsArray as $breadCrumbLocationId) { foreach ($locationRecords as $locationRecord) { if ($locationRecord['id'] === $breadCrumbLocationId) { $breadCrumbLocationNamesArray[] = $locationRecord['name']; } } } $r = ''; //Only display links to homepage if we have links to show if (!empty($breadCrumbLocationNamesArray)) { $r .= '<label><h4>Links to homepage</h4></label></br>'; $r .= '<div>'; $r .= '<ul id="homepage-breadcrumb">'; //Loop through the links to show foreach ($breadCrumbLocationNamesArray as $num => $breadCrumbLocationName) { //For each link back to the homepage, we need to give the homepage some locations IDs to rebuild //its breadcrumb with. So we need to include ids of any locations that are "above" the location we are linking back with. //e.g. If the link is for Guildford, then we would need to supply the ids for Guildford, Surrey and South England //as well to the homepage can make a full breadcrumb trail to guildford. if (empty($breadCrumbParamToSendBack)) { $breadCrumbParamToSendBack = 'breadcrumb=' . $breadCrumbLocationIdsArray[$num]; } else { $breadCrumbParamToSendBack .= ',' . $breadCrumbLocationIdsArray[$num]; } $r .= '<li id="breadcrumb-part-"' . $num . '>'; //The breadcrumb link is a name, with a url back to the homepage containing ids for the homepage //to show in its breadcrumb $r .= '<a href="' . $base_url . (variable_get('clean_url', 0) ? '' : '?q=') . $options['homepage_path'] . (variable_get('clean_url', 0) ? '?' : '&') . $breadCrumbParamToSendBack . '">' . $breadCrumbLocationName . '<a>'; $r .= '</li>'; } $r .= '</ul></div>'; } return $r; }
/** * Define the HTML required for this filter's UI panel. */ public function get_controls() { $r = '<div class="context-instruct messages warning">' . lang::get('Please note, you cannnot change this setting because of your access permissions in this context.') . '</div>'; $r .= data_entry_helper::checkbox(array('label' => lang::get('Only include my records'), 'fieldname' => 'my_records')); $vocabulary = taxonomy_vocabulary_machine_name_load('hubs'); $terms = entity_load('taxonomy_term', FALSE, array('vid' => $vocabulary->vid)); // the hub is driven by a user field, stored as tid. $r .= '<fieldset><legend>' . lang::get('Members of Hub:') . '</legend>'; $r .= "<p id=\"who-hub-instruct\">" . lang::get('Please note that this converts each Hub into a list of users associated with the Hub, and fetches the data created by those users.') . "</p>\n"; $hubList = array(); foreach ($terms as $term) { $hubList[] = array($term->tid, $term->name); // TODO Cache $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'user')->fieldCondition('field_preferred_training_hub', 'tid', $term->tid); $result = $query->execute(); // This gives us the CMS user ID: now convert to $userIDList = array(); if (count($result) == 0) { $userIDList = array(-1); } else { $cmsUserIDs = array_keys($result['user']); foreach ($cmsUserIDs as $cmsUserID) { $user_data = user_load($cmsUserID); // TODO Making assumption about language if (!empty($user_data->field_indicia_user_id['und'][0]['value'])) { $userIDList[] = $user_data->field_indicia_user_id['und'][0]['value']; } } if (count($userIDList) == 0) { $userIDList = array(-1); } } $userIDList = array_unique($userIDList); data_entry_helper::$javascript .= "indiciaData.hub" . $term->tid . " = '" . implode(',', $userIDList) . "';\n"; $r .= data_entry_helper::checkbox(array('label' => $term->name, 'fieldname' => 'hub' . $term->tid, 'helpText' => ($userIDList[0] == -1 ? 'No' : count($userIDList)) . lang::get(' users.'))); } data_entry_helper::$javascript .= "indiciaData.hubList = " . json_encode($hubList) . ";\n"; $r .= '</fieldset>'; return $r; }
/** * 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 (empty($_GET['group_id'])) { return 'This page needs a group_id URL parameter.'; } self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => self::$auth['read'] + array('id' => $_GET['group_id']))); $group = $group[0]; hostsite_set_page_title($group['title']); $filter = data_entry_helper::get_population_data(array('table' => 'filter', 'extraParams' => self::$auth['read'] + array('id' => $group['filter_id']))); $filter = $filter[0]; $def = json_decode($filter['definition'], true); $defstring = ''; // reconstruct this as a string to feed into dynamic report explorer foreach ($def as $key => $value) { if ($key) { $defstring .= "{$key}={$value}\n"; } } // add the group parameters to the preset parameters passed to all reports on this page $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring, "group_id=" . $_GET['group_id'])); return parent::get_form($args, $node); }
/** * Clears moderation notifications for a moderator automatically on visiting the page, so then they * will get notified about new incoming records. */ public static function clear_moderation_task_notifications($auth, $args, $tabalias, $options, $path) { //Using 'submission_list' and 'entries' allows us to specify several top-level submissions to the system //i.e. we need to be able to submit several notifications. $submission['submission_list']['entries'] = array(); $submission['id'] = 'notification'; $notifications = data_entry_helper::get_population_data(array('table' => 'notification', 'extraParams' => $auth['read'] + array('acknowledged' => 'f', 'user_id' => hostsite_get_user_field('indicia_user_id'), 'source_type' => 'PT'), 'nocache' => true)); if (count($notifications) > 0) { $auth = data_entry_helper::get_read_write_auth(variable_get('indicia_website_id', 0), variable_get('indicia_password', '')); //Setup the structure we need to submit. foreach ($notifications as $notification) { $data['id'] = 'notification'; $data['fields']['id']['value'] = $notification['id']; $data['fields']['acknowledged']['value'] = 't'; $submission['submission_list']['entries'][] = $data; } //Submit the stucture for processing $response = data_entry_helper::forward_post_to('save', $submission, $auth['write_tokens']); if (!is_array($response) || !array_key_exists('success', $response)) { drupal_set_message(print_r($response, true)); } } return ''; }
/** * Adds a vector to the map for a particular location, and zooms into it. */ function iform_map_zoom_to_location($locationId, $readAuth) { $getPopDataOpts = array('table' => 'location', 'extraParams' => $readAuth + array('id' => $locationId, 'view' => 'detail')); $response = data_entry_helper::get_population_data($getPopDataOpts); $geom = $response[0]['boundary_geom'] ? $response[0]['boundary_geom'] : $response[0]['centroid_geom']; iform_map_zoom_to_geom($geom, lang::get('{1} boundary', $response[0]['name'])); }
/** * Returns a list of hidden inputs which are extracted from the form attributes which can be extracted * from the user's profile information in Drupal. The attributes which are used are marked as handled * so they don't need to be output elsewhere on the form. This function also handles non-profile based * CMS User ID, Username, and Email; and also special processing for names. * @param array $attributes List of form attributes. * @param array $args List of form arguments. Can include values called: * copyFromProfile - boolean indicating if values should be copied from the profile when the names match * nameShow - boolean, if true then name values should be displayed rather than hidden. * In fact this extends to all profile fields whose names match attribute * captions. E.g. in D7, field_age would populate an attribute with caption * age. * emailShow - boolean, if true then email values should be displayed rather than hidden. * @param boolean $exists Pass true for an existing record. If the record exists, then the attributes * are marked as handled but are not output to avoid overwriting metadata about the original creator of the record. * @param array $readAuth Read authorisation tokens. * @return string HTML for the hidden inputs. */ function get_user_profile_hidden_inputs(&$attributes, $args, $exists, $readAuth) { // This is Drupal specific code global $user; $logged_in = $user->uid > 0; // If the user is not logged in there is no profile so return early. if (!$logged_in) { return ''; } $hiddens = ''; $version6 = substr(VERSION, 0, 1) == '6'; if ($version6) { // In version 6 the profile module holds user setttings. // but may not be using profile module, but still need to proceed to handle CMS User ID etc. if (function_exists('profile_load_all_profile')) { // D6 specific profile_load_all_profile($user); } } else { // In version 7, the field module holds user settings. $user = user_load($user->uid); } foreach ($attributes as &$attribute) { // Constuct the name of the user property (which varies between versions) to match against the attribute caption. $attrPropName = ($version6 ? 'profile_' : 'field_') . strtolower(str_replace(' ', '_', $attribute['caption'])); if (isset($user->{$attrPropName}) && isset($args['copyFromProfile']) && $args['copyFromProfile'] == true) { // Obtain the property value which is stored differently between versions. if ($version6) { $attrPropValue = $user->{$attrPropName}; } else { $attrPropValues = field_get_items('user', $user, $attrPropName); $attrPropValue = isset($attrPropValues[0]['safe value']) ? $attrPropValues[0]['safe value'] : $attrPropValues[0]['value']; } // lookups need to be translated to the termlist_term_id, unless they are already IDs if ($attribute['data_type'] === 'L' && !preg_match('/^[\\d]+$/', $attrPropValue)) { $terms = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $readAuth + array('termlist_id' => $attribute['termlist_id'], 'term' => $attrPropValue))); $value = count($terms) > 0 ? $terms[0]['id'] : ''; } else { $value = $attrPropValue; } if (isset($args['nameShow']) && $args['nameShow'] == true) { // Show the attribute with default value. $attribute['default'] = $value; } else { // Hide the attribute value $attribute['handled'] = true; $attribute['value'] = $value; } } elseif (strcasecmp($attribute['caption'], 'cms user id') == 0) { $attribute['value'] = $user->uid; $attribute['handled'] = true; // user id attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'cms username') == 0) { $attribute['value'] = $user->name; $attribute['handled'] = true; // username attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'email') == 0) { if (isset($args['emailShow']) && $args['emailShow'] == true) { // Show the email attribute with default value. $attribute['default'] = $user->mail; } else { // Hide the email value $attribute['value'] = $user->mail; $attribute['handled'] = true; } } elseif (strcasecmp($attribute['caption'], 'first name') == 0 || strcasecmp($attribute['caption'], 'last name') == 0 || strcasecmp($attribute['caption'], 'surname') == 0) { // This would be the case where the warehouse is configured to store these // values but there are no matching profile fields if (!isset($args['nameShow']) || $args['nameShow'] != true) { // Name attributes are not displayed because we have the users login. $attribute['handled'] = true; } } // If we have a value for one of the user login attributes then we need to // output this value. BUT, for existing data we must not overwrite the user // who created the record. Note that we don't do this at the beginning of // the method as we still wanted to mark the attributes as handled. if (isset($attribute['value']) && !$exists) { $hiddens .= '<input type="hidden" name="' . $attribute['fieldname'] . '" value="' . $attribute['value'] . '" />' . "\n"; } } return $hiddens; }
/** * Gets a taxon name from a Meaning ID. * * @param int $meaningId The map layer we are preparing. * @param array $readAuth Read authentication. * @return The taxon name. */ private static function get_taxon($meaningId, $readAuth) { global $user; $fetchOpts = array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + array('view' => 'detail', 'language_iso' => iform_lang_iso_639_2(hostsite_get_user_field('language')), 'taxon_meaning_id' => $meaningId)); $taxonRecords = data_entry_helper::get_population_data($fetchOpts); return $taxonRecords[0]['taxon']; }
/** * Ajax method to proxy requests for bulk verification on to the warehouse, attaching write auth * as it goes. */ public static function ajax_bulk_verify($website_id, $password) { iform_load_helpers(array('data_entry_helper')); $auth = data_entry_helper::get_read_write_auth($website_id, $password); $url = data_entry_helper::$base_url . "index.php/services/data_utils/bulk_verify"; $params = array_merge($_POST, $auth['write_tokens']); $response = data_entry_helper::http_post($url, $params); echo $response['output']; }
/** * Return the generated output for the media grid tab. * @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 object $auth The full read-write authorisation. * @return HTML. */ private static function get_media_tab($args, $nid, $auth) { global $user; data_entry_helper::add_resource('fancybox'); data_entry_helper::add_resource('plupload'); data_entry_helper::add_resource('jquery_ui'); $limit1 = $args['sample_attribute_id_1_limit']; $limit2 = $args['sample_attribute_id_2_limit']; if (!isset($args['sample_attribute_id_2']) || $args['sample_attribute_id_2'] == "") { $limit2 = 1; $caption2 = ""; } else { $caption2 = $attributesIdx[$args['sample_attribute_id_2']]['caption']; } $attributesIdx = data_entry_helper::getAttributes(array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $args['quadrat_level_sample_method_id'], 'multiValue' => false)); $scd = isset($args['site_caption_differentiator']) && $args['site_caption_differentiator'] != "" ? explode(',', $args['site_caption_differentiator']) : array('1'); $qcd = isset($args['quadrat_caption_differentiator']) && $args['quadrat_caption_differentiator'] != "" ? explode(',', $args['quadrat_caption_differentiator']) : array('1'); $bumpf = isset($args['media_tab_bumpf']) && $args['media_tab_bumpf'] != "" ? $args['media_tab_bumpf'] : lang::get('Please use the caption field to indicate whether the image is of a particular ' . (count($qcd) > 1 ? 'aspect of a ' : '') . $attributesIdx[$args['sample_attribute_id_1']]['caption'] . ', or the shore/site.') . ' ' . lang::get('When you start typing you should see a set of appropriate options from which you can choose: this will guide you to enter the correct value and format. Alternative just pressing the down arrow key should give the full list.'); // 'description'=>'Format is <x>:<n>=<txt>:<n>=<txt>[,<x>:<n>=<txt>:<n>=<txt>] where <x> is the attribute id, <n> is the attribute value, and <txt> is the replacement value to be used in the template.', $mappings = isset($args['quadrat_caption_attribute_mapping']) ? explode(',', $args['quadrat_caption_attribute_mapping']) : array(); $mappingsList = array(); foreach ($mappings as $mapping) { $parts = explode(':', $mapping); $map = array(); for ($i = 1; $i < count($parts); $i++) { // skip first $map[] = explode('=', $parts[$i]); } $mappingsList['attr' . $parts[0]] = $map; } data_entry_helper::$javascript .= "indiciaData.limit1={$limit1};\r\nindiciaData.site_caption_template='" . (isset($args['site_caption_template']) ? $args['site_caption_template'] : 'Site') . "';\r\nindiciaData.site_caption_differentiator=" . json_encode($scd) . ";\r\nindiciaData.limit2={$limit2};\r\nindiciaData.quadrat_caption_template='" . str_replace(array('{caption1}', '{caption2}'), array($attributesIdx[$args['sample_attribute_id_1']]['caption'], $caption2), isset($args['quadrat_caption_template']) ? $args['quadrat_caption_template'] : '{caption1} {N1}') . "';\r\nindiciaData.quadrat_caption_differentiator=" . json_encode($qcd) . ";\r\nindiciaData.quadrat_caption_attribute_mapping=" . json_encode($mappingsList) . ";\r\n"; $r = '<div id="media">' . '<p class="ui-state-highlight page-notice ui-corner-all">' . $bumpf . '<span style="display:none;">' . 'MEM:' . ini_get('memory_limit') . ' FILE:' . ini_get('upload_max_filesize') . ' POST:' . ini_get('post_max_size') . '</span>' . '<br/>' . lang::get('The maximum number of files you can upload is ') . (count($scd) + count($qcd) * $limit1 * $limit2) . '. The maximum filesize you can upload is 4M - the images will be resized to a maximum of 1500 pixels high or wide, to ensure this is the case.' . '.<p>' . data_entry_helper::file_box(array('table' => 'sample_medium', 'caption' => lang::get('Photos'), 'codeGenerated' => 'all', 'maxFileCount' => count($scd) + count($qcd) * $limit1 * $limit2, 'file_box_uploaded_extra_fieldsTemplate' => '<input type="hidden" name="{idField}" id="{idField}" value="{idValue}" />' . '<input type="hidden" name="{pathField}" id="{pathField}" value="{pathValue}" />' . '<input type="hidden" name="{typeField}" id="{typeField}" value="{typeValue}" />' . '<input type="hidden" name="{typeNameField}" id="{typeNameField}" value="{typeNameValue}" />' . '<input type="hidden" name="{deletedField}" id="{deletedField}" value="{deletedValue}" class="deleted-value" />' . '<input type="hidden" id="{isNewField}" value="{isNewValue}" />' . '<label for="{captionField}">Caption:</label><br/><input type="text" list="captions" maxlength="100" style="width: {imagewidth}px" name="{captionField}" id="{captionField}" value="{captionValue}"/>', 'resizeWidth' => '1500', 'resizeHeight' => '1500')) . (self::$readOnly ? '' : '<br/><input type="submit" value="' . lang::get('Save') . '" title="' . lang::get('Saves any data entered across all the tabs.') . '" />') . '<datalist id="captions"></datalist>' . '</div>'; $typeTermData = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $auth['read'] + array('view' => 'cache', 'termlist_title' => 'Media types', 'columns' => 'id,term'))); $typeTermIdLookup = array(); foreach ($typeTermData as $record) { $typeTermIdLookup[$record['term']] = $record['id']; } data_entry_helper::$javascript .= "indiciaData.mediaTypeTermIdLookup=" . json_encode($typeTermIdLookup) . ";\n"; 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; }
/** * Handles the construction of a submission array from a set of form values. * @param array $values Associative array of form data values. * @param array $args iform parameters. * @return array Submission structure. */ public static function get_submission($values, $args) { return data_entry_helper::build_sample_occurrences_list_submission($values); }
/** * Load the attributes for the sample defined by a supplied Id. */ private static function getAttributesForSample($args, $auth, $id) { $attrOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); if (!empty($id)) { $attrOpts['id'] = $id; } // select only the custom attributes that are for this sample method or all sample methods, if this // form is for a specific sample method. if (!empty($args['sample_method_id'])) { $attrOpts['sample_method_id'] = $args['sample_method_id']; } $attributes = data_entry_helper::getAttributes($attrOpts, false); return $attributes; }
/** * Outputs a pair of linked selects, for picking a prebuilt form from the library. The first select is for picking a form * category and the second select is populated by AJAX for picking the actual form. * @param array $options Options array with the following possibilities:<ul> * <li><b>form</b><br/> * Optional. The name of the form to select as a default value.</li> * <li><b>includeOutputDiv</b><br/> * Set to true to generate a div after the controls which will receive the form parameter * controls when a form is selected.</li> * <li><b>needWebsiteInputs</b><br/> * Defaults to false. In this state, the website ID and password controls are not displayed * when both the values are already specified, though hidden inputs are put into the form. * When set to true, the website ID and password input controls are always included in the form output. * </li> * </ul> */ public static function prebuilt_form_picker($options) { require_once 'data_entry_helper.php'; form_helper::add_resource('jquery_ui'); $path = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . self::relative_client_helper_path(); $r = ''; if (!($dir = opendir($path . 'prebuilt_forms/'))) { throw new Exception('Cannot open path to prebuilt form library.'); } while (false !== ($file = readdir($dir))) { $parts = explode('.', $file); if ($file != "." && $file != ".." && strtolower($parts[count($parts) - 1]) == 'php') { require_once $path . 'prebuilt_forms/' . $file; $file_tokens = explode('.', $file); ob_start(); if (is_callable(array('iform_' . $file_tokens[0], 'get_' . $file_tokens[0] . '_definition'))) { $definition = call_user_func(array('iform_' . $file_tokens[0], 'get_' . $file_tokens[0] . '_definition')); $definition['title'] = lang::get($definition['title']); $forms[$definition['category']][$file_tokens[0]] = $definition; if (isset($options['form']) && $file_tokens[0] == $options['form']) { $defaultCategory = $definition['category']; } } elseif (is_callable(array('iform_' . $file_tokens[0], 'get_title'))) { $title = call_user_func(array('iform_' . $file_tokens[0], 'get_title')); $forms['Miscellaneous'][$file_tokens[0]] = array('title' => $title); if (isset($options['form']) && $file_tokens[0] == $options['form']) { $defaultCategory = 'Miscellaneous'; } } ob_end_clean(); } } if (isset($defaultCategory)) { $availableForms = array(); foreach ($forms[$defaultCategory] as $form => $def) { $availableForms[$form] = $def['title']; } } else { $defaultCategory = ''; $availableForms = array('' => '<Please select a category first>'); } closedir($dir); // makes an assoc array from the categories. $categories = array_merge(array('' => '<Please select>'), array_combine(array_keys($forms), array_keys($forms))); // translate categories foreach ($categories as $key => &$value) { $value = lang::get($value); } asort($categories); if (isset($options['needWebsiteInputs']) && !$options['needWebsiteInputs'] && !empty($options['website_id']) && !empty($options['password'])) { $r .= '<input type="hidden" id="website_id" name="website_id" value="' . $options['website_id'] . '">'; $r .= '<input type="hidden" id="password" name="password" value="' . $options['password'] . '">'; } else { $r .= data_entry_helper::text_input(array('label' => lang::get('Website ID'), 'fieldname' => 'website_id', 'helpText' => lang::get('Enter the ID of the website record on the Warehouse you are using.'), 'default' => isset($options['website_id']) ? $options['website_id'] : '')); $r .= data_entry_helper::text_input(array('label' => lang::get('Password'), 'fieldname' => 'password', 'helpText' => lang::get('Enter the password for the website record on the Warehouse you are using.'), 'default' => isset($options['password']) ? $options['password'] : '')); } $r .= data_entry_helper::select(array('id' => 'form-category-picker', 'label' => lang::get('Select Form Category'), 'helpText' => lang::get('Select the form category pick a form from.'), 'lookupValues' => $categories, 'default' => $defaultCategory)); $r .= data_entry_helper::select(array('id' => 'form-picker', 'fieldname' => 'iform', 'label' => lang::get('Select Form'), 'helpText' => lang::get('Select the Indicia form you want to use.'), 'lookupValues' => $availableForms, 'default' => isset($options['form']) ? $options['form'] : '')); // div for the form instructions $details = ''; if (isset($options['form'])) { if (isset($forms[$defaultCategory][$options['form']]['description'])) { $details .= '<p>' . $forms[$defaultCategory][$options['form']]['description'] . '</p>'; } if (isset($forms[$defaultCategory][$options['form']]['helpLink'])) { $details .= '<p><a href="' . $forms[$defaultCategory][$options['form']]['helpLink'] . '">Find out more...</a></p>'; } if ($details !== '') { $details = "<div class=\"ui-state-highlight ui-corner-all page-notice\">{$details}</div>"; } } $r .= "<div id=\"form-def\">{$details}</div>\n"; $r .= '<input type="button" value="' . lang::get('Load Settings Form') . '" id="load-params" disabled="disabled" />'; if (isset($options['includeOutputDivs']) && $options['includeOutputDivs']) { $r .= '<div id="form-params"></div>'; } self::add_form_picker_js($forms); return $r; }
private static function do_data_services_download($args, $format) { iform_load_helpers(array('report_helper')); $conn = iform_get_connection_details($node); $readAuth = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']); if (preg_match('/^library\\/occurrences\\/filterable/', $args["report_{$format}"])) { $filter = self::build_filter($args, $readAuth, $format, true); } else { $filter = self::build_filter($args, $readAuth, $format, false); } global $indicia_templates; // let's just get the URL, not the whole anchor element $indicia_templates['report_download_link'] = '{link}'; $limit = $args['limit'] == 0 ? '' : $args['limit']; // unlimited or limited $sharing = preg_match('/^expert/', $_POST['user-filter']) ? 'verification' : 'data_flow'; $url = report_helper::report_download_link(array('readAuth' => $readAuth, 'dataSource' => $args["report_{$format}"], 'extraParams' => $filter, 'format' => $format, 'sharing' => $sharing, 'itemsPerPage' => $limit)); header("Location: {$url}"); }
/** * Handles the construction of a submission array from a set of form values. * For example, the following represents a submission structure for a simple * sample and 1 occurrence submission * return data_entry_helper::build_sample_occurrence_submission($values); * @param array $values Associative array of form data values. * @param array $args iform parameters. * @return array Submission structure. * @todo: Implement this method */ public static function get_submission($values, $args) { if (!isset($values['page']) || $values['page'] != 'grid') { // submitting the first page, with top level sample details if (!isset($values['sample:entered_sref'])) { // the sample does not have sref data, as the user has just picked a transect site at this point. Copy the // site's centroid across to the sample. $read = array('nonce' => $values['read_nonce'], 'auth_token' => $values['read_auth_token']); $site = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $read + array('view' => 'detail', 'id' => $values['sample:location_id'], 'deleted' => 'f'))); $site = $site[0]; $values['sample:entered_sref'] = $site['centroid_sref']; $values['sample:entered_sref_system'] = $site['centroid_sref_system']; } } $submission = submission_builder::build_submission($values, array('model' => 'sample')); return $submission; }
/** * Given a reject response, delete the invite, and redirect to the groups home page. * @param array $args Form config arguments * @param array $invite Invitation record */ private static function reject($args, $invite, $auth) { $values = array('id' => $invite['id'], 'deleted' => 't'); $s = submission_builder::build_submission($values, array('model' => 'group_invitation')); $r = data_entry_helper::forward_post_to('group_invitation', $s, $auth['write_tokens']); hostsite_show_message(lang::get("OK, thanks anyway. We've removed your invitation to join this group.")); hostsite_goto_page($args['groups_page_path']); }
/** * Ouputs a hidden date control set to the current date. * The output of this control can be configured using the following templates: * <ul> * <li><b>hidden_text</b></br> * Template used for the for hidden inputs. * </ul> * * * @param array $options Options array with the following possibilities:<ul> * <li><b>fieldname</b><br/> * Required. The name of the database field this control is bound to. * Default 'sample:date'.</li> * <li><b>id</b><br/> * Optional. The id to assign to the HTML control. If not assigned the * fieldname is used.</li> * <li><b>default</b><br/> * Optional. The default value to assign to the control. This is overridden * when reloading a record with existing data for this control.</li> * </ul> * * @return string HTML to insert into the page for the date picker control. */ public static function date_now($options, $hidden = NULL) { $r = ""; $options = self::check_options($options); $options = array_merge(array('fieldname' => 'sample:date', 'default' => '0'), $options); $id = isset($options['id']) ? $options['id'] : $options['fieldname']; $options['id'] = $id; $id = self::jq_esc($id); // JavaScript to obtain the date value; self::$javascript .= "\n (function (\$) {\n // Calculate date string\n var d = new Date();\n var day = d.getDate();\n day = ((day < 10) ? '0' : '') + day\n var month = d.getMonth() + 1;\n month = ((month < 10) ? '0' : '') + month\n var year = d.getFullYear()\n var date = year + '-' + month + '-' + day;\n \n \$('#{$id}').attr('value', date);\n }) (jqm);\n "; // HTML which will accept the date value if (is_null($hidden) || $hidden) { $r .= self::hidden_text($options); } else { $r .= data_entry_helper::apply_template('jqmDate', $options); } return $r; }
/** * Get the observer control as an autocomplete. */ protected static function get_control_observerautocomplete($auth, $args, $tabAlias, $options) { global $user; //Get the name of the currently logged in user $defaultUserData = data_entry_helper::get_report_data(array('dataSource' => 'library/users/get_people_details_for_website_or_user', 'readAuth' => $auth['read'], 'extraParams' => array('user_id' => hostsite_get_user_field('indicia_user_id'), 'website_id' => $args['website_id']))); //If we are in edit mode then we need to get the name of the saved observer for the sample if (!empty($_GET['sample_id']) && !empty($args['observer_name'])) { $existingUserData = data_entry_helper::get_population_data(array('table' => 'sample_attribute_value', 'extraParams' => $auth['read'] + array('sample_id' => $_GET['sample_id'], 'sample_attribute_id' => $args['observer_name']))); } $observer_list_args = array_merge_recursive(array('extraParams' => array_merge($auth['read'])), $options); $observer_list_args['label'] = t('Observer Name'); $observer_list_args['extraParams']['website_id'] = $args['website_id']; $observer_list_args['captionField'] = 'fullname_surname_first'; $observer_list_args['id'] = 'obSelect:' . $args['observer_name']; $observer_list_args['report'] = 'library/users/get_people_details_for_website_or_user'; //Auto-fill the observer name with the name of the observer of the existing saved sample if it exists, //else default to current user name if (!empty($existingUserData[0]['value'])) { $observer_list_args['defaultCaption'] = $existingUserData[0]['value']; } else { if (empty($_GET['sample_id'])) { $observer_list_args['defaultCaption'] = $defaultUserData[0]['fullname_surname_first']; } } return data_entry_helper::autocomplete($observer_list_args); }