1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21:
22: class cSetupSystemData extends cSetupMask {
23:
24: 25: 26: 27: 28: 29:
30: public function __construct($step, $previous, $next) {
31: $cfg = cRegistry::getConfig();
32:
33: cSetupMask::__construct('templates/setup/forms/systemdata.tpl', $step);
34:
35: cArray::initializeKey($_SESSION, 'dbprefix', '');
36: cArray::initializeKey($_SESSION, 'dbhost', '');
37: cArray::initializeKey($_SESSION, 'dbuser', '');
38: cArray::initializeKey($_SESSION, 'dbname', '');
39: cArray::initializeKey($_SESSION, 'dbpass', '');
40: cArray::initializeKey($_SESSION, 'dbcharset', '');
41: cArray::initializeKey($_SESSION, 'dbcollation', '');
42:
43: if (cFileHandler::exists($cfg['path']['contenido_config'] . 'config.php')) {
44: $cfgBackup = $cfg;
45:
46: @include($cfg['path']['contenido_config'] . 'config.php');
47:
48: $aVars = array(
49: 'dbhost' => $cfg['db']['connection']['host'],
50: 'dbuser' => $cfg['db']['connection']['user'],
51: 'dbname' => $cfg['db']['connection']['database'],
52: 'dbpass' => $cfg['db']['connection']['password'],
53: 'dbprefix' => $cfg['sql']['sqlprefix'],
54: 'dbcharset' => $cfg['db']['connection']['charset'],
55: );
56:
57: $cfg = $cfgBackup;
58: unset($cfgBackup);
59:
60: foreach ($aVars as $aVar => $sValue) {
61: if ($_SESSION[$aVar] == '') {
62: $_SESSION[$aVar] = $sValue;
63: }
64: }
65: }
66:
67: $this->setHeader(i18n("Database Parameters", "setup"));
68: $this->_stepTemplateClass->set('s', 'TITLE', i18n("Database Parameters", "setup"));
69:
70: switch ($_SESSION['setuptype']) {
71: case 'setup':
72: $this->_stepTemplateClass->set('s', 'DESCRIPTION', i18n("Please enter the required database information. If you are unsure about the data, ask your provider or administrator.", "setup") . " " . i18n("If the database does not exist and your database user has the sufficient permissions, setup will create the database automatically.", "setup"));
73: break;
74: case 'upgrade':
75: $this->_stepTemplateClass->set('s', 'DESCRIPTION', i18n("Please enter the required database information. If the database data of your previous installation could have been read, the data will be inserted automatically. If you are unsure about the data, please ask your provider or administrator.", "setup"));
76: break;
77: }
78:
79: if ($_SESSION['dbprefix'] == '') {
80: $_SESSION['dbprefix'] = 'con';
81: }
82:
83: if ($_SESSION['dbcharset'] == '' && $_SESSION['setuptype'] == 'setup') {
84: $_SESSION['dbcharset'] = CON_SETUP_DBCHARSET;
85: }
86:
87: unset($_SESSION['install_failedchunks']);
88: unset($_SESSION['install_failedupgradetable']);
89: unset($_SESSION['configsavefailed']);
90: unset($_SESSION['htmlpath']);
91: unset($_SESSION['frontendpath']);
92:
93: $dbhost = new cHTMLTextbox('dbhost', $_SESSION['dbhost'], 30, 255);
94: $dbname = new cHTMLTextbox('dbname', $_SESSION['dbname'], 30, 255);
95: $dbuser = new cHTMLTextbox('dbuser', $_SESSION['dbuser'], 30, 255);
96:
97: if ($_SESSION['dbpass'] != '') {
98: $mpass = str_repeat('*', cString::getStringLength($_SESSION['dbpass']));
99: } else {
100: $mpass = '';
101: }
102:
103: $dbpass = new cHTMLPasswordbox('dbpass', $mpass, 30, 255);
104: $dbpass->attachEventDefinition('onchange handler', 'onchange', "document.setupform.dbpass_changed.value = 'true';");
105: $dbpass->attachEventDefinition('onchange handler', 'onkeypress', "document.setupform.dbpass_changed.value = 'true';");
106:
107: $dbpass_hidden = new cHTMLHiddenField('dbpass_changed', 'false');
108:
109: $dbprefix = new cHTMLTextbox('dbprefix', $_SESSION['dbprefix'], 10, 30);
110: $dbcharset = new cHTMLSelectElement('dbcharset');
111: $dbcollation = new cHTMLSelectElement('collationSelect', '1', 'collationSelect');
112: $dbcollation->setAttribute("onchange", "comboBox('collationSelect', 'collationText')");
113:
114:
115: if (!cFileHandler::exists($cfg['path']['contenido_config'] . 'config.php') || (defined('CON_UTF8') && CON_UTF8 === true)) {
116:
117: $hiddenFieldDbCharset = new cHTMLHiddenField('dbcharset', 'utf8');
118: $dbcharsetTextbox = $hiddenFieldDbCharset . 'utf8';
119:
120:
121: $hiddenFieldDbCollation = new cHTMLHiddenField('dbcollation', 'utf8_general_ci');
122: $dbCollationTextbox = $hiddenFieldDbCollation . 'utf8_general_ci';
123: } else {
124:
125:
126: $pos = 0;
127: $option = new cHTMLOptionElement('-- ' . i18n("No character set", "setup") . ' --', '');
128: $dbcharset->addOptionElement(++$pos, $option);
129: $selectedCharset = (!empty($_SESSION['dbcharset'])) ? $_SESSION['dbcharset'] : '';
130: $aCharsets = fetchMySQLCharsets();
131: foreach ($aCharsets as $p => $charset) {
132: $selected = ($selectedCharset == $charset);
133: $option = new cHTMLOptionElement($charset, $charset, $selected);
134: $dbcharset->addOptionElement(++$pos, $option);
135: }
136: $dbcharsetTextbox = $dbcharset->render();
137:
138:
139: $pos = 0;
140: $noOp = new cHTMLOptionElement('-- ' . i18n("Other", "setup") . ' --', '');
141: $dbcollation->addOptionElement(++$pos, $noOp);
142: $selectedCollation = (!empty($_SESSION['dbcollation'])) ? $_SESSION['dbcollation'] : 'utf8_general_ci';
143: $collations = fetchMySQLCollations();
144: foreach ($collations as $p => $collation) {
145: $selected = ($selectedCollation == $collation);
146: $option = new cHTMLOptionElement($collation, $collation, $selected);
147: $dbcollation->addOptionElement(++$pos, $option);
148: }
149: $dbCollationTextbox = new cHTMLTextbox('dbcollation', $selectedCollation, '', '', 'collationText'). $dbcollation->render();
150: }
151:
152: $this->_stepTemplateClass->set('s', 'LABEL_DBHOST', i18n("Database Server (IP or name)", "setup"));
153:
154: if ($_SESSION['setuptype'] == 'setup') {
155: $this->_stepTemplateClass->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup") . '<br>' . i18n("(use empty or non-existant database)", "setup"));
156: } else {
157: $this->_stepTemplateClass->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup"));
158: $dbcharset->setDisabled(true);
159: }
160:
161: $this->_stepTemplateClass->set('s', 'LABEL_DBUSERNAME', i18n("Database Username", "setup"));
162: $this->_stepTemplateClass->set('s', 'LABEL_DBPASSWORD', i18n("Database Password", "setup"));
163: $this->_stepTemplateClass->set('s', 'LABEL_DBPREFIX', i18n("Table Prefix", "setup"));
164: $this->_stepTemplateClass->set('s', 'LABEL_DBADVANCED', i18n("Advanced Settings", "setup"));
165: $this->_stepTemplateClass->set('s', 'LABEL_DBCHARSET', i18n("Database character set", "setup"));
166: $this->_stepTemplateClass->set('s', 'LABEL_DBCOLLATION', i18n("Database collation", "setup"));
167:
168: $this->_stepTemplateClass->set('s', 'INPUT_DBHOST', $dbhost->render());
169: $this->_stepTemplateClass->set('s', 'INPUT_DBNAME', $dbname->render());
170: $this->_stepTemplateClass->set('s', 'INPUT_DBUSERNAME', $dbuser->render());
171: $this->_stepTemplateClass->set('s', 'INPUT_DBPASSWORD', $dbpass->render() . $dbpass_hidden->render());
172: $this->_stepTemplateClass->set('s', 'INPUT_DBPREFIX', $dbprefix->render());
173: $this->_stepTemplateClass->set('s', 'INPUT_DBCHARSET', $dbcharsetTextbox);
174: $this->_stepTemplateClass->set('s', 'INPUT_DBCOLLATION', $dbCollationTextbox);
175:
176: $this->setNavigation($previous, $next);
177: }
178:
179: 180: 181: 182: 183: 184: 185:
186: public function cSetupSystemData($step, $previous, $next) {
187: cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
188: $this->__construct($step, $previous, $next);
189: }
190:
191: protected function _createNavigation() {
192: $link = new cHTMLLink('#');
193:
194: if ($_SESSION['setuptype'] == 'setup') {
195: $checkScript = sprintf(
196: "var msg = ''; if (document.setupform.dbhost.value == '') { msg += '%s '; } if (document.setupform.dbname.value == '') { msg += '%s '; } if (document.setupform.dbuser.value == '') { msg += '%s '; } if (document.setupform.dbhost.value != '' && document.setupform.dbname.value != '' && document.setupform.dbuser.value != '') { document.setupform.submit(); } else { alert(msg); }", i18n("You need to enter a database host."), i18n("You need to enter a database name."), i18n("You need to enter a database user.")
197: );
198: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_nextstep . "';");
199: $link->attachEventDefinition('submitAttach', 'onclick', $checkScript);
200: } else {
201: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_nextstep . "'; document.setupform.submit();");
202: }
203: $link->setClass("nav");
204: $link->setContent("<span>»</span>");
205:
206: $this->_stepTemplateClass->set('s', 'NEXT', $link->render());
207:
208: $backlink = new cHTMLLink('#');
209: $backlink->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_backstep . "';");
210: $backlink->attachEventDefinition('submitAttach', 'onclick', 'document.setupform.submit();');
211: $backlink->setClass("nav navBack");
212: $backlink->setContent("<span>»</span>");
213: $this->_stepTemplateClass->set('s', 'BACK', $backlink->render());
214: }
215:
216: }
217:
218: ?>