<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>Product Reviews Pro</name>
    <code>Product_Reviews_Pro</code>
    <version>2.0</version>
    <author>CodingInspect</author>

	<file path="admin/controller/common/column_left.php">
		<operation error="skip">
			<search><![CDATA[$marketplace = array();]]></search>
			<add position="before"><![CDATA[
			/* Product Review Pro Starts */
			$cireviewpro = array();
			if ($this->user->hasPermission('access', 'cireviewpro/cireviews')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_cireviews'),
					'href'     => $this->url->link('cireviewpro/cireviews', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}
			if ($this->user->hasPermission('access', 'cireviewpro/ciabreason')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_ciabreason'),
					'href'     => $this->url->link('cireviewpro/ciabreason', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}
			if ($this->user->hasPermission('access', 'cireviewpro/cireviewpro_invite')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_cireviewpro_invite'),
					'href'     => $this->url->link('cireviewpro/cireviewpro_invite', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'cireviewpro/cireviewpro_invitelog')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_cireviewpro_invitelog'),
					'href'     => $this->url->link('cireviewpro/cireviewpro_invitelog', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'cireviewpro/cireviewpro_cron')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_cireviewpro_cron'),
					'href'     => $this->url->link('cireviewpro/cireviewpro_cron', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'cireviewpro/ciratingtype')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_ciratingtype'),
					'href'     => $this->url->link('cireviewpro/ciratingtype', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'cireviewpro/cireviewpro')) {
				$this->load->language('cireviewpro/cireviewpro_menu');
				$cireviewpro[] = array(
					'name'	   => $this->language->get('text_setting'),
					'href'     => $this->url->link('cireviewpro/cireviewpro', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);

				if ($cireviewpro) {
					$data['menus'][] = array(
						'id'       => 'menu-cireviewpro',
						'icon'	   => 'fa fa-star-o',
						'name'	   => $this->language->get('text_cireviewpro'),
						'href'     => '',
						'children' => $cireviewpro
					);
				}

				//$catalog = array_merge($catalog, $cireviewpro);
			}
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>

	<file path="catalog/controller/product/product.php">
		<operation error="skip">
			<search><![CDATA[$data['products'] = array();]]></search>
			<add position="before"><![CDATA[
			/* Product Review Pro Starts */
			if($this->config->get('cireviewpro_status')) {
				$data['review_status'] = true;
				if ($this->config->get('cireviewpro_reviewguest') || $this->customer->isLogged()) {
					$data['review_guest'] = true;
				} else {
					$data['review_guest'] = false;
				}
				$data['cireviewpro'] = $this->load->controller('cireviewpro/cireview');

				$this->load->model('cireviewpro/cireview');
				$filter_data = array(
					'product_id' => $this->request->get['product_id'],
				);

				$review_total = $this->model_cireviewpro_cireview->getTotalCiReviewsByProductId($filter_data);

				$data['tab_review'] = sprintf($this->language->get('tab_review'), $review_total);

				$data['reviews'] = sprintf($this->language->get('text_reviews'), $review_total);

				//$avg_rating = $this->model_cireviewpro_cireview->getAvgRatingOfProducts($product_info['product_id']);

				//$data['rating'] = (int)$avg_rating;

			}
			$data['cireviewpro_status'] = $this->config->get('cireviewpro_status');
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<!-- journal3 compatibility starts -->
	<file path="catalog/controller/journal3/blocks.php">
		<operation error="skip">
			<search><![CDATA[static::$PRODUCT_INFO['reviews']]]></search>
			<add position="before"><![CDATA[
			/* Product Review Pro Starts */
			if($this->config->get('cireviewpro_status')) {
				$data['review_status'] = true;
				if ($this->config->get('cireviewpro_reviewguest') || $this->customer->isLogged()) {
					$data['review_guest'] = true;
				} else {
					$data['review_guest'] = false;
				}
				$data['cireviewpro'] = $this->load->controller('cireviewpro/cireview');

				$this->load->model('cireviewpro/cireview');
				$filter_data = array(
					'product_id' => $this->request->get['product_id'],
				);

				$review_total = $this->model_cireviewpro_cireview->getTotalCiReviewsByProductId($filter_data);

				$data['tab_review'] = sprintf($this->language->get('tab_review'), $review_total);

				$data['reviews'] = sprintf($this->language->get('text_reviews'), $review_total);

				$avg_rating = $this->model_cireviewpro_cireview->getAvgRatingOfProducts($product_info['product_id']);

				$data['rating'] = (int)$avg_rating;

			}
			$data['cireviewpro_status'] = $this->config->get('cireviewpro_status');
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/journal3/product_tabs.php">
		<operation error="skip">
			<search><![CDATA[static::$PRODUCT_INFO['reviews']]]></search>
			<add position="before"><![CDATA[
			/* Product Review Pro Starts */
			if($this->config->get('cireviewpro_status')) {
				$data['review_status'] = true;
				if ($this->config->get('cireviewpro_reviewguest') || $this->customer->isLogged()) {
					$data['review_guest'] = true;
				} else {
					$data['review_guest'] = false;
				}
				$data['cireviewpro'] = $this->load->controller('cireviewpro/cireview');

				$this->load->model('cireviewpro/cireview');
				$filter_data = array(
					'product_id' => $this->request->get['product_id'],
				);

				$review_total = $this->model_cireviewpro_cireview->getTotalCiReviewsByProductId($filter_data);

				$data['tab_review'] = sprintf($this->language->get('tab_review'), $review_total);

				$data['reviews'] = sprintf($this->language->get('text_reviews'), $review_total);

				$avg_rating = $this->model_cireviewpro_cireview->getAvgRatingOfProducts($product_info['product_id']);

				$data['rating'] = (int)$avg_rating;

			}
			$data['cireviewpro_status'] = $this->config->get('cireviewpro_status');
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<!-- journal3 compatibility ends -->
	<file path="catalog/model/account/customer.php">
		<operation error="skip">
			<search><![CDATA[$customer_id = $this->db->getLastId();]]></search>
			<add position="after"><![CDATA[
			/* Product Review Pro Starts */
			if($this->config->get('cireviewpro_status')) {
				$this->load->model('cireviewpro/cireview');
				$this->model_cireviewpro_cireview->findSyncCustomerOldReviews($customer_id);
			}
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<file path="catalog/model/catalog/product.php">
		<operation error="skip">
			<search><![CDATA['product_id'       => $query->row['product_id'],]]></search>
			<add position="before" offset="1"><![CDATA[
			/* Product Review Pro Starts */
			if($this->config->get('cireviewpro_status')) {
				$this->load->model('cireviewpro/cireview');
				$avg_rating = $this->model_cireviewpro_cireview->getAvgRatingOfProducts($query->row['product_id']);

				$query->row['orating'] = $query->row['rating'];
				$query->row['rating'] = $avg_rating;
			}
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>

	<file path="catalog/view/theme/*/template/product/product.twig">
		<operation error="skip">
			<search><![CDATA[<form class="form-horizontal" id="form-review">]]></search>
			<add position="replace"><![CDATA[{% if cireviewpro_status %}
				<!-- Product Review Pro Starts -->
				{{ cireviewpro }}
				<!-- Product Review Pro Ends -->
			<form class="form-horizontal hide" id="form-review" style="display: none;">
			{% else %}
			<form class="form-horizontal" id="form-review">
			{% endif %}]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ reviews]]></search>
			<add position="replace"><![CDATA[onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;" class="ciscrolltoreviewtab">{{ reviews]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;">{{ text_write]]></search>
			<add position="replace"><![CDATA[onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;" class="ciopenreviewpopup">{{ text_write]]></add>
		</operation>
		<operation error="skip" info="for journal3">
			<search><![CDATA[var $review = $('#review');]]></search>
			<add position="after"><![CDATA[
			{% if cireviewpro_status %}var $review = $('#cireview-graph');{% endif %}
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/journal3/template/journal3/module/product_blocks_reviews.twig">
		<operation error="skip">
			<search><![CDATA[<form class="form-horizontal" id="form-review">]]></search>
			<add position="replace"><![CDATA[{% if cireviewpro_status %}
				<!-- Product Review Pro Starts -->
				{{ cireviewpro }}
				<!-- Product Review Pro Ends -->
			<form class="form-horizontal hide" id="form-review" style="display: none;">
			{% else %}
			<form class="form-horizontal" id="form-review">
			{% endif %}]]></add>
		</operation>
	</file>

	<!-- invite on order catalog -->
	<file path="catalog/model/checkout/order.php">
		<operation error="skip">
			<search><![CDATA['customer_id'             => $order_query->row['customer_id'],]]></search>
			<add position="before"><![CDATA[
			'customer_group_id'             => $order_query->row['customer_group_id'],
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[if (in_array($order_info['order_status_id'], array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status'))) && !in_array($order_status_id, array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status')))) {]]></search>
			<add position="before"><![CDATA[
			/* Product Review Pro Starts */
				$this->load->controller("cireviewpro/cireviewcron/reviewInviteOnOrder", array('order_id' => $order_id));
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>

	<!-- invite on order admin -->
	<file path="admin/controller/sale/order.php">
		<operation error="skip">
			<search><![CDATA[$data['button_view'] = $this->language->get('button_view');]]></search>
			<add position="before"><![CDATA[
				$this->load->language('cireviewpro/cireviewadmin');
				$data['button_cisendmail'] = $this->language->get('button_cisendmail');
			]]></add>
		</operation>
	</file>
	<!-- /*20-june-2019 order products design start*/ -->
	<!-- <file path="admin/view/template/sale/order_list.twig">
		<operation error="skip">
			<search><![CDATA[<a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a> ]]></search>
			<add position="after"><![CDATA[
			<a onclick="ciSendInviteEmails(this);" data-toggle="tooltip" title="{{ button_cisendmail }}" class="btn btn-warning"><i class="fa fa-envelope"></i></a>
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<a href="{{ order.view }}" data-toggle="tooltip" title="{{ button_view }}" class="btn btn-primary"><i class="fa fa-eye"></i></a>]]></search>
			<add position="replace"><![CDATA[<a onclick="ciSendInviteEmail(this);" data-id="{{ order.order_id }}" data-toggle="tooltip" title="{{ button_cisendmail }}" class="btn btn-warning"><i class="fa fa-envelope"></i></a>
			<a href="{{ order.view }}" data-toggle="tooltip" title="{{ button_view }}" class="btn btn-primary"><i class="fa fa-eye"></i></a>]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[$('#button-filter').on('click', function() {]]></search>
			<add position="before"><![CDATA[
			function ciSendInviteEmails(el) {
				var	data = 'multiple=true';


				$('input[name*=\'selected\']:checked').each(function() {
					data += '&order_ids[]='+ $(this).val();
				});


				$.ajax({
					url: 'index.php?route=cireviewpro/cireviewpro_cron/sendInviteEmail&user_token={{ user_token }}',
					type: 'post',
					data: data,
					dataType: 'json',
					beforeSend: function() {
						$(el).find('i').removeClass('fa-envelope').addClass('fa-circle-o-notch fa-spin');
						$(el).attr('disabled','disabled');
					},
					complete: function() {
						$(el).find('i').addClass('fa-envelope').removeClass('fa-circle-o-notch fa-spin');
						$(el).removeAttr('disabled');
					},
					success: function(json) {
						if(json['success']) {
							$('.panel.panel-default').before('<div class="cialert alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
						}

						if(json['error']) {
							$('.panel.panel-default').before('<div class="cialert alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
						}

						setTimeout(function() {
							$('.cialert').remove();
						}, 5000);
					},
					error: function(xhr, ajaxOptions, thrownError) {
						alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
					}
				});

			}

			function ciSendInviteEmail(el) {
				var order_id = $(el).attr('data-id');

				$.ajax({
					url: 'index.php?route=cireviewpro/cireviewpro_cron/sendInviteEmail&user_token={{ user_token }}',
					type: 'post',
					data: 'order_id=' + order_id +'&multiple=false',
					dataType: 'json',
					beforeSend: function() {
						$(el).find('i').removeClass('fa-envelope').addClass('fa-circle-o-notch fa-spin');
						$(el).attr('disabled','disabled');
					},
					complete: function() {
						$(el).find('i').addClass('fa-envelope').removeClass('fa-circle-o-notch fa-spin');
						$(el).removeAttr('disabled');
					},
					success: function(json) {
						if(json['success']) {
							$('#form-order').before('<div class="cialert alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
						}
						if(json['error']) {
							$('#form-order').before('<div class="cialert alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
						}

						setTimeout(function() {
							$('.cialert').remove();
						}, 5000);
					},
					error: function(xhr, ajaxOptions, thrownError) {
						alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
					}
				});

			}
			]]></add>
		</operation>
	</file> -->
	<!-- /*20-june-2019 order products design end*/ -->
	<!-- adding position information in setting array starts -->
	<file path="catalog/controller/common/column_left.php">
		<operation error="skip">
			<search><![CDATA[if ($setting_info && $setting_info['status'])]]></search>
			<add position="after"><![CDATA[
			/* Product Review Pro Starts */
			$setting_info['cireviewpro_position'] = 'column_left';
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/common/column_right.php">
		<operation error="skip">
			<search><![CDATA[if ($setting_info && $setting_info['status'])]]></search>
			<add position="after"><![CDATA[
			/* Product Review Pro Starts */
			$setting_info['cireviewpro_position'] = 'column_right';
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/common/content_top.php">
		<operation error="skip">
			<search><![CDATA[if ($setting_info && $setting_info['status'])]]></search>
			<add position="after"><![CDATA[
			/* Product Review Pro Starts */
			$setting_info['cireviewpro_position'] = 'content_top';
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<file path="catalog/controller/common/content_bottom.php">
		<operation error="skip">
			<search><![CDATA[if ($setting_info && $setting_info['status'])]]></search>
			<add position="after"><![CDATA[
			/* Product Review Pro Starts */
			$setting_info['cireviewpro_position'] = 'content_bottom';
			/* Product Review Pro Ends */
			]]></add>
		</operation>
	</file>
	<!-- adding position information in setting array ends -->
	<!-- seo urls starts -->
	<file path="catalog/controller/startup/seo_url.php">
		<operation error="log">
			<search><![CDATA[if ($url[0] == 'category_id') {]]></search>
			<add position="before"><![CDATA[
			if( VERSION < '3.0.0.0') {
				if($url[0] == 'cireviewpro/cireviews'.'-'.(int)$this->config->get('config_store_id')) {
					$query->row['query'] = 'cireviewpro/cireviews';
				}
			}
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[} elseif ($key == 'path') {]]></search>
			<add position="replace"><![CDATA[} elseif (($data['route'] == 'cireviewpro/cireviews') || ($data['route'] == 'cireviewpro/cireviews' && $key == 'cireview_product_id')) {

					$qquery = $value;

					if( VERSION >= '3.0.0.0') {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($qquery) . "' AND language_id='". (int)$this->config->get('config_language_id') ."' AND store_id='". (int)$this->config->get('config_store_id') ."'");

						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
							if($key!='route') {
							unset($data[$key]);
							}
						}
					} else {
						$qquery.= '-'. (int)$this->config->get('store_id');

						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($qquery) . "'");

						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
							if($key!='route') {
							unset($data[$key]);
							}
						}
					}
				} elseif ($key == 'path') {	]]></add>
		</operation>
	</file>
	<file path="catalog/controller/common/seo_url.php">
		<operation error="log">
			<search><![CDATA[if ($url[0] == 'category_id') {]]></search>
			<add position="before"><![CDATA[
			if( VERSION < '3.0.0.0') {
				if($url[0] == 'cireviewpro/cireviews'.'-'.(int)$this->config->get('config_store_id')) {
					$query->row['query'] = 'cireviewpro/cireviews';
				}
			}
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[} elseif ($key == 'path') {]]></search>
			<add position="replace"><![CDATA[} elseif (($data['route'] == 'cireviewpro/cireviews') || ($data['route'] == 'cireviewpro/cireviews' && $key == 'cireview_product_id')) {

					$qquery = $value;

					if( VERSION >= '3.0.0.0') {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($qquery) . "' AND language_id='". (int)$this->config->get('config_language_id') ."' AND store_id='". (int)$this->config->get('config_store_id') ."'");

						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
							if($key!='route') {
							unset($data[$key]);
							}
						}
					} else {
						$qquery.= '-'. (int)$this->config->get('store_id');
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($qquery) . "'");

						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
							if($key!='route') {
							unset($data[$key]);
							}
						}
					}
				} elseif ($key == 'path') {	]]></add>
		</operation>
	</file>
	<!-- seo urls ends -->
</modification>