예제 #1
0
 /**
  * Return the generated form output.
  * @param array $args List of parameter values passed through to the form depending on how the form has been configured.
  * This array always contains a value for language.
  * @param object $node The Drupal node object.
  * @param array $response When this form is reloading after saving a submission, contains the response from the service call.
  * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data).
  * @return Form HTML.
  */
 public static function get_form($args, $node, $response = null)
 {
     if (!hostsite_get_user_field('indicia_user_id')) {
         return 'Please ensure that you\'ve filled in your surname on your user profile before creating or editing groups.';
     }
     iform_load_helpers(array('report_helper', 'map_helper'));
     $args = array_merge(array('include_code' => false, 'include_dates' => false, 'include_report_filter' => true, 'include_private_records' => false, 'include_administrators' => false, 'include_members' => false, 'filter_types' => '{"":"what,where,when","Advanced":"source,quality"}'), $args);
     $args['filter_types'] = json_decode($args['filter_types'], true);
     $reloadPath = self::getReloadPath();
     data_entry_helper::$website_id = $args['website_id'];
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     if (!empty($_GET['group_id'])) {
         self::loadExistingGroup($_GET['group_id'], $auth, $args);
     } else {
         if (!empty($args['parent_group_relationship_type']) && empty($_GET['from_group_id'])) {
             return 'This form should be called with a from_group_id parameter to define the parent when creating a new group';
         }
     }
     $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n";
     $r .= $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n";
     $r .= data_entry_helper::hidden_text(array('fieldname' => 'group:id'));
     if (!empty($args['group_type'])) {
         $r .= '<input type="hidden" name="group:group_type_id" value="' . $args['group_type'] . '"/>';
         $response = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $auth['read'] + array('id' => $args['group_type'])));
         self::$groupType = strtolower($response[0]['term']);
     }
     if (!empty(data_entry_helper::$entity_to_load['group:title']) && function_exists('drupal_set_title')) {
         drupal_set_title(lang::get('Edit {1}', data_entry_helper::$entity_to_load['group:title']));
     }
     $r .= data_entry_helper::text_input(array('label' => lang::get('{1} name', ucfirst(self::$groupType)), 'fieldname' => 'group:title', 'validation' => array('required'), 'class' => 'control-width-5', 'helpText' => lang::get('The full title of the {1}', self::$groupType)));
     if ($args['include_code']) {
         $r .= data_entry_helper::text_input(array('label' => lang::get('Code'), 'fieldname' => 'group:code', 'class' => 'control-width-4', 'helpText' => lang::get('A code or abbreviation identifying the {1}', self::$groupType)));
     }
     if (empty($args['group_type'])) {
         $r .= data_entry_helper::select(array('label' => lang::get('Group type'), 'fieldname' => 'group:group_type_id', 'required' => true, 'table' => 'termlists_term', 'valueField' => 'id', 'captionField' => 'term', 'extraParams' => $auth['read'] + array('termlist_external_key' => 'indicia:group_types'), 'class' => 'control-width-4'));
     }
     $r .= self::joinMethodsControl($args);
     $r .= data_entry_helper::textarea(array('label' => ucfirst(lang::get('{1} description', self::$groupType)), 'fieldname' => 'group:description', 'helpText' => lang::get('Description and notes about the {1}.', self::$groupType)));
     $r .= self::dateControls($args);
     if ($args['include_private_records']) {
         $r .= data_entry_helper::checkbox(array('label' => lang::get('Records are private'), 'fieldname' => 'group:private_records', 'helpText' => lang::get('Tick this box if you want to withold the release of the records from this {1} until a ' . 'later point in time, e.g. when a project is completed.', self::$groupType)));
     }
     $r .= self::memberControls($args, $auth);
     $r .= self::reportFilterBlock($args, $auth, $hiddenPopupDivs);
     // auto-insert the creator as an admin of the new group, unless the admins are manually specified
     if (!$args['include_administrators'] && empty($_GET['group_id'])) {
         $r .= '<input type="hidden" name="groups_user:admin_user_id[]" value="' . hostsite_get_user_field('indicia_user_id') . '"/>';
     }
     $r .= '<input type="hidden" name="groups_user:administrator" value="t"/>';
     $r .= '<input type="submit" class="indicia-button" id="save-button" value="' . (empty(data_entry_helper::$entity_to_load['group:id']) ? lang::get('Create {1}', self::$groupType) : lang::get('Update {1} settings', self::$groupType)) . "\" />\n";
     $r .= '</form>';
     $r .= $hiddenPopupDivs;
     data_entry_helper::enable_validation('entry_form');
     // JavaScript to grab the filter definition and store in the form for posting when the form is submitted
     data_entry_helper::$javascript .= "\n\$('#entry_form').submit(function() {\n  \$('#filter-title-val').val('" . lang::get('Filter for user group') . " ' + \$('#group\\\\:title').val());\n  \$('#filter-def-val').val(JSON.stringify(indiciaData.filter.def));\n});\n";
     return $r;
 }
