3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Core_I18n_Form
extends CRM_Core_Form
{
36 function buildQuickForm() {
37 $config = CRM_Core_Config
::singleton();
38 $this->_locales
= array_keys($config->languageLimit
);
40 // get the part of the database we want to edit and validate it
41 $table = CRM_Utils_Request
::retrieve('table', 'String', $this);
42 $field = CRM_Utils_Request
::retrieve('field', 'String', $this);
43 $id = CRM_Utils_Request
::retrieve('id', 'Int', $this);
44 $this->_structure
= CRM_Core_I18n_SchemaStructure
::columns();
45 if (!isset($this->_structure
[$table][$field])) {
46 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
49 $this->addElement('hidden', 'table', $table);
50 $this->addElement('hidden', 'field', $field);
51 $this->addElement('hidden', 'id', $id);
54 foreach ($this->_locales
as $locale) {
55 $cols[] = "{$field}_{$locale} {$locale}";
57 $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id";
59 $dao = new CRM_Core_DAO();
60 $dao->query($query, FALSE);
63 // we want TEXTAREAs for long fields and INPUTs for short ones
64 $this->_structure
[$table][$field] == 'text' ?
$type = 'textarea' : $type = 'text';
66 $languages = CRM_Core_I18n
::languages(TRUE);
67 foreach ($this->_locales
as $locale) {
68 $this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('cols' => 60, 'rows' => 3));
69 $this->_defaults
["{$field}_{$locale}"] = $dao->$locale;
72 $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE)));
75 $this->assign('tsLocale', $tsLocale);
76 $this->assign('locales', $this->_locales
);
77 $this->assign('field', $field);
78 $this->assign('context', CRM_Utils_Request
::retrieve('context', 'String', $this));
81 function setDefaultValues() {
82 return $this->_defaults
;
85 function postProcess() {
86 $values = $this->exportValues();
87 $table = $values['table'];
88 $field = $values['field'];
90 // validate table and field
91 if (!isset($this->_structure
[$table][$field])) {
92 CRM_Core_Error
::fatal("$table.$field is not internationalized.");
96 $params = array(array($values['id'], 'Int'));
98 foreach ($this->_locales
as $locale) {
99 $cols[] = "{$field}_{$locale} = %$i";
100 $params[$i] = array($values["{$field}_{$locale}"], 'String');
103 $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0";
104 $dao = new CRM_Core_DAO();
105 $query = CRM_Core_DAO
::composeQuery($query, $params, TRUE);
106 $dao->query($query, FALSE);
108 CRM_Utils_System
::civiExit();