<?php $this->load->model('tool/image'); ?>
<?php
 // echo "<pre>"; var_dump($result); echo "</pre>"; 
?>
<div style="padding:10px 10px 0px 10px;">
	<div id="SendReminderSuccess"></div>
    <?php $result['customer_info'] = unserialize($result['customer_info']); ?>
    <form id="SendReminderCustomForm">
    	<input type="hidden" name="ABcart_id" value="<?php echo $_GET['id']; ?>" />
        <table class="table">
            <tr>
              <td width="33%"><label>To: <strong><?php if(!empty($result['customer_info']['email'])) echo $result['customer_info']['email']; ?></strong></label></td>
              <td width="33%"><label>Name: <strong><?php echo $result['customer_info']['firstname']." ". $result['customer_info']['lastname']; ?></strong></label></td>
              <td width="33%"><label>Phone: <strong><?php echo $result['customer_info']['telephone']; ?></strong></label></td>
            </tr>
        </table>
    <table class="form">
      <tr>
       <td width="20%"><span class="required">* </span>Тип скидки:</td>
       <td>
           <select name="DiscountType" > 
               <option value="P" <?php if(!empty($data['AbandonedCarts']['DiscountType']) && $data['AbandonedCarts']['DiscountType'] == "P") echo "selected"; ?>>Процентная</option>
               <option value="F" <?php if(!empty($data['AbandonedCarts']['DiscountType']) && $data['AbandonedCarts']['DiscountType'] == "F") echo "selected"; ?>>Фиксированная</option>
           </select>
       </td>
   </tr>
   <tr>
       <td><span class="required">* </span>Скидка:</td>
       <td>
        <div class="input-append">
            <input type="text" name="Discount" value="<?php if(!empty($data['AbandonedCarts']['Discount'])) echo $data['AbandonedCarts']['Discount']?>">
            <span class="add-on">
               <p style="display:none;" id="currencyAddon_custom"><?php echo $currency ?></p>
               <p style="display:none;" id="percentageAddon_custom">%</p>
           </span>
       </div>
   </td>	
</tr>
<tr>
   <td>Общая сумма: <span class="help">Общая сумма, которую должны набрать чтобы купон подействовал.</span></td>
   <td>
    <div class="input-append">
        <input type="text" name="TotalAmount" value="<?php if(!empty($data['AbandonedCarts']['TotalAmount'])) echo $data['AbandonedCarts']['TotalAmount']?>">
        <span class="add-on"><?php echo $currency ?></span>
    </div>
</td>
</tr>
<tr>
    <td><span class="required">* </span>Время действия скидки:<span class="help">Укажите, сколько дней код скидки будет активен после отправки напоминания.</span></td>
    <td><div class="input-append">
        <input type="text" value="<?php if(!empty($data['AbandonedCarts']['DiscountValidity'])) echo (int)$data['AbandonedCarts']['DiscountValidity']; else echo 7; ?>" name="DiscountValidity">
       <span class="add-on">дня(ей)</span> </div></td>
</tr>
<tr>
    <td><span class="required">*</span> Размеры изображения товара:</td>
    <td>
        <div class="input-append">
			<input class="input-mini" id="appendedInput" type="text" name="ProductWidth" value="<?php echo (isset($data['AbandonedCarts']['ProductWidth'])) ? $data['AbandonedCarts']['ProductWidth'] : '60' ?>">
          <span class="add-on">px</span>
        </div>
        <br />
		<div class="input-append">
			<input class="input-mini" id="appendedInput" type="text" name="ProductHeight" value="<?php echo (isset($data['AbandonedCarts']['ProductHeight'])) ? $data['AbandonedCarts']['ProductHeight'] : '60' ?>">
          <span class="add-on">px</span>
        </div>
   </td>
  </tr>
<tr>
   <td><span class="required">* </span>Тема: </td>
   <td><input placeholder="Mail subject" type="text" id="subject" name="Subject" value="<?php if(!empty($data['AbandonedCarts']['Subject'])) echo $data['AbandonedCarts']['Subject']; else echo "Вы забыли свою корзину :("; ?>" />
   </tr>
   <tr>
       <td><span class="required">* </span>Сообщение клиенту:<span class="help">Используйте следующие сокращения: <br /><br />
		{firstname} - имя<br />
		{lastname} - фамилия<br />
        {cart_content} - содержимое корзины<br />
		{discount_code} - код скидки<br />
        {discount_value} - значение скидки<br />
		{total_amount} - общая сумма<br />
        {date_end} - конечная дата действия купона</span></td> 
       <td>
           <textarea id="Message_Custom1">
               <?php if(!empty($data['AbandonedCarts']['Message'])) echo $data['AbandonedCarts']['Message']; else echo "Some text message!"; ?>
           </textarea>
       </td>
   </tr>
   <tr>
    <td>Дополнительные опции:</td>
    <td>
        <label class="checkbox">
          <input type="checkbox" name="RemoveAfterSend" value="yes" <?php echo !empty($data['AbandonedCarts']['RemoveAfterSend']) ? 'checked="checked"' : ''; ?>/>
         Удалить записи заброшенных корзин после отправки сообщений
        </label>
   </td>
  </tr>
</table>
		<a class="btn btn-primary" id="sendMail">Отправить письмо</a>
    </form>
</div>
<script type="text/javascript" >
CKEDITOR.replace('Message_Custom1', { 
    filebrowserBrowseUrl: 'index.php?route=common/filemanager&token' + getURLVar('token'),
    filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=' + getURLVar('token'),
    filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=' + getURLVar('token'),
    filebrowserUploadUrl: 'index.php?route=common/filemanager&token=' + getURLVar('token'),
    filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=' + getURLVar('token'),
    filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=' + getURLVar('token') 
});
if($('select[name="DiscountType"]').val() == 'P'){
	$('#percentageAddon_custom').show();
} else {
	$('#currencyAddon_custom').show();
}
$('select[name="DiscountType"]').on('change', function(e){ 
	if($(this).val() == 'P') {
		$('#percentageAddon_custom').show();
		$('#currencyAddon_custom').hide();
	} else {
		$('#currencyAddon_custom').show();
		$('#percentageAddon_custom').hide();
	}	
});
</script>
<script>
$('#sendMail').on('click', function(){
	var email_validate = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var email = "<?php echo $result['customer_info']['email']; ?>";
	if (!email.match(email_validate)) {
		alert("The email entered by the customer is invalid.")
	} else {
		$.ajax({
			url: 'index.php?route=module/abandonedcarts/sendcustomemail&token=' + getURLVar('token'),
			type: 'post',
			data: $('#SendReminderCustomForm').serialize()+'&CustomMessage='+CKEDITOR.instances['Message_Custom1'].getData(),
			success: function(response) {
				parent.$.fn.colorbox.close();
				//$('#SendReminderSuccess').html("<div class='success' style='display: none;'>"+ response +"</div>");
				//$('.success').fadeIn('slow');
			}
		});
	}
});
</script>