* ################################################## ################################################## #####
*/
require('includes/application_blog.php');
class blogCommentsManager {
/**
* @var CI_DB_query_builder
*/
protected $db;
protected $contentView;
public function __construct() {
$this->db = StaticGXCoreLoader::getDatabaseQueryBuilder();
$languageTextManager = MainFactory::create('LanguageTextManager', 'blog', $_SESSION['languages_id']);
}
public function blogComments($mycontentView) {
$this->contentView = $mycontentView;
if (isset($_GET['flag']) && ($_GET['actionset'] == 'edit')) {
xtc_set_reviews_status($_GET['id'], $_GET['flag']);
xtc_redirect(xtc_href_link('admin.php', 'do=Blog2$do=Blog2&action=comments&page=' . $_GET['page'] . '&action=edit&rID=' . $_GET['rID'] . '&id=' . $_GET['rID'], 'NONSSL'));
}
if ($_GET['action']) {
switch ($_GET['actionset']) {
case 'setflag':
xtc_set_reviews_status($_GET['id'], $_GET['flag']);
//xtc_redirect('/admin/blog.php?do=Blog2&action=comments');
break;
case 'update':
$reviews_id = xtc_db_prepare_input($_GET['rID']);
$comment_rating = xtc_db_prepare_input($_POST['comment_rating']);
$last_modified = xtc_db_prepare_input($_POST['last_modified']);
$reviews_text = xtc_db_prepare_input($_POST['reviews_text']);
$customers_name = xtc_db_prepare_input($_POST['customers_name']);
$date_added = xtc_db_prepare_input($_POST['date_added']);
$this->db->query("UPDATE " . TABLE_BLOG_COMMENT . " SET comment_rating = '" . xtc_db_input($comment_rating) . "', customers_name = '" . xtc_db_input($customers_name) . "', date_added = '" . xtc_db_input($date_added) . "', last_modified = now() where reviews_id = '" . xtc_db_input($reviews_id) . "'");
xtc_redirect(xtc_href_link('admin.php', 'do=Blog2&action=comments&page=' . $_GET['page'] . '&rID=' . $reviews_id));
break;
case 'deleteconfirm':
$reviews_id = xtc_db_prepare_input($_GET['rdID']);
$this->db->query("delete from " . TABLE_BLOG_COMMENT . " where id = '" . xtc_db_input($reviews_id) . "'");
break;
}
}
if ($_GET['actionset'] == 'edit') {
$rID = xtc_db_prepare_input($_GET['rID']);
$reviews = xtc_db_fetch_array($this->db->query("SELECT * FROM " . TABLE_BLOG_COMMENT . " WHERE id = '" . xtc_db_input($rID) . "';")->result_id);
$blogentry_name = xtc_db_fetch_array($this->db->query("SELECT (name) as item_name FROM " . TABLE_BLOG_ITEMS . " WHERE id = '" . $reviews['blog_id'] . "' AND language_id = '" . $_SESSION['languages_id'] . "'")->result_id);
$rInfo_array = xtc_array_merge($reviews, $blogentry_name);
$rInfo = new objectInfo($rInfo_array);
$this->contentView->set_content_data('FORM', xtc_draw_form('review', 'admin.php', 'page=' . $_GET['page'] . '&rID=' . $_GET['rID'] . 'do=Blog2&action=comments&actionset=preview'));
if ($rInfo->comment_status == '1') {
echo xtc_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . ' <a href="' . xtc_href_link('admin.php', 'flag=3&page=' . $_GET['page'] . '&action=edit&rID=' . $_GET['rID'] . '&id=' . $_GET['rID'], 'NONSSL') . '">' . xtc_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
} else {
echo '<a href="' . xtc_href_link('admin.php', 'flag=1&page=' . $_GET['page'] . '&action=edit&rID=' . $_GET['rID'] . '&id=' . $_GET['rID'], 'NONSSL') . '">' . xtc_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a> ' . xtc_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
}
echo ENTRY_REVIEW;
echo xtc_draw_textarea_field('reviews_text', 'soft', '60', '15', $rInfo->reviews_text);
echo ENTRY_REVIEW_TEXT;
echo ENTRY_RATING;
echo TEXT_BAD;
for ($i = 1; $i <= 5; $i++)
echo xtc_draw_radio_field('comment_rating', $i, '', $rInfo->comment_rating) . ' '; echo TEXT_GOOD;
echo xtc_draw_hidden_field('reviews_id', $rInfo->reviews_id) . xtc_draw_hidden_field('products_id', $rInfo->products_id) . xtc_draw_hidden_field('products_name', $rInfo->products_name) . xtc_draw_hidden_field('products_image', $rInfo->products_image) . '<input type="submit" class="button" onClick="this.blur();" value="' . BUTTON_PREVIEW . '"/> <a class="button" onClick="this.blur();" href="' . xtc_href_link('admin.php', 'page=' . $_GET['page'] . '&rID=' . $_GET['rID']) . '">' . BUTTON_CANCEL . '</a>';
} elseif ($_GET['actionset'] == 'preview') {
if ($_POST) {
$rInfo = new objectInfo($_POST);
} else {
$reviews = xtc_db_fetch_array($this->db->query("SELECT * FROM " . TABLE_BLOG_COMMENT . " WHERE id = '" . $_GET['rID'] . "';")->result_id);
$blogentry_name = xtc_db_fetch_array($this->db->query("SELECT (name) as item_name FROM " . TABLE_BLOG_ITEMS . " WHERE id = '" . $reviews['blog_id'] . "' AND language_id = '" . $_SESSION['languages_id'] . "'")->result_id);
$rInfo_array = xtc_array_merge($reviews, $blogentry_name);
$rInfo = new objectInfo($rInfo_array);
}
$this->contentView->set_content_data('FORM', xtc_draw_form('update', 'admin.php', 'page=' . $_GET['page'] . '&rID=' . $_GET['rID'] . '&action=update', 'post', 'enctype="multipart/form-data"'));
$contents = array();
$contents[] = array('text' => ENTRY_PRODUCT);
echo ENTRY_PRODUCT;
echo $rInfo->item_name;
echo ENTRY_FROM;
echo xtc_db_output($rInfo->name);
echo ENTRY_DATE;
echo xtc_date_short($rInfo->date);
echo ENTRY_REVIEW;
echo nl2br(xtc_db_output(xtc_break_string($rInfo->text, 15)));
echo ENTRY_RATING;
echo xtc_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/img/stars_' . $rInfo->comment_rating . '.gif', sprintf(TEXT_OF_5_STARS, $rInfo->comment_rating));
echo sprintf(TEXT_OF_5_STARS, $rInfo->comment_rating);
if ($_POST) {
// Re-Post all POST'ed variables
reset($_POST);
while (list($key, $value) = each($_POST))
echo '<input type="hidden" name="' . $key . '" value="' . htmlspecialchars(stripslashes($value)) . '">';
//echo '<a class="button" onClick="this.blur();" href="' . xtc_href_link('admin.php', 'page=' . $_GET['page'] . '&rID=' . $rInfo->reviews_id . '&action=edit') . '">' . BUTTON_BACK . '</a> <input type="submit" class="button" onClick="this.blur();" value="' . BUTTON_UPDATE . '"/> <a class="button" onClick="this.blur();" href="' . xtc_href_link('admin.php', 'page=' . $_GET['page'] . '&rID=' . $rInfo->reviews_id) . '">' . BUTTON_CANCEL . '</a>';
} else {
if ($_GET['origin']) {
$back_url = $_GET['origin'];
$back_url_params = '';
} else {
$back_url = 'admin.php';
$back_url_params = 'page=' . $_GET['page'] . '&rID=' . $rInfo->reviews_id;
}
}
} else {
$contents2 = array();
$reviews_query_raw = "SELECT * FROM " . TABLE_BLOG_COMMENT . " ORDER BY id DESC";
//$reviews_split = new splitPageResults($_GET['page'], '20', $reviews_query_raw, $reviews_query_numrows);
$reviews_query = $this->db->query($reviews_query_raw);
$i = 0;
while ($reviews = xtc_db_fetch_array($reviews_query->result_id)) {
if (!$_GET['rID'] || ($_GET['rID'] == $reviews['id'])) {
$mycom_query = $this->db->query("select * from " . TABLE_BLOG_COMCOM . " where com_id = " . $reviews['id'] . " order by id DESC ");
$a = 0;
while ($mycoments = xtc_db_fetch_array($mycom_query->result_id)) {
$myreviews[$i]['mycomments'][$a]['id'] = $mycoments['id'];
$myreviews[$i]['mycomments'][$a]['com_id'] = $mycoments['com_id'];
$myreviews[$i]['mycomments'][$a]['date'] = $mycoments['date'];
$myreviews[$i]['mycomments'][$a]['desc'] = $mycoments['description'];
$a++;
}
$myreviews[$i]['reviews_text'] = $reviews['text'];
$myreviews[$i]['reviews_average'] = xtc_db_fetch_array($this->db->query("SELECT comment_rating AS average_rating FROM " . TABLE_BLOG_COMMENT . " WHERE id = '" . $reviews['id'] . "'")->result_id);
$myreviews[$i]['reviews_averresult'] = round($myreviews[$i]['reviews_average']['average_rating'], 0);
$myreviews[$i]['wert'] = number_format($myreviews[$i]['reviews_average']['average_rating'], 2);
$blogentry_name = xtc_db_fetch_array($this->db->query("SELECT name FROM " . TABLE_BLOG_ITEMS . " WHERE id = '" . $reviews['blog_id'] . "' AND language_id = '" . $_SESSION['languages_id'] . "'")->result_id);
$myreviews[$i]['blogentry_name'] = $blogentry_name['name'];
$myreviews[$i]['reviews_image'] = xtc_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/img/stars_' . $myreviews[$i]['reviews_averresult'] . '.gif');
$myreviews[$i]['date'] = $reviews['date'];
$myreviews[$i]['button3'] = '<a class="btn btn-primary" title="edit" href="' . xtc_href_link('admin.php', 'do=Blog2&action=comments&page=' . $_GET['page'] . '&rID=' . $reviews['id'] . '&actionset=preview') . '"><span class="glyphicon glyphicon-wrench"></span></a>';
$myreviews[$i]['comid'] = $reviews['id'];
if ($reviews['comment_status'] == '1') {
$myreviews[$i]['button4'] = '<span class="btn btn-success">on</span> <a class="btn btn-default" href="' . xtc_href_link('admin.php', 'do=Blog2&action=comments&actionset=setflag&flag=0 &id=' . $reviews['id'], 'NONSSL') . '">off</a>';
} else {
$myreviews[$i]['button4'] = '<a class="btn btn-default" href="' . xtc_href_link('admin.php', 'do=Blog2&action=comments&actionset=setflag&flag=1 &id=' . $reviews['id'], 'NONSSL') . '">on</a> <span class="btn btn-danger">off</span>';
}
if ($reviews['id'] == $reviews['id']) {
$myreviews[$i]['button5'] = xtc_image(DIR_WS_IMAGES . 'icon_arrow_right.gif');
} else {
$myreviews[$i]['button5'] = '<a href="' . xtc_href_link('admin.php', 'do=Blog2&action=comments&page=' . $_GET['page'] . '&rID=' . $reviews['id']) . '">' . xtc_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>';
}
}
$i++;
}
}
$this->contentView->set_content_data('blogkey', $myreviews);
$this->contentView->set_content_data('FORM_END', '</form>');
$this->contentView->set_content_data('language', $_SESSION['language']);
}
}