protected static function get_control_targetspeciesgrid($auth, $args, $tabalias, $options)
 {
     $targetSpeciesAttr = iform_mnhnl_getAttr($auth, $args, 'sample', $args['targetSpeciesAttr']);
     if (!$targetSpeciesAttr) {
         return lang::get('The Target Species Grid control must be used with a survey that has the ' . $args['targetSpeciesAttr'] . ' attribute associated with it.');
     }
     // the target species grid is based on a grouping of samples determined by the
     // 1) the termlist id of the list of target species: argument targetSpeciesTermList
     // 2) a default set of attributes to be loaded: visit, Unsuitablity
     // 3) Overrides for specific target species: Common wall disabled second survey
     $termlist = $targetSpeciesAttr["termlist_id"];
     $extraParams = $auth['read'] + array('termlist_id' => $termlist, 'view' => 'detail');
     $targetSpecies = data_entry_helper::get_population_data(array('table' => 'termlists_term', 'extraParams' => $extraParams));
     $smpAttributes = data_entry_helper::getAttributes(array('attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => '{MyPrefix}:smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']), true);
     $retval = '<br /><table class="target-species-grid"><tr><th colspan=2>' . lang::get('Target Species') . '</th>';
     $attrList = explode(',', $args['targetSpeciesAttrList']);
     $attrIDs = array();
     foreach ($attrList as $attr) {
         $cell = "";
         // $retval .= '<th></th>'; // blank headings: will put captions in table itself.
         if (is_numeric($attr)) {
             $cell = $smpAttributes[intval($attr)]['caption'];
             $attrIDs[] = intval($attr);
         } else {
             foreach ($smpAttributes as $id => $sattr) {
                 if ($attr == $sattr['untranslatedCaption']) {
                     $cell = $sattr['caption'];
                     $attrIDs[] = $id;
                 }
             }
             if ($cell == "") {
                 $retval = lang::get('The configuration of the Target Species Grid includes a ' . $attr . ' samples attribute, which is not associated with this survey.') . '<br/>' . $retval;
             }
         }
         if (!isset($options['useCaptionsInHeader'])) {
             $cell = "";
         }
         $retval .= '<th class="targ-grid-cell">' . $cell . '</th>';
     }
     $retval .= '</tr>';
     if (isset($options['useCaptionsInHeader'])) {
         foreach ($smpAttributes as $id => $sattr) {
             unset($smpAttributes[$id]['caption']);
         }
     }
     $subSamples = array();
     $subSamplesAttrs = array();
     if (isset(data_entry_helper::$entity_to_load['sample:id'])) {
         $smpOptions = array('table' => 'sample', 'nocache' => true, 'extraParams' => $auth['read'] + array('view' => 'detail', 'parent_id' => data_entry_helper::$entity_to_load['sample:id']));
         $subSamples = data_entry_helper::get_population_data($smpOptions);
         foreach ($subSamples as $sample) {
             $subSamplesAttrs[$sample['id']] = data_entry_helper::getAttributes(array('attrtable' => 'sample_attribute', 'valuetable' => 'sample_attribute_value', 'id' => $sample['id'], 'key' => 'sample_id', 'fieldprefix' => '{MyPrefix}:smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']), true);
         }
     }
     // targ:sampleID:termlist_meaning_id:presence|smpAttr:attrdetails.
     foreach ($targetSpecies as $target) {
         $smpID = false;
         $fieldname = '{MyPrefix}:presence:' . $targetSpeciesAttr["attributeId"];
         $present = '';
         $attrOpts = array('lookUpKey' => 'meaning_id', 'extraParams' => $auth['read'], 'language' => iform_lang_iso_639_2($args['language']), 'disabled' => 'disabled');
         foreach ($subSamples as $subSample) {
             foreach ($subSamplesAttrs[$subSample['id']] as $id => $attr) {
                 if (isset($options['useCaptionsInHeader'])) {
                     unset($subSamplesAttrs[$subSample['id']][$id]['caption']);
                 }
                 if ($attr['attributeId'] == $targetSpeciesAttr["attributeId"] && $attr['default'] == $target['meaning_id']) {
                     $smpID = $subSample['id'];
                     $fieldname = str_replace('smpAttr', 'presence', $attr["fieldname"]);
                     $present = " checked=\"checked\" ";
                     unset($attrOpts['disabled']);
                 }
             }
         }
         $fieldprefix = 'targ:' . ($smpID ? $smpID : '-') . ':' . $target['meaning_id'];
         $retval .= str_replace('{MyPrefix}', $fieldprefix, '<tr><td>' . $target['term'] . '</td><td><input type="hidden" name="' . $fieldname . '" class="targ-presence" value=0><input type="checkbox" class="targ-presence" name="' . $fieldname . '" value=1 ' . $present . '></td>');
         foreach ($attrIDs as $attrID) {
             $retval .= str_replace('{MyPrefix}', $fieldprefix, '<td class="targ-grid-cell">' . data_entry_helper::outputAttribute($smpID ? $subSamplesAttrs[$smpID][$attrID] : $smpAttributes[$attrID], $attrOpts) . '</td>');
         }
         $retval .= '</tr>';
     }
     $retval .= '</table><br />';
     data_entry_helper::$javascript .= "// JS for target species grid control.\r\njQuery('.targ-presence').change(function(){\r\n  var myTR = jQuery(this).closest('tr');\r\n  if(jQuery(this).filter('[checked]').length>0) {\r\n    myTR.find('input').filter('[name*=\\:smpAttr\\:]').removeAttr('disabled');\r\n    myTR.find('select').removeAttr('disabled').addClass('required').after('<span class=\"deh-required\">*</span>');\r\n  } else {\r\n    myTR.find('.deh-required,.inline-error').remove();\r\n    myTR.find('.required').removeClass('ui-state-error required');\r\n    myTR.find('input').filter('[name*=\\:smpAttr\\:]').attr('disabled','disabled').removeAttr('checked');\r\n    myTR.find('select').attr('disabled','disabled').val('');\r\n  }\r\n});";
     if (isset($options['disableOptions'])) {
         $disableControls = explode(';', $options['disableOptions']);
         foreach ($disableControls as $disableControl) {
             $disableList = explode(',', $disableControl);
             data_entry_helper::$javascript .= "\njQuery('.target-species-grid').find('[name*=\\:" . $disableList[0] . "\\:smpAttr\\:]').find('option').filter('";
             for ($i = 1; $i < count($disableList); $i++) {
                 data_entry_helper::$javascript .= ($i > 1 ? ',' : '') . "[value=" . $disableList[$i] . "]";
             }
             data_entry_helper::$javascript .= "').attr('disabled','disabled');\n";
         }
     }
     data_entry_helper::$late_javascript .= "// JS for target species grid control.\r\n\$.validator.addMethod('targ-presence', function(value, element){\r\n\treturn jQuery('.targ-presence').filter('[checked]').length > 0;\r\n},\r\n  \"" . lang::get('validation_targ-presence') . "\");\r\n";
     return $retval;
 }
示例#2
0
 protected static function getSiteTypeJS($auth, $args)
 {
     $siteTypeAttr = iform_mnhnl_getAttr($auth, $args, 'location', $args['siteTypeAttr']);
     if (!$siteTypeAttr) {
         return lang::get('This form must be used with a survey that has the ' . $args['siteTypeAttr'] . ' attribute associated with it.');
     }
     $siteTypeAttrID = $siteTypeAttr['attributeId'];
     $siteTypeTermList = helper_base::get_termlist_terms($auth, intval($siteTypeAttr['termlist_id']), array('Other'));
     $siteTypeOtherAttrID = iform_mnhnl_getAttrID($auth, $args, 'location', 'site type other');
     if (!$siteTypeOtherAttrID) {
         return lang::get("This form must be used with a survey that has the 'site type other' location attribute associated with it.");
     }
     // this needs to handle site type as radio (bats1) or checkbox (bats2)
     // type-required is only used for checkboxes - radio ones can use required as per normal.
     data_entry_helper::$javascript .= "\nvar myTerms = jQuery('[name=locAttr\\:" . $siteTypeAttrID . "],[name=locAttr\\:" . $siteTypeAttrID . "\\[\\]],[name^=locAttr\\:" . $siteTypeAttrID . "\\:]').not(':hidden');\nmyTerms_change = function(){\n  if(jQuery('.type-required').filter('[checked]').length > 0)\n    jQuery('.type-required').removeClass('ui-state-error').next('p.inline-error').remove();\n  // for a radio button the change is fired on the newly checked button\n  // for a checkbox button the change is fired on the button itself\n  var attrs = jQuery('[name=locAttr\\:" . $siteTypeAttrID . "],[name=locAttr\\:" . $siteTypeAttrID . "\\[\\]],[name^=locAttr\\:" . $siteTypeAttrID . "\\:]').filter('[value=" . $siteTypeTermList[0]['meaning_id'] . "],[value^=" . $siteTypeTermList[0]['meaning_id'] . "\\:]').filter('[checked]');\n  if(attrs.length>0)\n    jQuery('[name=locAttr\\:" . $siteTypeOtherAttrID . "],[name^=locAttr\\:" . $siteTypeOtherAttrID . "\\:]').addClass('required').removeAttr('readonly');\n  else\n    jQuery('[name=locAttr\\:" . $siteTypeOtherAttrID . "],[name^=locAttr\\:" . $siteTypeOtherAttrID . "\\:]').removeClass('required').val('').attr('readonly',true);\n};\nvar other = jQuery('[name=locAttr\\:" . $siteTypeOtherAttrID . "],[name^=locAttr\\:" . $siteTypeOtherAttrID . "\\:]');\nother.next('br').remove();\nother.prev('label').remove();\nother.removeClass('wide').remove(); // remove Other field, then bolt in after the 'other' selection.\nmyTerms.change(myTerms_change).filter('[value=" . $siteTypeTermList[0]['meaning_id'] . "],[value^=" . $siteTypeTermList[0]['meaning_id'] . "\\:]').parent().append(other);\nif(myTerms.filter(':checkbox').length>0){\n  myTerms.addClass('type-required');\n  other.after('<span class=\"deh-required\">*</span>');\n  \$.validator.addMethod('type-required', function(value, element){\n    var valid = jQuery('.type-required').filter('[checked]').length > 0 || element != jQuery('.type-required').eq(0)[0];\n    if(valid){\n      jQuery('.type-required').removeClass('ui-state-error').next('p.inline-error').remove();\n    }\n    return valid;\n  }, \"" . lang::get('At least one site type entry must be selected.') . "\");\n}\nmyTerms_change();\n";
     return '';
 }
示例#3
0
function iform_mnhnl_getAttrID($auth, $args, $table, $caption, $qualifier = false)
{
    $attr = iform_mnhnl_getAttr($auth, $args, $table, $caption, $qualifier);
    if ($attr) {
        return $attr['attributeId'];
    }
    return false;
}
 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 '';
 }