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:
38: if (cFileHandler::exists($cfg['path']['contenido_config'] . 'config.php')) {
39: $cfgBackup = $cfg;
40:
41: @include($cfg['path']['contenido_config'] . 'config.php');
42:
43: $aVars = array(
44: 'dbhost' => $cfg['db']['connection']['host'],
45: 'dbuser' => $cfg['db']['connection']['user'],
46: 'dbname' => $cfg['db']['connection']['database'],
47: 'dbpass' => $cfg['db']['connection']['password'],
48: 'dbprefix' => $cfg['sql']['sqlprefix'],
49: 'dbcharset' => $cfg['db']['connection']['charset'],
50: );
51:
52: $cfg = $cfgBackup;
53: unset($cfgBackup);
54:
55: foreach ($aVars as $aVar => $sValue) {
56: if ($_SESSION[$aVar] == '') {
57: $_SESSION[$aVar] = $sValue;
58: }
59: }
60: }
61:
62: $this->setHeader(i18n("Database Parameters", "setup"));
63: $this->_oStepTemplate->set('s', 'TITLE', i18n("Database Parameters", "setup"));
64:
65: switch ($_SESSION['setuptype']) {
66: case 'setup':
67: $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"));
68: break;
69: case 'upgrade':
70: $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"));
71: break;
72: }
73:
74: if ($_SESSION['dbprefix'] == '') {
75: $_SESSION['dbprefix'] = 'con';
76: }
77:
78: if ($_SESSION['dbcharset'] == '' && $_SESSION['setuptype'] == 'setup') {
79: $_SESSION['dbcharset'] = CON_SETUP_DBCHARSET;
80: }
81:
82: unset($_SESSION['install_failedchunks']);
83: unset($_SESSION['install_failedupgradetable']);
84: unset($_SESSION['configsavefailed']);
85: unset($_SESSION['htmlpath']);
86: unset($_SESSION['frontendpath']);
87:
88: $dbhost = new cHTMLTextbox('dbhost', $_SESSION['dbhost'], 30, 255);
89: $dbname = new cHTMLTextbox('dbname', $_SESSION['dbname'], 30, 255);
90: $dbuser = new cHTMLTextbox('dbuser', $_SESSION['dbuser'], 30, 255);
91:
92: if ($_SESSION['dbpass'] != '') {
93: $mpass = str_repeat('*', strlen($_SESSION['dbpass']));
94: } else {
95: $mpass = '';
96: }
97:
98: $dbpass = new cHTMLPasswordbox('dbpass', $mpass, 30, 255);
99: $dbpass->attachEventDefinition('onchange handler', 'onchange', "document.setupform.dbpass_changed.value = 'true';");
100: $dbpass->attachEventDefinition('onchange handler', 'onkeypress', "document.setupform.dbpass_changed.value = 'true';");
101:
102: $dbpass_hidden = new cHTMLHiddenField('dbpass_changed', 'false');
103:
104: $dbprefix = new cHTMLTextbox('dbprefix', $_SESSION['dbprefix'], 10, 30);
105: $dbcharset = new cHTMLSelectElement('dbcharset');
106:
107:
108: $pos = 0;
109: $option = new cHTMLOptionElement('-- ' . i18n("No character set", "setup") . ' --', '');
110: $dbcharset->addOptionElement(++$pos, $option);
111: $selectedCharset = (!empty($_SESSION['dbcharset'])) ? $_SESSION['dbcharset'] : '';
112: $aCharsets = fetchMySQLCharsets();
113: foreach ($aCharsets as $p => $charset) {
114: $selected = ($selectedCharset == $charset);
115: $option = new cHTMLOptionElement($charset, $charset, $selected);
116: $dbcharset->addOptionElement(++$pos, $option);
117: }
118:
119: $this->_oStepTemplate->set('s', 'LABEL_DBHOST', i18n("Database Server (IP or name)", "setup"));
120:
121: if ($_SESSION['setuptype'] == 'setup') {
122: $this->_oStepTemplate->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup") . '<br>' . i18n("(use empty or non-existant database)", "setup"));
123: } else {
124: $this->_oStepTemplate->set('s', 'LABEL_DBNAME', i18n("Database Name", "setup"));
125: $dbcharset->setDisabled(true);
126: }
127:
128: $this->_oStepTemplate->set('s', 'LABEL_DBUSERNAME', i18n("Database Username", "setup"));
129: $this->_oStepTemplate->set('s', 'LABEL_DBPASSWORD', i18n("Database Password", "setup"));
130: $this->_oStepTemplate->set('s', 'LABEL_DBPREFIX', i18n("Table Prefix", "setup"));
131: $this->_oStepTemplate->set('s', 'LABEL_DBCHARSET', i18n("Database character set", "setup"));
132:
133: $this->_oStepTemplate->set('s', 'INPUT_DBHOST', $dbhost->render());
134: $this->_oStepTemplate->set('s', 'INPUT_DBNAME', $dbname->render());
135: $this->_oStepTemplate->set('s', 'INPUT_DBUSERNAME', $dbuser->render());
136: $this->_oStepTemplate->set('s', 'INPUT_DBPASSWORD', $dbpass->render() . $dbpass_hidden->render());
137: $this->_oStepTemplate->set('s', 'INPUT_DBPREFIX', $dbprefix->render());
138: $this->_oStepTemplate->set('s', 'INPUT_DBCHARSET', $dbcharset->render());
139:
140: $this->setNavigation($previous, $next);
141: }
142:
143: function _createNavigation() {
144: $link = new cHTMLLink('#');
145:
146: if ($_SESSION['setuptype'] == 'setup') {
147: $checkScript = sprintf(
148: "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.")
149: );
150: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bNextstep . "';");
151: $link->attachEventDefinition('submitAttach', 'onclick', $checkScript);
152: } else {
153: $link->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bNextstep . "'; document.setupform.submit();");
154: }
155: $link->setClass("nav");
156: $link->setContent("<span>»</span>");
157:
158:
159: $this->_oStepTemplate->set('s', 'NEXT', $link->render());
160:
161: $backlink = new cHTMLLink('#');
162: $backlink->attachEventDefinition('pageAttach', 'onclick', "document.setupform.step.value = '" . $this->_bBackstep . "';");
163: $backlink->attachEventDefinition('submitAttach', 'onclick', 'document.setupform.submit();');
164: $backlink->setClass("nav navBack");
165: $backlink->setContent("<span>»</span>");
166: $this->_oStepTemplate->set('s', 'BACK', $backlink->render());
167: }
168:
169: }
170:
171: ?>