/** * Return the Indicia form code * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { global $user; $retVal = ''; $logged_in = $user->uid > 0; if (!$logged_in) { return '<p>' . lang::get('Please log in before attempting to use this form.') . '</p>'; } // can't really do this automatically: better to give warning if (isset($args['locationTypeFilter'])) { return '<p>' . lang::get('Please contact the site administrator. This version of the form uses a different method of specifying the location types.') . '</p>'; } iform_load_helpers(array('report_helper')); $auth = report_helper::get_read_auth($args['website_id'], $args['password']); if (!self::set_up_survey($args, $auth)) { return lang::get('set_up_survey returned false: survey_id missing from presets or location_type definition.'); } $reportOptions = self::get_report_calendar_2_options($args, $auth); $reportOptions['id'] = 'calendar-summary-' . $node->nid; if (!empty($args['removable_params'])) { self::$removableParams = get_options_array_with_user_data($args['removable_params']); } self::copy_args($args, $reportOptions, array('weekstart', 'weekOneContains', 'weekNumberFilter', 'outputTable', 'outputChart', 'tableHeaders', 'chartLabels', 'disableableSeries', 'chartType', 'rowGroupColumn', 'rowGroupID', 'width', 'height', 'includeChartTotalSeries', 'includeChartItemSeries', 'includeRawData', 'includeSummaryData', 'includeEstimatesData', 'includeRawGridDownload', 'includeSummaryGridDownload', 'includeEstimatesGridDownload', 'sampleFields')); if (isset($_GET['outputSeries'])) { $reportOptions['outputSeries'] = $_GET['outputSeries']; } // default is all // Advanced Chart options $rendererOptions = trim($args['renderer_options']); if (!empty($rendererOptions)) { $reportOptions['rendererOptions'] = json_decode($rendererOptions, true); } $axesOptions = trim($args['axes_options']); if (!empty($axesOptions)) { $reportOptions['axesOptions'] = json_decode($axesOptions, true); } if (isset($args['countColumn']) && $args['countColumn'] != '') { $reportOptions['countColumn'] = 'attr_occurrence_' . str_replace(' ', '_', strtolower($args['countColumn'])); // assume that this is an occurrence attribute. $reportOptions['extraParams']['occattrs'] = $args['countColumn']; } // for a normal user, we can only link to those samples we have created $reportOptions['location_list'] = array(); // for a branch user, we have an allowed list of locations for which we can link to the sample. self::$branchLocationList = array(); if (isset($args['branch_manager_permission']) && $args['branch_manager_permission'] != "" && user_access($args['branch_manager_permission'])) { // Get list of locations attached to this user via the branch cms user id attribute // first need to scan param_presets for survey_id.. $attrArgs = array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth, 'survey_id' => self::$siteUrlParams[self::$SurveyKey]); if (isset($args['locationTypesFilter']) && $args['locationTypesFilter'] != "") { $attrArgs['location_type_id'] = self::$siteUrlParams[self::$locationTypeKey]['value']; } $locationAttributes = data_entry_helper::getAttributes($attrArgs, false); $cmsAttr = self::extract_attr($locationAttributes, $args['branchFilterAttribute']); if (!$cmsAttr) { return lang::get('Branch Manager location list lookup: missing Branch allocation attribute') . ' {' . print_r($attrArgs, true) . '} : ' . $args['branchFilterAttribute']; } $attrListArgs = array('extraParams' => array_merge(array('view' => 'list', 'website_id' => $args['website_id'], 'location_attribute_id' => $cmsAttr['attributeId'], 'raw_value' => $user->uid), $auth), 'table' => 'location_attribute_value'); $attrList = data_entry_helper::get_population_data($attrListArgs); if (isset($attrList['error'])) { return $attrList['error']; } if (count($attrList) > 0) { foreach ($attrList as $attr) { self::$branchLocationList[] = $attr['location_id']; } } $reportOptions['location_list'] = self::$branchLocationList; } // for an admin, we can link to all samples. if (isset($args['manager_permission']) && $args['manager_permission'] != "" && user_access($args['manager_permission'])) { $reportOptions['location_list'] = 'all'; } // Add controls first: set up a control bar $retVal .= "\n<table id=\"controls-table\" class=\"ui-widget ui-widget-content ui-corner-all controls-table\"><thead class=\"ui-widget-header\"><tr>"; $retVal .= self::year_control($args, $auth, $node, $reportOptions); $retVal .= '<th>' . self::user_control($args, $auth, $node, $reportOptions) . '</th>'; $retVal .= '<th>' . self::location_control($args, $auth, $node, $reportOptions) . '</th>'; // note this includes the location_type control if needed $siteUrlParams = self::get_site_url_params(); if (!empty($args['removable_params'])) { foreach (self::$removableParams as $param => $caption) { $checked = isset($_GET[$param]) && $_GET[$param] === 'true' ? ' checked="checked"' : ''; $retVal .= '<th><input type="checkbox" name="removeParam-' . $param . '" id="removeParam-' . $param . '" class="removableParam"' . $checked . '/>' . '<label for="removeParam-' . $param . '" >' . lang::get($caption) . '</label></th>'; if ($checked != '') { $reportOptions['downloadFilePrefix'] .= 'RM' . preg_replace('/[^A-Za-z0-9]/i', '', $param) . '_'; } } self::set_up_control_change('removeParam-' . $param, $param, array(), true); } // are there any params that should be set to blank using one of the removable params tickboxes? foreach (self::$removableParams as $param => $caption) { if (isset($_GET[$param]) && $_GET[$param] === 'true') { $reportOptions[$param] = ''; $reportOptions['extraParams'][$param] = ''; } } if (self::$siteUrlParams[self::$locationTypeKey]['value'] == '') { if (isset($args['locationTypesFilter']) && $args['locationTypesFilter'] != "") { $types = explode(',', $args['locationTypesFilter']); $terms = self::get_sorted_termlist_terms(array('read' => $auth), 'indicia:location_types', array($types[0])); $reportOptions['extraParams']['location_type_id'] = $terms[0]['id']; } } else { $reportOptions['extraParams']['location_type_id'] = self::$siteUrlParams[self::$locationTypeKey]['value']; } if (isset($args['linkURL'])) { $reportOptions['linkURL'] = $args['linkURL'] . (isset($siteUrlParams[self::$URLExtensionKey]) ? $siteUrlParams[self::$URLExtensionKey] : ''); $reportOptions['linkURL'] .= (strpos($reportOptions['linkURL'], '?') !== FALSE ? '&' : '?') . 'sample_id='; } $reportOptions['includeReportTimeStamp'] = isset($args['includeFilenameTimestamps']) && $args['includeFilenameTimestamps']; $retVal .= '</tr></thead></table>'; $reportOptions['survey_id'] = self::$siteUrlParams[self::$SurveyKey]; // Sort of assuming that only one location type recorded against per survey. $reportOptions['downloads'] = array(); if (isset($args['manager_permission']) && $args['manager_permission'] != "" && user_access($args['manager_permission']) || $reportOptions['extraParams']['location_list'] != '' || $reportOptions['extraParams']['user_id'] != '') { // if user specified - either me in normal or branch mode, or a manager for ($i = 1; $i <= 4; $i++) { if (isset($args['Download' . $i . 'Caption']) && $args['Download' . $i . 'Caption'] != "" && isset($args['download_report_' . $i]) && $args['download_report_' . $i] != "") { $reportOpts = array('caption' => $args['Download' . $i . 'Caption'], 'dataSource' => $args['download_report_' . $i], 'filename' => $reportOptions['downloadFilePrefix'] . preg_replace('/[^A-Za-z0-9]/i', '', $args['Download' . $i . 'Caption']) . (isset($reportOptions['includeReportTimeStamp']) && $reportOptions['includeReportTimeStamp'] ? '_' . date('YmdHis') : '')); if (isset($args['download_report_' . $i . '_format'])) { $reportOpts['format'] = $args['download_report_' . $i . '_format']; } $reportOptions['downloads'][] = $reportOpts; } } } else { $reportOptions['includeRawGridDownload'] = false; } $retVal .= report_helper::report_calendar_summary2($reportOptions); return $retVal; }