1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cSetupSystemData extends cSetupMask {
25:
26: function cSetupSystemData($step, $previous, $next) {
27: global $cfg;
28:
29: cSetupMask::cSetupMask('templates/setup/forms/systemdata.tpl', $step);
30:
31: cArray::initializeKey($_SESSION, 'dbprefix', '');
32: cArray::initializeKey($_SESSION, 'dbhost', '');
33: cArray::initializeKey($_SESSION, 'dbuser', '');
34: cArray::initializeKey($_SESSION, 'dbname', '');
35: cArray::initializeKey($_SESSION, 'dbpass', '');
36: cArray::initializeKey($_SESSION, 'dbcharset', '');
37: cArray::initializeKey($_SESSION, 'dbcollation', '');
38:
39: if (cFileHandler::exists($cfg['path']['contenido_config'] . 'config.php')) {
40: $cfgBackup = $cfg;
41:
42: @include($cfg['path']['contenido_config'] . 'config.php');
43:
44: $aVars = array(
45: 'dbhost' => $cfg['db']['connection']['host'],
46: 'dbuser' => $cfg['db']['connection']['user'],
47: 'dbname' => $cfg['db']['connection']['database'],
48: 'dbpass' => $cfg['db']['connection']['password'],
49: 'dbprefix' => $cfg['sql']['sqlprefix'],
50: 'dbcharset' => $cfg['db']['connection']['charset'],
51: );
52:
53: $cfg = $cfgBackup;
54: unset($cfgBackup);
55:
56: foreach ($aVars as $aVar => $sValue) {
57: if ($_SESSION[$aVar] == '') {
58: $_SESSION[$aVar] = $sValue;
59: }
60: }
61: }
62:
63: $this->setHeader(i18n("Database Parameters", "setup"));
64: $this->_oStepTemplate->set('s', 'TITLE', i18n("Database Parameters", "setup"));
65:
66: switch ($_SESSION['setuptype']) {
67: case 'setup':
68: $this->_oStepTemplate->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"));
69: break;
70: case 'upgrade':
71: $this->_oStepTemplate->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"));
72: break;
73: }
74:
75: if ($_SESSION['dbprefix'] == '') {
76: $_SESSION['dbprefix'] = 'con';
77: }
78:
79: if ($_SESSION['dbcharset'] == '' && $_SESSION['setuptype'] == 'setup') {
80: $_SESSION['dbcharset'] = CON_SETUP_DBCHARSET;
81: }
82:
83: unset($_SESSION['install_failedchunks']);
84: unset($_SESSION['install_failedupgradetable']);
85: unset($_SESSION['configsavefailed']);
86: unset($_SESSION['htmlpath']);
87: unset($_SESSION['frontendpath']);
88:
89: $dbhost = new cHTMLTextbox('dbhost', $_SESSION['dbhost'], 30, 255);
90: $dbname = new cHTMLTextbox('dbname', $_SESSION['dbname'], 30, 255);
91: $dbuser = new cHTMLTextbox('dbuser', $_SESSION['dbuser'], 30, 255);
92:
93: if ($_SESSION['dbpass'] != '') {
94: $mpass = str_repeat('*', strlen($_SESSION['dbpass']));
95: } else {
96: $mpass = '';
97: }
98:
99: $dbpass = new cHTMLPasswordbox('dbpass', $mpass, 30, 255);
100: $dbpass->attachEventDefinition('onchange handler', 'onchange', "document.setupform.dbpass_changed.value = 'true';");
101: $dbpass->attachEventDefinition('onchange handler', 'onkeypress', "document.setupform.dbpass_changed.value = 'true';");
102:
103: $dbpass_hidden = new cHTMLHiddenField('dbpass_changed', 'false');
104:
105: $dbprefix = new cHTMLTextbox('dbprefix', $_SESSION['dbprefix'], 10, 30);
106: $dbcharset = new cHTMLSelectElement('dbcharset');
107: $dbcollation = new cHTMLSelectElement('collationSelect', '1', 'collationSelect');
108: $dbcollation->setAttribute("onchange", "comboBox('collationSelect', 'collationText')");
109:
110:
111: $pos = 0;
112: $option = new cHTMLOptionElement('-- ' . i18n("No character set", "setup") . ' --', '');
113: $dbcharset->addOptionElement(++$pos, $option);
114: $selectedCharset = (!empty($_SESSION['dbcharset'])) ? $_SESSION['dbcharset'] : '';
115: $aCharsets = fetchMySQLCharsets();
116: foreach ($aCharsets as $p => $charset) {
117: $selected = ($selectedCharset == $charset);
118: $option = new cHTMLOptionElement($charset, $charset, $selected);
119: $dbcharset->addOptionElement(++$pos, $option);
120: }
121:
122:
123: $pos = 0;
124: $noOp = new cHTMLOptionElement('-- ' . i18n("Other", "setup") . ' --', '');
125: $dbcollation->addOptionElement(++$pos, $noOp);
126: $selectedCollation = (!empty($_SESSION['dbcollation'])) ? $_SESSION['dbcollation'] : 'utf8_general_ci';
127: $collations = fetchMySQLCollations();
128: foreach ($collations as $p => $collation) {
129: $selected = ($selectedCollation == $collation);
130: $option = new cHTMLOptionElement($collation, $collation, $selected);
131: $dbcollation->addOptionElement(++$pos, $option);
132: }
133: $dbCollationTextbox = new cHTMLTextbox('dbcollation', $selectedCollation, '', '', 'collationText');
134:
135:
136: $this->_oStepTemplate->set('s', 'LABEL_DBHOST', i18n("Database Server (IP or name)", "setup"));
137:
138: if ($_SESSION['setuptype'] == 'setup') {
139: $this->_oStepTemplate->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup") . '<br>' . i18n("(use empty or non-existant database)", "setup"));
140: } else {
141: $this->_oStepTemplate->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup"));
142: $dbcharset->setDisabled(true);
143: }
144:
145: $this->_oStepTemplate->set('s', 'LABEL_DBUSERNAME', i18n("Database Username", "setup"));
146: $this->_oStepTemplate->set('s', 'LABEL_DBPASSWORD', i18n("Database Password", "setup"));
147: $this->_oStepTemplate->set('s', 'LABEL_DBPREFIX', i18n("Table Prefix", "setup"));
148: $this->_oStepTemplate->set('s', 'LABEL_DBADVANCED', i18n("Advanced Settings", "setup"));
149: $this->_oStepTemplate->set('s', 'LABEL_DBCHARSET', i18n("Database character set", "setup"));
150: $this->_oStepTemplate->set('s', 'LABEL_DBCOLLATION', i18n("Database collation", "setup"));
151:
152: $this->_oStepTemplate->set('s', 'INPUT_DBHOST', $dbhost->render());
153: $this->_oStepTemplate->set('s', 'INPUT_DBNAME', $dbname->render());
154: $this->_oStepTemplate->set('s', 'INPUT_DBUSERNAME', $dbuser->render());
155: $this->_oStepTemplate->set('s', 'INPUT_DBPASSWORD', $dbpass->render() . $dbpass_hidden->render());
156: $this->_oStepTemplate->set('s', 'INPUT_DBPREFIX', $dbprefix->render());
157: $this->_oStepTemplate->set('s', 'INPUT_DBCHARSET', $dbcharset->render());
158: $this->_oStepTemplate->set('s', 'INPUT_DBCOLLATION', $dbCollationTextbox . $dbcollation->render());
159:
160: $this->setNavigation($previous, $next);
161: }
162:
163: function _createNavigation() {
164: $link = new cHTMLLink('#');
165:
166: if ($_SESSION['setuptype'] == 'setup') {
167: $checkScript = sprintf(
168: "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.")
169: );
170: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bNextstep . "';");
171: $link->attachEventDefinition('submitAttach', 'onclick', $checkScript);
172: } else {
173: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bNextstep . "'; document.setupform.submit();");
174: }
175: $link->setClass("nav");
176: $link->setContent("<span>»</span>");
177:
178:
179: $this->_oStepTemplate->set('s', 'NEXT', $link->render());
180:
181: $backlink = new cHTMLLink('#');
182: $backlink->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bBackstep . "';");
183: $backlink->attachEventDefinition('submitAttach', 'onclick', 'document.setupform.submit();');
184: $backlink->setClass("nav navBack");
185: $backlink->setContent("<span>»</span>");
186: $this->_oStepTemplate->set('s', 'BACK', $backlink->render());
187: }
188:
189: }
190:
191: ?>