 |
Travis Doering and Lori Collins MESOAMERICAN THREE-DIMENSIONAL IMAGING DATABASE © 2007 Travis Doering and Lori Collins |
 |
include("dbinfo.inc");
##include database info and connect to database
$db=mysql_connect(localhost,$username,$password);
@mysql_select_db($database,$db) or die( "Unable to select database");
mysql_set_charset('utf8', $db);
//initialize variables
$search="";
$rowstart=0;
$where=="";
##if search word does not exist retrieve it from search page else use the one passed in URL
if(!$_GET['_allSearch']) {
$search=htmlspecialchars($POST['_allSearch'],ENT_QUOTES);
} else {
$search=htmlspecialchars($_GET['_allSearch'],ENT_QUOTES);
}
$search = mysql_real_escape_string($search);
$site=htmlspecialchars($_GET['origin_site'],ENT_QUOTES);
$site = mysql_real_escape_string($site);
//echo $search;
if(!$_GET['geographicarea']) {
$geographicarea=htmlspecialchars($POST['geographicarea'],ENT_QUOTES);
} else {
$geographicarea=htmlspecialchars($_GET['geographicarea'],ENT_QUOTES);
}
$geographicarea = mysql_real_escape_string($geographicarea);
if(!$_GET['culture']) {
$culture=htmlspecialchars($POST['culture'],ENT_QUOTES);
} else {
$culture=htmlspecialchars($_GET['culture'],ENT_QUOTES);
}
$culture = mysql_real_escape_string($culture);
if($chron=="") {
$chron = htmlspecialchars($_GET['chronological'],ENT_QUOTES);
} else {
$chron = $chron . htmlspecialchars($_GET['chronological'],ENT_QUOTES);
}
//$chron = mysql_real_escape_string($chron);
if (@array_count_values($chron)) {
// $icons = explode('|',$icons);
// } else {
$chron = implode(' and ', $chron);
}
##initialize
$display_number = 9; //number of table rows it pulls from the database.
##if rowstart not passed in URL use zero else retrieve rowstart
if(!$_GET['rowstart']) {
$rowstart=htmlspecialchars($_POST['rowstart'],ENT_QUOTES);
} else {
$rowstart=htmlspecialchars($_GET['rowstart'],ENT_QUOTES);
}
if(!$rowstart) { $rowstart = 0; }
if ($_GET['pagenum']) {
$rowstart=((htmlentities($_GET['pagenum'])-1)*$display_number);
}
//check for wildcards, if exist change to %
if($search) {
if(strstr($search,'*'))
{
$search = str_replace("*","%",$search);
}
}
//echo $search;
//echo ' ';
##split search words for 'and' and 'or'
if($search) {
if(strstr($search,' and ') || strstr($search,' or ')) {
if(strstr($search,' and ')) {
$arr=split(' and ',$search);
while(list($key,$value) = each($arr)) {
if($where=="") {
$where="WHERE (id_number like '%$value%' or artifact_name like '%$value%' or origin_site like '%$value%' or artifact_type like '%$value%' or artifact_medium like '%$value%' or location like '%$value%' or notes like '%$value%' or chron_era like '%$value%' or chron_specific like '%$value%' or collaborators like '%$value%' or site_info like '%$value%')";
} else {
$where=$where . " and (id_number like '%$value%' or artifact_name like '%$value%' or origin_site like '%$value%' or artifact_type like '%$value%' or artifact_medium like '%$value%' or location like '%$value%' or notes like '%$value%' or chron_era like '%$value%' or chron_specific like '%$value%' or collaborators like '%$value%' or site_info like '%$value%')";
} //end where==""
}//end while
} //end if strstr($search,' and ')
if(strstr($search,' or ')) {
$arr=split(' or ',$search);
while(list($key,$value) = each($arr)) {
if($srch_cnt>0) {
if($where=="") {
$where="WHERE (id_number like '%$value%' or artifact_name like '%$value%' or origin_site like '%$value%' or artifact_type like '%$value%' or artifact_medium like '%$value%' or location like '%$value%' or notes like '%$value%' or chron_era like '%$value%' or chron_specific like '%$value%' or collaborators like '%$value%' or site_info like '%$value%')";
} else {
$where=$where . " or (id_number like '%$value%' or artifact_name like '%$value%' or origin_site like '%$value%' or artifact_type like '%$value%' or artifact_medium like '%$value%' or location like '%$value%' or notes like '%$value%' or chron_era like '%$value%' or chron_specific like '%$value%' or collaborators like '%$value%' or site_info like '%$value%')";
} //end where==""
}// end $srch_cnt>0
}//end while
} // end strstr($search,' or ')
} else {
if($where =="") {
$where="WHERE (id_number like '%$search%' or artifact_name like '%$search%' or origin_site like '%$search%' or artifact_type like '%$search%' or artifact_medium like '%$search%' or location like '%$search%' or notes like '%$search%' or chron_era like '%$search%' or chron_specific like '%$search%' or collaborators like '%$search%' or site_info like '%$search%')";
} else {
$where = $where . " and (id_number like '%$search%' or artifact_name like '%$search%' or origin_site like '%$search%' or artifact_type like '%$search%' or artifact_medium like '%$search%' or location like '%$search%' or notes like '%$search%' or chron_era like '%$search%' or chron_specific like '%$search%' or collaborators like '%$search%' or site_info like '%$search%')";
} //end if($where =="")
} //end if(strstr($search,' and ') || strstr($search,' or '))
} else {
if($where =="") {
$where="WHERE (id_number like '%$search%' or artifact_name like '%$search%' or origin_site like '%$search%' or artifact_type like '%$search%' or artifact_medium like '%$search%' or location like '%$search%' or notes like '%$search%' or chron_era like '%$search%' or chron_specific like '%$search%' or collaborators like '%$search%' or site_info like '%$search%')";
} else {
$where = $where . " and (id_number like '%$search%' or artifact_name like '%$search%' or origin_site like '%$search%' or artifact_type like '%$search%' or artifact_medium like '%$search%' or location like '%$search%' or notes like '%$search%' or chron_era like '%$search%' or chron_specific like '%$search%' or collaborators like '%$search%' or site_info like '%$search%')";
} //end if($where =="")
} //end if $search
//if($icons) {
if (@array_count_values($chron) ) {
//echo ' ' . $icons[0];
$cnt_chron = count($chron);
//echo $cnt_chron;
if($chron[0]) {
for($w=0; $w<$cnt_chron; $w++) {
//echo 'inside icons array';
if($chron_elements=="") {
$chron_elements = $chron[$w];
} else {
$chron_elements = $chron_elements . " and " . $chron[$w];
}
if(strstr($chron[$w],' or ')) {
$arr=split(' or ',$chron[$w]);
while(list($key,$value) = each($arr)) {
if($where =="") {
$where = "where (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} else {
$where = $where . " or chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} //end if($where =="")
} //while(list($key,$value) = each($arr))
} else {
//echo 'inside else';
if($where =="") {
$where = "where (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} else {
$where = $where . " and (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} //end if($where =="")
}//end if(strstr($chron[$w],' or '))
}//end for($w=0; $w<$cnt_chron; $w++)
} //end if($chron[0])
} else {
$chron_elements = "";
if(strstr($chron,' and ')) {
if($chron_elements=="") {
$chron_elements = $chron;
} else {
$chronelements = $chron_elements . " and " . $chron;
} //end if($chron_elements=="")
$arr=split(' and ',$chron);
while(list($key,$value) = each($arr)) {
if($where =="") {
$where = "where (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} else {
$where = $where . " and (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} //end if($where =="")
}//while(list($key,$value) = each($arr))
} else if(strstr($chron,' or ')) {
if($chron_elements=="") {
$chron_elements = $chron;
} else {
$chron_elements = $chron_elements . " or " . $chron;
} //end if($chron_elements=="")
$arr=split(' or ',$chron);
while(list($key,$value) = each($arr)) {
if($where =="") {
$where = "where (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} else {
$where = $where . " and (chron_specific like '%$value%' or chron_specific like '%$value %' or chron_era like '%$value%' or chron_era like '%$value %')";
} //end if($where =="")
}//while(list($key,$value) = each($arr))
} else {
if($chron) {
if($chron_elements=="") {
$chron_elements = $chron;
} else {
$chron_elements = $chron_elements . " or " . $chron;
} //end if($chron_elements=="")
if($where =="") {
$where = "where (chron_specific like '%$chron%' or chron_specific like '%$chron %' or chron_era like '%$chron%' or chron_era like '%$chron %')";
} else {
$where = $where . " and (chron_specific like '%$chron%' or chron_specific like '%$chron %' or chron_era like '%$chron%' or chron_era like '%$chron %')";
} //end if($where =="")
} //end if($chron)
} //end if(strstr($chron,' and '))
} //end if (@array_count_values($chron) )
if($culture) {
if($where =="") {
$where = "where (culture like '%$culture%' or culture like '%$culture %')";
} else {
$where = $where . " and (culture like '%$culture%' or culture like '%$culture %')";
}
}
if($geographicarea) {
if($where =="") {
$where = "where (geographicarea like '%$geographicarea%' or geographicarea like '%$geographicarea %')";
} else {
$where = $where . " and (geographicarea like '%$geographicarea%' or geographicarea like '%$geographicarea %')";
}
}
if($site) {
if($where =="") {
$where = "where (origin_site like '%$site%' or origin_site like '%$site %')";
} else {
$where = $where . " and (origin_site like '%$site%' or origin_site like '%$site %')";
}
}
//only display the published items
if($where =="") {
$where = "where publish = 1";
} else {
$where = $where . " and publish = 1";
}
//geographicarea, culture and chron not used at this time
//if($search || $site) {
#query db with new search term
$result = mysql_query("select * from 3dproject $where order by id_number, artifact_type ASC limit $rowstart,$display_number");
$sql = "select * from 3dproject $where order by id_number, artifact_type ASC limit $rowstart,$display_number";
//echo $sql;
$result2 = mysql_query("select * from 3dproject $where order by id_number, artifact_type ASC");
if(@mysql_num_rows($result2)==0) {
$result_cnt = 0;
} else {
$result_cnt = mysql_num_rows($result2);
}
if(@mysql_num_rows($result)==0) {
$record_cnt = 0;
} else {
$record_cnt = mysql_num_rows($result);
}
##determine number of pages
if (!isset($num_pages)) {
if($result_cnt > $display_number) {
$num_pages = ceil($result_cnt/$display_number);
} elseif($result_cnt > 0) {
$num_pages = 1;
}
} else {
$start=0;
}
$a = $rowstart + ($display_number) ;
if ($a > $result_cnt) { $a = $result_cnt ; }
$b = $rowstart + 1 ;
echo '';
echo 'Click on any image to view in high resolution. | ';
echo '';
echo "Click the checkboxes and the 'review selections' button to view images with captions in a printable format. | ";
echo ' |