Beispiel #1
0
 /**
  * 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;
 }
 /**
  * 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)
 {
     if (empty($_GET['group_id'])) {
         return 'This page needs a group_id URL parameter.';
     }
     global $base_url;
     global $user;
     iform_load_helpers(array('data_entry_helper'));
     data_entry_helper::$javascript .= "indiciaData.nodeId=" . $node->nid . ";\n";
     data_entry_helper::$javascript .= "indiciaData.baseUrl='" . $base_url . "';\n";
     data_entry_helper::$javascript .= "indiciaData.currentUsername='******';\n";
     //Translations for the comment that goes into occurrence_comments when a record is verified or rejected.
     data_entry_helper::$javascript .= 'indiciaData.verifiedTranslation = "' . lang::get('Verified') . "\";\n";
     data_entry_helper::$javascript .= 'indiciaData.rejectedTranslation = "' . lang::get('Rejected') . "\";\n";
     self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     group_authorise_form($args, self::$auth['read']);
     $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => self::$auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail')));
     $group = $group[0];
     hostsite_set_page_title("{$group['title']}: {$node->title}");
     $def = json_decode($group['filter_definition'], true);
     $defstring = '';
     // reconstruct this as a string to feed into dynamic report explorer
     foreach ($def as $key => $value) {
         if ($key) {
             $value = is_array($value) ? json_encode($value) : $value;
             $defstring .= "{$key}={$value}\n";
             if ($key === 'indexed_location_id' || $key === 'indexed_location_list' || $key === 'location_id' || $key === 'location_list') {
                 $args['location_boundary_id'] = $value;
             } elseif (($key === 'taxon_group_id' || $key === 'taxon_group_list') && strpos($value, ',') === FALSE) {
                 // if the report is locked to a single taxon group, then we don't need taxonomy columns.
                 $args['skipped_report_columns'] = array('taxon_group', 'taxonomy');
             }
         }
     }
     if (empty($_GET['implicit'])) {
         // no need for a group user filter
         $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring));
     } else {
         // filter to group users - either implicitly, or only if they explicitly submitted to the group
         $prefix = $_GET['implicit'] === 'true' || $_GET['implicit'] === 't' ? 'implicit_' : '';
         // add the group parameters to the preset parameters passed to all reports on this page
         $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring, "{$prefix}group_id=" . $_GET['group_id']));
     }
     $args['param_presets'] .= "\n";
     if (!empty($args['hide_standard_param_filter'])) {
         data_entry_helper::$javascript .= "\$('#standard-params').hide();\n";
     }
     return parent::get_form($args, $node);
 }
 /**
  * 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)
 {
     iform_load_helpers(array('import_helper'));
     $auth = import_helper::get_read_write_auth($args['website_id'], $args['password']);
     group_authorise_form($args, $auth['read']);
     if ($args['model'] == 'url') {
         if (!isset($_GET['type'])) {
             return "This form is configured so that it must be called with a type parameter in the URL";
         }
         $model = $_GET['type'];
     } else {
         $model = $args['model'];
     }
     if (isset($args['presetSettings'])) {
         $presets = get_options_array_with_user_data($args['presetSettings']);
         $presets = array_merge(array('website_id' => $args['website_id'], 'password' => $args['password']), $presets);
     } else {
         $presets = array('website_id' => $args['website_id'], 'password' => $args['password']);
     }
     if (!empty($_GET['group_id'])) {
         // loading data into a recording group.
         $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail')));
         $group = $group[0];
         $presets['sample:group_id'] = $_GET['group_id'];
         hostsite_set_page_title(lang::get('Import data into the {1} group', $group['title']));
         // if a single survey specified for this group, then force the data into the correct survey
         $filterdef = json_decode($group['filter_definition'], true);
         if (!empty($filterdef['survey_list_op']) && $filterdef['survey_list_op'] === 'in' && !empty($filterdef['survey_list'])) {
             $surveys = explode(',', $filterdef['survey_list']);
             if (count($surveys) === 1) {
                 $presets['survey_id'] = $surveys[0];
             }
         }
     }
     try {
         $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets));
     } catch (Exception $e) {
         hostsite_show_message($e->getMessage(), 'warning');
         $reload = import_helper::get_reload_link_parts();
         unset($reload['params']['total']);
         unset($reload['params']['uploaded_csv']);
         $reloadpath = $reload['path'] . '?' . import_helper::array_to_query_string($reload['params']);
         $r = "<p>" . lang::get('Would you like to ') . "<a href=\"{$reloadpath}\">" . lang::get('import another file?') . "</a></p>";
     }
     return $r;
 }
 /**
  * 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)
 {
     if (!hostsite_get_user_field('indicia_user_id')) {
         return 'Please ensure that you\'ve filled in your surname on your user profile before creating or editing groups.';
     }
     self::createBreadcrumb($args);
     iform_load_helpers(array('report_helper'));
     report_helper::$website_id = $args['website_id'];
     $auth = report_helper::get_read_write_auth($args['website_id'], $args['password']);
     if (empty($_GET['group_id'])) {
         return 'This form should be called with a group_id parameter';
     }
     $group = self::loadExistingGroup($_GET['group_id'], $auth, $args);
     hostsite_set_page_title(lang::get('Administer {1}', $group['title']));
     report_helper::$javascript .= "indiciaData.website_id={$args['website_id']};\n";
     report_helper::$javascript .= "indiciaData.group_id={$group['id']};\n";
     report_helper::$javascript .= 'indiciaData.ajaxFormPostUrl="' . iform_ajaxproxy_url(null, 'groups_user') . "\";\n";
     if (!empty($args['admin_role_name'])) {
         $adminRoleOnScreenName = $args['admin_role_name'];
     } else {
         $adminRoleOnScreenName = 'administrator';
     }
     if (!empty($args['member_role_name'])) {
         $memberRoleOnScreenName = $args['member_role_name'];
     } else {
         $memberRoleOnScreenName = 'member';
     }
     //Setup actions column
     $actions = array(array('caption' => 'Approve member', 'javascript' => 'approveMember({groups_user_id});', 'visibility_field' => 'pending'));
     if ($adminRoleOnScreenName === 'administrator') {
         $caption = 'Set user to be an ' . $adminRoleOnScreenName;
     } else {
         $caption = 'Set user to be a ' . $adminRoleOnScreenName;
     }
     //Only allow toggle of user's role if page is configured to allow this.
     if (isset($args['allow_role_toggle']) && $args['allow_role_toggle'] == true) {
         $actions[] = array('caption' => $caption, 'javascript' => 'toggleRole({groups_user_id},\'{name}\',\'administrator\');', 'visibility_field' => 'member');
         $actions[] = array('caption' => 'Set user to be a ' . $memberRoleOnScreenName, 'javascript' => 'toggleRole({groups_user_id},\'{name}\',\'member\');', 'visibility_field' => 'administrator');
     }
     //Only allow removal of users if page is configured to allow this.
     if (isset($args['allow_remove']) && $args['allow_remove'] == true) {
         $actions[] = array('caption' => 'Remove from group', 'javascript' => 'removeMember({groups_user_id},\'{name}\');');
     }
     $r = report_helper::report_grid(array('dataSource' => 'library/groups/group_members', 'readAuth' => $auth['read'], 'extraParams' => array('group_id' => $group['id']), 'columns' => array(array('display' => lang::get('Actions'), 'actions' => $actions))));
     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;
 }
Beispiel #7
0
 /**
  * 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.';
     }
     self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => self::$auth['read'] + array('id' => $_GET['group_id'])));
     $group = $group[0];
     hostsite_set_page_title($group['title']);
     $filter = data_entry_helper::get_population_data(array('table' => 'filter', 'extraParams' => self::$auth['read'] + array('id' => $group['filter_id'])));
     $filter = $filter[0];
     $def = json_decode($filter['definition'], true);
     $defstring = '';
     // reconstruct this as a string to feed into dynamic report explorer
     foreach ($def as $key => $value) {
         if ($key) {
             $defstring .= "{$key}={$value}\n";
         }
     }
     // add the group parameters to the preset parameters passed to all reports on this page
     $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring, "group_id=" . $_GET['group_id']));
     return parent::get_form($args, $node);
 }
 /**
  * A page displayed on following an invite link when logged out. Prompts login. If a login block is on the 
  * page, then the user can log in whilst on the page and the user can then immediately accept the invite.
  * @param array $invite Invitation record
  * @param array $auth Authorisation tokens
  * @return string HTML to add to the page.
  */
 private static function logged_out_page($invite, $auth)
 {
     $r = '<p>' . lang::get('If you would like to join the {1} group called {2} then please log in or register an account for {3} then ' . 'follow the link in your invitation email again once registered.', variable_get('site_name', ''), $invite['group_title'], variable_get('site_name', '')) . '</p>';
     hostsite_set_page_title(lang::get('Invitation to join {1}', $invite['group_title']));
     return $r;
 }
 /**
  * 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)
 {
     $conn = iform_get_connection_details($node);
     data_entry_helper::$js_read_tokens = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']);
     if (!empty($_POST) && !empty($_POST['format'])) {
         self::do_data_services_download($args, $node);
     }
     $conn = iform_get_connection_details($node);
     data_entry_helper::$js_read_tokens = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']);
     $types = self::get_download_types($args);
     $formats = self::get_download_formats($args);
     if (count($types) === 0) {
         return 'This download page is configured so that no download type options are available.';
     }
     if (count($formats) === 0) {
         return 'This download page is configured so that no download format options are available.';
     }
     $reload = data_entry_helper::get_reload_link_parts();
     $reloadPath = $reload['path'];
     if (count($reload['params'])) {
         $reloadPath .= '?' . helper_base::array_to_query_string($reload['params']);
     }
     $r = '<form method="POST" action="' . $reloadPath . '">';
     $r .= '<fieldset id="download-type-fieldset"><legend>' . lang::get('Records to download') . '</legend>';
     if (count($types) === 1) {
         $r .= '<input type="hidden" name="download-type" id="download-type" value="' . implode('', array_keys($types)) . '"/>';
         hostsite_set_page_title(lang::get('Download {1}', strtolower(implode('', $types))));
     } else {
         $r .= data_entry_helper::select(array('fieldname' => 'download-type', 'label' => lang::get('Download type'), 'lookupValues' => $types, 'class' => 'control-width-5', 'helpText' => 'Select the type of download you require, i.e. the purpose for the data. This defines which records are available to download.'));
     }
     $r .= data_entry_helper::select(array('fieldname' => 'download-subfilter', 'label' => lang::get('Filter to apply'), 'lookupValues' => array(), 'class' => 'control-width-5', 'helpText' => lang::get('Optionally select from the available filters. Filters you create on the Explore pages will be available here.')));
     $r .= "</fieldset>\n";
     $r .= '<fieldset><legend>' . lang::get('Limit the records') . '</legend>';
     if (empty($args['survey_id'])) {
         // put up an empty surveys drop down. AJAX will populate it.
         $r .= data_entry_helper::select(array('fieldname' => 'survey_id', 'label' => lang::get('Survey to include'), 'helpText' => 'Choose a survey, or <all> to not filter by survey.', 'lookupValues' => array(), 'class' => 'control-width-5'));
     } else {
         $r .= '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '"/>';
     }
     // Let the user pick the date range to download.
     $r .= data_entry_helper::select(array('label' => lang::get('Date field'), 'fieldname' => 'date_type', 'lookupValues' => array('recorded' => lang::get('Field record date'), 'input' => lang::get('Input date'), 'edited' => lang::get('Last changed date'), 'verified' => 'Verification status change date'), 'helpText' => 'If filtering on date, which date field would you like to filter on?'));
     $r .= data_entry_helper::date_picker(array('fieldname' => 'date_from', 'label' => lang::get('Start Date'), 'helpText' => 'Leave blank for no start date filter', 'class' => 'control-width-4'));
     $r .= data_entry_helper::date_picker(array('fieldname' => 'date_to', 'label' => lang::get('End Date'), 'helpText' => 'Leave blank for no end date filter', 'class' => 'control-width-4'));
     $r .= '</fieldset>';
     if (!empty($args['custom_formats'])) {
         $customFormats = json_decode($args['custom_formats'], true);
         foreach ($customFormats as $idx => $format) {
             if (empty($format['permission']) || user_access($format['permission'])) {
                 $formats["custom-{$idx}"] = lang::get(isset($format['title']) ? $format['title'] : 'Untitled format');
             }
         }
     }
     if (count($formats) > 1) {
         $r .= '<fieldset><legend>' . lang::get('Select a format to download') . '</legend>';
         $keys = array_keys($formats);
         $r .= data_entry_helper::radio_group(array('fieldname' => 'format', 'lookupValues' => $formats, 'default' => $keys[0]));
         $r .= '</fieldset>';
     } else {
         // only allowed 1 format, so no need for a selection control
         $keys = array_keys($formats);
         $r .= '<input type="hidden" name="format" value="' . array_pop($keys) . '"/>';
     }
     $r .= '<input type="submit" value="' . lang::get('Download') . '"/></form>';
     data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/easy_download_2') . "\";\n";
     data_entry_helper::$javascript .= 'indiciaData.nid = "' . $node->nid . "\";\n";
     data_entry_helper::$javascript .= "setAvailableDownloadFilters();\n";
     return $r;
 }
 /**
  * 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)
 {
     if (!hostsite_get_user_field('indicia_user_id')) {
         return 'Please ensure that you\'ve filled in your surname on your user profile before creating or editing groups.';
     }
     self::createBreadcrumb($args);
     iform_load_helpers(array('report_helper', 'map_helper'));
     $args = array_merge(array('include_code' => false, 'include_dates' => false, 'include_logo_controls' => true, 'include_sensitivity_controls' => true, 'include_report_filter' => true, 'include_linked_pages' => true, 'include_private_records' => false, 'include_administrators' => false, 'include_members' => false, 'filter_types' => '{"":"what,where,when","Advanced":"source,quality"}', 'indexed_location_type_ids' => '', 'other_location_type_ids' => '', 'data_inclusion_mode' => 'choose'), $args);
     $args['filter_types'] = json_decode($args['filter_types'], true);
     $reloadPath = self::getReloadPath();
     data_entry_helper::$website_id = $args['website_id'];
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     if (!empty($_GET['group_id'])) {
         self::loadExistingGroup($_GET['group_id'], $auth, $args);
     }
     // maintain compatibility with form settings from before group type became multiselect.
     if (empty($args['group_type'])) {
         $args['group_type'] = array();
     } elseif (!is_array($args['group_type'])) {
         $args['group_type'] = array($args['group_type']);
     }
     if (count($args['group_type']) === 1) {
         $response = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $auth['read'] + array('id' => $args['group_type'][0])));
         self::$groupType = strtolower($response[0]['term']);
     }
     self::$groupType = lang::get(self::$groupType);
     $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\" enctype=\"multipart/form-data\">\n";
     $r .= '<fieldset><legend>' . lang::get('Fill in details of your {1} below', self::$groupType) . '</legend>';
     $r .= $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n";
     $r .= data_entry_helper::hidden_text(array('fieldname' => 'group:id'));
     // if a fixed choice of group type, can use a hidden input to put the value in the form.
     if (count($args['group_type']) === 1) {
         $r .= '<input type="hidden" name="group:group_type_id" value="' . $args['group_type'][0] . '"/>';
     }
     if (!empty(data_entry_helper::$entity_to_load['group:title'])) {
         hostsite_set_page_title(lang::get('Edit {1}', data_entry_helper::$entity_to_load['group:title']));
     }
     $r .= data_entry_helper::text_input(array('label' => lang::get('{1} name', ucfirst(self::$groupType)), 'fieldname' => 'group:title', 'validation' => array('required'), 'class' => 'control-width-6', 'helpText' => lang::get('Provide the full title of the {1}', self::$groupType)));
     if ($args['include_code']) {
         $r .= data_entry_helper::text_input(array('label' => lang::get('Code'), 'fieldname' => 'group:code', 'class' => 'control-width-4', 'helpText' => lang::get('Provide a code or abbreviation identifying the {1}', self::$groupType)));
     }
     $r .= data_entry_helper::textarea(array('label' => ucfirst(lang::get('{1} description', self::$groupType)), 'fieldname' => 'group:description', 'helpText' => lang::get('LANG_Description_Field_Instruct', self::$groupType), 'class' => 'control-width-6'));
     // If adding a new group which should have a parent group of some type or other, but no parent
     // group is specified in the from_group_id parameter, then let the user pick a group to link as the parent.
     if (empty($_GET['group_id']) && !empty($args['parent_group_type']) && !empty($args['parent_group_relationship_type']) && empty($_REQUEST['from_group_id'])) {
         // There should be a parent group, but none provided, so allow the user to pick one.
         $r .= data_entry_helper::select(array('label' => ucfirst(lang::get('{1} parent', self::$groupType)), 'fieldname' => 'from_group_id', 'table' => 'groups_user', 'captionField' => 'title', 'valueFields' => 'group_id', 'extraParams' => $auth['read'] + array('group_type_id' => $args['parent_group_type'], 'user_id' => hostsite_get_user_field('indicia_user_id'), 'view' => 'detail'), 'validation' => array('required'), 'blankText' => lang::get('<please select>')));
     }
     if (count($args['group_type']) !== 1) {
         $params = array('termlist_external_key' => 'indicia:group_types', 'orderby' => 'sortorder,term');
         if (!empty($args['group_type'])) {
             $params['query'] = json_encode(array('in' => array('id' => array_values($args['group_type']))));
         }
         $r .= data_entry_helper::select(array('label' => ucfirst(lang::get('{1} type', self::$groupType)), 'fieldname' => 'group:group_type_id', 'validation' => array('required'), 'table' => 'termlists_term', 'valueField' => 'id', 'captionField' => 'term', 'extraParams' => $auth['read'] + $params, 'class' => 'control-width-4', 'blankText' => lang::get('<please select>'), 'helpText' => lang::get('What sort of {1} is it?', self::$groupType)));
     }
     $r .= self::groupLogoControl($args);
     $r .= self::joinMethodsControl($args);
     if ($args['include_sensitivity_controls']) {
         $r .= data_entry_helper::checkbox(array('label' => lang::get('Show records at full precision'), 'fieldname' => 'group:view_full_precision', 'helpText' => lang::get('Any sensitive records added to the system are normally shown blurred to a lower grid reference precision. If this box ' . 'is checked, then group members can see sensitive records explicitly posted for the {1} at full precision.', self::$groupType)));
     }
     $r .= self::dateControls($args);
     if ($args['include_private_records']) {
         $r .= data_entry_helper::checkbox(array('label' => lang::get('Records are private'), 'fieldname' => 'group:private_records', 'helpText' => lang::get('Tick this box if you want to withold the release of the records from this {1} until a ' . 'later point in time, e.g. when a project is completed.', self::$groupType)));
         // If an existing group with private records, then we might need to display a message warning the user about releasing the records.
         // Initially hidden, we use JS to display it when appropriate.
         if (!empty(data_entry_helper::$entity_to_load['group:id']) && data_entry_helper::$entity_to_load['group:private_records'] === 't') {
             $r .= '<p class="warning" style="display: none" id="release-warning">' . lang::get('You are about to release the records belonging to this group. Do not proceed unless you intend to do this!') . '</p>';
         }
     }
     $r .= self::memberControls($args, $auth);
     $r .= '</fieldset>';
     $r .= self::reportFilterBlock($args, $auth, $hiddenPopupDivs);
     $r .= self::inclusionMethodControl($args);
     $r .= self::formsBlock($args, $auth, $node);
     // auto-insert the creator as an admin of the new group, unless the admins are manually specified
     if (!$args['include_administrators'] && empty($_GET['group_id'])) {
         $r .= '<input type="hidden" name="groups_user:admin_user_id[]" value="' . hostsite_get_user_field('indicia_user_id') . '"/>';
     }
     $r .= '<input type="hidden" name="groups_user:administrator" value="t"/>';
     $r .= '<input type="submit" class="indicia-button" id="save-button" value="' . (empty(data_entry_helper::$entity_to_load['group:id']) ? lang::get('Create {1}', self::$groupType) : lang::get('Update {1} settings', self::$groupType)) . "\" />\n";
     $r .= '</form>';
     $r .= $hiddenPopupDivs;
     data_entry_helper::enable_validation('entry_form');
     // JavaScript to grab the filter definition and store in the form for posting when the form is submitted
     data_entry_helper::$javascript .= "\r\n\$('#entry_form').submit(function() {\r\n  \$('#filter-title-val').val('" . lang::get('Filter for user group') . " ' + \$('#group\\\\:title').val() + ' ' + new Date().getTime());\r\n  \$('#filter-def-val').val(JSON.stringify(indiciaData.filter.def));\r\n});\n";
     // for existing groups, prevent removal of yourself as a member. Someone else will have to do this for you so we don't orphan groups.
     if (!empty(data_entry_helper::$entity_to_load['group:id'])) {
         data_entry_helper::$javascript .= "\$('#groups_user\\\\:admin_user_id\\\\:sublist input[value=" . hostsite_get_user_field('indicia_user_id') . "]').closest('li').children('span').remove();\n";
     }
     return $r;
 }
 /**
  * Sets the page title according to an option. The title can refer to the URL query
  * string parameters as tokens.
  * @param $auth
  * @param $args
  * @param $tabalias
  * @param $options
  * @param $path
  * @return string
  */
 public static function set_page_title($auth, $args, $tabalias, $options, $path)
 {
     if (!isset($options['title'])) {
         return 'Please set the template for the title in the @title parameter';
     }
     foreach ($_GET as $key => $value) {
         $options['title'] = str_replace("#{$key}#", $value, $options['title']);
     }
     hostsite_set_page_title($options['title']);
     return '';
 }
 /**
  * Override the get_form_html function.
  * getForm in dynamic.php will now call this.
  * Vary the display of the page based on the interface type
  * 
  * @package    Client
  * @subpackage PrebuiltForms
  */
 protected static function get_form_html($args, $auth, $attributes)
 {
     if (isset($_POST['enable'])) {
         module_enable(array('iform_ajaxproxy'));
         drupal_set_message(lang::get('The Indicia AJAX Proxy module has been enabled.', 'info'));
     }
     if (!defined('IFORM_AJAXPROXY_PATH')) {
         $r = '<p>' . lang::get('The Indicia AJAX Proxy module must be enabled to use this form. This lets the form save verifications to the ' . 'Indicia Warehouse without having to reload the page.') . '</p>';
         $r .= '<form method="post">';
         $r .= '<input type="hidden" name="enable" value="t"/>';
         $r .= '<input type="submit" value="' . lang::get('Enable Indicia AJAX Proxy') . '"/>';
         $r .= '</form>';
         return $r;
     }
     if (empty($_GET['taxa_taxon_list_id']) && empty($_GET['taxon_meaning_id'])) {
         return 'This form requires a taxa_taxon_list_id or taxon_meaning_id parameter in the URL.';
     }
     self::get_names($auth);
     hostsite_set_page_title(lang::get('Summary details for {1}', self::$preferred));
     return parent::get_form_html($args, $auth, $attributes);
 }
