Mercurial > hg > fapweb
changeset 370:d65f28bf1080
Add backend code for generating entry show positions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 03 Dec 2013 15:22:57 +0200 |
parents | a3caded43f6d |
children | 1a7f97a36047 |
files | admajax.php |
diffstat | 1 files changed, 41 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/admajax.php Tue Dec 03 15:18:20 2013 +0200 +++ b/admajax.php Tue Dec 03 15:22:57 2013 +0200 @@ -228,29 +228,52 @@ $type = stGetRequestItem("type", ""); switch (stGetRequestItem("action", "")) { - case "dump": + case "randomize": // - // Perform generic data dump + // Randomize entries display order // - if (($res = stExecSQLCond( - "SELECT * FROM attendees WHERE email NOT NULL AND email != '' ORDER BY regtime DESC")) !== FALSE) + if ($type == "set") { - stSetStatus(200, "Dump OK."); - $out1 = array(); - $out2 = array(); - - foreach ($res as $item) + if (($compos = stExecSQL("SELECT * FROM compos")) === FALSE) + stError("Eh? SQL error occured."); + else + foreach ($compos as $compo) { - $out1[] = chentities($item["name"])." <".chentities($item["email"]).">"; - $out2[] = chentities($item["email"]); + $entries = stExecSQL("SELECT id FROM entries WHERE compo_id=".$compo["id"]); + if ($entries !== FALSE) + { + $final = array(); + foreach ($entries as $entry) + $final[] = $entry["id"]; + + $index = 1; + foreach ($final as $entry) + { + $sql = stPrepareSQL("UPDATE entries SET show_id=%d WHERE id=%d", $index, $entry); + if (stExecSQL($sql) === false) + { + stError("Error updating entry show positions."); + break; + } + $index++; + } + } } - - echo "<br /><hr />". - implode(", ", $out1)."<br /><hr /><br />". - implode("<br />", $out1)."<br /><hr /><br />". - implode(", ", $out2)."<br /><hr /><br />". - implode("<br />", $out2)."<br /><hr />"; - + } + else + if ($type == "check") + { + if (($compos = stExecSQL("SELECT * FROM compos")) === FALSE) + stError("Eh? SQL error occured."); + else + foreach ($compos as $compo) + { + $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE show_id<>0 AND compo_id=".$compo["id"]); + if ($nentries > 0) + { + stError("Compo #".$compo["id"]." - ".$compo["name"]." has show order set for at least some entries."); + } + } } break;