コード例 #1
0
ファイル: groups.php プロジェクト: BirenRathod/indicia-code
/**
 * List of methods that assist with handling recording groups.
 * @package Client
 * @subpackage PrebuiltForms.
 */
function group_authorise_form($args, $readAuth)
{
    if (!empty($args['limit_to_group_id']) && $args['limit_to_group_id'] !== (empty($_GET['group_id']) ? '' : $_GET['group_id'])) {
        // page owned by a different group, so throw them out
        hostsite_show_message(lang::get('This page is a private recording group page which you cannot access.'), 'alert');
        hostsite_goto_page('<front>');
    }
    if (!empty($_GET['group_id'])) {
        // loading data into a recording group. Are they a member or is the page public?
        // @todo: consider performance - 2 web services hits required to check permissions.
        if (hostsite_get_user_field('indicia_user_id')) {
            $gu = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id')), 'nocache' => true));
        } else {
            $gu = array();
        }
        $gp = data_entry_helper::get_population_data(array('table' => 'group_page', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'path' => drupal_get_path_alias($_GET['q']))));
        if (count($gp) === 0) {
            hostsite_show_message(lang::get('You are trying to access a page which is not available for this group.'), 'alert');
            hostsite_goto_page('<front>');
        } elseif (count($gu) === 0 && $gp[0]['administrator'] !== NULL) {
            // not a group member, so throw them out
            hostsite_show_message(lang::get('You are trying to access a page for a group you do not belong to.'), 'alert');
            hostsite_goto_page('<front>');
        }
    }
}
コード例 #2
0
 /**
  * Get the control for species input, either a grid or a single species input control.
  */
 protected static function get_control_species($auth, $args, $tabAlias, $options)
 {
     global $user;
     $extraParams = $auth['read'];
     $extraParams['preferred'] = "true";
     // Build the configuration options
     if (isset($options['view'])) {
         $extraParams['view'] = $options['view'];
     }
     // There may be options in the form occAttr:n|param => value targetted at specific attributes
     $occAttrOptions = array();
     // make sure that if extraParams is specified as a config option, it does not replace the essential stuff
     if (isset($options['extraParams'])) {
         $options['extraParams'] = array_merge($extraParams, $options['extraParams']);
     }
     $species_ctrl_opts = array_merge(array('occAttrOptions' => $occAttrOptions, 'listId' => $args['list_id'], 'label' => lang::get('occurrence:taxa_taxon_list_id'), 'columns' => 1, 'extraParams' => $extraParams, 'survey_id' => $args['survey_id'], 'language' => iform_lang_iso_639_2(hostsite_get_user_field('language'))), $options);
     if ($groups = hostsite_get_user_field('taxon_groups')) {
         $species_ctrl_opts['usersPreferredGroups'] = unserialize($groups);
     }
     if (isset($args['col_widths']) && $args['col_widths']) {
         $species_ctrl_opts['colWidths'] = explode(',', $args['col_widths']);
     }
     call_user_func(array(self::$called_class, 'build_grid_taxon_label_function'), $args, $options);
     if (self::$mode == self::MODE_CLONE) {
         $species_ctrl_opts['useLoadedExistingRecords'] = true;
     }
     // Start by outputting a hidden value that tells us we are using a grid when the data is posted,
     // then output the grid control
     return '<input type="hidden" value="true" name="gridmode" />' . self::my_species_checklist($species_ctrl_opts);
 }
コード例 #3
0
 /**
  * Preparing to display an existing sample with occurrences.
  * When displaying a grid of occurrences, just load the sample and data_entry_helper::species_checklist
  * will load the occurrences.
  * When displaying just one occurrence we must load the sample and the occurrence
  */
 protected static function getEntity($args, $auth)
 {
     data_entry_helper::$entity_to_load = array();
     // If we know the occurrence ID but not the sample, we must look it up
     if (self::$loadedOccurrenceId && !self::$loadedSampleId) {
         $response = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('id' => self::$loadedOccurrenceId, 'view' => 'detail')));
         if (count($response) != 0) {
             //we found an occurrence
             self::$loadedSampleId = $response[0]['sample_id'];
         }
     }
     // Load the sample record
     if (self::$loadedSampleId) {
         data_entry_helper::load_existing_record($auth['read'], 'sample', self::$loadedSampleId, 'detail', false, true);
     }
     // Ensure that if we are used to load a different survey's data, then we get the correct survey attributes. We can change args
     // because the caller passes by reference.
     if ($args['survey_id'] != data_entry_helper::$entity_to_load['sample:survey_id']) {
         throw new exception(lang::get('Attempt to access a record on a different survey.'));
     }
     if ($args['sample_method_id'] != data_entry_helper::$entity_to_load['sample:sample_method_id']) {
         throw new exception(lang::get('Attempt to access a record with the wrong sample_method_id.'));
     }
     // enforce that people only access their own data, unless explicitly have permissions
     $editor = !empty($args['edit_permission']) && function_exists('user_access') && user_access($args['edit_permission']);
     if (!$editor && function_exists('hostsite_get_user_field') && data_entry_helper::$entity_to_load['sample:created_by_id'] != 1 && data_entry_helper::$entity_to_load['sample:created_by_id'] !== hostsite_get_user_field('indicia_user_id')) {
         throw new exception(lang::get('Attempt to access a record you did not create.'));
     }
 }
コード例 #4
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)
 {
     if (!($user_id = hostsite_get_user_field('indicia_user_id'))) {
         return self::abort('Please ensure that you\'ve filled in your surname on your user profile before joining a group.', $args);
     }
     if (empty($_GET['group_id'])) {
         return self::abort('This form must be called with a group_id in the URL parameters.', $args);
     }
     $r = '';
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id']), 'nocache' => true));
     if (count($group) !== 1) {
         return self::abort('The group you\'ve requested membership of does not exist.', $args);
     }
     iform_load_helpers(array('submission_builder'));
     $group = $group[0];
     // Check for an existing group user record
     $existing = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $auth['read'] + array('group_id' => $_GET['group_id'], 'user_id' => $user_id), 'nocache' => true));
     if (count($existing)) {
         if ($existing[0]['pending'] === 'true') {
             // if a previous request was made and unapproved when the group was request only, but the group is now public, we can approve their existing
             // groups_user record.
             if ($group['joining_method'] === 'P') {
                 $data = array('groups_user:id' => $existing[0]['id'], 'groups_user:pending' => 'f');
                 $wrap = submission_builder::wrap($data, 'groups_user');
                 $r = data_entry_helper::forward_post_to('groups_user', $wrap, $auth['write_tokens']);
                 return self::success($auth, $group, $args);
             } else {
                 return self::abort("You've already got a membership request for {$group['title']} pending approval.", $args);
             }
         } else {
             return self::abort("You're already a member of {$group['title']}.", $args);
         }
     } else {
         $data = array('groups_user:group_id' => $group['id'], 'groups_user:user_id' => $user_id);
         // request only, so make the groups_user record pending approval
         if ($group['joining_method'] === 'R') {
             $data['groups_user:pending'] = 't';
         }
         $wrap = submission_builder::wrap($data, 'groups_user');
         $r = data_entry_helper::forward_post_to('groups_user', $wrap, $auth['write_tokens']);
         if (!isset($r['success'])) {
             return self::abort('An error occurred whilst trying to update your group membership.', $args);
         } elseif ($group['joining_method'] === 'R') {
             return self::abort("Your request to join {$group['title']} is now awaiting approval.", $args);
         } else {
             return self::success($auth, $group, $args);
         }
     }
     return $r;
 }
コード例 #5
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)
 {
     if (!($user_id = hostsite_get_user_field('indicia_user_id'))) {
         return self::abort('Please ensure that you\'ve filled in your surname on your user profile before leaving a group.', $args);
     }
     if (empty($_GET['group_id'])) {
         return self::abort('This form must be called with a group_id in the URL parameters.', $args);
     }
     $r = '';
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id']), 'nocache' => true));
     if (count($group) !== 1) {
         return self::abort('The group you\'ve requested membership of does not exist.', $args);
     }
     iform_load_helpers(array('submission_builder'));
     $group = $group[0];
     // Check for an existing group user record
     $existing = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $auth['read'] + array('group_id' => $_GET['group_id'], 'user_id' => $user_id), 'nocache' => true));
     if (count($existing) !== 1) {
         return self::abort('You are not a member of this group.', $args);
     }
     if (!empty($_POST['response']) && $_POST['response'] === lang::get('Cancel')) {
         drupal_goto($args['groups_page_path']);
     } elseif (!empty($_POST['response']) && $_POST['response'] === lang::get('Confirm')) {
         $data = array('groups_user:id' => $existing[0]['id'], 'groups_user:group_id' => $group['id'], 'groups_user:user_id' => $user_id, 'deleted' => 't');
         $wrap = submission_builder::wrap($data, 'groups_user');
         $response = data_entry_helper::forward_post_to('groups_user', $wrap, $auth['write_tokens']);
         if (isset($response['success'])) {
             hostsite_show_message("You are no longer participating in {$group['title']}!");
             drupal_goto($args['groups_page_path']);
         } else {
             return self::abort('An error occurred whilst trying to update your group membership.');
         }
     } else {
         // First access of the form. Let's get confirmation
         $reload = data_entry_helper::get_reload_link_parts();
         $reloadpath = $reload['path'] . '?' . data_entry_helper::array_to_query_string($reload['params']);
         $r = '<form action="' . $reloadpath . '" method="POST"><fieldset>';
         $r .= '<legend>' . lang::get('Confirmation') . '</legend>';
         $r .= '<input type="hidden" name="leave" value="1" />';
         $r .= '<p>' . lang::get('Are you sure you want to stop participating in {1}?', $group['title']) . '</p>';
         $r .= '<input type="submit" value="' . lang::get('Confirm') . '" name="response" />';
         $r .= '<input type="submit" value="' . lang::get('Cancel') . '" name="response" />';
         $r .= '</fieldset></form>';
     }
     return $r;
 }
コード例 #6
0
 /**
  * Clears moderation notifications for a moderator automatically on visiting the page, so then they
  * will get notified about new incoming records.
  */
 public static function clear_moderation_task_notifications($auth, $args, $tabalias, $options, $path)
 {
     //Using 'submission_list' and 'entries' allows us to specify several top-level submissions to the system
     //i.e. we need to be able to submit several notifications.
     $submission['submission_list']['entries'] = array();
     $submission['id'] = 'notification';
     $notifications = data_entry_helper::get_population_data(array('table' => 'notification', 'extraParams' => $auth['read'] + array('acknowledged' => 'f', 'user_id' => hostsite_get_user_field('indicia_user_id'), 'source_type' => 'PT'), 'nocache' => true));
     if (count($notifications) > 0) {
         $auth = data_entry_helper::get_read_write_auth(variable_get('indicia_website_id', 0), variable_get('indicia_password', ''));
         //Setup the structure we need to submit.
         foreach ($notifications as $notification) {
             $data['id'] = 'notification';
             $data['fields']['id']['value'] = $notification['id'];
             $data['fields']['acknowledged']['value'] = 't';
             $submission['submission_list']['entries'][] = $data;
         }
         //Submit the stucture for processing
         $response = data_entry_helper::forward_post_to('save', $submission, $auth['write_tokens']);
         if (!is_array($response) || !array_key_exists('success', $response)) {
             drupal_set_message(print_r($response, true));
         }
     }
     return '';
 }
