# HG changeset patch # User Matti Hamalainen # Date 1416355913 -7200 # Node ID 884c97eb35858f4cb068ec784fb642e9d5db33ed # Parent 26a168d3390f635c9d340a3d5b65ba78ea091b9c Work on handling of compo entry data per compo type. diff -r 26a168d3390f -r 884c97eb3585 admajax.php --- a/admajax.php Wed Nov 19 02:08:40 2014 +0200 +++ b/admajax.php Wed Nov 19 02:11:53 2014 +0200 @@ -52,7 +52,7 @@ } -function stValidateRequestEntryData(&$compo_id, $full) +function stValidateRequestEntryData(&$compo_id, $full, $ctype) { $res = TRUE; @@ -60,28 +60,37 @@ array(CHK_ISGT, VT_STR, 0, "Entry name too short."), array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NAME, "Entry name too long.")); - stChkRequestItemFail("author", $fake, $res, - array(CHK_ISGT, VT_STR, 0, "Author name not set."), - array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_AUTHOR, "Entry author too long.")); - - stChkRequestItemFail("filename", $fake, $res, - array(CHK_TYPE, VT_TEXT, "Invalid data."), - array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_FILENAME, "Entry filename too long.")); - - stChkRequestItemFail("info", $fake, $res, - array(CHK_TYPE, VT_TEXT, "Invalid data."), - array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_INFO, "Entry info too long.")); - stChkRequestItemFail("compo_id", $compo_id, $res, array(CHK_TYPE, VT_INT, "Invalid compo ID.")); - if ($full) + stChkRequestItemFail("notes", $fake, $res, + array(CHK_TYPE, VT_TEXT, "Invalid data."), + array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NOTES, "Entry notes too long.")); + + switch ($ctype) { - stChkRequestItemFail("notes", $fake, $res, - array(CHK_TYPE, VT_TEXT, "Invalid data."), - array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NOTES, "Entry notes too long.")); + case COMPO_NORMAL: + stChkRequestItemFail("author", $fake, $res, + array(CHK_ISGT, VT_STR, 0, "Author name not set."), + array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_AUTHOR, "Entry author too long.")); + + stChkRequestItemFail("filename", $fake, $res, + array(CHK_TYPE, VT_TEXT, "Invalid data."), + array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_FILENAME, "Entry filename too long.")); + + stChkRequestItemFail("info", $fake, $res, + array(CHK_TYPE, VT_TEXT, "Invalid data."), + array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_INFO, "Entry info too long.")); + break; + + case COMPO_POINTS: + case COMPO_ASSIGN: + stChkRequestItemFail("evalue", $fake, $res, + array(CHK_TYPE, VT_INT, "Invalid evalue.")); + break; } + return $res; } @@ -1512,17 +1521,28 @@ stExecSQLCond($sql, "OK, attendee added."); } else - if ($type == "entry" && stValidateRequestEntryData($fake, FALSE)) + if ($type == "entry") { - if (stFetchSQLColumn(stPrepareSQL("SELECT id FROM compos WHERE id=%D", "compo_id")) === FALSE) - { + if (($compo = stFetchSQL(stPrepareSQL("SELECT * FROM compos WHERE id=%D", "compo_id"))) === FALSE) stError("No such compo ID."); - } else + if (stValidateRequestEntryData($cfake, TRUE, $compo["ctype"])) { - $sql = stPrepareSQL( - "INSERT INTO entries (name,author,compo_id,filename,info) VALUES (%S,%S,%D,%S,%Q)", - "name", "author", "compo_id", "filename", "info"); + switch ($compo["type"]) + { + case COMPO_NORMAL: + $sql = stPrepareSQL( + "INSERT INTO entries (name,author,compo_id,filename,info,notes) VALUES (%S,%S,%d,%S,%Q,%Q)", + "name", "author", $compo["id"], "filename", "info", "notes"); + break; + + case COMPO_POINTS: + case COMPO_ASSIGN: + $sql = stPrepareSQL( + "INSERT INTO entries (name,compo_id,notes) VALUES (%S,%d,%Q)", + "name", $compo["id"], "notes"); + break; + } stExecSQLCond($sql, "OK, entry added."); } @@ -1614,24 +1634,38 @@ } } else - if ($type == "entry" && stValidateRequestEntryData($compo_id, TRUE)) + if ($type == "entry") { - if (stFetchSQLColumn("SELECT id FROM compos WHERE id=".$compo_id) === FALSE) + if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$compo_id)) === FALSE) + stError("No such compo ID."); + else + if (stValidateRequestEntryData($compo_id, TRUE, $compo["ctype"])) { - stError("No such compo ID."); - } - else - { + switch ($compo["ctype"]) + { + case COMPO_NORMAL: + $cdata = array( + "author" => "S", + "filename" => "S", + "info" => "Q", + ); + break; + + case COMPO_POINTS: + case COMPO_ASSIGN: + $cdata = array( + "evalue" => "D", + ); + break; + } + $sql = stPrepareSQLUpdate("entries", "WHERE id=".$id, - array( + array_merge(array( "name" => "S", - "author" => "S", - "filename" => "S", - "info" => "Q", "notes" => "Q", "compo_id" => "D", - )); + ), $cdata)); stExecSQLCond($sql, "OK, entry updated."); }