예제 #2
0
 /**
  * Return the generated form output.
  * @return Form HTML.
  */
 public static function get_form($args, $node)
 {
     data_entry_helper::$website_id = $args['website_id'];
     if (!empty($args['high_volume']) && $args['high_volume']) {
         // node level caching for most page hits
         $cached = data_entry_helper::cache_get(array('node' => $node->nid), HIGH_VOLUME_CACHE_TIMEOUT);
         if ($cached !== false) {
             $cached = explode('|!|', $cached);
             data_entry_helper::$javascript = $cached[1];
             data_entry_helper::$late_javascript = $cached[2];
             data_entry_helper::$onload_javascript = $cached[3];
             data_entry_helper::$required_resources = json_decode($cached[4], true);
             return $cached[0];
         }
     }
     self::$node = $node;
     self::$called_class = 'iform_' . $node->iform;
     // Convert parameter, defaults, into structured array
     self::parse_defaults($args);
     // Supply parameters that may be missing after form upgrade
     if (method_exists(self::$called_class, 'getArgDefaults')) {
         $args = call_user_func(array(self::$called_class, 'getArgDefaults'), $args);
     }
     // Get authorisation tokens to update and read from the Warehouse. We allow child classes to generate this first if subclassed.
     if (self::$auth) {
         $auth = self::$auth;
     } else {
         $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
         self::$auth = $auth;
     }
     // Determine how the form was requested and therefore what to output
     $mode = method_exists(self::$called_class, 'getMode') ? call_user_func(array(self::$called_class, 'getMode'), $args, $node) : '';
     self::$mode = $mode;
     if ($mode === self::MODE_GRID) {
         // Output a grid of existing records
         $r = call_user_func(array(self::$called_class, 'getGrid'), $args, $node, $auth);
     } else {
         if (($mode === self::MODE_EXISTING || $mode === self::MODE_EXISTING_RO || $mode === self::MODE_CLONE) && is_null(data_entry_helper::$entity_to_load)) {
             // only load if not in error situation.
             call_user_func_array(array(self::$called_class, 'getEntity'), array(&$args, $auth));
         }
         // attributes must be fetched after the entity to load is filled in - this is because the id gets filled in then!
         $attributes = method_exists(self::$called_class, 'getAttributes') ? call_user_func(array(self::$called_class, 'getAttributes'), $args, $auth) : array();
         $r = call_user_func(array(self::$called_class, 'get_form_html'), $args, $auth, $attributes);
     }
     if (!empty($args['high_volume']) && $args['high_volume']) {
         $c = $r . '|!|' . data_entry_helper::$javascript . '|!|' . data_entry_helper::$late_javascript . '|!|' . data_entry_helper::$onload_javascript . '|!|' . json_encode(data_entry_helper::$required_resources);
         data_entry_helper::cache_set(array('node' => $node->nid), $c, HIGH_VOLUME_CACHE_TIMEOUT);
     }
     return $r;
 }