コード例 #7
0
 /**
  * Return the generated form output.
  * @return Form HTML.
  * @todo: Implement this method
  */
 public static function get_form($args)
 {
     $lang = iform_lang_iso_639_2(hostsite_get_user_field('language', 'en'));
     if (function_exists('iform_load_helpers')) {
         iform_load_helpers(array('map_helper'));
     } else {
         require_once dirname(dirname(__FILE__)) . '/map_helper.php';
     }
     $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']);
     $r = '';
     // setup the map options
     $options = iform_map_get_map_options($args, $readAuth);
     $olOptions = iform_map_get_ol_options($args);
     if (array_key_exists('table', $_GET) && $_GET['table'] == 'sample') {
         // Use a cUrl request to get the data from Indicia which contains the value we need to filter against
         // Read the record that was just posted.
         $fetchOpts = array('dataSource' => 'reports_for_prebuilt_forms/my_dot_map/occurrences_list_2', 'mode' => 'report', 'readAuth' => $readAuth, 'extraParams' => array('sample_id' => $_GET['id'], 'language' => $lang));
         // @todo Error handling on the response
         $occurrence = data_entry_helper::get_report_data($fetchOpts);
         self::prepare_layer_titles($args, $occurrence);
         // Add the 3 distribution layers if present. Reverse the order so 1st layer is topmost
         $layerName = self::build_distribution_layer(3, $args, $occurrence);
         if ($layerName) {
             $options['layers'][] = $layerName;
         }
         $layerName = self::build_distribution_layer(2, $args, $occurrence);
         if ($layerName) {
             $options['layers'][] = $layerName;
         }
         $layerName = self::build_distribution_layer(1, $args, $occurrence);
         if ($layerName) {
             $options['layers'][] = $layerName;
         }
         if ($layerName) {
             $options['layers'][] = $layerName;
         }
         // This is not a map used for input
         $options['editLayer'] = false;
         if ($args['hide_grid'] == false) {
             // Now output a grid of the occurrences that were just saved.
             $r .= "<table class=\"submission\"><thead><tr><th>" . lang::get('Species') . "</th><th>" . lang::get('Latin Name') . "</th><th>" . lang::get('Abundance') . "</th><th>" . lang::get('Date') . "</th><th>" . lang::get('Spatial Ref') . "</th>" . "</th><th>" . lang::get('Comment') . "</th></tr></thead>\n";
             $r .= "<tbody>\n";
             foreach ($occurrence as $record) {
                 $r .= '<tr class="biota"><td>' . $record['taxon'] . '</td><td class="binomial"><em>' . $record['preferred_taxon'] . '</em></td><td>' . $record['abundance'] . '</td><td>' . $record['date'] . '</td><td>' . $record['entered_sref'] . '</td>' . $record['comment'] . "</td><td></tr>\n";
             }
             $r .= "</tbody></table>\n";
         }
     }
     if (!empty($args['add_another_link'])) {
         $path = $args['add_another_link'];
         if (count($occurrence) === 1) {
             $path = str_replace(array('#taxon_meaning_id#', '#external_key#'), array($occurrence[0]['taxon_meaning_id'], $occurrence[0]['external_key']), $path);
             $parts = explode('?', $path, 2);
             $parts[0] = url($parts[0]);
             $path = implode('?', $parts);
         }
         $r .= '<a class="indicia-button" href="' . $path . '">' . lang::get('Add another record') . '</a><br/>';
     }
     $r .= '<div id="mapandlegend">';
     $r .= map_helper::layer_list(array('id' => 'legend', 'includeSwitchers' => false, 'includeHiddenLayers' => false, 'includeIcons' => true, 'layerTypes' => array('overlay')));
     $r .= map_helper::map_panel($options, $olOptions);
     $r .= '</div>';
     return $r;
 }
コード例 #8
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.';
     }
     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;
 }
コード例 #9
0
ファイル: user.php プロジェクト: BirenRathod/indicia-code
/**
 * Takes a piece of configuration text and replaces tokens with the relevant user profile information. The following
 * replacements are applied:
 * {user_id} - the content management system User ID.
 * {username} - the content management system username.
 * {email} - the email address stored for the user in the content management system.
 * {profile_*} - the respective field from the user profile stored in the content management system.
 * [permission] - does the user have this permission? Replaces with 1 if they have the permission, else 0.
 */
function apply_user_replacements($text)
{
    global $user;
    if (!is_string($text)) {
        return $text;
    }
    $replace = array('{user_id}', '{username}', '{email}');
    $replaceWith = array($user->uid, isset($user->name) ? $user->name : '', isset($user->mail) ? $user->mail : '');
    // Do basic replacements and trim the data
    $text = trim(str_replace($replace, $replaceWith, $text));
    // Look for any profile field replacments
    if (preg_match_all('/{([^}]*)}/', $text, $matches) && function_exists('hostsite_get_user_field')) {
        $profileLoaded = false;
        foreach ($matches[1] as $profileField) {
            // got a request for a user profile field, so copy it's value across into the report parameters
            $fieldName = preg_replace('/^profile_/', '', $profileField);
            $value = hostsite_get_user_field($fieldName);
            if ($value) {
                // unserialise the data if it is serialised, e.g. when using profile_checkboxes to store a list of values.
                $value = @unserialize($value);
                // arrays are returned as a comma separated list
                if (is_array($value)) {
                    $value = implode(',', $value);
                } else {
                    $value = $value ? $value : hostsite_get_user_field($fieldName);
                }
                // nulls must be passed as empty string params.
                $value = $value === null ? '' : $value;
            } else {
                $value = '';
            }
            $text = str_replace('{' . $profileField . '}', $value, $text);
        }
    }
    // Look for any permission replacements
    if (preg_match_all('/\\[([^\\]]*)\\]/', $text, $matches)) {
        foreach ($matches[1] as $permission) {
            $value = user_access($permission) ? '1' : '0';
            $text = str_replace("[{$permission}]", $value, $text);
        }
    }
    // convert booleans to true booleans
    $text = $text === 'false' ? false : ($text === 'true' ? true : $text);
    return $text;
}
コード例 #10
0
 protected static function get_control_standardparams($auth, $args, $tabalias, $options)
 {
     self::$applyUserPrefs = false;
     $options = array_merge(array('allowSave' => true, 'sharing' => empty($args['sharing']) ? 'reporting' : $args['sharing']), $options);
     if ($args['redirect_on_success']) {
         $options['redirect_on_success'] = url($args['redirect_on_success']);
     }
     // any preset params on the report page should be loaded as initial settings for the filter.
     if (!empty($args['param_presets'])) {
         $params = data_entry_helper::explode_lines_key_value_pairs($args['param_presets']);
         foreach ($params as $key => $val) {
             $options["filter-{$key}"] = $val;
         }
     }
     foreach ($options as $key => &$value) {
         $value = apply_user_replacements($value);
     }
     if ($options['allowSave'] && !function_exists('iform_ajaxproxy_url')) {
         return 'The AJAX Proxy module must be enabled to support saving filters. Set @allowSave=false to disable this in the [standard params] control.';
     }
     if (!function_exists('hostsite_get_user_field') || !hostsite_get_user_field('indicia_user_id')) {
         return 'The standard params module requires Easy Login.';
     }
     $r = report_filter_panel($auth['read'], $options, $args['website_id'], $hiddenStuff);
     return $r . $hiddenStuff;
 }
コード例 #11
0
 /**
  * Gets a taxon name from a Meaning ID.
  *
  * @param int $meaningId The map layer we are preparing.
  * @param array $readAuth Read authentication.
  * @return The taxon name.
  */
 private static function get_taxon($meaningId, $readAuth)
 {
     global $user;
     $fetchOpts = array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + array('view' => 'detail', 'language_iso' => iform_lang_iso_639_2(hostsite_get_user_field('language')), 'taxon_meaning_id' => $meaningId));
     $taxonRecords = data_entry_helper::get_population_data($fetchOpts);
     return $taxonRecords[0]['taxon'];
 }
コード例 #12
0
 /**
  * Get the observer control as an autocomplete.
  */
 protected static function get_control_observerautocomplete($auth, $args, $tabAlias, $options)
 {
     global $user;
     //Get the name of the currently logged in user
     $defaultUserData = data_entry_helper::get_report_data(array('dataSource' => 'library/users/get_people_details_for_website_or_user', 'readAuth' => $auth['read'], 'extraParams' => array('user_id' => hostsite_get_user_field('indicia_user_id'), 'website_id' => $args['website_id'])));
     //If we are in edit mode then we need to get the name of the saved observer for the sample
     if (!empty($_GET['sample_id']) && !empty($args['observer_name'])) {
         $existingUserData = data_entry_helper::get_population_data(array('table' => 'sample_attribute_value', 'extraParams' => $auth['read'] + array('sample_id' => $_GET['sample_id'], 'sample_attribute_id' => $args['observer_name'])));
     }
     $observer_list_args = array_merge_recursive(array('extraParams' => array_merge($auth['read'])), $options);
     $observer_list_args['label'] = t('Observer Name');
     $observer_list_args['extraParams']['website_id'] = $args['website_id'];
     $observer_list_args['captionField'] = 'fullname_surname_first';
     $observer_list_args['id'] = 'obSelect:' . $args['observer_name'];
     $observer_list_args['report'] = 'library/users/get_people_details_for_website_or_user';
     //Auto-fill the observer name with the name of the observer of the existing saved sample if it exists,
     //else default to current user name
     if (!empty($existingUserData[0]['value'])) {
         $observer_list_args['defaultCaption'] = $existingUserData[0]['value'];
     } else {
         if (empty($_GET['sample_id'])) {
             $observer_list_args['defaultCaption'] = $defaultUserData[0]['fullname_surname_first'];
         }
     }
     return data_entry_helper::autocomplete($observer_list_args);
 }
