/** * 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) { iform_load_helpers(array('report_helper', 'map_helper')); $conn = iform_get_connection_details($node); $readAuth = report_helper::get_read_auth($conn['website_id'], $conn['password']); $r = '<div id="leftcol">'; $reportOptions = iform_report_get_report_options($args, $readAuth); iform_report_apply_explore_user_own_preferences($reportOptions); $reportOptions = array_merge(array('rowId' => 'external_key', 'columns' => array(), 'callback' => 'grid_load', 'rememberParamsReportGroup' => 'explore', 'paramsFormButtonCaption' => lang::get('Filter')), $reportOptions); $reportOptions['rowId'] = 'external_key'; $imgPath = empty(report_helper::$images_path) ? report_helper::relative_client_helper_path() . "../media/images/" : report_helper::$images_path; $reportOptions['columns'][] = array('actions' => array(array('img' => "{$imgPath}/add.png", 'caption' => 'Click to add this species to the map'))); $r .= report_helper::report_grid($reportOptions); $r .= '</div>'; $args['indicia_species_layer_slds'] = report_helper::explode_lines($args['indicia_species_layer_slds']); $r .= '<div id="rightcol">'; $r .= '<div id="layerbox">'; $r .= '<p id="instruct">' . lang::get('Click on the + buttons in the grid to add species layers to the map. You can add up to {1} layers at a time.', count($args['indicia_species_layer_slds'])); $r .= '<p id="instruct2" style="display: none">' . lang::get('Use the - buttons to permanently remove layers, or untick the box in the legend to temporarily hide them.'); $mapOptions = iform_map_get_map_options($args, $readAuth); $mapOptions['clickForSpatialRef'] = false; $olOptions = iform_map_get_ol_options($args, $readAuth); $r .= map_helper::layer_list(array('layerTypes' => array('overlay'), 'includeSwitchers' => true, 'includeHiddenLayers' => true)); $r .= '</div>'; $r .= map_helper::map_panel($mapOptions, $olOptions); $r .= '</div>'; $websiteIds = iform_get_allowed_website_ids($readAuth); if (!empty($args['indicia_species_layer_feature_type']) && !empty(report_helper::$geoserver_url)) { $training = function_exists('hostsite_get_user_field') && hostsite_get_user_field('training') ? 't' : 'f'; $cql = 'website_id IN (' . implode(',', $websiteIds) . ') AND ' . $args['indicia_species_layer_filter_field'] . "='{filterValue}' AND record_status NOT IN ('R', 'I', 'T') AND training='{$training}'"; if (isset($_POST[$reportOptions['reportGroup'] . '-quality'])) { $quality = $_POST[$reportOptions['reportGroup'] . '-quality']; } else { $quality = $reportOptions['extraParams']['quality']; } // logic here must match the quality_check function logic on the database. switch ($quality) { case 'V': $cql .= " AND record_status='V'"; break; case 'C': $cql .= " AND (record_status='V' OR certainty='C')"; break; case 'L': $cql .= " AND (record_status='V' OR ((certainty <> 'U' OR certainty IS NULL) AND record_status <> 'D'))"; break; case '!D': $cql .= " AND record_status<>'D'"; break; case '!R': // nothing to add - rejects are always excluded } report_helper::$javascript .= "indiciaData.indiciaSpeciesLayer = {\n" . ' "title":"' . lang::get('{1}') . "\",\n" . ' "myRecords":"' . lang::get('my records') . "\",\n" . ' "userId":"' . hostsite_get_user_field('indicia_user_id') . "\",\n" . ' "featureType":"' . $args['indicia_species_layer_feature_type'] . "\",\n" . ' "wmsUrl":"' . data_entry_helper::$geoserver_url . "wms\",\n" . " \"cqlFilter\":\"{$cql}\",\n" . " \"filterField\":\"taxon_meaning_id\",\n" . ' "slds":' . json_encode($args['indicia_species_layer_slds']) . "\n" . "};\n"; } return $r; }
/** * Either return a report picker, or if already picked, the report content. * @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) { iform_load_helpers(array('report_helper', 'map_helper')); $conn = iform_get_connection_details($node); $readAuth = report_helper::get_read_auth($conn['website_id'], $conn['password']); if (empty($_GET['catname']) || empty($_GET['report'])) { return self::report_picker($args, $node, $readAuth); } else { $reports = self::get_reports(); $reportDef = $reports[$_GET['catname']]['reports'][$_GET['report']]; $regionTerm = self::get_region_term($args, $readAuth); $reportDef['title'] = str_replace('#main_location_layer_type#', $regionTerm, $reportDef['title']); hostsite_set_page_title($reportDef['title']); $fn = "build_report_{$_GET['catname']}_{$_GET['report']}"; $output = $_GET['output']; hostsite_set_breadcrumb(array($node->title => $_GET['q'])); return call_user_func(array('iform_report_selector', $fn), $args, $readAuth, $output); } }
/** * 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.'; } require_once 'includes/map.php'; require_once 'includes/groups.php'; global $indicia_templates; iform_load_helpers(array('report_helper', 'map_helper')); $conn = iform_get_connection_details($node); $readAuth = report_helper::get_read_auth($conn['website_id'], $conn['password']); report_helper::$javascript .= "indiciaData.website_id={$conn['website_id']};\n"; report_helper::$javascript .= "indiciaData.nodeId={$node->nid};\n"; group_authorise_form($args, $readAuth); $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $readAuth + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; hostsite_set_page_title("{$group['title']}: {$node->title}"); $actions = array(); if (!empty($args['edit_location_path'])) { $actions[] = array('caption' => 'edit', 'url' => '{rootFolder}' . $args['edit_location_path'], 'urlParams' => array('group_id' => $_GET['group_id'], 'location_id' => '{location_id}')); } $actions[] = array('caption' => 'remove', 'javascript' => "remove_location_from_group({groups_location_id});"); $leftcol = report_helper::report_grid(array('readAuth' => $readAuth, 'dataSource' => 'library/locations/locations_for_groups', 'sendOutputToMap' => true, 'extraParams' => array('group_id' => $_GET['group_id']), 'rowId' => 'location_id', 'columns' => array(array('display' => 'Actions', 'actions' => $actions, 'caption' => 'edit', 'url' => '{rootFolder}')))); $leftcol .= '<fieldset><legend>' . lang::Get('Add sites to the group') . '</legend>'; $leftcol .= '<p>' . lang::get('LANG_Add_Sites_Instruct') . '</p>'; if (!empty($args['edit_location_path'])) { $leftcol .= lang::get('Either') . ' <a class="button" href="' . hostsite_get_url($args['edit_location_path'], array('group_id' => $_GET['group_id'])) . '">' . lang::get('enter details of a new site') . '</a><br/>'; } $leftcol .= data_entry_helper::select(array('label' => lang::get('Or, add an existing site'), 'fieldname' => 'add_existing_location_id', 'report' => 'library/locations/locations_available_for_group', 'caching' => false, 'blankText' => lang::get('<please select>'), 'valueField' => 'location_id', 'captionField' => 'name', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id', 0)), 'afterControl' => '<button id="add-existing">Add</button>')); $leftcol .= '</fieldset>'; // @todo Link existing My Site to group. Need a new report to list sites I created, with sites already in the group // removed. Show in a drop down with an add button. Adding must create the groups_locations record, plus refresh // the grid and refresh the drop down. // @todo set destination after saving added site $map = map_helper::map_panel(iform_map_get_map_options($args, $readAuth), iform_map_get_ol_options($args)); $r = str_replace(array('{col-1}', '{col-2}'), array($leftcol, $map), $indicia_templates['two-col-50']); data_entry_helper::$javascript .= "indiciaData.group_id={$_GET['group_id']};\n"; 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}"); }
/** * Performs the download. * @global array $indicia_templates * @param type $args * @param type $node */ private static function do_data_services_download($args, $node) { iform_load_helpers(array('report_helper')); $format = $_POST['format']; $isCustom = preg_match('/^custom-(\\d+)$/', $_POST['format'], $matches); if ($isCustom) { $customFormats = json_decode($args['custom_formats'], true); $customFormat = $customFormats[$matches[1]]; $report = $customFormat['report']; // strip unnecessary .xml from end of report name if provided $report = preg_replace('/\\.xml$/', '', $report); $format = $customFormat['format']; $additionalParamText = $customFormat['params']; } else { $report = $args["report_{$format}"]; $additionalParamText = $args["report_params_{$format}"]; } $params = self::build_params($args); $params = array_merge($params, get_options_array_with_user_data($additionalParamText)); $conn = iform_get_connection_details($node); 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 = substr($_POST['download-type'], 0, 1); $url = report_helper::report_download_link(array('readAuth' => data_entry_helper::$js_read_tokens, 'dataSource' => $report, 'extraParams' => $params, 'format' => $format, 'sharing' => self::expand_sharing_mode($sharing), 'itemsPerPage' => $limit)); if ($args['reverse_proxy'] == true) { // Rewrite the url to pass through proxy.php $relative_proxy_path = iform_client_helpers_path() . 'proxy.php?url=' . report_helper::$base_url; global $base_url; $proxy_path = $base_url . substr($relative_proxy_path, 1); // remove report_helper::$base_url from $url $url = substr($url, strlen(report_helper::$base_url)); // add $proxy_path to $url $url = $proxy_path . $url; } header("Location: {$url}"); }
/** * Performs the download. * URL arguments date_from, date_to, survey_list, format, download-type * @global array $indicia_templates * @param type $args * @param type $node */ private static function do_data_services_download($args, $node) { iform_load_helpers(array('report_helper')); // default data format JSON if (!array_key_exists('format', $_GET)) { $_GET['format'] = 'json'; } $format = $_GET['format']; // download type set to Reporting by default if (!array_key_exists('download-type', $_GET)) { $_GET['download-type'] = 'R'; } $isCustom = preg_match('/^custom-(\\d+)$/', $_GET['format'], $matches); if ($isCustom) { $customFormats = json_decode($args['custom_formats'], true); $customFormat = $customFormats[$matches[1]]; $report = $customFormat['report']; // strip unnecessary .xml from end of report name if provided $report = preg_replace('/\\.xml$/', '', $report); $format = $customFormat['format']; $additionalParamText = $customFormat['params']; } else { if ($format == 'json') { $report = $args["report_csv"]; $additionalParamText = $args["report_params_csv"]; } else { $report = $args["report_{$format}"]; $additionalParamText = $args["report_params_{$format}"]; } } //Getting the form params first and then allowing the user to //overwrite then through $args require_once 'includes/user.php'; $params = get_options_array_with_user_data($additionalParamText); $params = array_merge($params, self::build_params($args)); $conn = iform_get_connection_details($node); 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 = substr($_GET['download-type'], 0, 1); $url = report_helper::report_download_link(array('readAuth' => data_entry_helper::$js_read_tokens, 'dataSource' => $report, 'extraParams' => $params, 'format' => $format, 'sharing' => self::expand_sharing_mode($sharing), 'itemsPerPage' => $limit)); header("Location: {$url}"); }
/** * Override the get_form to fetch our own auth tokens. This skips the write auth as it is unnecessary, * which makes the tokens cachable therefore faster. It does mean that $auth['write'] will not be available. */ public static function get_form($args, $node) { $conn = iform_get_connection_details($node); self::$auth = array('read' => data_entry_helper::get_read_auth($conn['website_id'], $conn['password'])); return parent::get_form($args, $node); }
public static function ajax_save($website_id, $password, $node) { iform_load_helpers(array('data_entry_helper')); //Build submission $Model = self::build_three_level_sample_with_occ_submission($_POST, $website_id, $password, $node->params['gpx_data_attr_id'], $node->params['dive_start_time_attr_id'], $node->params['exif_date_time_attr_id']); $node = node_load($nid); $conn = iform_get_connection_details($node); $postargs = "website_id=" . $conn['website_id']; $response = data_entry_helper::http_post(data_entry_helper::$base_url . '/index.php/services/security/get_nonce', $postargs, false); $nonce = $response['output']; $writeTokens = array('nonce' => $nonce, 'auth_token' => sha1($nonce . ":" . $conn['password'])); //When the first page is saved we create a sample but we don't have a spatial reference. An attempt is made to read //a position from the first photo exif (elsewhere in code), however if GPS data can't be found on photo, then just fall back on a point on the Isle of Wight (as it is on land it won't get confused with a real position. if (empty($Model['fields']['entered_sref']['value'])) { drupal_set_message('Unable to find any GPS information, please correct this manually using the GPX upload or map tools'); $Model['fields']['entered_sref_system']['value'] = '4277'; $Model['fields']['entered_sref']['value'] = '50:41.0994N, 1:17.1864W'; } //Save submission $response = data_entry_helper::forward_post_to('save', $Model, $writeTokens); echo json_encode($response); }