function lists() { $serviceid = $_SESSION["serviceid"]; echo "{"; print_jason_records(false, "SELECT id, name AS name, x, y, w, h, type FROM states WHERE serviceid={$serviceid} AND (type='s' OR type='')", "states"); echo "}"; }
function lists() { $serviceid = $_SESSION["serviceid"]; echo "{"; print_jason_records(false, "SELECT id, id1, id2 FROM connections WHERE serviceid={$serviceid}", "connections"); echo "}"; }
function getCurrentState() { echo "{"; $id = $_SESSION["current_state"]; if (!$id) { echo '"state":[]}'; return; } print_jason_records(false, "SELECT id, name, description_{$this->language} AS description, type, decision_type, input_type, question_{$this->language} AS question FROM states WHERE id = {$id}", "state"); print_jason_records(true, "SELECT connections.expr FROM connections INNER JOIN states ON states.id=connections.id2 WHERE id1 = {$id}", "answers"); $r = mysql_fetch_assoc(mysql_query("SELECT " . build_field_list(array("description", "info", "document", "video_link"), $this->language) . " FROM states WHERE id = {$id}")); echo ", \"video_links\":" . json_encode(explode("|", $r["video_link"])); echo ", \"documents\":" . json_encode(explode("|", $r["document"])); echo ", \"info\":" . json_encode(explode("|", $r["info"])); echo "}"; }
function print_json_record($qr, $r) { $first = true; echo '{'; $fieldc = mysql_num_fields($qr); for ($i = 0; $i < $fieldc; $i++) { if (mysql_field_name($qr, $i) == "subquery") { $subq = explode(";", $r[$i]); if ($subq[1] != "") { print_jason_records(true, $subq[1], $subq[0]); } } else { if (!$first) { echo ", "; } $type = mysql_field_type($qr, $i); $var_cont = $type == "string" || $type == "blob" || $type == "timestamp" ? '"' : ''; $val = $r[$i]; //$val = str_replace("\"","\\\"",$val); if ($val == "" && ($type == "int" || $type == "real")) { $val = 0; } if ($var_cont == '"') { echo '"' . mysql_field_name($qr, $i) . '":' . json_encode($val); } else { echo '"' . mysql_field_name($qr, $i) . '":' . $val; } $first = false; } } echo '}'; }