コード例 #13
0
 public static function get_occurrences_form($args, $node, $response)
 {
     global $user;
     if (!module_exists('iform_ajaxproxy')) {
         return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.';
     }
     drupal_add_js('misc/tableheader.js');
     // for sticky heading
     data_entry_helper::add_resource('jquery_form');
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     // did the parent sample previously exist? Default is no.
     $existing = false;
     $url = explode('?', $args['my_obs_page'], 2);
     $params = NULL;
     $fragment = NULL;
     // fragment is always at the end.
     if (count($url) > 1) {
         $params = explode('#', $url[1], 2);
         if (count($params) > 1) {
             $fragment = $params[1];
         }
         $params = $params[0];
     } else {
         $url = explode('#', $url[0], 2);
         if (count($url) > 1) {
             $fragment = $url[1];
         }
     }
     $args['my_obs_page'] = url($url[0], array('query' => $params, 'fragment' => $fragment, 'absolute' => TRUE));
     if (isset($_POST['sample:id'])) {
         // have just posted an edit to the existing sample
         $sampleId = $_POST['sample:id'];
         $existing = true;
         data_entry_helper::load_existing_record($auth['read'], 'sample', $sampleId);
     } else {
         if (isset($response['outer_id'])) {
             // have just posted a new sample.
             $sampleId = $response['outer_id'];
         } else {
             $sampleId = $_GET['sample_id'];
             $existing = true;
         }
     }
     $sample = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $sampleId, 'deleted' => 'f')));
     $sample = $sample[0];
     $date = $sample['date_start'];
     if (!function_exists('module_exists') || !module_exists('easy_login')) {
         // work out the CMS User sample ID.
         $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Field Observation'));
         $attributes = data_entry_helper::getAttributes(array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id']));
         if (false == ($cmsUserAttr = extract_cms_user_attr($attributes))) {
             return 'Easy Login not active: This form is designed to be used with the CMS User ID attribute setup for samples in the survey.';
         }
     }
     $allTaxonMeaningIdsAtSample = array();
     if ($existing) {
         // Only need to load the occurrences for a pre-existing sample
         $o = data_entry_helper::get_population_data(array('report' => 'reports_for_prebuilt_forms/UKBMS/ukbms_occurrences_list_for_sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'sample_id' => $sampleId, 'survey_id' => $args['survey_id'], 'date_from' => '', 'date_to' => '', 'taxon_group_id' => '', 'smpattrs' => '', 'occattrs' => $args['occurrence_attribute_ids']), 'nocache' => true));
         // build an array keyed for easy lookup
         $occurrences = array();
         $attrs = explode(',', $args['occurrence_attribute_ids']);
         if (!isset($o['error'])) {
             foreach ($o as $occurrence) {
                 if (!in_array($occurrence['taxon_meaning_id'], $allTaxonMeaningIdsAtSample)) {
                     $allTaxonMeaningIdsAtSample[] = $occurrence['taxon_meaning_id'];
                 }
                 $occurrences[$occurrence['taxon_meaning_id']] = array('ttl_id' => $occurrence['taxa_taxon_list_id'], 'ttl_id' => $occurrence['taxa_taxon_list_id'], 'preferred_ttl_id' => $occurrence['preferred_ttl_id'], 'o_id' => $occurrence['occurrence_id'], 'processed' => false);
                 foreach ($attrs as $attr) {
                     $occurrences[$occurrence['taxon_meaning_id']]['value_' . $attr] = $occurrence['attr_occurrence_' . $attr];
                     $occurrences[$occurrence['taxon_meaning_id']]['a_id_' . $attr] = $occurrence['attr_id_occurrence_' . $attr];
                 }
             }
         }
         // store it in data for JS to read when populating the grid
         data_entry_helper::$javascript .= "indiciaData.existingOccurrences = " . json_encode($occurrences) . ";\n";
     } else {
         data_entry_helper::$javascript .= "indiciaData.existingOccurrences = {};\n";
     }
     $occ_attributes = data_entry_helper::getAttributes(array('valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'fieldprefix' => 'occAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'multiValue' => false));
     data_entry_helper::$javascript .= "indiciaData.occurrence_totals = [];\n";
     data_entry_helper::$javascript .= "indiciaData.occurrence_attribute = [];\n";
     data_entry_helper::$javascript .= "indiciaData.occurrence_attribute_ctrl = [];\n";
     $defAttrOptions = array('extraParams' => $auth['read'] + array('orderby' => 'id'), 'suffixTemplate' => 'nosuffix');
     $occ_attributes_captions = array();
     foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
         $occ_attributes_captions[$idx] = $occ_attributes[$attr]['caption'];
         unset($occ_attributes[$attr]['caption']);
         $ctrl = data_entry_helper::outputAttribute($occ_attributes[$attr], $defAttrOptions);
         data_entry_helper::$javascript .= "indiciaData.occurrence_totals[" . $idx . "] = [];\n";
         data_entry_helper::$javascript .= "indiciaData.occurrence_attribute[" . $idx . "] = {$attr};\n";
         data_entry_helper::$javascript .= "indiciaData.occurrence_attribute_ctrl[" . $idx . "] = jQuery('" . str_replace("\n", "", $ctrl) . "');\n";
     }
     //    $r = "<h2>".$location[0]['name']." on ".$date."</h2>\n";
     $r = '<div id="tabs">';
     $tabs = array('#grid1' => t($args['species_tab_1']));
     // tab 1 is required.
     if (isset($args['taxon_list_id_2']) && $args['taxon_list_id_2'] != '') {
         $tabs['#grid2'] = t(isset($args['species_tab_2']) && $args['species_tab_2'] != '' ? $args['species_tab_2'] : 'Species Tab 2');
     }
     if (isset($args['taxon_list_id_3']) && $args['taxon_list_id_3'] != '') {
         $tabs['#grid3'] = t(isset($args['species_tab_3']) && $args['species_tab_3'] != '' ? $args['species_tab_3'] : 'Species Tab 3');
     }
     if (isset($args['taxon_list_id_4']) && $args['taxon_list_id_4'] != '') {
         $tabs['#grid4'] = t(isset($args['species_tab_4']) && $args['species_tab_4'] != '' ? $args['species_tab_4'] : 'Species Tab 4');
     }
     $tabs['#notes'] = lang::get('Notes');
     $r .= data_entry_helper::tab_header(array('tabs' => $tabs));
     data_entry_helper::enable_tabs(array('divId' => 'tabs', 'style' => 'Tabs'));
     // will assume that first table is based on abundance count, so do totals
     $r .= '<div id="grid1"><table id="observation-input1" class="ui-widget species-grid"><thead class="table-header"><tr><th class="ui-widget-header"></th>';
     foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
         $r .= '<th class="ui-widget-header col-' . ($idx + 1) . '">' . $occ_attributes_captions[$idx] . '</th>';
     }
     $r .= '<th class="ui-widget-header">' . lang::get('Total') . '</th></tr></thead>';
     $r .= '<tbody class="ui-widget-content occs-body"></tbody><tfoot><tr><td>Total</td>';
     foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
         $r .= '<td class="col-' . ($idx + 1) . ' ' . ($idx % 5 == 0 ? 'first' : '') . ' col-total"></td>';
     }
     $r .= '<td class="ui-state-disabled first"></td></tr></tfoot></table><br /><a href="' . $args['my_obs_page'] . '" class="button">' . lang::get('Finish') . '</a></div>';
     $extraParams = array_merge($auth['read'], array('taxon_list_id' => $args['taxon_list_id_1'], 'preferred' => 't', 'allow_data_entry' => 't', 'view' => 'cache', 'orderby' => 'taxonomic_sort_order'));
     if (!empty($args['taxon_filter_field_1']) && !empty($args['taxon_filter_1'])) {
         $extraParams[$args['taxon_filter_field_1']] = helper_base::explode_lines($args['taxon_filter_1']);
     }
     $taxa = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $extraParams));
     data_entry_helper::$javascript .= "indiciaData.speciesList1List = [";
     $first = true;
     foreach ($taxa as $taxon) {
         data_entry_helper::$javascript .= ($first ? "\n" : ",\n") . "{'id':" . $taxon['id'] . ",'taxon_meaning_id':" . $taxon['taxon_meaning_id'] . ",'preferred_language_iso':'" . $taxon["preferred_language_iso"] . "','default_common_name':'" . str_replace("'", "\\'", $taxon["default_common_name"]) . "'}";
         $first = false;
     }
     data_entry_helper::$javascript .= "];\n";
     data_entry_helper::$javascript .= "indiciaData.allTaxonMeaningIdsAtSample = [" . implode(',', $allTaxonMeaningIdsAtSample) . "];\n";
     if (isset($args['taxon_list_id_2']) && $args['taxon_list_id_2'] != '') {
         $r .= '<div id="grid2"><p id="grid2-loading">' . lang::get('Loading - Please Wait') . '</p><table id="observation-input2" class="ui-widget species-grid"><thead class="table-header"><tr><th class="ui-widget-header"></th>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<th class="ui-widget-header col-' . ($idx + 1) . '">' . $occ_attributes_captions[$idx] . '</th>';
         }
         $r .= '<th class="ui-widget-header">' . lang::get('Total') . '</th></tr></thead><tbody class="ui-widget-content occs-body"></tbody><tfoot><tr><td>Total</td>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<td class="col-' . ($idx + 1) . ' ' . ($idx % 5 == 0 ? 'first' : '') . ' col-total"></td>';
         }
         $r .= '<td class="ui-state-disabled first"></td></tr></tfoot></table><br /><a href="' . $args['my_obs_page'] . '" class="button">' . lang::get('Finish') . '</a></div>';
     }
     if (isset($args['taxon_list_id_3']) && $args['taxon_list_id_3'] != '') {
         $r .= '<div id="grid3"><p id="grid3-loading">' . lang::get('Loading - Please Wait') . '</p><table id="observation-input3" class="ui-widget species-grid"><thead class="table-header"><tr><th class="ui-widget-header"></th>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<th class="ui-widget-header col-' . ($idx + 1) . '">' . $occ_attributes_captions[$idx] . '</th>';
         }
         $r .= '<th class="ui-widget-header">' . lang::get('Total') . '</th></tr></thead><tbody class="ui-widget-content occs-body"></tbody><tfoot><tr><td>Total</td>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<td class="col-' . ($idx + 1) . ' ' . ($idx % 5 == 0 ? 'first' : '') . ' col-total"></td>';
         }
         $r .= '<td class="ui-state-disabled first"></td></tr></tfoot></table><br /><a href="' . $args['my_obs_page'] . '" class="button">' . lang::get('Finish') . '</a></div>';
     }
     if (isset($args['taxon_list_id_4']) && $args['taxon_list_id_4'] != '') {
         $r .= '<div id="grid4"><p id="grid4-loading">' . lang::get('Loading - Please Wait') . '</p><table id="observation-input4" class="ui-widget species-grid"><thead class="table-header"><tr><th class="ui-widget-header"></th>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<th class="ui-widget-header col-' . ($idx + 1) . '">' . $occ_attributes_captions[$idx] . '</th>';
         }
         $r .= '<th class="ui-widget-header">' . lang::get('Total') . '</th></tr></thead><tbody class="ui-widget-content occs-body"></tbody><tfoot><tr><td>Total</td>';
         foreach (explode(',', $args['occurrence_attribute_ids']) as $idx => $attr) {
             $r .= '<td class="col-' . ($idx + 1) . ' ' . ($idx % 5 == 0 ? 'first' : '') . ' col-total"></td>';
         }
         $r .= '<td class="ui-state-disabled first"></td></tr></tfoot></table>';
         $r .= '<label for="taxonLookupControl4" class="auto-width">' . lang::get('Add species to list') . ':</label> <input id="taxonLookupControl4" name="taxonLookupControl4" >';
         $r .= '<br /><a href="' . $args['my_obs_page'] . '" class="button">' . lang::get('Finish') . '</a></div>';
     }
     // for the comment form, we want to ensure that if there is a timeout error that it reloads the
     // data as stored in the DB.
     $reload = data_entry_helper::get_reload_link_parts();
     $reload['params']['sample_id'] = $parentSampleId;
     unset($reload['params']['new']);
     $reloadPath = $reload['path'];
     if (count($reload['params'])) {
         // decode params prior to encoding to prevent double encoding.
         foreach ($reload['params'] as $key => $param) {
             $reload['params'][$key] = urldecode($param);
         }
         $reloadPath .= '?' . http_build_query($reload['params']);
     }
     // fragment is always at the end. discard this.
     $reloadPath = explode('#', $reloadPath, 2);
     $reloadPath = $reloadPath[0];
     $r .= "<div id=\"notes\"><form method=\"post\" id=\"notes_form\" action=\"" . $reloadPath . "#notes\">\n";
     $r .= $auth['write'];
     $r .= '<input type="hidden" name="sample:id" value="' . $sampleId . '" />' . '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>' . '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '"/>' . '<input type="hidden" name="page" value="notes"/>';
     $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('When using this page, please remember that the data is not saved to the database as you go (which is the case for the previous tabs). In order to save the data entered in this page you must click on the Submit button at the bottom of the page.') . '</p>';
     $r .= data_entry_helper::textarea(array('fieldname' => 'sample:comment', 'label' => lang::get('Notes'), 'helpText' => "Use this space to input comments about this week's walk."));
     $r .= '<input type="submit" value="' . lang::get('Submit') . '" id="save-button"/></form>';
     $r .= '<br /><a href="' . $args['my_walks_page'] . '" class="button">' . lang::get('Finish') . '</a></div></div>';
     // enable validation on the comments form in order to include the simplified ajax queuing for the autocomplete.
     data_entry_helper::enable_validation('notes_form');
     // A stub form for AJAX posting when we need to create an occurrence
     $r .= '<form style="display: none" id="occ-form" method="post" action="' . iform_ajaxproxy_url($node, 'occurrence') . '">';
     $r .= '<input name="website_id" value="' . $args['website_id'] . '"/>';
     $r .= '<input name="occurrence:id" id="occid" />';
     $r .= '<input name="occurrence:taxa_taxon_list_id" id="ttlid" />';
     $r .= '<input name="occurrence:sample_id" value="' . $sampleId . '"/>';
     $r .= '<input name="occAttr:" id="occattr"/>';
     $r .= '<input name="transaction_id" id="transaction_id"/>';
     $r .= '<input name="user_id" value="' . hostsite_get_user_field('user_id', 1) . '"/>';
     $r .= '</form>';
     // tell the Javascript where to get species from.
     data_entry_helper::add_resource('jquery_ui');
     data_entry_helper::add_resource('json');
     data_entry_helper::add_resource('autocomplete');
     data_entry_helper::$javascript .= "indiciaData.speciesList1 = " . $args['taxon_list_id_1'] . ";\n";
     if (!empty($args['taxon_filter_field_1']) && !empty($args['taxon_filter_1'])) {
         data_entry_helper::$javascript .= "indiciaData.speciesList1FilterField = '" . $args['taxon_filter_field_1'] . "';\n";
         $filterLines = helper_base::explode_lines($args['taxon_filter_1']);
         data_entry_helper::$javascript .= "indiciaData.speciesList1FilterValues = '" . json_encode($filterLines) . "';\n";
     }
     data_entry_helper::$javascript .= "indiciaData.speciesList2 = " . (isset($args['taxon_list_id_2']) && $args['taxon_list_id_2'] != "" ? $args['taxon_list_id_2'] : "-1") . ";\n";
     if (!empty($args['taxon_filter_field_2']) && !empty($args['taxon_filter_2'])) {
         data_entry_helper::$javascript .= "indiciaData.speciesList2FilterField = '" . $args['taxon_filter_field_2'] . "';\n";
         $filterLines = helper_base::explode_lines($args['taxon_filter_2']);
         data_entry_helper::$javascript .= "indiciaData.speciesList2FilterValues = " . json_encode($filterLines) . ";\n";
     }
     data_entry_helper::$javascript .= "indiciaData.speciesList3 = " . (isset($args['taxon_list_id_3']) && $args['taxon_list_id_3'] != "" ? $args['taxon_list_id_3'] : "-1") . ";\n";
     if (!empty($args['taxon_filter_field_3']) && !empty($args['taxon_filter_3'])) {
         data_entry_helper::$javascript .= "indiciaData.speciesList3FilterField = '" . $args['taxon_filter_field_3'] . "';\n";
         $filterLines = helper_base::explode_lines($args['taxon_filter_3']);
         data_entry_helper::$javascript .= "indiciaData.speciesList3FilterValues = " . json_encode($filterLines) . ";\n";
     }
     data_entry_helper::$javascript .= "indiciaData.speciesList4 = " . (isset($args['taxon_list_id_4']) && $args['taxon_list_id_4'] != "" ? $args['taxon_list_id_4'] : "-1") . ";\n";
     if (!empty($args['taxon_filter_field_4']) && !empty($args['taxon_filter_4'])) {
         data_entry_helper::$javascript .= "indiciaData.speciesList4FilterField = '" . $args['taxon_filter_field_4'] . "';\n";
         $filterLines = helper_base::explode_lines($args['taxon_filter_4']);
         data_entry_helper::$javascript .= "indiciaData.speciesList4FilterValues = " . json_encode($filterLines) . ";\n";
     }
     // allow js to do AJAX by passing in the information it needs to post forms
     data_entry_helper::$javascript .= "bindSpeciesAutocomplete(\"taxonLookupControl4\",\"table#observation-input4\",\"" . data_entry_helper::$base_url . "index.php/services/data\", indiciaData.speciesList4,\n  indiciaData.speciesList4FilterField, indiciaData.speciesList4FilterValues, {\"auth_token\" : \"" . $auth['read']['auth_token'] . "\", \"nonce\" : \"" . $auth['read']['nonce'] . "\"},\n  \"" . lang::get('LANG_Duplicate_Taxon') . "\", 25, 4);\n\n";
     data_entry_helper::$javascript .= "indiciaData.indiciaSvc = '" . data_entry_helper::$base_url . "';\n";
     data_entry_helper::$javascript .= "indiciaData.readAuth = {nonce: '" . $auth['read']['nonce'] . "', auth_token: '" . $auth['read']['auth_token'] . "'};\n";
     data_entry_helper::$javascript .= "indiciaData.sample = " . $sampleId . ";\n";
     if (function_exists('module_exists') && module_exists('easy_login')) {
         data_entry_helper::$javascript .= "indiciaData.easyLogin = true;\n";
         $userId = hostsite_get_user_field('indicia_user_id');
         if (!empty($userId)) {
             data_entry_helper::$javascript .= "indiciaData.UserID = " . $userId . ";\n";
         } else {
             return '<p>Easy Login active but could not identify user</p>';
         }
         // something is wrong
     } else {
         data_entry_helper::$javascript .= "indiciaData.easyLogin = false;\n";
         data_entry_helper::$javascript .= "indiciaData.CMSUserAttrID = " . $cmsUserAttr['attributeId'] . ";\n";
         data_entry_helper::$javascript .= "indiciaData.CMSUserID = " . $user->uid . ";\n";
     }
     // Do an AJAX population of the grid rows.
     data_entry_helper::$javascript .= "loadSpeciesList();\njQuery('#tabs').bind('tabsshow', function(event, ui) {\n    var target = ui.panel;\n    // first get rid of any previous tables\n    jQuery('table.sticky-header').remove();\n    jQuery('table.sticky-enabled thead.tableHeader-processed').removeClass('tableHeader-processed');\n    jQuery('table.sticky-enabled.tableheader-processed').removeClass('tableheader-processed');\n    jQuery('table.species-grid.sticky-enabled').removeClass('sticky-enabled');\n    var table = jQuery('#'+target.id+' table.species-grid');\n    if(table.length > 0) {\n        table.addClass('sticky-enabled');\n        if(typeof Drupal.behaviors.tableHeader == 'object') // Drupal 7\n          Drupal.behaviors.tableHeader.attach(table.parent());\n        else // Drupal6 : it is a function\n          Drupal.behaviors.tableHeader(target);\n    }\n    // remove any hanging autocomplete select list.\n    jQuery('.ac_results').hide();\n});";
     return $r;
 }
