Browse code

Initial commit

Benjamin Roth authored on26/03/2015 15:24:56
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,305 @@
1
+<?php
2
+
3
+/**
4
+ * References for Contao
5
+ *
6
+ * Copyright (c) 2014 Benjamin Roth [http://www.esales-media.de]
7
+ *
8
+ * @package eSM_clients
9
+ * @link    http://www.esales-media.de
10
+ * @license commercial
11
+ */
12
+
13
+/**
14
+ * Table tl_esm_clients_settings
15
+ */
16
+$GLOBALS['TL_DCA']['tl_esm_clients_settings'] = array
17
+(
18
+
19
+	// Config
20
+	'config' => array
21
+	(
22
+		'dataContainer'               => 'Table',
23
+		'enableVersioning'            => true,
24
+		'onload_callback' => array
25
+		(
26
+		),
27
+		'oncopy_callback' => array
28
+		(
29
+		),
30
+		'onsubmit_callback' => array
31
+		(
32
+		),
33
+		'sql' => array
34
+		(
35
+			'keys' => array
36
+			(
37
+				'id' => 'primary',
38
+			)
39
+		)
40
+	),
41
+
42
+	// List
43
+	'list' => array
44
+	(
45
+		'sorting' => array
46
+		(
47
+			'mode'                    => 1,
48
+			'flag'                    => 11,
49
+			'fields'                  => array('type','title'),
50
+			'panelLayout'             => 'filter,search,limit',
51
+		),
52
+		'label' => array
53
+		(
54
+			'fields'                  => array('title'),
55
+			'format'                  => '%s'
56
+//			'showColumns'             => true,
57
+//			'label_callback'          => array('tl_member', 'addIcon')
58
+		),
59
+		'global_operations' => array
60
+		(
61
+			'all' => array
62
+			(
63
+				'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
64
+				'href'                => 'act=select',
65
+				'class'               => 'header_edit_all',
66
+				'attributes'          => 'onclick="Backend.getScrollOffset()" accesskey="e"'
67
+			),
68
+			'back' => array
69
+			(
70
+				'label'               => &$GLOBALS['TL_LANG']['MSC']['backBT'],
71
+				'href'                => '',
72
+				'class'               => 'header_back',
73
+				'button_callback'     => array('tl_esm_clients_settings', 'backBT')
74
+			)
75
+		),
76
+		'operations' => array
77
+		(
78
+			'edit' => array
79
+			(
80
+				'label'               => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['edit'],
81
+				'href'                => 'act=edit',
82
+				'icon'                => 'edit.gif',
83
+			),
84
+			'copy' => array
85
+			(
86
+				'label'               => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['copy'],
87
+				'href'                => 'act=copy',
88
+				'icon'                => 'copy.gif'
89
+			),
90
+			'delete' => array
91
+			(
92
+				'label'               => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['delete'],
93
+				'href'                => 'act=delete',
94
+				'icon'                => 'delete.gif',
95
+				'attributes'          => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
96
+			),
97
+			'show' => array
98
+			(
99
+				'label'               => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['show'],
100
+				'href'                => 'act=show',
101
+				'icon'                => 'show.gif'
102
+			)
103
+		)
104
+	),
105
+
106
+	// Palettes
107
+	'palettes' => array
108
+	(
109
+		'__selector__'                => array('type'),
110
+		'default'                     => '{type_legend},type;{attribute_legend},title',
111
+		'services'                    => '{type_legend},type;{attribute_legend},title,url',
112
+		'tech'                        => '{type_legend},type;{attribute_legend},title,url'
113
+	),
114
+
115
+	// Fields
116
+	'fields' => array
117
+	(
118
+		'id' => array
119
+		(
120
+			'sql'                     => "int(10) unsigned NOT NULL auto_increment"
121
+		),
122
+		'tstamp' => array
123
+		(
124
+			'sql'                     => "int(10) unsigned NOT NULL default '0'"
125
+		),
126
+		'type' => array
127
+		(
128
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['type'],
129
+			'inputType'               => 'select',
130
+			'exclude'                 => true,
131
+			'filter'                  => true,
132
+			'options'                 => array('branch','type','services','tech'),
133
+			'reference'               => $GLOBALS['TL_LANG']['tl_esm_clients_settings']['REF'],
134
+			'eval'                    => array('mandatory'=>true, 'includeBlankOption'=>true,'submitOnChange'=>true, 'csv'=>','),
135
+			'sql'                     => "text NULL"
136
+		),
137
+		'title' => array
138
+		(
139
+			'label'                   => &$GLOBALS['TL_LANG']['tl_esm_clients_settings']['title'],
140
+			'inputType'               => 'text',
141
+			'exclude'                 => true,
142
+			'search'                  => true,
143
+			'eval'                    => array('mandatory'=>true, 'maxlength'=>128, 'tl_class'=>'w50'),
144
+			'sql'                     => "varchar(128) NOT NULL default ''"
145
+		),
146
+		'url' => array
147
+		(
148
+			'label'                   => &$GLOBALS['TL_LANG']['MSC']['url'],
149
+			'exclude'                 => true,
150
+			'search'                  => true,
151
+			'inputType'               => 'text',
152
+			'eval'                    => array('mandatory'=>true, 'rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'fieldType'=>'radio', 'tl_class'=>'w50 wizard'),
153
+			'wizard' => array
154
+			(
155
+				array('tl_esm_clients_settings', 'pagePicker')
156
+			),
157
+			'sql'                     => "varchar(255) NOT NULL default ''"
158
+		),
159
+	)
160
+);
161
+
162
+class tl_esm_clients_settings extends Backend
163
+{
164
+
165
+	/**
166
+	 * Import the back end user object
167
+	 */
168
+	public function __construct()
169
+	{
170
+		parent::__construct();
171
+		$this->import('BackendUser', 'User');
172
+	}
173
+
174
+	/**
175
+	 * Return the back button
176
+	 * @param string
177
+	 * @param string
178
+	 * @param string
179
+	 * @param string
180
+	 * @param string
181
+	 * @return string
182
+	 */
183
+	public function backBT($href, $label, $title, $class, $attributes)
184
+	{
185
+		return '<a href="'.$this->addToUrl($href,true,array('table')).'" class="'.$class.'" title="'.specialchars($title).'"'.$attributes.'>'.$label.'</a> ';
186
+	}
187
+
188
+	/**
189
+	 * Return the file picker wizard
190
+	 * @param \DataContainer
191
+	 * @return string
192
+	 */
193
+	public function filePicker(DataContainer $dc)
194
+	{
195
+		return ' <a href="contao/file.php?do='.Input::get('do').'&amp;table='.$dc->table.'&amp;field='.$dc->field.'&amp;value='.$dc->value.'" title="'.specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['filepicker'])).'" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\''.specialchars($GLOBALS['TL_LANG']['MOD']['files'][0]).'\',\'url\':this.href,\'id\':\''.$dc->field.'\',\'tag\':\'ctrl_'.$dc->field . ((Input::get('act') == 'editAll') ? '_' . $dc->id : '').'\',\'self\':this});return false">' . Image::getHtml('pickfile.gif', $GLOBALS['TL_LANG']['MSC']['filepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>';
196
+	}
197
+
198
+	/**
199
+	 * Return the link picker wizard
200
+	 * @param \DataContainer
201
+	 * @return string
202
+	 */
203
+	public function pagePicker(DataContainer $dc)
204
+	{
205
+		return ' <a href="contao/page.php?do=' . Input::get('do') . '&amp;table=' . $dc->table . '&amp;field=' . $dc->field . '&amp;value=' . str_replace(array('{{link_url::', '}}'), '', $dc->value) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']) . '" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MOD']['page'][0])) . '\',\'url\':this.href,\'id\':\'' . $dc->field . '\',\'tag\':\'ctrl_'. $dc->field . ((Input::get('act') == 'editAll') ? '_' . $dc->id : '') . '\',\'self\':this});return false">' . Image::getHtml('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>';
206
+	}
207
+
208
+	/**
209
+	 * Return the "toggle visibility" button
210
+	 * @param array
211
+	 * @param string
212
+	 * @param string
213
+	 * @param string
214
+	 * @param string
215
+	 * @param string
216
+	 * @return string
217
+	 */
218
+	public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
219
+	{
220
+		if (strlen(Input::get('tid')))
221
+		{
222
+			$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
223
+			$this->redirect($this->getReferer());
224
+		}
225
+
226
+		// Check permissions AFTER checking the tid, so hacking attempts are logged
227
+		if (!$this->User->hasAccess('tl_esm_clients_settings::invisible', 'alexf'))
228
+		{
229
+			return '';
230
+		}
231
+
232
+		$href .= '&amp;id='.Input::get('id').'&amp;tid='.$row['id'].'&amp;state='.$row['invisible'];
233
+
234
+		if ($row['invisible'])
235
+		{
236
+			$icon = 'invisible.gif';
237
+		}
238
+
239
+		return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ';
240
+	}
241
+
242
+
243
+	/**
244
+	 * Toggle the visibility of an element
245
+	 * @param integer
246
+	 * @param boolean
247
+	 */
248
+	public function toggleVisibility($intId, $blnVisible)
249
+	{
250
+		// Check permissions to edit
251
+		Input::setGet('id', $intId);
252
+		Input::setGet('act', 'toggle');
253
+
254
+		// The onload_callbacks vary depending on the dynamic parent table (see #4894)
255
+		if (is_array($GLOBALS['TL_DCA']['tl_esm_clients_settings']['config']['onload_callback']))
256
+		{
257
+			foreach ($GLOBALS['TL_DCA']['tl_esm_clients_settings']['config']['onload_callback'] as $callback)
258
+			{
259
+				if (is_array($callback))
260
+				{
261
+					$this->import($callback[0]);
262
+					$this->$callback[0]->$callback[1]($this);
263
+				}
264
+				elseif (is_callable($callback))
265
+				{
266
+					$callback($this);
267
+				}
268
+			}
269
+		}
270
+
271
+		// Check permissions to publish
272
+		if (!$this->User->hasAccess('tl_esm_clients_settings::invisible', 'alexf'))
273
+		{
274
+			$this->log('Not enough permissions to show/hide content element ID "'.$intId.'"', __METHOD__, TL_ERROR);
275
+			$this->redirect('contao/main.php?act=error');
276
+		}
277
+
278
+		$objVersions = new Versions('tl_content', $intId);
279
+		$objVersions->initialize();
280
+
281
+		// Trigger the save_callback
282
+		if (is_array($GLOBALS['TL_DCA']['tl_esm_clients_settings']['fields']['invisible']['save_callback']))
283
+		{
284
+			foreach ($GLOBALS['TL_DCA']['tl_esm_clients_settings']['fields']['invisible']['save_callback'] as $callback)
285
+			{
286
+				if (is_array($callback))
287
+				{
288
+					$this->import($callback[0]);
289
+					$blnVisible = $this->$callback[0]->$callback[1]($blnVisible, $this);
290
+				}
291
+				elseif (is_callable($callback))
292
+				{
293
+					$blnVisible = $callback($blnVisible, $this);
294
+				}
295
+			}
296
+		}
297
+
298
+		// Update the database
299
+		$this->Database->prepare("UPDATE tl_esm_clients_settings SET tstamp=". time() .", invisible='" . ($blnVisible ? '' : 1) . "' WHERE id=?")
300
+			->execute($intId);
301
+
302
+		$objVersions->create();
303
+		$this->log('A new version of record "tl_esm_clients_settings.id='.$intId.'" has been created', __METHOD__, TL_GENERAL);
304
+	}
305
+}
0 306
\ No newline at end of file