本文整理汇总了PHP中data_entry_helper::load_existing_record方法的典型用法代码示例。如果您正苦于以下问题:PHP data_entry_helper::load_existing_record方法的具体用法?PHP data_entry_helper::load_existing_record怎么用?PHP data_entry_helper::load_existing_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data_entry_helper
的用法示例。
在下文中一共展示了data_entry_helper::load_existing_record方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntity
/**
* Preparing to display an existing sample with occurrences.
* When displaying a grid of occurrences, just load the sample and data_entry_helper::species_checklist
* will load the occurrences.
* When displaying just one occurrence we must load the sample and the occurrence
*/
protected static function getEntity($args, $auth)
{
data_entry_helper::$entity_to_load = array();
// If we know the occurrence ID but not the sample, we must look it up
if (self::$loadedOccurrenceId && !self::$loadedSampleId) {
$response = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('id' => self::$loadedOccurrenceId, 'view' => 'detail')));
if (count($response) != 0) {
//we found an occurrence
self::$loadedSampleId = $response[0]['sample_id'];
}
}
// Load the sample record
if (self::$loadedSampleId) {
data_entry_helper::load_existing_record($auth['read'], 'sample', self::$loadedSampleId, 'detail', false, true);
}
// Ensure that if we are used to load a different survey's data, then we get the correct survey attributes. We can change args
// because the caller passes by reference.
if ($args['survey_id'] != data_entry_helper::$entity_to_load['sample:survey_id']) {
throw new exception(lang::get('Attempt to access a record on a different survey.'));
}
if ($args['sample_method_id'] != data_entry_helper::$entity_to_load['sample:sample_method_id']) {
throw new exception(lang::get('Attempt to access a record with the wrong sample_method_id.'));
}
// enforce that people only access their own data, unless explicitly have permissions
$editor = !empty($args['edit_permission']) && function_exists('user_access') && user_access($args['edit_permission']);
if (!$editor && 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'] !== hostsite_get_user_field('indicia_user_id')) {
throw new exception(lang::get('Attempt to access a record you did not create.'));
}
}
示例2: get_form
/**
* 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)
{
$reloadPath = self::get_reload_path();
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n";
$r .= $auth['write'];
data_entry_helper::$entity_to_load = array();
if (!empty($_GET['termlists_term_id'])) {
data_entry_helper::load_existing_record($auth['read'], 'termlists_term', $_GET['termlists_term_id']);
// map fields to their appropriate supermodels
data_entry_helper::$entity_to_load['term:term'] = data_entry_helper::$entity_to_load['termlists_term:term'];
data_entry_helper::$entity_to_load['term:id'] = data_entry_helper::$entity_to_load['termlists_term:term_id'];
data_entry_helper::$entity_to_load['meaning:id'] = data_entry_helper::$entity_to_load['termlists_term:meaning_id'];
if (function_exists('hostsite_set_page_title')) {
hostsite_set_page_title(lang::get('Edit {1}', data_entry_helper::$entity_to_load['term:term']));
}
}
$r .= data_entry_helper::hidden_text(array('fieldname' => 'website_id', 'default' => $args['website_id']));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'termlists_term:id'));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'termlists_term:termlist_id', 'default' => $args['termlist_id']));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'termlists_term:preferred', 'default' => 't'));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'term:id'));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'term:language_id', 'default' => $args['language_id']));
$r .= data_entry_helper::hidden_text(array('fieldname' => 'meaning:id'));
// request automatic JS validation
data_entry_helper::enable_validation('entry_form');
$r .= data_entry_helper::text_input(array('label' => lang::get('Term'), 'fieldname' => 'term:term', 'helpText' => lang::get('Please provide the term'), 'validation' => array('required'), 'class' => 'control-width-5'));
$r .= "<input type=\"submit\" name=\"form-submit\" id=\"delete\" value=\"Delete\" />\n";
$r .= "<input type=\"submit\" name=\"form-submit\" value=\"Save\" />\n";
$r .= '<form>';
self::set_breadcrumb($args);
return $r;
}
示例3: get_form
/**
* 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 $errors 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, $errors = null)
{
$r = '';
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
// variables to tracks which parts of the plots grid are not completed, so we can display a correct message
$someGridRefsMissing = false;
$someHabitatsMissing = false;
$someSqTypesMissing = false;
data_entry_helper::$validation_mode = array('colour', 'hint', 'message');
if (isset($_GET['sample_id'])) {
data_entry_helper::load_existing_record($auth['read'], 'sample', $_GET['sample_id']);
if (isset(data_entry_helper::$entity_to_load['sample:date']) && preg_match('/^(\\d{4})/', data_entry_helper::$entity_to_load['sample:date'])) {
// Date has 4 digit year first (ISO style) - convert date to expected output format
// @todo The date format should be a global configurable option. It should also be applied to reloading of custom date attributes.
$d = new DateTime(data_entry_helper::$entity_to_load['sample:date']);
data_entry_helper::$entity_to_load['sample:date'] = $d->format('d/m/Y');
}
$topSampleAttrs = self::load_top_sample_attrs($auth, $args, $_GET['sample_id']);
} else {
$topSampleAttrs = self::load_top_sample_attrs($auth, $args);
}
global $indicia_templates;
$indicia_templates['starredSuffix'] = "*<br/>\n";
$indicia_templates['validation_message'] = "<span class=\"ui-state-error-text\">{error}</span>\n";
data_entry_helper::enable_validation('entry-form');
$r .= '<form method="post" action="" id="entry-form">';
$r .= '<div id="tabs">';
data_entry_helper::enable_tabs(array('divId' => 'tabs', 'navButtons' => true));
$r .= data_entry_helper::tab_header(array('tabs' => array('#your-square' => 'Find Place', '#your-plots' => 'Your Plots', '#species_1' => 'Species Page 1', '#species_2' => 'Species Page 2', '#species_3' => 'Species Page 3', '#species_other' => 'Other Species')));
$r .= '<div id="your-square">';
$r .= self::get_hiddens($args, $auth);
$r .= self::tab_your_square($args, $auth['read'], $topSampleAttrs);
$r .= '</div>';
// your-square
$r .= '<div id="your-plots">';
$r .= self::tab_your_plots($args, $auth['read']);
$r .= '</div>';
// your-plots
$r .= '<div id="species_1">';
$r .= self::tab_species($args, $auth, 0, 34);
$r .= '</div>';
// species-1
$r .= '<div id="species_2">';
$r .= self::tab_species($args, $auth, 34, 34);
$r .= '</div>';
// species-2
$r .= '<div id="species_3">';
$r .= self::tab_species($args, $auth, 68, 34);
$r .= '</div>';
// species-3
$r .= '<div id="species_other">';
$r .= self::tab_other_species($args, $auth);
$r .= '</div>';
// species-3
$r .= '</div>';
// tabs
$r .= '</form>';
return $r;
}
示例4: get_form
/**
* 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)
{
require_once drupal_get_path('module', 'iform') . '/client_helpers/map_helper.php';
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$settings = array('locationTypes' => helper_base::get_termlist_terms($auth, 'indicia:location_types', array('Transect Section')), 'locationId' => isset($_GET['section_id']) ? $_GET['section_id'] : null, 'parentId' => isset($_GET['transect_id']) ? $_GET['transect_id'] : null);
if ($settings['parentId']) {
$parent = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $settings['parentId'], 'deleted' => 'f'), 'nocache' => true));
$settings['parent'] = $parent[0];
} else {
return 'This form must be called with a parent transect_id parameter.';
}
$settings['sections'] = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'parent_id' => $settings['parentId'], 'deleted' => 'f'), 'nocache' => true));
if ($settings['locationId']) {
data_entry_helper::load_existing_record($auth['read'], 'location', $settings['locationId']);
} else {
data_entry_helper::$entity_to_load['location:code'] = 'S' . (count($settings['sections']) + 1);
}
$settings['attributes'] = data_entry_helper::getAttributes(array('id' => $settings['locationId'], 'valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'location_type_id' => $settings['locationTypes'][0]['id']));
if (data_entry_helper::$entity_to_load['location:code']) {
$r = '<form method="post" id="input-form">';
}
$r .= $auth['write'];
$r .= '<div id="controls">';
$customAttributeTabs = array_merge(array('Section' => array('[*]')), get_attribute_tabs($settings['attributes']));
if (count($customAttributeTabs) > 1) {
$headerOptions = array('tabs' => array());
foreach ($customAttributeTabs as $tab => $content) {
$alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab));
$headerOptions['tabs']['#' . $alias] = lang::get($tab);
}
$r .= data_entry_helper::tab_header($headerOptions);
data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true));
}
foreach ($customAttributeTabs as $tab => $content) {
if ($tab == 'Section') {
$r .= self::get_section_tab($auth, $args, $settings);
} else {
$alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab));
$r .= "\n<div id=\"{$alias}\">\n";
$r .= get_attribute_html($settings['attributes'], $args, array('extraParams' => $auth['read']), $tab);
$r .= "</div>\n";
}
}
$r .= '</div>';
// controls
$r .= '</form>';
data_entry_helper::link_default_stylesheet();
if (function_exists('drupal_set_breadcrumb')) {
$breadcrumb = array();
$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l('Sites', $args['sites_list_path']);
$breadcrumb[] = l($settings['parent']['name'], $args['transect_edit_path'], array('query' => array('id' => $settings['parentId'])));
$breadcrumb[] = $settings['locationId'] ? data_entry_helper::$entity_to_load['location:name'] : lang::get('new section');
drupal_set_breadcrumb($breadcrumb);
}
return $r;
}
示例5: get_form
/**
* Return the generated form output.
* @return Form HTML.
*/
public static function get_form($args)
{
require_once drupal_get_path('module', 'iform') . '/client_helpers/map_helper.php';
$hidden = str_replace("\r\n", "\n", $args['hide_fields']);
$hidden = explode("\n", $hidden);
if (empty($_GET['occurrence_id'])) {
return 'This form requires an occurrence_id parameter in the URL.';
}
// Get authorisation tokens to update and read from the Warehouse.
$auth = data_entry_helper::get_read_auth($args['website_id'], $args['password']);
data_entry_helper::load_existing_record($auth, 'occurrence', $_GET['occurrence_id']);
data_entry_helper::load_existing_record($auth, 'sample', data_entry_helper::$entity_to_load['occurrence:sample_id']);
$r .= "<div id=\"controls\">\n";
$r .= "<table>\n";
if (!in_array('Species', $hidden)) {
$r .= "<tr><td><strong>" . lang::get('Species') . "</strong></td><td>" . data_entry_helper::$entity_to_load['occurrence:taxon'] . "</td></tr>\n";
}
if (!in_array('Date', $hidden)) {
$r .= "<tr><td><strong>Date</strong></td><td>" . data_entry_helper::$entity_to_load['sample:date'] . "</td></tr>\n";
}
if (!in_array('Grid Reference', $hidden)) {
$r .= "<tr><td><strong>Grid 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'];
}
if (!in_array('Site', $hidden) && !empty($siteLabels)) {
$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, '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, 'survey_id' => data_entry_helper::$entity_to_load['occurrence:survey_id']));
$attributes = array_merge($smpAttrs, $occAttrs);
foreach ($attributes as $attr) {
if (!in_array($attr['caption'], $hidden)) {
$r .= "<tr><td><strong>" . lang::get($attr['caption']) . "</strong></td><td>" . $attr['displayValue'] . "</td></tr>\n";
}
}
$r .= "</table>\n";
$r .= "</div>\n";
$options = iform_map_get_map_options($args, $readAuth);
$olOptions = iform_map_get_ol_options($args);
$options['initialFeatureWkt'] = data_entry_helper::$entity_to_load['occurrence:wkt'];
$r .= map_helper::map_panel($options, $olOptions);
return $r;
}
示例6: get_form
/**
* 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;
}
示例7: get_occurrences_form
public static function get_occurrences_form($args, $node, $response)
{
global $user;
data_entry_helper::add_resource('jquery_form');
data_entry_helper::add_resource('jquery_ui');
data_entry_helper::add_resource('json');
data_entry_helper::add_resource('autocomplete');
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
// did the parent sample previously exist? Default is no.
$parentSampleId = null;
$existing = false;
if (isset($_POST['sample:id'])) {
// have just posted an edit to the existing parent sample, so can use it to get the parent location id.
$parentSampleId = $_POST['sample:id'];
$existing = true;
} else {
if (isset($response['outer_id'])) {
// have just posted a new parent sample, so can use it to get the parent location id.
$parentSampleId = $response['outer_id'];
} else {
$parentSampleId = $_GET['sample_id'];
$existing = true;
}
}
if (!$parentSampleId || $parentSampleId == '') {
return 'Could not determine the parent sample.';
}
// find any attributes that apply to Timed Count Count samples.
$sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Timed Count Count'));
if (count($sampleMethods) == 0) {
return 'The sample method "Timed Count Count" must be defined in the termlist in order to use this form.';
}
$attributes = 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' => $sampleMethods[0]['id'], 'multiValue' => false));
if (!isset(data_entry_helper::$validation_errors)) {
// the parent sample and at least one sub-sample have already been created: can't cache in case a new subsample (Count) added.
data_entry_helper::load_existing_record($auth['read'], 'sample', $parentSampleId);
$d = new DateTime(data_entry_helper::$entity_to_load['sample:date']);
data_entry_helper::$entity_to_load['sample:date'] = $d->format('Y');
// using the report returns the attributes as well.
$subSamples = data_entry_helper::get_population_data(array('report' => 'library/samples/samples_list_for_parent_sample', 'extraParams' => $auth['read'] + array('sample_id' => $parentSampleId, 'date_from' => '', 'date_to' => '', 'sample_method_id' => '', 'smpattrs' => implode(',', array_keys($attributes))), 'nocache' => true));
// subssamples ordered by id desc, so reorder by date asc.
usort($subSamples, "iform_timed_count_subsample_cmp");
for ($i = 0; $i < count($subSamples); $i++) {
data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:id'] = $subSamples[$i]['sample_id'];
data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date'] = $subSamples[$i]['date'];
// this is in correct format
foreach ($subSamples[$i] as $field => $value) {
if (preg_match('/^attr_sample_/', $field)) {
$parts = explode('_', $field);
if ($subSamples[$i]['attr_id_sample_' . $parts[2]] != null) {
data_entry_helper::$entity_to_load['C' . ($i + 1) . ':smpAttr:' + $parts[2] + ':' + $subSamples[$i]['attr_id_sample_' . $parts[2]]] = $value;
}
}
}
}
}
data_entry_helper::$javascript .= "indiciaData.speciesList = " . $args['taxon_list_id'] . ";\n";
if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) {
data_entry_helper::$javascript .= "indiciaData.speciesListFilterField = '" . $args['taxon_filter_field'] . "';\n";
$filterLines = helper_base::explode_lines($args['taxon_filter']);
data_entry_helper::$javascript .= "indiciaData.speciesListFilterValues = '" . json_encode($filterLines) . "';\n";
}
data_entry_helper::$javascript .= "\r\nindiciaData.indiciaSvc = '" . data_entry_helper::$base_url . "';\n";
data_entry_helper::$javascript .= "indiciaData.readAuth = {nonce: '" . $auth['read']['nonce'] . "', auth_token: '" . $auth['read']['auth_token'] . "'};\n";
data_entry_helper::$javascript .= "indiciaData.parentSample = " . $parentSampleId . ";\n";
data_entry_helper::$javascript .= "indiciaData.occAttrId = " . $args['occurrence_attribute_id'] . ";\n";
if ($existing) {
// Only need to load the occurrences for a pre-existing sample
$o = data_entry_helper::get_population_data(array('report' => 'library/occurrences/occurrences_list_for_parent_sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'sample_id' => $parentSampleId, 'survey_id' => '', 'date_from' => '', 'date_to' => '', 'taxon_group_id' => '', 'smpattrs' => '', 'occattrs' => $args['occurrence_attribute_id']), 'nocache' => true));
// the report is ordered id desc. REverse it
$o = array_reverse($o);
} else {
$o = array();
}
// empty array of occurrences when no creating a new sample.
// we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse
// without an additional (expensive) warehouse call.
// pass a param that sets the next page to display
$r = "<form method='post' id='subsamples'>" . $auth['write'] . "\r\n<input type='hidden' name='page' value='occurrences'/>\r\n<input type='hidden' name='read_nonce' value='" . $auth['read']['nonce'] . "'/>\r\n<input type='hidden' name='read_auth_token' value='" . $auth['read']['auth_token'] . "'/>\r\n<input type='hidden' name='website_id' value='" . $args['website_id'] . "'/>\r\n<input type='hidden' name='sample:id' value='" . data_entry_helper::$entity_to_load['sample:id'] . "'/>\r\n<input type='hidden' name='sample:survey_id' value='" . $args['survey_id'] . "'/>\r\n<input type='hidden' name='sample:date' value='" . data_entry_helper::$entity_to_load['sample:date'] . "'/>\r\n<input type='hidden' name='sample:entered_sref' value='" . data_entry_helper::$entity_to_load['sample:entered_sref'] . "'/>\r\n<input type='hidden' name='sample:entered_sref_system' value='" . data_entry_helper::$entity_to_load['sample:entered_sref_system'] . "'/>\r\n<input type='hidden' name='sample:geom' value='" . data_entry_helper::$entity_to_load['sample:geom'] . "'/>\r\n";
if (isset($args['custom_attribute_options']) && $args['custom_attribute_options']) {
$blockOptions = get_attr_options_array_with_user_data($args['custom_attribute_options']);
} else {
$blockOptions = array();
}
for ($i = 0; $i < $args['numberOfCounts']; $i++) {
$subSampleId = isset($subSamples[$i]) ? $subSamples[$i]['sample_id'] : null;
$r .= "<fieldset id=\"count-{$i}\"><legend>" . lang::get('Count ') . ($i + 1) . "</legend>";
if ($subSampleId) {
$r .= "<input type='hidden' name='C" . ($i + 1) . ":sample:id' value='" . $subSampleId . "'/>";
}
$r .= '<input type="hidden" name="C' . ($i + 1) . ':sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />';
if ($subSampleId || isset(data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date']) && data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date'] != '') {
$dateValidation = array('required', 'date');
} else {
$dateValidation = array('date');
}
$r .= data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'C' . ($i + 1) . ':sample:date', 'validation' => $dateValidation));
data_entry_helper::$javascript .= "\$('#C" . ($i + 1) . "\\\\:sample\\\\:date' ).datepicker( 'option', 'minDate', new Date(" . data_entry_helper::$entity_to_load['sample:date'] . ", 1 - 1, 1) );\r\n\$('#C" . ($i + 1) . "\\\\:sample\\\\:date' ).datepicker( 'option', 'maxDate', new Date(" . data_entry_helper::$entity_to_load['sample:date'] . ", 12 - 1, 31) );\n";
if (!$subSampleId && $i) {
$r .= "<p>" . lang::get('You must enter the date before you can enter any further information.') . '</p>';
//.........这里部分代码省略.........
示例8: array
<div id="wrap">
<h1>Record details</h1>
<?php
if ($_POST) {
$response = data_entry_helper::forward_post_to('occurrence_comment');
echo data_entry_helper::dump_errors($response);
}
if (empty($_GET['id'])) {
echo 'This form requires an occurrence_id parameter in the URL.';
return;
}
data_entry_helper::link_default_stylesheet();
// Get authorisation tokens to update and read from the Warehouse.
$auth = data_entry_helper::get_read_write_auth($config['website_id'], $config['password']);
data_entry_helper::load_existing_record($auth['read'], 'occurrence', $_GET['id']);
data_entry_helper::load_existing_record($auth['read'], 'sample', data_entry_helper::$entity_to_load['occurrence:sample_id']);
$r .= "<div id=\"controls\">\n";
$r .= "<table>\n";
$r .= "<tr><td><strong>" . lang::get('Species') . "</strong></td><td>" . data_entry_helper::$entity_to_load['occurrence:taxon'] . "</td></tr>\n";
$r .= "<tr><td><strong>Date</strong></td><td>" . data_entry_helper::$entity_to_load['sample:date'] . "</td></tr>\n";
$r .= "<tr><td><strong>Grid 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']));
示例9: get_sample_form
public static function get_sample_form($args, $node, $response)
{
global $user;
if (!module_exists('iform_ajaxproxy')) {
return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.';
}
require_once dirname(dirname(__FILE__)) . '/map_helper.php';
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$sampleId = isset($_GET['sample_id']) ? $_GET['sample_id'] : null;
if ($sampleId) {
data_entry_helper::load_existing_record($auth['read'], 'sample', $sampleId);
$locationId = data_entry_helper::$entity_to_load['sample:location_id'];
} else {
$locationId = isset($_GET['site']) ? $_GET['site'] : null;
// location ID also might be in the $_POST data after a validation save of a new record
if (!$locationId && isset($_POST['sample:location_id'])) {
$locationId = $_POST['sample:location_id'];
}
}
$r .= '<form method="post" id="sample">';
$r .= $auth['write'];
// we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse
// without an additional (expensive) warehouse call, so it can get location details.
$r .= '<input type="hidden" name="read_nonce" value="' . $auth['read']['nonce'] . '"/>';
$r .= '<input type="hidden" name="read_auth_token" value="' . $auth['read']['auth_ token'] . '"/>';
$r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>';
if (isset(data_entry_helper::$entity_to_load['sample:id'])) {
$r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>';
}
$r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>';
// pass a param that sets the next page to display
$r .= '<input type="hidden" name="page" value="grid"/>';
if ($locationId) {
$site = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $locationId, 'deleted' => 'f')));
$site = $site[0];
$r .= '<input type="hidden" name="sample:location_id" value="' . $locationId . '"/>';
$r .= '<input type="hidden" name="sample:entered_sref" value="' . $site['centroid_sref'] . '"/>';
$r .= '<input type="hidden" name="sample:entered_sref_system" value="' . $site['centroid_sref_system'] . '"/>';
}
if ($locationId && isset(data_entry_helper::$entity_to_load['sample:id'])) {
// for reload of existing, don't let the user switch the transect as that would mess everything up.
$r .= '<label>' . lang::get('Transect') . ':</label><span>' . $site['name'] . '</span><br/>';
} else {
// Output only the locations for this website and transect type. Note we load both transects and sections, just so that
// we always use the same warehouse call and therefore it uses the cache.
$locationTypes = helper_base::get_termlist_terms($auth, 'indicia:location_types', array('Transect', 'Transect Section'));
$availableSites = data_entry_helper::get_population_data(array('report' => 'library/locations/locations_list', 'extraParams' => $auth['read'] + array('website_id' => $args['website_id'], 'location_type_id' => $locationTypes[0]['id'], 'locattrs' => 'CMS User ID', 'attr_location_cms_user_id' => $user->uid), 'nocache' => true));
// convert the report data to an array for the lookup, plus one to pass to the JS so it can keep the hidden sref fields updated
$sitesLookup = array();
$sitesJs = array();
foreach ($availableSites as $site) {
$sitesLookup[$site['location_id']] = $site['name'];
$sitesJs[$site['location_id']] = $site;
}
data_entry_helper::$javascript .= "indiciaData.sites = " . json_encode($sitesJs) . ";\n";
$options = array('label' => lang::get('Select Transect'), 'validation' => array('required'), 'blankText' => lang::get('please select'), 'lookupValues' => $sitesLookup);
if ($locationId) {
$options['default'] = $locationId;
}
$r .= data_entry_helper::location_select($options);
}
if (!$locationId) {
$r .= '<input type="hidden" name="sample:entered_sref" value="" id="entered_sref"/>';
$r .= '<input type="hidden" name="sample:entered_sref_system" value="" id="entered_sref_system"/>';
// sref values for the sample will be populated automatically when the submission is built.
}
$r .= data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'sample:date'));
$sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Transect'));
$attributes = data_entry_helper::getAttributes(array('id' => $sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id']));
$r .= get_attribute_html($attributes, $args, array('extraParams' => $auth['read']));
$r .= '<input type="hidden" name="sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />';
$r .= '<input type="submit" value="' . lang::get('Next') . '" class="ui-state-default ui-corner-all" />';
$r .= '</form>';
data_entry_helper::enable_validation('sample');
return $r;
}
示例10: get_form
/**
* 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)
{
global $user;
$checks = self::check_prerequisites();
$args = self::getArgDefaults($args);
if ($checks !== true) {
return $checks;
}
iform_load_helpers(array('map_helper'));
data_entry_helper::add_resource('jquery_form');
self::$ajaxFormUrl = iform_ajaxproxy_url($node, 'location');
self::$ajaxFormSampleUrl = iform_ajaxproxy_url($node, 'sample');
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$typeTerms = array(empty($args['transect_type_term']) ? 'Transect' : $args['transect_type_term'], empty($args['section_type_term']) ? 'Section' : $args['section_type_term']);
$settings = array('locationTypes' => helper_base::get_termlist_terms($auth, 'indicia:location_types', $typeTerms), 'locationId' => isset($_GET['id']) ? $_GET['id'] : null, 'canEditBody' => true, 'canEditSections' => true, 'canAllocBranch' => $args['managerPermission'] == "" || user_access($args['managerPermission']), 'canAllocUser' => $args['managerPermission'] == "" || user_access($args['managerPermission']));
$settings['attributes'] = data_entry_helper::getAttributes(array('id' => $settings['locationId'], 'valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'location_type_id' => $settings['locationTypes'][0]['id'], 'multiValue' => true));
$settings['section_attributes'] = 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'], 'location_type_id' => $settings['locationTypes'][1]['id'], 'multiValue' => true));
if ($args['allow_user_assignment']) {
if (false == ($settings['cmsUserAttr'] = extract_cms_user_attr($settings['attributes']))) {
return 'This form is designed to be used with the CMS User ID attribute setup for locations in the survey, or the "Allow users to be assigned to transects" option unticked.';
}
// keep a copy of the cms user ID attribute so we can use it later.
self::$cmsUserAttrId = $settings['cmsUserAttr']['attributeId'];
}
// need to check if branch allocation is active.
if ($args['branch_assignment_permission'] != '') {
if (false == ($settings['branchCmsUserAttr'] = self::extract_attr($settings['attributes'], "Branch CMS User ID"))) {
return '<br />This form is designed to be used with either<br />1) the Branch CMS User ID attribute setup for locations in the survey, or<br />2) the "Permission name for Branch Manager" option left blank.<br />';
}
// keep a copy of the branch cms user ID attribute so we can use it later.
self::$branchCmsUserAttrId = $settings['branchCmsUserAttr']['attributeId'];
}
data_entry_helper::$javascript .= "indiciaData.sections = {};\n";
$settings['sections'] = array();
$settings['numSectionsAttr'] = "";
$settings['maxSectionCount'] = $args['maxSectionCount'];
$settings['autocalcSectionLengthAttrId'] = empty($args['autocalc_section_length_attr_id']) ? 0 : $args['autocalc_section_length_attr_id'];
$settings['defaultSectionGridRef'] = empty($args['default_section_grid_ref']) ? 'parent' : $args['default_section_grid_ref'];
if ($settings['locationId']) {
data_entry_helper::load_existing_record($auth['read'], 'location', $settings['locationId']);
$settings['walks'] = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'location_id' => $settings['locationId'], 'deleted' => 'f'), 'nocache' => true));
// Work out permissions for this user: note that canAllocBranch setting effectively shows if a manager.
if (!$settings['canAllocBranch']) {
// Check whether I am a normal user and it is allocated to me, and also if I am a branch manager and it is allocated to me.
$settings['canEditBody'] = false;
$settings['canEditSections'] = false;
if ($args['allow_user_assignment'] && count($settings['walks']) == 0 && isset($settings['cmsUserAttr']['default']) && !empty($settings['cmsUserAttr']['default'])) {
foreach ($settings['cmsUserAttr']['default'] as $value) {
// multi value
if ($value['default'] == $user->uid) {
// comparing string against int so no triple equals
$settings['canEditBody'] = true;
$settings['canEditSections'] = true;
break;
}
}
}
// If a Branch Manager and not a main manager, then can't edit the number of sections
if ($args['branch_assignment_permission'] != '' && user_access($args['branch_assignment_permission']) && isset($settings['branchCmsUserAttr']['default']) && !empty($settings['branchCmsUserAttr']['default'])) {
foreach ($settings['branchCmsUserAttr']['default'] as $value) {
// now multi value
if ($value['default'] == $user->uid) {
// comparing string against int so no triple equals
$settings['canEditBody'] = true;
$settings['canAllocUser'] = true;
break;
}
}
}
}
// for an admin user the defaults apply, which will be can do everything.
// find the number of sections attribute.
foreach ($settings['attributes'] as $attr) {
if ($attr['caption'] === 'No. of sections') {
$settings['numSectionsAttr'] = $attr['fieldname'];
for ($i = 1; $i <= $attr['displayValue']; $i++) {
$settings['sections']["S{$i}"] = null;
}
$existingSectionCount = empty($attr['displayValue']) ? 1 : $attr['displayValue'];
data_entry_helper::$javascript .= "\$('#" . str_replace(':', '\\\\:', $attr['id']) . "').attr('min',{$existingSectionCount}).attr('max'," . $args['maxSectionCount'] . ");\n";
if (!$settings['canEditSections']) {
data_entry_helper::$javascript .= "\$('#" . str_replace(':', '\\\\:', $attr['id']) . "').attr('readonly','readonly').css('color','graytext');\n";
}
}
}
$sections = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'parent_id' => $settings['locationId'], 'deleted' => 'f', 'orderby' => 'id'), 'nocache' => true));
foreach ($sections as $section) {
$code = $section['code'];
data_entry_helper::$javascript .= "indiciaData.sections.{$code} = {'geom':'" . $section['boundary_geom'] . "','id':'" . $section['id'] . "','sref':'" . $section['centroid_sref'] . "','system':'" . $section['centroid_sref_system'] . "'};\n";
$settings['sections'][$code] = $section;
//.........这里部分代码省略.........
示例11: get_form
/**
* 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)
{
$form = '<form action="#" method="POST" id="entry_form">';
if ($_POST) {
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
self::subscribe($args, $auth);
} else {
// don't bother with write auth for initial form load, as read auth is cached and faster
$auth = array('read' => data_entry_helper::get_read_auth($args['website_id'], $args['password']));
}
if (!empty($_GET['id'])) {
data_entry_helper::load_existing_record($auth['read'], 'species_alert', $_GET['id']);
// enforce permissions
if (data_entry_helper::$entity_to_load['species_alert:user_id'] != hostsite_get_user_field('indicia_user_id')) {
return lang::get('You cannot modify a species alert subscription created by someone else');
}
$form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:id', 'default' => $_GET['id']));
}
// if not logged in, then ask for details to register against
global $user;
if (!hostsite_get_user_field('id') || !isset($user) || empty($user->mail) || !hostsite_get_user_field('last_name')) {
$form .= "<fieldset><legend>" . lang::get('Your details') . ":</legend>\n";
$default = empty($_POST['first_name']) ? hostsite_get_user_field('first_name', '') : $_POST['first_name'];
$form .= data_entry_helper::text_input(array('label' => lang::get('First name'), 'fieldname' => 'first_name', 'validation' => array('required'), 'default' => $default, 'class' => 'control-width-4'));
$default = empty($_POST['surname']) ? hostsite_get_user_field('last_name', '') : $_POST['surname'];
$form .= data_entry_helper::text_input(array('label' => lang::get('Last name'), 'fieldname' => 'surname', 'validation' => array('required'), 'default' => $default, 'class' => 'control-width-4'));
$default = empty($_POST['email']) ? empty($user->mail) ? '' : $user->mail : $_POST['email'];
$form .= data_entry_helper::text_input(array('label' => lang::get('Email'), 'fieldname' => 'email', 'validation' => array('required', 'email'), 'default' => $default, 'class' => 'control-width-4'));
$form .= "</fieldset>\n";
} else {
$form .= data_entry_helper::hidden_text(array('fieldname' => 'first_name', 'default' => hostsite_get_user_field('first_name')));
$form .= data_entry_helper::hidden_text(array('fieldname' => 'surname', 'default' => hostsite_get_user_field('last_name')));
$form .= data_entry_helper::hidden_text(array('fieldname' => 'email', 'default' => $user->mail));
$form .= data_entry_helper::hidden_text(array('fieldname' => 'user_id', 'default' => hostsite_get_user_field('indicia_user_id')));
}
$form .= "<fieldset><legend>" . lang::get('Alert criteria') . ":</legend>\n";
// Output the species selection control
// Default after saving with a validation failure can be pulled direct from the post, but
// when reloading we don't need a default taxa taxon list ID since we already know the meaning
// ID or external key.
$default = empty($_POST['taxa_taxon_list_id']) ? '' : $_POST['taxa_taxon_list_id'];
if (empty($_POST['taxa_taxon_list_id:taxon'])) {
$defaultCaption = empty(data_entry_helper::$entity_to_load['species_alert:preferred_taxon']) ? '' : data_entry_helper::$entity_to_load['species_alert:preferred_taxon'];
} else {
$defaultCaption = $_POST['taxa_taxon_list_id:taxon'];
}
$form .= data_entry_helper::species_autocomplete(array('label' => lang::get('Alert species'), 'helpText' => lang::get('Select the species you are interested in receiving alerts in ' . 'relation to if you want to receive alerts on a single species.'), 'fieldname' => 'taxa_taxon_list_id', 'cacheLookup' => true, 'extraParams' => $auth['read'] + array('taxon_list_id' => $args['list_id']), 'class' => 'control-width-4', 'default' => $default, 'defaultCaption' => $defaultCaption));
if (empty($default)) {
// Unless we've searched for the species name then posted (and failed), then the
// default will be empty. We might therefore be reloading existing data which has
// a meaning ID or external key.
if (!empty(data_entry_helper::$entity_to_load['species_alert:external_key'])) {
$form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:external_key', 'default' => data_entry_helper::$entity_to_load['species_alert:external_key']));
} elseif (!empty(data_entry_helper::$entity_to_load['species_alert:taxon_meaning_id'])) {
$form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:taxon_meaning_id', 'default' => data_entry_helper::$entity_to_load['species_alert:taxon_meaning_id']));
}
}
if (!empty($args['full_lists'])) {
$form .= data_entry_helper::select(array('label' => lang::get('Select full species lists'), 'helpText' => lang::get('If you want to restrict the alerts to records of any ' . 'species within a species list, then select the list here.'), 'fieldname' => 'species_alert:taxon_list_id', 'blankText' => lang::get('<Select a species list>'), 'table' => 'taxon_list', 'valueField' => 'id', 'captionField' => 'title', 'extraParams' => $auth['read'] + array('id' => $args['full_lists'], 'orderby' => 'title'), 'class' => 'control-width-4'));
}
$form .= data_entry_helper::location_select(array('label' => lang::get('Select location'), 'helpText' => lang::get('If you want to restrict the alerts to records within a certain boundary, select it here.'), 'fieldname' => 'species_alert:location_id', 'id' => 'imp-location', 'blankText' => lang::get('<Select boundary>'), 'extraParams' => $auth['read'] + array('location_type_id' => $args['location_type_id'], 'orderby' => 'name'), 'class' => 'control-width-4'));
$form .= data_entry_helper::checkbox(array('label' => lang::get('Alert on initial entry'), 'helpText' => lang::get('Tick this box if you want to receive a notification when the record is first input into the system.'), 'fieldname' => 'species_alert:alert_on_entry'));
$form .= data_entry_helper::checkbox(array('label' => lang::get('Alert on verification as correct'), 'helpText' => lang::get('Tick this box if you want to receive a notification when the record has been verified as correct.'), 'fieldname' => 'species_alert:alert_on_verify'));
$form .= "</fieldset>\n";
$form .= '<input type="Submit" value="Subscribe" />';
$form .= '</form>';
data_entry_helper::enable_validation('entry_form');
iform_load_helpers(array('map_helper'));
$mapOptions = iform_map_get_map_options($args, $auth['read']);
$map = map_helper::map_panel($mapOptions);
global $indicia_templates;
return str_replace(array('{col-1}', '{col-2}'), array($form, $map), $indicia_templates['two-col-50']);
}
示例12: get_form
/**
* 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 $errors 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, $errors = null)
{
$r = '';
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
// Determine how the form was requested and therefore what to output
self::$mode = self::getMode($args, $node);
if (self::$mode === self::MODE_GRID) {
//Displayed the grid when the page opens initially
$r .= self::getGrid($args, $node, $auth);
} else {
// variables to tracks which parts of the plots grid are not completed, so we can display a correct message
$someGridRefsMissing = false;
$someHabitatsMissing = false;
$someSqTypesMissing = false;
data_entry_helper::$validation_mode = array('colour', 'hint', 'message');
if (self::$mode === self::MODE_EXISTING || self::$mode === self::MODE_CLONE) {
data_entry_helper::load_existing_record($auth['read'], 'sample', $_GET['sample_id']);
if (isset(data_entry_helper::$entity_to_load['sample:date']) && preg_match('/^(\\d{4})/', data_entry_helper::$entity_to_load['sample:date'])) {
// Date has 4 digit year first (ISO style) - convert date to expected output format
// @todo The date format should be a global configurable option. It should also be applied to reloading of custom date attributes.
$d = new DateTime(data_entry_helper::$entity_to_load['sample:date']);
data_entry_helper::$entity_to_load['sample:date'] = $d->format('d/m/Y');
}
$topSampleAttrs = self::load_top_sample_attrs($auth, $args, $_GET['sample_id']);
} else {
$topSampleAttrs = self::load_top_sample_attrs($auth, $args);
}
//If in mode clone, we want to load existing data but as a new sample. So strip out all the existing attribute value ids from the form
//html so the data is loaded but it creates a new sample.
if (self::$mode === self::MODE_CLONE) {
self::cloneEntity($args, $auth, $topSampleAttrs);
}
global $indicia_templates;
$indicia_templates['starredSuffix'] = "*<br/>\n";
$indicia_templates['validation_message'] = "<span class=\"ui-state-error-text\">{error}</span>\n";
data_entry_helper::enable_validation('entry-form');
$r .= '<form method="post" action="" id="entry-form">';
$r .= '<div id="tabs">';
data_entry_helper::enable_tabs(array('divId' => 'tabs', 'navButtons' => true));
//User needs to set configuration options for the number of species tabs they want and the
//number of species to appear on each tab. The user needs to make sure this will result in enough
//space to display all the required species from the species list.
if (!empty($args['num_species_tabs'])) {
$numSpeciesTabs = $args['num_species_tabs'];
} else {
$numSpeciesTabs = 3;
}
if (!empty($args['num_species_per_tab'])) {
$numSpeciesPerTab = $args['num_species_per_tab'];
} else {
$numSpeciesPerTab = 34;
}
$tabsArray = array('#your-square' => 'Find Place', '#your-plots' => 'Your Path');
//Tell the system that it needs to display the number of tabs specified by the user
for ($i = 0; $i < $numSpeciesTabs; $i++) {
$tabNum = $i + 1;
$tabsArray = array_merge($tabsArray, array('#species_' . $tabNum => 'Species Page ' . $tabNum));
}
$r .= data_entry_helper::tab_header(array('tabs' => $tabsArray));
$r .= '<div id="your-square">';
$r .= self::get_hiddens($args, $auth);
$r .= self::getFirstTabAdditionalContent($args, $auth);
$r .= self::tab_your_square($args, $auth['read'], $topSampleAttrs);
$r .= '</div>';
// your-square
$r .= '<div id="your-plots">';
$r .= self::tab_your_plots($args, $auth['read']);
$r .= '</div>';
// your-plots (now called Your Paths, the old Wildflower form was Your Plots)
//Create the html for each species tab.
for ($i = 0; $i < $numSpeciesTabs; $i++) {
$tabNum = $i + 1;
$speciesStartIndex = $numSpeciesPerTab * $i;
$r .= '<div id="species_' . $tabNum . '">';
$r .= self::tab_species_npms_paths($args, $auth, $speciesStartIndex, $numSpeciesPerTab, $tabNum, $numSpeciesTabs);
$r .= '</div>';
// species-1
}
$r .= '</div>';
// tabs
$r .= '</form>';
}
return $r;
}
示例13: ajax_details
/**
* Ajax handler to provide the content for the details of a single record.
*/
public static function ajax_details($website_id, $password)
{
iform_load_helpers(array('data_entry_helper'));
$auth = data_entry_helper::get_read_auth($website_id, $password);
data_entry_helper::load_existing_record($auth, 'occurrence', $_GET['occurrence_id']);
data_entry_helper::load_existing_record($auth, 'sample', data_entry_helper::$entity_to_load['occurrence:sample_id']);
$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'];
}
// build an array of all the data. This allows the JS to insert the data into emails etc. Note we
// use an array rather than an assoc array to build the JSON, so that order is guaranteed.
$data = array(array('caption' => lang::get('Species'), 'value' => data_entry_helper::$entity_to_load['occurrence:taxon']), array('caption' => lang::get('Date'), 'value' => data_entry_helper::$entity_to_load['sample:date']), array('caption' => lang::get('Grid Ref.'), 'value' => data_entry_helper::$entity_to_load['sample:entered_sref']), array('caption' => lang::get('Site'), 'value' => implode(' | ', $siteLabels)));
$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, '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, 'survey_id' => data_entry_helper::$entity_to_load['occurrence:survey_id']));
$attributes = array_merge($smpAttrs, $occAttrs);
foreach ($attributes as $attr) {
$data[] = array('caption' => lang::get($attr['caption']), 'value' => $attr['displayValue']);
}
$r = "<table>\n";
$status = data_entry_helper::$entity_to_load['occurrence:record_status'];
$r .= '<tr><td><strong>' . lang::get('Status') . '</strong></td><td class="status status-' . $status . '">';
$r .= self::statusLabel($status);
if (data_entry_helper::$entity_to_load['occurrence:zero_abundance'] === 't') {
$r .= '<br/>' . lang::get('This is a record indicating absence.');
}
$r .= "</td></tr>\n";
foreach ($data as $item) {
if (!empty($item['value'])) {
$r .= "<tr><td><strong>" . $item['caption'] . "</strong></td><td>" . $item['value'] . "</td></tr>\n";
}
}
$r .= "</table>\n";
$additional = array();
$additional['wkt'] = data_entry_helper::$entity_to_load['occurrence:wkt'];
$additional['taxon'] = data_entry_helper::$entity_to_load['occurrence:taxon'];
header('Content-type: application/json');
echo json_encode(array('content' => $r, 'data' => $data, 'additional' => $additional));
}
示例14: get_form_mode_7
protected static function get_form_mode_7($args, $node)
{
// MODE_POST_OCCURRENCE
if (!is_null(data_entry_helper::$entity_to_load)) {
// errors with new sample+occurrence combination, entity poulated with post, so display this data.
return call_user_func(array(get_called_class(), 'get_form_sampleoccurrence'), $args, $node);
}
// else valid save
if (array_key_exists('navigate:newoccurrence', $_POST)) {
// display a new sample/occurrence combination, with the same parent & date
data_entry_helper::$entity_to_load = array('sample:parent_id' => $_POST['sample:parent_id'], 'sample:date' => $_POST['sample:date']);
return call_user_func(array(get_called_class(), 'get_form_sampleoccurrence'), $args, $node);
}
$loadedSampleId = $_POST['sample:parent_id'];
data_entry_helper::load_existing_record(self::$auth['read'], 'sample', $loadedSampleId);
return call_user_func(array(get_called_class(), 'get_form_supersample'), $args, $node);
}
示例15: get_form
/**
* 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)
{
global $user;
data_entry_helper::$helpTextPos = 'before';
$checks = self::check_prerequisites();
$args = self::getArgDefaults($args);
if ($checks !== true) {
return $checks;
}
iform_load_helpers(array('map_helper'));
data_entry_helper::add_resource('jquery_form');
self::$ajaxFormUrl = iform_ajaxproxy_url($node, 'loc-smp-occ');
self::$ajaxFormLocationUrl = iform_ajaxproxy_url($node, 'location');
self::$ajaxFormSampleUrl = iform_ajaxproxy_url($node, 'sample');
$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
$settings = array('SiteLocationType' => helper_base::get_termlist_terms($auth, 'indicia:location_types', array(empty($args['location_type_term']) ? 'TreeSite' : $args['location_type_term'])), 'TreeLocationType' => helper_base::get_termlist_terms($auth, 'indicia:location_types', array(empty($args['tree_type_term']) ? 'Tree' : $args['tree_type_term'])), 'locationId' => isset($_GET['id']) ? $_GET['id'] : null, 'canAllocUser' => $args['manager_permission'] == "" || user_access($args['manager_permission']));
$settings['attributes'] = data_entry_helper::getAttributes(array('id' => $settings['locationId'], 'valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'location_type_id' => $settings['SiteLocationType'][0]['id'], 'multiValue' => true));
$settings['tree_attributes'] = 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'], 'location_type_id' => $settings['TreeLocationType'][0]['id'], 'multiValue' => true));
if ($args['allow_user_assignment']) {
if (false == ($settings['cmsUserAttr'] = extract_cms_user_attr($settings['attributes']))) {
return 'This form is designed to be used with the "CMS User ID" attribute setup for Site locations in the survey, or the "Allow users to be assigned to locations" option unticked.';
}
// keep a copy of the cms user ID attribute so we can use it later.
self::$cmsUserAttrId = $settings['cmsUserAttr']['attributeId'];
$found = false;
foreach ($settings['tree_attributes'] as $idx => $attr) {
if (strcasecmp($attr['caption'], 'Recorder Name') === 0) {
data_entry_helper::$javascript .= "indiciaData.assignedRecorderID = " . $attr['attributeId'] . ";\n";
$found = true;
break;
}
}
if (!$found) {
return 'This form is designed to be used with the "Recorder Name" attribute setup for Tree locations in the survey, or the "Allow users to be assigned to locations" option unticked.';
}
}
// TBD data drive
$definitions = array(array("attr" => "111", "term" => "WD", "target" => "112", "required" => true, "title" => "You must pick the dominant species from this drop down list when the WD (Dominant Species) checkbox is set."), array("attr" => "111", "term" => "WP", "target" => "113", "required" => false, "title" => "If known, you may enter the year that the woodland was planted in when the WP (Planted Date) checkbox is set."));
$common = "var check_attrs = function(){\n";
data_entry_helper::$javascript .= "var checkbox_changed_base = function(changedSelector, targetSelector, required){\n \$(changedSelector).closest('span').find('label.inline-error').remove();\n \$(changedSelector).closest('span').find('.ui-state-error').removeClass('ui-state-error');\n \$(changedSelector).closest('span').find('label.error').remove();\n \$(changedSelector).closest('span').find('.error').removeClass('error');\n if(\$(changedSelector).attr('checked'))\n \$(targetSelector).addClass(required ? 'required' : 'notrequired').closest('span').show();\n else {\n \$(targetSelector).removeClass('required').val('').closest('span').hide();\n }\n};\nvar check_attr_def = [];\ncheck_attrs = function(){\n for(var i=0; i<check_attr_def.length; i++){\n checkbox_changed_base(check_attr_def[i][0], check_attr_def[i][1], check_attr_def[i][2]);\n }\n}\n";
foreach ($definitions as $defn) {
data_entry_helper::$javascript .= "\$('[id^=locAttr\\\\:" . $defn["attr"] . "\\\\:]:checkbox').each(function(idx,elem){\n if(\$('label[for='+\$(elem).attr('id').replace(/:/g,'\\\\:')+']').html() == '" . $defn["term"] . "'){\n var tgt = \$('#locAttr\\\\:" . $defn["target"] . "');\n tgt.prev('label').remove();\n tgt.next('br').remove();\n var span = \$('<span/>');\n \$(elem).closest('span').append(span);\n span.append(tgt);" . ($defn["required"] ? "\n span.append('<span class=\"deh-required\">*</span>');" : "") . "\n tgt.attr('title','" . $defn["title"] . "');\n \$(elem).change(function(e){checkbox_changed_base(e.target, '#locAttr\\\\:" . $defn["target"] . "', " . ($defn["required"] ? "true" : "false") . ");});\n check_attr_def.push([elem, '#locAttr\\\\:" . $defn["target"] . "', " . ($defn["required"] ? "true" : "false") . "]);\n }\n});\n";
}
data_entry_helper::$javascript .= "check_attrs();\nindiciaData.trees = {};\n";
$settings['trees'] = array();
if ($settings['locationId']) {
data_entry_helper::load_existing_record($auth['read'], 'location', $settings['locationId']);
// Work out permissions for this user
$canEdit = $args['manager_permission'] == "" || user_access($args['manager_permission']);
if ($args['allow_user_assignment'] && isset($settings['cmsUserAttr']['default']) && !empty($settings['cmsUserAttr']['default'])) {
foreach ($settings['cmsUserAttr']['default'] as $value) {
// multi value
if ($value['default'] == $user->uid) {
// comparing string against int so no triple equals
$canEdit = true;
break;
}
}
}
if (!$canEdit) {
return 'You do not have access to this site.';
}
$trees = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'parent_id' => $settings['locationId'], 'deleted' => 'f', 'orderby' => 'name'), 'nocache' => true));
foreach ($trees as $tree) {
$id = $tree['id'];
data_entry_helper::$javascript .= "indiciaData.trees[{$id}] = {'id':'" . $tree['id'] . "','name':'" . str_replace("'", "\\'", $tree['name']) . "','geom':'" . $tree['centroid_geom'] . "','sref':'" . $tree['centroid_sref'] . "','system':'" . $tree['centroid_sref_system'] . "'};\n";
$settings['trees'][$id] = $tree;
}
}
$r = '<div id="controls">';
$headerOptions = array('tabs' => array('#site-details' => lang::get('Site Details')));
$tabOptions = array('divId' => 'controls', 'style' => 'Tabs');
if ($settings['locationId']) {
$headerOptions['tabs']['#site-trees'] = lang::get('Tree Details');
$tabOptions['active'] = '#site-trees';
}
$r .= data_entry_helper::tab_header($headerOptions);
data_entry_helper::enable_tabs($tabOptions);
$settings['treeSampleMethod'] = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('TreeInitialRegistration'));
// TODO put in error check, add in $arg driving of text value
$settings['treeSampleMethod'] = $settings['treeSampleMethod'][0];
$r .= self::get_site_tab($auth, $args, $settings);
if ($settings['locationId']) {
$r .= self::get_site_trees_tab($auth, $args, $settings);
data_entry_helper::enable_validation('tree-form');
data_entry_helper::setup_jquery_validation_js();
}
$r .= '</div>';
// controls
data_entry_helper::enable_validation('input-form');
if (function_exists('drupal_set_breadcrumb')) {
//.........这里部分代码省略.........