%@ page contentType="text/html; charset=euc-jp" %>
<%@ page import = "java.util.*, java.io.*, java.text.*, java.sql.*, java.net.*" %>
<%@ page errorPage="syserror_user.jsp" %>
<%!
private String NullConv( String val ) {
try {
val.equals("null");
return val;
} catch ( Exception e ) {
return "";
}
}
%>
<%
String cond = "", cond2 = "", str, query, bg;
int count = 0, c = 0;
ResultSet rs, cnt;
HashMap hm1 = new HashMap();
HashMap hm2 = new HashMap();
HashMap hm3 = new HashMap();
HashMap hm4 = new HashMap();
hm1.put( request.getParameter("category_1"), "checked");
hm2.put( request.getParameter("category_2"), "checked");
hm3.put( request.getParameter("category_3"), "checked");
hm4.put( request.getParameter("category_4"), "checked");
db.open();
// フリーワード検索
String freeword = request.getParameter("freeword");
if ( freeword != null && freeword.getBytes().length > 0 ) {
freeword = new String( freeword.getBytes("8859_1"), "EUC-JP");
}
if ( freeword != null && freeword.getBytes().length > 0 ) {
String word_cond = "";
StringTokenizer tkn = new StringTokenizer( freeword, " ");
while ( tkn.hasMoreTokens()) {
String st = tkn.nextToken();
query = "SELECT recipe_material.recipe_id ";
query += "FROM recipe_material, recipe_procedure WHERE ";
query += "recipe_material.recipe_id = recipe_procedure.recipe_id AND ";
query += "(material like '%" + st + "%' OR procedure like '%" + st + "%') ";
query += "GROUP BY recipe_material.recipe_id";
rs = db.select( query );
while ( rs.next()) {
if ( cond2 != null && cond2.getBytes().length > 0 ) { cond2 += " OR "; }
cond2 += "id = " + rs.getString(1);
}
if ( cond != null && cond.getBytes().length > 0 ) { cond += " AND "; }
if ( cond2 != null && cond2.getBytes().length > 0 ) {
cond += "( recipe.title like '%" + st + "%' OR " + cond2 + ")";
} else {
cond += "recipe.title like '%" + st + "%'";
}
cond2 = "";
}
}
// 調理時間検索
str = request.getParameter("category_1");
if ( str != null && str.getBytes().length > 0 ) {
if ( cond != null && cond.getBytes().length > 0 ) { cond += " AND "; }
cond += "category_1 = " + str;
}
// 難易度検索
str = request.getParameter("category_2");
if ( str != null && str.getBytes().length > 0 ) {
if ( cond != null && cond.getBytes().length > 0 ) { cond += " AND "; }
cond += "category_2 = " + str;
}
// ジャンル検索
str = request.getParameter("category_3");
if ( str != null && str.getBytes().length > 0 ) {
if ( cond != null && cond.getBytes().length > 0 ) { cond += " AND "; }
cond += "category_3 = " + str;
}
// 材料検索
str = request.getParameter("category_4");
if ( str != null && str.getBytes().length > 0 ) {
if ( cond != null && cond.getBytes().length > 0 ) { cond += " AND "; }
cond += "category_4 = " + str;
}
if ( cond.getBytes().length > 0 ) { cond += " AND "; }
cond += "recipe.del is not true AND start_date <= current_timestamp";
if ( request.getQueryString() != null ) {
query = "SELECT count(*) FROM recipe WHERE " + cond;
cnt = db.select( query );
cnt.next();
count = cnt.getInt("count");
}
String uriQuery = "", tmpStr;
Enumeration queryList = request.getParameterNames();
while ( queryList.hasMoreElements()) {
String k = (String)queryList.nextElement();
if ( k.equals("offset") || k.equals("submit")) { continue; }
tmpStr = new String( request.getParameter(k).getBytes("8859_1"), "EUC-JP");
uriQuery += k + "=" + URLEncoder.encode( tmpStr, "Shift_JIS") + "&";
}
int offset, limit = 15, max;
String uri = request.getRequestURI() + "?" + uriQuery;
String prev = "", next = "", box = "";
if ( request.getParameter("offset") != null ) {
offset = Integer.parseInt( request.getParameter("offset"));
} else {
offset = 0;
}
int l = 15;
String[] defDspCount = new String[]{"1","2","3","4","5","6","7","8","9"};
int pagecount = 0;
String dspcount = null;
for ( int i = 0; i < count; i+=l ) {
pagecount++;
if ( 10 > pagecount ) {
dspcount = defDspCount[ pagecount -1 ];
} else {
dspcount = new Integer( pagecount ).toString();
}
if ( offset > i ) {
box += "" + dspcount + " ";
prev = "<前ページ";
} else if ( offset + l <= i ) {
box += "" + dspcount + " "; next = "次ページ>";
} else {
box += dspcount + " ";
}
}
String PageNavi = prev + "[" + box + "]" + next;
if (( offset + limit ) < count ) {
max = offset + limit;
} else {
max = count;
}
%>
〜本当のおいしさを〜いかりスーパー
<% db.close(); %>