<?xml version="1.0" encoding="utf-8"?>
<modification>
	<code>clicker_elfinder</code>
	<name>Cl!cker Elfinder Filemanager - OC 3.x</name>
	<version>3.6.2_E2.1.60n</version>
	<author>Cl!cker</author>
	<link>https://opencart.click</link>

	<file path="admin/controller/common/filemanager.php">
		<operation>
			<search trim="true" index="0"><![CDATA[
				public function index() {
			]]></search>
			<add position="replace" trim="false" offset="0"><![CDATA[
				public function index() {
					if (!$this->user->hasPermission('access', 'extension/elfinder')) {
						$this->index_fm();
						return;
					}

					$data = $this->language->load('extension/elfinder');

					if (version_compare(VERSION, '3.0.0') >= 0) {
						$data['token_name'] = 'user_token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					} else {
						$data['token_name'] = 'token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					}

					$data['connector_url'] = $this->url->link('extension/elfinder/connector', $data['token_name'] . '=' . $data['user_token'], true);
					$data['setting_url'] = $this->url->link('extension/elfinder/setting', $data['token_name'] . '=' . $data['user_token'], true);
					$data['el_setting'] = $this->load->controller('extension/elfinder/getsetting');

					$data['modal'] = true;
					$data['iframe'] = false;

					$data['thumb_image'] = !empty($this->request->get['thumb']) ? $this->request->get['thumb'] : '';
					$data['target_image'] = !empty($this->request->get['target']) ? $this->request->get['target'] : '';
					$data['multiple'] = !empty($this->request->get['multiple']) ? $this->request->get['multiple'] : '';
					$data['CKEditor'] = !empty($this->request->get['CKEditor']) ? $this->request->get['CKEditor'] : '';
					$data['CKEditorFuncNum'] = !empty($this->request->get['CKEditorFuncNum']) ? $this->request->get['CKEditorFuncNum'] : '';

					$data['version'] = $this->load->controller('extension/elfinder/getversion');
					$data['oc_version'] = defined('VERSION') ? VERSION : 0;

					if (!empty($data['CKEditorFuncNum'])) {
						$data['iframe'] = true;
						//$this->el_iframe();
						//return true;
					}

					$params = !empty($this->request->get) ? $this->request->get : array($data['token_name'] => $data['user_token']);

					if (isset($params['route'])) {
						unset($params['route']);
					}

					$data['iframe_link'] = $this->url->link('common/filemanager/el_iframe', http_build_query($params), true);

					$this->response->setOutput($this->load->view('extension/elfinder', $data));
				}

				public function el_iframe() {
					if (!$this->user->hasPermission('access', 'extension/elfinder')) {
						die('Permission extension/elfinder denied!');
						return;
					}

					$data = $this->language->load('extension/elfinder');

					$data['title'] = $this->language->get('heading_title');
					$data['lang'] = $this->language->get('code');
					$data['direction'] = $this->language->get('direction');

					if (version_compare(VERSION, '3.0.0') >= 0) {
						$data['token_name'] = 'user_token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					} else {
						$data['token_name'] = 'token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					}

					$data['connector_url'] = $this->url->link('extension/elfinder/connector', $data['token_name'] . '=' . $data['user_token'], true);
					$data['setting_url'] = $this->url->link('extension/elfinder/setting', $data['token_name'] . '=' . $data['user_token'], true);
					$data['el_setting'] = $this->load->controller('extension/elfinder/getsetting');

					$data['iframe'] = true;
					$data['modal'] = false;

					$data['thumb_image'] = !empty($this->request->get['thumb']) ? $this->request->get['thumb'] : '';
					$data['target_image'] = !empty($this->request->get['target']) ? $this->request->get['target'] : '';
					$data['multiple'] = !empty($this->request->get['multiple']) ? $this->request->get['multiple'] : '';
					$data['CKEditor'] = !empty($this->request->get['CKEditor']) ? $this->request->get['CKEditor'] : '';
					$data['CKEditorFuncNum'] = !empty($this->request->get['CKEditorFuncNum']) ? $this->request->get['CKEditorFuncNum'] : '';

					$data['version'] = $this->load->controller('extension/elfinder/getversion');
					$data['oc_version'] = defined('VERSION') ? VERSION : 0;

					$this->response->setOutput($this->load->view('extension/elfinder', $data));
				}

				public function index_fm() {
			]]></add>
		</operation>
	</file>

	<file path="admin/controller/common/column_left.php">
		<operation>
			<search trim="true" index="0"><![CDATA[
				$marketplace = array();
			]]></search>
			<add position="after" trim="false" offset="0"><![CDATA[
				if ($this->user->hasPermission('access', 'extension/elfinder')) {
					if (version_compare(VERSION, '3.0.0') >= 0) {
						$data['token_name'] = 'user_token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					} else {
						$data['token_name'] = 'token';
						$data['user_token'] = $this->session->data[$data['token_name']];
					}

					$this->language->load('extension/elfinder');
					$marketplace[] = array(
						'name'	   => $this->language->get('text_filemanager'),
						'href'     => $this->url->link('extension/elfinder', $data['token_name'] . '='. $data['user_token'], true),
						'children' => array()
					);
				}
			]]></add>
		</operation>
	</file>

	<file path="admin/view/template/catalog/product_form.twig">
		<operation>
			<search trim="true" index="0"><![CDATA[
				{{ footer }}
			]]></search>
			<add position="before" trim="false" offset="0"><![CDATA[
				<script type="text/javascript">
					$(document).ready(function() {
						var html = '&nbsp;&nbsp;<button type="button" onclick="addMultipleImages(this);" data-toggle="tooltip" title="Add multiple images" class="btn btn-success"><i class="fa fa-list"></i></button>';
						html += '<input type="hidden" id="elfinder_multiple" value=""/>';
						$('button[onclick*="addImage("]').after(html);
					});

					function addMultipleImages(btn) {
						var $button = $(btn);

						$('#modal-image').remove();

						if (getURLVar('user_token')) {
							var user_token = '&user_token=' + getURLVar('user_token');
						} else {
							var user_token = '&token=' + getURLVar('token');
						}

						$.ajax({
						  url: 'index.php?route=common/filemanager' + user_token + '&multiple=callbackMultipleImages&target=elfinder_multiple&thumb=placeholder',
							dataType: 'html',
							beforeSend: function() {
								$button.prop('disabled', true);
							},
							complete: function() {
								$button.prop('disabled', false);
							},
							success: function(html) {
								$('body').append('<div id="modal-image" class="modal">' + html + '</div>');

								$('#modal-image').modal('show');
							}
						});
					}

					function callbackMultipleImages(data={}) {
						if (!data) return;

						for (idx in data) {
							if (data[idx].mime) {
								var file = data[idx];
								if (file.path && (String(file.path).substring(0, 6) == 'image\\' || String(file.path).substring(0, 6) == 'image/')) {
									// Fix root for image folder if default is not image/catalog
									file.path = String(file.path).substring(6);
								}

								var curr_image_row = image_row;
								addImage();

								$('#thumb-image' + curr_image_row + ' img').attr('src', file.tmb).css('max-width', '100%');
								$('#input-image' + curr_image_row + '').val(file.path);
								$('input[name="product_image[' + curr_image_row + '][sort_order]"]').val(curr_image_row);
							}
						}
					}
				</script>
			]]></add>
		</operation>
	</file>

</modification>