Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Core_I18n_Form extends CRM_Core_Form { | |
36 | function buildQuickForm() { | |
37 | $config = CRM_Core_Config::singleton(); | |
d606fff7 | 38 | global $tsLocale; |
6a488035 TO |
39 | $this->_locales = array_keys($config->languageLimit); |
40 | ||
41 | // get the part of the database we want to edit and validate it | |
42 | $table = CRM_Utils_Request::retrieve('table', 'String', $this); | |
43 | $field = CRM_Utils_Request::retrieve('field', 'String', $this); | |
44 | $id = CRM_Utils_Request::retrieve('id', 'Int', $this); | |
45 | $this->_structure = CRM_Core_I18n_SchemaStructure::columns(); | |
46 | if (!isset($this->_structure[$table][$field])) { | |
47 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
48 | } | |
49 | ||
50 | $this->addElement('hidden', 'table', $table); | |
51 | $this->addElement('hidden', 'field', $field); | |
52 | $this->addElement('hidden', 'id', $id); | |
53 | ||
54 | $cols = array(); | |
55 | foreach ($this->_locales as $locale) { | |
56 | $cols[] = "{$field}_{$locale} {$locale}"; | |
57 | } | |
58 | $query = 'SELECT ' . implode(', ', $cols) . " FROM $table WHERE id = $id"; | |
59 | ||
60 | $dao = new CRM_Core_DAO(); | |
61 | $dao->query($query, FALSE); | |
62 | $dao->fetch(); | |
63 | ||
64 | // we want TEXTAREAs for long fields and INPUTs for short ones | |
65 | $this->_structure[$table][$field] == 'text' ? $type = 'textarea' : $type = 'text'; | |
66 | ||
67 | $languages = CRM_Core_I18n::languages(TRUE); | |
68 | foreach ($this->_locales as $locale) { | |
d606fff7 | 69 | $this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('class' => 'huge huge12' . ($locale == $tsLocale ? ' default-lang' : ''))); |
6a488035 TO |
70 | $this->_defaults["{$field}_{$locale}"] = $dao->$locale; |
71 | } | |
72 | ||
d606fff7 CW |
73 | $this->addDefaultButtons(ts('Save'), 'next', NULL); |
74 | ||
75 | CRM_Utils_System::setTitle(ts('Languages')); | |
6a488035 | 76 | |
6a488035 TO |
77 | $this->assign('locales', $this->_locales); |
78 | $this->assign('field', $field); | |
6a488035 TO |
79 | } |
80 | ||
b5c2afd0 EM |
81 | /** |
82 | * This virtual function is used to set the default values of | |
83 | * various form elements | |
84 | * | |
85 | * access public | |
86 | * | |
87 | * @return array reference to the array of default values | |
88 | * | |
89 | */ | |
6a488035 TO |
90 | function setDefaultValues() { |
91 | return $this->_defaults; | |
92 | } | |
93 | ||
94 | function postProcess() { | |
95 | $values = $this->exportValues(); | |
96 | $table = $values['table']; | |
97 | $field = $values['field']; | |
98 | ||
99 | // validate table and field | |
100 | if (!isset($this->_structure[$table][$field])) { | |
101 | CRM_Core_Error::fatal("$table.$field is not internationalized."); | |
102 | } | |
103 | ||
104 | $cols = array(); | |
105 | $params = array(array($values['id'], 'Int')); | |
106 | $i = 1; | |
107 | foreach ($this->_locales as $locale) { | |
108 | $cols[] = "{$field}_{$locale} = %$i"; | |
109 | $params[$i] = array($values["{$field}_{$locale}"], 'String'); | |
110 | $i++; | |
111 | } | |
112 | $query = "UPDATE $table SET " . implode(', ', $cols) . " WHERE id = %0"; | |
113 | $dao = new CRM_Core_DAO(); | |
114 | $query = CRM_Core_DAO::composeQuery($query, $params, TRUE); | |
115 | $dao->query($query, FALSE); | |
6a488035 TO |
116 | } |
117 | } | |
118 |