From 0d53041fc67e13fc53cca0c993ec1a7a31a5a16e Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 15 Jan 2017 05:57:19 -0500 Subject: Reorganize examples/ directory --- examples/model/sysconf.mod.php | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 examples/model/sysconf.mod.php (limited to 'examples/model/sysconf.mod.php') diff --git a/examples/model/sysconf.mod.php b/examples/model/sysconf.mod.php new file mode 100644 index 0000000..cfbed42 --- /dev/null +++ b/examples/model/sysconf.mod.php @@ -0,0 +1,93 @@ +field_text("dbAddress"); + $form->field_text("dbName"); + $form->field_text("dbUser"); + $form->field_text("dbPass", null, false); + $form->field_enum("settSSL", array("force", "neither", "forbid")); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + /* test database connection (set global vars and try to get a db object) */ + $_SCROTT['conf'] = 'conf'; + $_SCROTT['dbEngine'] = 'mysql'; + $_SCROTT['dbAddress'] = $form->dbAddress; + $_SCROTT['dbName'] = $form->dbName; + $_SCROTT['dbUser'] = $form->dbUser; + $_SCROTT['dbPass'] = $form->dbPass; + + try + { + $db = $this->getDbConnection(); + } + catch (Exception $e) + { + $this->logError($e->getMessage()); + return; + } + + /* write file */ + $f = fopen($this->CONF_FILE, "w"); + + if (!$f) + { + $this->logError("Can not create configuration file"); + return; + } + + fwrite($f, "dbAddress . "';\n"); + fwrite($f, "\$_SCROTT['dbName'] = '" . $form->dbName . "';\n"); + fwrite($f, "\$_SCROTT['dbUser'] = '" . $form->dbUser . "';\n"); + fwrite($f, "\$_SCROTT['dbPass'] = '" . $form->dbPass . "';\n"); + fwrite($f, "\$_SCROTT['settSSL'] = '" . $form->settSSL . "';\n"); + fwrite($f, "?>\n"); + + fclose($f); + $this->redirectTo($this->ar() . "/"); + } +} + +?> -- cgit v1.2.3