Ejemplo n.º 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;
        // 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;
    }
Ejemplo n.º 2
0
 public static function get_form($args, $node, $response = null)
 {
     global $indicia_templates;
     global $user;
     $indicia_templates['select_item'] = '<option value="{value}" {selected} >{caption}&nbsp;</option>';
     if ($user->uid === 0) {
         return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.');
     }
     // we don't use the map, but a lot of the inherited code assumes the map is present.
     self::$svcUrl = data_entry_helper::$base_url . '/index.php/services';
     data_entry_helper::add_resource('openlayers');
     $indicia_templates['label'] = '<label for="{id}"{labelClass}>{label}:</label>';
     // can't have the CR on the end
     $indicia_templates['zilch'] = '';
     // can't have the CR on the end
     self::$locations = iform_loctools_listlocations($node);
     $retVal = parent::get_form($args, $node, $response);
     if (parent::$mode != self::MODE_GRID) {
         iform_mnhnl_addCancelButton($args['interface']);
         data_entry_helper::$javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
         if (!iform_loctools_checkaccess($node, 'superuser')) {
             data_entry_helper::$javascript .= "\njQuery('[name=smpAttr\\:" . $args['observer_attr_id'] . "],[name^=smpAttr\\:" . $args['observer_attr_id'] . "\\:]').attr('readonly',true)";
             if (parent::$mode == self::MODE_NEW) {
                 data_entry_helper::$javascript .= ".val(\"" . $user->name . "\");";
             } else {
                 data_entry_helper::$javascript .= ";";
             }
         } else {
             $userlist = iform_loctools_listusers($node);
             data_entry_helper::$javascript .= "\nexisting = jQuery('[name=smpAttr\\:" . $args['observer_attr_id'] . "],[name^=smpAttr\\:" . $args['observer_attr_id'] . "\\:]');\nreplacement = '<select name=\"'+existing.attr('name')+'\" >";
             foreach ($userlist as $uid => $a_user) {
                 data_entry_helper::$javascript .= "<option value=\"" . $a_user->name . "\">" . $a_user->name . "&nbsp;</option>";
             }
             data_entry_helper::$javascript .= "</select>';\njQuery(replacement).insertBefore(existing).val(existing.val());\nexisting.remove();\n";
         }
         data_entry_helper::$javascript .= "\n// jQuery('#sample\\\\:date').datepicker( \"option\", \"minDate\", new Date(2010, 4 - 1, 1) );\nDate.prototype.getMonthName = function() {\nvar m = ['" . lang::get('January') . "','" . lang::get('February') . "','" . lang::get('March') . "',\n'" . lang::get('April') . "','" . lang::get('May') . "','" . lang::get('June') . "',\n'" . lang::get('July') . "','" . lang::get('August') . "','" . lang::get('September') . "',\n'" . lang::get('October') . "','" . lang::get('November') . "','" . lang::get('December') . "'];\nreturn m[this.getMonth()];\n} \nvar monthAttr = jQuery('[name=smpAttr\\\\:" . $args['month_attr_id'] . "],[name^=smpAttr\\\\:" . $args['month_attr_id'] . "\\\\:]').attr('disabled', true);\nmonthAttr.before('<input type=\"hidden\" id=\"storedMonth\" name=\"'+monthAttr.attr('name')+'\">');\nupdateSampleDate = function(context, doAlert){\n  jQuery('.displayDateDetails').empty().append('<span>'+jQuery('[name=sample\\:date]').val()+'</span>');\n  var myDate = jQuery(context).datepicker(\"getDate\");\n  var monthAttr = jQuery('[name=smpAttr\\\\:" . $args['month_attr_id'] . "],[name^=smpAttr\\\\:" . $args['month_attr_id'] . "\\\\:]').filter('select').val('');\n  if(myDate != null){\n    myDate = myDate.getMonthName();\n    monthAttr.find(\"option:contains('\"+myDate+\"')\").attr('selected',true) ; \n    jQuery('#storedMonth').val(monthAttr.val()); // doing in this order converts the text to a number and stores that number in the storedMonth\n  } else\n    jQuery('#storedMonth').val('');\n  if(doAlert && monthAttr.val() == \"\")\n  \talert('Given date is outside valid month range (April to September).');\n};\njQuery('#sample\\\\:date').change(function(){updateSampleDate(this, true);});\nupdateSampleDate('#sample\\\\:date', false);\njQuery('.tab-submit').unbind('click');\njQuery('.tab-submit').click(function() {\n  var current=jQuery('#controls').tabs('option', 'selected');\n  var tabinputs = jQuery('#entry_form div > .ui-tabs-panel:eq('+current+')').find('input,select');\n  var secList = '';\n  if (!tabinputs.valid()) { return; }\n  var rows = jQuery('.sectionlist').find('tr');\n  for(var i=1; i<= " . $args['max_number_sections'] . "; i++){\n    if(jQuery('.sectionlist').find('[section='+i+']').length > 0) {\n      var aucuneControl = jQuery(':checkbox[name^=\"SLA\\:'+i+'\\:\"]').filter('[name\$=\"\\:" . $args['aucune_attr_id'] . "\"]');\n      var foundEntry = false;\n      for(var j = 1; j < (rows.length-(numAttrs+1)); j++){\n        foundEntry = foundEntry || (jQuery(rows[j]).find('td').filter(':eq('+i+')').find('[value!=\"\"]').length > 0);\n      }\n      if(!foundEntry && !aucuneControl.attr('checked')){\n          secList = secList + (secList=='' ? '' : ', ') + i;\n      }\n    }\n  }\n  if (secList != ''){\n    alert('The following sections have no species recorded against them: Section(s) '+secList+'. In these circumstances, the \"No observation\" checkbox must be checked for the relevant section.'); \n    return;\n  }\n  var form = jQuery(this).parents('form:first');\n  form.submit();\n});\n";
     } else {
         $retVal .= "<div style=\"display:none\" />\n    <form id=\"form-delete-survey\" action=\"" . iform_mnhnl_getReloadPath() . "\" method=\"POST\">" . parent::$auth['write'] . "\n       <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n       <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n       <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n       <input type=\"hidden\" name=\"sample:date\" value=\"2010-01-01\"/>\n       <input type=\"hidden\" name=\"sample:location_id\" value=\"\" />\n       <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n    </form>\n</div>";
         data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n  if(confirm(\"Are you sure you wish to delete survey \"+sampleID)){\n    jQuery.getJSON(\"" . self::$svcUrl . "/data/sample/\"+sampleID +\n            \"?mode=json&view=detail&auth_token=" . parent::$auth['read']['auth_token'] . "&nonce=" . parent::$auth['read']["nonce"] . "\" +\n            \"&callback=?\", function(data) {\n        if (data.length>0) {\n          jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n          jQuery('#form-delete-survey').find('[name=sample\\:date]').val(data[0].date_start);\n          jQuery('#form-delete-survey').find('[name=sample\\:location_id]').val(data[0].location_id);\n          jQuery('#form-delete-survey').submit();\n  }});\n  };\n};\n";
     }
     return $retVal;
 }
   /**
    * Construct a grid of existing records.
    * @param array $args iform parameters.
    * @param object $node node being shown.
    * @param array $auth authentication tokens for accessing the warehouse.
    * @return string HTML for grid.
    */
   protected static function getGrid($args, $node, $auth)
   {
       $r = '';
       $attributeOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
       if (isset($args['sample_method_id'])) {
           $attributeOpts['sample_method_id'] = $args['sample_method_id'];
       }
       $attributes = data_entry_helper::getAttributes($attributeOpts, false);
       $tabs = array('#sampleList' => lang::get('LANG_Main_Samples_Tab'));
       // Add in a tab for the allocation of locations if this option was selected
       if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) {
           $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations');
       }
       // An option for derived classes to add in extra tabs
       if (method_exists(self::$called_class, 'getExtraGridModeTabs')) {
           $extraTabs = call_user_func(array(self::$called_class, 'getExtraGridModeTabs'), false, $auth['read'], $args, $attributes);
           if (is_array($extraTabs)) {
               $tabs = $tabs + $extraTabs;
           }
       }
       // Only actually need to show tabs if there is more than one
       if (count($tabs) > 1) {
           $active = isset($_GET['page']) ? '#setLocations' : '#sampleList';
           $r .= "<div id=\"controls\">" . data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => $active)) . "<div id=\"temp\"></div>";
           $r .= data_entry_helper::tab_header(array('tabs' => $tabs));
       }
       // Here is where we get the table of samples
       $r .= "<div id=\"sampleList\">" . call_user_func(array(self::$called_class, 'getSampleListGrid'), $args, $node, $auth, $attributes) . "</div>";
       // Add content to the Allocate Locations tab if this option was selected
       if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) {
           $r .= '<div id="setLocations">';
           $url = data_entry_helper::$base_url . '/index.php/services/data/location?mode=json&view=detail' . '&auth_token=' . $auth['read']['auth_token'] . '&nonce=' . $auth['read']["nonce"] . "&parent_id=NULL&orderby=name" . "&columns=id,name" . (isset($args['loctoolsLocTypeID']) && $args['loctoolsLocTypeID'] != '' ? '&location_type_id=' . $args['loctoolsLocTypeID'] : '');
           if (!isset($options['loctoolsPageSize'])) {
               $options['loctoolsPageSize'] = 20;
           }
           $page = empty($_REQUEST['page']) ? 1 : $_REQUEST['page'];
           // starts at 1.
           $session = curl_init($url);
           curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
           $entities = json_decode(curl_exec($session), true);
           $pages = ceil(count($entities) / $options['loctoolsPageSize']);
           // starts at 1
           $count = $page < $pages ? $options['loctoolsPageSize'] : (count($entities) - 1) % $options['loctoolsPageSize'] + 1;
           // number displayed on this page
           // build a jumper control:
           if ($pages > 1) {
               $reload = data_entry_helper::get_reload_link_parts();
               $r .= '<form method="GET" action="' . $reload['path'] . '">';
               if (count($reload['params'])) {
                   foreach ($reload['params'] as $param => $value) {
                       if ($param != "page") {
                           $r .= '<input type="hidden" name="' . $param . '" value="' . $value . '">';
                       }
                   }
               }
               $r .= '<label style="width:auto;" for="pageField">' . lang::get('Jump to page for location') . ':</label><select id="pageField" name="page"><option value="1">' . lang::get('Pick') . '</option>';
               foreach ($entities as $idx => $entity) {
                   $r .= '<option value="' . ceil(($idx + 1) / $options['loctoolsPageSize']) . '">' . $entity["name"] . '</option>';
               }
               $r .= "<input type=\"submit\" class=\"default-button\" value=\"" . lang::get('Go') . "\" /></form>\n";
               $r .= '<p>' . lang::get('You must save any changes made to data on this page before viewing any other page, otherwise those changes will be lost.') . "</p>\n";
           }
           $r .= '<form method="post"><input type="hidden" id="mnhnld1" name="mnhnld1" value="mnhnld1" /><input type="hidden" name="page" value="' . $page . '" />
 <div class="location-allocation-wrapper-outer" ><div class="location-allocation-wrapper-inner"><table border="1"></thead><tr><th class="freeze-first-col">' . lang::get('Location') . '</th>';
           // Main table body
           $userlist = iform_loctools_listusers($node);
           foreach ($userlist as $uid => $a_user) {
               $r .= '<th>' . $a_user->name . '</th>';
           }
           $r .= "</tr></thead><tbody>";
           if (!empty($entities)) {
               for ($i = 0; $i < $count; $i++) {
                   $entity = $entities[$i + ($page - 1) * $options['loctoolsPageSize']];
                   // only assign parent locations.
                   $r .= '<tr><td class="freeze-first-col">' . $entity["name"] . '</td>';
                   $defaultuserids = iform_loctools_getusers($node, $entity["id"]);
                   foreach ($userlist as $uid => $a_user) {
                       $r .= '<td><input type="hidden" name="location:' . $entity["id"] . ':' . $uid . '" value="0"><input type="checkbox" name="location:' . $entity["id"] . ':' . $uid . (in_array($uid, $defaultuserids) ? '" checked="checked"' : '"') . ' value="1"></td>';
                   }
                   $r .= "</tr>";
               }
           }
           $r .= "<tbody></table></div></div>\n";
           // build pager outside scrollable table.
           $numEachSide = 5;
           if ($pages > 1) {
               $path = iform_mnhnl_getReloadPath();
               $path .= (strpos($path, '?') === false ? '?' : '&') . 'page=';
               $r .= "<div class=\"pager ui-helper-clearfix\">";
               if ($page == 1) {
                   $r .= '<span class="ui-state-disabled pager-button">1</span>';
               } else {
                   $r .= '<a class="pager-button" href="' . $path . '1" rel="nofollow">1</a>';
               }
               if ($page - $numEachSide > 2) {
                   $r .= '...';
               }
               for ($i = max(2, $page - $numEachSide); $i <= min($pages - 1, $page + $numEachSide); $i++) {
                   if ($page == $i) {
                       $r .= ' <span class="ui-state-disabled pager-button">' . $i . '</span> ';
                   } else {
                       $r .= '<a class="pager-button" href="' . $path . $i . '" rel="nofollow">' . $i . '</a>';
                   }
               }
               if ($page + $numEachSide < $pages - 1) {
                   $r .= '...';
               }
               if ($page == $pages) {
                   $r .= '<span class="ui-state-disabled pager-button">' . $pages . '</span>';
               } else {
                   $r .= '<a class="pager-button" href="' . $path . $pages . '" rel="nofollow">' . $pages . '</a>';
               }
               $r .= "</div>";
           }
           $r .= '</table><input type="submit" class="default-button" value="' . lang::get('Save Location Allocations') . '" /></form></div>';
       }
       // Add content to extra tabs that derived classes may have added
       if (method_exists(self::$called_class, 'getExtraGridModeTabs')) {
           $r .= call_user_func(array(self::$called_class, 'getExtraGridModeTabs'), true, $auth['read'], $args, $attributes);
       }
       // Close tabs div if present
       if (count($tabs) > 1) {
           $r .= "</div>";
       }
       return $r;
   }
