コード例 #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
 /**
  * Return the Indicia form code
  * @param array $args Input parameters.
  * @param array $node Drupal node object
  * @param array $response Response from Indicia services after posting a verification.
  * @return HTML string
  */
 public static function get_form($args, $node, $response)
 {
     iform_load_helpers(array('import_helper'));
     $auth = import_helper::get_read_write_auth($args['website_id'], $args['password']);
     group_authorise_form($args, $auth['read']);
     if ($args['model'] == 'url') {
         if (!isset($_GET['type'])) {
             return "This form is configured so that it must be called with a type parameter in the URL";
         }
         $model = $_GET['type'];
     } else {
         $model = $args['model'];
     }
     if (isset($args['presetSettings'])) {
         $presets = get_options_array_with_user_data($args['presetSettings']);
         $presets = array_merge(array('website_id' => $args['website_id'], 'password' => $args['password']), $presets);
     } else {
         $presets = array('website_id' => $args['website_id'], 'password' => $args['password']);
     }
     if (!empty($_GET['group_id'])) {
         // loading data into a recording group.
         $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail')));
         $group = $group[0];
         $presets['sample:group_id'] = $_GET['group_id'];
         hostsite_set_page_title(lang::get('Import data into the {1} group', $group['title']));
         // if a single survey specified for this group, then force the data into the correct survey
         $filterdef = json_decode($group['filter_definition'], true);
         if (!empty($filterdef['survey_list_op']) && $filterdef['survey_list_op'] === 'in' && !empty($filterdef['survey_list'])) {
             $surveys = explode(',', $filterdef['survey_list']);
             if (count($surveys) === 1) {
                 $presets['survey_id'] = $surveys[0];
             }
         }
     }
     try {
         $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets));
     } catch (Exception $e) {
         hostsite_show_message($e->getMessage(), 'warning');
         $reload = import_helper::get_reload_link_parts();
         unset($reload['params']['total']);
         unset($reload['params']['uploaded_csv']);
         $reloadpath = $reload['path'] . '?' . import_helper::array_to_query_string($reload['params']);
         $r = "<p>" . lang::get('Would you like to ') . "<a href=\"{$reloadpath}\">" . lang::get('import another file?') . "</a></p>";
     }
     return $r;
 }
コード例 #3
0
 /**
  * Given a maybe response, leave the invite alone, and redirect to the groups home page.
  * @param array $args Form config arguments
  * @param array $invite Invitation record
  * @param array $auth Authorisation tokens
  */
 private static function maybe($args, $invite, $auth)
 {
     hostsite_show_message(lang::get('Just follow the link in your invitation email if and when you are ready to join.'));
     hostsite_goto_page($args['groups_page_path']);
 }
コード例 #4
0
 /**
  * Method called when posting the form. Saves the subscription details to the warehouse.
  * @param $args
  * @param $auth
  * @throws \exception
  */
 private static function subscribe($args, $auth)
 {
     $url = data_entry_helper::$base_url . 'index.php/services/species_alerts/register?';
     $params = array('auth_token' => $auth['write_tokens']['auth_token'], 'nonce' => $auth['write_tokens']['nonce'], 'first_name' => $_POST['first_name'], 'surname' => $_POST['surname'], 'email' => $_POST['email'], 'website_id' => $args['website_id'], 'alert_on_entry' => $_POST['species_alert:alert_on_entry'] ? 't' : 'f', 'alert_on_verify' => $_POST['species_alert:alert_on_verify'] ? 't' : 'f');
     if (!empty($_POST['species_alert:id'])) {
         $params['id'] = $_POST['species_alert:id'];
     }
     if (!empty($_POST['species_alert:taxon_list_id'])) {
         $params['taxon_list_id'] = $_POST['species_alert:taxon_list_id'];
     }
     if (!empty($_POST['species_alert:location_id'])) {
         $params['location_id'] = $_POST['species_alert:location_id'];
     }
     if (!empty($_POST['user_id'])) {
         $params['user_id'] = $_POST['user_id'];
     }
     if (!empty($_POST['taxa_taxon_list_id'])) {
         // We've got a taxa_taxon_list_id in the post data. But, it is better to subscribe via a taxon
         // meaning ID, or even better, the external key.
         $taxon = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $auth['read'] + array('id' => $_POST['taxa_taxon_list_id'], 'view' => 'cache')));
         if (count($taxon) !== 1) {
             throw new exception('Unable to find unique taxon when attempting to subscribe');
         }
         $taxon = $taxon[0];
         if (!empty($taxon['external_key'])) {
             $params['external_key'] = $taxon['external_key'];
         } else {
             $params['taxon_meaning_id'] = $taxon['taxon_meaning_id'];
         }
     } elseif (!empty($_POST['species_alert:external_key'])) {
         $params['external_key'] = $_POST['species_alert:external_key'];
     } elseif (!empty($_POST['species_alert:taxon_meaning_id'])) {
         $params['taxon_meaning_id'] = $_POST['species_alert:taxon_meaning_id'];
     }
     $url .= data_entry_helper::array_to_query_string($params, true);
     $result = data_entry_helper::http_post($url);
     if ($result['result']) {
         hostsite_show_message(lang::get('Your subscription has been saved.'));
     } else {
         hostsite_show_message(lang::get('There was a problem saving your subscription.'));
         if (function_exists('watchdog')) {
             watchdog('iform', 'Species alert error on save: ' . print_r($result, true));
         }
     }
 }
