$ajrv_opt_maxval, )); if(strstr($ajrv_opt_meta_show, "post")){ add_meta_box( 'ajrv_meta_box', 'AJ 리뷰', 'post_metabox_insert', 'post'); } if(strstr($ajrv_opt_meta_show, "post")){ add_meta_box( 'ajrv_meta_box', 'AJ 리뷰', 'post_metabox_insert', 'page'); } } function post_metabox_insert($post){ post_metabox($post->ID); } function post_metabox($postid = "", $reviewid = "", $from = "include"){ global $table_prefix, $wpdb; $ajrv_category = $table_prefix . 'ajrv_category'; $ajrv_review = $table_prefix . 'ajrv_review'; $ajrv_review_item = $table_prefix . 'ajrv_review_item'; $ajrv_group = $table_prefix . 'ajrv_group'; $list_group = $wpdb->get_results("select * from $ajrv_group"); $ajrv_opt_cur = get_option('ajrv_opt_cur', "KRW"); $ajrv_opt_cur_mark = get_option('ajrv_opt_cur_mark', ""); $ajrv_opt_maxval = get_option('ajrv_opt_maxval', "10"); wp_nonce_field('ajrv_nonce_action', 'ajrv_reviewbox_nonce'); $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $isupdate = false; if($postid){ $res = $mysqli->query("select a.*, b.title as categoryname from $ajrv_review as a, $ajrv_category as b where postid = $postid;"); $ritemdata = array(); if(mysqli_num_rows($res)){ $isupdate = true; $row = mysqli_fetch_assoc($res); } }else if($reviewid){ error_log("select a.*, b.title as categoryname from $ajrv_review as a, $ajrv_category as b where a.id = $reviewid;"); $res = $mysqli->query("select a.*, b.title as categoryname from $ajrv_review as a, $ajrv_category as b where a.id = $reviewid;"); $ritemdata = array(); if(mysqli_num_rows($res)){ $isupdate = true; $row = mysqli_fetch_assoc($res); } } $pre_group_id = ""; if(isset($_GET["ajrv_gid"])){ $pre_group_id = sanitize_text_field( $_GET["ajrv_gid"] ); } if($isupdate){ $pre_group_id = $row["groupid"]; } ?>
"> ">
5
query("select * from $ajrv_review_item where reviewid = ". $row['id'] . ";"); if(mysqli_num_rows($resitem)){ while ($ritem = mysqli_fetch_assoc($resitem)) { ?>
"> "/> '>
'>
/
()
()
(
  " name="ajrv_reamount" class="form-control-sm" style="text-align:right;width:120px" />  
query("select * from $ajrv_review where id = $reviewid;"); if(mysqli_num_rows($resPre)){ $rowPre = mysqli_fetch_assoc($resPre); $pre_categoryid = $rowPre["categoryid"]; } } //Category error_log("Category OK? " .$isnewcate); if($isnewcate == "Y"){ //새로운 카테고리 등록 $categoryname = $categoryname != "" ? $categoryname : "Uncategorized"; $res = $mysqli->query("select id from $ajrv_category where title = '$categoryname' and groupid = $groupid;"); if(mysqli_num_rows($res)){ $row = mysqli_fetch_assoc($res); $categoryid = $row["id"]; }else{ $mysqli->query("insert into $ajrv_category(groupid, title, reviewcount, comment, regdate) values($groupid, '$categoryname', 0, '', '" . date("Y-m-d H:i:s") . "');"); $categoryid = $mysqli->insert_id; } } $mysqli->query("update $ajrv_category set reviewcount = reviewcount + 1 where id = $categoryid;"); if($categoryid != $pre_categoryid && $pre_categoryid){ $mysqli->query("update $ajrv_category set reviewcount = reviewcount - 1 where id = $pre_categoryid;"); } $r_item = array(); $sqlitem = ""; $overall = 0; $realcount = 0; $totalvalue = 0; //Review Items for($i = 0; $i < count($_POST['ajrv_item']); $i++){ $itemname = sanitize_text_field($_POST['ajrv_item'][$i]); $itemvalue = sanitize_text_field($_POST['ajrv_itemvalue'][$i]); if($itemname){ $realcount++; $totalvalue += (int)$itemvalue; $itemname = mysqli_real_escape_string($mysqli, $itemname); array_push($r_item, "insert into $ajrv_review_item(reviewid, title, overall) values(__RVID__, '$itemname', $itemvalue);"); } } if($realcount > 0){ $overall = round((float)$totalvalue / (float)$realcount, 3); } $res_rev = $mysqli->query("select id from $ajrv_review where postid = $post_id;"); if(mysqli_num_rows($res_rev)){ $row = mysqli_fetch_assoc($res_rev); $reviewid = $row["id"]; } //Review if($reviewid){ $sql = "update $ajrv_review set"; $sql .= " groupid = $groupid ,"; $sql .= " categoryid = $categoryid ,"; $sql .= " postid = $post_id ,"; $sql .= " authorid = $user_id ,"; $sql .= " title = '$title' ,"; $sql .= " publisher = '$publisher' ,"; $sql .= " platform = '$platform' ,"; $sql .= " singleword = '$singleword' ,"; $sql .= " onelinereview = '$onecomment' ,"; $sql .= " overall = $overall ,"; $sql .= " pros = '$pros' ,"; $sql .= " cons = '$cons' ,"; $sql .= " photo = $photo ,"; $sql .= " useramount = $reamount ,"; $sql .= " updated = '".date("Y-m-d H:i:s")."' where id = $reviewid ;"; error_log($sql); $mysqli->query($sql); }else{ $sql = "insert into $ajrv_review(groupid, categoryid, postid, authorid, title, publisher, platform, singleword, onelinereview, overall, pros, cons, photo, useramount, regdate) values("; $sql .= " $groupid, $categoryid, $post_id, $user_id, '$title', '$publisher', '$platform', '$singleword', '$onecomment', $overall, '$pros', '$cons', $photo, $reamount, '".date("Y-m-d H:i:s")."');"; error_log($sql); $mysqli->query($sql); $reviewid = $mysqli->insert_id; } $mysqli->query("delete from $ajrv_review_item where reviewid = $reviewid;"); foreach($r_item as $ritem){ $ritem = str_replace("__RVID__", $reviewid, $ritem); $mysqli->query($ritem); } } ?>