function main_switch() { $tabs = mailspy_main_tabs(); if ($_GET["main"] == "emails_received") { $tabs = null; } switch ($_GET["main"]) { case "mailspylogs": echo $tabs . mailspylogs(); exit; break; case "reports": echo $tabs . "<div id='allreports' style='width:700px'>" . reports() . "</div>"; exit; break; case "conf": echo main_conf(); exit; break; case "connections": default: echo $tabs . mailspylogs(); break; } }
function mustache($viewPath, $values = []) { global $controller; global $renderArgs; global $strings; $mustache = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'), 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/partials'), 'strict_callables' => true]); $tpl = $mustache->loadTemplate($viewPath); $values["controller:{$controller}?"] = true; $values["controller"] = $controller; foreach (["firstName", "lastName", "roles", "id", "email"] as $i) { if (isset($_SESSION[$i])) { $values["currentUser:{$i}"] = $_SESSION[$i]; } } if (isset($_SESSION["id"])) { $reports = reports("SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end", $_SESSION["id"], ":created_by", ":start", ":end"); foreach (["weekly", "monthly", "quarterly", "annually"] as $j) { $values["currentUser:{$j}"] = $reports[$j]; } $thisWeek = query("SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end", [":created_by" => $_SESSION["id"], ":start" => date("Y-m-d", strtotime("last Sunday")), ":end" => date("Y-m-d", strtotime("this Saturday"))])[0][0]; if ($thisWeek === null) { $thisWeek = 0; } $values["currentUser:thisWeek"] = $thisWeek; } # Roles identifier for template foreach (roles() as $role) { $values["currentUser:{$role}?"] = true; } foreach ($renderArgs as $key => $value) { if (isset($strings[$value])) { $value = $strings[$value]; } $values["args:{$key}"] = $value; } return $tpl->render($values); }
case 'actions': reports_form_actions(); break; case 'item_movedown': reports_item_movedown(); header('Location: reports_user.php?action=edit&tab=items&id=' . $_REQUEST['id']); break; case 'item_moveup': reports_item_moveup(); header('Location: reports_user.php?action=edit&tab=items&id=' . $_REQUEST['id']); break; case 'item_remove': reports_item_remove(); header('Location: reports_user.php?action=edit&tab=items&id=' . $_REQUEST['id']); break; case 'item_edit': general_header(); reports_item_edit(); bottom_footer(); break; case 'edit': general_header(); reports_edit(); bottom_footer(); break; default: general_header(); reports(); bottom_footer(); break; }
<?php if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; } $projects = query("SELECT * FROM projects WHERE status='active' ORDER BY name ASC"); foreach ($projects as $i => $project) { $id = $project["id"]; $reports = reports("SELECT SUM(hours) FROM logs WHERE project_id = :project_id AND date >= :start AND date <= :end", $id, ":project_id", ":start", ":end"); $projects[$i]["weekly"] = $reports["weekly"]; $projects[$i]["monthly"] = $reports["monthly"]; $projects[$i]["quarterly"] = $reports["quarterly"]; $projects[$i]["annually"] = $reports["annually"]; } render("projects", ["projects?" => true, "projects" => $projects, "title" => "Project management"]);
<?php if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; } $userCount = query("SELECT COUNT(id) FROM users WHERE status='active'")[0][0]; $users = query(" SELECT id, first_name, last_name, email, roles, created_by, updated_by, created_at, updated_at FROM users WHERE status='active' ORDER BY last_name ASC, id ASC"); $countHourQuery = "SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end"; foreach ($users as $i => $user) { $id = $user["id"]; $roles = []; $roleBits = array_reverse(str_split(decbin($user["roles"]))); foreach ($roleBits as $j => $roleBit) { if ($roleBit == "1") { array_push($roles, $j + 1); } } $users[$i]["roles"] = json_encode($roles); $reports = reports("SELECT SUM(hours) FROM logs WHERE created_by = :created_by AND date >= :start AND date <= :end", $id, ":created_by", ":start", ":end"); $users[$i]["weekly"] = $reports["weekly"]; $users[$i]["monthly"] = $reports["monthly"]; $users[$i]["quarterly"] = $reports["quarterly"]; $users[$i]["annually"] = $reports["annually"]; } if (count($users) > 0) { render("users", ["users?" => true, "roles" => listRoles(), "users" => $users, "title" => "User management"]); } else { render("users"); }