Mercurial > hg > fapweb
diff admin.php @ 171:705dabdc37d4
Move administration interface page to separate layout, to make things less cramped.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Oct 2013 06:47:42 +0200 |
parents | admin.inc.php@aeebfedb5709 |
children | 63c840590476 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/admin.php Sun Oct 27 06:47:42 2013 +0200 @@ -0,0 +1,445 @@ +<? +// +// FAPWeb Simple Demoparty System +// Party administration page frontend module +// (C) Copyright 2012-2013 Tecnic Software productions (TNSP) +// +$sessionType = "admin"; +require "mconfig.inc.php"; +require "msite.inc.php"; +require "mcommon.inc.php"; +require "msession.inc.php"; +require "majax.php"; + + +// Switch to https first, if needed +if (!stCheckHTTPS()) +{ + header("Location: https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); + exit; +} + +// Start output +cmPrintPageHeader("FAPWeb Administration", + " <meta http-equiv=\"Pragma\" content=\"no-cache\" />", + FALSE); + +echo "<div id=\"admCont\">\n"; + +// Initiate SQL database connection +if (!stConnectSQLDB()) +{ + // Error occured, bail out early + cmPrintPageFooter(); + exit; +} + +// Fetch non-"hardcoded" settings from SQL database +stReloadSettings(); + +function stCreateSettingsData() +{ + $args = array(); + + if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE) + { + foreach ($res as $item) + { + switch ($item["vtype"]) + { + case VT_STR: + case VT_TEXT: $type = 0; break; + case VT_INT: $type = 4; break; + case VT_BOOL: $type = 3; break; + } + $args[] = "\"".$item["key"]."\":".$type; + } + } + + echo + "\n". + "function updateSettings()\n". + "{\n". + " var args = makePostArgs({".implode(",", $args)."}, \"st\", \"\");\n". + " sendPOSTRequest(\"action=update&type=settings&\"+args);\n". + " return false;\n". + "}\n"; +} + +// Check if sessions are enabled +if (!stChkSetting("admPassword")) +{ + 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"; +} +else +if (!stAdmSessionAuth(FALSE)) +{ + // Perform authentication if we are not in session already + 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". + stGetFormStart("admlogin", "admlogin.php"). + stGetFormHiddenInput("mode", "check")."\n". + stGetFormPasswordInput("admpass", "", "")."\n". + stGetFormSubmitInput("submit", "Login"). + "</form>\n"; +} +else +{ +?> +<script type="text/javascript"> +// <? stCreateSettingsData(); stCommonAJAX("admajax.php", "admlogout.php", FALSE); ?> + + +function refreshItems(id,name,msgname) +{ + var msuccess = function(txt) + { + var nitem = document.getElementById(id); + nitem.innerHTML = txt; + } + + sendPOSTRequest("action=get&type="+name, msuccess); +} + + +function deleteItem(id,prefix,type,func,dsc) +{ + var msuccess = function(txt) + { + var item = document.getElementById(prefix+id); + item.style.display = "none"; + setTimeout(func, 50); + } + + // Clearly mark the element when asking confirmation + var item = document.getElementById(prefix+id); + var tmp = item.style.background; + item.style.background = "red"; + + // Ask confirmation for deletion + if (confirm("Are you sure you want to delete "+dsc+" #"+id+"?")) + { + // Okay, delete + sendPOSTRequest("action=delete&type="+type+"&id="+id, msuccess); + } + + // Restore background + item.style.background = tmp; +} + + +function refreshSettings() +{ + refreshItems("nsettings", "settings", "General settings"); +} + + +function refreshNews() +{ + refreshItems("nnews", "news", "News list"); +} + + +function refreshAttendees() +{ + refreshItems("nattendees", "attendees", "Attendees list"); +} + + +function refreshVoters() +{ + refreshItems("nvoters", "voters", "Voters list"); +} + + +function refreshCompos() +{ + refreshItems("ncompos", "compos", "Compo list"); +} + + +function refreshEntries() +{ + refreshItems("nentries", "entries", "Entry list"); +} + + +function addNews() +{ + var args = makePostArgs({"title":1,"text":1,"author":1}, "nn", ""); + + var msuccess = function(txt) + { + setTimeout("refreshNews();", 50); + } + + if (args != "") + sendPOSTRequest("action=add&type=news&"+args, msuccess); + + return false; +} + + +function deleteNews(id) +{ + deleteItem(id, "news", "news", "refreshNews();", "news item"); +} + + +function addAttendee() +{ + var args = makePostArgs({"name":1,"groups":0,"oneliner":0,"email":0}, "ne", "x"); + + var msuccess = function(txt) + { + setTimeout("refreshAttendees();", 50); + } + + if (args != "") + sendPOSTRequest("action=add&type=attendees&"+args, msuccess); + + return false; +} + + +function deleteAttendee(id) +{ + deleteItem(id, "attendee", "attendees", "refreshAttendees();", "attendee"); +} + + +function updateAttendee(id) +{ + var args = makePostArgs({"oneliner":0,"email":0,"active":3}, "at", id); + + var msuccess = function(txt) + { + setTimeout("refreshAttendees();", 50); + } + + if (args != "") + sendPOSTRequest("action=update&type=attendees&id="+id+"&"+args, msuccess); +} + + +function updateAttendee2(id) +{ + var elem = document.getElementById("atactive"+id); + if (elem && !elem.checked) + { + if (confirm("Are you sure you want deactivate vote ID #"+id+"?")) + updateAttendee(id); + else + setTimeout("refreshAttendees();", 50); + } + else + updateAttendee(id); +} + + +function addCompo() +{ + var args = makePostArgs({"name":1, "description":1}, "nc", ""); + + var msuccess = function(txt) + { + setTimeout("refreshCompos();", 50); + } + + if (args != "") + sendPOSTRequest("action=add&type=compo&"+args, msuccess); + return false; +} + + +function updateCompo(id) +{ + var args = makePostArgs({"name":1, "description":1, "visible":3, "voting":3, "showAuthors":3}, "co", id); + + if (args != "") + sendPOSTRequest("action=update&type=compo&id="+id+"&"+args); +} + + +function addEntry(id) +{ + var args = makePostArgs({"name":1, "author":1, "filename":0}, "ne", id); + + var msuccess = function(txt) + { + setTimeout("refreshEntries();", 50); + } + + if (args != "") + sendPOSTRequest("action=add&type=entry&compo_id="+id+"&"+args, msuccess); + return false; +} + + +function updateEntry(id) +{ + var args = makePostArgs({"name":1, "author":1, "filename":0, "compo_id":2}, "en", id); + + var msuccess = function(txt) + { + setTimeout("refreshEntries();", 50); + } + + if (args != "") + sendPOSTRequest("action=update&type=entry&id="+id+"&"+args, msuccess); +} + + +function deleteEntry(id) +{ + deleteItem(id, "entry", "entries", "refreshEntries();", "entry"); +} + + +var registeredTabs = Object(); + + +function updateTabList() +{ + var item = document.getElementById("pageTabs"); + var str = ""; + for (var id in registeredTabs) + { + str += "<a id=\"cc"+id+ + "\"href=\"#\" onClick=\"switchActiveTab('"+id+ + "')\">"+registeredTabs[id]+"</a>"; + } + + str += "<a class=\"admin\" href=\"admlogout.php\">Logout</a>"; + + item.innerHTML = str; +} + + +function registerTab(id, name) +{ + registeredTabs[id] = name; +} + + +function refreshTabs() +{ + for (var id in registeredTabs) + { + setTimeout("refresh"+ registeredTabs[id] +"();", 10); + } +} + + +function switchActiveTab(tab) +{ + for (var id in registeredTabs) + { + var ob = document.getElementById(id); + var ccob = document.getElementById("cc"+id); + if (ob && ccob) + { + ob.style.display = (tab == id) ? "block" : "none"; + ccob.style.borderTop = (tab == id) ? "4px solid white" : "none"; + if (tab == id) + { + setTimeout("refresh"+ registeredTabs[id] +"();", 10); + } + } + } +} +</script> + +<!-- ========================== --> + +<div id="nstatus">-</div> + +<div id="pageTabs"></div> + +<div id="admin"> +<div> + +<!-- ========================== --> + +<div id="tabSettings"> + <form method="post" action="" onsubmit="return updateSettings()"> + <div id="nsettings"></div> + </form> +</div> + +<!-- ========================== --> + +<div id="tabNews"> + <form method="post" action="" onsubmit="return addNews()"> + <input id="nntitle" type="text" size="40" /><br /> + <textarea id="nntext" rows="5" cols="60"></textarea><br /> + <input id="nnauthor" type="text" value="orgaz" /> + <input id="nnadd" type="submit" value=" Add post " /> + <input type="button" value=" Clear " onClick="this.form.reset()" /> + </form> + <hr /> + <div id="nnews"></div> +</div> + +<!-- ========================== --> + +<div id="tabAttendees"> + <div id="nattendees"></div> +</div> + +<!-- ========================== --> + +<div id="tabVoters"> + <div id="nvoters"></div> +</div> + +<!-- ========================== --> + +<div id="tabCompos"> + <form method="post" action="" onsubmit="return addCompo()"> + <input id="ncname" type="text" size="64" /><br /> + <textarea id="ncdescription" rows="5" cols="60"></textarea><br /> + <input id="nccompo" type="submit" value=" Add compo " /> + <input type="button" value=" Clear " onClick="this.form.reset()" /> + </form> + <hr /> + <div id="ncompos"></div> +</div> + +<!-- ========================== --> + +<div id="tabEntries"> + <div id="nentries"></div> +</div> + +<!-- ========================== --> + +<div id="tabInfo"> + <div id="ninfo"></div> +</div> + +<!-- ========================== --> + +</div> +</div> + +<script type="text/javascript"> + registerTab("tabSettings", "Settings"); + registerTab("tabNews", "News"); + registerTab("tabAttendees", "Attendees"); + registerTab("tabVoters", "Voters"); + registerTab("tabCompos", "Compos"); + registerTab("tabEntries", "Entries"); + registerTab("tabInfo", "Party Info"); + updateTabList(); + switchActiveTab("tabSettings"); +</script> +<? +} + +cmPrintPageFooter(); + +?> \ No newline at end of file