Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
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); | |
39 | ||
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."); | |
47 | } | |
48 | ||
49 | $this->addElement('hidden', 'table', $table); | |
50 | $this->addElement('hidden', 'field', $field); | |
51 | $this->addElement('hidden', 'id', $id); | |
52 | ||
53 | $cols = array(); | |
54 | foreach ($this->_locales as $locale) { | |
55 | $cols[] = "{$field}_{$locale} {$locale}"; | |
56 | } | |
57 | $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id"; | |
58 | ||
59 | $dao = new CRM_Core_DAO(); | |
60 | $dao->query($query, FALSE); | |
61 | $dao->fetch(); | |
62 | ||
63 | // we want TEXTAREAs for long fields and INPUTs for short ones | |
64 | $this->_structure[$table][$field] == 'text' ? $type = 'textarea' : $type = 'text'; | |
65 | ||
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; | |
70 | } | |
71 | ||
72 | $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE))); | |
73 | ||
74 | global $tsLocale; | |
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)); | |
79 | } | |
80 | ||
81 | function setDefaultValues() { | |
82 | return $this->_defaults; | |
83 | } | |
84 | ||
85 | function postProcess() { | |
86 | $values = $this->exportValues(); | |
87 | $table = $values['table']; | |
88 | $field = $values['field']; | |
89 | ||
90 | // validate table and field | |
91 | if (!isset($this->_structure[$table][$field])) { | |
92 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
93 | } | |
94 | ||
95 | $cols = array(); | |
96 | $params = array(array($values['id'], 'Int')); | |
97 | $i = 1; | |
98 | foreach ($this->_locales as $locale) { | |
99 | $cols[] = "{$field}_{$locale} = %$i"; | |
100 | $params[$i] = array($values["{$field}_{$locale}"], 'String'); | |
101 | $i++; | |
102 | } | |
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); | |
107 | ||
108 | CRM_Utils_System::civiExit(); | |
109 | } | |
110 | } | |
111 |