public function uploadCsvList($hasHeader, $thesId)
 {
     set_time_limit(300);
     ini_set("max_input_time", 300);
     ini_set('auto_detect_line_endings', true);
     $successCnt = 0;
     $fh = fopen($_FILES['uploadfile']['tmp_name'], 'r') or die("Can't open file. File may be too large. Try uploading file in sections.");
     $headerArr = array();
     if ($hasHeader) {
         $headerData = fgetcsv($fh);
         foreach ($headerData as $k => $v) {
             $vStr = strtolower($v);
             $vStr = str_replace(array(" ", ".", "_"), "", $vStr);
             $vStr = str_replace(array("scientificnamewithauthor", "scientificname", "taxa", "species", "taxon"), "sciname", $vStr);
             $headerArr[$vStr] = $k;
         }
     } else {
         $headerArr["sciname"] = 0;
     }
     if (array_key_exists("sciname", $headerArr)) {
         $cnt = 0;
         ob_flush();
         flush();
         $taxUtil = new TaxonomyUtilities();
         while ($valueArr = fgetcsv($fh)) {
             $tid = 0;
             $rankId = 0;
             $sciName = "";
             $family = "";
             $sciNameStr = $this->cleanInStr($valueArr[$headerArr["sciname"]]);
             $noteStr = '';
             if ($sciNameStr) {
                 $sciNameArr = $taxUtil->parseSciName($sciNameStr);
                 //Check name is in taxa table and grab tid if it is
                 $sql = "";
                 if ($thesId && is_numeric($thesId)) {
                     $sql = 'SELECT t2.tid, ts.family, t2.rankid ' . 'FROM (taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid) ' . 'INNER JOIN taxa t2 ON ts.tidaccepted = t2.tid ' . 'WHERE (ts.taxauthid = ' . $thesId . ') ';
                 } else {
                     $sql = 'SELECT t.tid, ts.family, t.rankid ' . 'FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid ' . 'WHERE ts.taxauthid = 1 ';
                 }
                 $cleanSciName = $this->encodeString($sciNameArr['sciname']);
                 $sql .= 'AND (t.sciname IN("' . $sciNameStr . '"' . ($cleanSciName ? ',"' . $cleanSciName . '"' : '') . '))';
                 $rs = $this->conn->query($sql);
                 if ($rs) {
                     if ($row = $rs->fetch_object()) {
                         $tid = $row->tid;
                         $family = $row->family;
                         $rankId = $row->rankid;
                     }
                     $rs->free();
                 }
                 //Load taxon into checklist
                 if ($tid) {
                     if ($rankId >= 180) {
                         $sqlInsert = '';
                         $sqlValues = '';
                         if (array_key_exists('family', $headerArr) && ($valueArr[$headerArr['family']] && strtolower($family) != strtolower($valueArr[$headerArr['family']]))) {
                             $sqlInsert .= ',familyoverride';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['family']]) . '"';
                         }
                         if (array_key_exists('habitat', $headerArr) && $valueArr[$headerArr['habitat']]) {
                             $sqlInsert .= ',habitat';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['habitat']]) . '"';
                         }
                         if (array_key_exists('abundance', $headerArr) && $valueArr[$headerArr['abundance']]) {
                             $sqlInsert .= ',abundance';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['abundance']]) . '"';
                         }
                         if ($noteStr || array_key_exists('notes', $headerArr) && $valueArr[$headerArr['notes']]) {
                             if (array_key_exists('notes', $headerArr) && $valueArr[$headerArr['notes']]) {
                                 if ($noteStr) {
                                     $noteStr .= '; ';
                                 }
                                 $noteStr .= $valueArr[$headerArr['notes']];
                             }
                             $sqlInsert .= ',notes';
                             $sqlValues .= ',"' . $this->cleanInStr($noteStr) . '"';
                         }
                         $sql = 'INSERT INTO fmchklsttaxalink (tid,clid' . $sqlInsert . ') VALUES (' . $tid . ', ' . $this->clid . $sqlValues . ')';
                         //echo $sql;
                         if ($this->conn->query($sql)) {
                             $successCnt++;
                         } else {
                             $this->errorArr[] = $sciNameStr . " (TID = {$tid}) failed to load<br />Error msg: " . $this->conn->error;
                             //echo $sql."<br />";
                         }
                     } else {
                         $this->errorArr[] = $sciNameStr . " failed to load (taxon must be of genus, species, or infraspecific ranking)";
                     }
                 } else {
                     $this->problemTaxa[] = $cleanSciName;
                     //$statusStr = $sciNameStr." failed to load (misspelled or not yet in taxonomic thesaurus)";
                     //$failCnt++;
                 }
                 $cnt++;
                 if ($cnt % 500 == 0) {
                     echo '<li style="margin-left:10px;">' . $cnt . ' taxa loaded</li>';
                     ob_flush();
                     flush();
                 }
             }
         }
         fclose($fh);
         if ($cnt && $this->clMeta['type'] == 'rarespp') {
             $occUtil = new OccurrenceUtilities();
             $occUtil->protectStateRareSpecies();
         }
     } else {
         $this->errorStr = 'ERROR: unable to locate scientific name column';
     }
     return $successCnt;
 }