Beispiel #13
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;
 }
 /**
  * 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 $nid The Drupal node object's ID.
  * @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, $nid, $response = null)
 {
     drupal_add_js(iform_client_helpers_path() . "prebuilt_forms/js/easy_download_2.js");
     drupal_add_css(iform_client_helpers_path() . "prebuilt_forms/css/easy_download_2.css");
     $conn = iform_get_connection_details($nid);
     $args = array_merge(array('download_administered_groups' => 'indicia data admin', 'download_group_types' => ''), $args);
     $readAuth = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']);
     if (data_entry_helper::$js_read_tokens === null) {
         data_entry_helper::$js_read_tokens = $readAuth;
     }
     if (!empty($_POST) && !empty($_POST['format'])) {
         self::do_data_services_download($args, $nid);
     }
     $types = self::get_download_types($args);
     $formats = self::get_download_formats($args);
     if (count($types) === 0) {
         return 'This download page is configured so that no download type options are available.';
     }
     if (count($formats) === 0) {
         return 'This download page is configured so that no download format options are available.';
     }
     $reload = data_entry_helper::get_reload_link_parts();
     $reloadPath = $reload['path'];
     if (count($reload['params'])) {
         $reloadPath .= '?' . helper_base::array_to_query_string($reload['params']);
     }
     $r = '<form method="POST" action="' . $reloadPath . '">';
     $r .= '<fieldset id="download-type-fieldset"><legend>' . lang::get('Records to download') . '</legend>';
     if (count($types) === 1) {
         $r .= '<input type="hidden" name="download-type" id="download-type" value="' . implode('', array_keys($types)) . '"/>';
         hostsite_set_page_title(lang::get('Download {1}', strtolower(implode('', $types))));
     } else {
         $r .= data_entry_helper::select(array('fieldname' => 'download-type', 'label' => lang::get('Download type'), 'lookupValues' => $types, 'class' => 'control-width-5', 'helpText' => 'Select the type of download you require, i.e. the purpose for the data. This defines which records are available to download.'));
     }
     $r .= data_entry_helper::select(array('fieldname' => 'download-subfilter', 'label' => lang::get('Filter to apply'), 'lookupValues' => array(), 'class' => 'control-width-5', 'helpText' => lang::get('Optionally select from the available filters. Filters you create on the Explore pages will be available here.')));
     $r .= "</fieldset>\n";
     $r .= '<fieldset><legend>' . lang::get('Limit the records') . '</legend>';
     // Hub
     // TODO may run into URL size limits
     $vocabulary = taxonomy_vocabulary_machine_name_load('hubs');
     $terms = entity_load('taxonomy_term', FALSE, array('vid' => $vocabulary->vid));
     // the hub is driven by a user field, stored as tid.
     $hubList = array('' => lang::get('<All>'));
     foreach ($terms as $term) {
         // TODO Cache
         $query = new EntityFieldQuery();
         $query->entityCondition('entity_type', 'user')->fieldCondition('field_preferred_training_hub', 'tid', $term->tid);
         $result = $query->execute();
         // This gives us the list of users which are in the hub: CMS user ID: now convert to indicia user id
         $userIDList = array();
         if (count($result) > 0) {
             $cmsUserIDs = array_keys($result['user']);
             foreach ($cmsUserIDs as $cmsUserID) {
                 $user_data = user_load($cmsUserID);
                 // TODO Making assumption about language
                 if (!empty($user_data->field_indicia_user_id['und'][0]['value'])) {
                     $userIDList[] = $user_data->field_indicia_user_id['und'][0]['value'];
                 }
             }
             if (count($userIDList) > 0) {
                 $hubList[implode(',', $userIDList)] = $term->tid . ' ' . $term->name;
             }
         }
     }
     $r .= data_entry_helper::select(array('fieldname' => 'user_id_list', 'label' => lang::get('Hub to include'), 'helpText' => 'Choose a Hub, or &lt;All&gt; to not filter by Hub. This is driven off the users currently allocated to the hub. This currently does not apply to the NBN download.', 'lookupValues' => $hubList, 'class' => 'control-width-5'));
     // End Cocoast Hub
     if (empty($args['survey_id'])) {
         // put up an empty surveys drop down. AJAX will populate it.
         $r .= data_entry_helper::select(array('fieldname' => 'survey_id', 'label' => lang::get('Survey to include'), 'helpText' => 'Choose a survey, or &lt;All&gt; to not filter by survey.', 'lookupValues' => array(), 'class' => 'control-width-5'));
     } else {
         $r .= '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '"/>';
     }
     // Let the user pick the date range to download.
     $r .= data_entry_helper::select(array('label' => lang::get('Date field'), 'fieldname' => 'date_type', 'lookupValues' => array('recorded' => lang::get('Field record date'), 'input' => lang::get('Input date'), 'edited' => lang::get('Last changed date'), 'verified' => 'Verification status change date'), 'helpText' => 'If filtering on date, which date field would you like to filter on?'));
     $r .= data_entry_helper::date_picker(array('fieldname' => 'date_from', 'label' => lang::get('Start Date'), 'helpText' => 'Leave blank for no start date filter', 'class' => 'control-width-4'));
     $r .= data_entry_helper::date_picker(array('fieldname' => 'date_to', 'label' => lang::get('End Date'), 'helpText' => 'Leave blank for no end date filter', 'class' => 'control-width-4'));
     $r .= '</fieldset>';
     if (!empty($args['custom_formats'])) {
         $customFormats = json_decode($args['custom_formats'], true);
         foreach ($customFormats as $idx => $format) {
             if (empty($format['permission']) || hostsite_user_has_permission($format['permission'])) {
                 $formats["custom-{$idx}"] = lang::get(isset($format['title']) ? $format['title'] : 'Untitled format');
             }
         }
     }
     if (count($formats) > 1) {
         $r .= '<fieldset><legend>' . lang::get('Select a format to download') . '</legend>';
         $keys = array_keys($formats);
         $r .= data_entry_helper::radio_group(array('fieldname' => 'format', 'lookupValues' => $formats, 'default' => $keys[0]));
         $r .= '</fieldset>';
     } else {
         // only allowed 1 format, so no need for a selection control
         $keys = array_keys($formats);
         $r .= '<input type="hidden" name="format" value="' . array_pop($keys) . '"/>';
     }
     $r .= '<input type="submit" value="' . lang::get('Download') . '"/></form>';
     data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/easy_download_2') . "\";\n";
     data_entry_helper::$javascript .= 'indiciaData.nid = "' . $nid . "\";\n";
     data_entry_helper::$javascript .= "setAvailableDownloadFilters();\n";
     return $r;
 }
 /**
  * Draw Record Details section of the page.
  * @return string The output freeform report.
  * 
  * @package    Client
  * @subpackage PrebuiltForms
  */
 protected static function get_control_recorddetails($auth, $args, $tabalias, $options)
 {
     iform_load_helpers(array('report_helper'));
     $options = array_merge(array('dataSource' => 'reports_for_prebuilt_forms/record_details_2/record_data_attributes_with_hiddens'), $options);
     $fields = helper_base::explode_lines($args['fields']);
     $fieldsLower = helper_base::explode_lines(strtolower($args['fields']));
     //Draw the Record Details, but only if they aren't requested as hidden by the administrator
     $attrsTemplate = '<div class="field ui-helper-clearfix"><span>{caption}</span><span{class}>{value}</span></div>';
     $test = $args['operator'] === 'in';
     $availableFields = array('sensitive' => 'Sensitive', 'occurrence_id' => 'Record ID', 'taxon' => 'Species', 'preferred_taxon' => 'Preferred species name', 'taxonomy' => 'Taxonomy', 'survey_title' => 'Survey', 'recorder' => 'Recorder', 'inputter' => 'Input by', 'record_status' => 'Record status', 'verifier' => 'Verified by', 'date' => 'Date', 'entered_sref' => 'Grid ref', 'occurrence_comment' => 'Record comment', 'location_name' => 'Site name', 'sample_comment' => 'Sample comment');
     if (!empty(self::$record['sensitivity_precision'])) {
         unset($availableFields['recorder']);
         unset($availableFields['inputter']);
         unset($availableFields['entered_sref']);
         unset($availableFields['occurrence_comment']);
         unset($availableFields['location_name']);
         unset($availableFields['sample_comment']);
     }
     self::load_record($auth, $args);
     $details_report = '<div class="record-details-fields ui-helper-clearfix">';
     foreach ($availableFields as $field => $caption) {
         if ($caption === 'Species') {
             $title = lang::get('Record of {1}', self::$record[$field]);
             hostsite_set_page_title($title);
         }
         if ($test === in_array(strtolower($caption), $fieldsLower) && !empty(self::$record[$field])) {
             // special case, sensitive icon
             $class = self::$record[$field] === 'This record is sensitive' ? ' class="ui-state-error"' : '';
             $caption = self::$record[$field] === 'This record is sensitive' ? '' : "{$caption}:";
             $details_report .= str_replace(array('{caption}', '{value}', '{class}'), array(lang::get($caption), lang::get(self::$record[$field]), $class), $attrsTemplate);
         }
     }
     $created = date('jS F Y \\a\\t H:i', strtotime(self::$record['created_on']));
     $updated = date('jS F Y \\a\\t H:i', strtotime(self::$record['updated_on']));
     $dateInfo = lang::get('Entered on {1}', $created);
     if ($created !== $updated) {
         $dateInfo .= lang::get(' and last updated on {1}', $updated);
     }
     if ($test === in_array('submission date', $fieldsLower)) {
         $details_report .= str_replace(array('{caption}', '{value}', '{class}'), array(lang::get('Submission date'), $dateInfo, ''), $attrsTemplate);
     }
     $details_report .= '</div>';
     if (!self::$record['sensitivity_precision']) {
         //draw any custom attributes added by the user, but only for a non-sensitive record
         $attrs_report = report_helper::freeform_report(array('readAuth' => $auth['read'], 'class' => 'record-details-fields ui-helper-clearfix', 'dataSource' => $options['dataSource'], 'bands' => array(array('content' => str_replace('{class}', '', $attrsTemplate))), 'extraParams' => array('occurrence_id' => $_GET['occurrence_id'], 'attrs' => strtolower(self::convert_array_to_set($fields)), 'testagainst' => $args['testagainst'], 'operator' => $args['operator'], 'sharing' => 'reporting')));
     }
     $r = '<div class="detail-panel" id="detail-panel-recorddetails"><h3>Record Details</h3>';
     $r .= $details_report;
     if (isset($attrs_report)) {
         $r .= $attrs_report;
     }
     $r .= '</div>';
     return $r;
 }
 public static function points_editor($auth, $args, $tabalias, $options, $path)
 {
     if (!empty($_GET['dynamic-transect'])) {
         $tokens = explode(':', $_GET['dynamic-transect']);
         hostsite_set_page_title('Review points for transect ' . $tokens[2] . ' of survey ' . $tokens[1] . ' by group ' . $tokens[0]);
     }
     hostsite_set_breadcrumb(array('Review transect lines' => 'data/review-transect-lines'));
     data_entry_helper::$javascript .= "mapInitialisationHooks.push(drawPoints);\n";
     data_entry_helper::$javascript .= "indiciaData.website_id={$args['website_id']};\n";
     data_entry_helper::$javascript .= 'indiciaData.ajaxFormPostUrl="' . iform_ajaxproxy_url(null, 'sample') . "\";\n";
     return '';
 }