1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
<?php
/** @version 4.6.1 */
$data = $this->view['template_data'];
$campaigns = isset($this->view['template_campaigns']) && is_array($this->view['template_campaigns']) ? $this->view['template_campaigns'] : array();
$triggerEventOptions = isset($this->view['template_trigger_event_options']) && is_array($this->view['template_trigger_event_options']) ? $this->view['template_trigger_event_options'] : array();
$triggerValueOptions = isset($this->view['template_trigger_value_options']) && is_array($this->view['template_trigger_value_options']) ? $this->view['template_trigger_value_options'] : array();
$assignedCampaignIds = isset($data['assigned_campaign_ids']) && is_array($data['assigned_campaign_ids']) ? array_map('intval', $data['assigned_campaign_ids']) : array();
$isEdit = intval($data['id']) > 0;
$triggerStatusOptions = isset($this->view['template_trigger_status_options']) && is_array($this->view['template_trigger_status_options']) ? $this->view['template_trigger_status_options'] : array();
$selectedTriggerEvent = (string)$data['trigger_event'];
$selectedTriggerValue = (string)$data['trigger_value'];
$selectedTriggerProduct = (($data['trigger_product'] === null || $data['trigger_product'] === '')?'':(string)intval($data['trigger_product']));
$bStatusTrigger = ($selectedTriggerEvent === 'order_status');
?>
<div class="wrap columns-2 wpng_template_addedit">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h2>
<?php echo __('Versandprofile', 'wpsg'); ?> - <?php echo $isEdit ? __('Bearbeiten', 'wpsg') : __('Neu hinzufügen', 'wpsg'); ?>
</h2>
<form method="post" action="<?php echo esc_url(admin_url('admin.php?page=wpng-mod_template&wpng_action=save&noheader=1')); ?>">
<?php wp_nonce_field('wpsg-campaigns-save'); ?>
<input type="hidden" name="id" value="<?php echo intval($data['id']); ?>" />
<div class="metabox-holder has-right-sidebar wpng_metabox-holder">
<div id="side-info-column" class="inner-sidebar" style="width:386px;">
<div id="side-sortables" class="meta-box-sortables ui-sortable" style="width:380px;">
<div class="postbox">
<h3 class="postbox-header"><?php echo __('Einstellungen', 'wpsg'); ?></h3>
<div class="inside">
<!-- <p>-->
<!-- <label><input type="checkbox" id="status" name="status" value="1" --><?php //checked(intval($data['status']), 1); ?><!-- /> --><?php //echo __('Aktiv', 'wpsg'); ?><!--</label>-->
<!-- </p>-->
<p class="submit">
<input type="submit" class="button-primary" name="submit" value="<?php echo __('Speichern', 'wpsg'); ?>" />
<input type="submit" class="button" name="submit_index" value="<?php echo __('Speichern und zur Übersicht', 'wpsg'); ?>" />
</p>
</div>
</div>
<div class="postbox">
<h3 class="postbox-header"><?php echo __('Kampagnen-Zuordnung', 'wpsg'); ?></h3>
<div class="inside">
<p>
<label for="campaign_ids"><strong><?php echo __('Kampagnen', 'wpsg'); ?></strong></label><br />
<select id="campaign_ids" name="campaign_ids[]" multiple="multiple" size="8" style="width:100%;">
<?php foreach ($campaigns as $campaign) { ?>
<?php $campaignId = intval($campaign['id']); ?>
<option value="<?php echo $campaignId; ?>" <?php echo in_array($campaignId, $assignedCampaignIds, true) ? 'selected="selected"' : ''; ?>>
<?php echo esc_html($campaign['name']); ?>
</option>
<?php } ?>
</select>
<small><?php echo __('Mehrfachauswahl: Strg/Cmd gedrückt halten.', 'wpsg'); ?></small>
</p>
</div>
</div>
</div>
</div>
<div id="post-body">
<div id="titlediv" style="margin-right:400px;">
<div id="titlewrap">
<input type="text" value="<?php echo esc_attr($data['name']); ?>" size="30" name="name" id="title" required />
</div>
</div>
<br />
<div id="normal-sortables" class="meta-box-sortables" style="margin-right:400px; width:initial !important;">
<div class="postbox">
<!-- <p>-->
<!-- <label><input type="checkbox" id="status" name="status" value="1" --><?php //checked(intval($data['status']), 1); ?><!-- /> --><?php //echo __('Aktiv', 'wpsg'); ?><!--</label>-->
<!-- </p>-->
</div>
<div class="postbox">
<h3 class="postbox-header"><?php echo __('Auslöser', 'wpsg'); ?></h3>
<div class="inside">
<p>
<label for="trigger_event"><strong><?php echo __('Trigger Event', 'wpsg'); ?></strong></label><br />
<select class="widefat" id="trigger_event" name="trigger_event">
<option value="" <?php selected($selectedTriggerEvent, ''); ?>><?php echo __('Bitte auswählen', 'wpsg'); ?></option>
<?php foreach ($triggerEventOptions as $eventKey => $eventLabel) { ?>
<option value="<?php echo esc_attr($eventKey); ?>" <?php selected($selectedTriggerEvent, $eventKey); ?>><?php echo esc_html($eventLabel); ?></option>
<?php } ?>
<?php if ($selectedTriggerEvent !== '' && !isset($triggerEventOptions[$selectedTriggerEvent])) { ?>
<option value="<?php echo esc_attr($selectedTriggerEvent); ?>" selected="selected"><?php echo esc_html($selectedTriggerEvent); ?></option>
<?php } ?>
</select>
</p>
<p id="wpsg_trigger_value_product_wrap"<?php if ($bStatusTrigger) { ?> style="display:none;"<?php } ?>>
<label for="trigger_value"><strong><?php echo __('Trigger Wert (Produkt)', 'wpsg'); ?></strong></label><br />
<select class="widefat" id="trigger_value" name="trigger_value"<?php if ($bStatusTrigger) { ?> disabled="disabled"<?php } ?>>
<option value=""><?php echo __('Produkt auswählen', 'wpsg'); ?></option>
<?php foreach ($triggerValueOptions as $productId => $productName) { ?>
<?php $productId = (string)intval($productId); ?>
<option value="<?php echo esc_attr($productId); ?>" <?php selected($selectedTriggerValue, $productId); ?>>
<?php echo esc_html($productName); ?> (<?php echo intval($productId); ?>)
</option>
<?php } ?>
<?php if (!$bStatusTrigger && $selectedTriggerValue !== '' && !isset($triggerValueOptions[intval($selectedTriggerValue)])) { ?>
<option value="<?php echo esc_attr($selectedTriggerValue); ?>" selected="selected"><?php echo esc_html($selectedTriggerValue); ?></option>
<?php } ?>
</select>
<small><?php echo __('Für Trigger "WPSG: Produktkauf" wird hier die Produkt-ID ausgewählt.', 'wpsg'); ?></small>
</p>
<p id="wpsg_trigger_value_status_wrap"<?php if (!$bStatusTrigger) { ?> style="display:none;"<?php } ?>>
<label for="trigger_value_status"><strong><?php echo __('Trigger Wert (Zielstatus)', 'wpsg'); ?></strong></label><br />
<select class="widefat" id="trigger_value_status" name="trigger_value"<?php if (!$bStatusTrigger) { ?> disabled="disabled"<?php } ?>>
<option value=""><?php echo __('Bitte auswählen', 'wpsg'); ?></option>
<?php foreach ($triggerStatusOptions as $statusKey => $statusLabel) { ?>
<option value="<?php echo esc_attr((string)$statusKey); ?>" <?php selected($selectedTriggerValue, (string)$statusKey); ?>><?php echo esc_html($statusLabel); ?></option>
<?php } ?>
</select>
<small><?php echo __('Die Kampagne wird ausgelöst, sobald eine Bestellung diesen Status erreicht.', 'wpsg'); ?></small>
</p>
<p id="wpsg_trigger_product_wrap"<?php if (!$bStatusTrigger) { ?> style="display:none;"<?php } ?>>
<label for="trigger_product"><strong><?php echo __('Produkt (optional)', 'wpsg'); ?></strong></label><br />
<select class="widefat" id="trigger_product" name="trigger_product"<?php if (!$bStatusTrigger) { ?> disabled="disabled"<?php } ?>>
<option value=""><?php echo __('Alle Bestellungen', 'wpsg'); ?></option>
<?php foreach ($triggerValueOptions as $productId => $productName) { ?>
<?php $productId = (string)intval($productId); ?>
<option value="<?php echo esc_attr($productId); ?>" <?php selected($selectedTriggerProduct, $productId); ?>>
<?php echo esc_html($productName); ?> (<?php echo intval($productId); ?>)
</option>
<?php } ?>
</select>
<small><?php echo __('Ohne Auswahl gilt die Kampagne für jede Bestellung, die den Zielstatus erreicht.', 'wpsg'); ?></small>
</p>
</div>
</div>
<p>
<label for="delay_value"><strong><?php echo __('Verzögerung', 'wpsg'); ?></strong></label><br />
<input type="number" min="0" id="delay_value" name="delay_value" value="<?php echo intval($data['delay_value']); ?>" style="width:120px;" />
<select id="delay_unit" name="delay_unit">
<?php $units = $this->callMod('wpsg_mod_campaigns', 'getDelayUnitOptions'); if (!is_array($units)) $units = array(); foreach ($units as $unit => $unitLabel) { ?>
<option value="<?php echo esc_attr($unit); ?>" <?php selected($data['delay_unit'], $unit); ?>><?php echo esc_html($unitLabel); ?></option>
<?php } ?>
</select>
</p>
<div class="postbox">
<h3 class="postbox-header"><?php echo __('Bedingungen', 'wpsg'); ?></h3>
<div class="inside">
<?php include(WPSG_PATH_VIEW . '/mods/mod_campaigns/conditions_fields.phtml'); ?>
</div>
</div>
<?php /* "Aktionen"-Block vorerst deaktiviert: aktuell werden ausschließlich E-Mails
versendet, daher ist keine separate Aktionsdefinition nötig. Für spätere
Aktionstypen (siehe Doku-Ausblick) wieder aktivieren und dazu eine Spalte
`actions` anlegen sowie in saveTemplateAction() einlesen.
<div class="postbox">
<h3 class="postbox-header"><?php echo __('Aktionen', 'wpsg'); ?></h3>
<div class="inside">
<textarea id="actions" name="actions" rows="10" class="large-text code"><?php echo esc_textarea($data['actions']); ?></textarea>
</div>
</div>
*/ ?>
</div>
<p class="submit">
<input type="submit" class="button-primary" name="submit" value="<?php echo __('Speichern', 'wpsg'); ?>" />
<input type="submit" class="button" name="submit_index" value="<?php echo __('Speichern und zur Übersicht', 'wpsg'); ?>" />
</p>
</div>
</div>
</form>
</div>
<script type="text/javascript">/* <![CDATA[ */
/**
* Schaltet die Trigger-Felder passend zum gewaehlten Ereignis um. Das jeweils nicht
* benutzte Feld wird zusaetzlich deaktiviert, damit es nicht mitgesendet wird — beide
* Auswahlfelder heissen trigger_value.
*/
( function() {
var elEvent = document.getElementById('trigger_event');
if (!elEvent) return;
function wpsgToggleTrigger() {
var bStatus = (elEvent.value === 'order_status');
[
['wpsg_trigger_value_product_wrap', 'trigger_value', !bStatus],
['wpsg_trigger_value_status_wrap', 'trigger_value_status', bStatus],
['wpsg_trigger_product_wrap', 'trigger_product', bStatus]
].forEach(function(a) {
var elWrap = document.getElementById(a[0]);
var elField = document.getElementById(a[1]);
if (elWrap) elWrap.style.display = (a[2] ? '' : 'none');
if (elField) elField.disabled = !a[2];
});
// Der Bestellstatus als Bedingung ergibt nur beim Statuswechsel-Trigger Sinn.
var elCond = document.getElementById('wpsg_cond_order_status_wrap');
if (elCond) elCond.style.display = (bStatus ? '' : 'none');
}
elEvent.addEventListener('change', wpsgToggleTrigger);
wpsgToggleTrigger();
} )();
/* ]]> */</script>
|