コード例 #14
0
 /**
  * When viewing the list of locations for this user, get the grid to insert into the page.
  * Filtering of locations is by Indicia User ID stored in the user profile.
  * Enable Easy Login module to achieve this function.
  */
 protected static function getLocationListGrid($args, $node, $auth)
 {
     global $user;
     // User must be logged in before we can access their records.
     if ($user->uid === 0) {
         // Return a login link that takes you back to this form when done.
         return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.');
     }
     // get the Indicia User ID attribute so we can filter the grid to this user
     if (function_exists('hostsite_get_user_field')) {
         $iUserId = hostsite_get_user_field('indicia_user_id');
     }
     if (!isset($iUserId) || !$iUserId) {
         return lang::get('LANG_No_User_Id');
     }
     // Subclassed forms may provide a getLocationListGridPreamble function
     if (method_exists(self::$called_class, 'getLocationListGridPreamble')) {
         $r = call_user_func(array(self::$called_class, 'getLocationListGridPreamble'));
     } else {
         $r = '';
     }
     $extraParams = array('website_id' => $args['website_id'], 'iUserID' => $iUserId);
     if (!$args['list_all_locations']) {
         // The option to list all locations is denied so enforce selection of own data.
         $extraParams['ownData'] = '1';
     }
     $r .= data_entry_helper::report_grid(array('id' => 'locations-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(self::$called_class, 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => $extraParams, 'paramDefaults' => array('ownData' => '1')));
     $r .= '<form>';
     $r .= '<input type="button" value="' . lang::get('LANG_Add_Location') . '" ' . 'onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">';
     $r .= '</form>';
     return $r;
 }
コード例 #15
0
 /**
  * Either takes the passed in submission, or creates it from the post data if this is null, and forwards
  * it to the data services for saving as a member of the entity identified.
  * @param string $entity Name of the top level entity being submitted, e.g. sample or occurrence.
  * @param array $submission The wrapped submission structure. If null, then this is automatically constructer
  * from the form data in $_POST.
  * @param array $writeTokens Array containing auth_token and nonce for the write operation, plus optionally persist_auth=true
  * to prevent the authentication tokens from expiring after use. If null then the values are read from $_POST.
  */
 public static function forward_post_to($entity, $submission = null, $writeTokens = null)
 {
     if (self::$validation_errors == null) {
         $remembered_fields = self::get_remembered_fields();
         if ($submission == null) {
             $submission = submission_builder::wrap($_POST, $entity);
         }
         if ($remembered_fields !== null) {
             // the form is configured to remember fields
             if (!isset($_POST['cookie_optin']) || $_POST['cookie_optin'] === '1') {
                 // if given a choice, the user opted for fields to be remembered
                 $arr = array();
                 foreach ($remembered_fields as $field) {
                     $arr[$field] = $_POST[$field];
                 }
                 // put them in a cookie with a 30 day expiry
                 setcookie('indicia_remembered', serialize($arr), time() + 60 * 60 * 24 * 30);
                 // cookies are only set when the page is loaded. So if we are reloading the same form after submission,
                 // we need to fudge the cookie
                 $_COOKIE['indicia_remembered'] = serialize($arr);
             } else {
                 // the user opted out of having a cookie - delete one if present.
                 setcookie('indicia_remembered', '');
             }
         }
         $media = self::extract_media_data($_POST);
         $request = parent::$base_url . "index.php/services/data/{$entity}";
         $postargs = 'submission=' . urlencode(json_encode($submission));
         // passthrough the authentication tokens as POST data. Use parameter writeTokens, or current $_POST if not supplied.
         if ($writeTokens) {
             foreach ($writeTokens as $token => $value) {
                 $postargs .= '&' . $token . '=' . ($value === true ? 'true' : ($value === false ? 'false' : $value));
             }
             // this will do auth_token, nonce, and persist_auth
         } else {
             if (array_key_exists('auth_token', $_POST)) {
                 $postargs .= '&auth_token=' . $_POST['auth_token'];
             }
             if (array_key_exists('nonce', $_POST)) {
                 $postargs .= '&nonce=' . $_POST['nonce'];
             }
         }
         // pass through the user_id if hostsite_get_user_field is implemented
         if (function_exists('hostsite_get_user_field')) {
             $postargs .= '&user_id=' . hostsite_get_user_field('indicia_user_id');
         }
         // look for media files attached to fields like group:logo_path (*:*_path)
         // which are not in submodels, so not picked up by the extract_media_data code.
         foreach ($_FILES as $fieldname => $file) {
             if (preg_match('/^([a-z_]+:)?[a-z_]+_path$/', $fieldname)) {
                 $media[] = array('path' => $file['name']);
             }
         }
         // if there are images, we will send them after the main post, so we need to persist the write nonce
         if (count($media) > 0) {
             $postargs .= '&persist_auth=true';
         }
         $response = self::http_post($request, $postargs);
         // The response should be in JSON if it worked
         $output = json_decode($response['output'], true);
         // If this is not JSON, it is an error, so just return it as is.
         if (!$output) {
             $output = $response['output'];
         }
         if (is_array($output) && array_key_exists('success', $output)) {
             if (isset(self::$final_image_folder) && self::$final_image_folder != 'warehouse') {
                 // moving the files on the local machine. Find out where from and to
                 $interim_image_folder = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . self::relative_client_helper_path() . (isset(parent::$interim_image_folder) ? parent::$interim_image_folder : 'upload/');
                 $final_image_folder = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . self::relative_client_helper_path() . parent::$final_image_folder;
             }
             // submission succeeded. So we also need to move the images to the final location
             $image_overall_success = TRUE;
             $image_errors = array();
             foreach ($media as $item) {
                 // no need to resend an existing image, or a media link, just local files.
                 if ((empty($item['media_type']) || preg_match('/:Local$/', $item['media_type'])) && (!isset($item['id']) || empty($item['id']))) {
                     if (!isset(self::$final_image_folder) || self::$final_image_folder == 'warehouse') {
                         // Final location is the Warehouse
                         // @todo Set PERSIST_AUTH false if last file
                         $success = self::send_file_to_warehouse($item['path'], true, $writeTokens);
                     } else {
                         $success = rename($interim_image_folder . $item['path'], $final_image_folder . $item['path']);
                     }
                     if ($success !== true) {
                         // Record all files that fail to move successfully.
                         $image_overall_success = FALSE;
                         $image_errors[] = $success;
                     }
                 }
             }
             if (!$image_overall_success) {
                 // Report any file transfer failures.
                 $error = lang::get('submit ok but file transfer failed') . '<br/>';
                 $error .= implode('<br/>', $image_errors);
                 $output = array('error' => $error);
             }
         }
         return $output;
     } else {
         return array('error' => 'Pre-validation failed', 'errors' => self::$validation_errors);
     }
 }
コード例 #16
0
 /**
  * Fetch an existing group's information from the database when editing.
  * @param integer $id Group ID
  * @param array $auth Authorisation tokens
  */
 private static function loadExistingGroup($id, $auth, $args)
 {
     $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $_GET['group_id']), 'nocache' => true));
     $group = $group[0];
     if ($group['created_by_id'] !== hostsite_get_user_field('indicia_user_id')) {
         if (!function_exists('user_access') || !user_access('Iform groups admin')) {
             // user did not create group. So, check they are an admin
             $admins = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $auth['read'] + array('group_id' => $_GET['group_id'], 'administrator' => 't'), 'nocache' => true));
             $found = false;
             foreach ($admins as $admin) {
                 if ($admin['user_id'] === hostsite_get_user_field('indicia_user_id')) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 throw new exception(lang::get('You are trying to edit a group you don\'t have admin rights to.'));
             }
         }
     }
     data_entry_helper::$entity_to_load = array('group:id' => $group['id'], 'group:title' => $group['title'], 'group:code' => $group['code'], 'group:group_type_id' => $group['group_type_id'], 'group:joining_method' => $group['joining_method'], 'group:description' => $group['description'], 'group:from_date' => $group['from_date'], 'group:to_date' => $group['to_date'], 'group:private_records' => $group['private_records'], 'group:filter_id' => $group['filter_id'], 'group:logo_path' => $group['logo_path'], 'filter:id' => $group['filter_id']);
     if ($args['include_report_filter']) {
         $def = $group['filter_definition'] ? $group['filter_definition'] : '{}';
         data_entry_helper::$javascript .= "indiciaData.filter.def={$def};\n";
     }
     if ($args['include_administrators'] || $args['include_members']) {
         $members = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $auth['read'] + array('view' => 'detail', 'group_id' => $_GET['group_id']), 'nocache' => true));
         $admins = array();
         $others = array();
         foreach ($members as $member) {
             if ($member['administrator'] === 't') {
                 $admins[] = array('fieldname' => 'groups_user:user_id:' . $member['id'], 'caption' => $member['person_name'], 'default' => $member['user_id']);
             } else {
                 $others[] = array('fieldname' => 'groups_user:user_id:' . $member['id'], 'caption' => $member['person_name'], 'default' => $member['user_id']);
             }
         }
         data_entry_helper::$entity_to_load['groups_user:admin_user_id'] = $admins;
         data_entry_helper::$entity_to_load['groups_user:user_id'] = $others;
     }
 }
