<?php
/* Copyright (C) 2017  Laurent Destailleur  <eldy@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 *
 * Need to have following variables defined:
 * $object (invoice, order, ...)
 * $action
 * $conf
 * $langs
 * $form
 */

// Protection to avoid direct call of template
if (empty($conf) || !is_object($conf)) {
	print "Error, template page can't be called as URL";
	exit;
}

?>
<!-- BEGIN PHP TEMPLATE commonfields_add.tpl.php -->
<?php

$object->fields = dol_sort_array($object->fields, 'position');

foreach ($object->fields as $key => $val) {
	// Discard if extrafield is a hidden field on form
	if (abs($val['visible']) != 1 && abs($val['visible']) != 3) {
		continue;
	}

	if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
		continue; // We don't want this field
	}

	print '<tr class="field_' . $key . '">';
	print '<td';
	print ' class="titlefieldcreate';
	if (isset($val['notnull']) && $val['notnull'] > 0) {
		print ' fieldrequired';
	}
	if ($val['type'] == 'text' || $val['type'] == 'html') {
		print ' tdtop';
	}
	print '"';
	print '>';
	if (!empty($val['help'])) {
		print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
	} else {
		print $langs->trans($val['label']);
	}
	print '</td>';
	print '<td class="valuefieldcreate">';
	if (!empty($val['picto'])) {
		print img_picto('', $val['picto'], '', false, 0, 0, '', 'pictofixedwidth');
	}
	if (in_array($val['type'], array('int', 'integer'))) {
		$value = GETPOST($key, 'int');
	} elseif ($val['type'] == 'double') {
		$value = price2num(GETPOST($key, 'alphanohtml'));
	} elseif ($val['type'] == 'text' || $val['type'] == 'html') {
		$value = GETPOST($key, 'restricthtml');
	} elseif ($val['type'] == 'date') {
		$value = dol_mktime(12, 0, 0, GETPOST($key . 'month', 'int'), GETPOST($key . 'day', 'int'), GETPOST($key . 'year', 'int'));
	} elseif ($val['type'] == 'datetime') {
		$value = dol_mktime(GETPOST($key . 'hour', 'int'), GETPOST($key . 'min', 'int'), 0, GETPOST($key . 'month', 'int'), GETPOST($key . 'day', 'int'), GETPOST($key . 'year', 'int'));
	} elseif ($val['type'] == 'boolean') {
		$value = (GETPOST($key) == 'on' ? 1 : 0);
	} elseif ($val['type'] == 'price') {
		$value = price2num(GETPOST($key));
	} elseif ($key == 'lang') {
		$value = GETPOST($key, 'aZ09');
	} else {
		$value = GETPOST($key, 'alphanohtml');
	}
	if (!empty($val['noteditable'])) {
		print $object->showOutputField($val, $key, $value, '', '', '', 0);
	} else {
		if ($key == 'lang') {
			print img_picto('', 'language', 'class="pictofixedwidth"');
			print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
		} elseif ($key == 'package_id') {
			print '<input type="hidden" name="' . $key . '" value="' . $value . '">';
			print $object->showInputField($val, $key, $value, 'disabled', '', '', 'minwidth500', 0);
		} elseif ($key == 'user_id') {
			$selectableUsers = $helper->getSelectableUsers(GETPOST('fk_group_id', 'int'));
			print '<select id="user_id" name="' . $key . '" class="flat minwidth500 --success select2-hidden-accessible" tabindex="-1" data-select2-id="user_id" name="user_id" aria-hidden="true">';
			print '<option value="-1">' . $langs->trans('SelectUser') . '</option>';
			foreach ($selectableUsers as $userKey => $userValue) {
				print '<option value="' . $userKey . '">' . $userValue . '</option>';
			}
			print '</select>';
			//print '<span class="select2 select2-container select2-container--default select2-container--below select2-container--focus" dir="ltr" data-select2-id="3" style="width: 500px;"><span class="selection"><span class="select2-selection select2-selection--single flat minwidth500 --success" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-user_id-container"><span class="select2-selection__rendered" id="select2-user_id-container" role="textbox" aria-readonly="true" title="&nbsp;"><span class="placeholder">&nbsp;</span></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>';
		} elseif ($key == 'fk_group_id') {
			print '<input type="hidden" name="' . $key . '" value="' . $value . '">';
			print $object->showInputField($val, $key, $value, 'disabled', '', '', 'minwidth500', 0);
		} elseif ($key == 'fk_groupuser_id') {
			print '<input type="hidden" name="' . $key . '" value="' . $value . '">';
			print $object->showInputField($val, $key, $value, 'disabled', '', '', 'minwidth500', 0);
		} elseif ($key == 'income_pdf') {
			//print $object->showInputField($val, $key, $value, '', '', '', 0);
		} elseif ($key == 'delivery_pdf') {
			//print $object->showInputField($val, $key, $value, '', '', '', 0);
		} elseif ($key == 'status') {
			print '<input type="hidden" name="' . $key . '" value="0">';
			print $object->showInputField($val, $key, 0, 'disabled', '', '', 0);
		} else {
			print $object->showInputField($val, $key, $value, '', '', '', 0);
		}
	}
	print '</td>';
	print '</tr>';
}
$Block1stData = $dailyClosing->get1stBlocHistorykData($package_id);
$BLock2ndData = $helper->get2ndBlockData($package_id);
$changeMoney = $helper->getChanges();
$changeMoneyHUF = $changeMoney[0]['title'];
$changeMoneyEUR = $changeMoney[1]['title'];