예제 #3
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)
 {
     global $indicia_templates;
     iform_load_helpers(array('map_helper', 'report_helper'));
     // apply defaults
     $args = array_merge(array(), $args);
     $reloadPath = self::getReloadPath();
     data_entry_helper::$website_id = $args['website_id'];
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     if (!empty($_GET['user_trust_id'])) {
         self::loadExistingUserTrust($_GET['user_trust_id'], $auth, $args);
     }
     $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n";
     $r .= $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n";
     $r .= data_entry_helper::hidden_text(array('fieldname' => 'user_trust:id'));
     $r .= data_entry_helper::autocomplete(array('label' => lang::get('Recorder to trust'), 'fieldname' => 'user_trust:user_id', 'table' => 'user', 'valueField' => 'id', 'captionField' => 'person_name', 'extraParams' => $auth['read'] + array('view' => 'detail'), 'class' => 'control-width-4'));
     $col1 = '<p>Define the combination of survey, taxon group and/or location that this recorder is trusted for below.</p>';
     $col1 .= '<fieldset><legend>' . lang::get('Trust settings') . '</legend>';
     $col1 .= data_entry_helper::autocomplete(array('label' => lang::get('Trust records in this survey'), 'fieldname' => 'user_trust:survey_id', 'table' => 'survey', 'valueField' => 'id', 'captionField' => 'title', 'blankText' => '<' . lang::get('any') . '>', 'extraParams' => $auth['read'] + array('sharing' => 'verification'), 'class' => 'control-width-4'));
     $col1 .= data_entry_helper::autocomplete(array('label' => lang::get('Trust records in this taxon group'), 'fieldname' => 'user_trust:taxon_group_id', 'table' => 'taxon_group', 'valueField' => 'id', 'captionField' => 'title', 'blankText' => '<' . lang::get('any') . '>', 'extraParams' => $auth['read'], 'class' => 'control-width-4'));
     $col1 .= data_entry_helper::autocomplete(array('label' => lang::get('Trust records in this location'), 'fieldname' => 'user_trust:location_id', 'table' => 'location', 'valueField' => 'id', 'captionField' => 'name', 'blankText' => '<' . lang::get('any') . '>', 'extraParams' => $auth['read'] + array('location_type_id' => variable_get('indicia_profile_location_type_id', '')), 'class' => 'control-width-4'));
     $col2 = '<p>' . lang::get('Review this recorder\'s experience in the tabs below') . '</p>';
     $col2 .= '<div id="summary-tabs">';
     $col2 .= data_entry_helper::tab_header(array('tabs' => array('#tab-surveys' => lang::get('Surveys'), '#tab-taxon-groups' => lang::get('Taxon groups'), '#tab-locations' => lang::get('Locations'))));
     data_entry_helper::enable_tabs(array('divId' => 'summary-tabs'));
     $col2 .= '<div id="tab-surveys">';
     $col2 .= report_helper::report_grid(array('id' => 'surveys-summary', 'readAuth' => $auth['read'], 'dataSource' => 'library/surveys/filterable_surveys_verification_breakdown', 'ajax' => TRUE, 'autoloadAjax' => FALSE, 'extraParams' => array('my_records' => 1)));
     $col2 .= '</div>';
     $col2 .= '<div id="tab-taxon-groups">';
     $col2 .= report_helper::report_grid(array('id' => 'taxon-groups-summary', 'readAuth' => $auth['read'], 'dataSource' => 'library/taxon_groups/filterable_taxon_groups_verification_breakdown', 'ajax' => TRUE, 'autoloadAjax' => FALSE, 'extraParams' => array('my_records' => 1)));
     $col2 .= '</div>';
     $col2 .= '<div id="tab-locations">';
     $col2 .= report_helper::report_grid(array('id' => 'locations-summary', 'readAuth' => $auth['read'], 'dataSource' => 'library/locations/filterable_locations_verification_breakdown', 'ajax' => TRUE, 'autoloadAjax' => FALSE, 'extraParams' => array('my_records' => 1, 'location_type_id' => variable_get('indicia_profile_location_type_id', ''))));
     $col2 .= '</div>';
     $col2 .= '</div>';
     $r .= str_replace(array('{col-1}', '{col-2}'), array($col1, $col2), $indicia_templates['two-col-50']);
     $r .= '</fieldset>';
     $r .= '<input type="submit" class="indicia-button" id="save-button" value="' . (empty(data_entry_helper::$entity_to_load['user_trust_id:id']) ? lang::get('Grant trust') : lang::get('Update trust settings')) . "\" />\n";
     if (!empty($_GET['user_trust_id'])) {
         $r .= '<input type="submit" class="indicia-button" id="delete-button" name="delete-button" value="' . lang::get('Revoke this trust') . "\" />\n";
         data_entry_helper::$javascript .= "\$('#delete-button').click(function(e) {\n        if (!confirm(\"Are you sure you want to revoke this trust?\")) {\n          e.preventDefault();\n          return false;\n        }\n      });\n";
     }
     $r .= '</form>';
     data_entry_helper::enable_validation('entry_form');
     return $r;
 }