コード例 #17
0
 /**
  * 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;
     $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_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', 'simultaneousOutput', 'tableHeaders', 'chartLabels', 'disableableSeries', 'chartType', 'rowGroupColumn', 'rowGroupID', 'width', 'height', 'includeTableTotalRow', 'includeTableTotalColumn', 'includeChartTotalSeries', 'includeChartItemSeries', 'includeRawData', 'includeSummaryData', 'includeEstimatesData', 'summaryDataCombining', 'dataRound', 'zeroPointAnchor', 'interpolation', 'firstValue', 'lastValue', 'linkURL', 'includeRawGridDownload', 'includeRawListDownload', 'includeSummaryGridDownload', 'includeEstimatesGridDownload', 'includeListDownload', 'avgFields'));
     if (isset($_GET['outputSource'])) {
         $reportOptions['outputSource'] = $_GET['outputSource'];
     }
     if (isset($_GET['outputFormat'])) {
         $reportOptions['outputFormat'] = $_GET['outputFormat'];
     } else {
         $reportOptions['outputFormat'] = $args['defaultOutput'];
     }
     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);
     }
     $legendOptions = trim($args['legend_options']);
     if (!empty($legendOptions)) {
         $reportOptions['legendOptions'] = json_decode($legendOptions, 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['branchManagerPermission']) && $args['branchManagerPermission'] != "" && user_access($args['branchManagerPermission'])) {
         // 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['managerPermission']) && $args['managerPermission'] != "" && user_access($args['managerPermission'])) {
         $reportOptions['location_list'] = 'all';
     }
     if (function_exists('module_exists') && module_exists('easy_login') && function_exists('hostsite_get_user_field')) {
         $reportOptions['my_user_id'] = hostsite_get_user_field('indicia_user_id');
     } else {
         $reportOptions['my_user_id'] = $user->uid;
     }
     $retVal = '';
     // 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::date_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>';
         }
         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['extraParams'][$param] = '';
         }
     }
     if (self::$siteUrlParams[self::$userKey]['value'] == '' && self::$siteUrlParams[self::$locationKey]['value'] == '') {
         $checked = self::$siteUrlParams[self::$cacheKey]['value'] === 'true' ? ' checked="checked"' : '';
         $retVal .= '<th><input type="checkbox" name="cachingParam" id="cachingParam" class="cachingParam"' . $checked . '/>' . '<label for="cachingParam" title="' . lang::get("When fetching the full data set, selcting this improves performance by not going to the warehouse to get the data. Occassionally, even when selected, the data will be refreshed, which will appear to slow down the response.") . '" >' . lang::get("Use cached data") . '</label></th>';
         $reportOptions['caching'] = self::$siteUrlParams[self::$cacheKey]['value'] === 'true' ? true : 'store';
         self::set_up_control_change('cachingParam', self::$cacheKey, array(), true);
         $checked = self::$siteUrlParams[self::$downloadKey]['value'] === 'true' ? ' checked="checked"' : '';
         if (self::$siteUrlParams[self::$downloadKey]['value'] !== 'true' && isset($reportOptions['includeListDownload']) && $reportOptions['includeListDownload'] == true) {
             $reportOptions['includeRawGridDownload'] = false;
             $reportOptions['includeRawListDownload'] = false;
             $reportOptions['includeSummaryGridDownload'] = false;
             $reportOptions['includeEstimatesGridDownload'] = false;
             $reportOptions['includeListDownload'] = false;
             for ($i = 1; $i <= 4; $i++) {
                 unset($args['Download' . $i . 'Caption']);
                 unset($args['download_report_' . $i]);
             }
             data_entry_helper::$javascript .= "jQuery('.downloads-table-label').remove();\n" . "jQuery('#downloads-table thead tr').prepend('<th>" . "<label for=\"downloadParam\" title=\"" . lang::get("When fetching the full data set, unselecting this improves performance by not including the download data in the page. This extra data can lead to a significantly increase in download time.") . "\" >" . lang::get("Include Downloads") . "</label>" . "<input type=\"checkbox\" name=\"downloadParam\" id=\"downloadParam\" class=\"downloadParam\"" . $checked . "/>" . "</th>');\n";
             self::set_up_control_change('downloadParam', self::$downloadKey, array(), true);
         }
     }
     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'];
     }
     $reportOptions['includeReportTimeStamp'] = isset($args['includeFilenameTimestamps']) && $args['includeFilenameTimestamps'];
     $retVal .= '</tr></thead></table>';
     $reportOptions['highlightEstimates'] = true;
     $retVal .= report_helper::report_calendar_summary($reportOptions);
     // upto this point the report options holds the cms user id as user_id: the report_helper converts this to the indicia
     // user_id if relevant to this installation. We now need to do the same for the report links.
     if (isset($reportOptions['extraParams']['user_id'])) {
         $reportOptions['extraParams']['cms_user_id'] = $reportOptions['extraParams']['user_id'];
         if (function_exists('module_exists') && module_exists('easy_login')) {
             $account = user_load($reportOptions['extraParams']['user_id']);
             if (function_exists('profile_load_profile')) {
                 profile_load_profile($account);
             }
             /* will not be invoked for Drupal7 where the fields are already in the account object */
             if (isset($account->profile_indicia_user_id)) {
                 $reportOptions['extraParams']['user_id'] = $account->profile_indicia_user_id;
             }
         }
     }
     if (isset($args['managerPermission']) && $args['managerPermission'] != "" && user_access($args['managerPermission']) || $reportOptions['extraParams']['location_list'] != '' || $reportOptions['extraParams']['user_id'] != '') {
         // if user specified - either me in normal or branch mode, or a manager
         global $indicia_templates;
         $indicia_templates['report_download_link'] = '<th><a href="{link}"><button type="button">{caption}</button></a></th>';
         // format is assumed to be CSV
         $downloadOptions = array('readAuth' => $auth, 'extraParams' => array_merge($reportOptions['extraParams'], array('date_from' => $reportOptions['date_start'], 'date_to' => $reportOptions['date_end'])), 'itemsPerPage' => false);
         // there are problems dealing with location_list as an array if empty, so connvert
         if ($downloadOptions['extraParams']['location_list'] == "") {
             $downloadOptions['extraParams']['location_list'] = "(-1)";
         } else {
             $downloadOptions['extraParams']['location_list'] = '(' . $downloadOptions['extraParams']['location_list'] . ')';
         }
         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] != "") {
                 $downloadOptions['caption'] = $args['Download' . $i . 'Caption'];
                 $downloadOptions['dataSource'] = $args['download_report_' . $i];
                 $downloadOptions['filename'] = $reportOptions['downloadFilePrefix'] . preg_replace('/[^A-Za-z0-9]/i', '', $args['Download' . $i . 'Caption']);
                 $downloadOptions['filename'] .= isset($reportOptions['includeReportTimeStamp']) && $reportOptions['includeReportTimeStamp'] ? '_' . date('YmdHis') : '';
                 if (isset($args['download_report_' . $i . '_format'])) {
                     $downloadOptions['format'] = $args['download_report_' . $i . '_format'];
                 }
                 data_entry_helper::$javascript .= "\nif(jQuery('#downloads-table th').length==0)\n  jQuery('#downloads-table thead tr').append('<th class=\"downloads-table-label\">" . lang::get("Downloads") . "</th>');\njQuery('#downloads-table thead tr').append('" . report_helper::report_download_link($downloadOptions) . "');\n";
             }
         }
     }
     return $retVal;
 }
コード例 #18
0
 /**
  * Use the mapping from Drupal to Indicia users to get the Indicia user ID for the current logged in Drupal user.
  * If there is a user profile field called profile_indicia_user_id then this value is used instead, for
  * example when the Easy Login feature is installed.
  */
 private static function get_indicia_user_id($args)
 {
     // Does the host site provide a warehouse user ID?
     if (function_exists('hostsite_get_user_field') && ($userId = hostsite_get_user_field('indicia_user_id'))) {
         return $userId;
     }
     // Use the configured mapping from local user ID to warehouse ID.
     global $user;
     if (substr(',', $args['verifiers_mapping']) !== false) {
         $arr = explode(',', $args['verifiers_mapping']);
         foreach ($arr as $mapping) {
             $mapArr = explode('=', $mapping);
             if (count($mapArr) == 0) {
                 return trim($mapping);
             } else {
                 if (trim($mapArr[0]) == $user->uid) {
                     return trim($mapArr[1]);
                 }
             }
         }
     } else {
         // verifiers mapping is just a single number
         return trim($args['verifiers_mapping']);
     }
     return 1;
     // default to admin
 }
コード例 #19
0
 /**
  * Retrieve the HTML required for an edit record button.
  * @param array $auth Read authorisation array
  * @param array $args Form options
  * @param string $tabalias The alias of the tab this appears on
  * @param array $options Options configured for this control. 
  * @return string HTML for the button.
  */
 protected static function buttons_edit($auth, $args, $tabalias, $options)
 {
     if (!$args['default_input_form']) {
         throw new exception('Please set the default input form path setting before using the [edit button] control');
     }
     self::load_record($auth);
     $record = self::$record;
     if (($user_id = hostsite_get_user_field('indicia_user_id')) && $user_id == self::$record['created_by_id'] && variable_get('indicia_website_id', 0) == self::$record['website_id']) {
         if (empty($record['input_form'])) {
             $record['input_form'] = $args['default_input_form'];
         }
         $pathParam = function_exists('variable_get') && variable_get('clean_url', 0) == '0' ? '?q=' : '';
         $paramJoin = empty($pathParam) ? '?' : '&';
         $url = data_entry_helper::getRootFolder() . "{$pathParam}{$record['input_form']}{$paramJoin}occurrence_id={$record['occurrence_id']}";
         return '<a class="button" href="' . $url . '">' . lang::get('Edit this record') . '</a>';
     } else {
         // no rights to edit, so button omitted.
         return '';
     }
 }
コード例 #20
0
 /**
  * When viewing the list of samples for this user, get the grid to insert into the page.
  */
 protected static function getSampleListGrid($args, $node, $auth, $attributes)
 {
     global $user;
     // User must be logged in before we can access their records.
     if ($user->uid === 0) {
         // Return a login link that takes you back to this form when done.
         return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => array('destination' => 'node/' . $node->nid))) . '">login</a> to the website.');
     }
     $filter = array();
     // Get the CMS User ID attribute so we can filter the grid to this user
     foreach ($attributes as $attrId => $attr) {
         if (strcasecmp($attr['caption'], 'CMS User ID') == 0) {
             $filter = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $attr['attributeId'], 'userID' => $user->uid, 'iUserID' => 0);
             break;
         }
     }
     // Alternatively get the Indicia User ID and use that instead
     if (function_exists('hostsite_get_user_field')) {
         $iUserId = hostsite_get_user_field('indicia_user_id');
         if (isset($iUserId) && $iUserId != false) {
             $filter = array('survey_id' => $args['survey_id'], 'userID_attr_id' => 0, 'userID' => 0, 'iUserID' => $iUserId);
         }
     }
     // Return with error message if we cannot identify the user records
     if (!isset($filter)) {
         return lang::get('LANG_No_User_Id');
     }
     // An option for derived classes to add in extra html before the grid
     if (method_exists(self::$called_class, 'getSampleListGridPreamble')) {
         $r = call_user_func(array(self::$called_class, 'getSampleListGridPreamble'));
     } else {
         $r = '';
     }
     $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $args['grid_report'], 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(self::$called_class, 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => $filter));
     $r .= '<form>';
     if (isset($args['multiple_occurrence_mode']) && $args['multiple_occurrence_mode'] == 'either') {
         $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Single') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">';
         $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1', 'gridmode' => '1'))) . '\'">';
     } else {
         $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => array('new' => '1'))) . '\'">';
     }
     $r .= '</form>';
     return $r;
 }
コード例 #21
0
 /**
  * Builds the parameters array to apply which filters the download report according to the report type, subfilter,
  * date range and survey selected.
  * @param array Form parameters.
  * @return array Parameters array to apply to the report.
  * @throws exception Thrown if requested download type not allowed for this user.
  */
 private static function build_params($args)
 {
     require_once 'includes/user.php';
     $availableTypes = self::get_download_types($args, data_entry_helper::$js_read_tokens);
     if (!array_key_exists($_POST['download-type'], $availableTypes)) {
         throw new exception('Selected download type not authorised');
     }
     $sharing = substr($_POST['download-type'], 0, 1);
     $params = array();
     // Have we got any filters to apply?
     if ($_POST['download-type'] === 'V profile') {
         // the user's profile defined verification settings
         $location_id = hostsite_get_user_field('location_expertise');
         if ($location_id) {
             $params['location_list_context'] = $location_id;
         }
         $taxon_groups_ids = hostsite_get_user_field('taxon_groups_expertise');
         if ($taxon_groups_ids) {
             $params['taxon_group_list_context'] = implode(',', unserialize($taxon_groups_ids));
         }
         $survey_ids = hostsite_get_user_field('surveys_expertise');
         if ($survey_ids) {
             $params['survey_list_context'] = implode(',', unserialize($survey_ids));
         }
         $_POST['download-type'] = 'V';
     } elseif (preg_match('/^[RPVDM] my$/', $_POST['download-type'])) {
         // autogenerated context for my records
         $params['my_records_context'] = 1;
         $_POST['download-type'] = substr($_POST['download-type'], 0, 1);
     }
     if (strlen($_POST['download-type']) > 1 || !empty($_POST['download-subfilter'])) {
         // use the saved filters system to filter the records
         $filterData = self::load_filter_set($sharing);
         if (preg_match('/^[RPVDM] filter (\\d+)$/', $_POST['download-type'], $matches)) {
             // download type includes a context filter from the database
             self::apply_filter_to_params($filterData, $matches[1], '_context', $params);
         }
         if (!empty($_POST['download-subfilter'])) {
             // a download subfilter has been selected
             self::apply_filter_to_params($filterData, $_POST['download-subfilter'], '', $params);
         }
     }
     if (!empty($_POST['survey_id'])) {
         $params['survey_list'] = $_POST['survey_id'];
     }
     $datePrefix = !empty($_POST['date_type']) && $_POST['date_type'] !== 'recorded' ? "{$_POST['date_type']}_" : '';
     if (!empty($_POST['date_from']) && $_POST['date_from'] !== lang::get('Click here')) {
         $params[$datePrefix . 'date_from'] = $_POST['date_from'];
     }
     if (!empty($_POST['date_to']) && $_POST['date_to'] !== lang::get('Click here')) {
         $params[$datePrefix . 'date_to'] = $_POST['date_to'];
     }
     return $params;
 }
