3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 class CRM_Core_I18n_Form
extends CRM_Core_Form
{
37 public function buildQuickForm() {
38 $config = CRM_Core_Config
::singleton();
39 $tsLocale = CRM_Core_I18n
::getLocale();
40 $this->_locales
= array_keys($config->languageLimit
);
42 // get the part of the database we want to edit and validate it
43 $table = CRM_Utils_Request
::retrieve('table', 'String', $this);
44 $field = CRM_Utils_Request
::retrieve('field', 'String', $this);
45 $id = CRM_Utils_Request
::retrieve('id', 'Int', $this);
46 $this->_structure
= CRM_Core_I18n_SchemaStructure
::columns();
47 if (!isset($this->_structure
[$table][$field])) {
48 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
51 $this->addElement('hidden', 'table', $table);
52 $this->addElement('hidden', 'field', $field);
53 $this->addElement('hidden', 'id', $id);
56 foreach ($this->_locales
as $locale) {
57 $cols[] = "{$field}_{$locale} {$locale}";
59 $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id";
61 $dao = new CRM_Core_DAO();
62 $dao->query($query, FALSE);
65 // get html type and attributes for this field
66 $widgets = CRM_Core_I18n_SchemaStructure
::widgets();
67 $widget = $widgets[$table][$field];
70 $attributes = ['class' => ''];
71 if (isset($widget['rows'])) {
72 $attributes['rows'] = $widget['rows'];
74 if (isset($widget['cols'])) {
75 $attributes['cols'] = $widget['cols'];
77 $required = !empty($widget['required']);
79 if ($widget['type'] == 'RichTextEditor') {
80 $widget['type'] = 'wysiwyg';
81 $attributes['class'] .= ' collapsed';
84 $languages = CRM_Core_I18n
::languages(TRUE);
85 foreach ($this->_locales
as $locale) {
87 $name = "{$field}_{$locale}";
88 if ($locale == $tsLocale) {
89 $attr['class'] .= ' default-lang';
91 $this->add($widget['type'], $name, $languages[$locale], $attr, $required);
93 $this->_defaults
[$name] = $dao->$locale;
96 $this->addDefaultButtons(ts('Save'), 'next', NULL);
98 CRM_Utils_System
::setTitle(ts('Languages'));
100 $this->assign('locales', $this->_locales
);
101 $this->assign('field', $field);
105 * This virtual function is used to set the default values of
106 * various form elements
111 * reference to the array of default values
113 public function setDefaultValues() {
114 return $this->_defaults
;
117 public function postProcess() {
118 $values = $this->exportValues();
119 $table = $values['table'];
120 $field = $values['field'];
122 // validate table and field
123 if (!isset($this->_structure
[$table][$field])) {
124 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
128 $params = [[$values['id'], 'Int']];
130 foreach ($this->_locales
as $locale) {
131 $cols[] = "{$field}_{$locale} = %$i";
132 $params[$i] = [$values["{$field}_{$locale}"], 'String'];
135 $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0";
136 $dao = new CRM_Core_DAO();
137 $query = CRM_Core_DAO
::composeQuery($query, $params, TRUE);
138 $dao->query($query, FALSE);