contact.php
9.76 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/**
* @package Joomla.Administrator
* @subpackage com_contact
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
use Joomla\CMS\Language\LanguageHelper;
/**
* Supports a modal contact picker.
*
* @since 1.6
*/
class JFormFieldModal_Contact extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Modal_Contact';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
$allowNew = ((string) $this->element['new'] == 'true');
$allowEdit = ((string) $this->element['edit'] == 'true');
$allowClear = ((string) $this->element['clear'] != 'false');
$allowSelect = ((string) $this->element['select'] != 'false');
$allowPropagate = ((string) $this->element['propagate'] == 'true');
$languages = LanguageHelper::getContentLanguages(array(0, 1));
// Load language
JFactory::getLanguage()->load('com_contact', JPATH_ADMINISTRATOR);
// The active contact id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';
// Create the modal id.
$modalId = 'Contact_' . $this->id;
// Add the modal field script to the document head.
JHtml::_('jquery.framework');
JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true));
// Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect)
{
static $scriptSelect = null;
if (is_null($scriptSelect))
{
$scriptSelect = array();
}
if (!isset($scriptSelect[$this->id]))
{
JFactory::getDocument()->addScriptDeclaration("
function jSelectContact_" . $this->id . "(id, title, object) {
window.processModalSelect('Contact', '" . $this->id . "', id, title, '', object);
}
");
JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED');
$scriptSelect[$this->id] = true;
}
}
// Setup variables for display.
$linkContacts = 'index.php?option=com_contact&view=contacts&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$linkContact = 'index.php?option=com_contact&view=contact&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$modalTitle = JText::_('COM_CONTACT_CHANGE_CONTACT');
if (isset($this->element['language']))
{
$linkContacts .= '&forcedLanguage=' . $this->element['language'];
$linkContact .= '&forcedLanguage=' . $this->element['language'];
$modalTitle .= ' — ' . $this->element['label'];
}
$urlSelect = $linkContacts . '&function=jSelectContact_' . $this->id;
$urlEdit = $linkContact . '&task=contact.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkContact . '&task=contact.add';
if ($value)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('name'))
->from($db->quoteName('#__contact_details'))
->where($db->quoteName('id') . ' = ' . (int) $value);
$db->setQuery($query);
try
{
$title = $db->loadResult();
}
catch (RuntimeException $e)
{
JError::raiseWarning(500, $e->getMessage());
}
}
$title = empty($title) ? JText::_('COM_CONTACT_SELECT_A_CONTACT') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// The current contact display field.
$html = '<span class="input-append">';
$html .= '<input class="input-medium" id="' . $this->id . '_name" type="text" value="' . $title . '" disabled="disabled" size="35" />';
// Select contact button
if ($allowSelect)
{
$html .= '<button'
. ' type="button"'
. ' class="btn hasTooltip' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"'
. ' data-toggle="modal"'
. ' data-target="#ModalSelect' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CONTACT_CHANGE_CONTACT') . '">'
. '<span class="icon-file" aria-hidden="true"></span> ' . JText::_('JSELECT')
. '</button>';
}
// New contact button
if ($allowNew)
{
$html .= '<button'
. ' type="button"'
. ' class="btn hasTooltip' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_new"'
. ' data-toggle="modal"'
. ' data-target="#ModalNew' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CONTACT_NEW_CONTACT') . '">'
. '<span class="icon-new" aria-hidden="true"></span> ' . JText::_('JACTION_CREATE')
. '</button>';
}
// Edit contact button
if ($allowEdit)
{
$html .= '<button'
. ' type="button"'
. ' class="btn hasTooltip' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"'
. ' data-toggle="modal"'
. ' data-target="#ModalEdit' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CONTACT_EDIT_CONTACT') . '">'
. '<span class="icon-edit" aria-hidden="true"></span> ' . JText::_('JACTION_EDIT')
. '</button>';
}
// Clear contact button
if ($allowClear)
{
$html .= '<button'
. ' type="button"'
. ' class="btn' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-remove" aria-hidden="true"></span>' . JText::_('JCLEAR')
. '</button>';
}
// Propagate contact button
if ($allowPropagate && count($languages) > 2)
{
// Strip off language tag at the end
$tagLength = (int) strlen($this->element['language']);
$callbackFunctionStem = substr("jSelectContact_" . $this->id, 0, -$tagLength);
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_propagate"'
. ' href="#"'
. ' title="' . JHtml::tooltipText('JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP') . '"'
. ' onclick="Joomla.propagateAssociation(\'' . $this->id . '\', \'' . $callbackFunctionStem . '\');">'
. '<span class="icon-refresh" aria-hidden="true"></span>' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON')
. '</a>';
}
$html .= '</span>';
// Select contact modal
if ($allowSelect)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalSelect' . $modalId,
array(
'title' => $modalTitle,
'url' => $urlSelect,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn" data-dismiss="modal">' . JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>',
)
);
}
// New contact modal
if ($allowNew)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
'title' => JText::_('COM_CONTACT_NEW_CONTACT'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlNew,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn"'
. ' onclick="window.processModalEdit(this, \''
. $this->id . '\', \'add\', \'contact\', \'cancel\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
. '<button type="button" class="btn btn-primary"'
. ' onclick="window.processModalEdit(this, \''
. $this->id . '\', \'add\', \'contact\', \'save\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JSAVE') . '</button>'
. '<button type="button" class="btn btn-success"'
. ' onclick="window.processModalEdit(this, \''
. $this->id . '\', \'add\', \'contact\', \'apply\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JAPPLY') . '</button>',
)
);
}
// Edit contact modal.
if ($allowEdit)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => JText::_('COM_CONTACT_EDIT_CONTACT'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlEdit,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn"'
. ' onclick="window.processModalEdit(this, \'' . $this->id
. '\', \'edit\', \'contact\', \'cancel\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
. '<button type="button" class="btn btn-primary"'
. ' onclick="window.processModalEdit(this, \''
. $this->id . '\', \'edit\', \'contact\', \'save\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JSAVE') . '</button>'
. '<button type="button" class="btn btn-success"'
. ' onclick="window.processModalEdit(this, \''
. $this->id . '\', \'edit\', \'contact\', \'apply\', \'contact-form\', \'jform_id\', \'jform_name\'); return false;">'
. JText::_('JAPPLY') . '</button>',
)
);
}
// Note: class='required' for client side validation.
$class = $this->required ? ' class="required modal-value"' : '';
$html .= '<input type="hidden" id="' . $this->id . '_id"' . $class . ' data-required="' . (int) $this->required . '" name="' . $this->name
. '" data-text="' . htmlspecialchars(JText::_('COM_CONTACT_SELECT_A_CONTACT', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';
return $html;
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since 3.4
*/
protected function getLabel()
{
return str_replace($this->id, $this->id . '_id', parent::getLabel());
}
}