Author Topic: [MOD] Search between specifyed date  (Read 67240 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« on: June 10, 2003, 08:54:50 PM »
Reqested several times mod, that will let visitors search between date they select. (uses dropdown options for day, month, year)


-------- Files to edit ------------
/search.php
/templates/<yourtemplate>/search_form.html
/lang/<yourlanguage>/main.php



-------- Installation -------------

Step 1.
Open /search.php
Find:
Code: [Select]
include(ROOT_PATH.'includes/search_utils.php');Add after:
Code: [Select]
$year_default = 2000;
$year_now = date("Y", time());
$year_start = (isset($HTTP_POST_VARS['year_start']) ) ? intval($HTTP_POST_VARS['year_start']) : ((isset($HTTP_GET_VARS['year_start'])) ? intval($HTTP_GET_VARS['year_start']) : $year_default);
$year_end = (isset($HTTP_POST_VARS['year_end']) ) ? intval($HTTP_POST_VARS['year_end']) : ((isset($HTTP_GET_VARS['year_end'])) ? intval($HTTP_GET_VARS['year_end']) : $year_now);
$month_start = (isset($HTTP_POST_VARS['month_start']) ) ? intval($HTTP_POST_VARS['month_start']) : ((isset($HTTP_GET_VARS['month_start'])) ? intval($HTTP_GET_VARS['month_start']) : 1);
$month_end = (isset($HTTP_POST_VARS['month_end']) ) ? intval($HTTP_POST_VARS['month_end']) : ((isset($HTTP_GET_VARS['month_end'])) ? intval($HTTP_GET_VARS['month_end']) : date("n", time()));
$day_start = (isset($HTTP_POST_VARS['day_start']) ) ? intval($HTTP_POST_VARS['day_start']) : ((isset($HTTP_GET_VARS['day_start'])) ? intval($HTTP_GET_VARS['day_start']) : 1);
$day_end = (isset($HTTP_POST_VARS['day_end']) ) ? intval($HTTP_POST_VARS['day_end']) : ((isset($HTTP_GET_VARS['day_end'])) ? intval($HTTP_GET_VARS['day_end']) : date("j", time()));
$date_start = mktime(0,0,0,$month_start,$day_start,$year_start);
$date_end = mktime(23,59,59,$month_end,$day_end,$year_end);

Step 1.2.
Find:
Code: [Select]
     $sql = "SELECT m.image_id
              FROM ".WORDLIST_TABLE." w, ".WORDMATCH_TABLE." m
              WHERE w.word_text LIKE '".addslashes(str_replace("*", "%", $split_words[$i]))."'
              AND m.word_id = w.word_id
              $match_field_sql";
Replace with:
Code: [Select]
     $sql = "SELECT m.image_id, i.image_date
              FROM ".WORDLIST_TABLE." w, ".WORDMATCH_TABLE." m
              LEFT JOIN ".IMAGES_TABLE." i ON (m.image_id = i.image_id)
              WHERE w.word_text LIKE '".addslashes(str_replace("*", "%", $split_words[$i]))."'
              AND m.word_id = w.word_id AND i.image_date >= ".$date_start." AND i.image_date <= ".$date_end."
              $match_field_sql";

Step 1.3.
Find:
Code: [Select]
 $site_template->register_vars(array(
    "search_keywords" => htmlspecialchars(stripslashes($org_search_keywords)),
Replace with:
Code: [Select]
 function date_select($start, $end, $now, $text_array = ""){
    $options = "";
    $start = ($start) ? $start : $start + 1;
    for ($i = $start; $i <= $end; $i++){
      $select = ($i == $now) ? " selected" : "";
      $options .= "<option value=\"".$i."\"".$select.">".(($text_array) ? $text_array[$i - 1] : $i)."</option>";
    }
    return $options;
  }

  $site_template->register_vars(array(
    "search_keywords" => stripslashes($org_search_keywords),
    "year_start" => date_select($year_default, $year_now, $year_start),
    "year_end" => date_select($year_default, $year_now, $year_end),
    "month_start" => date_select(1, 12, $month_start, $lang['month_array']),
    "month_end" => date_select(1, 12, $month_end, $lang['month_array']),
    "day_start" => date_select(1, 31, $day_start),
    "day_end" => date_select(1, 31, $day_end),
    "lang_search_date" => $lang['search_date'],
    "lang_search_date_start" => $lang['search_start'],
    "lang_search_date_end" => $lang['search_end'],


Step 2.
Open /templates/<yourtemplate>/search_form.html
Add this:
Code: [Select]
<tr class="row2">
<td><b>{lang_search_date}:</b></td>
<td>
{lang_search_date_start}<br />
<select name="day_start" class="select">{day_start}</select>
<select name="month_start" class="select">{month_start}</select>
<select name="year_start" class="select">{year_start}</select><br /><br />
{lang_search_date_end}<br />
<select name="day_end" class="select">{day_end}</select>
<select name="month_end" class="select">{month_end}</select>
<select name="year_end" class="select">{year_end}</select>
</td>
</tr>


Step 3.
Open /lang/<yourlanguage>/main.php
Add at the end, just before closing ?>
Code: [Select]
$lang['month_array'] = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$lang['search_date'] = "Search between";
$lang['search_start'] = "Start";
$lang['search_end'] = "End";


NOTE:
- If u dont want display name for each month instead of number (1 to 12), then just comment $lang['month_array'] in Step 3.
- U can change minimum year in dropdown: $year_default = 2000; from Step 1.

P.S. I know, design and text - sux, and would really appretiate it if somebody help me with that ;) :D
« Last Edit: August 30, 2010, 02:03:50 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[MOD] Search between specifyed date
« Reply #1 on: June 10, 2003, 09:37:15 PM »
hey v@no this is awesome :)
just what i needed

but i think there's some prob on it cause i went to your demo and tryed to do a search and no results were found, and i've tried many dates

is it me?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« Reply #2 on: June 10, 2003, 09:38:21 PM »
what were u searching?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[MOD] Search between specifyed date
« Reply #3 on: June 10, 2003, 11:12:41 PM »
well i wanted to see all images that were submitted in a specified period of time, isn't that what this can do? or does this only search all images with specified keywords in the mentioned period?

if so, how can i put this working like the 1st way?
thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« Reply #4 on: June 10, 2003, 11:19:33 PM »
Quote from: Bomba
well i wanted to see all images that were submitted in a specified period of time, isn't that what this can do? or does this only search all images with specified keywords in the mentioned period?

if so, how can i put this working like the 1st way?
thanks
maybe I should have name it as "limit images by date" or something...
yes, it will search from keywords, but limit it by date.
use * to search all images (add as many * as set max keyword lenght)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline reson

  • Pre-Newbie
  • Posts: 3
    • View Profile
[MOD] Search between specifyed date
« Reply #5 on: June 16, 2003, 08:19:56 PM »
My error msg........

Fatal error: Call to undefined function: date_select() in /var/www/phpbb/4images/search.php on line 372


 :(

Offline heiko

  • Newbie
  • *
  • Posts: 42
    • View Profile
[MOD] Search between specifyed date
« Reply #6 on: June 16, 2003, 09:48:46 PM »
Quote from: reson
My error msg........

Fatal error: Call to undefined function: date_select() in /var/www/phpbb/4images/search.php on line 372


 :(




Hi V@no...


Where is this function defined :?:

date_select()  


Greetings

Heiko

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« Reply #7 on: June 16, 2003, 09:56:59 PM »
omg  :oops: how did I miss that??? :?
I just changed Step1.3.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline reson

  • Pre-Newbie
  • Posts: 3
    • View Profile
[MOD] Search between specifyed date
« Reply #8 on: June 17, 2003, 10:17:20 AM »
Thank!! ^_^

Offline heiko

  • Newbie
  • *
  • Posts: 42
    • View Profile
Now it works.!!
« Reply #9 on: June 17, 2003, 07:39:18 PM »
Quote from: V@no
omg  :oops: how did I miss that??? :?
I just changed Step1.3.


 :P  thanx ...like ever.. good job...

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
[MOD] Search between specifyed date
« Reply #10 on: June 18, 2003, 06:48:19 PM »
v@no -

i have an original .... /search.php ...  file ...
when i do a search and replace for coding in steps 1.2/1.3 - it does not find the references  :roll:

where does the coding live??  8O

thanx
bruce

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« Reply #11 on: June 18, 2003, 07:27:42 PM »
ah, yes, u are right :ops:
I just fixed it.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[MOD] Search between specifyed date
« Reply #12 on: June 27, 2003, 02:29:14 AM »
i think i've found some kind of bug in the mod...

i installed it on my site today, and now, that is counting as 27 of June, when i search for all my images on the server (***), it doesn't appear the pics that were submitted after the 0am of June 27.

why's that, why doesn't search images that were submitted on the present day?
they all have words with more than 3 letters...
i don't understand it

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Search between specifyed date
« Reply #13 on: June 27, 2003, 11:56:00 AM »
yes, u are right, replace:
Code: [Select]
AND m.word_id = w.word_id AND i.image_date > UNIX_TIMESTAMP('".$date_start."') AND i.image_date < UNIX_TIMESTAMP('".$date_end."')with:
Code: [Select]
AND m.word_id = w.word_id AND i.image_date >= UNIX_TIMESTAMP('".$date_start."') AND i.image_date <= UNIX_TIMESTAMP('".$date_end."')
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[MOD] Search between specifyed date
« Reply #14 on: June 27, 2003, 05:37:02 PM »
hey v@no, are u sure that that's correct?
cause i replaced my code and everything works the same way as before...

here's my changed code:
Code: [Select]
$sql = "SELECT m.image_id, i.image_date
              FROM ".WORDLIST_TABLE." w, ".WORDMATCH_TABLE." m
              LEFT JOIN ".IMAGES_TABLE." i ON (m.image_id = i.image_id)
              WHERE w.word_text LIKE '".addslashes(str_replace("*", "%", $split_words[$i]))."'
              AND m.word_id = w.word_id AND i.image_date >= UNIX_TIMESTAMP('".$date_start."') AND i.image_date < UNIX_TIMESTAMP('".$date_end."')
              $match_field_sql";



edit:

i just noticed that no your step 1.2 it's
Code: [Select]
AND m.word_id = w.word_id AND i.image_date > UNIX_TIMESTAMP('".$date_start."') AND i.image_date < UNIX_TIMESTAMP('".$date_end."')

and now the changed code says that i have to replace this
Code: [Select]
AND m.word_id = w.word_id AND i.image_date > UNIX_TIMESTAMP('".$date_start."') AND i.image_date <= UNIX_TIMESTAMP('".$date_end."')

but as you can see, these codes are not the same just look at this part:
Code: [Select]
AND i.image_date <= UNIX_TIMESTAMP

maybe you posted it wrong
maybe :)