1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * search.php is a part of PhpWebGallery * |
---|
4 | * ------------------- * |
---|
5 | * last update : Wednesday, July 25, 2002 * |
---|
6 | * email : pierrick@z0rglub.com * |
---|
7 | * * |
---|
8 | ***************************************************************************/ |
---|
9 | |
---|
10 | /*************************************************************************** |
---|
11 | * * |
---|
12 | * This program is free software; you can redistribute it and/or modify * |
---|
13 | * it under the terms of the GNU General Public License as published by * |
---|
14 | * the Free Software Foundation; * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | |
---|
18 | //----------------------------------------------------------- personnal include |
---|
19 | include_once( './include/init.inc.php' ); |
---|
20 | //-------------------------------------------------- access authorization check |
---|
21 | check_login_authorization(); |
---|
22 | //----------------------------------------------------------------- redirection |
---|
23 | $error = array(); |
---|
24 | if ( isset( $_POST['search'] ) ) |
---|
25 | { |
---|
26 | $redirect = true; |
---|
27 | $search = array(); |
---|
28 | $words = preg_split( '/\s+/', $_POST['search'] ); |
---|
29 | foreach ( $words as $i => $word ) { |
---|
30 | if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) ) |
---|
31 | { |
---|
32 | array_push( $search, $word ); |
---|
33 | } |
---|
34 | else |
---|
35 | { |
---|
36 | $redirect = false; |
---|
37 | array_push( $error, $lang['invalid_search'] ); |
---|
38 | break; |
---|
39 | } |
---|
40 | } |
---|
41 | $search = array_unique( $search ); |
---|
42 | $search = implode( ',', $search ); |
---|
43 | if ( $redirect ) |
---|
44 | { |
---|
45 | $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode']; |
---|
46 | $url = add_session_id( $url, true ); |
---|
47 | header( 'Request-URI: '.$url ); |
---|
48 | header( 'Content-Location: '.$url ); |
---|
49 | header( 'Location: '.$url ); |
---|
50 | exit(); |
---|
51 | } |
---|
52 | } |
---|
53 | //----------------------------------------------------- template initialization |
---|
54 | $vtp = new VTemplate; |
---|
55 | $handle = $vtp->Open( './template/default/search.vtp' ); |
---|
56 | // language |
---|
57 | $vtp->setGlobalVar( $handle, 'search_page_title',$lang['search_title'] ); |
---|
58 | $vtp->setGlobalVar( $handle, 'search_title', $lang['search_title'] ); |
---|
59 | $vtp->setGlobalVar( $handle, 'search_return_main_page', |
---|
60 | $lang['search_return_main_page'] ); |
---|
61 | $vtp->setGlobalVar( $handle, 'submit', $lang['submit'] ); |
---|
62 | // user |
---|
63 | $vtp->setGlobalVar( $handle, 'page_style', $user['style'] ); |
---|
64 | // structure |
---|
65 | $vtp->setGlobalVar( $handle, 'frame_start', get_frame_start() ); |
---|
66 | $vtp->setGlobalVar( $handle, 'frame_begin', get_frame_begin() ); |
---|
67 | $vtp->setGlobalVar( $handle, 'frame_end', get_frame_end() ); |
---|
68 | //----------------------------------------------------------------- form action |
---|
69 | $vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) ); |
---|
70 | //-------------------------------------------------------------- errors display |
---|
71 | if ( sizeof( $error ) != 0 ) |
---|
72 | { |
---|
73 | $vtp->addSession( $handle, 'errors' ); |
---|
74 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
75 | { |
---|
76 | $vtp->addSession( $handle, 'li' ); |
---|
77 | $vtp->setVar( $handle, 'li.li', $error[$i] ); |
---|
78 | $vtp->closeSession( $handle, 'li' ); |
---|
79 | } |
---|
80 | $vtp->closeSession( $handle, 'errors' ); |
---|
81 | } |
---|
82 | //------------------------------------------------------------------------ form |
---|
83 | // search field |
---|
84 | $vtp->addSession( $handle, 'line' ); |
---|
85 | $vtp->setVar( $handle, 'line.name', $lang['search_field_search'] ); |
---|
86 | $vtp->addSession( $handle, 'text' ); |
---|
87 | $vtp->setVar( $handle, 'text.size', '40' ); |
---|
88 | $vtp->setVar( $handle, 'text.name', 'search' ); |
---|
89 | $vtp->setVar( $handle, 'text.value', $_POST['search'] ); |
---|
90 | $vtp->closeSession( $handle, 'text' ); |
---|
91 | $vtp->closeSession( $handle, 'line' ); |
---|
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'] ); |
---|
100 | if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' ) |
---|
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'] ); |
---|
110 | if ( $_POST['mode'] == 'AND' ) |
---|
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' ); |
---|
118 | //---------------------------------------------------- return to main page link |
---|
119 | $vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) ); |
---|
120 | //----------------------------------------------------------- html code display |
---|
121 | $code = $vtp->Display( $handle, 0 ); |
---|
122 | echo $code; |
---|
123 | //------------------------------------------------------------ log informations |
---|
124 | pwg_log( 'category', $page['title'] ); |
---|
125 | mysql_close(); |
---|
126 | $query = 'insert into '.PREFIX_TABLE.'history'; |
---|
127 | $query.= '(date,login,IP,page) values'; |
---|
128 | $query.= "('".time()."', '".$user['pseudo']."','".$_SERVER['REMOTE_ADDR']."'"; |
---|
129 | $query.= ",'search');"; |
---|
130 | @mysql_query( $query ); |
---|
131 | ?> |
---|