[2] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[57] | 3 | * search.php * |
---|
[2] | 4 | * ------------------- * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[2] | 7 | * * |
---|
[57] | 8 | * $Id: search.php 350 2004-02-05 23:18:05Z z0rglub $ |
---|
| 9 | * * |
---|
[2] | 10 | ***************************************************************************/ |
---|
| 11 | |
---|
| 12 | /*************************************************************************** |
---|
| 13 | * * |
---|
| 14 | * This program is free software; you can redistribute it and/or modify * |
---|
| 15 | * it under the terms of the GNU General Public License as published by * |
---|
| 16 | * the Free Software Foundation; * |
---|
| 17 | * * |
---|
| 18 | ***************************************************************************/ |
---|
| 19 | |
---|
| 20 | //----------------------------------------------------------- personnal include |
---|
| 21 | include_once( './include/init.inc.php' ); |
---|
| 22 | //-------------------------------------------------- access authorization check |
---|
| 23 | check_login_authorization(); |
---|
| 24 | //----------------------------------------------------------------- redirection |
---|
| 25 | $error = array(); |
---|
| 26 | if ( isset( $_POST['search'] ) ) |
---|
| 27 | { |
---|
[17] | 28 | $redirect = true; |
---|
| 29 | $search = array(); |
---|
| 30 | $words = preg_split( '/\s+/', $_POST['search'] ); |
---|
| 31 | foreach ( $words as $i => $word ) { |
---|
| 32 | if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) ) |
---|
| 33 | { |
---|
| 34 | array_push( $search, $word ); |
---|
| 35 | } |
---|
| 36 | else |
---|
| 37 | { |
---|
| 38 | $redirect = false; |
---|
| 39 | array_push( $error, $lang['invalid_search'] ); |
---|
| 40 | break; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | $search = array_unique( $search ); |
---|
| 44 | $search = implode( ',', $search ); |
---|
| 45 | if ( $redirect ) |
---|
[2] | 46 | { |
---|
[17] | 47 | $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode']; |
---|
| 48 | $url = add_session_id( $url, true ); |
---|
[2] | 49 | header( 'Request-URI: '.$url ); |
---|
| 50 | header( 'Content-Location: '.$url ); |
---|
| 51 | header( 'Location: '.$url ); |
---|
| 52 | exit(); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | //----------------------------------------------------- template initialization |
---|
[290] | 56 | // |
---|
| 57 | // Start output of page |
---|
| 58 | // |
---|
| 59 | $title= $lang['search_title']; |
---|
| 60 | include('include/page_header.php'); |
---|
| 61 | |
---|
[19] | 62 | $handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' ); |
---|
| 63 | initialize_template(); |
---|
| 64 | $tpl = array( 'search_title','search_return_main_page','submit', |
---|
| 65 | 'search_comments' ); |
---|
| 66 | templatize_array( $tpl, 'lang', $handle ); |
---|
[2] | 67 | //----------------------------------------------------------------- form action |
---|
| 68 | $vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) ); |
---|
| 69 | //-------------------------------------------------------------- errors display |
---|
| 70 | if ( sizeof( $error ) != 0 ) |
---|
| 71 | { |
---|
| 72 | $vtp->addSession( $handle, 'errors' ); |
---|
| 73 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
| 74 | { |
---|
| 75 | $vtp->addSession( $handle, 'li' ); |
---|
| 76 | $vtp->setVar( $handle, 'li.li', $error[$i] ); |
---|
| 77 | $vtp->closeSession( $handle, 'li' ); |
---|
| 78 | } |
---|
| 79 | $vtp->closeSession( $handle, 'errors' ); |
---|
| 80 | } |
---|
[17] | 81 | //------------------------------------------------------------------------ form |
---|
| 82 | // search field |
---|
[2] | 83 | $vtp->addSession( $handle, 'line' ); |
---|
[19] | 84 | $vtp->setVar( $handle, 'line.name', $lang['search_field_search'].' *' ); |
---|
[2] | 85 | $vtp->addSession( $handle, 'text' ); |
---|
| 86 | $vtp->setVar( $handle, 'text.size', '40' ); |
---|
| 87 | $vtp->setVar( $handle, 'text.name', 'search' ); |
---|
[276] | 88 | if (isset($_POST['search'])) |
---|
[2] | 89 | $vtp->setVar( $handle, 'text.value', $_POST['search'] ); |
---|
| 90 | $vtp->closeSession( $handle, 'text' ); |
---|
| 91 | $vtp->closeSession( $handle, 'line' ); |
---|
[17] | 92 | // mode of search : match all words or at least one of this words |
---|
| 93 | $vtp->addSession( $handle, 'line' ); |
---|
| 94 | $vtp->addSession( $handle, 'group' ); |
---|
| 95 | |
---|
| 96 | $vtp->addSession( $handle, 'radio' ); |
---|
| 97 | $vtp->setVar( $handle, 'radio.name', 'mode' ); |
---|
| 98 | $vtp->setVar( $handle, 'radio.value', 'OR' ); |
---|
| 99 | $vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] ); |
---|
[290] | 100 | if (!isset($_POST['mode']) || $_POST['mode'] == 'OR' ) |
---|
[17] | 101 | { |
---|
| 102 | $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' ); |
---|
| 103 | } |
---|
| 104 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 105 | |
---|
| 106 | $vtp->addSession( $handle, 'radio' ); |
---|
| 107 | $vtp->setVar( $handle, 'radio.name', 'mode' ); |
---|
| 108 | $vtp->setVar( $handle, 'radio.value', 'AND' ); |
---|
| 109 | $vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] ); |
---|
[276] | 110 | if ( isset($_POST['mode']) && $_POST['mode'] == 'AND' ) |
---|
[17] | 111 | { |
---|
| 112 | $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' ); |
---|
| 113 | } |
---|
| 114 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 115 | |
---|
| 116 | $vtp->closeSession( $handle, 'group' ); |
---|
| 117 | $vtp->closeSession( $handle, 'line' ); |
---|
[2] | 118 | //---------------------------------------------------- return to main page link |
---|
| 119 | $vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) ); |
---|
| 120 | //----------------------------------------------------------- html code display |
---|
[350] | 121 | $output.= $vtp->Display( $handle, 0 ); |
---|
[2] | 122 | //------------------------------------------------------------ log informations |
---|
[290] | 123 | pwg_log( 'search', $title ); |
---|
[17] | 124 | mysql_close(); |
---|
[290] | 125 | include('include/page_tail.php'); |
---|
[350] | 126 | ?> |
---|