function child_render($param) { global $g_page, $g_cfg; $g_page["frame"] = "site_admin/frame.html"; if (!http_user_auth("admin", "admin")) { return redirect("/"); } if (isset($param[1]) && $param[1] == "switch_status") { list($cname, $p) = [$_GET["name"], $_GET["p"]]; if ($p == "close") { dbupdate("sys_variations", [], ["test" => $cname], ["completed" => "now()"]); } return redirect("/stats/multivariants"); } $q = gettable("select * from sys_variations where completed is null"); $t = []; foreach ($q as $row) { if (!isset($t[$row["test"]])) { $t[$row["test"]] = []; } if (!isset($t[$row["test"]][$row["variation"]])) { $t[$row["test"]][$row["variation"]] = ["goals" => []]; } $t[$row["test"]][$row["variation"]]["content"] = substr($row["content"], 0, 256); $cm = new Variant($row["test"]); $t[$row["test"]][$row["variation"]]["enrolled"] = $cm->get() == $row["variation"] ? 1 : 0; $t[$row["test"]][$row["variation"]]["variation"] = $row["variation"]; $cv = []; $cgoal = $row; $cgoal["pc"] = $row["sample"] == 0 ? "N/A" : round($row["conversion"] / $row["sample"] * 100, 2); $t[$row["test"]][$row["variation"]]["goals"][] = $cgoal; $t[$row["test"]][$row["variation"]] = update($t[$row["test"]][$row["variation"]], $cv); } $res = []; foreach ($t as $name => $row) { $cm = []; foreach ($t[$name] as $varname => $cvar) { uasort($cvar["goals"], function ($a, $b) { global $g_mv_goals; if (($i = array_search($a["goal"], $g_mv_goals)) === false) { return -1; } if (($j = array_search($b["goal"], $g_mv_goals)) === false) { return -1; } if ($i == $j) { return 0; } return $i > $j ? 1 : -1; }); $cm[] = $cvar; } $res[] = ["test" => $name, "var" => $cm]; } // print_r($res); exit; $scr = new Scriptor("site_admin/multivariants.html", ["tests" => $res]); return $scr->result(); }
function child_render($param) { $data = ["msglist" => gettable("select * from site_guestbook")]; $scr = new Scriptor("site_guestbook/guestbook.html", $data); return $scr->result(); }
function child_render($param) { variant_hitgoal("scr:purchasetest"); $scr = new Scriptor("site_guestbook/thanks.html"); return $scr->result(); }
function child_render($param) { $scr = new Scriptor("site_guestbook/purchase.html"); return $scr->result(); }
function child_render($param) { header("HTTP/1.0 404 Not Found"); $scr = new Scriptor("site_guestbook/notfound.html"); return $scr->result(); }
function result() { global $g_cfg, $g_page, $g_pageforms; $g_page = $this->defaults; // GET-less URI $uri = explode("?", $_SERVER["REQUEST_URI"]); $uri = $uri[0]; $cm = $this->map($uri); list($incfn, $childfunc) = is_array($cm) ? $cm : array($cm, null); // Rule 1: functions are called directly if ($incfn instanceof Closure) { $g_page["child"] = $incfn; } else { if (endsWith($incfn, ".html")) { $scr = new Scriptor($incfn, array()); $g_page["child"] = $scr->result(); $incfn = null; } else { if (!endsWith($incfn, ".php") && file_exists($incfn)) { // determine content-type via file extension $mimetype = "text/plain; charset=utf-8"; if (endsWith($incfn, ".ico")) { $mimetype = "image/x-icon"; } if (endsWith($incfn, ".xml")) { $mimetype = "application/xhtml+xml; charset=UTF-8"; } header("Content-Type: " . $mimetype); return file_get_contents($incfn); } } } // everything from hereon assumed to be UTF-8 string header("Content-Type: text/html; charset=UTF-8"); // include optional handler file; this gets merged in the global function space if ($incfn != null && (!is_callable($incfn) && file_exists($incfn))) { include_once $incfn; } // merge child_render into frame if (!isset($g_page["child"]) && is_callable("child_render")) { $g_page["child"] = function ($params) { return child_render($params); }; } if (!isset($g_page["child"])) { internal_error("No renderer for URL: " . $uri); } // handle forms if (isset($_POST["submitedForm"]) && isset($g_pageforms[$_POST["submitedForm"]])) { $g_page["child"] = $g_pageforms[$_POST["submitedForm"]]($this->regparams, $_POST); } if ($g_page["child"] instanceof Closure) { $g_page["child"] = $g_page["child"]($this->regparams); } // results are either: // - null for redirection, // - an array for ajax endpoints; or // - an UTF-8 string containing HTML output if ($g_page["child"] == null) { return ""; } if (is_array($g_page["child"])) { // JSONP extension // IE file uploading requires text/html header("Content-Type: application/json; charset=UTF-8"); if (isset($_GET["perfstats"]) && $g_cfg["debug"] == true) { global $g_logstart, $pagequeries; $g_logend = array_sum(explode(' ', microtime())); $pagegen = $g_logend - $g_logstart; $g_page["child"]["__perfstats"] = ["total" => $pagegen, "breakdown" => $pagequeries]; } if (isset($_GET["callback"])) { return $_GET["callback"] . '(' . json_encode($g_page["child"]) . ')'; } else { return json_encode($g_page["child"]); } } // format HTML results into the frame $scr = new Scriptor($g_page["frame"], $g_page); return $scr->result(); }