/**
  * 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;
 }
 protected static function get_control_transectsbar($auth, $args, $tabAlias, $options)
 {
     $captions = explode(',', $args['transect_captions']);
     $r = '<input type="hidden" name="sample:parent_id" value="' . $_GET['id'] . '"/>';
     // use same date as parent
     $r .= '<input type="hidden" name="sample:date" value="' . data_entry_helper::$entity_to_load["sample:date"] . '"/>';
     $r .= '<input type="hidden" id="imp-sref" name="sample:entered_sref" value="' . data_entry_helper::$entity_to_load["sample:entered_sref"] . '"/>';
     $r .= '<input type="hidden" id="imp-sref-system" name="sample:entered_sref_system" value="' . data_entry_helper::$entity_to_load["sample:entered_sref_system"] . '"/>';
     $r .= '<input type="hidden" id="imp-geom" name="sample:geom" value="' . data_entry_helper::$entity_to_load["sample:wkt"] . '"/>';
     $r .= '<div class="ui-helper-clearfix">';
     $ids = array();
     $wantNext = false;
     // loop through the list of attributes which hold a transect count (one per shore zone)
     foreach (self::$transectCountAttrs as $idx => $id) {
         $attr = self::$parentSampleAttrs["smpAttr:{$id}"];
         // output a fieldset per zone
         $r .= "<fieldset class=\"left\" id=\"tcount-{$id}\"><legend>{$captions[$idx]}</legend><div>";
         // output buttons, 1 per transect in the zone
         for ($i = 1; $i <= $attr['default']; $i++) {
             $selected = self::$selectedZoneAttrId === $attr['id'] && self::$selectedTransect == $i;
             if ($selected) {
                 // As this is the selected zone/transect, we can grab the information about it now
                 $title = "{$captions[$idx]} - transect {$i}";
                 $fld = self::$thisSampleAttrs['smpAttr:' . $args['child_sample_zone_attr_id']]['fieldname'];
                 $r .= "<input type=\"hidden\" name=\"{$fld}\" value=\"{$captions[$idx]}\"/>";
                 $fld = self::$thisSampleAttrs['smpAttr:' . $args['child_sample_transect_attr_id']]['fieldname'];
                 $r .= "<input type=\"hidden\" name=\"{$fld}\" value=\"{$i}\"/>";
                 $wantNext = true;
             } elseif ($wantNext) {
                 // This is the button after the selected transect. Store the values required to find the next page after successful save.
                 $r .= "<input type=\"hidden\" name=\"next-zone\" value=\"{$id}\"/>";
                 $r .= "<input type=\"hidden\" name=\"next-transect\" value=\"{$i}\"/>";
                 $wantNext = false;
             }
             if ($selected) {
                 $r .= "<span class=\"button select-transect ui-state-highlight\" id=\"sel-{$attr['id']}-{$i}\">{$i}</span>";
             } else {
                 $link = hostsite_get_url($args['redirect_on_success'], array('table' => 'sample', 'id' => $_GET['id'], 'zone' => $id, 'transect' => $i));
                 $r .= "<a href=\"{$link}\" class=\"button select-transect\" id=\"sel-{$attr['id']}-{$i}\">{$i}</a>";
             }
         }
         $r .= "</div></fieldset>";
         $ids[] = $attr['id'];
     }
     $r .= "</div><h2 id=\"transect-name\">{$title}</h2><p>" . data_entry_helper::$entity_to_load["sample:date"] . '</p>';
     data_entry_helper::$javascript .= "indiciaData.transectCountAttrs=" . json_encode($ids) . ";\n";
     return $r;
 }
 /**
  * 
  */
 public static function survey_points_report_params($auth, $args, $tabalias, $options, $path)
 {
     if (!function_exists('iform_ajaxproxy_url')) {
         return 'An AJAX Proxy module must be enabled for the survey_points_report_params control to work.';
     }
     if (!($userId = hostsite_get_user_field('indicia_user_id'))) {
         return 'The user account must be connected via Easy Login for the survey_points_report_params control to work';
     }
     // map the ID parameter provided after saving a crossing sample to the report input parameter to filter the list
     if (!empty($_GET['id']) && empty($_GET['dynamic-parent_sample_id'])) {
         $_GET['dynamic-parent_sample_id'] = $_GET['id'];
     }
     if (empty($_GET['dynamic-parent_sample_id'])) {
         return 'Survey identifier not provided - cannot load the survey';
     }
     $requiredOptions = array('transectIdAttrId', 'sampleTypeAttrId', 'sampleTypeTermlistId', 'transectSampleMethodId');
     foreach ($requiredOptions as $option) {
         if (empty($options[$option])) {
             return "Please provide a value for the @{$option} option.";
         }
     }
     $surveySampleId = $_GET['dynamic-parent_sample_id'];
     $samples = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('id' => $surveySampleId)));
     if (count($samples) !== 1) {
         return 'No unique survey found for the provided ID';
     }
     $sample = $samples[0];
     $sampleMethods = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $auth['read'] + array('term' => 'Transect', 'termlist_title' => 'Sample methods', 'view' => 'cache')));
     if (count($sampleMethods) !== 1) {
         return 'No sample method term found for Transect';
     }
     $transectMethodId = $sampleMethods[0]['id'];
     $date = strtotime($sample['date_start']);
     hostsite_set_page_title(lang::get('Effort and sightings points for {1} on {2}', $sample['location'], date('d/m/Y', $date)));
     $r = '<div id="points-params">';
     $r .= data_entry_helper::radio_group(array('fieldname' => 'point-type-param', 'lookupValues' => array('E' => lang::get('Effort only'), 'S' => lang::get('Sightings only'), 'ES' => lang::get('Both effort and sightings')), 'default' => 'ES'));
     $r .= '<fieldset>';
     $r .= data_entry_helper::select(array('fieldname' => 'transect-param', 'label' => lang::get('Transect'), 'report' => 'reports_for_prebuilt_forms/marinelife/transects_list', 'valueField' => 'id', 'captionField' => 'caption', 'extraParams' => $auth['read'] + array('parent_sample_id' => $surveySampleId, 'sample_type_attr_id' => $options['sampleTypeAttrId'], 'transect_id_attr_id' => $options['transectIdAttrId']), 'caching' => false));
     $r .= '<a href="#" id="new-transect" class="indicia-button">New transect</a>';
     $r .= '<a href="' . hostsite_get_url('survey/points/edit-effort', array('transect_sample_id' => 0, 'parent_sample_id' => $surveySampleId)) . '" id="edit-effort" class="indicia-button edit-point">Add effort waypoint(s)</a>';
     $r .= '<a href="' . hostsite_get_url('survey/points/edit-sighting', array('transect_sample_id' => 0, 'parent_sample_id' => $surveySampleId)) . '" id="edit-sighting" class="indicia-button edit-point">Add sighting(s)</a>';
     $r .= '</fieldset>';
     $r .= '<a href="casual/edit">Add casual sighting(s)</a>';
     $r .= "</div>\n";
     // popup template for adding a transect
     $r .= '<div style="display: none">';
     $r .= '<div id="add-transect-popup">';
     $r .= '<h3>' . lang::get('New transect') . '</h3>';
     $r .= data_entry_helper::text_input(array('fieldname' => 'popup-transect-id', 'label' => lang::get('Transect ID')));
     $r .= data_entry_helper::select(array('fieldname' => 'popup-sample-type', 'label' => lang::get('Sample type'), 'table' => 'termlists_term', 'valueField' => 'id', 'captionField' => 'term', 'blankText' => lang::get('<Please select>'), 'extraParams' => $auth['read'] + array('view' => 'cache', 'termlist_id' => $options['sampleTypeTermlistId'], 'orderby' => 'sort_order'), 'validation' => array('required')));
     $r .= data_entry_helper::date_picker(array('fieldname' => 'popup-transect-date', 'label' => lang::get('Date'), 'helpText' => lang::get('Please alter the date if the survey spans several days'), 'default' => $sample['date_start']));
     $r .= '<button id="transect-popup-save">Save</button> ';
     $r .= '<button id="transect-popup-cancel">Cancel</button>';
     $r .= '</div>';
     $r .= '</div>';
     $url = iform_ajaxproxy_url(null, 'sample');
     data_entry_helper::$javascript .= "indiciaData.surveySampleId={$surveySampleId};\n";
     data_entry_helper::$javascript .= "indiciaData.websiteId={$args['website_id']};\n";
     data_entry_helper::$javascript .= "indiciaData.userId='{$userId}';\n";
     data_entry_helper::$javascript .= "indiciaData.surveyId='{$sample['survey_id']}';\n";
     !!(data_entry_helper::$javascript .= "indiciaData.sampleDate='{$sample['date_start']}';\n");
     data_entry_helper::$javascript .= "indiciaData.sampleSref='{$sample['entered_sref']}';\n";
     data_entry_helper::$javascript .= "indiciaData.transectMethodId={$transectMethodId};\n";
     data_entry_helper::$javascript .= "indiciaData.saveSampleUrl='{$url}';\n";
     data_entry_helper::$javascript .= "indiciaData.transectIdAttrId={$options['transectIdAttrId']};\n";
     data_entry_helper::$javascript .= "indiciaData.sampleTypeAttrId={$options['sampleTypeAttrId']};\n";
     data_entry_helper::$javascript .= "indiciaData.transectSampleMethodId={$options['transectSampleMethodId']};\n";
     data_entry_helper::$javascript .= "indiciaData.langRequireTransectID='" . lang::get('Please supply the Transect ID.') . "';\n";
     data_entry_helper::$javascript .= "indiciaData.langRequireSampleType='" . lang::get('Please supply the Sample Type.') . "';\n";
     return $r;
 }