예제 #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)
 {
     $reloadPath = self::getReloadPath();
     data_entry_helper::$website_id = $args['website_id'];
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     $group = self::loadGroup($auth);
     if (!empty($_POST['invitee_emails'])) {
         self::sendInvites($args, $auth);
     }
     $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n";
     $r .= data_entry_helper::textarea(array('label' => lang::get('Send invites to'), 'helpText' => 'Enter email addresses for the people you want to invite, one per line', 'fieldname' => 'invitee_emails', 'validation' => array('required')));
     $r .= data_entry_helper::textarea(array('label' => lang::get('Invitation message'), 'helpText' => 'What message would you like to send to your invitees?', 'fieldname' => 'invite_message', 'validation' => array('required'), 'default' => 'Would you like to join the ' . $group['title'] . '?'));
     $r .= '<button type="submit" class="indicia-button" id="save-button">' . lang::get('Send Invites') . "</button>\n";
     $r .= '<button type="button" class="indicia-button" id="not-now-button" ' . 'onclick="window.location.href=\'' . url($args['redirect_on_success']) . '\'">' . lang::get('Not Now') . "</button>\n";
     $r .= '</form>';
     data_entry_helper::enable_validation('entry_form');
     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 (!hostsite_get_user_field('indicia_user_id')) {
         return 'Please ensure that you\'ve filled in your surname on your user profile before creating or editing groups.';
     }
     self::createBreadcrumb($args);
     iform_load_helpers(array('report_helper', 'map_helper'));
     $args = array_merge(array('include_code' => false, 'include_dates' => false, 'include_logo_controls' => true, 'include_sensitivity_controls' => true, 'include_report_filter' => true, 'include_linked_pages' => true, 'include_private_records' => false, 'include_administrators' => false, 'include_members' => false, 'filter_types' => '{"":"what,where,when","Advanced":"source,quality"}', 'indexed_location_type_ids' => '', 'other_location_type_ids' => '', 'data_inclusion_mode' => 'choose'), $args);
     $args['filter_types'] = json_decode($args['filter_types'], true);
     $reloadPath = self::getReloadPath();
     data_entry_helper::$website_id = $args['website_id'];
     $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
     if (!empty($_GET['group_id'])) {
         self::loadExistingGroup($_GET['group_id'], $auth, $args);
     }
     // maintain compatibility with form settings from before group type became multiselect.
     if (empty($args['group_type'])) {
         $args['group_type'] = array();
     } elseif (!is_array($args['group_type'])) {
         $args['group_type'] = array($args['group_type']);
     }
     if (count($args['group_type']) === 1) {
         $response = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $auth['read'] + array('id' => $args['group_type'][0])));
         self::$groupType = strtolower($response[0]['term']);
     }
     self::$groupType = lang::get(self::$groupType);
     $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\" enctype=\"multipart/form-data\">\n";
     $r .= '<fieldset><legend>' . lang::get('Fill in details of your {1} below', self::$groupType) . '</legend>';
     $r .= $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n";
     $r .= data_entry_helper::hidden_text(array('fieldname' => 'group:id'));
     // if a fixed choice of group type, can use a hidden input to put the value in the form.
     if (count($args['group_type']) === 1) {
         $r .= '<input type="hidden" name="group:group_type_id" value="' . $args['group_type'][0] . '"/>';
     }
     if (!empty(data_entry_helper::$entity_to_load['group:title'])) {
         hostsite_set_page_title(lang::get('Edit {1}', data_entry_helper::$entity_to_load['group:title']));
     }
     $r .= data_entry_helper::text_input(array('label' => lang::get('{1} name', ucfirst(self::$groupType)), 'fieldname' => 'group:title', 'validation' => array('required'), 'class' => 'control-width-6', 'helpText' => lang::get('Provide the full title of the {1}', self::$groupType)));
     if ($args['include_code']) {
         $r .= data_entry_helper::text_input(array('label' => lang::get('Code'), 'fieldname' => 'group:code', 'class' => 'control-width-4', 'helpText' => lang::get('Provide a code or abbreviation identifying the {1}', self::$groupType)));
     }
     $r .= data_entry_helper::textarea(array('label' => ucfirst(lang::get('{1} description', self::$groupType)), 'fieldname' => 'group:description', 'helpText' => lang::get('LANG_Description_Field_Instruct', self::$groupType), 'class' => 'control-width-6'));
     // If adding a new group which should have a parent group of some type or other, but no parent
     // group is specified in the from_group_id parameter, then let the user pick a group to link as the parent.
     if (empty($_GET['group_id']) && !empty($args['parent_group_type']) && !empty($args['parent_group_relationship_type']) && empty($_REQUEST['from_group_id'])) {
         // There should be a parent group, but none provided, so allow the user to pick one.
         $r .= data_entry_helper::select(array('label' => ucfirst(lang::get('{1} parent', self::$groupType)), 'fieldname' => 'from_group_id', 'table' => 'groups_user', 'captionField' => 'title', 'valueFields' => 'group_id', 'extraParams' => $auth['read'] + array('group_type_id' => $args['parent_group_type'], 'user_id' => hostsite_get_user_field('indicia_user_id'), 'view' => 'detail'), 'validation' => array('required'), 'blankText' => lang::get('<please select>')));
     }
     if (count($args['group_type']) !== 1) {
         $params = array('termlist_external_key' => 'indicia:group_types', 'orderby' => 'sortorder,term');
         if (!empty($args['group_type'])) {
             $params['query'] = json_encode(array('in' => array('id' => array_values($args['group_type']))));
         }
         $r .= data_entry_helper::select(array('label' => ucfirst(lang::get('{1} type', self::$groupType)), 'fieldname' => 'group:group_type_id', 'validation' => array('required'), 'table' => 'termlists_term', 'valueField' => 'id', 'captionField' => 'term', 'extraParams' => $auth['read'] + $params, 'class' => 'control-width-4', 'blankText' => lang::get('<please select>'), 'helpText' => lang::get('What sort of {1} is it?', self::$groupType)));
     }
     $r .= self::groupLogoControl($args);
     $r .= self::joinMethodsControl($args);
     if ($args['include_sensitivity_controls']) {
         $r .= data_entry_helper::checkbox(array('label' => lang::get('Show records at full precision'), 'fieldname' => 'group:view_full_precision', 'helpText' => lang::get('Any sensitive records added to the system are normally shown blurred to a lower grid reference precision. If this box ' . 'is checked, then group members can see sensitive records explicitly posted for the {1} at full precision.', self::$groupType)));
     }
     $r .= self::dateControls($args);
     if ($args['include_private_records']) {
         $r .= data_entry_helper::checkbox(array('label' => lang::get('Records are private'), 'fieldname' => 'group:private_records', 'helpText' => lang::get('Tick this box if you want to withold the release of the records from this {1} until a ' . 'later point in time, e.g. when a project is completed.', self::$groupType)));
         // If an existing group with private records, then we might need to display a message warning the user about releasing the records.
         // Initially hidden, we use JS to display it when appropriate.
         if (!empty(data_entry_helper::$entity_to_load['group:id']) && data_entry_helper::$entity_to_load['group:private_records'] === 't') {
             $r .= '<p class="warning" style="display: none" id="release-warning">' . lang::get('You are about to release the records belonging to this group. Do not proceed unless you intend to do this!') . '</p>';
         }
     }
     $r .= self::memberControls($args, $auth);
     $r .= '</fieldset>';
     $r .= self::reportFilterBlock($args, $auth, $hiddenPopupDivs);
     $r .= self::inclusionMethodControl($args);
     $r .= self::formsBlock($args, $auth, $node);
     // auto-insert the creator as an admin of the new group, unless the admins are manually specified
     if (!$args['include_administrators'] && empty($_GET['group_id'])) {
         $r .= '<input type="hidden" name="groups_user:admin_user_id[]" value="' . hostsite_get_user_field('indicia_user_id') . '"/>';
     }
     $r .= '<input type="hidden" name="groups_user:administrator" value="t"/>';
     $r .= '<input type="submit" class="indicia-button" id="save-button" value="' . (empty(data_entry_helper::$entity_to_load['group:id']) ? lang::get('Create {1}', self::$groupType) : lang::get('Update {1} settings', self::$groupType)) . "\" />\n";
     $r .= '</form>';
     $r .= $hiddenPopupDivs;
     data_entry_helper::enable_validation('entry_form');
     // JavaScript to grab the filter definition and store in the form for posting when the form is submitted
     data_entry_helper::$javascript .= "\r\n\$('#entry_form').submit(function() {\r\n  \$('#filter-title-val').val('" . lang::get('Filter for user group') . " ' + \$('#group\\\\:title').val() + ' ' + new Date().getTime());\r\n  \$('#filter-def-val').val(JSON.stringify(indiciaData.filter.def));\r\n});\n";
     // for existing groups, prevent removal of yourself as a member. Someone else will have to do this for you so we don't orphan groups.
     if (!empty(data_entry_helper::$entity_to_load['group:id'])) {
         data_entry_helper::$javascript .= "\$('#groups_user\\\\:admin_user_id\\\\:sublist input[value=" . hostsite_get_user_field('indicia_user_id') . "]').closest('li').children('span').remove();\n";
     }
     return $r;
 }
