Location: PHPKode > projects > PhpScribe Documentation Generator > setup.php
<?php
require_once("config/scribe.inc");
require_once(PHPSCRIBE_CLASS_HTML);
require_once(PHPSCRIBE_CLASS_FORMTEMPLATE);

$HTML = new Html();
$HTML->addStyle("phpscribe.css");
$HTML->addScript("setup.js");
$HTML->addBodyCfg("bgColor='#d6d6d6'");
$HTML->makePage();
$HTML->header->setAndPrepare("header.tpl");
$HTML->header->replace(array("imagePath"=>PHPSCRIBE_IMAGE_PATH,
                             "localPath"=>PHPSCRIBE_ABSOLUTE_PATH,
                             "pageTitle"=>"Setup"));
$HTML->footer->setAndPrepare("footer.tpl");
$HTML->footer->replace(array("imagePath"=>PHPSCRIBE_IMAGE_PATH,
                             "localPath"=>PHPSCRIBE_ABSOLUTE_PATH));
$HTML->printPage();

function Main() {
     global $PS_USER_CFG;
     if (!empty($_POST)) {
          SaveSettings($PS_USER_CFG);
     }
     while(list($key,$value)=each($PS_USER_CFG)) {
          $GLOBALS[$key] = $value;
     }
     $MAIN_TPL = new Template(PHPSCRIBE_TEMPLATE_PATH."main.tpl");
     $MAIN_TPL->prepare();
     $FORM = new formTemplate(PHPSCRIBE_XML_PATH."setup.xml",PHPSCRIBE_TEMPLATE_PATH."setup.tpl","setup",$_SERVER['PHP_SELF'],"POST");
     $FORM->Document = &$GLOBALS['HTML'];
     $FORM->inputStyle = "normal";
     $FORM->labelStyle = "subnav";
     $FORM->buttonStyle = "button";
     $FORM->jsPath = PHPSCRIBE_JAVASCRIPT_PATH;
     $FORM->processXML();
     $MAIN_TPL->assign("mainContent",$FORM->getContents());
     $MAIN_TPL->assign("imagePath",PHPSCRIBE_IMAGE_PATH);
     $MAIN_TPL->printToScreen();
     focus("setup","DATABASE_HOST");
}

function SaveSettings(&$PS_USER_CFG) {
     $out = "<?\n";
     while(list($key,$value)=each($_POST)) {
          if (!ereg("btn",$key)) {
               if ($value[strlen($value)-1] == "\/") {
                    $value = substr($value,0,strlen($value)-1);
               }
               $value = ($value == "1" ? "TRUE" : ($value == "0" ? "FALSE" : "\"".str_replace("\\\\","\\",str_replace("\\","\\\\",$value))."\""));
               $out .= "\$PS_USER_CFG['".$key."']=".$value.";\n";
               $GLOBALS['PS_USER_CFG'][$key] = str_replace("\\\\","\\",str_replace("\\","\\\\",$_POST[$key]));
          }
     }
     $out .= "\$PS_USER_CFG['CAPTURE_ERRORS']=TRUE;\n";
     $out .= "\$PS_USER_CFG['LOG_ERRORS']=TRUE;\n";
     $out .= "\$PS_USER_CFG['SHOW_ERRORS']=TRUE;\n";
     $out .= "?>\n";
     $fp = fopen("config/user.cfg","w") or trigger_error("Couldn't open settings file to write!",E_USER_ERROR);
     fputs($fp,$out);
     fclose($fp);
     alert("Settings were updated successfully!");
}
?>
Return current item: PhpScribe Documentation Generator