view admin.php @ 820:e213dca6354d

Add filename as ref variable argument to stSetFileEntryFilename().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 24 Nov 2014 22:31:47 +0200
parents 8b1abca34033
children ab2697983ab0
line wrap: on
line source

<?
//
// FAPWeb - Simple Web-based Demoparty Management System
// Party administration page frontend module
// (C) Copyright 2012-2014 Tecnic Software productions (TNSP)
//
$sessionType = "admin";
require_once "mconfig.inc.php";
require_once "msite.inc.php";
require_once "msession.inc.php";
require_once "majax.inc.php";


function stCreateSettingsData()
{
  echo
  "<script type=\"text/javascript\">\n".
  "\n".
  "var jsSettingsArgs = [];\n";

  foreach (stExecSQL("SELECT * FROM settings_groups") as $group)
  {
    $args = array();
    if (($res = stExecSQL("SELECT * FROM settings WHERE vgroup=".$group["id"])) !== false)
    {
      foreach ($res as $item)
      {
        switch ($item["vtype"])
        {
          case VT_STR:
          case VT_TEXT: $type = 1; break;
          case VT_INT:  $type = 2; break;
          case VT_BOOL: $type = 3; break;
        }
        $args[] = "\"".$item["key"]."\":".$type;
      }
    }

    echo "jsSettingsArgs[".$group["id"]."] = {".implode(",", $args)."};\n";
  }

  echo
  "\n".
  "function jsUpdateSettings(id)\n".
  "{\n".
  "  if (id in jsSettingsArgs)\n".
  "    jsSendPOSTRequest(\"action=update&type=settings&id=\"+id+\"&\"+jsMakePostArgs(jsSettingsArgs[id], \"st\", \"\"));\n".
  "  return false;\n".
  "}\n".
  "\n".
  "</script>\n";
}


function stLoginContent()
{
  echo "<div id=\"adminContent\">\n<div id=\"adminLogin\">";
}

function stLoginFooter()
{
  echo "</div>\n";
  cmPrintPageFooter();
}


// Switch to https first, if needed
if (!stCheckHTTPS())
{
  header("Location: https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
  exit;
}

// Start output
$pageCSS = "css/admin.css";
cmPrintPageHeader("FAPWeb Administration",
  "  <meta http-equiv=\"Pragma\" content=\"no-cache\" />\n",
  FALSE);


// Initiate SQL database connection
if (!stConnectSQLDB())
{
  // Error occured, bail out early
  cmPrintPageFooter();
  exit;
}

// Fetch non-"hardcoded" settings from SQL database
stReloadSettings();

// Check if sessions are enabled
if (!stChkSetting("admPassword"))
{
  stLoginContent();
  echo
    "<h1>Oh noes, admin configuration not done!</h1>\n".
    "<p>Better go and prod that, so you get to use the fine admin interface.</p>\n";
  stLoginFooter();
  exit;
}
else
if (!stAdmSessionAuth(FALSE))
{
  // Perform authentication if we are not in session already
  stLoginContent();
  echo
    "<h1>Party admin login</h1>\n".
    "<p>Please use illegal telepathy over HTTP to provide a ".
    "password to enter the party administration systembolaget.</p>\n".
    "\n".
    " ".stGetFormStart("admlogin", "admlogin.php").
    "  ".stGetFormHiddenInput("mode", "check")."\n".
    "  ".stGetFormPasswordInput("admpass", "", "", "autofocus=\"autofocus\"")."\n".
    "  ".stGetFormSubmitInput("submit", "Login")."\n".
    " </form>\n".
    "\n".
    "<p>[<a href=\"".stGetSetting("defaultPage")."\">Return to the main page</a>].</p>\n";
  stLoginFooter();
  exit;
}
else
{
stCreateSettingsData();
stCommonAJAX("admajax.php", "admlogout.php");
?>
<script type="text/javascript" src="admin.js"></script>

<!-- ========================== -->

<div id="adminPopup"></div>
<div id="adminContent">

<div id="nstatus">-</div>
<div id="tabHeadersCC" class="tabHeaders"></div>
<div id="tabContentsCC" class="tabContents"></div>

<script type="text/javascript">
  jsRegisterTab("CC", "Settings", "Settings");
  jsRegisterTab("CC", "News", "News");
  jsRegisterTab("CC", "Attendees", "Attendees");
  jsRegisterTab("CC", "Voting", "Voting");
  jsRegisterTab("CC", "Compos", "Compos");
  jsRegisterTab("CC", "Entries", "Entries");
  jsRegisterTab("CC", "InfoSys", "Infosystem");
  jsUpdateTabList("CC",
    "<a class=\"admin\" href=\"admlogout.php\">Logout</a> " +
    "<a class=\"admin\" href=\"about\">Mainpage</a>");
  jsSwitchActiveTab("CC", "Settings");
</script>
<?
}

cmPrintPageFooter();
?>