1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * search.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: search.php 57 2003-08-24 07:40:56Z z0rglub $ |
---|
9 | * * |
---|
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 | { |
---|
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 ) |
---|
46 | { |
---|
47 | $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode']; |
---|
48 | $url = add_session_id( $url, true ); |
---|
49 | header( 'Request-URI: '.$url ); |
---|
50 | header( 'Content-Location: '.$url ); |
---|
51 | header( 'Location: '.$url ); |
---|
52 | exit(); |
---|
53 | } |
---|
54 | } |
---|
55 | //----------------------------------------------------- template initialization |
---|
56 | $vtp = new VTemplate; |
---|
57 | $handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' ); |
---|
58 | initialize_template(); |
---|
59 | |
---|
60 | $tpl = array( 'search_title','search_return_main_page','submit', |
---|
61 | 'search_comments' ); |
---|
62 | templatize_array( $tpl, 'lang', $handle ); |
---|
63 | //----------------------------------------------------------------- form action |
---|
64 | $vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) ); |
---|
65 | //-------------------------------------------------------------- errors display |
---|
66 | if ( sizeof( $error ) != 0 ) |
---|
67 | { |
---|
68 | $vtp->addSession( $handle, 'errors' ); |
---|
69 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
70 | { |
---|
71 | $vtp->addSession( $handle, 'li' ); |
---|
72 | $vtp->setVar( $handle, 'li.li', $error[$i] ); |
---|
73 | $vtp->closeSession( $handle, 'li' ); |
---|
74 | } |
---|
75 | $vtp->closeSession( $handle, 'errors' ); |
---|
76 | } |
---|
77 | //------------------------------------------------------------------------ form |
---|
78 | // search field |
---|
79 | $vtp->addSession( $handle, 'line' ); |
---|
80 | $vtp->setVar( $handle, 'line.name', $lang['search_field_search'].' *' ); |
---|
81 | $vtp->addSession( $handle, 'text' ); |
---|
82 | $vtp->setVar( $handle, 'text.size', '40' ); |
---|
83 | $vtp->setVar( $handle, 'text.name', 'search' ); |
---|
84 | $vtp->setVar( $handle, 'text.value', $_POST['search'] ); |
---|
85 | $vtp->closeSession( $handle, 'text' ); |
---|
86 | $vtp->closeSession( $handle, 'line' ); |
---|
87 | // mode of search : match all words or at least one of this words |
---|
88 | $vtp->addSession( $handle, 'line' ); |
---|
89 | $vtp->addSession( $handle, 'group' ); |
---|
90 | |
---|
91 | $vtp->addSession( $handle, 'radio' ); |
---|
92 | $vtp->setVar( $handle, 'radio.name', 'mode' ); |
---|
93 | $vtp->setVar( $handle, 'radio.value', 'OR' ); |
---|
94 | $vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] ); |
---|
95 | if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' ) |
---|
96 | { |
---|
97 | $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' ); |
---|
98 | } |
---|
99 | $vtp->closeSession( $handle, 'radio' ); |
---|
100 | |
---|
101 | $vtp->addSession( $handle, 'radio' ); |
---|
102 | $vtp->setVar( $handle, 'radio.name', 'mode' ); |
---|
103 | $vtp->setVar( $handle, 'radio.value', 'AND' ); |
---|
104 | $vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] ); |
---|
105 | if ( $_POST['mode'] == 'AND' ) |
---|
106 | { |
---|
107 | $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' ); |
---|
108 | } |
---|
109 | $vtp->closeSession( $handle, 'radio' ); |
---|
110 | |
---|
111 | $vtp->closeSession( $handle, 'group' ); |
---|
112 | $vtp->closeSession( $handle, 'line' ); |
---|
113 | //---------------------------------------------------- return to main page link |
---|
114 | $vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) ); |
---|
115 | //----------------------------------------------------------- html code display |
---|
116 | $code = $vtp->Display( $handle, 0 ); |
---|
117 | echo $code; |
---|
118 | //------------------------------------------------------------ log informations |
---|
119 | pwg_log( 'search', $page['title'] ); |
---|
120 | mysql_close(); |
---|
121 | ?> |
---|