コード例 #5
0
 private static function abort($msg, $args)
 {
     hostsite_show_message($msg);
     // if there is a main page for groups, and this page was deliberately called (i.e. not just a cron indexing scan) then
     // we can go back.
     if (!empty($_GET['group_id']) && !empty($args['groups_page_path'])) {
         hostsite_goto_page($args['groups_page_path']);
     }
 }
コード例 #6
0
 /**
  * Takes a response from a call to forward_post_to() and outputs any errors from it onto the screen.
  *
  * @param string $response Return value from a call to forward_post_to().
  * @param boolean $inline Set to true if the errors are to be placed alongside the controls rather than at the top of the page.
  * Default is true.
  * @see forward_post_to()
  * @link http://code.google.com/p/indicia/wiki/TutorialBuildingBasicPage#Build_a_data_entry_page
  */
 public static function dump_errors($response, $inline = true)
 {
     $r = "";
     if (is_array($response)) {
         // set form mode
         self::$form_mode = 'ERRORS';
         if (array_key_exists('error', $response) || array_key_exists('errors', $response)) {
             if ($inline && array_key_exists('errors', $response)) {
                 // Setup an errors array that the data_entry_helper can output alongside the controls
                 self::$validation_errors = $response['errors'];
                 // And tell the helper to reload the existing data.
                 self::$entity_to_load = $_POST;
                 if (isset($response['code'])) {
                     switch ($response['code']) {
                         case 2003:
                             if (function_exists('hostsite_show_message')) {
                                 hostsite_show_message(lang::get('The data could not be saved.'), 'error');
                             } else {
                                 $r .= "<div class=\"ui-widget ui-corner-all ui-state-highlight page-notice\">" . lang::get('The data could not be saved.') . "</div>\n";
                             }
                     }
                 }
             } else {
                 $r .= "<div class=\"ui-state-error ui-corner-all\">\n";
                 $r .= "<p>An error occurred when the data was submitted.</p>\n";
                 if (is_array($response['error'])) {
                     $r .= "<ul>\n";
                     foreach ($response['error'] as $field => $message) {
                         $r .= "<li>{$field}: {$message}</li>\n";
                     }
                     $r .= "</ul>\n";
                 } else {
                     $r .= "<p class=\"error_message\">" . $response['error'] . "</p>\n";
                 }
                 if (array_key_exists('file', $response) && array_key_exists('line', $response)) {
                     $r .= "<p>Error occurred in " . $response['file'] . " at line " . $response['line'] . "</p>\n";
                 }
                 if (array_key_exists('errors', $response)) {
                     $r .= "<pre>" . print_r($response['errors'], true) . "</pre>\n";
                 }
                 if (array_key_exists('trace', $response)) {
                     $r .= "<pre>" . print_r($response['trace'], true) . "</pre>\n";
                 }
                 $r .= "</div>\n";
             }
         } elseif (array_key_exists('warning', $response)) {
             if (function_exists('hostsite_show_message')) {
                 hostsite_show_message(lang::get('A warning occurred when the data was submitted.') . ' ' . $response['error'], 'error');
             } else {
                 $r .= 'A warning occurred when the data was submitted.';
                 $r .= '<p class="error">' . $response['error'] . "</p>\n";
             }
         } elseif (array_key_exists('success', $response)) {
             $successMessage = lang::get('Thank you for submitting your data.');
             if (function_exists('hostsite_show_message')) {
                 hostsite_show_message($successMessage);
             } else {
                 $r .= "<div class=\"ui-widget ui-corner-all ui-state-highlight page-notice\">" . $successMessage . "</div>\n";
             }
         }
     } else {
         $r .= "<div class=\"ui-state-error ui-corner-all\">{$response}</div>\n";
     }
     return $r;
 }
