3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Core_I18n_Form
extends CRM_Core_Form
{
19 public function buildQuickForm() {
20 $config = CRM_Core_Config
::singleton();
21 $tsLocale = CRM_Core_I18n
::getLocale();
22 $this->_locales
= array_keys($config->languageLimit
);
24 // get the part of the database we want to edit and validate it
25 $table = CRM_Utils_Request
::retrieve('table', 'String', $this);
26 $field = CRM_Utils_Request
::retrieve('field', 'String', $this);
27 $id = CRM_Utils_Request
::retrieve('id', 'Int', $this);
28 $this->_structure
= CRM_Core_I18n_SchemaStructure
::columns();
29 if (!isset($this->_structure
[$table][$field])) {
30 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
33 $this->addElement('hidden', 'table', $table);
34 $this->addElement('hidden', 'field', $field);
35 $this->addElement('hidden', 'id', $id);
38 foreach ($this->_locales
as $locale) {
39 $cols[] = "{$field}_{$locale} {$locale}";
41 $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id";
43 $dao = new CRM_Core_DAO();
44 $dao->query($query, FALSE);
47 // get html type and attributes for this field
48 $widgets = CRM_Core_I18n_SchemaStructure
::widgets();
49 $widget = $widgets[$table][$field];
52 $attributes = ['class' => ''];
53 if (isset($widget['rows'])) {
54 $attributes['rows'] = $widget['rows'];
56 if (isset($widget['cols'])) {
57 $attributes['cols'] = $widget['cols'];
59 $required = !empty($widget['required']);
61 if ($widget['type'] == 'RichTextEditor') {
62 $widget['type'] = 'wysiwyg';
63 $attributes['class'] = 'collapsed';
65 elseif ($widget['type'] == 'Text') {
66 $attributes['class'] = 'huge';
69 $languages = CRM_Core_I18n
::languages(TRUE);
70 foreach ($this->_locales
as $locale) {
72 $name = "{$field}_{$locale}";
73 if ($locale == $tsLocale) {
74 $attr['class'] .= ' default-lang';
76 $this->add($widget['type'], $name, $languages[$locale], $attr, $required);
78 $this->_defaults
[$name] = $dao->$locale;
81 $this->addDefaultButtons(ts('Save'), 'next', NULL);
83 CRM_Utils_System
::setTitle(ts('Languages'));
85 $this->assign('locales', $this->_locales
);
86 $this->assign('field', $field);
90 * This virtual function is used to set the default values of
91 * various form elements
96 * reference to the array of default values
98 public function setDefaultValues() {
99 return $this->_defaults
;
102 public function postProcess() {
103 $values = $this->exportValues();
104 $table = $values['table'];
105 $field = $values['field'];
107 // validate table and field
108 if (!isset($this->_structure
[$table][$field])) {
109 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
113 $params = [[$values['id'], 'Int']];
115 foreach ($this->_locales
as $locale) {
116 $cols[] = "{$field}_{$locale} = %$i";
117 $params[$i] = [$values["{$field}_{$locale}"], 'String'];
120 $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0";
121 $dao = new CRM_Core_DAO();
122 $query = CRM_Core_DAO
::composeQuery($query, $params, TRUE);
123 $dao->query($query, FALSE);