# HG changeset patch # User Matti Hamalainen # Date 1447956690 -7200 # Node ID 35a00a986f7951cfa6c310903d9ecc7d95ddd4b9 # Parent 8f242f756b0b81dcb7dfab4ad0e364093c63f2ed Factorize compo entry adding into stAddCompoEntry(). diff -r 8f242f756b0b -r 35a00a986f79 admajax.php --- a/admajax.php Thu Nov 19 20:05:26 2015 +0200 +++ b/admajax.php Thu Nov 19 20:11:30 2015 +0200 @@ -1738,22 +1738,8 @@ else if (stValidateRequestEntryData($cfake, FALSE, $compo["ctype"])) { - switch ($compo["ctype"]) - { - case COMPO_NORMAL: - $sql = stPrepareSQL( - "INSERT INTO entries (name,author,compo_id,info,notes,utime,owner_id) VALUES (%S,%S,%d,%Q,%Q,%d,0)", - "name", "author", $compo["id"], "info", "notes", time()); - break; - - case COMPO_POINTS: - case COMPO_ASSIGN: - $sql = stPrepareSQL( - "INSERT INTO entries (name,compo_id,notes,evalue,utime,owner_id) VALUES (%S,%d,%Q,%D,%d,0)", - "name", $compo["id"], "notes", "evalue", time()); - break; - } - stExecSQLCond($sql, "OK, entry added."); + // The function gets most of its data from request parameters + stAddCompoEntry($compo, 0); // User ID = 0 for admin } } stDBCommitTransaction(); diff -r 8f242f756b0b -r 35a00a986f79 msite.inc.php --- a/msite.inc.php Thu Nov 19 20:05:26 2015 +0200 +++ b/msite.inc.php Thu Nov 19 20:11:30 2015 +0200 @@ -1323,4 +1323,26 @@ } +function stAddCompoEntry($compo, $uid) +{ + switch ($compo["ctype"]) + { + case COMPO_NORMAL: + $sql = stPrepareSQL( + "INSERT INTO entries (name,author,compo_id,info,notes,preview_type,utime,owner_id) VALUES (%S,%S,%d,%Q,%Q,%D,%d,%d)", + "name", "author", $compo["id"], "info", "notes", "preview_type", time(), $uid); + break; + + case COMPO_POINTS: + case COMPO_ASSIGN: + $sql = stPrepareSQL( + "INSERT INTO entries (name,compo_id,notes,evalue,utime,owner_id) VALUES (%S,%d,%Q,%D,%d,%d)", + "name", $compo["id"], "notes", "evalue", time(), $uid); + break; + } + + return stExecSQLCond($sql, "OK, entry added."); +} + + ?> \ No newline at end of file