コード例 #7
0
 private static function abort($msg, $args)
 {
     hostsite_show_message(lang::get($msg));
     if (!empty($_GET['group_id']) && !empty($args['groups_page_path'])) {
         hostsite_goto_page($args['groups_page_path']);
     }
 }
コード例 #8
0
 /**
  * Applies any filters set in the page URL to the report options.
  */
 private static function check_filters(&$reportOptions)
 {
     if (!empty($_GET['my_records'])) {
         $reportOptions['extraParams']['my_records'] = $_GET['my_records'];
         $reportOptions['extraParams']['user_id'] = hostsite_get_user_field('indicia_user_id');
     }
     if (!empty($_GET['year'])) {
         $_GET['year'] = trim($_GET['year']);
         if (is_numeric($_GET['year']) && strlen($_GET['year']) === 4) {
             if ($_GET['year'] > date('Y')) {
                 hostsite_show_message(lang::get('Please select a year to report on that is not in the future.'), 'warning');
             } else {
                 $reportOptions['extraParams']['date_from'] = "{$_GET['year']}/01/01";
                 $reportOptions['extraParams']['date_to'] = "{$_GET['year']}/12/31";
             }
         } else {
             hostsite_show_message(lang::get('Please enter the year as a 4 digit number.'), 'warning');
         }
     }
     if (!empty($_GET['taxon_group_list'])) {
         $reportOptions['extraParams']['taxon_group_list'] = $_GET['taxon_group_list'];
     }
 }
コード例 #9
0
 private static function check_prerequisites()
 {
     $msg = false;
     if (!function_exists('iform_ajaxproxy_url')) {
         $msg = 'The AJAX Proxy module must be enabled to support saving filters on the verification page.';
     }
     if (!module_exists('easy_login')) {
         $msg = 'The verification 4 page requires the Easy Login module to be enabled.';
     }
     if (!function_exists('hostsite_get_user_field') || !hostsite_get_user_field('indicia_user_id')) {
         $msg = 'Before verifying records, please visit your user account profile and ensure that you have entered your full name, then save it.';
     }
     if ($msg) {
         hostsite_show_message($msg, 'warning');
     }
     return $msg ? false : true;
 }
コード例 #10
0
 /**
  * Override the get_form_html function.
  * getForm in dynamic.php will now call this.
  * Vary the display of the page based on the interface type
  * 
  * @package    Client
  * @subpackage PrebuiltForms
  */
 protected static function get_form_html($args, $auth, $attributes)
 {
     if (isset($_POST['enable'])) {
         module_enable(array('iform_ajaxproxy'));
         hostsite_show_message(lang::get('The Indicia AJAX Proxy module has been enabled.'));
     }
     if (!defined('IFORM_AJAXPROXY_PATH')) {
         $r = '<p>' . lang::get('The Indicia AJAX Proxy module must be enabled to use this form. This lets the form save verifications to the ' . 'Indicia Warehouse without having to reload the page.') . '</p>';
         $r .= '<form method="post">';
         $r .= '<input type="hidden" name="enable" value="t"/>';
         $r .= '<input type="submit" value="' . lang::get('Enable Indicia AJAX Proxy') . '"/>';
         $r .= '</form>';
         return $r;
     }
     if (empty($_GET['taxa_taxon_list_id']) && empty($_GET['taxon_meaning_id'])) {
         return 'This form requires a taxa_taxon_list_id or taxon_meaning_id parameter in the URL.';
     }
     self::get_names($auth);
     hostsite_set_page_title(lang::get('Summary details for {1}', self::$preferred));
     return parent::get_form_html($args, $auth, $attributes);
 }