aboutsummaryrefslogtreecommitdiffstats
path: root/search.php
diff options
context:
space:
mode:
authorjwangen <jwangen>2002-10-23 07:22:44 +0000
committerjwangen <jwangen>2002-10-23 07:22:44 +0000
commitdc6ed70273afd85fd0191d81965ea5969ec291a5 (patch)
tree10c558e2c05ac54a540665acce26b575a2770663 /search.php
parentcb6775d79a91c2dc7d8c8c21e6a0c84dbcb86948 (diff)
downloadphpicalendar-dc6ed70273afd85fd0191d81965ea5969ec291a5.tar.gz
phpicalendar-dc6ed70273afd85fd0191d81965ea5969ec291a5.tar.bz2
phpicalendar-dc6ed70273afd85fd0191d81965ea5969ec291a5.zip
Modified search.php, still not complete
Diffstat (limited to 'search.php')
-rw-r--r--search.php151
1 files changed, 121 insertions, 30 deletions
diff --git a/search.php b/search.php
index 24ade80..d31d461 100644
--- a/search.php
+++ b/search.php
@@ -2,31 +2,128 @@
include('./functions/ical_parser.php');
-$search_string = 'final';
-$search_arr = explode(' ', $search_string);
+// takes a boolean search and a string. Returns an array with
+// [0] = True/False and [1] = formatted search string
+function search_boolean($needle,$haystack) {
+ // init arrays
+ $and_arr = array();
+ $or_arr = array();
+ $not_arr = array();
+ $or_str_arr = array();
-function array_in($string,$arr) {
- foreach($arr as $s) {
- if (eregi($s,$string) == false) {
- return false;
+ // compare lowercase versions of the strings
+ $haystack = strtolower($haystack);
+ $needle = strtolower($needle);
+
+ // clean up search string
+ $needle = str_replace(' and ', ' ', $needle);
+ $needle = ereg_replace('[[:space:]]+',' ', $needle);
+
+ // start out with an AND array of all the items
+ $and_arr = explode(' ', $needle);
+ $count = count($and_arr);
+ $j = 0;
+
+ // build an OR array from the items in AND
+ for($i=0;$i<$count;$i++) {
+ if ($i != 0 && $and_arr[$i] == 'or') {
+ while ($and_arr[$i] == 'or') {
+ $or_arr[$j][] = $and_arr[$i-1];
+ unset($and_arr[$i], $and_arr[$i-1]);
+ $i += 2;
+ }
+ if (isset($and_arr[$i-1])) {
+ $or_arr[$j][] = $and_arr[$i-1];
+ unset($and_arr[$i-1]);
+ }
+ $or_str_arr[$j] = implode('</b> OR <b>', $or_arr[$j]);
+ $j++;
+ }
+ }
+
+ // build a NOT array from the items in AND
+ foreach($and_arr as $key => $val) {
+ if (substr($val,0,1) == '-') {
+ $not_arr[] = substr($val,1);
+ unset($and_arr[$key]);
+ } elseif(substr($val,0,1) == '+') {
+ $and_arr[] = substr($val,1);
+ unset($and_arr[$key]);
+ }
+ }
+
+ // prepare our formatted search string
+ if (count($and_arr) > 1) {
+ $final_str_arr[] = implode('</b> AND <b>', $and_arr);
+ } elseif (isset($and_arr[0]) && $and_arr[0] != '') {
+ $final_str_arr[] = $and_arr[0];
+ }
+
+ if (count($or_str_arr) > 1) {
+ $final_str_arr[] = implode('</b> AND <b>', $or_str_arr);
+ } elseif (isset($or_str_arr[0]) && $or_str_arr[0] != '') {
+ $final_str_arr[] = $or_str_arr[0];
+ }
+
+ if (count($not_arr) > 1) {
+ $final_str_arr[] = '-'.implode('</b> AND <b>-', $not_arr);
+ } elseif (isset($not_arr[0]) && $not_arr[0] != '') {
+ $final_str_arr[] = '-'.$not_arr[0];
+ }
+
+ if (count($final_str_arr) > 1) {
+ $formatted_search = '<b>'.implode('</b> AND <b>', $final_str_arr).'</b>';
+ } else {
+ $formatted_search = '<b>'.$final_str_arr[0].'</b>';
+ }
+
+ // check against the NOT
+ foreach($not_arr as $s) {
+ if (ereg($s, $haystack) == true) {
+ return array(false,$formatted_search);
}
}
- return true;
+
+ // check against the AND
+ foreach($and_arr as $s) {
+ if (ereg($s,$haystack) == false) {
+ return array(false,$formatted_search);
+ }
+ }
+
+ // check against the OR
+ foreach($or_arr as $or) {
+ $is_false = true;
+ foreach($or as $s) {
+ if (ereg($s,$haystack) == true) {
+ $is_false = false;
+ break;
+ }
+ }
+ if ($is_false) return array(false,$formatted_search);
+ }
+
+ // if we haven't returned false, then we return true
+ return array(true,$formatted_search);
}
-function search($find_arr) {
- global $master_array;
- if (isset($master_array) && is_array($master_array)) {
- foreach($master_array as $date_key => $date) {
- if (is_array($date)) {
- foreach($date as $time_key => $time) {
- if (is_array($time)) {
- foreach ($time as $event_key => $event) {
- if (is_array($event)) {
- if (array_in($event['description'],$find_arr) || array_in($event['event_text'],$find_arr)) {
- $tmp_arr = $event;
- $tmp_arr['date'] = $date_key;
- $retarr[] = $tmp_arr;
- }
+
+$search_string = 'final japan';
+
+if (isset($master_array) && is_array($master_array)) {
+ foreach($master_array as $date_key_tmp => $date_tmp) {
+ if (is_array($date_tmp)) {
+ foreach($date_tmp as $time_tmp) {
+ if (is_array($time_tmp)) {
+ foreach ($time_tmp as $event_tmp) {
+ if (is_array($event_tmp)) {
+ $results1 = search_boolean($search_string,$event_tmp['event_text']);
+ $formatted_search = $results1[1];
+ if (!$results1[0]) {
+ $results2 = search_boolean($search_string,$event_tmp['description']);
+ }
+ if ($results1[0] || $results2[0]) {
+ $event_tmp['date'] = $date_key_tmp;
+ $the_arr[] = $event_tmp;
}
}
}
@@ -34,11 +131,8 @@ function search($find_arr) {
}
}
}
- return $retarr;
}
-
-$the_arr = search($search_arr);
-
+
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
@@ -55,13 +149,10 @@ $the_arr = search($search_arr);
<table border="0" width="737" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="calborder">
<tr>
<td align="left" valign="top" width="1%" class="sideback"><?php echo "<a class=\"psf\" href=\"month.php?cal=$cal&getdate=$prev_day\"><img src=\"styles/$style_sheet/left_arrows.gif\" alt=\"right\" border=\"0\" align=\"left\"></a>"; ?></td>
- <td align="center" class="sideback"><font class="G10B"><b><?php print (localizeDate ($dateFormat_day, strtotime($getdate))); ?></b></font></td>
+ <td align="center" class="sideback"><font class="G10BOLD"><?php print "Search Results" ?></font></td>
<td align="right" valign="top" width="1%" class="sideback"><?php echo "<a class=\"psf\" href=\"month.php?cal=$cal&getdate=$next_day\"><img src=\"styles/$style_sheet/right_arrows.gif\" alt=\"right\" border=\"0\" align=\"right\"></a>"; ?></td>
</tr>
<tr>
- <td colspan="3"><img src="images/spacer.gif" width="1" height="5"></td>
- </tr>
- <tr>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
@@ -69,7 +160,7 @@ $the_arr = search($search_arr);
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" width="160" class="montheventtop"><?php echo "<img src=\"images/spacer.gif\" alt=\"right\" width=\"16\" height=\"20\" border=\"0\" align=\"left\"></a>"; ?></td>
- <td align="center" class="montheventtop" width="417" nowrap><font class="G10BOLD"><?php echo "Search Results"; ?></font></td>
+ <td align="center" class="montheventtop" width="417" nowrap><font class="G10B"><?php echo 'Search: '.$formatted_search; ?></font></td>
<td align="right" valign="top" width="160" class="montheventtop"><?php echo "<img src=\"images/spacer.gif\" alt=\"right\" width=\"16\" height=\"20\" border=\"0\" align=\"right\"></a>"; ?></td>
</tr>
<tr>

© 2014-2024 Faster IT GmbH | imprint | privacy policy