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';
83 elseif ($widget['type'] == 'Text') {
84 $attributes['class'] = 'huge';
87 $languages = CRM_Core_I18n
::languages(TRUE);
88 foreach ($this->_locales
as $locale) {
90 $name = "{$field}_{$locale}";
91 if ($locale == $tsLocale) {
92 $attr['class'] .= ' default-lang';
94 $this->add($widget['type'], $name, $languages[$locale], $attr, $required);
96 $this->_defaults
[$name] = $dao->$locale;
99 $this->addDefaultButtons(ts('Save'), 'next', NULL);
101 CRM_Utils_System
::setTitle(ts('Languages'));
103 $this->assign('locales', $this->_locales
);
104 $this->assign('field', $field);
108 * This virtual function is used to set the default values of
109 * various form elements
114 * reference to the array of default values
116 public function setDefaultValues() {
117 return $this->_defaults
;
120 public function postProcess() {
121 $values = $this->exportValues();
122 $table = $values['table'];
123 $field = $values['field'];
125 // validate table and field
126 if (!isset($this->_structure
[$table][$field])) {
127 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
131 $params = [[$values['id'], 'Int']];
133 foreach ($this->_locales
as $locale) {
134 $cols[] = "{$field}_{$locale} = %$i";
135 $params[$i] = [$values["{$field}_{$locale}"], 'String'];
138 $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0";
139 $dao = new CRM_Core_DAO();
140 $query = CRM_Core_DAO
::composeQuery($query, $params, TRUE);
141 $dao->query($query, FALSE);