whereAdd("id = '$get_id'");
$recipe->whereAdd("status = 'active'", 'AND');
$recipe->limit(1);
if(!$recipe->find()){
$url = 'error.php';
header("Location: {$url}");
}
$recipe->fetch();
$keywords = $recipe->keyword;
$description = $recipe->story;
$title = $recipe->title .' || ' . $title;
if ($recipe->competition_id) {
$competition = DB_DataObject::factory("competition");
$competition->get("id", $recipe->competition_id);
if ($competition->status != "open") {
$recipe->competition_id = 0;
}
}
$recipe->story = nl2br($recipe->story);
$recipe->note = nl2br($recipe->note);
$recipe->modified = COM_changeDatetimeFormat($recipe->modified);
$author = DB_DataObject::factory("author");
$author->get("id", $recipe->author_id);
$company = DB_DataObject::factory("company");
$company->get("id", $author->company_id);
$recipe_update = DB_DataObject::factory("recipe");
$recipe_update->whereAdd("id = '$get_id'");
$recipe_update->access = $recipe->access + 1;
$recipe_update->modified = DB_DataObject_Cast::Sql('NOW()');
$recipe_update->update(DB_DATAOBJECT_WHEREADD_ONLY);
$tempbigimage = str_replace('_small.jpg', '_big.jpg', $recipe->image);
$recipes = $recipe->toArray();
$recipes["big_image"] = $tempbigimage;
$recipes["author"] = $author->name;
$recipes["company"] = $company->name;
/* フォーム作成 */
$form = new HTML_QuickForm('commentform', 'post', $_SERVER['SCRIPT_NAME'] . '?id=' . $get_id);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($o_smarty, true);
$form->addElement('textarea', 'body', 'コメント:', array("cols"=>60, "rows"=>15));
/* ルール適用 */
HTML_QuickForm::registerRule("hankanaCheck", "callback", "hankanaCheck");
HTML_QuickForm::registerRule("htmlTagCheck", "callback", "htmlTagCheck");
$form->addRule('body', 'コメントを入力してください', 'required', null);
$form->addRule('body', "半角カナは使えません", "hankanaCheck", NULL, "server");
$form->addRule('body', "htmlは使えません", "htmlTagCheck", NULL, "server");
/* フィルター適用 */
$form->applyFilter('__ALL__', 'trim');
//$form->applyFilter('__ALL__', 'htmlentities');
//$form->applyFilter('__ALL__', 'addslashes');
//$form->applyFilter('__ALL__', 'escapeshellcmd');
/* 出力分岐処理 */
$submit = $form->getSubmitValue('submit');
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . ".tpl";
if ($form->validate()) {
$title = 'コメントを書く || ' . $title;
if (isset($submit["submit"])) {
/* 確認画面 */
$title = '確認画面 || ' . $title;
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . "_confirm.tpl";
display_confirm($form);
} elseif (isset($submit["done"])) {
/* 完了画面 */
if ($_SESSION['ticket'] == $_POST['session_ticket']) {
/* 正常終了 */
unset($_SESSION['ticket']);
$title = 'コメントを受け付けました! || ' . $title;
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . "_complete.tpl";
$form->process('insert_data', false);
} else {
/* 二重投稿エラー */
$url = 'error.php';
header("Location: {$url}");
}
} else {
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . "_confirm.tpl";
display_form($form);
}
} else {
if (!isset($submit["submit"])) {
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . ".tpl";
display_form($form);
}else{
$title = 'エラーが発生しています || ' . 'コメントを書く || ' . $title;
$template = basename($_SERVER['SCRIPT_NAME'], ".php") . "_confirm.tpl";
display_form($form);
}
}
/* フォーム出力処理 */
$renderer->setErrorTemplate('{if $error}{$error}{/if}');
$renderer->setRequiredTemplate('{if $error}{$label}{else}{$label}{if $required} *{/if}{/if}');
$form->accept($renderer);
$o_smarty->assign("commentform", $renderer->toArray());
/**
* コメント内容出力
*/
$comment = DB_DataObject::factory("comment");
$comment->whereAdd("{$comment->__table}.recipe_id = '$get_id'");
$comment->whereAdd("{$comment->__table}.status = 'active'", 'AND');
$comment->find();
while ($comment->fetch()) {
$comment->modified = COM_changeDatetimeFormat($comment->modified);
$comment->body = nl2br(htmlspecialchars($comment->body));
$user = DB_DataObject::factory("user");
$user->get("id", $comment->user_id);
$tempArray = $comment->toArray();
$tempArray["nickname"] = htmlspecialchars($user->nickname);
$comments[] = $tempArray;
}
/**
* 手順内容出力
*/
$step_by_step_recipe = DB_DataObject::factory("step_by_step_recipe");
$step_by_step_recipe->orderBy("num ASC");
$step_by_step_recipe->whereAdd("recipe_id = '$get_id'");
$step_by_step_recipe->find();
while ($step_by_step_recipe->fetch()) {
if ($step_by_step_recipe->type == 'step') {
$step[] = $step_by_step_recipe->toArray();
} else {
$precook[] = $step_by_step_recipe->toArray();
}
}
/**
* 材料出力
*/
$ingredient=DB_DataObject::factory("ingredient");
$ingredient->whereAdd("recipe_id = '$get_id'");
$ingredient->orderBy("id ASC");
$ingredient->find();
while ($ingredient->fetch()) {
if ($ingredient->assembly) {
$group[] = $ingredient->toArray();
} else {
$ingredients[] = $ingredient->toArray();
}
}
$g_ingredient_color = Array('FFDDDD','DDFFFF','FFFFDD','DDDDFF','DFDFDF','FDFDFD','DDDDDD');
$j = 0;
for ($i = 0;$i < count($group);$i++) {
$g_ingredient[$j][] = $group[$i];
if ($g_ingredient_num[$j]) {
$g_ingredient_num[$j]++;
} else {
$g_ingredient_num[$j] = 1;
}
if ($group[$i]["assembly"] != $group[$i+1]["assembly"]) {
$j++;
}
}
/**
* カテゴリ出力
*/
$term_relationship = DB_DataObject::factory("term_relationship");
$term_taxonomy = DB_DataObject::factory("term_taxonomy");
$term = DB_DataObject::factory("term");
$term_relationship->whereAdd("recipe_id = '$get_id'");
$term_taxonomy->joinAdd($term);
$term_relationship->joinAdd($term_taxonomy);
$term_relationship->selectAs($term_taxonomy, 'tt_%s');
$term_relationship->selectAs($term, 't_%s');
$term_relationship->find();
while ($term_relationship->fetch()) {
if ($term_relationship->tt_taxonomy == 'category') {
$tempArray = $term_relationship->toArray();
$categorylist[] = $tempArray;
} elseif ($term_relationship->tt_taxonomy == 'foodstuff'){
$tempArray = $term_relationship->toArray();
$foodstufflist[] = $tempArray;
}
$pankuzu[] = COM_getPankuzuList($term_relationship->tt_id);
}
/**
* テンプレート組立て
*/
$o_smarty->assign("author", $author);
$o_smarty->assign("pankuzu", $pankuzu);
$o_smarty->assign("recipe", $recipes);
$o_smarty->assign("comment", $comments);
$o_smarty->assign("comment_num", count($comments));
$o_smarty->assign("step", $step);
$o_smarty->assign("precook", $precook);
$o_smarty->assign("ingredient", $ingredients);
$o_smarty->assign("ingredient_num", count($ingredients)+count($group));
$o_smarty->assign("g_ingredient", $g_ingredient);
$o_smarty->assign("g_ingredient_num", $g_ingredient_num);
$o_smarty->assign("g_ingredient_color", $g_ingredient_color);
$o_smarty->assign("categorylist", $categorylist);
$o_smarty->assign("foodstufflist", $foodstufflist);
} else {
$url = 'error.php';
header("Location: {$url}");
}
$o_smarty->assign("keywords", $keywords);
$o_smarty->assign("description", $description);
$o_smarty->assign("title", $title);
loginCheckFunction();
$o_smarty->display($template);
/* フォーム出力 */
function display_form($form){
$buttons[] = $form->createElement('image', 'submit', 'images/recipe/tugihebar', array('alt'=>'次へ進む'));
//$buttons[] = $form->createElement('reset', 'reset', 'リセット');
$form->addGroup($buttons, "submit");
}
/* 確認画面出力 */
function display_confirm($form){
global $o_smarty;
$_SESSION['ticket'] = md5(mt_rand());
$o_smarty->assign("session_ticket", '');
$buttons[] = $form->createElement('image', 'done', 'images/recipe/toukoubar', array('alt'=>'投稿する'));
$buttons[] = $form->createElement('submit', 'return', '変更する');
$form->addGroup($buttons, "submit");
$form->addElement('static', 'message', '入力内容を確認して、「投稿する」ボタンを押してください。');
$form->freeze();
}
/* DBに登録 */
function insert_data($values){
global $myAuth;
$get_id = (int)$_GET['id'];
$comment = DB_DataObject::factory("comment");
$comment->body = $values['body'];
$comment->recipe_id = $get_id;
$comment->user_id = $myAuth->getAuthData("id");
$comment->status = 'inactive';
$comment->created = DB_DataObject_Cast::Sql('NOW()');
$comment->modified = DB_DataObject_Cast::Sql('NOW()');
$comment->insert();
}
?>