| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Types; |
| 4 |
|
| 5 |
use AcyMailing\Core\AcymObject; |
| 6 |
|
| 7 |
class DelayType extends AcymObject |
| 8 |
{ |
| 9 |
var $values = []; |
| 10 |
var $num = 0; |
| 11 |
var $onChange = ''; |
| 12 |
|
| 13 |
public function display($map, $value, $type = 1, $num = '', $inputClass = '', $hiddenInputClass = '') |
| 14 |
{ |
| 15 |
static $i = 0; |
| 16 |
$i++; |
| 17 |
$this->num = $i; |
| 18 |
|
| 19 |
if (empty($num)) { |
| 20 |
$js = ' |
| 21 |
function updateDelay'.$this->num.'(){ |
| 22 |
delayvar = window.document.getElementById("delayvar'.$this->num.'"); |
| 23 |
delaytype = window.document.getElementById("delaytype'.$this->num.'").value; |
| 24 |
delayvalue = window.document.getElementById("delayvalue'.$this->num.'"); |
| 25 |
realValue = delayvalue.value; |
| 26 |
if(delaytype == "minute"){ realValue = realValue*60; } |
| 27 |
if(delaytype == "hour"){ realValue = realValue*3600; } |
| 28 |
if(delaytype == "day"){ realValue = realValue*86400; } |
| 29 |
if(delaytype == "week"){ realValue = realValue*604800; } |
| 30 |
if(delaytype == "month"){ realValue = realValue*2592000; } |
| 31 |
delayvar.value = realValue; |
| 32 |
delayvar.dispatchEvent(new Event("change")); |
| 33 |
}'; |
| 34 |
$updateFunction = 'updateDelay'.$this->num.'();'; |
| 35 |
} else { |
| 36 |
$js = ' |
| 37 |
function updateDelayNum(num){ |
| 38 |
delayvar = window.document.getElementById("delayvar"+num); |
| 39 |
delaytype = window.document.getElementById("delaytype"+num).value; |
| 40 |
delayvalue = window.document.getElementById("delayvalue"+num); |
| 41 |
realValue = delayvalue.value; |
| 42 |
if(delaytype == "minute"){ realValue = realValue*60; } |
| 43 |
if(delaytype == "hour"){ realValue = realValue*3600; } |
| 44 |
if(delaytype == "day"){ realValue = realValue*86400; } |
| 45 |
if(delaytype == "week"){ realValue = realValue*604800; } |
| 46 |
if(delaytype == "month"){ realValue = realValue*2592000; } |
| 47 |
delayvar.value = realValue; |
| 48 |
}'; |
| 49 |
$updateFunction = 'updateDelayNum(\''.$num.'\');'; |
| 50 |
$this->num = $num; |
| 51 |
} |
| 52 |
acym_addScript(true, $js); |
| 53 |
|
| 54 |
$this->values = []; |
| 55 |
|
| 56 |
if ($type == 0) { |
| 57 |
$this->values[] = acym_selectOption('second', 'ACYM_SECONDS'); |
| 58 |
$this->values[] = acym_selectOption('minute', 'ACYM_MINUTES'); |
| 59 |
} elseif ($type == 1) { |
| 60 |
$this->values[] = acym_selectOption('minute', 'ACYM_MINUTES'); |
| 61 |
$this->values[] = acym_selectOption('hour', 'ACYM_HOURS'); |
| 62 |
$this->values[] = acym_selectOption('day', 'ACYM_DAYS'); |
| 63 |
$this->values[] = acym_selectOption('week', 'ACYM_WEEKS'); |
| 64 |
} elseif ($type == 2) { |
| 65 |
$this->values[] = acym_selectOption('minute', 'ACYM_MINUTES'); |
| 66 |
$this->values[] = acym_selectOption('hour', 'ACYM_HOURS'); |
| 67 |
} elseif ($type == 3) { |
| 68 |
$this->values[] = acym_selectOption('hour', 'ACYM_HOURS'); |
| 69 |
$this->values[] = acym_selectOption('day', 'ACYM_DAYS'); |
| 70 |
$this->values[] = acym_selectOption('week', 'ACYM_WEEKS'); |
| 71 |
$this->values[] = acym_selectOption('month', 'ACYM_MONTHS'); |
| 72 |
} elseif ($type == 4) { |
| 73 |
$this->values[] = acym_selectOption('week', 'ACYM_WEEKS'); |
| 74 |
$this->values[] = acym_selectOption('month', 'ACYM_MONTHS'); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
$return = $this->get($value, $type); |
| 79 |
$delayValue = '<input class="intext_input '.$inputClass.'" onchange="'.$updateFunction.$this->onChange.'" type="number" min="0" id="delayvalue'.$this->num.'" value="'.$return->value.'" /> '; |
| 80 |
$delayVar = '<input class="'.$hiddenInputClass.'" type="hidden" name="'.$map.'" id="delayvar'.$this->num.'" value="'.$value.'"/>'; |
| 81 |
|
| 82 |
return $delayValue.acym_select( |
| 83 |
$this->values, |
| 84 |
'delaytype'.$this->num, |
| 85 |
$return->type, |
| 86 |
[ |
| 87 |
'class' => 'intext_select', |
| 88 |
'onchange' => $updateFunction.$this->onChange, |
| 89 |
], |
| 90 |
'value', |
| 91 |
'text', |
| 92 |
'delaytype'.$this->num |
| 93 |
).$delayVar; |
| 94 |
} |
| 95 |
|
| 96 |
public function get($value, $type) |
| 97 |
{ |
| 98 |
|
| 99 |
$return = new \stdClass(); |
| 100 |
|
| 101 |
$return->value = $value; |
| 102 |
if ($type == 0) { |
| 103 |
$return->type = 'second'; |
| 104 |
$return->typeText = acym_translation('ACYM_SECONDS'); |
| 105 |
} else { |
| 106 |
$return->type = 'minute'; |
| 107 |
$return->typeText = acym_translation('ACYM_MINUTES'); |
| 108 |
} |
| 109 |
|
| 110 |
if ($return->value >= 60 && $return->value % 60 == 0) { |
| 111 |
$return->value = (int)$return->value / 60; |
| 112 |
$return->type = 'minute'; |
| 113 |
$return->typeText = acym_translation('ACYM_MINUTES'); |
| 114 |
if ($type != 0 && $return->value >= 60 && $return->value % 60 == 0) { |
| 115 |
$return->type = 'hour'; |
| 116 |
$return->typeText = acym_translation('ACYM_HOURS'); |
| 117 |
$return->value = $return->value / 60; |
| 118 |
if ($type != 2 && $return->value >= 24 && $return->value % 24 == 0) { |
| 119 |
$return->type = 'day'; |
| 120 |
$return->typeText = acym_translation('ACYM_DAYS'); |
| 121 |
$return->value = $return->value / 24; |
| 122 |
if ($type >= 3 && $return->value >= 30 && $return->value % 30 == 0) { |
| 123 |
$return->type = 'month'; |
| 124 |
$return->typeText = acym_translation('ACYM_MONTHS'); |
| 125 |
$return->value = $return->value / 30; |
| 126 |
} elseif ($return->value >= 7 && $return->value % 7 == 0) { |
| 127 |
$return->type = 'week'; |
| 128 |
$return->typeText = acym_translation('ACYM_WEEKS'); |
| 129 |
$return->value = $return->value / 7; |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
return $return; |
| 136 |
} |
| 137 |
} |
| 138 |
|