Ejemplo n.º 4
0
function iform_mnhnl_addCancelButton($interface = 'tabs')
{
    switch ($interface) {
        case 'wizard':
            data_entry_helper::$javascript .= "\njQuery('<div class=\"ui-widget-content ui-state-default ui-corner-all indicia-button tab-cancel\"><span><a href=\"" . iform_mnhnl_getReloadPath() . "\">" . lang::get('LANG_Cancel') . "</a></span></div>').appendTo('.buttons');\n";
            break;
        default:
            data_entry_helper::$javascript .= "\njQuery('<a href=\"" . iform_mnhnl_getReloadPath() . "\"><input type=\"button\" name=\"cancel\" value=\"" . lang::get('LANG_Cancel') . "\" /></a>').appendTo('#controls > div');\n";
            break;
    }
}
Ejemplo n.º 5
0
 protected static function getSampleListGrid($args, $node, $auth, $attributes)
 {
     global $user;
     if ($user->uid === 0) {
         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 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 Username sampleattribute associated with it so records can be tagged against their creator.');
     }
     $villageAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Village');
     if (!$villageAttr) {
         $villageAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'VillageDD');
     }
     if (!$villageAttr) {
         return lang::get('This form must be used with a survey that has either the Village or VillageDD location attributes associated with it.');
     }
     $communeAttr = iform_mnhnl_getAttrID($auth, $args, 'location', 'Commune');
     if (!$communeAttr) {
         return lang::get('This form must be used with a survey that has the Commune location attribute associated with it.');
     }
     $reportName = $args['grid_report'];
     if (method_exists(get_called_class(), 'getSampleListGridPreamble')) {
         $r = call_user_func(array(get_called_class(), 'getSampleListGridPreamble'));
     } else {
         $r = '';
     }
     $isAdmin = isset($args['edit_permission']) && $args['edit_permission'] != "" && user_access($args['edit_permission']);
     $isExpert = isset($args['ro_permission']) && $args['ro_permission'] != "" && user_access($args['ro_permission']);
     $extraparams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'username_attr_id' => $usernameAttr, 'village_attr_id' => $villageAttr, 'commune_attr_id' => $communeAttr);
     if ($isAdmin || $isExpert) {
         $extraparams['userID'] = -1;
     } else {
         $extraparams['userID'] = $user->uid;
     }
     $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' => $args['grid_num_rows'], 'autoParamsForm' => true, 'extraParams' => $extraparams));
     $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>\n<div style=\"display:none\" />\n    <form id=\"form-delete-survey\" action=\"" . iform_mnhnl_getReloadPath() . "\" method=\"POST\">" . parent::$auth['write'] . "\n       <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n       <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n       <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n       <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n    </form>\n</div>";
     if (!(function_exists('hostsite_get_user_field') && data_entry_helper::$entity_to_load['sample:created_by_id'] != 1 && data_entry_helper::$entity_to_load['sample:created_by_id'] !== ($userID = hostsite_get_user_field('indicia_user_id')))) {
         $userID = 1;
     }
     data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n  jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n            \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n            \"&callback=?\", function(data) {\n      if (data.length>0) {\n        if(" . ($isExpert ? 0 : 1) . " || data[0].created_by_id == " . $userID . "){\n          if(confirm(\"" . lang::get('Are you sure you wish to delete survey') . " \"+sampleID+\"?\")){\n            jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n            jQuery('#form-delete-survey').submit();\n          }\n        } else\n          alert(\"" . lang::get('You do not have permissions to delete survey') . " \"+sampleID+\". " . lang::get('You only have read only permissions on this survey.') . "\");\n      }\n  });\n};";
     return $r;
 }
