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
19 class CRM_Core_I18n_Form
extends CRM_Core_Form
{
21 public function buildQuickForm() {
22 $config = CRM_Core_Config
::singleton();
23 $tsLocale = CRM_Core_I18n
::getLocale();
24 $this->_locales
= array_keys($config->languageLimit
);
26 // get the part of the database we want to edit and validate it
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);
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.");
35 $this->addElement('hidden', 'table', $table);
36 $this->addElement('hidden', 'field', $field);
37 $this->addElement('hidden', 'id', $id);
40 foreach ($this->_locales
as $locale) {
41 $cols[] = "{$field}_{$locale} {$locale}";
43 $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id";
45 $dao = new CRM_Core_DAO();
46 $dao->query($query, FALSE);
49 // get html type and attributes for this field
50 $widgets = CRM_Core_I18n_SchemaStructure
::widgets();
51 $widget = $widgets[$table][$field];
54 $attributes = ['class' => ''];
55 if (isset($widget['rows'])) {
56 $attributes['rows'] = $widget['rows'];
58 if (isset($widget['cols'])) {
59 $attributes['cols'] = $widget['cols'];
61 $required = !empty($widget['required']);
63 if ($widget['type'] == 'RichTextEditor') {
64 $widget['type'] = 'wysiwyg';
65 $attributes['class'] = 'collapsed';
67 elseif ($widget['type'] == 'Text') {
68 $attributes['class'] = 'huge';
71 $languages = CRM_Core_I18n
::languages(TRUE);
72 foreach ($this->_locales
as $locale) {
74 $name = "{$field}_{$locale}";
75 if ($locale == $tsLocale) {
76 $attr['class'] .= ' default-lang';
78 $this->add($widget['type'], $name, $languages[$locale], $attr, $required);
80 $this->_defaults
[$name] = $dao->$locale;
83 $this->addDefaultButtons(ts('Save'), 'next', NULL);
85 CRM_Utils_System
::setTitle(ts('Languages'));
87 $this->assign('locales', $this->_locales
);
88 $this->assign('field', $field);
92 * This virtual function is used to set the default values of
93 * various form elements
98 * reference to the array of default values
100 public function setDefaultValues() {
101 return $this->_defaults
;
104 public function postProcess() {
105 $values = $this->exportValues();
106 $table = $values['table'];
107 $field = $values['field'];
109 // validate table and field
110 if (!isset($this->_structure
[$table][$field])) {
111 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
115 $params = [[$values['id'], 'Int']];
117 foreach ($this->_locales
as $locale) {
118 $cols[] = "{$field}_{$locale} = %$i";
119 $params[$i] = [$values["{$field}_{$locale}"], 'String'];
122 $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0";
123 $dao = new CRM_Core_DAO();
124 $query = CRM_Core_DAO
::composeQuery($query, $params, TRUE);
125 $dao->query($query, FALSE);