private function get_links_hierarchy($auth, $layerLocationTypes, $countUnitBoundaryTypeId, $urlParameter) { iform_load_helpers(array('report_helper')); $locationId = $_GET[$urlParameter]; $locationRecord = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('id' => $locationId), 'nocache' => true)); $locationTypeId = $locationRecord[0]['location_type_id']; $i = -1; //Cycle round the list of all Location Types that can be displayed on the homepage map in order. //Then stop when we reach the location type that is the same as the location we have clicked on. This gives us a list of location //types up until that point. do { $i++; if (!empty($SupportedLocationTypeIdsAsString)) { $SupportedLocationTypeIdsAsString = $SupportedLocationTypeIdsAsString . ',' . $layerLocationTypes[$i]; } else { $SupportedLocationTypeIdsAsString = $layerLocationTypes[$i]; } } while ($locationTypeId != $layerLocationTypes[$i] && $i < count($layerLocationTypes) - 1); //Use a report to get a list of locations that match the different layer location types and also intersect the location we are interested in. $reportOptions = array('dataSource' => 'reports_for_prebuilt_forms/CUDI/get_map_hierarchy_for_current_position', 'readAuth' => $auth['read'], 'mode' => 'report', 'extraParams' => array('location_id' => $locationId, 'location_type_ids' => $SupportedLocationTypeIdsAsString)); $breadcrumbHierarchy = report_helper::get_report_data($reportOptions); //The report doesn't know the order of the layers we want, so re-order the data. $breadcrumbHierarchy = self::reorderBreadcrumbHierarchy($breadcrumbHierarchy, $layerLocationTypes); return $breadcrumbHierarchy; }
/** * Method that retrieves the data from a report or a table/view, ready to display in a chart or grid. * @param array $options Refer to documentation for report_helper::get_report_data. * @param string $extra Refer to documentation for report_helper::get_report_data. * @deprecated, use report_helper::get_report_data instead. */ public static function get_report_data($options, $extra = '') { require_once 'report_helper.php'; return report_helper::get_report_data($options, $extra); }
protected static function get_control_hideControlForNonGroupMembers($auth, $args, $tabalias, $options) { iform_load_helpers(array('report_helper')); $currentUserId = hostsite_get_user_field('indicia_user_id'); if (empty($options['controlId'])) { drupal_set_message('The option to hide a control based on group has been specified, but no option to indicate which control has been provided.'); return false; } if (empty($options['groupId'])) { drupal_set_message('The option to hide a control based on group has been specified, but no group id has been provided.'); return false; } $reportOptions = array('dataSource' => 'library/groups/group_members', 'readAuth' => $auth['read'], 'mode' => 'report', 'extraParams' => array('group_id' => $options['groupId'])); $usersInGroup = report_helper::get_report_data($reportOptions); //Check all members in the group, if the current user is in the group, then there is no need to hide the control. $userFoundInGroup = false; foreach ($usersInGroup as $userInGroup) { if ($userInGroup['id'] === $currentUserId) { $userFoundInGroup = true; } } if ($userFoundInGroup !== true || empty($_GET['group_id']) || $_GET['group_id'] != $options['groupId']) { //Parent hide control stops the control and label from showing on screen. //Disable control stops it appearing in the POST and getting submitted. data_entry_helper::$javascript .= "\$('#" . $options['controlId'] . "').attr('disabled', true);\n"; data_entry_helper::$javascript .= "\$('#" . $options['controlId'] . "').parent().hide();\n"; } }
protected static function getAnnotationsList($args, $locationId, $auth) { iform_load_helpers(array('report_helper')); $extraParams = array('count_unit_id' => $locationId, 'count_unit_boundary_location_type_id' => $args['count_unit_boundary_location_type_id']); $optionsForAnnotationsReport = array('dataSource' => 'reports_for_prebuilt_forms/CUDI/get_count_unit_annotations', 'readAuth' => $auth['read'], 'extraParams' => $extraParams); //Get the report options such as the Preset Parameters on the Edit Tab $optionsForAnnotationsReport = array_merge(iform_report_get_report_options($args, $readAuth), $optionsForAnnotationsReport); //Collect the annotations from a report. $annotations = report_helper::get_report_data($optionsForAnnotationsReport); return $annotations; }
/** * Hierarchy map control, which can be added to user interface form configurations using [site_hierarchy_navigator.map]. * * Display a map with polygons loaded onto it of a particular location type. When the user clicks on one, reloads the map layer * to show the intersecting polygons from the next location type. Continues down the locations hierarchy in a supplied sequence of * location types (e.g. you might set the location type sequence to Country, County, Parish, Site). * * Supply an option @layerLocationTypes with a comma separated array of the location types ID to load in top down order. */ public function map($auth, $args, $tabalias, $options, $path) { global $base_root; //Setup the path to the cudi information sheets. //Include the parameter on the end of the path, but leave off the parameter values //as these will change for each path used. iform_load_helpers(array('map_helper', 'report_helper')); $informationSheetLinkParts = explode('|', $options['informationSheetLink']); $path = $base_root . base_path() . (variable_get('clean_url', 0) ? '' : '?q=') . $informationSheetLinkParts[0] . (variable_get('clean_url', 0) ? '?' : '&') . $informationSheetLinkParts[1] . '='; map_helper::$javascript .= "indiciaData.informationSheetLink='" . $path . "';\n"; if (empty($options['layerLocationTypes'])) { return '<p>Please provide a @layerLocationTypes option for the [site_hierarchy_navigator.map] map control on the edit tab</p>'; } $msg = self::check_format($options, 'layerLocationTypes', 'location_type_id (from the termlists term table)', '/^([0-9]*,\\s*)*[0-9]*\\s*$/'); if ($msg !== true) { return $msg; } //This option is optional, so don't need to check if it isn't present $msg = self::check_format($options, 'showCountUnitsForLayers', 'location_type_id (from the termlists term table)', '/^([0-9]*,\\s*)*[0-9]*\\s*$/'); if ($msg !== true) { return $msg; } drupal_add_js(iform_client_helpers_path() . 'prebuilt_forms/extensions/site_hierarchy_navigator.js'); //The location types are supplied by the user in a comma seperated list. //The first number is used as the initial location type to display. //The second number is used after the user clicks the first time on a feature and so on $layerLocationTypes = explode(',', $options['layerLocationTypes']); //Comma seperated list of location types which signify which layers should also display the Count Unit location type. //This should be a subset of $layerLocationTypes. $showCountUnitsForLayers = explode(',', $options['showCountUnitsForLayers']); $locationTypesWithSymbols = explode(',', $options['locationTypesWithSymbols']); //Annotation location types as defined on edit tab $annotationTypeIds = explode(',', $options['annotationTypeIds']); $mapOptions = iform_map_get_map_options($args, $auth); $olOptions = iform_map_get_ol_options($args); $mapOptions['readAuth'] = $mapOptions['readAuth']['read']; $mapOptions['clickForSpatialRef'] = false; //When user clicks on map, run specified Javascript function $mapOptions['clickableLayersOutputMode'] = 'customFunction'; $mapOptions['customClickFn'] = 'move_to_new_layer'; $mapOptions['clickableLayersOutputDiv'] = ''; //Tell the system which layers we to be clickable. $mapOptions['clickableLayers'] = array('indiciaData.reportlayer'); $r .= map_helper::map_panel($mapOptions, $olOptions); map_helper::$javascript .= "indiciaData.layerLocationTypes=" . json_encode($layerLocationTypes) . ";\n"; $reportOptions = array('dataSource' => 'reports_for_prebuilt_forms/CUDI/get_layer_list_names', 'readAuth' => $auth['read'], 'mode' => 'report', 'extraParams' => array('layer_ids' => $options['layerLocationTypes'])); //Return a list of location type names for the location type id layers list //provided by the user in the form structure. $locationTypeNamesDirty = data_entry_helper::get_report_data($reportOptions); //The data returned by the database is not a simple array of names, so convert the data and put into correct order foreach ($layerLocationTypes as $originalLayerIndex => $layerLocationTypeFromOriginalList) { foreach ($locationTypeNamesDirty as $locationTypeNamesData) { if ($locationTypeNamesData['id'] === $layerLocationTypeFromOriginalList) { $locationTypeNamesClean[$originalLayerIndex] = $locationTypeNamesData['name']; } } } //Send the array of names to javascript map_helper::$javascript .= "indiciaData.layerLocationTypesNames=" . json_encode($locationTypeNamesClean) . ";\n"; //Send the user supplied options for layers to display count units to Javascript map_helper::$javascript .= "indiciaData.showCountUnitsForLayers=" . json_encode($showCountUnitsForLayers) . ";\n"; map_helper::$javascript .= "indiciaData.countUnitBoundaryTypeId=" . $options['countUnitBoundaryTypeId'] . ";\n"; map_helper::$javascript .= "indiciaData.annotationTypeIds=" . json_encode($annotationTypeIds) . ";\n"; map_helper::$javascript .= "indiciaData.deactivateSiteAttributeId=" . $options['deactivateSiteAttributeId'] . ";\n"; //Get translatable label for top-level breadcrub item. map_helper::$javascript .= "indiciaData.allSitesLabel='" . lang::get('All Sites') . "';\n"; $reportOptions = array('linkOnly' => 'true', 'dataSource' => 'reports_for_prebuilt_forms/cudi/get_boundaries_and_locations_for_cudi_map', 'readAuth' => $auth['read']); //Get the report options such as the Preset Parameters on the Edit Tab $reportOptions = array_merge(iform_report_get_report_options($args, $readAuth), $reportOptions); //Run the report that shows the locations (features) to the user when the map loads the first time. map_helper::$javascript .= "indiciaData.layerReportRequest='" . report_helper::get_report_data($reportOptions) . "';\n"; //Options for the report that is used to draw the map breadcrumb $reportOptions = array('linkOnly' => 'true', 'dataSource' => 'reports_for_prebuilt_forms/CUDI/get_map_hierarchy_for_current_position', 'readAuth' => $auth['read']); //Get the report options such as the Preset Parameters on the Edit Tab $reportOptions = array_merge(iform_report_get_report_options($args, $readAuth), $reportOptions); //Run the report that builds the map breadcrumb. map_helper::$javascript .= "indiciaData.breadcrumbReportRequest='" . report_helper::get_report_data($reportOptions) . "';\n"; return $r; }
/** * Loads the record associated with the page if not already loaded. */ protected static function load_record($auth) { if (!isset(self::$record)) { $records = report_helper::get_report_data(array('readAuth' => $auth['read'], 'dataSource' => 'reports_for_prebuilt_forms/record_details_2/record_data', 'extraParams' => array('occurrence_id' => $_GET['occurrence_id'], 'sharing' => 'reporting'))); self::$record = $records[0]; } }
public static function autoset_record_id_and_record_type($auth, $args, $tabalias, $options, $path) { $mode = empty($options['mode']) ? false : $options['mode']; // skip this functionality for existing data if (empty($_GET['sample_id']) && !empty($_GET['transect_sample_id'])) { $recordIdAttrId = $options['recordIdAttrId']; if (!empty($_SESSION['last_transect']) && !empty($_SESSION['last_record_id']) && $_SESSION['last_transect'] === $_GET['transect_sample_id']) { // session holds the last record ID we created $recordId = $_SESSION['last_record_id'] + 1; } else { // not available in session, so we need to fetch the max existing record ID for this transect from the db $_SESSION['last_transect'] = $_GET['transect_sample_id']; iform_load_helpers(array('report_helper')); $report = report_helper::get_report_data(array('dataSource' => 'reports_for_prebuilt_forms/marinelife/max_occattr_val_for_parent_sample', 'readAuth' => $auth['read'], 'extraParams' => array('parent_sample_id' => $_GET['transect_sample_id'], 'attr_id' => $options['recordIdAttrId']))); if (count($report) === 0 || empty($report[0]['maxval'])) { $recordId = 1; if ($mode === 'effort') { $mode = 'start'; } } else { $recordId = $report[0]['maxval'] + 1; } } if ($mode && !empty($options['recordTypeAttrId'])) { // set the record type control to hold the $mode data_entry_helper::$javascript .= "\$.each(\$('#smpAttr\\\\:{$options['recordTypeAttrId']} option'), function() {\n if (\$(this).html().toLowerCase()==='{$mode}'.toLowerCase()) {\n \$(this).attr('selected', 'selected');\n } \n});\n"; } $_SESSION['last_record_id'] = $recordId; data_entry_helper::$javascript .= "\$('#smpAttr\\\\:{$recordIdAttrId}').val('{$recordId}');\n"; // default the selector for what happens after save if ($mode === 'sighting') { data_entry_helper::$javascript .= "\$('#next-action').val('sighting');\n"; } } }
private static function plot_report_panel($auth, $options) { iform_load_helpers(array('report_helper')); $reportOptions = array('linkOnly' => 'true', 'dataSource' => 'reports_for_prebuilt_forms/Splash/get_square_details_for_square_id', 'readAuth' => $auth['read']); //Report that will return the type of the square selected by the user data_entry_helper::$javascript .= "indiciaData.squareReportRequest='" . report_helper::get_report_data($reportOptions) . "';\n"; $reportOptions = array('linkOnly' => 'true', 'dataSource' => 'reports_for_prebuilt_forms/Splash/get_plot_details', 'readAuth' => $auth['read']); data_entry_helper::$javascript .= "indiciaData.plotReportRequest='" . report_helper::get_report_data($reportOptions) . "';\n"; //The html to place the data into using jQuery $htmlTemplate = "\n </br><div id='plot_report_panel'>\n </br>\n <h5>Details</h5>\n <div id='field ui-helper-clearfix'>\n <span><b>Square Type: </b></span><span id='square-type-value'></span></br>\n <span><b>Plot Type: </b></span><span id='plot-type-value'></span></br>\n <span><b>Plot Description: </b></span><span id='plot-description-value'></span></br>\n <span><b>Vice County: </b></span><span id='vice-county-value'></span></br>\n <span><b>Orientation: </b></span><span id='orientation-value'></span></br>\n <span><b>Aspect: </b></span><span id='aspect-value'></span></br>\n <span><b>Slope: </b></span><span id='slope-value'></span></br>\n <span><b>% Ash cover: </b></span><span id='ash-cover-value'></span></br>\n </div>\n </div></br>"; //When the square or plot is changed or the page is loaded then get the data about the square/plot from reports and then //place it into the mini report html template using jQuery. data_entry_helper::$javascript .= "\n \$('#squares-select-list').ready(function() {\n loadMiniSquareReport();\n });\n \$('#squares-select-list').change(function() {\n loadMiniSquareReport();\n });\n function loadMiniSquareReport() {\n if (\$('#squares-select-list').val()) {\n var squareReportRequest = indiciaData.squareReportRequest\n + '&square_id=' + \$('#squares-select-list').val()\n + '&core_square_location_type_id=' + " . $options['coreSquareLocationTypeId'] . "\n + '&callback=?';\n \$.getJSON(squareReportRequest,\n null,\n function(response, textStatus, jqXHR) {\n if (response[0].type) {\n \$('#square-type-value').text(response[0].type);\n } else {\n \$('#square-type-value').text('');\n }\n }\n );\n }\n }\n \$('#imp-location').ready(function() {\n loadMiniPlotReport();\n });\n \$('#imp-location').change(function() {\n loadMiniPlotReport();\n });\n function loadMiniPlotReport() {\n if (\$('#imp-location').val()==='<Please select>') {\n \$('#plot-type-value').text('');\n \$('#plot-description-value').text('');\n \$('#vice-county-value').text('');\n \$('#orientation-value').text('');\n \$('#aspect-value').text('');\n \$('#slope-value').text('');\n \$('#ash-value').text('');\n } else {\n var reportRequest = indiciaData.plotReportRequest\n + '&vice_county_name_attribute_id=' + " . $options['viceCountyLocationAttributeId'] . "\n + '&orientation_attribute_id=' + " . $options['orientationAttributeId'] . "\n + '&aspect_attribute_id=' + " . $options['aspectAttributeId'] . "\n + '&slope_attribute_id='+ " . $options['slopeAttributeId'] . "\n + '&ash_attribute_id=' + " . $options['ashAttributeId'] . "\n + '&plot_id='+ \$('#imp-location').val() + '&callback=?';\n \$.getJSON(reportRequest,\n null,\n function(response, textStatus, jqXHR) {\n \$.each(response, function (idx, obj) { \n if (obj.type) {\n \$('#plot-type-value').text(obj.type);\n } else {\n \$('#plot-type-value').text('');\n }\n if (obj.description) {\n \$('#plot-description-value').text(obj.description);\n } else {\n \$('#plot-description-value').text('');\n }\n if (obj.county) {\n \$('#vice-county-value').text(obj.county);\n } else {\n \$('#vice-county-value').text('');\n }\n if (obj.orientation) {\n \$('#orientation-value').text(obj.orientation);\n } else {\n \$('#orientation-value').text('');\n }\n if (obj.aspect) {\n \$('#aspect-value').text(obj.aspect);\n } else {\n \$('#aspect-value').text('');\n }\n if (obj.slope) {\n \$('#slope-value').text(obj.slope);\n } else {\n \$('#slope-value').text('');\n }\n if (obj.ash) {\n \$('#ash-value').text(obj.ash);\n } else {\n \$('#ash-value').text('');\n }\n });\n }\n );\n }\n }"; return $htmlTemplate; }
protected static function get_control_speciesnotes($auth, $args) { //We can't return the notes for a specific taxon unless we have an taxa_taxon_list_id, as the meaning could apply //to several taxa. In this case ignore the notes control. if (empty(self::$taxa_taxon_list_id)) { return ''; } $reportResult = report_helper::get_report_data(array('readAuth' => $auth['read'], 'dataSource' => 'library/taxa/species_notes_and_images', 'useCache' => false, 'extraParams' => array('taxa_taxon_list_id' => self::$taxa_taxon_list_id, 'taxon_meaning_id' => self::$taxon_meaning_id))); if (!empty($reportResult[0]['the_text'])) { return '<div class="detail-panel" id="detail-panel-speciesnotes"><h3>' . lang::get('Species Notes') . '</h3><p>' . $reportResult[0]['the_text'] . '</p></div>'; } }
/** * Loads the record associated with the page if not already loaded. */ protected static function load_record($auth, $args) { if (!isset(self::$record)) { $params = array('occurrence_id' => $_GET['occurrence_id'], 'sharing' => 'reporting'); if (!empty($args['map_geom_precision'])) { $params['geom_precision'] = $args['map_geom_precision']; } $records = report_helper::get_report_data(array('readAuth' => $auth['read'], 'dataSource' => 'reports_for_prebuilt_forms/record_details_2/record_data', 'extraParams' => $params)); self::$record = $records[0]; // set the page metadata global $iform_page_metadata; if (!isset($iform_page_metadata)) { $iform_page_metadata = array(); } $species = self::$record['taxon']; if (!empty(self::$record['preferred_taxon']) && $species !== self::$record['preferred_taxon']) { $species .= ' (' . self::$record['preferred_taxon'] . ')'; } $iform_page_metadata['description'] = lang::get('Record of {1} on {2}', $species, self::$record['date']); if (!empty(self::$record['sample_comment'])) { $iform_page_metadata['description'] .= '. ' . trim(self::$record['sample_comment'], '. \\t\\n\\r\\0\\x0B') . '.'; } if (!empty(self::$record['occurrence_comment'])) { $iform_page_metadata['description'] .= ' ' . trim(self::$record['occurrence_comment'], '. \\t\\n\\r\\0\\x0B') . '.'; } if (empty(self::$record['sensitivity_precision'])) { $iform_page_metadata['latitude'] = number_format((double) self::$record['lat'], 5, '.', ''); $iform_page_metadata['longitude'] = number_format((double) self::$record['long'], 5, '.', ''); } } }
protected function get_termlists_terms_id_for_occurrence_term($occAttrId, $term, $args) { $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $reportOptions = array('dataSource' => 'reports_for_prebuilt_forms/Shorewatch/get_ids_from_occ_terms_for_import', 'readAuth' => $readAuth, 'mode' => 'report', 'extraParams' => array('occurrence_attr_id' => $occAttrId, 'term' => $term)); $termlistsTermIdData = report_helper::get_report_data($reportOptions); return $termlistsTermIdData[0]['id']; }
private static function league_table_position($auth, $args, $options, $report, $label) { $userId = hostsite_get_user_field('indicia_user_id'); if (!$userId) { return ''; } iform_load_helpers(array('report_helper')); $reportOptions = array_merge(iform_report_get_report_options($args, $auth['read']), array('dataSource' => $report, 'autoParamsForm' => false), $options); if (hostsite_get_user_field('training')) { $reportOptions['extraParams']['training'] = 'true'; } $reportOptions['extraParams']['user_id'] = $userId; $rows = report_helper::get_report_data($reportOptions); if (count($rows)) { $r = self::output_title($options); $r .= '<div>'; $r .= '<div class="totals">' . lang::get('Position {1}', $rows[0]['position']) . '</div>'; $r .= '<div class="totals">' . lang::get('{1} species', $rows[0]['value']) . '</div>'; $r .= '</div>'; } return $r; }
/** * Define the HTML required for this filter's UI panel. */ public function get_controls($readAuth, $options) { if (function_exists('iform_load_helpers')) { iform_load_helpers(array('report_helper')); } else { //When running on warehouse we don't have iform_load_helpers require_once DOCROOT . 'client_helpers/report_helper.php'; } $r = '<div class="context-instruct messages warning">' . lang::get('Please note, or options for source filtering are limited by your access permissions in this context.') . '</div>'; $r .= '<div>'; //If running on the warehouse then use a single website (as the user is on the website details->milestones tab for a single website) so don't diplay website selection (which is based on website sharing) if (!isset($options['runningOnWarehouse']) || $options['runningOnWarehouse'] == false) { $sources = report_helper::get_report_data(array('dataSource' => 'library/websites/websites_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing']))); if (count($sources) > 1) { $r .= '<div id="filter-websites" class="filter-popup-columns"><h3>' . lang::get('Websites') . '</h3><p>' . '<select id="filter-websites-mode" name="website_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="website-list-checklist">'; foreach ($sources as $source) { $r .= '<li><input type="checkbox" value="' . $source['id'] . '" id="check-' . $source['id'] . '"/>' . '<label for="check-' . $source['id'] . '">' . $source['title'] . '</label></li>'; } $r .= '</ul></div>'; } } //If running on the warehouse then use a single website id (as the user is on the website details->milestones tab for a single website) so supply this as a param, we don't need to worry about sharing //as other websites will have their own milestones if (isset($options['runningOnWarehouse']) && $options['runningOnWarehouse'] == true) { $sources = data_entry_helper::get_population_data(array('table' => 'survey', 'extraParams' => $readAuth + array('view' => 'detail', 'website_id' => $options['website_id']))); $titleToDisplay = 'title'; } else { $sources = report_helper::get_report_data(array('dataSource' => 'library/surveys/surveys_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing']))); $titleToDisplay = 'fulltitle'; } $r .= '<div id="filter-surveys" class="filter-popup-columns"><h3>' . lang::get('Survey datasets') . '</h3><p>' . '<select id="filter-surveys-mode" name="survey_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="survey-list-checklist">'; foreach ($sources as $source) { $r .= '<li class="vis-website-' . $source['website_id'] . '">' . '<input type="checkbox" value="' . $source['id'] . '" id="check-survey-' . $source['id'] . '"/>' . '<label for="check-survey-' . $source['id'] . '">' . $source[$titleToDisplay] . '</label></li>'; } $r .= '</ul></div>'; $sourceOptions = array('dataSource' => 'library/input_forms/input_forms_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing'])); //If in the warehouse then we are only interested in the website for the milestone we are editing if (isset($options['website_id'])) { $sourceOptions['extraParams'] = array_merge(array('website_id' => $options['website_id']), $sourceOptions['extraParams']); } $sources = report_helper::get_report_data($sourceOptions); $r .= '<div id="filter-input_forms" class="filter-popup-columns"><h3>' . lang::get('Input forms') . '</h3><p>' . '<select id="filter-input_forms-mode" name="input_forms_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="input_form-list-checklist">'; // create an object to contain a lookup from id to form for JS, since forms don't have a real id. $obj = array(); foreach ($sources as $idx => $source) { if (!empty($source['input_form'])) { $r .= '<li class="vis-survey-' . $source['survey_id'] . ' vis-website-' . $source['website_id'] . '">' . '<input type="checkbox" value="' . $source['input_form'] . '" id="check-form-' . $idx . '"/>' . '<label for="check-form-' . $idx . '">' . ucfirst(trim(preg_replace('/(http:\\/\\/)|[\\/\\-_]|(\\?q=)/', ' ', $source['input_form']))) . '</label></li>'; $obj[$source['input_form']] = $idx; } } $r .= '</ul></div>'; report_helper::$javascript .= 'indiciaData.formsList=' . json_encode($obj) . ";\n"; $r .= '</div><p>' . lang::get('Leave any list unticked to leave that list unfiltered.') . '</p>'; return $r; }
private static function league_table($auth, $args, $options, $report, $label) { iform_load_helpers(array('report_helper')); $reportOptions = array_merge(iform_report_get_report_options($args, $auth['read']), array('dataSource' => $report, 'limit' => 20), $options); if (hostsite_get_user_field('training')) { $reportOptions['extraParams']['training'] = 'true'; } $reportOptions['extraParams']['limit'] = $reportOptions['limit']; $rows = report_helper::get_report_data($reportOptions); $r = "<table class=\"league\"><thead><th>Pos</th><th>{$label}</th><th>Species</th></thead><tbody>"; if (count($rows)) { $pos = 1; $lastVal = $rows[0]['value']; foreach ($rows as $idx => $row) { if ($row['value'] < $lastVal) { $pos = $idx + 1; // +1 because zero indexed $idx $lastVal = $row['value']; } $r .= "<tr><td>{$pos}</td><td>{$row[name]}</td><td>{$row[value]}</td></tr>\n"; } } else { $r .= '<td colspan="3">' . lang::get('No results yet') . '</td>'; } $r .= '</tbody></table>'; return $r; }
private static function location_control($args, $readAuth, $node, &$options) { // note that when in user specific mode it returns the list currently assigned to the user: it does not give // locations which the user previously recorded data against, but is no longer allocated to. global $user; $ctrl = ''; $siteUrlParams = self::get_site_url_params(); // loctools is not appropriate here as it is based on a node, for which this is a very simple one, invoking other nodes for the sample creation if (!isset($args['includeLocationFilter']) || !$args['includeLocationFilter']) { return ''; } // this is user specific: when no user selection control, or all users selected then default to all locations // this means it does not get a list of all locations if no user is selected: to be added later? $options['location_id'] = $siteUrlParams[self::$locationKey]['value']; $options['extraParams']['location_id'] = $siteUrlParams[self::$locationKey]['value']; $options['extraParams']['location_list'] = ''; // Set up common data. $locationListArgs = array('extraParams' => array_merge(array('website_id' => $args['website_id'], 'location_type_id' => '', 'sensattr' => '', 'exclude_sensitive' => 0), $readAuth), 'readAuth' => $readAuth, 'caching' => true, 'dataSource' => 'library/locations/locations_list_exclude_sensitive'); $allowSensitive = empty($args['sensitivityLocAttrId']) || function_exists('user_access') && !empty($args['sensitivityAccessPermission']) && user_access($args['sensitivityAccessPermission']); if (!empty($args['sensitivityLocAttrId'])) { $locationListArgs['extraParams']['locattrs'] = $args['sensitivityLocAttrId']; } $attrArgs = array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $readAuth, 'survey_id' => self::$siteUrlParams[self::$SurveyKey]); if (isset($args['locationTypesFilter']) && $args['locationTypesFilter'] != "") { $types = explode(',', $args['locationTypesFilter']); $types1 = array(); $types2 = array(); foreach ($types as $type) { $parts = explode(':', $type); $types1[] = $parts[0]; $types2[] = $parts; } $terms = self::get_sorted_termlist_terms(array('read' => $readAuth), 'indicia:location_types', $types1); $attrArgs['location_type_id'] = $siteUrlParams[self::$locationTypeKey]['value']; $locationListArgs['extraParams']['location_type_id'] = $siteUrlParams[self::$locationTypeKey]['value']; if (count($types) > 1) { $lookUpValues = array(); foreach ($terms as $termDetails) { $lookUpValues[$termDetails['id']] = $termDetails['term']; } // if location is predefined, can not change unless a 'manager_permission' $ctrlid = 'calendar-location-type-' . $node->nid; $ctrl .= data_entry_helper::select(array('label' => lang::get('Site Type'), 'id' => $ctrlid, 'fieldname' => 'location_type_id', 'lookupValues' => $lookUpValues, 'default' => $siteUrlParams[self::$locationTypeKey]['value'])) . '</th><th>'; self::set_up_control_change($ctrlid, self::$locationTypeKey, array()); $options['downloadFilePrefix'] .= preg_replace('/[^A-Za-z0-9]/i', '', $lookUpValues[$siteUrlParams[self::$locationTypeKey]['value']]) . '_'; } } $locationAttributes = data_entry_helper::getAttributes($attrArgs, false); $locationList = array(); // If we are looking a user, then we display all that users sites. If I am that user, or if I am a person with sensitive access, then I can see all the sites, even sensitive. if (isset($args['includeUserFilter']) && $args['includeUserFilter'] && isset($args['userSpecificLocationLookUp']) && $args['userSpecificLocationLookUp'] && isset($options['user_id']) && $options['user_id'] != "" && $siteUrlParams[self::$userKey]['value'] != "branch") { if (!$allowSensitive && $options['user_id'] != $user->uid) { // ensure can see sensitive sites for my sites only, unless manager who can see all $locationListArgs['extraParams']['sensattr'] = $args['sensitivityLocAttrId']; $locationListArgs['extraParams']['exclude_sensitive'] = 1; } $cmsAttr = extract_cms_user_attr($locationAttributes, false); if (!$cmsAttr) { return lang::get('Location control: CMS User ID Attribute missing from locations.'); } $attrListArgs = array('extraParams' => array_merge(array('view' => 'list', 'website_id' => $args['website_id'], 'location_attribute_id' => $cmsAttr['attributeId'], 'raw_value' => $options['user_id']), $readAuth), 'table' => 'location_attribute_value'); $description = "All " . ($user->uid == $options['user_id'] ? 'my' : 'user') . " sites"; $attrList = data_entry_helper::get_population_data($attrListArgs); if (isset($attrList['error'])) { return $attrList['error']; } if (count($attrList) === 0) { $options['downloadFilePrefix'] .= 'NS_'; return $ctrl . lang::get('[No sites allocated.]'); } $locationIDList = array(); foreach ($attrList as $attr) { $locationIDList[] = $attr['location_id']; } $locationListArgs['extraParams']['idlist'] = implode(',', $locationIDList); $locationList = report_helper::get_report_data($locationListArgs); if (isset($locationList['error'])) { return $locationList['error']; } } else { // If we are looking at a branch, we can see all the sites allocated to me even sensitive. if (isset($args['includeUserFilter']) && $args['includeUserFilter'] && isset($args['userSpecificLocationLookUp']) && $args['userSpecificLocationLookUp'] && $siteUrlParams[self::$userKey]['value'] == "branch") { $description = "All branch sites"; if (count(self::$branchLocationList) === 0) { $options['downloadFilePrefix'] .= 'NS_'; return $ctrl . lang::get('[No branch sites allocated.]'); } $locationListArgs['extraParams']['idlist'] = implode(',', self::$branchLocationList); $locationList = report_helper::get_report_data($locationListArgs); if (isset($locationList['error'])) { return $locationList['error']; } $options['extraParams']['location_list'] = implode(',', self::$branchLocationList); $options['branch_location_list'] = self::$branchLocationList; } else { // If we are looking at all sites, we can see all non sensitive sites, plus sensitive sites if they are allocated to me as a site or as a branch, or if I have access to sensitive. $description = "All sites"; $locationListArgs['extraParams']['idlist'] = ''; // get my sites, including sensitive sites. $cmsAttr = extract_cms_user_attr($locationAttributes, false); if ($cmsAttr) { $attrListArgs = array('extraParams' => array_merge(array('view' => 'list', 'website_id' => $args['website_id'], 'location_attribute_id' => $cmsAttr['attributeId'], 'raw_value' => $user->uid), $readAuth), 'table' => 'location_attribute_value'); $attrList = data_entry_helper::get_population_data($attrListArgs); if (isset($attrList['error'])) { return $attrList['error']; } if (count($attrList) > 0) { $locationIDList = array(); foreach ($attrList as $attr) { $locationIDList[] = $attr['location_id']; } $locationListArgs['extraParams']['idlist'] = implode(',', $locationIDList); } } // Next add Branch Sites, sensitive or not if (count(self::$branchLocationList) > 0) { $locationListArgs['extraParams']['idlist'] .= ($locationListArgs['extraParams']['idlist'] == '' ? '' : ',') . implode(',', self::$branchLocationList); } $userLocationList = array(); if ($locationListArgs['extraParams']['idlist'] != '') { $userLocationList = report_helper::get_report_data($locationListArgs); if (isset($userLocationList['error'])) { return $userLocationList['error']; } } // Next get all other non sensitive sites if (!$allowSensitive) { $locationListArgs['extraParams']['sensattr'] = $args['sensitivityLocAttrId']; $locationListArgs['extraParams']['exclude_sensitive'] = 1; } $locationListArgs['extraParams']['idlist'] = ""; $allLocationList = report_helper::get_report_data($locationListArgs); if (isset($allLocationList['error'])) { return $allLocationList['error']; } foreach ($userLocationList as $loc) { $locationList[$loc['id']] = $loc; } foreach ($allLocationList as $loc) { if (!isset($locationList[$loc['id']])) { $locationList[$loc['id']] = $loc; } } } } // we want to sort by name, but also keep details of sensitivity. $sort = array(); $locs = array(); foreach ($locationList as $location) { $sort[$location['id']] = $location['name']; $locs[$location['id']] = $location; } natcasesort($sort); $ctrlid = 'calendar-location-select-' . $node->nid; $ctrl .= '<label for="' . $ctrlid . '" class="location-select-label">' . lang::get('Filter by site') . ': </label><select id="' . $ctrlid . '" class="location-select">' . '<option value="" class="location-select-option" ' . ($siteUrlParams[self::$locationKey]['value'] == '' ? 'selected="selected" ' : '') . '>' . $description . '</option>'; if ($siteUrlParams[self::$locationKey]['value'] == '') { $options['downloadFilePrefix'] .= preg_replace('/[^A-Za-z0-9]/i', '', $description) . '_'; } foreach ($sort as $id => $name) { $ctrl .= '<option value=' . $id . ' class="location-select-option ' . (!empty($args['sensitivityLocAttrId']) && $locs[$id]['attr_location_' . $args['sensitivityLocAttrId']] === "1" ? 'sensitive' : '') . '" ' . ($siteUrlParams[self::$locationKey]['value'] == $id ? 'selected="selected" ' : '') . '>' . $name . (isset($args['includeSrefInLocationFilter']) && $args['includeSrefInLocationFilter'] ? ' (' . $locs[$id]['centroid_sref'] . ')' : '') . '</option>' . "\n"; if ($siteUrlParams[self::$locationKey]['value'] == $id) { $options['downloadFilePrefix'] .= preg_replace('/[^A-Za-z0-9]/i', '', $name) . '_'; } } $ctrl .= '</select>'; self::set_up_control_change($ctrlid, self::$locationKey, array()); return $ctrl; }
/** * Ajax handler to determine if a user is likely to see a notification added to their comments. * @param $website_id * @param $password * @param $node * @return string Either yes, no, maybe or unknown. * @throws \Exception */ public function ajax_do_they_see_notifications($website_id, $password, $node) { iform_load_helpers(array('report_helper')); $readAuth = report_helper::get_read_auth($website_id, $password); $data = report_helper::get_report_data(array('dataSource' => 'library/users/user_notification_response_likely', 'readAuth' => $readAuth, 'extraParams' => array('user_id' => $_GET['user_id']))); $acknowledged = 0; $unacknowledged = 0; $emailFrequency = false; foreach ($data as $row) { if ($row['key'] === 'acknowledged') { $acknowledged = (int) $row['value']; } elseif ($row['key'] === 'unacknowledged') { $unacknowledged = (int) $row['value']; } elseif ($row['key'] === 'email_frequency') { $emailFrequency = $row['value']; } } if ($emailFrequency) { // If they receive emails for comment notifications, we can assume they will see a comment echo 'yes'; } elseif ($acknowledged + $unacknowledged > 0) { // otherwise, we need some info on the ratio of acknowledged to unacknowledged notifications over the last year $ratio = $acknowledged / ($acknowledged + $unacknowledged); if ($ratio > 0.3) { echo 'yes'; } elseif ($ratio === 0) { echo 'no'; } else { echo 'maybe'; } } else { // They don't have notifications in database, so we can't say echo 'unknown'; } }
/** * Additional functionality required to load habitat data for existing samples. * @param integer $sample_id ID of the parent sample being loaded * @param array $auth Authorisation tokens */ protected static function load_existing($sample_id, $auth) { iform_load_helpers(array('report_helper')); $samples = report_helper::get_report_data(array('dataSource' => 'library/samples/subsamples', 'readAuth' => $auth['read'], 'extraParams' => array('parent_sample_id' => $sample_id))); foreach ($samples as $sample) { self::$existingSubsampleData['sample:' . $sample['id']] = array('sample_id' => $sample['id'], 'comment' => $sample['comment'], 'values' => array()); } $values = report_helper::get_report_data(array('dataSource' => 'library/sample_attribute_values/subsample_attribute_values', 'readAuth' => $auth['read'], 'extraParams' => array('parent_sample_id' => $sample_id))); foreach ($values as $idx => $value) { self::$existingSubsampleData['sample:' . $value['sample_id']]['values']["{$idx}:{$value['sample_attribute_id']}"] = "{$value['id']}:{$value['value']}:{$value['data_type']}"; } data_entry_helper::$javascript .= "indiciaData.existingSubsampleData=" . json_encode(array_values(self::$existingSubsampleData)) . ";\n"; }
private static function _build_taxon_groups_report($args, $readAuth, $output, $type) { $r = self::filter_toolbar(array('my_records', 'year'), $readAuth); $reportPerUser = !empty($_GET['my_records']); $reportOptions = array('readAuth' => $readAuth, 'dataSource' => "library/taxon_groups/filterable_{$type}_counts", 'caching' => true, 'cachePerUser' => $reportPerUser, 'cachetimeout' => $reportPerUser ? self::FAST_CACHE_REFRESH : self::SLOW_CACHE_REFRESH); self::check_filters($reportOptions); if (!empty($args['min_rank_sort_order_for_species'])) { $reportOptions['extraParams'] = array('min_taxon_rank_sort_order' => $args['min_rank_sort_order_for_species']); } if ($output === 'pie_chart') { $data = report_helper::get_report_data($reportOptions); // Get the taxon groups used in the master checklist $groups = report_helper::get_report_data(array('dataSource' => '/library/taxon_groups/taxon_groups_used_in_checklist', 'readAuth' => $readAuth, 'extraParams' => array('taxon_list_id' => variable_get('iform_master_checklist_id', 0)), 'caching' => true, 'cachePerUser' => false, 'cachetimeout' => self::SLOW_CACHE_REFRESH)); // make an easy lookup $groupIds = array(); foreach ($groups as $group) { $groupIds[$group['id']] = $group['title']; } // roll categories into 'other' if too many and process to remove unofficial groups $totalOther = 0; $processedData = array(); foreach ($data as $row) { if (count($processedData) >= 10 || !array_key_exists($row['id'], $groupIds)) { $totalOther += $row['count']; } else { $processedData[] = $row; } } if ($totalOther > 0) { $processedData[] = array('taxon_group' => lang::get('other'), 'count' => $totalOther); } $reportOptions['dataSource'] = 'static'; $reportOptions += array('staticData' => $processedData, 'chartType' => 'pie', 'seriesColors' => array('#ccebc5', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#8dd3c7', '#bc80bd', '#d9d9d9'), 'height' => '500', 'yValues' => 'count', 'xLabels' => 'taxon_group', 'autoParamsForm' => false, 'axesOptions' => array('yaxis' => array('min' => 0, 'tickOptions' => array('formatString' => '%d'))), 'legendOptions' => array('show' => true), 'rendererOptions' => array('sliceMargin' => 3)); $r .= report_helper::report_chart($reportOptions); } else { $reportOptions += array('downloadLink' => true); $r .= report_helper::report_grid($reportOptions); } return $r; }
/** * Ajax method to retrieve phenology data for a species by external key. */ public static function ajax_phenology($website_id, $password) { iform_load_helpers(array('report_helper')); $readAuth = report_helper::get_read_auth($website_id, $password); $extraParams = array('external_key' => empty($_GET['external_key']) || $_GET['external_key'] === 'null' ? '' : $_GET['external_key'], 'taxon_meaning_id' => empty($_GET['external_key']) || $_GET['external_key'] === 'null' ? $_GET['taxon_meaning_id'] : '', 'date_from' => '', 'date_to' => '', 'survey_id' => '', 'quality' => 'V'); $data = report_helper::get_report_data(array('dataSource' => 'library/months/phenology', 'readAuth' => $readAuth, 'extraParams' => $extraParams, 'sharing' => 'verification')); // must output all months $output = array(array(1, 0), array(2, 0), array(3, 0), array(4, 0), array(5, 0), array(6, 0), array(7, 0), array(8, 0), array(9, 0), array(10, 0), array(11, 0), array(12, 0)); foreach ($data as $month) { // -1 here, because our array is zero indexed, but the report returns a real month number $output[$month['name'] - 1][1] = intval($month['value']); } echo json_encode($output); }
/** * Define the HTML required for this filter's UI panel. */ public function get_controls($readAuth, $options) { iform_load_helpers(array('report_helper')); $sources = report_helper::get_report_data(array('dataSource' => 'library/websites/websites_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing']))); $r = '<div class="context-instruct messages warning">' . lang::get('Please note, or options for source filtering are limited by your access permissions in this context.') . '</div>'; $r .= '<div>'; if (count($sources) > 1) { $r .= '<div id="filter-websites" class="filter-popup-columns"><h3>' . lang::get('Websites') . '</h3><p>' . '<select id="filter-websites-mode" name="website_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="website-list-checklist">'; foreach ($sources as $source) { $r .= '<li><input type="checkbox" value="' . $source['id'] . '" id="check-' . $source['id'] . '"/>' . '<label for="check-' . $source['id'] . '">' . $source['title'] . '</label></li>'; } $r .= '</ul></div>'; } $sources = report_helper::get_report_data(array('dataSource' => 'library/surveys/surveys_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing']))); $r .= '<div id="filter-surveys" class="filter-popup-columns"><h3>' . lang::get('Survey datasets') . '</h3><p>' . '<select id="filter-surveys-mode" name="survey_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="survey-list-checklist">'; foreach ($sources as $source) { $r .= '<li class="vis-website-' . $source['website_id'] . '">' . '<input type="checkbox" value="' . $source['id'] . '" id="check-survey-' . $source['id'] . '"/>' . '<label for="check-survey-' . $source['id'] . '">' . $source['fulltitle'] . '</label></li>'; } $r .= '</ul></div>'; $sources = report_helper::get_report_data(array('dataSource' => 'library/input_forms/input_forms_list', 'readAuth' => $readAuth, 'caching' => true, 'extraParams' => array('sharing' => $options['sharing']))); $r .= '<div id="filter-input_forms" class="filter-popup-columns"><h3>' . lang::get('Input forms') . '</h3><p>' . '<select id="filter-input_forms-mode" name="input_forms_list_op"><option value="in">' . lang::get('Include') . '</option><option value="not in">' . lang::get('Exclude') . '</option></select> ' . lang::get('records from') . ':</p><ul id="input_form-list-checklist">'; // create an object to contain a lookup from id to form for JS, since forms don't have a real id. $obj = array(); foreach ($sources as $idx => $source) { $r .= '<li class="vis-survey-' . $source['survey_id'] . ' vis-website-' . $source['website_id'] . '">' . '<input type="checkbox" value="' . $source['input_form'] . '" id="check-form-' . $idx . '"/>' . '<label for="check-form-' . $idx . '">' . ucfirst(trim(preg_replace('/(http:\\/\\/)|[\\/\\-_]|(\\?q=)/', ' ', $source['input_form']))) . '</label></li>'; $obj[$source['input_form']] = $idx; } $r .= '</ul></div>'; report_helper::$javascript .= 'indiciaData.formsList=' . json_encode($obj) . ";\n"; $r .= '</div><p>' . lang::get('Leave any list unticked to leave that list unfiltered.') . '</p>'; return $r; }