diff options
Diffstat (limited to 'app/model')
-rw-r--r-- | app/model/master.mod.php | 42 | ||||
-rw-r--r-- | app/model/sysconf.mod.php | 60 |
2 files changed, 102 insertions, 0 deletions
diff --git a/app/model/master.mod.php b/app/model/master.mod.php new file mode 100644 index 0000000..aebcaaa --- /dev/null +++ b/app/model/master.mod.php @@ -0,0 +1,42 @@ +<?php + +require_once "class/model.class.php"; + +class MasterModel extends Model +{ + /* + * Get the appropriate alert class to use when showing the notice modal + */ + function getNoticeModalAlertClass() + { + if ($this->isError()) + return "alert-danger"; + + if ($this->isWarning()) + return "alert-warning"; + + if ($this->isNotice()) + return "alert-info"; + + return ""; + } + + /* + * Get the appropriate glyphicon to use when showing the notice modal + */ + function getNoticeModalGlyphicon() + { + if ($this->isError()) + return "glyphicon glyphicon-remove-sign"; + + if ($this->isWarning()) + return "glyphicon glyphicon-exclamation-sign"; + + if ($this->isNotice()) + return "glyphicon glyphicon-info-sign"; + + return ""; + } +} + +?> diff --git a/app/model/sysconf.mod.php b/app/model/sysconf.mod.php new file mode 100644 index 0000000..30ebd58 --- /dev/null +++ b/app/model/sysconf.mod.php @@ -0,0 +1,60 @@ +<?php + +require_once "model/master.mod.php"; +require_once "class/form.class.php"; + +class SysconfModel extends MasterModel +{ + var $CONF_FILE = "scrott.conf.php"; + + /* + * Default action + */ + function deflt() + { + } + + /* + * Save the submitted data to the config file + */ + function save($input) + { + $form = new Form(); + $form->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; + } + + /* TODO -- test database connection before proceeding */ + + $f = fopen($this->CONF_FILE, "w"); + + if (!$f) + { + $this->logError("Can not create configuration file"); + return; + } + + fwrite($f, "<?php\n"); + fwrite($f, "\$_SCROTT['conf'] = 'conf';\n"); + fwrite($f, "\$_SCROTT['dbEngine'] = 'mysql';\n"); + fwrite($f, "\$_SCROTT['dbAddress'] = '" . $form->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()); + } +} + +?> |