print '<div id="DCuserData" style="width: 100%, height:100%">';
print '<table style="width:50%;">';
print '<tr><td colspan="4">&nbsp;</td></tr>';
print '<tr><td colspan="4"><div class="center devicelist">' . $langs->trans('DevicesList') . '</div></td></tr>';
if ($BLock2ndData) {
	foreach ($BLock2ndData as $device) {
		print '<tr style="height: 35px;"><td style="width:200px;">' . $device['ref'] . '</td><td style="width:350px;">' . $device['title'] . '</td><td></td><td class="fields"></td></tr>';
	}
}else{
	print '<tr style="height: 35px;"><td colspan="3"><font style="color:red;">' . $langs->trans('emptyPackage') . '</font></td></tr>';
}
if (isset($JSON->block3)) {
	foreach ($JSON->block3 as $changeKey => $changeValue) {

	}
}
print '<tr style="height: 35px;"><td style="width:200px;">Change HUF</td><td style="width:350px;">' . $helper->correctNumber($changeMoneyHUF) . ' HUF</td><td></td><td class="fields"></td></tr>';
print '<tr style="height: 35px;"><td style="width:200px;">Change EUR</td><td style="width:350px;">' . $helper->correctNumber($changeMoneyEUR) . ' EUR</td><td></td><td class="fields"></td></tr>';
print '<tr style="height: 35px;"><td style="width:200px;">Budapest Card</td><td><input class="inputfieldclass" type="text" name="bpcard"></td><td class="fields">' . $langs->trans('Pieces')  . '</td></tr>';
print '<tr style="height: 35px;"><td style="width:200px;">Dinner & Cruise</td><td><input class="inputfieldclass" type="text" name="dandc"></td><td class="fields"></td></tr>';
print '<tr style="height: 35px;"><td style="width:200px;">RiverRide</td><td><input class="inputfieldclass" type="text" name="riverride"></td><td class="fields"></td></tr>';

?>
<style>
	.cursorNotAllowed {
		cursor: not-allowed;
	}

	.inputfieldclass {
		width: 300px;
	}

	.devicelist {
		display: block;
		height: 30px;
		padding-top: 10px;
		width: 100%;
		background-color: darkgrey;
		border-radius: 10px 10px 0px 0px;
		color: white;
	}
</style>
<script>
	$(document).ready(function () {
		$('#user_id').select2({
			dir: 'ltr',
			width: 'resolve',
			minimumInputLength: 0,
			language: select2arrayoflanguage,
			containerCssClass: ':all:',
			selectionCssClass: ':all:',
			templateResult: function (data, container) {
				if (data.element) { $(container).addClass($(data.element).attr("class")); }
				if (data.id == -1 && $(data.element).attr("data-html") == undefined) {
					return '&nbsp;';
				}
				if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html"));		// If property html set, we decode html entities and use this
				return data.text;
			},
			templateSelection: function (selection) {
				if (selection.id == -1) return '<span class="placeholder">' + selection.text + '</span>';
				return selection.text;
			},
			escapeMarkup: function (markup) {
				return markup;
			},
			dropdownCssClass: 'ui-dialog'
		});
	});
</script>
<!-- END PHP TEMPLATE commonfields_add.tpl.php -->