1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function wikiplugin_trackerprefill_info()
9{
10	return [
11		'name' => tra('Tracker Prefill'),
12		'documentation' => 'PluginTrackerPrefill',
13		'description' => tra('Create a button to prefill tracker fields'),
14		'prefs' => [ 'feature_trackers', 'wikiplugin_trackerprefill' ],
15		'iconname' => 'trackers',
16		'introduced' => 2,
17		'params' => [
18			'page' => [
19				'required' => true,
20				'name' => tra('Page'),
21				'description' => tra('Tracker page name'),
22				'since' => '2.0',
23				'filter' => 'pagename',
24				'default' => '',
25				'profile_reference' => 'wiki_page',
26			],
27			'label' => [
28				'required' => false,
29				'name' => tra('Label'),
30				'description' => tra('Button Label.'),
31				'since' => '2.0',
32				'filter' => 'text',
33				'default' => '',
34			],
35			'urlparams' => [
36				'required' => false,
37				'name' => tra('URL Parameters'),
38				'description' => tr(
39					'Parameters to pass in the URL, for example, %0&my_parameter1=123&my_parameter2=q%1',
40					'<code>',
41					'</code>'
42				),
43				'since' => '6.0',
44				'filter' => 'striptags',
45				'default' => '',
46			],
47			'field1' => [
48				'required' => true,
49				'name' => tra('Field 1'),
50				'description' => tra('Field ID for the first field'),
51				'since' => '2.0',
52				'filter' => 'digits',
53				'default' => '',
54				'profile_reference' => 'tracker_field',
55			],
56			'value1' => [
57				'required' => true,
58				'name' => tra('Value 1'),
59				'description' => tra('Content that should be used to prefill the field.'),
60				'since' => '2.0',
61				'filter' => 'striptags',
62				'default' => '',
63			],
64			'field2' => [
65				'required' => false,
66				'name' => tra('Field 2'),
67				'description' => tra('Field ID for the second field'),
68				'since' => '2.0',
69				'filter' => 'digits',
70				'default' => '',
71				'profile_reference' => 'tracker_field',
72			],
73			'value2' => [
74				'required' => false,
75				'name' => tra('Value 2'),
76				'description' => tra('Content that should be used to prefill the field.'),
77				'since' => '2.0',
78				'filter' => 'striptags',
79				'default' => '',
80			],
81			'field3' => [
82				'required' => false,
83				'name' => tra('Field 3'),
84				'description' => tra('Field ID for the third field'),
85				'since' => '2.0',
86				'filter' => 'digits',
87				'default' => '',
88				'profile_reference' => 'tracker_field',
89			],
90			'value3' => [
91				'required' => false,
92				'name' => tra('Value 3'),
93				'description' => tra('Content that should be used to prefill the field.'),
94				'since' => '2.0',
95				'filter' => 'striptags',
96				'default' => '',
97			],
98			'field4' => [
99				'required' => false,
100				'name' => tra('Field 4'),
101				'description' => tra('Field ID for the fourth field'),
102				'since' => '2.0',
103				'filter' => 'digits',
104				'default' => '',
105				'profile_reference' => 'tracker_field',
106			],
107			'value4' => [
108				'required' => false,
109				'name' => tra('Value 4'),
110				'description' => tra('Content that should be used to prefill the field.'),
111				'since' => '2.0',
112				'filter' => 'striptags',
113				'default' => '',
114			],
115			'field5' => [
116				'required' => false,
117				'name' => tra('Field 5'),
118				'description' => tra('Field ID for the fifth field'),
119				'since' => '2.0',
120				'filter' => 'digits',
121				'default' => '',
122				'profile_reference' => 'tracker_field',
123			],
124			'value5' => [
125				'required' => false,
126				'name' => tra('Value 5'),
127				'description' => tra('Content that should be used to prefill the field.'),
128				'since' => '2.0',
129				'filter' => 'striptags',
130				'default' => '',
131			],
132			'field6' => [
133				'required' => false,
134				'name' => tra('Field 6'),
135				'description' => tra('Field ID for the sixth field'),
136				'since' => '2.0',
137				'filter' => 'digits',
138				'default' => '',
139				'profile_reference' => 'tracker_field',
140			],
141			'value6' => [
142				'required' => false,
143				'name' => tra('Value 6'),
144				'description' => tra('Content that should be used to prefill the field.'),
145				'since' => '2.0',
146				'filter' => 'striptags',
147				'default' => '',
148			],
149			'field7' => [
150				'required' => false,
151				'name' => tra('Field 7'),
152				'description' => tra('Field ID for the seventh field'),
153				'since' => '2.0',
154				'filter' => 'digits',
155				'default' => '',
156				'profile_reference' => 'tracker_field',
157			],
158			'value7' => [
159				'required' => false,
160				'name' => tra('Value 7'),
161				'description' => tra('Content that should be used to prefill the field.'),
162				'since' => '2.0',
163				'filter' => 'striptags',
164				'default' => '',
165			],
166			'field8' => [
167				'required' => false,
168				'name' => tra('Field 8'),
169				'description' => tra('Field ID for the eighth field'),
170				'since' => '2.0',
171				'filter' => 'digits',
172				'default' => '',
173				'profile_reference' => 'tracker_field',
174			],
175			'value8' => [
176				'required' => false,
177				'name' => tra('Value 8'),
178				'description' => tra('Content that should be used to prefill the field.'),
179				'since' => '2.0',
180				'filter' => 'striptags',
181				'default' => '',
182			],
183		],
184	];
185}
186
187function wikiplugin_trackerprefill($data, $params)
188{
189	$smarty = TikiLib::lib('smarty');
190	$prefills = [];
191	foreach ($params as $param => $value) {
192		if (strstr($param, 'field')) {
193			$id = substr($param, strlen('field'));
194			$f['fieldId'] = $value;
195			$f['value'] = $params["value$id"];
196			$prefills[] = $f;
197		}
198	}
199	$smarty->assign_by_ref('prefills', $prefills);
200	$smarty->assign_by_ref('params', $params);
201	return $smarty->fetch('wiki-plugins/wikiplugin_trackerprefill.tpl');
202}
203