コード例 #22
0
 private static function build_filter($args, $readAuth, $format, $useStandardParams)
 {
     require_once 'includes/user.php';
     $filterToApply = $_POST['user-filter'];
     $availableFilters = self::get_filters($args, $readAuth);
     if (!array_key_exists($filterToApply, $availableFilters)) {
         throw new exception('Selected filter type not authorised');
     }
     if ($filterToApply === 'expert') {
         require_once 'includes/user.php';
         $location_expertise = hostsite_get_user_field('location_expertise');
         $taxon_groups_expertise = hostsite_get_user_field('taxon_groups_expertise');
         $taxon_groups_expertise = $taxon_groups_expertise ? unserialize($taxon_groups_expertise) : null;
         $surveys_expertise = hostsite_get_user_field('surveys_expertise');
         $available_surveys = $surveys_expertise ? unserialize($surveys_expertise) : null;
     } else {
         // Default is no filter by survey, locality, taxon group
         $location_expertise = '';
         $available_surveys = '';
         $taxon_groups_expertise = '';
         $surveys_expertise = '';
     }
     // We are downloading either a configured survey, a selected single survey, or the surveys the
     // user can see. The field name used will depend on which of the survey selects were active -
     // either we are selecting from a list of surveys the user is an expert for, or a list of
     // all surveys.
     $surveyFieldName = 'survey_id_' . (preg_match('/^expert/', $filterToApply) ? 'expert' : 'all');
     if (empty($args['survey_id'])) {
         $surveys = empty($_POST[$surveyFieldName]) ? implode(',', $available_surveys) : $_POST[$surveyFieldName];
     } else {
         // survey to load is preconfigured for the form
         $surveys = $args['survey_id'];
     }
     $ownData = $filterToApply === 'mine' ? 1 : 0;
     // depending on if we are using the old explore report format or the new filterable format, the filter field names differ
     $userIdField = $useStandardParams ? 'user_id' : 'currentUser';
     $myRecordsField = $useStandardParams ? 'my_records' : 'ownData';
     $locationIdField = $useStandardParams ? 'indexed_location_id' : 'location_id';
     $surveysListField = $useStandardParams ? 'survey_list' : 'surveys';
     $taxonGroupListField = $useStandardParams ? 'taxon_group_list' : 'taxon_groups';
     $filters = array_merge(array($userIdField => hostsite_get_user_field('indicia_user_id'), $myRecordsField => $ownData, $locationIdField => $location_expertise, 'ownLocality' => !empty($location_expertise) && $filterToApply === 'expert' ? 1 : 0, $taxonGroupListField => !empty($taxon_groups_expertise) ? implode(',', $taxon_groups_expertise) : '', 'ownGroups' => !empty($taxon_groups_expertise) && $taxon_groups_expertise && $filterToApply === 'expert' ? 1 : 0, $surveysListField => $surveys, 'ownSurveys' => empty($surveys) ? 0 : 1), get_options_array_with_user_data($args["report_params_{$format}"]));
     // some of these filter fields are not required for standard params
     if ($useStandardParams) {
         unset($filters['ownLocality']);
         unset($filters['ownGroups']);
         unset($filters['ownSurveys']);
     }
     if (!empty($_POST['date_from']) && $_POST['date_from'] !== lang::get('Click here')) {
         $filters['date_from'] = $_POST['date_from'];
     } else {
         if (!$useStandardParams) {
             $filters['date_from'] = '';
         }
     }
     if (!empty($_POST['date_to']) && $_POST['date_to'] !== lang::get('Click here')) {
         $filters['date_to'] = $_POST['date_to'];
     } else {
         if (!$useStandardParams) {
             $filters['date_to'] = '';
         }
     }
     // now, if they have a verification context filter in force, then apply it
     $filters = array_merge(self::get_filter_verification_context($filterToApply, $readAuth), $filters);
     return $filters;
 }
コード例 #23
0
 /**
  * Performs the action of accepting an invite.
  * @param array $args Form configuration arguments
  * @param array $invite Invitation record
  * @param array $auth Authorisation tokens
  * @return type 
  */
 private static function accept($args, $invite, $auth)
 {
     // insert a groups_users record
     $values = array('group_id' => $invite['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id'), 'administrator' => 'f');
     $auth['write_tokens']['persist_auth'] = true;
     $s = submission_builder::build_submission($values, array('model' => 'groups_user'));
     $r = data_entry_helper::forward_post_to('groups_user', $s, $auth['write_tokens']);
     // either a success, or already a member (2004=unique key violation)
     if (!isset($r['success']) && (!isset($r['code']) || $r['code'] !== 2004)) {
         if (function_exists('watchdog')) {
             watchdog('iform', 'An internal error occurred whilst trying to accept an invite: ' . print_r($r, true));
         }
         return self::fail_message('An internal error occurred whilst trying to accept the invite', $args);
     } elseif (isset($r['code']) && $r['code'] === 2004) {
         hostsite_show_message(lang::get('You are already a member of the group!'));
         hostsite_goto_page($args['groups_page_path']);
     } else {
         // delete the invitation
         $values = array('id' => $invite['id'], 'deleted' => 't');
         $s = submission_builder::build_submission($values, array('model' => 'group_invitation'));
         $r = data_entry_helper::forward_post_to('group_invitation', $s, $auth['write_tokens']);
         $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $invite['group_id'])));
         if (!isset($r['success'])) {
             if (function_exists('watchdog')) {
                 watchdog('iform', 'An internal error occurred whilst trying to delete an accepted invite: ' . print_r($r, true));
             }
             // probably no point telling the user, as the invite accept worked OK
         }
         hostsite_goto_page($args['group_home_path'], array('group_id' => $invite['group_id']));
     }
 }
コード例 #24
0
 /**
  * Loads the group record from the database. Also checks that the user is an admin of the group.
  * @param array $auth Authorisation tokens
  * @return array Group record loaded from the db
  */
 private static function loadGroup($auth)
 {
     if (empty($_GET['group_id']) && !empty($_GET['id'])) {
         $_GET['group_id'] = $_GET['id'];
     }
     if (empty($_GET['group_id'])) {
         throw new exception('Form must be called with an group_id parameter for the group.');
     }
     // check the logged in user is admin of this group
     $response = data_entry_helper::get_population_data(array('table' => 'groups_user', 'extraParams' => $auth['read'] + array('group_id' => $_GET['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id')), 'nocache' => true));
     if (count($response) === 0 || $response[0]['administrator'] === 'f') {
         throw new exception('Attempt to send invites for a group you are not administrator of.');
     }
     $response = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id']), 'nocache' => true));
     return $response[0];
 }
コード例 #25
0
 private static function report_filter_panel($args, $readAuth)
 {
     $options = array('allowSave' => true, 'sharing' => 'verification', 'linkToMapDiv' => 'map', 'filter-quality' => 'P');
     if (!function_exists('iform_ajaxproxy_url')) {
         return 'The AJAX Proxy module must be enabled to support saving filters.';
     }
     if (!function_exists('hostsite_get_user_field') || !hostsite_get_user_field('indicia_user_id')) {
         return 'The verification_4 form requires Easy Login.';
     }
     $r = report_filter_panel($readAuth, $options, $args['website_id'], $hiddenStuff);
     return $r . $hiddenStuff;
 }
コード例 #26
0
 /**
  * Get the control for species input, either a grid or a single species input control.
  */
 protected static function get_control_species($auth, $args, $tabalias, $options)
 {
     global $user;
     $extraParams = $auth['read'];
     $fieldPrefix = !empty($options['fieldprefix']) ? $options['fieldprefix'] : '';
     if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) {
         $filterLines = helper_base::explode_lines($args['taxon_filter']);
         if ($args['multiple_subject_observation_mode'] !== 'single' && $args['taxon_filter_field'] !== 'taxon_group' && count($filterLines) === 1) {
             // The form is configured for filtering by taxon name or meaning id. If there is only one specified then the form
             // cannot display a species checklist, as there is no point. So, convert our preferred taxon name or meaning ID to find the
             // preferred taxa_taxon_list_id from the selected checklist, and then output a hidden ID.
             if (empty($args['list_id'])) {
                 throw new exception(lang::get('Please configure the Initial Species List parameter to define which list the species to record is selected from.'));
             }
             $filter = array('preferred' => 't', 'taxon_list_id' => $args['list_id']);
             if ($args['taxon_filter_field'] == 'preferred_name') {
                 $filter['taxon'] = $filterLines[0];
             } else {
                 $filter[$args['taxon_filter_field']] = $filterLines[0];
             }
             $options = array('table' => 'taxa_taxon_list', 'extraParams' => $auth['read'] + $filter);
             $response = data_entry_helper::get_population_data($options);
             if (count($response) === 0) {
                 throw new exception(lang::get('Failed to find the single species that this form is setup to record in the defined list.'));
             }
             if (count($response) > 1) {
                 throw new exception(lang::get('This form is setup for single species recording, but more than one species with the same name exists in the list.'));
             }
             return '<input type="hidden" name="' . $fieldPrefix . 'occurrence:taxa_taxon_list_id" value="' . $response[0]['id'] . "\"/>\n";
         }
     }
     if (call_user_func(array(get_called_class(), 'getGridMode'), $args)) {
         // multiple species being input via a grid
         $species_ctrl_opts = array_merge(array('listId' => $args['list_id'], 'label' => lang::get('occurrence:taxa_taxon_list_id'), 'columns' => 1, 'extraParams' => $extraParams, 'survey_id' => $args['survey_id'], 'occurrenceComment' => $args['occurrence_comment'], 'occurrenceSensitivity' => isset($args['subject_observation_confidential']) ? $args['subject_observation_confidential'] : false, 'occurrenceImages' => $args['observation_images'], 'PHPtaxonLabel' => true, 'language' => iform_lang_iso_639_2(hostsite_get_user_field('language')), 'cacheLookup' => isset($args['cache_lookup']) && $args['cache_lookup'], 'speciesNameFilterMode' => self::getSpeciesNameFilterMode($args)), $options);
         if ($args['extra_list_id']) {
             $species_ctrl_opts['lookupListId'] = $args['extra_list_id'];
         }
         if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) {
             $species_ctrl_opts['taxonFilterField'] = $args['taxon_filter_field'];
             $species_ctrl_opts['taxonFilter'] = $filterLines;
         }
         if (isset($args['col_widths']) && $args['col_widths']) {
             $species_ctrl_opts['colWidths'] = explode(',', $args['col_widths']);
         }
         call_user_func(array(get_called_class(), 'build_grid_taxon_label_function'), $args);
         call_user_func(array(get_called_class(), 'build_grid_autocomplete_function'), $args);
         // Start by outputting a hidden value that tells us we are using a grid when the data is posted,
         // then output the grid control
         return '<input type="hidden" value="true" name="gridmode" />' . data_entry_helper::species_checklist($species_ctrl_opts);
     } else {
         // A single species entry control of some kind
         if ($args['extra_list_id'] == '') {
             $extraParams['taxon_list_id'] = $args['list_id'];
         } elseif ($args['species_ctrl'] == 'autocomplete') {
             $extraParams['taxon_list_id'] = empty($args['extra_list_id']) ? $args['list_id'] : $args['extra_list_id'];
         } else {
             $extraParams['taxon_list_id'] = array($args['list_id'], $args['extra_list_id']);
         }
         if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) {
             // filter the taxa available to record
             $query = array('in' => array($args['taxon_filter_field'], helper_base::explode_lines($args['taxon_filter'])));
         } else {
             $query = array();
         }
         // Apply the species names filter to the single species picker control
         if (isset($args['species_names_filter'])) {
             $languageFieldName = isset($args['cache_lookup']) && $args['cache_lookup'] ? 'language_iso' : 'language';
             switch ($args['species_names_filter']) {
                 case 'preferred':
                     $extraParams += array('preferred' => 't');
                     break;
                 case 'currentLanguage':
                     if (isset($options['language'])) {
                         $extraParams += array($languageFieldName => $options['language']);
                     }
                     break;
                 case 'excludeSynonyms':
                     $query['where'] = array("(preferred='t' OR {$languageFieldName}<>'lat')");
                     break;
             }
         }
         if (count($query)) {
             $extraParams['query'] = json_encode($query);
         }
         $species_ctrl_opts = array_merge(array('label' => lang::get('occurrence:taxa_taxon_list_id'), 'fieldname' => $fieldPrefix . 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'parentField' => 'parent_id', 'extraParams' => $extraParams, 'blankText' => 'Please select'), $options);
         if (isset($args['cache_lookup']) && $args['cache_lookup']) {
             $species_ctrl_opts['extraParams']['view'] = 'cache';
         }
         global $indicia_templates;
         if (isset($args['species_include_both_names']) && $args['species_include_both_names']) {
             if ($args['species_names_filter'] == 'all') {
                 $indicia_templates['species_caption'] = '{taxon}';
             } elseif ($args['species_names_filter'] == 'language') {
                 $indicia_templates['species_caption'] = '{taxon} - {preferred_name}';
             } else {
                 $indicia_templates['species_caption'] = '{taxon} - {common}';
             }
             $species_ctrl_opts['captionTemplate'] = 'species_caption';
         }
         if ($args['species_ctrl'] == 'tree_browser') {
             // change the node template to include images
             $indicia_templates['tree_browser_node'] = '<div>' . '<img src="' . self::warehouseUrl() . '/upload/thumb-{image_path}" alt="Image of {caption}" width="80" /></div>' . '<span>{caption}</span>';
         }
         // Dynamically generate the species selection control required.
         return call_user_func(array('data_entry_helper', $args['species_ctrl']), $species_ctrl_opts);
     }
 }
