public static function get_form($args, $node)
 {
     if (!empty($_GET['sample_id'])) {
         //Disable the existing records grid so the user can only delete items from here
         data_entry_helper::$javascript .= "\$('#Epiphytes-free').find('input[type=checkbox]').attr('disabled','disabled');\n";
         //Need to stop user clicking on checkboxes as they are deliberately re-enabled on submit because disabled checkboxes don't submit to post. On validation error they enable
         //but user is left on the page, so stop them clicking on checkboxes by other means. This is a bit of a workaround.
         data_entry_helper::$javascript .= "\$('#Epiphytes-free').find('input[type=checkbox]').click(false);\n";
         //Just before the post is processed, we re-enable the grid, so the values are exposed in the submission else they won't be processed
         data_entry_helper::$javascript .= "\$('#entry_form').submit(function() { \$('#Epiphytes-free').find('input[type=checkbox]').removeAttr('disabled');});\n";
     }
     return parent::get_form($args, $node);
 }
 /**
  * 
  * @param type $args The args for the page including the options selected on the edit tab.
  * @param type $node The node
  * @return type The parent get_form method html
  */
 public static function get_form($args, $node)
 {
     $pageMode = self::getMode($args, $node);
     global $user;
     //Always override any role a user has with a larger role if they have that role.
     $roleType = 'guest';
     if (in_array('volunteer', $user->roles)) {
         $roleType = 'volunteer';
     }
     if (in_array('staff', $user->roles)) {
         $roleType = 'staff';
     }
     if (in_array('data manager', $user->roles)) {
         $roleType = 'data manager';
     }
     //Get the data such as phone number associated with the user
     $user_fields = user_load($user->uid);
     $userPhoneNum = null;
     $userEmail = null;
     $userName = null;
     if (!empty($user_fields->field_main_phone_number['und']['0']['value'])) {
         $userPhoneNum = $user_fields->field_main_phone_number['und']['0']['value'];
     }
     if (!empty($user->mail)) {
         $userEmail = $user->mail;
     } else {
         //we need to pass javascript an empty string rather than null variable
         $userEmail = '';
     }
     if (!empty($user->name)) {
         $userName = "******";
     } else {
         //we need to pass javascript an empty string rather than null variable
         $userName = "******";
     }
     $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']);
     //Need to collect the user's name from the people table
     $defaultUserData = data_entry_helper::get_report_data(array('dataSource' => 'library/users/get_people_details_for_website_or_user', 'readAuth' => $readAuth, 'extraParams' => array('user_id' => hostsite_get_user_field('indicia_user_id'), 'website_id' => $args['website_id'])));
     //Pass the javascript the sample id if in edit mode.
     if (!empty($_GET['sample_id'])) {
         data_entry_helper::$javascript .= "indiciaData.sample_id = " . $_GET['sample_id'] . ";\n";
     }
     //Allow the user to match up the attributes on the edit tab so we don't hard code attribute ids
     //Pass these into javascript
     data_entry_helper::$javascript .= "\r\n    indiciaData.person_name = '" . $defaultUserData[0]['fullname_surname_first'] . "';     \r\n    indiciaData.observer_name_attr_id = " . $args['observer_name'] . ";\r\n    indiciaData.observer_email_attr_id = " . $args['observer_email'] . ";\r\n    indiciaData.observer_phone_number_attr_id = " . $args['observer_phone_number'] . ";\r\n    \r\n    indiciaData.start_time_attr_id = " . $args['start_time'] . ";\r\n    indiciaData.end_time_attr_id = " . $args['end_time'] . ";  \r\n      \r\n    indiciaData.sea_state_attr_id = " . $args['sea_state'] . ";  \r\n    indiciaData.visibility_attr_id = " . $args['visibility'] . ";  \r\n    indiciaData.cetaceans_seen_attr_id = " . $args['cetaceans_seen'] . ";\r\n    indiciaData.non_cetacean_marine_animals_seen_attr_id = " . $args['non_cetacean_marine_animals_seen'] . ";\r\n    indiciaData.feeding_birds_seen_attr_id = " . $args['feeding_birds_seen'] . ";\r\n    indiciaData.number_of_people_spoken_to_during_watch_attr_id = " . $args['number_of_people_spoken_to_during_watch'] . ";\r\n\r\n    indiciaData.wdcs_newsletter_attr_id = " . $args['wdcs_newsletter'] . ";\r\n    indiciaData.bearing_to_sighting_attr_id = " . $args['bearing_to_sighting'] . ";\r\n    indiciaData.reticules_attr_id = " . $args['reticules'] . ";\r\n    indiciaData.reticules_from_attr_id = " . $args['reticules_from'] . ";\r\n    indiciaData.distance_estimate_attr_id = " . $args['distance_estimate'] . "; \r\n    indiciaData.adults_attr_id = " . $args['adults'] . ";\r\n    indiciaData.calves_attr_id = " . $args['calves'] . "; \r\n    indiciaData.activity_attr_id = " . $args['activity'] . ";\r\n    indiciaData.behaviour_attr_id = " . $args['behaviour'] . ";\r\n    \r\n    indiciaData.user_phone_number = \"{$userPhoneNum}\"; \r\n    indiciaData.user_email = \"{$userEmail}\";   \r\n    indiciaData.username = \"{$userName}\";\r\n    indiciaData.roleType = \"{$roleType}\"; \r\n    indiciaData.adhocMode = \"" . $args['adhocMode'] . "\";\r\n    indiciaData.tenMinMessage = \"" . lang::get('SW efforts should always be 10 mins. If you saw a sightings that started after the 10 mins then please use the ad-hoc form') . "\";\r\n    indiciaData.emailPhoneMessage = \"" . lang::get('Please supply a phone number or email address') . "\";  \r\n    indiciaData.addSpeciesMessage = \"" . lang::get('Please add a species') . "\";";
     //We need to put root folder into indiciadata so the addrowtogrid.js code knows the details of the server
     //we are running without hard coding it
     //The user needs to specify which page to go to when the user clicks on the notes icon on the species grid
     //The indiciaData.notesIcon is used by the addrowtogrid.js code so that the code for notes on the species grid is not run by old code.
     data_entry_helper::$javascript .= "\r\n    indiciaData.rootFolder = '" . data_entry_helper::getRootFolder() . "';    \r\n    ";
     $r = '';
     //We need a div so we can can put the form into read only mode when required.
     $r = '<div id = "disableDiv">';
     $r .= parent::get_form($args, $node);
     $r .= '</div>';
     //Get a list of sightings, this is used to determine if there are any that are verified or if there are no sightings at all.
     //If we find this is the case then we set the form into read only mode.
     if (!empty($_GET['sample_id'])) {
         $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']);
         $sightingsData = data_entry_helper::get_report_data(array('dataSource' => 'reports_for_prebuilt_forms/Shorewatch/get_sightings_for_sample', 'readAuth' => $readAuth, 'extraParams' => array('sample_id' => $_GET['sample_id'])));
     }
     $verifiedDataDetected = false;
     //Check for sample id as we don't do this in add mode.
     if (!empty($_GET['sample_id']) && empty($sightingsData)) {
         $r = '<div><i>This page is locked as it does not having any sightings.</i></div>' . $r;
         data_entry_helper::$javascript .= "\$('[id*=_lock]').remove();\n";
         data_entry_helper::$javascript .= "\$('#disableDiv').find('input, textarea, text, button, select').attr('disabled','disabled');\n";
         data_entry_helper::$javascript .= "\$('.species-grid, .page-notice, .indicia-button').hide();\n";
         //If the page is locked then we don't run the logic on the Save/Next Step button
         //as this logic enables the button when we don't want it enabled.
         data_entry_helper::$javascript .= "indiciaData.dontRunCetaceanSaveButtonLogic=true;";
     }
     if (!empty($sightingsData)) {
         //If any verified sightings are found then put page into read-only mode.
         foreach ($sightingsData as $sightingData) {
             if ($verifiedDataDetected === false) {
                 if ($sightingData['verification_status'] === 'D' || $sightingData['verification_status'] === 'V' || $sightingData['verification_status'] === 'R') {
                     $r = '<div><i>This page is locked as it has at least 1 verified sighting.</i></div>' . $r;
                     data_entry_helper::$javascript .= "\$('[id*=_lock]').remove();\n \$('.remove-row').remove();\n";
                     data_entry_helper::$javascript .= "\$('.scImageLink,.scClonableRow').hide();\n";
                     data_entry_helper::$javascript .= "\$('.edit-taxon-name,.remove-row').hide();\n";
                     data_entry_helper::$javascript .= "\$('#disableDiv').find('input, textarea, text, button, select').attr('disabled','disabled');\n";
                     //If the page is locked then we don't run the logic on the Save/Next Step button
                     //as this logic enables the button when we don't want it enabled.
                     data_entry_helper::$javascript .= "indiciaData.dontRunCetaceanSaveButtonLogic=true;";
                     $verifiedDataDetected = true;
                 }
             }
         }
     }
     return $r;
 }
 public static function get_form($args, $node)
 {
     //Don't use a submit button, as we are saving after each stage of the wizard, so just save on every Next button click. Use additional wizard page at the end as a
     //finish confirmation page, this doesn't need submitting.
     data_entry_helper::$javascript .= "\$('#tab-submit').hide();\n";
     data_entry_helper::$javascript .= 'indiciaData.nid = "' . $node->nid . "\";\n";
     //Use ajax saving so that we can save without full page reload on a lot of pages.
     data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/dynamic_progressive_seasearch_survey') . "\";\n";
     $paramsSeparator = variable_get('clean_url', 0) ? '?' : '&';
     data_entry_helper::$javascript .= "indiciaData.paramsSeparator='" . $paramsSeparator . "';\n";
     if (empty($args['in_progress_sample_attr_id'])) {
         drupal_set_message('Please fill in the edit tab option for the In-Progress Sample attribute id');
         return false;
     }
     if (empty($args['gpx_data_attr_id'])) {
         drupal_set_message('Please fill in the edit tab option for the GPX Data attribute id');
         return false;
     }
     if (empty($args['habitat_smpAttr_cluster_ids'])) {
         drupal_set_message('Please fill in the option for the Habitat Sample Attribute Cluster');
         return false;
     }
     if (empty($args['dive_duration_attr_id'])) {
         drupal_set_message('Please fill in the option for the Dive Duration attribute id');
         return false;
     }
     if (empty($args['dive_start_time_attr_id'])) {
         drupal_set_message('Please fill in the option for the Dive Start Time attribute id');
         return false;
     }
     if (empty($args['exif_date_time_attr_id'])) {
         drupal_set_message('Please fill in the option for the Exif Date Times attribute id');
         return false;
     }
     //Hidden and displayed using jQuery
     $r = '<div id="loading">
 <br>
 <br>
 <br>
 <h3>Preparing page...</h3>
 <br>
 <br>
 <br>
 </div>';
     //Hide the attribute that holds whether a sample is in progress or not
     //Also need to hide the label associated with the attribute.
     data_entry_helper::$javascript .= "\n    \$('#smpAttr\\\\:" . $args['in_progress_sample_attr_id'] . "').hide();\n\n    \$('[for=smpAttr\\\\:" . $args['in_progress_sample_attr_id'] . "]').hide();";
     //Same with attribute that holds GPX data
     data_entry_helper::$javascript .= "\n    \$('#smpAttr\\\\:" . $args['gpx_data_attr_id'] . "').hide();\n\n    \$('[for=smpAttr\\\\:" . $args['gpx_data_attr_id'] . "]').hide();";
     //etc
     data_entry_helper::$javascript .= "\n    \$('#smpAttr\\\\:" . $args['exif_date_time_attr_id'] . "').hide();\n\n    \$('[for=smpAttr\\\\:" . $args['exif_date_time_attr_id'] . "]').hide();";
     //Clean up the occurrences tab, remove unused images column on the bottom grid
     //Also remove the name of the Add photos column on main grid as the column is empty is edit mode, and obvious what it is in add mode.
     data_entry_helper::$javascript .= "\n    \$('#first-level-smp-occ-grid-images-0').remove();\n\n    \$('#third-level-smp-occ-grid-images-0').text('');";
     // A jquery selector for the element which must be at the top of the page when moving to the next page. Could be the progress bar or the
     // tabbed div itself.
     if (isset($options['progressBar']) && $options['progressBar'] == true) {
         data_entry_helper::$javascript .= "indiciaData.topSelector=" . "'.wiz-prog'" . ";";
     } else {
         data_entry_helper::$javascript .= "indiciaData.topSelector=" . "'#controls'" . ";";
     }
     $options['progressBar'] = true;
     //Safer to still initialise $getSampleId if there is no sample_id in the $_GET, avoid an error
     if (!empty($_GET['sample_id'])) {
         $getSampleId = $_GET['sample_id'];
     } else {
         $getSampleId = '';
     }
     //When reloading a tab, then we need to move to the next tab
     if (!empty($_GET['load_tab'])) {
         data_entry_helper::$javascript .= "indiciaData.tabToReloadTo=" . $_GET['load_tab'] . ";";
     } else {
         data_entry_helper::$javascript .= "indiciaData.tabToReloadTo=0;";
     }
     //Need a jquery selector when referencing the in-progress sample attribute.
     data_entry_helper::$javascript .= "indiciaData.inProgressAttrSelector='#smpAttr\\\\:" . $args['in_progress_sample_attr_id'] . "';";
     //Need the number of the occurrences tab, so we can hide the Add Photos button in the species grid.
     data_entry_helper::$javascript .= "\n    indiciaData.reloadtabs=[0,4,5,6];\n    indiciaData.occTabIdx=6;\n";
     if (!empty($args['gps_sync_warning'])) {
         data_entry_helper::$javascript .= "indiciaData.gpsSyncWarning=\"" . $args['gps_sync_warning'] . "\";";
     }
     //If option is supplied, warn the user that the GPS device and camera need to be synchronised before they upload GPX file.
     //Also when the screen loads, if there is a "In Progress" attribute (which there should be) and it is not set explicitely as not
     //In Progress, then it must be in progress, so set the attribute to 1.
     data_entry_helper::$javascript .= "\n    \$(window).load(function () {\n      if (indiciaData.gpsSyncWarning) {\n        \$('#file_upload').click(function() {\n            var r = confirm(indiciaData.gpsSyncWarning);\n            if (r != true) {\n              return false;\n            }\n        });\n      }\n      if (\$(indiciaData.inProgressAttrSelector).length && \$(indiciaData.inProgressAttrSelector).val()!=='0') {\n        \$(indiciaData.inProgressAttrSelector).val(1);\n      }\n      indiciaData.getSampleId = '{$getSampleId}';";
     if (!empty($args['no_photos_with_date_warning'])) {
         self::no_photos_with_date_warning($args);
     }
     if (!empty($args['dive_start_outside_one_hour_warning'])) {
         self::dive_start_outside_one_hour_warning($args);
     }
     data_entry_helper::$javascript .= "    \n    });";
     drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.form.js', 'module');
     data_entry_helper::add_resource('jquery_form');
     return $r . parent::get_form($args, $node);
 }
 public static function get_form($args, $node, $response = null)
 {
     if (is_array($response)) {
         // we have got here via a post that has not been redirected.
         data_entry_helper::$javascript .= "\njQuery('div.field-name-body').remove();\n";
         return '<p>' . lang::get('Your phenology observation has been saved.') . '<p>' . '<p>' . lang::get('The creation of this observation was instigated after adding or modifying a tree, which was done in another tab or window - you may now close this browser tab, should you wish.') . '</p>' . '<a href="JavaScript:window.close()"><input type="button" class="indicia-button" name="close" value="' . lang::get('Close Tab') . '" /></a>';
     }
     return parent::get_form($args, $node, $response);
 }