protected static function getExtraGridModeTabs($retTabs, $readAuth, $args, $attributes) { if (!user_access($args['edit_permission'])) { return ''; } $targetSpeciesAttr = iform_mnhnl_getAttr(parent::$auth, $args, 'sample', $args['targetSpeciesAttr']); if (!$targetSpeciesAttr) { return lang::get('This form must be used with a survey that has the ' . $args['targetSpeciesAttr'] . ' attribute associated with it.'); } if (!$retTabs) { return array('#downloads' => lang::get('Reports'), '#locations' => lang::get('LANG_Locations')); } if ($args['LocationTypeTerm'] == '' && isset($args['loctoolsLocTypeID'])) { $args['LocationTypeTerm'] = $args['loctoolsLocTypeID']; } $primary = iform_mnhnl_getTermID(array('read' => $readAuth), 'indicia:location_types', $args['LocationTypeTerm']); data_entry_helper::$javascript .= "\r\njQuery('.downloadreportparams').val('{\"survey_id\":" . $args['survey_id'] . ", \"location_type_id\":" . $primary . ", \"taxon_list_id\":" . $args['extra_list_id'] . ", \"target_species_attr\":" . $targetSpeciesAttr['attributeId'] . ", \"target_species_termlist\":" . $targetSpeciesAttr['termlist_id'] . (isset($args['targetSpeciesAttrList']) ? ", \"target_species_attr_list\":\"" . $args['targetSpeciesAttrList'] . "\"" : "") . "}');\r\n"; return '<div id="downloads" > <p>' . lang::get('LANG_Data_Download') . '</p>' . ($args['sites_download_report'] != '' ? ' <form id="sitesReportRequestForm" method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=' . $args['sites_download_report'] . '.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv&filename=' . $args['reportFilenamePrefix'] . 'Sites"> <input type="hidden" name="params" class="downloadreportparams" value="" /> <label>' . lang::get('Sites report') . ':</label><input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('Download') . '"> </form>' : '') . ($args['conditions_download_report'] != '' ? ' <form id="conditionsReportRequestForm" method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=' . $args['conditions_download_report'] . '.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv&filename=' . $args['reportFilenamePrefix'] . 'Conditions"> <input type="hidden" name="params" class="downloadreportparams" value="" /> <label>' . lang::get('Conditions report') . ':</label><input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('Download') . '"> </form>' : '') . ' <form id="speciesReportRequestForm" method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=' . $args['species_download_report'] . '.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv&filename=' . $args['reportFilenamePrefix'] . 'Species"> <input type="hidden" name="params" class="downloadreportparams" value="" /> <label>' . lang::get('Species report') . ':</label><input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('Download') . '"> </form> </div>' . iform_mnhnl_locModTool(parent::$auth, $args, parent::$node); }
protected static function get_control_conditionsgrid($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. * Has been updated to have a target species attribute: this makes it too big to fit onto one line * hardcode to 2 lines (could be configurable), first attribute is spread over 2 rows, rest on second row. * first row has remove button, name, first attribute, date and comment.*/ data_entry_helper::$javascript .= "\n///////////////////////////////////////\n// Functions for the conditions grid //\n///////////////////////////////////////\n"; $extraParams = $auth['read'] + array('view' => 'detail', 'reset_timeout' => 'true'); // A single species entry control of some kind $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('class' => 'cgAttr', 'extraParams' => array_merge($auth['read'], array('view' => 'detail')), 'language' => 'eng'), $options); $tabName = isset($options['tabNameFilter']) ? $options['tabNameFilter'] : null; $ret = '<p>' . lang::get("LANG_ConditionsGridInstructions") . "</p>\n<table id=\"cgCloneableTable\" style='display:none' >"; $cloneprefix = 'CG:--rownum--:--sampleid--:'; $LocationTypeID = iform_mnhnl_getTermID(parent::$auth, 'indicia:location_types', $args['LocationTypeTerm']); unset($attrArgs['id']); $attrArgs['fieldprefix'] = $cloneprefix . 'smpAttr'; // have to disabled averything in the cloneable grid due to validation issues. data_entry_helper::$javascript .= "\njQuery('#cgCloneableTable').find('td').attr('disabled','disabled').find('input,select').attr('disabled','disabled');"; $sampleAttributes = data_entry_helper::getAttributes($attrArgs, false); $numRows = isset($options['NumRows']) ? $options['NumRows'] : 2; $numAttrCols = isset($options['NumAttrCols']) ? $options['NumAttrCols'] : 3; $attrHtml = array(); for ($i = 0; $i < $numRows; $i++) { $attrHtml[$i] = self::get_sample_attribute_html($sampleAttributes, $args, $defAttrOptions, $tabName, 'Row' . ($i + 1), $i != 0); } $attrHtml[0] = preg_replace('/>/', ' rowspan=' . $numRows . '>', $attrHtml[0], 1); $ret .= " <tr class=\"cgCloneableRow1\">\n <td class=\"ui-state-default remove-cgnewrow\" style=\"width: 1%\" rowspan=" . $numRows . " >X</td>\n <td class=\"cggrid-namecell\" rowspan=" . $numRows . " ><input name=\"" . $cloneprefix . "name\" class=\"cggrid-name narrow\" value=\"\" readonly=\"readonly\" >\n <input type=\"hidden\" name=\"" . $cloneprefix . "location:centroid_sref\" class=\"cggrid-centroid_sref\" ><input type=\"hidden\" name=\"" . $cloneprefix . "location:centroid_geom\" class=\"cggrid-centroid_geom\" ><input type=\"hidden\" name=\"" . $cloneprefix . "location:boundary_geom\" class=\"cggrid-boundary_geom\" ><input type=\"hidden\" name=\"" . $cloneprefix . "location:location_type_id\" class=\"cggrid-location_type_id\" value=\"" . $LocationTypeID . "\"></td>\n " . $attrHtml[0] . "\n <td class=\"cggrid-datecell\"><label class=\"auto-width\">" . lang::get('Date') . ":</label> <input name=\"" . $cloneprefix . "date\" class=\"cggrid-date customDate checkYear checkComplete\" value=\"\" ></td>\n <td class=\"cggrid-commentcell\" colspan=" . (count($sampleAttributes) - 3) . "><label>" . lang::get('Comment') . ":</label> <input name=\"" . $cloneprefix . "comment\" class=\"cggrid-comment\" ></td>\n </tr>"; for ($i = 1; $i < $numRows; $i++) { $ret .= " <tr class=\"cgCloneableRow" . $i . "\">\n " . $attrHtml[$i] . "\n </tr>\n"; } $ret .= "</table><table id =\"conditions-grid\"><thead><tr><th colSpan=2>" . lang::get("Site") . '</th>'; foreach ($sampleAttributes as $attr) { if (strcasecmp('Row1', $attr['inner_structure_block']) == 0) { $ret .= '<th>' . $attr['caption'] . '</th>'; } } for ($i = 0; $i < $numAttrCols; $i++) { $ret .= '<th></th>'; } $ret .= '</tr></thead><tbody>'; $cgRowNum = 0; // actually equivalent to 2 row group if (isset(data_entry_helper::$entity_to_load["sample:updated_by_id"])) { // only set if data loaded from db, not error condition $subsamples = self::getLocationsInGrid($auth, $args); if (isset($subsamples)) { foreach ($subsamples as $entity) { $cgRowNum++; data_entry_helper::$javascript .= "\njQuery('#conditions-grid > tbody').find('tr:eq(" . $numRows * ($cgRowNum - 1) . ")').find('.cggrid-date').datepicker({dateFormat : 'dd/mm/yy', changeMonth: true, changeYear: true, constrainInput: false, maxDate: '0', onClose: function() { \$(this).valid(); }});\n"; for ($i = 0; $i < $numRows; $i++) { data_entry_helper::$javascript .= "\njQuery('#conditions-grid > tbody').find('tr:eq(" . ($numRows * ($cgRowNum - 1) + $i) . ")').data('locID', " . $entity['location_id'] . ").data('cgRowNum', " . $cgRowNum . ");"; } if (isset($entity['sample_id'])) { $fieldprefix = 'CG:' . $cgRowNum . ':' . $entity['sample_id'] . ':'; $attrArgs['id'] = $entity['sample_id']; } else { $fieldprefix = 'CG:' . $cgRowNum . ':--sampleid--:'; unset($attrArgs['id']); } if (isset($entity['date']) && preg_match('/^(\\d{4})/', $entity['date'])) { // Date has 4 digit year first (ISO style) - convert date to expected output format // @todo The date format should be a global configurable option. It should also be applied to reloading of custom date attributes. $d = new DateTime($entity['date']); $entity['date'] = $d->format('d/m/Y'); } $attrArgs['fieldprefix'] = $fieldprefix . 'smpAttr'; $sampleAttributes = data_entry_helper::getAttributes($attrArgs, false); $attrHtml = array(); for ($i = 0; $i < $numRows; $i++) { $attrHtml[$i] = self::get_sample_attribute_html($sampleAttributes, $args, $defAttrOptions, $tabName, 'Row' . ($i + 1), $i != 0); } $attrHtml[0] = preg_replace('/>/', ' rowspan=' . $numRows . '>', $attrHtml[0], 1); $ret .= " <tr class=\"cggrid-row\">\n <td class=\"ui-state-default clear-cgrow\" style=\"width: 1%\" rowspan=" . $numRows . " >X</td>\n <td class=\"cggrid-namecell\" rowspan=" . $numRows . " ><input name=\"" . $fieldprefix . "name\" class=\"cggrid-name narrow\" value=\"" . $entity['name'] . "\" readonly=\"readonly\" >\n <input type=\"hidden\" name=\"" . $fieldprefix . "location_id\" value=\"" . $entity['location_id'] . "\" class=\"cggrid-location_id\" ></td>\n " . $attrHtml[0] . "\n <td class=\"cggrid-datecell\"><label class=\"auto-width\">" . lang::get('Date') . ":</label> <input name=\"" . $fieldprefix . "date\" class=\"cggrid-date customDate checkYear checkComplete\" value=\"" . $entity['date'] . "\" ></td>\n <td class=\"cggrid-commentcell\" colspan=" . (count($sampleAttributes) - 3) . "><label>" . lang::get('Comment') . ":</label> <input name=\"" . $fieldprefix . "comment\" class=\"cggrid-comment\" value=\"" . htmlspecialchars($entity['comment']) . "\" ></td>\n </tr>"; for ($i = 1; $i < $numRows; $i++) { $ret .= " <tr class=\"cggrid-row" . ($i + 1) . "\">\n " . $attrHtml[$i] . "\n </tr>\n"; } } } } $ret .= '</tbody></table>'; data_entry_helper::$onload_javascript .= "\ncgRowNum={$cgRowNum};"; data_entry_helper::$javascript .= "\nif (typeof jQuery.validator !== \"undefined\") {\n jQuery.validator.addMethod('customDate',\n function(value, element) {\n // parseDate throws exception if the value is invalid\n try{jQuery.datepicker.parseDate( 'dd/mm/yy', value);return true;}\n catch(e){return false;}\n }, '" . lang::get('Please enter a valid date') . "'\n );\n jQuery.validator.addMethod('checkYear',\n function(value, element) {\n if(jQuery(element).val() == '') return true;\n var myYear = jQuery(element).datepicker(\"getDate\").getFullYear();\n return (myYear == jQuery('[name=sample\\:date]').val());\n }, '" . lang::get('Please ensure the year matches the year entered above.') . "'\n );\n jQuery.validator.addMethod('checkNumSites',\n function(value, element) {\n return (jQuery(element).val() > 0);\n }, '" . lang::get('You must add at least one site to the square before you can continue.') . "'\n );\n jQuery.validator.addMethod('checkComplete',\n function(value, element) {\n return (jQuery('.cggrid-date').not('[value=]').length > 0);\n }, '" . lang::get('You must fill in the data for at least one site in this grid.') . "'\n );\n}\njQuery('.cggrid-row').each(function(index, Element) { // initial rows: don't need to worry about name drop down.\n if(jQuery(this).find('.cggrid-date').val()==\"\"){ // disable if blank.\n jQuery(this).find('td:not(.cggrid-datecell,.cggrid-namecell)').css('opacity',0.25);\n jQuery(this).find('*:not(.cggrid-date,.cggrid-datecell,.cggrid-name,.cggrid-namecell)').attr('disabled','disabled');"; // disable all active controls from the row group apart from the date. // Do NOT disable the date or its container td, otherwise it is not submitted. for ($i = 1; $i < $numRows; $i++) { $query = "jQuery(this)"; for ($j = 0; $j < $i; $j++) { $query .= ".next()"; } data_entry_helper::$javascript .= "\n" . $query . ".find('td').css('opacity',0.25);\n" . $query . ".find('*').attr('disabled','disabled');"; } data_entry_helper::$javascript .= "\n var myRowNum = jQuery(this).closest('tr').data('cgRowNum');\n jQuery('.smp-'+myRowNum).css('opacity','0.25').find(':checkbox').attr('disabled','disabled');\n } else { // when filled in, the date is mandatory, plus any specified attributes on the second row\n jQuery(this).find('.cggrid-datecell').append('<span class=\"deh-required\">*</span>').find('input').addClass('required');"; if (isset($options['setRowRequired'])) { $query = "jQuery(this)"; for ($i = 1; $i < $options['setRowRequired']; $i++) { $query .= ".next()"; } data_entry_helper::$javascript .= "\n" . $query . ".find('td').each(function(){\n jQuery(this).append('<span class=\"deh-required\">*</span>').find('input,select').addClass('required');});"; } data_entry_helper::$javascript .= "\n }\n});\njQuery('.cggrid-date').live('change', function() {\n var myRow = jQuery(this).closest('tr');\n var myRowNum = myRow.data('cgRowNum');\n jQuery('.smp-'+myRowNum).css('opacity','').find('input').removeAttr('disabled').removeClass('disabled');"; for ($i = 0; $i < $numRows; $i++) { $query = " myRow"; for ($j = 0; $j < $i; $j++) { $query .= ".next()"; } data_entry_helper::$javascript .= "\n" . $query . ".find('td').css('opacity','');\n" . $query . ".find('*').removeAttr('disabled').removeClass('required ui-state-error');\n" . $query . ".find('.deh-required,.inline-error').remove();\n"; } data_entry_helper::$javascript .= "\n jQuery(this).addClass('required').parent().append('<span class=\"deh-required\">*</span>');"; if (isset($options['setRowRequired'])) { $query = " myRow"; for ($i = 1; $i < $options['setRowRequired']; $i++) { $query .= ".next()"; } data_entry_helper::$javascript .= "\n" . $query . ".find('td').each(function(){\n jQuery(this).append('<span class=\"deh-required\">*</span>').find('input,select').addClass('required');});"; } data_entry_helper::$javascript .= "\n});\njQuery('.clear-cgrow').live('click', function() { // existing location - no name select.\n var thisRow=jQuery(this).closest('tr');\n if(!confirm(\"" . lang::get('LANG_conditionsgrid:clearconfirm') . "\")) return;\n thisRow.find('td:not(.cggrid-datecell,.cggrid-namecell)').css('opacity',0.25);\n thisRow.find('*').removeClass('required ui-state-error');\n thisRow.find(':text').filter('*:not(.cggrid-name)').val('');\n thisRow.find('select').val('');\n thisRow.find('.inline-error,.deh-required').remove();\n thisRow.find('*:not(.cggrid-date,.cggrid-datecell,.cggrid-name,.cggrid-namecell)').attr('disabled','disabled');"; for ($i = 1; $i < $numRows; $i++) { $query = "thisRow"; for ($j = 0; $j < $i; $j++) { $query .= ".next()"; } data_entry_helper::$javascript .= "\n " . $query . ".find('td').css('opacity',0.25);\n " . $query . ".find('.inline-error,.deh-required').remove();\n " . $query . ".find(':checkbox').attr('checked',false);\n " . $query . ".find('*').removeClass('required ui-state-error').attr('disabled','disabled');\n " . $query . ".find('select,:text').val('');\n"; } data_entry_helper::$javascript .= "\n var myRowNum = thisRow.data('cgRowNum');\n jQuery('.smp-'+myRowNum).css('opacity',0.25).find(':text').attr('disabled','disabled').addClass('disabled').val('');\n jQuery('.smp-'+myRowNum).css('opacity',0.25).find(':checkbox').attr('disabled','disabled').attr('checked','');\n});\nsetNameDropDowns(true, false);\njQuery('.remove-cgnewrow').live('click', function() {\n if(jQuery('.cggrid-row,.cgAddedRow').length < 2) {\n alert(\"" . lang::get("You can't remove the last site in the square/grid - there must be at least one. If you wish to remove this one, you must first add another in the Site tab.") . "\");\n return;\n }\n var thisRow=jQuery(this).closest('tr');\n if(!confirm(\"" . lang::get('LANG_conditionsgrid:removeconfirm') . "\")) return;\n var myRowNum = thisRow.data('cgRowNum');\n var mySiteNum = thisRow.data('SiteNum');\n jQuery('.smp-'+myRowNum).remove();\n jQuery('#conditions-grid > tbody').find('tr').each(function(index, elem){\n if(jQuery(elem).data('cgRowNum') == myRowNum)\n jQuery(elem).remove();\n });\n recalcNumSites();\n // TBD de highlight, demodify, and remove from map\n for(var i=SiteLabelLayer.features.length-1; i>=0; i--){ // Row may not be selected on map\n if(SiteLabelLayer.features[i].attributes.SiteNum == mySiteNum){\n SiteLabelLayer.destroyFeatures([SiteLabelLayer.features[i]]);\n setNameDropDowns(true, false);\n }\n }\n for(var i=SiteAreaLayer.features.length-1; i>=0; i--){ // Row may not be selected on map\n if(SiteAreaLayer.features[i].attributes.SiteNum == mySiteNum){\n if(SiteAreaLayer.features[i].attributes.highlighted){\n modAreaFeature.unselectFeature(SiteAreaLayer.features[i]);\n selectFeature.unhighlight(SiteAreaLayer.features[i]);\n }\n SiteAreaLayer.destroyFeatures([SiteAreaLayer.features[i]]);\n setNameDropDowns(true, false);\n }\n }\n for(var i=SitePathLayer.features.length-1; i>=0; i--){ // Row may not be selected on map\n if(SitePathLayer.features[i].attributes.SiteNum == mySiteNum){\n if(SitePathLayer.features[i].attributes.highlighted){\n modPathFeature.unselectFeature(SitePathLayer.features[i]);\n selectFeature.unhighlight(SitePathLayer.features[i]);\n }\n setNameDropDowns(true, false);\n SitePathLayer.destroyFeatures([SitePathLayer.features[i]]);\n }\n }\n for(var i=SitePointLayer.features.length-1; i>=0; i--){ // Row may not be selected on map\n if(SitePointLayer.features[i].attributes.SiteNum == mySiteNum){\n if(SitePointLayer.features[i].attributes.highlighted){\n modPointFeature.unselectFeature(SitePointLayer.features[i]);\n }\n setNameDropDowns(true, false);\n SitePointLayer.destroyFeatures([SitePointLayer.features[i]]);\n }\n }\n cgRowNum=0;\n jQuery('.cggrid-row,.cgAddedRow').each(function(i,thisRow){\n if(jQuery(thisRow).data('cgRowNum') > cgRowNum)\n cgRowNum=jQuery(thisRow).data('cgRowNum');\n });\n setNameDropDowns('leave', false);\n});\n// 2 places we can delete from the main map delete site button and on the conditions grid 'X' button\nhook_RemoveNewSite= function() {\n // assume all checks done by main function, and it will destroy the features after this is called.\n var highlighted = gethighlight();\n var myRowNum = highlighted[0].attributes.cgRowNum;\n jQuery('#conditions-grid > tbody').find('tr').each(function(index, elem){\n if(jQuery(elem).data('cgRowNum') == myRowNum)\n jQuery(elem).remove();\n });\n jQuery('.smp-'+myRowNum).remove();\n cgRowNum=0;\n jQuery('.cggrid-row,.cgAddedRow').each(function(i,thisRow){\n if(jQuery(thisRow).data('cgRowNum') > cgRowNum)\n cgRowNum=jQuery(thisRow).data('cgRowNum');\n });\n};\nhook_multisite_setGeomFields=function(feature, boundaryWKT, centreWKT){\n if(feature.attributes['new'] != true) return; // just to be safe...\n // AND assume that we can modify existing.\n // want newCGRow to stay valid until json returns so don't scope local.\n newCGrow=false;\n jQuery('.cgAddedRow').each(function (index, Element){\n if(jQuery(this).data('SiteNum') == feature.attributes.SiteNum) newCGrow=jQuery(this);\n });\n if(!newCGrow) return; \n newCGrow.find('.cggrid-boundary_geom').val(boundaryWKT);\n newCGrow.find('.cggrid-centroid_geom').val(centreWKT);\n jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/spatial/wkt_to_sref?wkt=\" + centreWKT + \"&system=2169&precision=8&callback=?\",\n function(data){\n if(typeof data.error != 'undefined') alert(data.error);\n else newCGrow.find('.cggrid-centroid_sref').val(data.sref);});\n}\njQuery('#dummy-name').change(function() {\n var highlighted = gethighlight();\n if(highlighted.length == 0 || !highlighted[0].attributes['new']) {\n setNameDropDowns(true, false);\n return;\n }\n var myRowNum = highlighted[0].attributes.cgRowNum;\n ZoomToSite();\n jQuery('.cgAddedRow').each(function(index, elem){\n if(jQuery(elem).data('cgRowNum') == myRowNum)\n jQuery(elem).find('.cggrid-name').val(jQuery('#dummy-name').val());\n });\n moveGridEntries(myRowNum);\n jQuery('#mnhnl-species-grid-header').find('.smp-'+myRowNum).empty().append(jQuery(this).val());\n resetSpeciesGridHeader();\n for(var i=SiteLabelLayer.features.length-1; i>=0; i--){ // Row may not be selected on map\n if(typeof SiteLabelLayer.features[i].attributes.cgRowNum != 'undefined'\n && SiteLabelLayer.features[i].attributes.cgRowNum == myRowNum\n && SiteLabelLayer.features[i].attributes['new']){\n feature = SiteLabelLayer.features[i];\n SiteLabelLayer.removeFeatures([feature]);\n feature.style.label = jQuery(this).val();\n SiteLabelLayer.addFeatures([feature]);\n break;\n }\n }\n});\nsetCommentWidth = function(){\n jQuery('.cggrid-comment').width('10px');\n var myWidth=jQuery('#conditions-grid > tbody').find('.cggrid-commentcell').eq(0).width();\n var labelWidth=jQuery('#conditions-grid > tbody').find('.cggrid-commentcell').find('label').eq(0).width();\n jQuery('.cggrid-commentcell').each(function(index){\n jQuery(this).find('input').width(myWidth-labelWidth-1-6);\n });\n}\nconditionsTabHandler = function(e, ui){\n panel = typeof ui.newPanel==='undefined' ? ui.panel : ui.newPanel[0];\n if (panel.id=='conditions') {\n setCommentWidth();\n indiciaFns.unbindTabsActivate(jQuery(jQuery('#conditions').parent()), conditionsTabHandler);\n }\n}\nindiciaFns.bindTabsActivate(jQuery(jQuery('#conditions').parent()), conditionsTabHandler);\n"; return $ret; }
function iform_mnhnl_set_editable($auth, $args, $node, $locList, $force, $loctypeParam) { global $user; if ($force === true || $force === false) { data_entry_helper::$javascript .= "\ncanEditExistingSites = " . ($force ? "true" : "false") . ";\n"; return; } $isAdmin = user_access('edit_permission'); if ($isAdmin) { data_entry_helper::$javascript .= "\ncanEditExistingSites = true;\n"; return; } $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 so records can be tagged against their creator.'); } if (count($locList) == 0) { $location_list_args = array('nocache' => true, 'extraParams' => array_merge(array('view' => 'detail', 'website_id' => $args['website_id'], 'location_type_id' => $loctypeParam), $auth['read']), 'columns' => 'id,location_type_id', 'table' => 'location'); // Idea here is to get a list of all locations in order to build drop downs. $locList = data_entry_helper::get_population_data($location_list_args); // Want id, location_type_id if (isset($locList['error'])) { return $locList['error']; } } $primary = iform_mnhnl_getTermID($auth, 'indicia:location_types', $args['LocationTypeTerm']); data_entry_helper::$javascript .= "SiteEditable = {"; $locCheckList = array(); $locEditList = array(); foreach ($locList as $location) { if ($location['location_type_id'] == $primary) { $locCheckList[] = $location['id']; $locEditList[$location['id']] = true; } else { data_entry_helper::$javascript .= "\"" . $location['id'] . "\" : false,\n"; } } $maxPerQuery = 100; $locCount = count($locCheckList); $locIdx = 0; $smpList = array(); if ($locCount > 0) { while ($locIdx < $locCount) { $locIDs = array(); for ($i = 0; $i < $maxPerQuery && $locIdx < $locCount; $i++, $locIdx++) { $locIDs[] = $locCheckList[$smpIdx]; } $sample_list_args = array('nocache' => true, 'extraParams' => array_merge(array('orderby' => 'id', 'view' => 'detail', 'website_id' => $args['website_id'], 'location_id' => $locIDs), $auth['read']), 'table' => 'sample'); $smpListX = data_entry_helper::get_population_data($sample_list_args); if (isset($smpListX['error'])) { return $smpListX['error']; } $smpList = $smpList + $smpListX; } } $smpCount = count($smpList); $smpIdx = 0; if ($smpCount > 0) { while ($smpIdx < $smpCount) { $smpIDs = array(); $smpLocList = array(); for ($i = 0; $i < $maxPerQuery && $smpIdx < $smpCount; $i++, $smpIdx++) { $smpIDs[] = $smpList[$smpIdx]['id']; $smpLocList[$smpList[$smpIdx]['id']] = $smpList[$smpIdx]['location_id']; } $sample_attr_args = array('extraParams' => array_merge(array('website_id' => $args['website_id'], 'sample_attribute_id' => $userIdAttr, 'sample_id' => $smpIDs), $auth['read']), 'table' => 'sample_attribute_value'); $smpAttr = data_entry_helper::get_population_data($sample_attr_args); foreach ($smpAttr as $attribute) { if (!empty($attribute['id']) && $attribute['raw_value'] != $user->uid) { $locEditList[$smpLocList[$attribute['sample_id']]] = false; } } } } foreach ($locEditList as $id => $state) { data_entry_helper::$javascript .= "\"" . $id . "\" : " . ($state ? "true" : "false") . ",\n"; } data_entry_helper::$javascript .= "};\n"; }
private static function set_code_functionality($auth, $args, $isAdmin) { if (self::$mode === self::MODE_EXISTING_RO) { return; } if ($args['LocationTypeTerm'] == '' && isset($args['loctoolsLocTypeID'])) { $args['LocationTypeTerm'] = $args['loctoolsLocTypeID']; } $primary = iform_mnhnl_getTermID($auth, 'indicia:location_types', $args['LocationTypeTerm']); if ($args['SecondaryLocationTypeTerm'] != '') { $secondary = iform_mnhnl_getTermID($auth, 'indicia:location_types', $args['SecondaryLocationTypeTerm']); $loctypequery = "&query='+escape(JSON.stringify({'in': ['location_type_id', [{$primary}, {$secondary}]]}))+'"; } else { $loctypequery = "&location_type_id=" . $primary; } data_entry_helper::$javascript .= "// This is called after the location is cleared, including the code.\nhook_set_defaults=function(){\n // If we come to set the code and we find it is filled in, it must have already been set by a fetch from DB so leave...\n if(jQuery('[name=location\\:code]').val() == '')\n jQuery('[name=location\\:code]').val(defaultCode);\n};\n"; if (!$isAdmin) { data_entry_helper::$javascript .= "jQuery('#location-code').attr('readonly','readonly');\n"; } else { data_entry_helper::$javascript .= "jQuery('#location-code').change(function(){\n if(jQuery.inArray(jQuery(this).val(), usedCodes) >= 0 && jQuery(this).attr('dbCode') != jQuery(this).val()) {\n alert(\"" . lang::get('This code is already in use. The value will be set to the next in sequence: ') . "\" + defaultCode + \". \"+(jQuery(this).attr('dbCode') != '' ? \"" . lang::get('This site previously had a code of: ') . "\"+jQuery(this).attr('dbCode') : ''));\n jQuery(this).val(defaultCode);\n }\n});\n"; } }