コード例 #27
0
ファイル: map.php プロジェクト: BirenRathod/indicia-code
/**
 * Return a list of options to pass to the data_entry_helper::map_panel method, built from the prebuilt
 * form arguments.
 * @param $args
 * @param $readAuth
 * @return array Options array for the map.
 */
function iform_map_get_map_options($args, $readAuth)
{
    // read out the activated preset layers
    $presetLayers = array();
    if (!empty($args['preset_layers'])) {
        foreach ($args['preset_layers'] as $key => $value) {
            if (is_int($key)) {
                // normally a checkbox group would just output an array
                $presetLayers[] = $value;
            } elseif ($value !== 0) {
                // but the Drupal version of the the parameters form (deprecated) leaves a strange array structure in the parameter value.
                $presetLayers[] = $key;
            }
        }
    }
    $options = array('readAuth' => $readAuth, 'presetLayers' => $presetLayers, 'editLayer' => true, 'layers' => array(), 'initial_lat' => $args['map_centroid_lat'], 'initial_long' => $args['map_centroid_long'], 'initial_zoom' => (int) $args['map_zoom'], 'width' => $args['map_width'], 'height' => $args['map_height'], 'standardControls' => array('layerSwitcher', 'panZoomBar'), 'rememberPos' => isset($args['remember_pos']) ? $args['remember_pos'] == true : false);
    // If they have defined a custom base layer, add it
    if (!empty($args['wms_base_title']) && !empty($args['wms_base_url']) && !empty($args['wms_base_layer'])) {
        data_entry_helper::$onload_javascript .= "var baseLayer = new OpenLayers.Layer.WMS(\n      '" . $args['wms_base_title'] . "',\n      '" . $args['wms_base_url'] . "',\n      {layers: '" . $args['wms_base_layer'] . "', sphericalMercator: true}, {singleTile: true}\n    );\n";
        $options['layers'][] = 'baseLayer';
    }
    // Also add any tilecaches they have defined
    if (!empty($args['tile_cache_layers'])) {
        $options['tilecacheLayers'] = json_decode($args['tile_cache_layers'], true);
    }
    // And any indicia Wms layers from the GeoServer
    if (!empty($args['indicia_wms_layers'])) {
        $options['indiciaWMSLayers'] = explode("\n", $args['indicia_wms_layers']);
    }
    // set up standard control list if supplied
    if (array_key_exists('standard_controls', $args) && $args['standard_controls']) {
        $args['standard_controls'] = str_replace("\r\n", "\n", $args['standard_controls']);
        $options['standardControls'] = explode("\n", $args['standard_controls']);
        // If drawing controls are enabled, then allow polygon recording.
        if (in_array('drawPolygon', $options['standardControls']) || in_array('drawLine', $options['standardControls'])) {
            $options['allowPolygonRecording'] = true;
        }
    }
    // And pass through any translation strings, only if they exist
    $msgGeorefSelectPlace = lang::get('LANG_Georef_SelectPlace');
    if ($msgGeorefSelectPlace != 'LANG_Georef_SelectPlace') {
        $options['msgGeorefSelectPlace'] = $msgGeorefSelectPlace;
    }
    $msgGeorefNothingFound = lang::get('LANG_Georef_NothingFound');
    if ($msgGeorefNothingFound != 'LANG_Georef_NothingFound') {
        $options['msgGeorefNothingFound'] = $msgGeorefNothingFound;
    }
    // if in Drupal, and IForm proxy is installed, then use this path as OpenLayers proxy
    if (defined('DRUPAL_BOOTSTRAP_CONFIGURATION') && module_exists('iform_proxy')) {
        global $base_url;
        $options['proxy'] = $base_url . '/?q=' . variable_get('iform_proxy_path', 'proxy') . '&url=';
    }
    // And a single location boundary if defined
    if (!empty($args['location_boundary_id'])) {
        $location = $args['location_boundary_id'];
    } elseif (isset($args['display_user_profile_location']) && $args['display_user_profile_location']) {
        $location = hostsite_get_user_field('location');
    }
    if (!empty($location)) {
        iform_map_zoom_to_location($location, $readAuth);
    }
    return $options;
}
コード例 #28
0
 /**
  * Return the generated form output.
  * @return Form HTML.
  */
 public static function get_form($args)
 {
     iform_load_helpers(array('map_helper', 'data_entry_helper'));
     global $user;
     $readAuth = map_helper::get_read_auth($args['website_id'], $args['password']);
     // setup the map options
     $options = iform_map_get_map_options($args, $readAuth);
     $olOptions = iform_map_get_ol_options($args);
     if (!$args['show_all_species']) {
         if (isset($args['taxon_identifier']) && !empty($args['taxon_identifier'])) {
             // This page is for a predefined species map
             $taxonIdentifier = $args['taxon_identifier'];
         } else {
             if (isset($_GET['taxon'])) {
                 $taxonIdentifier = $_GET['taxon'];
             } else {
                 return lang::get("The distribution map cannot be displayed without a taxon identifier");
             }
         }
         if ($args['external_key'] == true) {
             if (empty($args['taxon_list_id'])) {
                 return lang::get('This form is configured with the Distribution Layer - External Key option ticked, but no species list has been configured to ' . 'lookup the external keys against.');
             }
             // the taxon identifier is an external key, so we need to translate to a meaning ID.
             $fetchOpts = array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + array('view' => 'detail', 'external_key' => $taxonIdentifier, 'taxon_list_id' => $args['taxon_list_id'], 'preferred' => true));
             $prefRecords = data_entry_helper::get_population_data($fetchOpts);
             // We might have multiple records back, e.g. if there are several photos, but we should have a unique meaning id.
             $meaningId = 0;
             foreach ($prefRecords as $prefRecord) {
                 if ($meaningId != 0 && $meaningId != $prefRecord['taxon_meaning_id']) {
                     // bomb out, as we  don't know which taxon to display
                     return lang::get("The taxon identifier cannot be used to identify a unique taxon.");
                 }
                 $meaningId = $prefRecord['taxon_meaning_id'];
             }
             if ($meaningId == 0) {
                 return lang::get("The taxon identified by the taxon identifier cannot be found.");
             }
             $meaningId = $prefRecords[0]['taxon_meaning_id'];
         } else {
             // the taxon identifier is the meaning ID.
             $meaningId = $taxonIdentifier;
         }
         // We still need to fetch the species record, to get its common name
         $fetchOpts = array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + array('view' => 'detail', 'language_iso' => iform_lang_iso_639_2(hostsite_get_user_field('language')), 'taxon_meaning_id' => $meaningId));
         $taxonRecords = data_entry_helper::get_population_data($fetchOpts);
     }
     $url = map_helper::$geoserver_url . 'wms';
     // Get the style if there is one selected
     $style = $args["wms_style"] ? ", styles: '" . $args["wms_style"] . "'" : '';
     map_helper::$onload_javascript .= "\n    var filter='website_id=" . $args['website_id'] . "';";
     if ($args['show_all_species']) {
         $layerTitle = lang::get('All species occurrences');
     } else {
         $layerTitle = str_replace('{species}', $taxonRecords[0]['taxon'], $args['layer_title']);
         map_helper::$onload_javascript .= "\n    filter += ' AND taxon_meaning_id={$meaningId}';\n";
     }
     if (!empty($args['cql_filter'])) {
         map_helper::$onload_javascript .= "\n    filter += ' AND(" . str_replace("'", "\\'", $args['cql_filter']) . ")';\n";
     }
     $layerTitle = str_replace("'", "\\'", $layerTitle);
     map_helper::$onload_javascript .= "\n    var distLayer = new OpenLayers.Layer.WMS(\r\n          '" . $layerTitle . "',\r\n          '{$url}',\r\n          {layers: '" . $args["wms_feature_type"] . "', transparent: true, CQL_FILTER: filter {$style}},\r\n          {isBaseLayer: false, sphericalMercator: true, singleTile: true}\r\n    );\n";
     $options['layers'][] = 'distLayer';
     if (isset($args['click_on_occurrences_mode']) && $args['click_on_occurrences_mode'] != 'none') {
         $options['clickableLayersOutputMode'] = $args['click_on_occurrences_mode'];
         $options['clickableLayersOutputDiv'] = 'getinfo-output';
         $options['clickableLayers'][] = 'distLayer';
         if (!empty($args['click_columns'])) {
             // convert the input column list argument to a structured array to pass to the map
             $inputarr = explode("\r\n", $args['click_columns']);
             $outputarr = array();
             foreach ($inputarr as $coldef) {
                 $coldef = explode('=', $coldef);
                 $outputarr[$coldef[0]] = $coldef[1];
             }
             $options['clickableLayersOutputColumns'] = $outputarr;
         }
     }
     // This is not a map used for input
     $options['editLayer'] = false;
     // if in Drupal, and IForm proxy is installed, then use this path as OpenLayers proxy
     if (defined('DRUPAL_BOOTSTRAP_CONFIGURATION') && module_exists('iform_proxy')) {
         global $base_url;
         $options['proxy'] = $base_url . '?q=' . variable_get('iform_proxy_path', 'proxy') . '&url=';
     }
     // output a legend
     if (isset($args['include_layer_list_types'])) {
         $layerTypes = explode(',', $args['include_layer_list_types']);
     } else {
         $layerTypes = array('base', 'overlay');
     }
     $r = '';
     if (!isset($args['include_layer_list']) || $args['include_layer_list']) {
         $r .= map_helper::layer_list(array('includeSwitchers' => isset($args['include_layer_list_switchers']) ? $args['include_layer_list_switchers'] : true, 'includeHiddenLayers' => true, 'layerTypes' => $layerTypes));
     }
     // output a map
     $r .= map_helper::map_panel($options, $olOptions);
     // add an empty div for the output of getinfo requests
     if (isset($args['click_on_occurrences_mode']) && $args['click_on_occurrences_mode'] == 'div') {
         $r .= '<div id="getinfo-output"></div>';
     }
     // Set up a page refresh for dynamic update of the map at set intervals
     if (!empty($args['refresh_timer']) && $args['refresh_timer'] !== 0 && is_numeric($args['refresh_timer'])) {
         // is_int prevents injection
         if (isset($args['load_on_refresh']) && !empty($args['load_on_refresh'])) {
             map_helper::$javascript .= "setTimeout('window.location=\"" . $args['load_on_refresh'] . "\";', " . $args['refresh_timer'] . "*1000 );\n";
         } else {
             map_helper::$javascript .= "setTimeout('window.location.reload( false );', " . $args['refresh_timer'] . "*1000 );\n";
         }
     }
     return $r;
 }
