Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Core_I18n_Form extends CRM_Core_Form { | |
00be9182 | 36 | public function buildQuickForm() { |
6a488035 | 37 | $config = CRM_Core_Config::singleton(); |
98466ff9 | 38 | $tsLocale = CRM_Core_I18n::getLocale(); |
6a488035 TO |
39 | $this->_locales = array_keys($config->languageLimit); |
40 | ||
41 | // get the part of the database we want to edit and validate it | |
353ffa53 TO |
42 | $table = CRM_Utils_Request::retrieve('table', 'String', $this); |
43 | $field = CRM_Utils_Request::retrieve('field', 'String', $this); | |
44 | $id = CRM_Utils_Request::retrieve('id', 'Int', $this); | |
6a488035 TO |
45 | $this->_structure = CRM_Core_I18n_SchemaStructure::columns(); |
46 | if (!isset($this->_structure[$table][$field])) { | |
47 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
48 | } | |
49 | ||
50 | $this->addElement('hidden', 'table', $table); | |
51 | $this->addElement('hidden', 'field', $field); | |
52 | $this->addElement('hidden', 'id', $id); | |
53 | ||
54 | $cols = array(); | |
55 | foreach ($this->_locales as $locale) { | |
56 | $cols[] = "{$field}_{$locale} {$locale}"; | |
57 | } | |
58 | $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id"; | |
59 | ||
60 | $dao = new CRM_Core_DAO(); | |
61 | $dao->query($query, FALSE); | |
62 | $dao->fetch(); | |
63 | ||
313df5ee SV |
64 | // get html type and attributes for this field |
65 | $widgets = CRM_Core_I18n_SchemaStructure::widgets(); | |
66 | $widget = $widgets[$table][$field]; | |
6a488035 | 67 | |
313df5ee | 68 | // attributes |
132ab804 | 69 | $attributes = array('class' => ''); |
313df5ee SV |
70 | if (isset($widget['rows'])) { |
71 | $attributes['rows'] = $widget['rows']; | |
72 | } | |
73 | if (isset($widget['cols'])) { | |
74 | $attributes['cols'] = $widget['cols']; | |
75 | } | |
313df5ee | 76 | $required = !empty($widget['required']); |
132ab804 | 77 | |
100a45ff CW |
78 | if ($widget['type'] == 'RichTextEditor') { |
79 | $widget['type'] = 'wysiwyg'; | |
80 | $attributes['class'] .= ' collapsed'; | |
81 | } | |
82 | ||
6a488035 TO |
83 | $languages = CRM_Core_I18n::languages(TRUE); |
84 | foreach ($this->_locales as $locale) { | |
100a45ff | 85 | $attr = $attributes; |
313df5ee SV |
86 | $name = "{$field}_{$locale}"; |
87 | if ($locale == $tsLocale) { | |
100a45ff | 88 | $attr['class'] .= ' default-lang'; |
313df5ee | 89 | } |
100a45ff | 90 | $this->add($widget['type'], $name, $languages[$locale], $attr, $required); |
313df5ee SV |
91 | |
92 | $this->_defaults[$name] = $dao->$locale; | |
6a488035 TO |
93 | } |
94 | ||
d606fff7 CW |
95 | $this->addDefaultButtons(ts('Save'), 'next', NULL); |
96 | ||
97 | CRM_Utils_System::setTitle(ts('Languages')); | |
6a488035 | 98 | |
6a488035 TO |
99 | $this->assign('locales', $this->_locales); |
100 | $this->assign('field', $field); | |
6a488035 TO |
101 | } |
102 | ||
b5c2afd0 EM |
103 | /** |
104 | * This virtual function is used to set the default values of | |
105 | * various form elements | |
106 | * | |
107 | * access public | |
108 | * | |
a6c01b45 CW |
109 | * @return array |
110 | * reference to the array of default values | |
b5c2afd0 | 111 | */ |
00be9182 | 112 | public function setDefaultValues() { |
6a488035 TO |
113 | return $this->_defaults; |
114 | } | |
115 | ||
00be9182 | 116 | public function postProcess() { |
6a488035 | 117 | $values = $this->exportValues(); |
353ffa53 TO |
118 | $table = $values['table']; |
119 | $field = $values['field']; | |
6a488035 TO |
120 | |
121 | // validate table and field | |
122 | if (!isset($this->_structure[$table][$field])) { | |
123 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
124 | } | |
125 | ||
353ffa53 | 126 | $cols = array(); |
6a488035 | 127 | $params = array(array($values['id'], 'Int')); |
353ffa53 | 128 | $i = 1; |
6a488035 TO |
129 | foreach ($this->_locales as $locale) { |
130 | $cols[] = "{$field}_{$locale} = %$i"; | |
131 | $params[$i] = array($values["{$field}_{$locale}"], 'String'); | |
132 | $i++; | |
133 | } | |
134 | $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0"; | |
353ffa53 | 135 | $dao = new CRM_Core_DAO(); |
6a488035 TO |
136 | $query = CRM_Core_DAO::composeQuery($query, $params, TRUE); |
137 | $dao->query($query, FALSE); | |
6a488035 | 138 | } |
96025800 | 139 | |
6a488035 | 140 | } |