Ejemplo n.º 6
0
    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', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false);
        if (!$userIdAttr) {
            return lang::get('getSampleListGrid function: 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.');
        }
        $extraParams = array('survey_id' => $args['survey_id'], 'userID_attr_id' => $userIdAttr, 'userID' => user_access($args['edit_permission']) ? -1 : $user->uid);
        // use -1 if admin - non logged in will not get this far.
        $userNameAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', 'CMS Username', isset($args['sample_method_id']) && $args['sample_method_id'] != "" ? $args['sample_method_id'] : false);
        if ($userNameAttr) {
            $extraParams['userName_attr_id'] = $userNameAttr;
        }
        if (isset($args['targetSpeciesAttr']) && $args['targetSpeciesAttr'] != "") {
            $targetSpeciesIdAttr = iform_mnhnl_getAttrID($auth, $args, 'sample', $args['targetSpeciesAttr'], $args['target_species_subsample_method_id']);
            $extraParams['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 'Parent':
                        $custom_terms['location name'] = lang::get('location name');
                        break;
                    case 'Shape':
                        $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' => $args['grid_report'], '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>';
        $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>';
        data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n  if(confirm(\"Are you sure you wish to delete survey \"+sampleID)){\n    jQuery.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/data/sample/\"+sampleID +\n            \"?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n            \"&callback=?\", function(data) {\n        if (data.length>0) {\n          jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n          jQuery('#form-delete-survey').submit();\n  }});\n  };\n};";
        return $r;
    }