source: trunk/search.php @ 354

Last change on this file since 354 was 354, checked in by gweltas, 20 years ago

Migration of common.php in the include directory to fit the new coding rules

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                           search.php                                |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : 1.4                                                   |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-02-07 19:36:44 +0000 (Sat, 07 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 354 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28//----------------------------------------------------------- include
29$phpwg_root_path = './';
30include_once( $phpwg_root_path.'include/common.inc.php' );
31//-------------------------------------------------- access authorization check
32check_login_authorization();
33//----------------------------------------------------------------- redirection
34$error = array();
35if ( isset( $_POST['search'] ) )
36{
37  $redirect = true;
38  $search = array();
39  $words = preg_split( '/\s+/', $_POST['search'] );
40  foreach ( $words as $i => $word ) {
41    if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
42    {
43      array_push( $search, $word );
44    }
45    else
46    {
47      $redirect = false;
48      array_push( $error, $lang['invalid_search'] );
49      break;
50    }
51  }
52  $search = array_unique( $search );
53  $search = implode( ',', $search );
54  if ( $redirect )
55  {
56    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
57    $url = add_session_id( $url, true );
58    header( 'Request-URI: '.$url );
59    header( 'Content-Location: '.$url ); 
60    header( 'Location: '.$url );
61    exit();
62  }
63}
64//----------------------------------------------------- template initialization
65//
66// Start output of page
67//
68$title= $lang['search_title'];
69include('include/page_header.php');
70
71$handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' );
72initialize_template();
73$tpl = array( 'search_title','search_return_main_page','submit',
74              'search_comments' );
75templatize_array( $tpl, 'lang', $handle );
76//----------------------------------------------------------------- form action
77$vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) );
78//-------------------------------------------------------------- errors display
79if ( sizeof( $error ) != 0 )
80{
81  $vtp->addSession( $handle, 'errors' );
82  for ( $i = 0; $i < sizeof( $error ); $i++ )
83  {
84    $vtp->addSession( $handle, 'li' );
85    $vtp->setVar( $handle, 'li.li', $error[$i] );
86    $vtp->closeSession( $handle, 'li' );
87  }
88  $vtp->closeSession( $handle, 'errors' );
89}
90//------------------------------------------------------------------------ form
91// search field
92$vtp->addSession( $handle, 'line' );
93$vtp->setVar( $handle, 'line.name', $lang['search_field_search'].' *' );
94$vtp->addSession( $handle, 'text' );
95$vtp->setVar( $handle, 'text.size', '40' );
96$vtp->setVar( $handle, 'text.name', 'search' );
97if (isset($_POST['search']))
98$vtp->setVar( $handle, 'text.value', $_POST['search'] );
99$vtp->closeSession( $handle, 'text' );
100$vtp->closeSession( $handle, 'line' );
101// mode of search : match all words or at least one of this words
102$vtp->addSession( $handle, 'line' );
103$vtp->addSession( $handle, 'group' );
104
105$vtp->addSession( $handle, 'radio' );
106$vtp->setVar( $handle, 'radio.name', 'mode' );
107$vtp->setVar( $handle, 'radio.value', 'OR' );
108$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
109if (!isset($_POST['mode']) || $_POST['mode'] == 'OR' )
110{
111  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
112}
113$vtp->closeSession( $handle, 'radio' );
114
115$vtp->addSession( $handle, 'radio' );
116$vtp->setVar( $handle, 'radio.name', 'mode' );
117$vtp->setVar( $handle, 'radio.value', 'AND' );
118$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
119if ( isset($_POST['mode']) && $_POST['mode'] == 'AND' )
120{
121  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
122}
123$vtp->closeSession( $handle, 'radio' );
124
125$vtp->closeSession( $handle, 'group' );
126$vtp->closeSession( $handle, 'line' );
127//---------------------------------------------------- return to main page link
128$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
129//----------------------------------------------------------- html code display
130$code = $vtp->Display( $handle, 0 );
131echo $code;
132//------------------------------------------------------------ log informations
133pwg_log( 'search', $title );
134mysql_close();
135include('include/page_tail.php');
136?>
Note: See TracBrowser for help on using the repository browser.