Example #4
0
 private static function success($auth, $group, $args)
 {
     hostsite_set_page_title("Welcome to {$group['title']}!");
     $pageData = data_entry_helper::get_population_data(array('table' => 'group_page', 'extraParams' => $auth['read'] + array('group_id' => $group['id'], 'query' => json_encode(array('in' => array('administrator' => array('', 'f')))))));
     $r = '<p>' . lang::get("You've successfully joined {$group['title']}. You can") . ':</p>';
     $r .= '<ul>';
     if (!empty($args['group_home_path'])) {
         $r .= '<li><a href="' . hostsite_get_url($args['group_home_path'], array('group_id' => $group['id'])) . '">' . lang::get("Visit the {$group['title']} home page") . '<a></li>';
     }
     foreach ($pageData as $page) {
         $r .= '<li><a href="' . hostsite_get_url($page['path'], array('group_id' => $group['id'])) . '">' . lang::get($page['caption']) . '<a></li>';
     }
     $r .= '<li><a href="' . hostsite_get_url($args['groups_page_path']) . '">' . lang::get("Return to your recording groups list") . '<a></li>';
     $r .= '</ul>';
     return $r;
 }
 /**
  * Ajax handler to provide the content for the details of a single record.
  */
 public static function ajax_details($website_id, $password, $node)
 {
     $details_report = empty($node->params['record_details_report']) ? 'reports_for_prebuilt_forms/verification_3/record_data' : $node->params['record_details_report'];
     $attrs_report = empty($node->params['record_attrs_report']) ? 'reports_for_prebuilt_forms/verification_3/record_data_attributes' : $node->params['record_attrs_report'];
     iform_load_helpers(array('report_helper'));
     $readAuth = report_helper::get_read_auth($website_id, $password);
     $options = array('dataSource' => $details_report, 'readAuth' => $readAuth, 'sharing' => 'verification', 'extraParams' => array('occurrence_id' => $_GET['occurrence_id'], 'wantColumns' => 1, 'locality_type_id' => variable_get('indicia_profile_location_type_id', 0)));
     $reportData = report_helper::get_report_data($options);
     // set some values which must exist in the record
     $record = array_merge(array('wkt' => '', 'taxon' => '', 'sample_id' => '', 'date' => '', 'entered_sref' => '', 'taxon_external_key' => '', 'taxon_meaning_id' => '', 'record_status' => '', 'zero_abundance' => ''), $reportData['records'][0]);
     // 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();
     $email = '';
     foreach ($reportData['columns'] as $col => $def) {
         if ($def['visible'] !== 'false' && !empty($record[$col])) {
             $caption = explode(':', $def['display']);
             // is this a new heading?
             if (!isset($data[$caption[0]])) {
                 $data[$caption[0]] = array();
             }
             $val = $col === 'record_status' ? self::status_label($record[$col], $record['record_substatus']) : $record[$col];
             $data[$caption[0]][] = array('caption' => $caption[1], 'value' => $val);
         }
         if ($col === 'email' && !empty($record[$col])) {
             $email = $record[$col];
         }
     }
     if ($record['zero_abundance'] === 't') {
         $data['Key facts'][] = array('caption' => lang::get('Absence'), 'value' => lang::get('This is a record indicating absence.'));
     }
     // Do the custom attributes
     $options = array('dataSource' => $attrs_report, 'readAuth' => $readAuth, 'sharing' => 'verification', 'extraParams' => array('occurrence_id' => $_GET['occurrence_id']));
     $reportData = report_helper::get_report_data($options);
     foreach ($reportData as $attribute) {
         if (!empty($attribute['value'])) {
             if (!isset($data[$attribute['attribute_type'] . ' attributes'])) {
                 $data[$attribute['attribute_type'] . ' attributes'] = array();
             }
             $data[$attribute['attribute_type'] . ' attributes'][] = array('caption' => $attribute['caption'], 'value' => $attribute['value']);
         }
     }
     $r = "<table class=\"report-grid\">\n";
     $first = true;
     foreach ($data as $heading => $items) {
         if ($first && !empty($node->params['record_details_path'])) {
             $heading .= ' <a title="View full details of the record" target="_blank" href="' . hostsite_get_url($node->params['record_details_path'], array('occurrence_id' => $_GET['occurrence_id'])) . '"><img src="' . data_entry_helper::$images_path . 'nuvola/find-22px.png" width="22" height="22" /></a>';
             $first = false;
         }
         $r .= "<tr><td colspan=\"2\" class=\"header\">{$heading}</td></tr>\n";
         foreach ($items as $item) {
             if (!is_null($item['value']) && $item['value'] != '') {
                 $value = preg_match('/^http(s)?:\\/\\//', $item['value']) ? "<a href=\"{$item['value']}\" target=\"_blank\">{$item['value']}</a>" : $item['value'];
                 $r .= "<tr><td class=\"caption\">" . $item['caption'] . "</td><td>{$value}</td></tr>\n";
                 if ($email === '' && (strtolower($item['caption']) === 'email' || strtolower($item['caption']) === 'email address')) {
                     $email = $item['value'];
                 }
             }
         }
     }
     $r .= "</table>\n";
     $extra = array();
     $extra['wkt'] = $record['wkt'];
     $extra['taxon'] = $record['taxon'];
     $extra['recorder'] = $record['recorder'];
     $extra['sample_id'] = $record['sample_id'];
     $extra['created_by_id'] = $record['created_by_id'];
     $extra['input_by_first_name'] = $record['input_by_first_name'];
     $extra['input_by_surname'] = $record['input_by_surname'];
     $extra['survey_title'] = $record['survey_title'];
     $extra['survey_id'] = $record['survey_id'];
     $extra['date'] = $record['date'];
     $extra['entered_sref'] = $record['entered_sref'];
     $extra['taxon_external_key'] = $record['taxon_external_key'];
     $extra['taxon_meaning_id'] = $record['taxon_meaning_id'];
     $extra['recorder_email'] = $email;
     $extra['taxon_group'] = $record['taxon_group'];
     $extra['taxon_group_id'] = $record['taxon_group_id'];
     $extra['taxon_list_id'] = $record['taxon_list_id'];
     $extra['localities'] = $record['localities'];
     $extra['locality_ids'] = $record['locality_ids'];
     header('Content-type: application/json');
     echo json_encode(array('content' => $r, 'data' => $data, 'extra' => $extra));
 }