/* ********************************************************************************* * システム:katsuyo.net * *===============================================================================* * クラス:diet_top |モジュール:diet_top.php * * 概要 :ダイエット趣向レシピ ダイエットディナー表示用画面 * * パス :APP_HOME/diet/ * * 作成 :2006/07/12 J.Nikaido * *-------------------------------------------------------------------------------* * 更新 : * ********************************************************************************* */ require_once('../prepare.php'); require_once('lib/diet_function.php'); function diet_top( $p ){ //******************************// // データ取得処理 // //******************************// //現在時刻を取得 $today_now = getdate(); $hours = $today_now[hours]; //22:00以降は翌日のレシピを表示するための処理 if($hours >= 22){ //明日日時を取得 $date_today = mktime (0, 0, 0, date("m"), date("d"), date("y")); $date_tomorrow = $date_today + 86400; //本日日付取得 $base = date('Ymd', $date_tomorrow); $base_day = substr($base,6,2); $base_month = substr($base,4,2); $base_year = substr($base,0,4); }else{ //本日日付取得 $base_day = date("d"); $base_month = date("m"); $base_year = date("Y"); } //前日を選択の場合、$todayに前日日付を設定 if(!empty($p[day]) || '' != $p[day]){ if(!empty($p[set_id])){ $today = str_replace('.','-',substr($p[day],0,10)); }else{ $today = date("Y-m-d",mktime(0,0,0,$base_month,$base_day - 1,$base_year)); } }else{ $today = sprintf("%s-%s-%s",$base_year,$base_month,$base_day); } //******************************// // DB取得処理 // //******************************// //DB接続 $db = DB::connect(constant('KTY_DSN')); if(DB::isError($db)){ echo "DB接続エラー:".DB::errorMessage($db)."\n"; exit; } $join = " INNER JOIN contents_data_bsc_r_new AS r1 ON r1.rcp_no = d.staple_id "; $join.= " INNER JOIN contents_data_bsc_r_new AS r2 ON r2.rcp_no = d.main_id"; $join.= " INNER JOIN contents_data_bsc_r_new AS r3 ON r3.rcp_no = d.sub_id"; if(!empty($p[set_id])){ $where = sprintf(" d.uniq_id = '%s' and date = '%s*' and dlt_flg = 0 " , $p[set_id] ,$today); }else{ $where = sprintf(" date = '%s*' and dlt_flg = 0 ",$today); } $sql = "SELECT d.uniq_id, d.set_name,"; $sql.= " d.staple_id ,r1.rcp_nm name1 ,d.staple_cmt ,r1.rcp_f_nm rcp_f_nm1 ,r1.rcp_crl rcp_crl1,"; $sql.= " d.main_id ,r2.rcp_nm name2 ,d.main_cmt ,r2.rcp_f_nm rcp_f_nm2 ,r2.rcp_crl rcp_crl2,"; $sql.= " d.sub_id ,r3.rcp_nm name3 ,d.sub_cmt ,r3.rcp_f_nm rcp_f_nm3 ,r3.rcp_crl rcp_crl3"; $sql.= sprintf(" FROM contents_data_kty_diet_set AS d %s Where %s",$join,$where); $res = $db->query($sql); if(DB::isError($res)){ echo "
クエリの送信が失敗しました。
"; exit; } // テンプレート読み込み $template =& loadTemplate( $p ); //件数取得 $num = $res->numRows(); //件数分だけループ while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)){ $img_path1 = sprintf("/home/www/public/image/recipe/%d_n-thm.jpg",$row['staple_id']); $img_path2 = sprintf("/home/www/public/image/recipe/%d_n-thm.jpg",$row['main_id']); $img_path3 = sprintf("/home/www/public/image/recipe/%d_n-thm.jpg",$row['sub_id']); //******************************// // ページング処理 // //******************************// //前日の情報取得 $yesterday = date("Y-m-d",mktime(0,0,0,$base_month,$base_day - 1,$base_year)); $where = ''; $where .= sprintf(" date = '%s*' and dlt_flg = 0 ",$yesterday); $res2 = $db->query($sql); if(DB::isError($res)){ echo "クエリの送信が失敗しました。
"; exit; } //件数取得 $num2 = $res2->numRows(); //件数がある場合、表示処理 if(!empty($p[set_id])){ $template->setCurrentBlock('__ReturnRank__'); $template->setVariable('day',$today); $template->setVariable('flg','y'); $template->parseCurrentBlock(); // $template->setCurrentBlock('__ReturnRank__'); // $template->setVariable('day',$yesterday); // $template->parseCurrentBlock(); $template->hideBlock('__Regist__'); }else{ if(!empty($num2)){ $template->setCurrentBlock('__Yesterday__'); $template->setVariable('day',$yesterday); $template->setVariable('flg','y'); $template->parseCurrentBlock(); }else{ $template->hideBlock('__Yesterday__'); } if(!empty($p[flg]) && $p[flg] == 'y'){ $template->setCurrentBlock('__Today__'); $template->setVariable('day',''); $template->setVariable('flg',''); $template->hideBlock('__Yesterday__'); $template->parseCurrentBlock(); }else{ $template->hideBlock('__Today__'); } } //******************************// // テンプレート引渡し処理 // //******************************// if(file_exists($img_path1)){ $template->touchBlock('__ShowImage1__'); $template->setVariable('today_image1',sprintf("",str_replace(KTY_SERVER_ROOT,"",$img_path1))); }else{ $template->hideBlock('__ShowImage1__'); } if(file_exists($img_path2)){ $template->touchBlock('__ShowImage2__'); $template->setVariable('today_image2',sprintf("",str_replace(KTY_SERVER_ROOT,"",$img_path2))); }else{ $template->hideBlock('__ShowImage2__'); } if(file_exists($img_path3)){ $template->touchBlock('__ShowImage3__'); $template->setVariable('today_image3',sprintf("",str_replace(KTY_SERVER_ROOT,"",$img_path3))); }else{ $template->hideBlock('__ShowImage3__'); } //var_dump ($row); //カロリーの合算 $ttl_crl = $row['rcp_crl1'] + $row['rcp_crl2'] + $row['rcp_crl3']; clearstatcache(); $template->setCurrentBlock("__List__"); $template->setVariable('uniq_id',$row['uniq_id']); $template->setVariable('set_name',$row['set_name']); $template->setVariable('staple_id',$row['staple_id']); $template->setVariable('name1',$row['name1']); $template->setVariable('staple_cmt',$row['staple_cmt']); $template->setVariable('rcp_crl1',$row['rcp_crl1']); $template->setVariable('main_id',$row['main_id']); $template->setVariable('name2',$row['name2']); $template->setVariable('main_cmt',$row['main_cmt']); $template->setVariable('rcp_crl2',$row['rcp_crl2']); $template->setVariable('sub_id',$row['sub_id']); $template->setVariable('name3',$row['name3']); $template->setVariable('sub_cmt',$row['sub_cmt']); $template->setVariable('rcp_crl3',$row['rcp_crl3']); $template->setVariable('ttl_crl',$ttl_crl); $template->parse("__List__"); } $template->show(); //DB開放 $db->disconnect(); } diet_top( $p ); ?>