Browse code

Initial commit

Benjamin Roth authored on19/03/2019 14:48:59
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,207 @@
1
+<?php
2
+
3
+/**
4
+ * Shipment tracking for Isotope eCommerce
5
+ *
6
+ * Copyright (c) 2017 Benjamin Roth
7
+ *
8
+ * @license commercial
9
+ */
10
+
11
+/**
12
+ * Table tl_iso_shipmenttracking
13
+ */
14
+$GLOBALS['TL_DCA']['tl_iso_shipmenttracking'] = array
15
+(
16
+
17
+	// Config
18
+	'config' => array
19
+	(
20
+		'dataContainer'             => 'Table',
21
+    'enableVersioning'          => true,
22
+    'closed'                    => true,
23
+    'onload_callback' => array
24
+    (
25
+      array('\Isotope\Backend', 'initializeSetupModule'),
26
+      array('tl_iso_shipmenttracking', 'checkPermission'),
27
+      array('tl_iso_shipmenttracking', 'mandatoryCheck'),
28
+    ),
29
+    'sql' => array
30
+    (
31
+      'keys' => array
32
+      (
33
+        'id' => 'primary',
34
+      )
35
+    ),
36
+	),
37
+
38
+	// List
39
+	'list' => array
40
+	(
41
+		'sorting' => array
42
+		(
43
+      'mode'                  => 1,
44
+      'fields'                => array('name'),
45
+      'flag'                  => 1,
46
+      'panelLayout'           => 'sort,filter;search,limit',
47
+		),
48
+		'label' => array
49
+    (
50
+      'fields'                => array('name'),
51
+      'format'                => '%s',
52
+    ),
53
+		'global_operations' => array
54
+		(
55
+      'back' => array
56
+      (
57
+        'label'             => &$GLOBALS['TL_LANG']['MSC']['backBT'],
58
+        'href'              => 'mod=&table=',
59
+        'class'             => 'header_back',
60
+        'attributes'        => 'onclick="Backend.getScrollOffset();"',
61
+      ),
62
+      'new' => array
63
+      (
64
+        'label'             => &$GLOBALS['TL_LANG']['tl_iso_shipping']['new'],
65
+        'href'              => 'act=create',
66
+        'class'             => 'header_new',
67
+        'attributes'        => 'onclick="Backend.getScrollOffset();"',
68
+      ),
69
+      'all' => array
70
+      (
71
+        'label'                 => &$GLOBALS['TL_LANG']['MSC']['all'],
72
+        'href'                  => 'act=select',
73
+        'class'                 => 'header_edit_all',
74
+        'attributes'            => 'onclick="Backend.getScrollOffset()" accesskey="e"'
75
+      )
76
+		),
77
+		'operations' => array
78
+		(
79
+      'edit' => array
80
+      (
81
+        'label'               => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['edit'],
82
+        'href'                => 'act=edit',
83
+        'icon'                => 'edit.gif',
84
+      ),
85
+      'copy' => array
86
+      (
87
+        'label'                 => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['copy'],
88
+        'href'                  => 'act=copy',
89
+        'icon'                  => 'copy.gif'
90
+      ),
91
+      'delete' => array
92
+      (
93
+        'label'               => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['delete'],
94
+        'href'                => 'act=delete',
95
+        'icon'                => 'delete.gif',
96
+      ),
97
+      'toggle' => array
98
+      (
99
+        'label'               => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['toggle'],
100
+        'icon'                => 'visible.gif',
101
+        'attributes'          => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
102
+//        'button_callback'     => array('tl_iso_shipmenttracking', 'toggleIcon')
103
+      ),
104
+      'show' => array
105
+      (
106
+        'label'               => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['show'],
107
+        'icon'                => 'show.gif',
108
+      ),
109
+		)
110
+	),
111
+
112
+	// Palettes
113
+	'palettes' => array
114
+	(
115
+	  'default'                   => '{title_legend},name;{note_legend},note;{tracking_legend},trackingUrl'
116
+	),
117
+
118
+	// Subpalettes
119
+	'subpalettes' => array
120
+	(
121
+	),
122
+
123
+	// Fields
124
+	'fields' => array
125
+	(
126
+		'id' => array
127
+		(
128
+			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
129
+		),
130
+		'tstamp' => array
131
+		(
132
+			'sql'                     => "int(10) unsigned NOT NULL default '0'"
133
+		),
134
+    'name' => array
135
+    (
136
+      'exclude'                 => true,
137
+      'label'                   => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['name'],
138
+      'sorting'                 => true,
139
+      'search'                  => true,
140
+      'flag'                    => 1,
141
+      'inputType'               => 'text',
142
+      'eval'                    => array('mandatory'=>true, 'maxlength'=>255),
143
+      'sql'                     => "varchar(255) NOT NULL default ''",
144
+    ),
145
+    'note' => array
146
+    (
147
+      'label'                   => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['note'],
148
+      'exclude'                 => true,
149
+      'inputType'               => 'textarea',
150
+      'explanation'             => 'iso_shipmenttracking_placeholder',
151
+      'eval'                    => array('mandatory'=>true,'rte'=>'tinyMCE', 'decodeEntities'=>true, 'helpwizard'=>true),
152
+      'sql'                     => "text NULL",
153
+    ),
154
+    'trackingUrl' => array
155
+    (
156
+      'exclude'                 => true,
157
+      'label'                   => &$GLOBALS['TL_LANG']['tl_iso_shipmenttracking']['trackingUrl'],
158
+      'inputType'               => 'text',
159
+      'eval'                    => array('mandatory'=>false, 'rgxp'=>'url', 'maxlength'=>255, 'decodeEntities'=>true),
160
+      'sql'                     => "varchar(255) NOT NULL default ''",
161
+    ),
162
+	)
163
+);
164
+
165
+
166
+class tl_iso_shipmenttracking extends \Backend
167
+{
168
+  /**
169
+   * Import the back end user object
170
+   */
171
+  public function __construct()
172
+  {
173
+    parent::__construct();
174
+    $this->import('BackendUser', 'User');
175
+  }
176
+
177
+  /**
178
+   * Check permissions to edit table tl_iso_shipping
179
+   * @return void
180
+   */
181
+  public function checkPermission()
182
+  {
183
+    // Check permissions to add shipping modules
184
+    if (!\BackendUser::getInstance()->hasAccess(\Input::get('mod'), 'iso_modules')) {
185
+      $GLOBALS['TL_DCA']['tl_iso_shipmenttracking']['config']['closed'] = true;
186
+      unset($GLOBALS['TL_DCA']['tl_iso_shipping']['list']['global_operations']['new']);
187
+    }
188
+  }
189
+
190
+  /**
191
+   * Set fields mandatory if needed
192
+   * @param DataContainer $dc
193
+   * @return void
194
+   */
195
+  public function mandatoryCheck(\DataContainer $dc)
196
+  {
197
+    if (\Input::get('act') == 'edit')
198
+    {
199
+      $data = \Database::getInstance()->execute("SELECT note FROM $dc->table WHERE id = $dc->id");
200
+      if ($data->numRows && preg_match('/(%%TRACKING[^%]+%%)/', $data->note))
201
+      {
202
+        $GLOBALS['TL_DCA']['tl_iso_shipmenttracking']['fields']['trackingUrl']['eval']['mandatory'] = true;
203
+      }
204
+    }
205
+  }
206
+
207
+}