// 1) go through all .php's and document use cases as function calls.
// 2) create a json_api.php with those php functions that take arguments and return the json.
// 3) refactor the current user.php and prod.php etc to use them, parsing the json result into the currently used php arrays.
// 4) test if all documented use cases are working ok locally. only then push it live.
// 5) write a json_rpc_api.php with functions that parse a json rpc input call, detect the right call and wrap it to the corresponding function in json_api.php (or port the calls to nodejs/whatever)
// 6) replace all user.php and prod.php again and have them call the json_rpc_api directly?
// 7) refactor v2 to use json_rpc_api calls. open them to authenticated external calls.
// lets take this wonderful opportunity to migrate from the deprecated mysql to mysqli
// SELECT cdc, (CURRENT_DATE - timelock) as time, prods.name FROM users_cdcs LEFT JOIN prods ON prods.id = users_cdcs.cdc WHERE user='".$_SESSION["SCENEID_ID"]."'";
// create_cache_module("onelines", "SELECT oneliner.who,oneliner.message,users.nickname,users.avatar FROM oneliner,users WHERE oneliner.who=users.id ORDER BY oneliner.quand DESC LIMIT 50",0);
// $query="INSERT bbs_topics SET topic='".mysql_real_escape_string($topic)."',category='".(int)$_POST["category"]."',lastpost=NOW(),firstpost=NOW(),userlastpost=".$_SESSION["SCENEID_ID"].",userfirstpost=".$_SESSION["SCENEID_ID"];
// $query="SELECT who FROM comments where comment='".addslashes($comment)."' and who=".$_SESSION["SCENEID_ID"]." and which=".$which." ORDER BY quand DESC LIMIT 1";
// create_cache_module("latest_comments", "SELECT prods.id,prods.name,prods.type,prods.group1,prods.group2,prods.group3,comments.who,users.nickname,users.avatar FROM prods JOIN comments LEFT JOIN users ON users.id=comments.who WHERE comments.which=prods.id ORDER BY comments.quand DESC LIMIT 20",1);
// create_cache_module("top_demos", "SELECT prods.id, prods.name,prods.type,prods.group1,prods.group2,prods.group3 FROM prods WHERE prods.quand > DATE_SUB(sysdate(),INTERVAL '30' DAY) AND prods.quand < DATE_SUB(sysdate(),INTERVAL '0' DAY) ORDER BY (prods.views/((sysdate()-prods.quand)/100000)+prods.views)*prods.voteavg*prods.voteup desc LIMIT 50",1);
// are any of these beeing used for anything? should they be replaced?
//
// leave for later
// meanwhile poke gargaj for more info
//
//
// awardscandidates.php
//
// dont think this will be needed anymore, not worth porting
//
//
// bbs_del.php
//
// uc_bbs_del_1
// delete bbs
// should deletions also be wrapped in jsonp api?
//
// bbs.php
//
// uc_bbs_1
// $query="SELECT count(0) FROM bbs_topics";
// if ($_GET["categoryfilter"])
// $query.= sprintf(" where bbs_topics.category = %d",$_GET["categoryfilter"]);
//$result=mysql_query($query);
//$nb_topics=mysql_result($result,0);
// uc_bbs_2
//$query="SELECT bbs_topics.id, bbs_topics.topic, bbs_topics.firstpost, bbs_topics.lastpost, bbs_topics.userfirstpost, bbs_topics.userlastpost, bbs_topics.count, bbs_topics.category, users1.nickname as nickname_1, users1.avatar as avatar_1, users2.nickname as nickname_2, users2.avatar as avatar_2 FROM bbs_topics LEFT JOIN users as users2 on users2.id=bbs_topics.userfirstpost LEFT JOIN users as users1 on users1.id=bbs_topics.userlastpost";
//if ($_GET["categoryfilter"])
// $query.= sprintf(" where bbs_topics.category = %d",$_GET["categoryfilter"]);
//switch($order) {
// case "userfirstpost": $query.=" ORDER BY nickname_2, avatar_2, bbs_topics.lastpost //DESC"; break;
// case "firstpost": $query.=" ORDER BY firstpost DESC"; break;
// case "userlastpost": $query.=" ORDER BY nickname_1, avatar_1, bbs_topics.lastpost DESC"; break;
// case "lastpost": $query.=" ORDER BY bbs_topics.lastpost DESC"; break;
// case "count": $query.=" ORDER BY bbs_topics.count DESC"; break;
// case "topic": $query.=" ORDER BY bbs_topics.topic"; break;
// case "category": $query.=" ORDER BY bbs_topics.category"; break;
// default: $query.=" ORDER BY bbs_topics.lastpost DESC"; break;
// this should probably get seperated into 2 use cases, first being which=id and the second the pattern lookup
//
// if($which) {
// $query = "SELECT bbs2 from bbsesaka WHERE bbs1=".$which;
// $result = mysql_query($query);
// while($tmp=mysql_fetch_array($result)) {
// $bbsesaka[]=$tmp;
// }
// $query="SELECT id,name,sysop,started,closed,phonenumber,telnetip,added,adder FROM bbses WHERE id=".$which;
// for($i=0;$i<count($bbsesaka);$i++) { $query.=" OR id=".$bbsesaka[$i]["bbs2"]; }
// } elseif($pattern) {
// if($pattern=="#") {
// $sqlwhere="(name LIKE '0%')||(name LIKE '1%')||(name LIKE '2%')||(name LIKE '3%')||(name LIKE '4%')||(name LIKE '5%')||(name LIKE '6%')||(name LIKE '7%')||(name LIKE '8%')||(name LIKE '9%')";
// } else {
// $sqlwhere="name LIKE '".$pattern."%'";
// }
// $query="SELECT id,name,phonenumber,telnetip FROM bbses WHERE (".$sqlwhere.") ORDER BY name";
// }
// $result = mysql_query($query);
// while($tmp = mysql_fetch_array($result)) {
// $bbses[]=$tmp;
// }
//
// if($which) {
// //get user who added this bbs
// $query="SELECT id,nickname,avatar FROM users WHERE id=".$bbses[0]["adder"];
// $result=mysql_query($query);
// $myuser=mysql_fetch_array($result);
//
// $query="SELECT prods.id, prods.name, prods.group1, groups.name as group1name from prods LEFT JOIN groups on prods.group1=groups.id WHERE prods.boardID=$which";
// $result = mysql_query($query);
// while($tmp = mysql_fetch_array($result)) {
// $bbstros[]=$tmp;
// }
//
// $query="SELECT affiliatedbbses.group,affiliatedbbses.type,groups.name from affiliatedbbses LEFT JOIN groups on affiliatedbbses.group=groups.id WHERE affiliatedbbses.bbs=$which ORDER BY affiliatedbbses.type, groups.name";
// $result = mysql_query($query);
// while($tmp = mysql_fetch_array($result)) {
// $bbsaffils[]=$tmp;
// }
//
// $query="SELECT * from othernfos WHERE type='bbs' and refid='$which'";
// $result = mysql_query($query);
// while($tmp = mysql_fetch_array($result)) {
// $bbsnfos[]=$tmp;
// }
//
// $query="select platforms.name,platforms.icon from bbses_platforms, platforms where bbses_platforms.bbs='".$which."' and platforms.id=bbses_platforms.platform";
// $result = mysql_query($query);
// while($tmp = mysql_fetch_array($result)) {
// $platforms[]=$tmp;
// }
// }
//
// buttons.php
//
// uc_buttons_1
// $query="SELECT type,img,url,alt FROM buttons WHERE dead = 0 ORDER BY type,RAND()";