コード例 #29
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 integer $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)
 {
     global $user;
     //    if (!function_exists('module_exists') || !module_exists('iform_ajaxproxy'))
     //      return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.';
     if (!function_exists('module_exists') || !module_exists('easy_login')) {
         return 'FATAL INTERNAL CONFIGURATION ERROR: This form must be used in Drupal with the Easy Login module enabled.';
     }
     if (!function_exists('module_exists') || !module_exists('species_packages')) {
         return 'FATAL INTERNAL CONFIGURATION ERROR: This form must be used in Drupal with the custom species_packages module enabled.';
     }
     // assuming easy login
     $userId = hostsite_get_user_field('indicia_user_id');
     if (empty($userId)) {
         return '<p>FATAL ERROR: Could not identify user.</p>';
     }
     // something is wrong
     $r = isset($response['error']) ? data_entry_helper::dump_errors($response) : '';
     iform_load_helpers(array('map_helper', 'report_helper'));
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     self::$sampleId = null;
     self::$occurrenceId = false;
     if (isset(data_entry_helper::$entity_to_load['sample:id']) && data_entry_helper::$entity_to_load['sample:id'] != "") {
         // have just posted a (failed) edit to an existing parent sample.
         self::$sampleId = data_entry_helper::$entity_to_load['sample:id'];
     } else {
         if (isset(data_entry_helper::$entity_to_load['sample:survey_id']) && data_entry_helper::$entity_to_load['sample:survey_id'] != "") {
             // have just posted a (failed) edit to a new parent sample.
             self::$sampleId = null;
         } else {
             if (isset($response['outer_id'])) {
                 // have just successfully posted either a new parent sample, or an update to an existing one.
                 self::$sampleId = $response['outer_id'];
                 data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 if (!isset($_POST['force_page_reload'])) {
                     return self::get_success_page($args, $auth, $response['outer_id']);
                 }
                 drupal_set_message(lang::get('The Transect you have just saved specified the Species Package to be used. The Transect has been reloaded below, and the Species tab now contains the Species Grid for the Species Package, which will allow you to enter the species data.'));
             } else {
                 if (isset($_GET['sample_id']) && intval($_GET['sample_id']) == $_GET['sample_id']) {
                     self::$sampleId = $_GET['sample_id'];
                     data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 } else {
                     self::$sampleId = null;
                 }
             }
         }
     }
     if (isset($_GET['occurrence_id']) && intval($_GET['occurrence_id']) == $_GET['occurrence_id']) {
         self::$occurrenceId = $_GET['occurrence_id'];
         if (self::$sampleId == null) {
             // fill in the sample_id from the occurrence if don't already have it
             $occurrence = data_entry_helper::get_population_data(array('table' => 'occurrence', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => self::$occurrenceId)));
             // this throws an error exception if any error.
             // this gives
             if (count($occurrence) == 1) {
                 $subsample = data_entry_helper::get_population_data(array('table' => 'sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $occurrence[0]['sample_id'])));
                 if (count($subsample) == 1) {
                     self::$sampleId = $subsample[0]['parent_id'];
                     data_entry_helper::load_existing_record($auth['read'], 'sample', self::$sampleId, 'detail', false, true);
                 }
             }
         }
     }
     if (isset(data_entry_helper::$entity_to_load['sample:survey_id']) && data_entry_helper::$entity_to_load['sample:survey_id'] != $args['survey_id']) {
         drupal_set_message(t('The data entry form you have selected to use is configured for a particular survey:') . ' ID ' . $args['survey_id'] . ' ' . t('The sample you have chosen to view is not assigned to this survey.'), 'error');
         drupal_goto('<front>');
     }
     if (isset(data_entry_helper::$entity_to_load['sample:parent_id']) && data_entry_helper::$entity_to_load['sample:parent_id'] != '' && data_entry_helper::$entity_to_load['sample:parent_id'] !== null) {
         drupal_set_message(t('An attempt has been made to access a non top level sample.'));
         drupal_goto('<front>');
     }
     $survey = data_entry_helper::get_population_data(array('table' => 'survey', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $args['survey_id'], 'website_id' => $args['website_id'])));
     if (count($survey) != 1) {
         return "FATAL INTERNAL CONFIGURATION ERROR: Supplied form survey_id value (" . $args['survey_id'] . ") is not valid survey for this website (" . $args['website_id'] . ").<br/>";
     }
     $surveyTitle = $survey[0]['title'];
     if (self::$sampleId == null) {
         $packages = species_packages_get_packages($user->uid, $args['survey_id']);
         if ($packages === false || is_array($packages) && count($packages) == 0) {
             drupal_set_message(t('You have not yet selected a species package that is compatible with survey') . ' : &quot;' . $surveyTitle . '&quot;', 'error');
             drupal_set_message(str_replace('#link#', '<a href="' . url('user/' . $user->uid . '/edit') . '">' . t('this link') . '</a>', t('You can set the species package on your user account page, which can be accessed using #link#. If you have already selected a species package, and wish to add another or wish to change your selection, please contact your Hub Manager.')));
             drupal_goto('<front>');
         }
         self::$readOnly = false;
     } else {
         self::$readOnly = !isset($response['error']) && data_entry_helper::$entity_to_load['sample:created_by_id'] != hostsite_get_user_field('indicia_user_id') && (empty($args['edit_permission']) || !hostsite_user_has_permission($args['edit_permission']));
     }
     if (self::$readOnly) {
         drupal_set_message(t('In order to save changes to existing records, you must either be the creator of the entry, or have been given the appropriate permission.'));
     }
     // In readonly mode, the forms are replaced by divs and there are no save buttons.
     //    $r .= '<span style="display:none;">'.print_r($packages,true).'</span>';
     //	$r .= '<span style="display:none;">'.print_r(array($user->uid, $args, $packageAttr), true).'</span>' .
     $attributes = data_entry_helper::getAttributes(array('id' => self::$sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $args['transect_level_sample_method_id']));
     $packageAttr = self::extract_package_attr($attributes, true);
     if (!$packageAttr) {
         return "FATAL INTERNAL CONFIGURATION ERROR: This form must be used with a survey which has a &#x22;Species Package&#x22; sample attribute defined for it (integer, required on parent).<br/>";
     }
     self::_remove_options($args);
     $r .= (self::$readOnly ? '<div id="data_entry_form">' : '<form method="post" id="data_entry_form">' . $auth['write']) . '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>' . (isset(data_entry_helper::$entity_to_load['sample:id']) ? '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>' : '') . '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>' . '<input type="hidden" name="sample:sample_method_id" value="' . $args['transect_level_sample_method_id'] . '" />';
     if (isset(data_entry_helper::$entity_to_load['sample:id'])) {
         $r .= "<h2>" . data_entry_helper::$entity_to_load['sample:location_name'] . " on " . data_entry_helper::$entity_to_load['sample:date'] . (self::$readOnly ? ' ' . lang::get('READ ONLY') : '') . "</h2>\n";
     }
     $r .= "<div id=\"tabs\">\n";
     $tabs = array();
     $smpTab = self::get_sample_tab($args, $nid, $auth, $attributes, $packageAttr);
     $mediaTab = self::get_media_tab($args, $nid, $auth);
     $occTab = self::get_occurrences_tab($args, $nid, $auth, $packageAttr);
     // Note this messes with the templates, so done last just in case
     $tabs['#sample'] = t($args['sample_tab_label']);
     if ($occTab != "") {
         $tabs['#occurrences'] = t($args['occurrence_tab_label']);
     }
     if ($mediaTab != "") {
         $tabs['#media'] = t($args['media_tab_label']);
     }
     $r .= data_entry_helper::tab_header(array('tabs' => $tabs));
     data_entry_helper::enable_tabs(array('divId' => 'tabs', 'style' => 'Tabs', 'active' => $occTab != "" && (self::$occurrenceId || self::$sampleId) ? 'occurrences' : 'sample'));
     $r .= $smpTab . $occTab . $mediaTab . '</div>' . (self::$readOnly ? '</div>' : '</form>');
     if (!self::$readOnly) {
         // custom version of enable validation code
         data_entry_helper::$validated_form_id = 'data_entry_form';
         data_entry_helper::$javascript .= "indiciaData.validatedFormId = '" . data_entry_helper::$validated_form_id . "';\n";
         // prevent double submission of the form
         data_entry_helper::$javascript .= "\$('#data_entry_form').submit(function(e) {\r\n  if (typeof \$('#data_entry_form').valid === 'undefined' || \$('#data_entry_form').valid()) {\r\n    if (typeof indiciaData.formSubmitted==='undefined' || !indiciaData.formSubmitted) {\r\n      \$('<p>" . lang::get('Please wait whilst the data is saved.') . "</p>').dialog({ title: '" . lang::get('Saving Data') . "', buttons: { '" . lang::get('OK') . "' : function() { \$( this ).dialog('close'); } } });\r\n      indiciaData.formSubmitted=true;\r\n    } else {\r\n      e.preventDefault();\r\n      return false;\r\n    }\r\n  }\r\n});\n";
         data_entry_helper::add_resource('validation');
     }
     return $r;
 }
コード例 #30
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)
 {
     $form = '<form action="#" method="POST" id="entry_form">';
     if ($_POST) {
         $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
         self::subscribe($args, $auth);
     } else {
         // don't bother with write auth for initial form load, as read auth is cached and faster
         $auth = array('read' => data_entry_helper::get_read_auth($args['website_id'], $args['password']));
     }
     if (!empty($_GET['id'])) {
         data_entry_helper::load_existing_record($auth['read'], 'species_alert', $_GET['id']);
         // enforce permissions
         if (data_entry_helper::$entity_to_load['species_alert:user_id'] != hostsite_get_user_field('indicia_user_id')) {
             return lang::get('You cannot modify a species alert subscription created by someone else');
         }
         $form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:id', 'default' => $_GET['id']));
     }
     // if not logged in, then ask for details to register against
     global $user;
     if (!hostsite_get_user_field('id') || !isset($user) || empty($user->mail) || !hostsite_get_user_field('last_name')) {
         $form .= "<fieldset><legend>" . lang::get('Your details') . ":</legend>\n";
         $default = empty($_POST['first_name']) ? hostsite_get_user_field('first_name', '') : $_POST['first_name'];
         $form .= data_entry_helper::text_input(array('label' => lang::get('First name'), 'fieldname' => 'first_name', 'validation' => array('required'), 'default' => $default, 'class' => 'control-width-4'));
         $default = empty($_POST['surname']) ? hostsite_get_user_field('last_name', '') : $_POST['surname'];
         $form .= data_entry_helper::text_input(array('label' => lang::get('Last name'), 'fieldname' => 'surname', 'validation' => array('required'), 'default' => $default, 'class' => 'control-width-4'));
         $default = empty($_POST['email']) ? empty($user->mail) ? '' : $user->mail : $_POST['email'];
         $form .= data_entry_helper::text_input(array('label' => lang::get('Email'), 'fieldname' => 'email', 'validation' => array('required', 'email'), 'default' => $default, 'class' => 'control-width-4'));
         $form .= "</fieldset>\n";
     } else {
         $form .= data_entry_helper::hidden_text(array('fieldname' => 'first_name', 'default' => hostsite_get_user_field('first_name')));
         $form .= data_entry_helper::hidden_text(array('fieldname' => 'surname', 'default' => hostsite_get_user_field('last_name')));
         $form .= data_entry_helper::hidden_text(array('fieldname' => 'email', 'default' => $user->mail));
         $form .= data_entry_helper::hidden_text(array('fieldname' => 'user_id', 'default' => hostsite_get_user_field('indicia_user_id')));
     }
     $form .= "<fieldset><legend>" . lang::get('Alert criteria') . ":</legend>\n";
     // Output the species selection control
     // Default after saving with a validation failure can be pulled direct from the post, but
     // when reloading we don't need a default taxa taxon list ID since we already know the meaning
     // ID or external key.
     $default = empty($_POST['taxa_taxon_list_id']) ? '' : $_POST['taxa_taxon_list_id'];
     if (empty($_POST['taxa_taxon_list_id:taxon'])) {
         $defaultCaption = empty(data_entry_helper::$entity_to_load['species_alert:preferred_taxon']) ? '' : data_entry_helper::$entity_to_load['species_alert:preferred_taxon'];
     } else {
         $defaultCaption = $_POST['taxa_taxon_list_id:taxon'];
     }
     $form .= data_entry_helper::species_autocomplete(array('label' => lang::get('Alert species'), 'helpText' => lang::get('Select the species you are interested in receiving alerts in ' . 'relation to if you want to receive alerts on a single species.'), 'fieldname' => 'taxa_taxon_list_id', 'cacheLookup' => true, 'extraParams' => $auth['read'] + array('taxon_list_id' => $args['list_id']), 'class' => 'control-width-4', 'default' => $default, 'defaultCaption' => $defaultCaption));
     if (empty($default)) {
         // Unless we've searched for the species name then posted (and failed), then the
         // default will be empty. We might therefore be reloading existing data which has
         // a meaning ID or external key.
         if (!empty(data_entry_helper::$entity_to_load['species_alert:external_key'])) {
             $form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:external_key', 'default' => data_entry_helper::$entity_to_load['species_alert:external_key']));
         } elseif (!empty(data_entry_helper::$entity_to_load['species_alert:taxon_meaning_id'])) {
             $form .= data_entry_helper::hidden_text(array('fieldname' => 'species_alert:taxon_meaning_id', 'default' => data_entry_helper::$entity_to_load['species_alert:taxon_meaning_id']));
         }
     }
     if (!empty($args['full_lists'])) {
         $form .= data_entry_helper::select(array('label' => lang::get('Select full species lists'), 'helpText' => lang::get('If you want to restrict the alerts to records of any ' . 'species within a species list, then select the list here.'), 'fieldname' => 'species_alert:taxon_list_id', 'blankText' => lang::get('<Select a species list>'), 'table' => 'taxon_list', 'valueField' => 'id', 'captionField' => 'title', 'extraParams' => $auth['read'] + array('id' => $args['full_lists'], 'orderby' => 'title'), 'class' => 'control-width-4'));
     }
     $form .= data_entry_helper::location_select(array('label' => lang::get('Select location'), 'helpText' => lang::get('If you want to restrict the alerts to records within a certain boundary, select it here.'), 'fieldname' => 'species_alert:location_id', 'id' => 'imp-location', 'blankText' => lang::get('<Select boundary>'), 'extraParams' => $auth['read'] + array('location_type_id' => $args['location_type_id'], 'orderby' => 'name'), 'class' => 'control-width-4'));
     $form .= data_entry_helper::checkbox(array('label' => lang::get('Alert on initial entry'), 'helpText' => lang::get('Tick this box if you want to receive a notification when the record is first input into the system.'), 'fieldname' => 'species_alert:alert_on_entry'));
     $form .= data_entry_helper::checkbox(array('label' => lang::get('Alert on verification as correct'), 'helpText' => lang::get('Tick this box if you want to receive a notification when the record has been verified as correct.'), 'fieldname' => 'species_alert:alert_on_verify'));
     $form .= "</fieldset>\n";
     $form .= '<input type="Submit" value="Subscribe" />';
     $form .= '</form>';
     data_entry_helper::enable_validation('entry_form');
     iform_load_helpers(array('map_helper'));
     $mapOptions = iform_map_get_map_options($args, $auth['read']);
     $map = map_helper::map_panel($mapOptions);
     global $indicia_templates;
     return str_replace(array('{col-1}', '{col-2}'), array($form, $map), $indicia_templates['two-col-50']);
 }