예제 #6
0
 /**
  * Retrieves read and write nonce tokens from the warehouse.
  * @param string $website_id Indicia ID for the website.
  * @param string $password Indicia password for the website.
  * @return Returns an array containing:
  * 'read' => the read authorisation array,
  * 'write' => the write authorisation input controls to insert into your form.
  * 'writeTokens' => the write authorisation array, if needed as separate tokens rather than just placing in form.
  */
 public static function get_read_write_auth($website_id, $password)
 {
     self::$website_id = $website_id;
     /* Store this for use with data caching */
     $postargs = "website_id={$website_id}";
     $response = self::http_post(parent::$base_url . 'index.php/services/security/get_read_write_nonces', $postargs);
     $nonces = json_decode($response['output'], true);
     $write = '<input id="auth_token" name="auth_token" type="hidden" class="hidden" ' . 'value="' . sha1($nonces['write'] . ':' . $password) . '" />' . "\r\n";
     $write .= '<input id="nonce" name="nonce" type="hidden" class="hidden" ' . 'value="' . $nonces['write'] . '" />' . "\r\n";
     return array('write' => $write, 'read' => array('auth_token' => sha1($nonces['read'] . ':' . $password), 'nonce' => $nonces['read']), 'write_tokens' => array('auth_token' => sha1($nonces['write'] . ':' . $password), 'nonce' => $nonces['write']));
 }
 /**
  * Return the generated form output.
  * @param array $args The form settings.
  * @param array $node
  * @return string Form HTML.
  */
 public static function get_form($args, $node)
 {
     iform_load_helpers(array('mobile_entry_helper'));
     data_entry_helper::$website_id = $args['website_id'];
     self::$node = $node;
     self::$called_class = 'iform_' . $node->iform;
     // Convert parameter, $args['defaults'], into structured array.
     self::parse_defaults($args);
     // Check permissions to access form.
     $func = get_user_func(self::$called_class, 'enforcePermissions');
     if ($func) {
         if (call_user_func($func) && !user_access('IForm n' . $node->nid . ' admin') && !user_access('IForm n' . $node->nid . ' user')) {
             return lang::get('LANG_no_permissions');
         }
     }
     // Else add authorisation tokens to update and read from the Warehouse. We allow
     // child classes to generate this first if subclassed.
     if (self::$auth) {
         $auth = self::$auth;
     } else {
         $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
         self::$auth = $auth;
     }
     // Load custom attribute definitions from warehouse.
     self::loadSmpAttrs($auth['read'], $args['survey_id']);
     self::loadOccAttrs($auth['read'], $args['survey_id']);
     // Build a structured array describing the form.
     // Attribute definitions on the warehouse may specify some tabs.
     $attrForm = get_attribute_tabs(self::$smpAttrs);
     // They are combined with those in the Form Structure.
     $form = self::structureForm($args['structure'], $attrForm);
     // A second pass organises the content within the tabs
     $structure = self::structureFormContent($form);
     // Render the form
     $renderedForm = self::renderForm($structure, $args, $auth);
     $options = array();
     //build options for form template
     $options['content'] = $renderedForm;
     //use mobile authentication
     if ($args['mobileauth'] == 1) {
         if (!empty($args['mobileauthpath'])) {
             $options['action'] = $args['mobileauthpath'];
         } else {
             $options['action'] = 'mobile/submit';
         }
     } else {
         //no mobile authentication
         $options['action'] = "";
         //use default action
     }
     $options['id'] = 'entry_form';
     $options['method'] = 'post';
     //output form
     return mobile_entry_helper::apply_template('form', $options);
 }
예제 #8
0
 /**
  * Retrieves a read token and passes it back as an array suitable to drop into the
  * 'extraParams' options for an Ajax call.
  *
  * @param string $website_id Indicia ID for the website.
  * @param string $password Indicia password for the website.
  */
 public static function get_read_auth($website_id, $password)
 {
     self::$website_id = $website_id;
     /* Store this for use with data caching */
     $postargs = "website_id={$website_id}";
     $response = self::http_post(parent::$base_url . 'index.php/services/security/get_read_nonce', $postargs);
     $nonce = $response['output'];
     return array('auth_token' => sha1("{$nonce}:{$password}"), 'nonce' => $nonce);
 }