Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | class CRM_Core_I18n_Form extends CRM_Core_Form { | |
518fa0ee | 20 | |
00be9182 | 21 | public function buildQuickForm() { |
6a488035 | 22 | $config = CRM_Core_Config::singleton(); |
98466ff9 | 23 | $tsLocale = CRM_Core_I18n::getLocale(); |
6a488035 TO |
24 | $this->_locales = array_keys($config->languageLimit); |
25 | ||
26 | // get the part of the database we want to edit and validate it | |
353ffa53 TO |
27 | $table = CRM_Utils_Request::retrieve('table', 'String', $this); |
28 | $field = CRM_Utils_Request::retrieve('field', 'String', $this); | |
29 | $id = CRM_Utils_Request::retrieve('id', 'Int', $this); | |
6a488035 TO |
30 | $this->_structure = CRM_Core_I18n_SchemaStructure::columns(); |
31 | if (!isset($this->_structure[$table][$field])) { | |
32 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
33 | } | |
34 | ||
35 | $this->addElement('hidden', 'table', $table); | |
36 | $this->addElement('hidden', 'field', $field); | |
37 | $this->addElement('hidden', 'id', $id); | |
38 | ||
be2fb01f | 39 | $cols = []; |
6a488035 TO |
40 | foreach ($this->_locales as $locale) { |
41 | $cols[] = "{$field}_{$locale} {$locale}"; | |
42 | } | |
43 | $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id"; | |
44 | ||
45 | $dao = new CRM_Core_DAO(); | |
46 | $dao->query($query, FALSE); | |
47 | $dao->fetch(); | |
48 | ||
313df5ee SV |
49 | // get html type and attributes for this field |
50 | $widgets = CRM_Core_I18n_SchemaStructure::widgets(); | |
51 | $widget = $widgets[$table][$field]; | |
6a488035 | 52 | |
313df5ee | 53 | // attributes |
be2fb01f | 54 | $attributes = ['class' => '']; |
313df5ee SV |
55 | if (isset($widget['rows'])) { |
56 | $attributes['rows'] = $widget['rows']; | |
57 | } | |
58 | if (isset($widget['cols'])) { | |
59 | $attributes['cols'] = $widget['cols']; | |
60 | } | |
313df5ee | 61 | $required = !empty($widget['required']); |
132ab804 | 62 | |
100a45ff CW |
63 | if ($widget['type'] == 'RichTextEditor') { |
64 | $widget['type'] = 'wysiwyg'; | |
071e5a4f CW |
65 | $attributes['class'] = 'collapsed'; |
66 | } | |
67 | elseif ($widget['type'] == 'Text') { | |
68 | $attributes['class'] = 'huge'; | |
100a45ff CW |
69 | } |
70 | ||
6a488035 TO |
71 | $languages = CRM_Core_I18n::languages(TRUE); |
72 | foreach ($this->_locales as $locale) { | |
100a45ff | 73 | $attr = $attributes; |
313df5ee SV |
74 | $name = "{$field}_{$locale}"; |
75 | if ($locale == $tsLocale) { | |
100a45ff | 76 | $attr['class'] .= ' default-lang'; |
313df5ee | 77 | } |
100a45ff | 78 | $this->add($widget['type'], $name, $languages[$locale], $attr, $required); |
313df5ee SV |
79 | |
80 | $this->_defaults[$name] = $dao->$locale; | |
6a488035 TO |
81 | } |
82 | ||
d606fff7 CW |
83 | $this->addDefaultButtons(ts('Save'), 'next', NULL); |
84 | ||
85 | CRM_Utils_System::setTitle(ts('Languages')); | |
6a488035 | 86 | |
6a488035 TO |
87 | $this->assign('locales', $this->_locales); |
88 | $this->assign('field', $field); | |
6a488035 TO |
89 | } |
90 | ||
b5c2afd0 EM |
91 | /** |
92 | * This virtual function is used to set the default values of | |
93 | * various form elements | |
94 | * | |
95 | * access public | |
96 | * | |
a6c01b45 CW |
97 | * @return array |
98 | * reference to the array of default values | |
b5c2afd0 | 99 | */ |
00be9182 | 100 | public function setDefaultValues() { |
6a488035 TO |
101 | return $this->_defaults; |
102 | } | |
103 | ||
00be9182 | 104 | public function postProcess() { |
6a488035 | 105 | $values = $this->exportValues(); |
353ffa53 TO |
106 | $table = $values['table']; |
107 | $field = $values['field']; | |
6a488035 TO |
108 | |
109 | // validate table and field | |
110 | if (!isset($this->_structure[$table][$field])) { | |
111 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
112 | } | |
113 | ||
be2fb01f CW |
114 | $cols = []; |
115 | $params = [[$values['id'], 'Int']]; | |
353ffa53 | 116 | $i = 1; |
6a488035 TO |
117 | foreach ($this->_locales as $locale) { |
118 | $cols[] = "{$field}_{$locale} = %$i"; | |
be2fb01f | 119 | $params[$i] = [$values["{$field}_{$locale}"], 'String']; |
6a488035 TO |
120 | $i++; |
121 | } | |
122 | $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0"; | |
353ffa53 | 123 | $dao = new CRM_Core_DAO(); |
6a488035 TO |
124 | $query = CRM_Core_DAO::composeQuery($query, $params, TRUE); |
125 | $dao->query($query, FALSE); | |
6a488035 | 126 | } |
96025800 | 127 | |
6a488035 | 128 | } |