function update_review($title, $comment, $rating, $review_id) { global $database; $review = new mosBookLibrary_review($database); $review->load($review_id); if (!$review->bind($_POST)) { echo "<script> alert('" . $book->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (!$review->check()) { echo "<script> alert('" . $book->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (!$review->store()) { echo "<script> alert('" . $book->getError() . "'); window.history.go(-1); </script>\n"; exit; } }
/** * comments for registered users */ function reviewBook($options, $catid) { PHP_booklibrary::addTitleAndMetaTags(); global $mainframe, $database, $my, $Itemid, $acl; global $booklibrary_configuration, $mosConfig_absolute_path; /* , $catid */ global $mosConfig_mailfrom, $session; if (!isset($my->id)) { //for 1.6 $my->id = 0; } if (!$GLOBALS['reviews_show'] || !checkAccessBL($GLOBALS['reviews_registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) { echo _BOOKLIBRARY_NOT_AUTHORIZED; return; } $review = new mosBookLibrary_review($database); $review->date = date("Y-m-d H:i:s"); $review->fk_userid = $my->id; //********************* begin compare to key *************************** //********************** end compare to key ***************************** //********************** BEGIN review approve *************************** if ($booklibrary_configuration['approve_review']['show'] == '1') { $review->published = 1; } else { $review->published = 0; } if ($booklibrary_configuration['approve_review']['show']) { if (checkAccessBL($booklibrary_configuration['approve_review']['registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) { $review->published = 1; } else { $review->published = 0; } } else { $review->published = 0; } //********************** END review approve *************************** if (!$review->bind($_POST)) { echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n"; exit; } if (!$review->check()) { echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n"; exit; } if (!$review->store()) { echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n"; exit; } $review->updateRatingBook(); //*************** begin add send mail for admin ****************** if (version_compare(JVERSION, '3.0', 'lt')) { $menu = new JTableMenu($database); // for 1.6 $menu->load($Itemid); $params = new mosParameters($menu->params); } else { $menu = new JTableMenu($database); $menu->load($Itemid); $params = new JRegistry(); $params->loadString($menu->params); } if (!isset($my->id)) { //for 1.6 $my->id = 0; } if ($GLOBALS['review_added_email_show'] && trim($GLOBALS['review_email_address']) != "") { $params->def('show_email', 1); if (checkAccessBL($GLOBALS['review_added_email_registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) { $params->def('show_input_email', 1); } } if ($params->get('show_input_email')) { $mail_to = explode(",", $GLOBALS['review_email_address']); // select book title $zapros = "SELECT title FROM #__booklibrary WHERE id = '" . intval($_POST['fk_bookid']) . "';"; $database->setQuery($zapros); $book_title = $database->loadObjectList(); echo $database->getErrorMsg(); $userid = $my->id; //select new review $zapros = "SELECT * FROM #__booklibrary_review WHERE date = '" . $review->date . "';"; $database->setQuery($zapros); $item_review = $database->loadObjectList(); echo $database->getErrorMsg(); $zapros = "SELECT name, email FROM #__users WHERE id=" . $userid . ";"; $database->setQuery($zapros); $item_user = $database->loadObjectList(); echo $database->getErrorMsg(); $rating = $item_review[0]->rating / 2; $query = "SELECT * FROM #__booklibrary WHERE id='" . $_REQUEST['fk_bookid'] . "'"; $database->setQuery($query); $book_name = $database->loadAssoc(); $username = isset($item_user[0]->name) ? $item_user[0]->name : "anonymous"; $message = _BOOKLIBRARY_EMAIL_NOTIFICATION_REVIEW; $message = str_replace("{username}", $username, $message); $message = str_replace("{book_title}", $book_name['title'], $message); $message = str_replace("{label title comment}", _BOOKLIBRARY_LABEL_TITLE_COMMENT, $message); $message = str_replace("{title}", $_REQUEST['title'], $message); $message = str_replace("{label rating}", _BOOKLIBRARY_LABEL_RATING, $message); $message = str_replace("{rating}", $_REQUEST['rating'], $message); $message = str_replace("{label label title review comment}", _BOOKLIBRARY_LABEL_TITLE_REVIEW_COMMENT, $message); $message = str_replace("{comment}", $_REQUEST['comment'], $message); if ($userid == 0) { mosMail($mosConfig_mailfrom, 'anonymous', $mail_to, 'New book review added', $message, true); } else { mosMail($mosConfig_mailfrom, $item_user[0]->name, $mail_to, 'New book review added', $message, true); } } mosRedirect("index.php?option=com_booklibrary&task=view&catid=" . $catid . "&id={$review->fk_bookid}&Itemid={$Itemid}"); }