예제 #1
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;
     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.');
     }
     $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID');
     if (!$userIdAttr) {
         return lang::get('This form must be used with a survey that has the CMS User ID sample attribute associated with it.');
     }
     $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username');
     if (!$userNameAttr) {
         return lang::get('This form must be used with a survey that has the CMS Username sample attribute associated with it.');
     }
     $observerAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Observer');
     if (!$observerAttr) {
         return lang::get('This form must be used with a survey that has the Observer sample attribute associated with it.');
     }
     if (isset($args['grid_report'])) {
         $reportName = $args['grid_report'];
     } else {
         // provide a default in case the form settings were saved in an old version of the form
         $reportName = 'reports_for_prebuilt_forms/MNHNL/mnhnl_butterflies';
     }
     $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble'));
     $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 10, 'autoParamsForm' => true, 'extraParams' => array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => iform_loctools_checkaccess($node, 'superuser') ? -1 : $user->uid, 'userName_attr_id' => $userNameAttr, 'userName' => $user->name, 'observer_attr_id' => $observerAttr)));
     $r .= '<form>';
     $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">';
     $r .= '</form>';
     return $r;
 }
    /**
     * 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;
        // get the CMS User ID attribute so we can filter the grid to this user
        $userIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS User ID');
        if (!$userIdAttr) {
            return lang::get('This form must be used with a survey that has the CMS User ID attribute associated with it so records can be tagged against their creator.');
        }
        $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username');
        if (!$userNameAttr) {
            return lang::get('This form must be used with a survey that has the CMS User Name attribute associated with it so records can be tagged against their creator.');
        }
        $targetSpeciesIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', $args['targetSpeciesAttr']);
        if (!$targetSpeciesIdAttr) {
            return lang::get('This form must be used with a survey that has the ' . $args['targetSpeciesAttr'] . ' attribute associated with it.');
        }
        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.');
        }
        if (isset($args['grid_report'])) {
            $reportName = $args['grid_report'];
        } else {
            // provide a default in case the form settings were saved in an old version of the form
            $reportName = 'reports_for_prebuilt_forms/MNHNL/mnhnl_reptiles';
        }
        $extraParams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => iform_loctools_checkaccess($node, 'superuser') ? -1 : $user->uid, 'userName_attr_id' => $userNameAttr, 'userName' => $user->name, 'target_species_attr_id' => $targetSpeciesIdAttr);
        if (isset($args['filterAttrs']) && $args['filterAttrs'] != '') {
            global $custom_terms;
            $filterAttrs = explode(',', $args['filterAttrs']);
            $idxN = 1;
            foreach ($filterAttrs as $idx => $filterAttr) {
                $filterAttr = explode(':', $filterAttr);
                switch ($filterAttr[0]) {
                    case 'Display':
                        break;
                    case 'Parent':
                        $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[1]);
                        $custom_terms['attr_' . $idxN] = lang::get($filterAttr[1]);
                        $idxN++;
                        break;
                    default:
                        $extraParams['attr_id_' . $idxN] = iform_mnhnl_getAttrID($auth, $args, 'location', $filterAttr[0]);
                        $custom_terms['attr_' . $idxN] = lang::get($filterAttr[0]);
                        $idxN++;
                        break;
                }
            }
        }
        $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble'));
        $r .= data_entry_helper::report_grid(array('id' => 'samples-grid', 'dataSource' => $reportName, 'mode' => 'report', 'readAuth' => $auth['read'], 'columns' => call_user_func(array(get_called_class(), 'getReportActions')), 'itemsPerPage' => isset($args['grid_num_rows']) ? $args['grid_num_rows'] : 25, 'autoParamsForm' => true, 'extraParams' => $extraParams));
        $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' => 'new')) . '\'">';
            $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample_Grid') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new&gridmode')) . '\'">';
        } else {
            $r .= '<input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'">';
        }
        $r .= '</form>
<div style="display:none" />
  <form id="form-delete-survey" action="' . iform_mnhnl_getReloadPath() . '" method="POST">' . $auth['write'] . '
    <input type="hidden" name="website_id" value="' . $args['website_id'] . '" />
    <input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" />
    <input type="hidden" name="sample:id" value="" />
    <input type="hidden" name="sample:deleted" value="t" />
  </form>
</div>
<div style="display:none" />
  <form id="form-delete-survey-location" action="' . iform_mnhnl_getReloadPath() . '" method="POST">' . $auth['write'] . '
     <input type="hidden" name="website_id" value="' . $args['website_id'] . '" />
     <input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" />
     <input type="hidden" name="sample:id" value="" />
     <input type="hidden" name="sample:deleted" value="t" />
     <input type="hidden" name="location:id" value="" />
     <input type="hidden" name="location:deleted" value="t" />
  </form>
</div>';
        data_entry_helper::$javascript .= "\r\ndeleteSurvey = function(sampleID){\r\n  jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\r\n          \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\r\n          \"&callback=?\", function(data) {\r\n      if (data.length>0) {\r\n        jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\r\n        jQuery('#form-delete-survey-location').find('[name=sample\\:id]').val(data[0].id);\r\n        jQuery('#form-delete-survey-location').find('[name=location\\:id]').val(data[0].location_id);\r\n        // next get the location ID from sample, count the samples that are attached to that location\r\n        jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample?location_id=\"+data[0].location_id +\r\n                \"&parent_id=NULL&mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\r\n                \"&callback=?\", function(sdata) {\r\n            if (sdata.length==1) {\r\n              var dialog = \$('<p>" . lang::get('The site only has this survey associated with it. Do you wish to delete the site as well?') . "</p>').\r\n                  dialog({ title: 'Delete Location Data?',\r\n                    width: 400,\r\n                    buttons: {\r\n                      'Cancel': function() { dialog.dialog('close'); },\r\n                      'Survey Only': function() {\r\n                          dialog.dialog('close');\r\n                          jQuery('#form-delete-survey').submit();\r\n                        },\r\n                      'Site and Survey':  function() {\r\n                          dialog.dialog('close');\r\n                          jQuery('#form-delete-survey-location').submit();\r\n                        }}});\r\n            } else if (sdata.length > 1) {\r\n              if(confirm(\"" . lang::get('Are you sure you wish to delete survey ') . "\"+sampleID)){\r\n                jQuery('#form-delete-survey').submit();\r\n              }\r\n            }\r\n        });\r\n      }\r\n  });\r\n};\n";
        return $r;
    }
예제 #3
0
function iform_mnhnl_locationattributes($auth, $args, $tabalias, $options)
{
    $creatorAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Creator');
    if ($creatorAttr) {
        data_entry_helper::$javascript .= "\njQuery('[name=locAttr:" . $creatorAttr . "],[name^=locAttr:" . $creatorAttr . ":]').removeClass('wide').attr('readonly','readonly');";
    }
    $attrArgs = array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
    //    if($options['read_only']===true) $attrArgs['read_only']='read_only';
    $tabName = isset($options['tabNameFilter']) && isset($options['tabNameFilter']) != '' ? $options['tabNameFilter'] : '';
    if (array_key_exists('location:id', data_entry_helper::$entity_to_load) && data_entry_helper::$entity_to_load['location:id'] != "") {
        // if we have location Id to load, use it to get attribute values
        $attrArgs['id'] = data_entry_helper::$entity_to_load['location:id'];
    }
    $locationAttributes = data_entry_helper::getAttributes($attrArgs, false);
    $defAttrOptions = array_merge(array('extraParams' => array_merge($auth['read'], array('view' => 'detail')), 'language' => iform_lang_iso_639_2($args['language'])), $options);
    $r = '';
    foreach ($locationAttributes as $attribute) {
        if ($tabName == '' && $attribute['inner_structure_block'] != "Filter" || strcasecmp($tabName, $attribute['inner_structure_block']) == 0) {
            $opt = $defAttrOptions + get_attr_validation($attribute, $args);
            $r .= data_entry_helper::outputAttribute($attribute, $opt);
        }
    }
    return $r;
}
예제 #4
0
 /**
  * Get the custom species control.
  */
 protected static function get_control_species($auth, $args, $tabalias, $options)
 {
     $surveyMethodIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Bats2SurveyMethod');
     if (!$surveyMethodIdAttr) {
         return 'get_control_species : This Species control must be used with a survey that has the Bats2SurveyMethod attribute associated with it.';
     }
     $list = data_entry_helper::get_population_data(array('table' => 'termlist', 'extraParams' => $auth['read'] + array('external_key' => $options['surveyMethodTermList'])));
     if (count($list) == 0) {
         return "get_control_species : Termlist " . $options['surveyMethodTermList'] . " not available on the Warehouse";
     }
     if (count($list) > 1) {
         return "get_control_species : Multiple termlists identified by " . $options['surveyMethodTermList'] . " found on the Warehouse";
     }
     $termlist = $list[0]['id'];
     $extraParams = $auth['read'] + array('termlist_id' => $termlist, 'view' => 'detail');
     $surveyMethods = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $extraParams));
     data_entry_helper::$javascript .= "\nhook_species_checklist_pre_delete_row=function(e) {\n    return confirm(\"" . lang::get('Are you sure you want to delete this row?') . "\");\n};\n";
     $extraParams = $auth['read'];
     if ($args['species_names_filter'] == 'preferred') {
         $extraParams += array('preferred' => 't');
     }
     if ($args['species_names_filter'] == 'language') {
         $extraParams += array('language' => iform_lang_iso_639_2($user->lang));
     }
     // multiple species being input via a grid
     $species_ctrl_opts = array_merge(array("extra_list_id" => $args["extra_list_id"], 'listId' => $args['list_id'], 'label' => lang::get('occurrence:taxa_taxon_list_id'), 'columns' => 1, 'readAuth' => $auth['read'], 'extraParams' => $extraParams, 'survey_id' => $args['survey_id'], 'PHPtaxonLabel' => true, 'language' => iform_lang_iso_639_2($user->lang), 'max_species_ids' => $args['max_species_ids'], 'surveyMethodAttrId' => $surveyMethodIdAttr, 'surveyMethods' => $surveyMethods), $options);
     if ($args['extra_list_id']) {
         $species_ctrl_opts['lookupListId'] = $args['extra_list_id'];
     }
     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, array());
     // 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 self::mnhnl_bats2_species_checklist($args, $species_ctrl_opts);
 }
    protected static function get_control_speciesgrid($auth, $args, $tabalias, $options)
    {
        /* We will make the assumption that only one of these will be put onto a form.
         * A lot of this is copied from the species control and has the same features. */
        $countAttr = iform_mnhnl_getAttrID($auth, $args, 'occurrence', 'Count');
        if (!$countAttr) {
            return lang::get('This form must be used with a survey that has the Count Occurrence attribute associated with it.');
        }
        $subsamples = self::getLocationsInGrid($auth, $args);
        $ret = '<p>' . lang::get("LANG_SpeciesGridInstructions") . '</p><table id="sgCloneableTable" style="display:none">';
        $cloneprefix = 'SG:--sgrownum--:--cgrownum--:--sampleid--:--ttlid--:--occid--:';
        $ret .= "<tr class=\"sgCloneableRow\">\n<td class=\"ui-state-default remove-sgnewrow\" >X</td><td class=\"sggrid-namecell\"></td>";
        // ordering is the order they are initially created.
        // need to get a sorted list of occurrence IDs; then generate a list of ttls in order set by occurrences.
        $fullOccList = array();
        if (isset($subsamples)) {
            foreach ($subsamples as $key => $entity) {
                // have to disabled averything in the cloneable grid due to validation issues.
                $ret .= str_replace(array('--cgrownum--', '--sampleid--'), array($key + 1, $entity['sample_id']), '<td class="smp---cgrownum--" ' . (isset($entity['date']) ? '' : 'style="opacity: 0.25"') . ' disabled="disabled"><input class="digits narrow ' . (isset($entity['date']) ? '' : 'disabled') . '" name="' . $cloneprefix . 'occAttr:' . $countAttr . '" disabled="disabled" min="1" ></td>');
                if (isset($entity['sample_id'])) {
                    $url = data_entry_helper::$base_url . "/index.php/services/data/occurrence?sample_id=" . $entity['sample_id'] . "&mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"];
                    $session = curl_init($url);
                    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
                    $occs = json_decode(curl_exec($session), true);
                    $occList = array();
                    $subsampleOccs = array();
                    foreach ($occs as $an_occ) {
                        $occList[] = $an_occ['id'];
                        $fullOccList[intval($an_occ['id'])] = $an_occ['taxa_taxon_list_id'];
                        $subsampleOccs[$an_occ['taxa_taxon_list_id']] = $an_occ;
                        // this indexes the occurrences for the subsample by taxa_taxon_list_id
                    }
                    $subsamples[$key]['occurrences'] = $subsampleOccs;
                    $url = data_entry_helper::$base_url . "/index.php/services/data/occurrence_attribute_value?query=" . json_encode(array('in' => array('occurrence_id', $occList))) . "&mode=json&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"];
                    $session = curl_init($url);
                    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
                    $occAttributes = json_decode(curl_exec($session), true);
                    $subsampleOccAttrs = array();
                    foreach ($occAttributes as $an_occAttr) {
                        if ($an_occAttr['occurrence_attribute_id'] == $countAttr) {
                            $subsampleOccAttrs[$an_occAttr['occurrence_id']] = $an_occAttr;
                        }
                    }
                    $subsamples[$key]['occattrs'] = $subsampleOccAttrs;
                } else {
                    $subsamples[$key]['occurrences'] = array();
                }
            }
        }
        $ret .= '</table>';
        /* We will make the assumption that only one of these will be put onto a form.
         * A lot of this is copied from the species control and has the same features. */
        $extraParams = $auth['read'] + array('view' => 'detail', 'reset_timeout' => 'true');
        // no name filtering
        // 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'] = $args['extra_list_id'];
        } else {
            $extraParams['taxon_list_id'] = array($args['list_id'], $args['extra_list_id']);
        }
        $species_list_args = array_merge(array('label' => lang::get('speciesgrid:taxa_taxon_list_id'), 'fieldname' => 'speciesgrid_taxa_taxon_list_id', 'id' => 'speciesgrid_taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'parentField' => 'parent_id', 'extraParams' => $extraParams, 'numValues' => $args['max_species_ids']), $options);
        // do not allow tree browser
        if ($args['species_ctrl'] == 'tree_browser') {
            return '<p>Can not use tree browser in this context</p>';
        }
        $ret .= '<div>' . call_user_func(array('data_entry_helper', $args['species_ctrl']), $species_list_args) . '</div>';
        $ret .= '<table id="mnhnl-species-grid-head"><thead id="mnhnl-species-grid-head-head"><tr></tr></thead></table><div id="mnhnl-species-grid-container"><table id="mnhnl-species-grid"><thead><tr id="mnhnl-species-grid-header"><th></th><th>' . lang::get('Species') . '</th>';
        if (isset($subsamples)) {
            foreach ($subsamples as $key => $entity) {
                $ret .= '<th class="smp-' . ($key + 1) . '" ' . (isset($entity['date']) ? '' : 'style="opacity: 0.25"') . '>' . $entity['name'] . '</th>';
            }
        }
        $ret .= '</tr></thead><tbody>';
        $taxonRow = 0;
        ksort($fullOccList);
        $taxonList = array();
        foreach ($fullOccList as $occ => $ttlid) {
            if (!in_array($ttlid, $taxonList)) {
                $taxonList[] = $ttlid;
            }
            // we want the unique entries but keeping order of initial appearance in array
        }
        foreach ($taxonList as $ttlid) {
            $url = data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list?id=" . $ttlid . "&mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"];
            $session = curl_init($url);
            curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
            $taxon = json_decode(curl_exec($session), true);
            $url = data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list?taxon_meaning_id=" . $taxon[0]['taxon_meaning_id'] . "&mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"];
            $session = curl_init($url);
            curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
            $allnames = json_decode(curl_exec($session), true);
            $name = '';
            foreach ($allnames as $aname) {
                if ($aname['preferred'] == 't') {
                    $name = '<em>' . $aname['taxon'] . '</em>' . ($name != '' ? ', ' : '') . $name;
                } else {
                    $name = $name . ($name != '' ? ', ' : '') . $aname['taxon'];
                }
            }
            $taxonRow++;
            data_entry_helper::$javascript .= "\njQuery('#mnhnl-species-grid').find('tr:eq(" . ($taxonRow - 1) . ")').data('taxonRow', " . $taxonRow . ").data('ttlid', " . $ttlid . ").data('meaning_id', " . $taxon[0]['taxon_meaning_id'] . ");";
            $ret .= '
<tr class="sgOrigRow"><td class="ui-state-default clear-sgrow" >X</td><td class="sggrid-namecell">' . $name . '</td>';
            foreach ($subsamples as $key => $entity) {
                $template = '<td class="smp---cgrownum--" ' . (isset($entity['date']) ? '' : 'style="opacity: 0.25"') . '><input class="digits narrow" name="' . $cloneprefix . 'occAttr:' . $countAttr . '--attrid--" ' . (isset($entity['date']) ? '' : 'disabled="disabled"') . ' value="--value--" min="1"></td>';
                if (isset($entity['occurrences'][$ttlid])) {
                    $occid = $entity['occurrences'][$ttlid]['id'];
                    $ret .= str_replace(array('--sgrownum--', '--cgrownum--', '--sampleid--', '--ttlid--', '--occid--', '--attrid--', '--value--'), array($taxonRow, $key + 1, $entity['sample_id'], $ttlid, $occid, isset($entity['occattrs'][$occid]) ? ':' . $entity['occattrs'][$occid]['id'] : '', isset($entity['occattrs'][$occid]) ? $entity['occattrs'][$occid]['value'] : ''), $template);
                } else {
                    $ret .= str_replace(array('--sgrownum--', '--cgrownum--', '--sampleid--', '--ttlid--', '--attrid--', '--value--'), array($taxonRow, $key + 1, isset($entity['sample_id']) ? $entity['sample_id'] : '', $ttlid, '', ''), $template);
                }
            }
            $ret .= '</tr>';
        }
        $ret .= '<tr class="sgNoObRow" ><td></td><td>' . lang::get('No observation') . '</td>';
        if (isset($subsamples)) {
            foreach ($subsamples as $key => $entity) {
                // pretend that the no observations are actually part of the conditions grid.
                $attrArgs = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
                $defAttrOptions = array_merge(array('cellClass' => 'smp-' . ($key + 1), 'class' => 'narrow', 'extraParams' => array_merge($auth['read'], array('view' => 'detail')), 'language' => 'eng'), $options);
                if (isset($entity['sample_id'])) {
                    $attrArgs['id'] = $entity['sample_id'];
                }
                $attrArgs['fieldprefix'] = 'CG:' . ($key + 1) . ':' . (isset($entity['sample_id']) ? $entity['sample_id'] : '') . ':smpAttr';
                $sampleAttributes = data_entry_helper::getAttributes($attrArgs, false);
                $ret .= self::get_sample_attribute_html($sampleAttributes, $args, $defAttrOptions, null, 'Species');
                // validation has to be put on hidden element in the checkbox group/
                data_entry_helper::$late_javascript .= "\njQuery('.sgNoObRow').find(':checkbox:eq(" . $key . ")').rules('add', {no_observation: " . ($key + 1) . "});";
            }
        }
        $ret .= '</tr></tbody></table></div>';
        // remembering that validation for checkbox is actually called on the hidden element, not the checkbox itself.
        data_entry_helper::$late_javascript .= "\n\$.validator.addMethod('no_observation', function(value, element, params){\n  if(jQuery('[name='+jQuery(element).attr('name')+']').not(':hidden').filter('[disabled]').length>0) return true;\n  var numFilledIn = jQuery('.smp-'+params).find('.digits').filter('[value!=]').length;\n  if(jQuery('[name='+jQuery(element).attr('name')+']').not(':hidden').filter('[checked]').length>0)\n    return(numFilledIn==0);\n  else\n    return(numFilledIn>0);\n}, \"" . lang::get('validation_no_observation') . "\");\n";
        data_entry_helper::$javascript .= "\nresetSpeciesGridHeader = function(){\n  // easiest way to get a scrollable table body\n  \$('#mnhnl-species-grid').find('th,td').each(function(){ \$(this).css('width', ''); });\n  jQuery('#mnhnl-species-grid > thead').show();\n  var headerWidths = new Array(); // treat separately as may have different CSS\n  var columnWidths = new Array();\n  \$('#mnhnl-species-grid > thead').find('th').each(function (index) {\n    headerWidths[index] = \$(this).width();\n  });\n  \$('#mnhnl-species-grid > tbody').find('tr:eq(0)').find('td').each(function (index) {\n    columnWidths[index] = \$(this).width();\n  });\n  \$('#mnhnl-species-grid th').each(function(index){\n      \$(this).css('width', headerWidths[index]);\n  });\n  \$('#mnhnl-species-grid tr').each(function(){\n    \$(this).find('td').each(function(index){\n      \$(this).css('width', columnWidths[index]);\n    });\n  });\n  jQuery('#mnhnl-species-grid-head-head').empty().append(jQuery('#mnhnl-species-grid > thead').find('tr').clone().removeAttr('id'));\n  jQuery('#mnhnl-species-grid > thead').hide();\n}\nresetSpeciesGridHeader();\nsgRowIndex = " . $taxonRow . ";\njQuery('#speciesgrid_taxa_taxon_list_id').change(function(){\n  jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list/\" +jQuery('#speciesgrid_taxa_taxon_list_id').val()+\n    \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&callback=?\",\n    function(tdata) {\n      jQuery('#speciesgrid_taxa_taxon_list_id\\\\:taxon').val('');\n      if (tdata.length>0) {\n        found=false;\n        jQuery('#mnhnl-species-grid').find('tr').each(function(i, row){\n          if(tdata[0].taxon_meaning_id == jQuery(row).data('meaning_id'))\n            found=true;\n        });\n        if(found){\n          alert(\"" . lang::get('speciesgrid:rowexists') . "\");\n          return;\n        }\n        sgRowIndex++;\n        newSGrow = jQuery('.sgCloneableRow').clone().removeClass('sgCloneableRow').addClass('sgAddedRow');\n        newSGrow.find('td').removeAttr('disabled');\n        newSGrow.find('input').not('.disabled').removeAttr('disabled');\n        jQuery.each(newSGrow.children(), function(i, cell) {\n          cell.innerHTML = cell.innerHTML.replace(/--ttlid--/g, tdata[0].id).replace(/--sgrownum--/g, sgRowIndex);\n        });\n        newSGrow.find('.sggrid-namecell').append(tdata[0].taxon);\n        newSGrow.data('taxonRow', sgRowIndex).data('ttlid',tdata[0].id).data('meaning_id',tdata[0].taxon_meaning_id).insertBefore('.sgNoObRow');\n        jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list\" +\n            \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&taxon_meaning_id=\" + tdata[0].taxon_meaning_id + \"&callback=?\",\n          function(ldata) {\n            if (ldata.length>0) {\n              var name = '';\n              for(var i=0; i< ldata.length; i++){\n                if(ldata[i].preferred == 't')\n                  name = '<em>'+ldata[i].taxon+'</em>'+(i>0?', ':'')+name;\n                else\n                  name = name+(i>0?', ':'')+ldata[i].taxon;\n              }\n              jQuery('#mnhnl-species-grid').find('tr').each(function(i, row){\n                if(ldata[0].taxon_meaning_id == jQuery(row).data('meaning_id'))\n                  jQuery(row).find('.sggrid-namecell').empty().append(name);});\n              resetSpeciesGridHeader();\n            }});\n        }});\n});\njQuery('.clear-sgrow').live('click', function() {\n  var thisRow=jQuery(this).closest('tr');\n  if(!confirm(\"" . lang::get('LANG_speciesgrid:clearconfirm') . "\")) return;\n  thisRow.find('*').removeClass('ui-state-error');\n  thisRow.find(':text').val('');\n  thisRow.find('.inline-error').remove();\n});\njQuery('.remove-sgnewrow').live('click', function() {\n  var thisRow=jQuery(this).closest('tr');\n  if(!confirm(\"" . lang::get('LANG_speciesgrid:removeconfirm') . "\")) return;\n  thisRow.remove();\n  resetSpeciesGridHeader();\n});\nindiciaFns.bindTabsActivate(jQuery(jQuery('#species').parent()), function(e, ui){\n  panel = typeof ui.newPanel==='undefined' ? ui.panel : ui.newPanel[0];\n  if (panel.id=='species') {\n    resetSpeciesGridHeader();\n  }\n})";
        return $ret;
    }
예제 #6
0
 protected static function communeJS($auth, $args)
 {
     if (self::$mode === self::MODE_EXISTING_RO) {
         return;
     }
     // proxiedurl,featurePrefix,featureType,geometryName,featureNS,srsName,propertyNames
     // http://localhost/geoserver/wfs,indiciaCommune,Communes,the_geom,indicia,EPSG:2169,COMMUNE
     if (isset($args['communeLayerLookup']) && $args['communeLayerLookup'] != '') {
         $communeAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Commune');
         if (!$communeAttr) {
             return lang::get('The lateJS control form must be used with a survey that has the Commune attribute associated with it.');
         }
         $parts = explode(',', $args['communeLayerLookup']);
         data_entry_helper::$onload_javascript .= "communeProtocol = new OpenLayers.Protocol.WFS({\n              url:  '" . str_replace("{HOST}", $_SERVER['HTTP_HOST'], $parts[0]) . "',\n              featurePrefix: '" . $parts[1] . "',\n              featureType: '" . $parts[2] . "',\n              geometryName:'" . $parts[3] . "',\n              featureNS: '" . $parts[4] . "',\n              srsName: '" . $parts[5] . "', // map projection /* GARY */\n              version: '1.1.0'                  \n      \t\t  ,propertyNames: [\"" . $parts[6] . "\"]\n});\nfillCommune = function(a1){\n  if(a1.error && (typeof a1.error.success == 'undefined' || a1.error.success == false)){\n    alert(\"" . lang::get('LANG_CommuneLookUpFailed') . "\");\n    return;\n  }\n  if(a1.features.length > 0)\n    jQuery('[name=locAttr\\:{$communeAttr}],[name^=locAttr\\:{$communeAttr}\\:]').val(a1.features[0].attributes[\"" . $parts[6] . "\"]).attr('readonly','readonly');\n  else {\n    alert(\"" . lang::get('LANG_PositionOutsideCommune') . "\");\n  }\n}\njQuery('[name=locAttr\\:{$communeAttr}],[name^=locAttr\\:{$communeAttr}\\:]').attr('readonly','readonly');\nhook_setSref = function(geom){ // map projection\n  jQuery('[name=locAttr\\:{$communeAttr}],[name^=locAttr\\:{$communeAttr}\\:]').val('');\n  var filter = new OpenLayers.Filter.Spatial({\n  \t\ttype: OpenLayers.Filter.Spatial.CONTAINS ,\n    \tproperty: '" . $parts[3] . "',\n    \tvalue: geom\n  });\n  communeProtocol.read({filter: filter, callback: fillCommune});\n};";
     }
 }
예제 #7
0
 protected static function get_control_moveotherfields($auth, $args, $tabalias, $options)
 {
     // We assume that the key is meaning_id.
     $groups = explode(';', $options['groups']);
     foreach ($groups as $group) {
         $parts = explode(',', $group);
         $attr = iform_mnhnl_getAttr($auth, $args, $parts[0], $parts[1]);
         $other = helper_base::get_termlist_terms($auth, intval($attr['termlist_id']), array('Other'));
         $attr2 = iform_mnhnl_getAttrID($auth, $args, $parts[0], $parts[2]);
         switch ($parts[0]) {
             case 'sample':
                 $prefix = 'smpAttr';
                 break;
             default:
                 break;
         }
         data_entry_helper::$javascript .= "\nvar other = jQuery('[name=" . $prefix . "\\:" . $attr2 . "],[name^=" . $prefix . "\\:" . $attr2 . "\\:]');\nother.next().remove(); // remove break\nother.prev().remove(); // remove legend\nother.removeClass('wide').remove(); // remove Other field, then bolt in after the other radio button.\njQuery('[name=" . str_replace(':', '\\:', $attr['id']) . "],[name^=" . str_replace(':', '\\:', $attr['id']) . "\\:],[name=" . str_replace(':', '\\:', $attr['id']) . "\\[\\]]').filter('[value=" . $other[0]['meaning_id'] . "],[value^=" . $other[0]['meaning_id'] . "\\:]').parent().css('width','auto').append(other);\njQuery('[name=" . str_replace(':', '\\:', $attr['id']) . "],[name^=" . str_replace(':', '\\:', $attr['id']) . "\\:],[name=" . str_replace(':', '\\:', $attr['id']) . "\\[\\]]').change(function(){\n  jQuery('[name=" . str_replace(':', '\\:', $attr['id']) . "],[name^=" . str_replace(':', '\\:', $attr['id']) . "\\:],[name=" . str_replace(':', '\\:', $attr['id']) . "\\[\\]]').filter('[value=" . $other[0]['meaning_id'] . "],[value^=" . $other[0]['meaning_id'] . "\\:]').each(function(){\n    if(this.checked)\n      jQuery('[name=" . $prefix . "\\:" . $attr2 . "],[name^=" . $prefix . "\\:" . $attr2 . "\\:]').addClass('required').removeAttr('readonly');\n    else\n      jQuery('[name=" . $prefix . "\\:" . $attr2 . "],[name^=" . $prefix . "\\:" . $attr2 . "\\:]').removeClass('required').val('').attr('readonly',true);\n  });\n});\njQuery('[name=" . str_replace(':', '\\:', $attr['id']) . "],[name^=" . str_replace(':', '\\:', $attr['id']) . "\\:],[name=" . str_replace(':', '\\:', $attr['id']) . "\\[\\]]').filter('[value=" . $other[0]['meaning_id'] . "],[value^=" . $other[0]['meaning_id'] . "\\:]').change();\n";
     }
     return '';
 }