function download_csv() { // Get Data $file = "Team ID,Team Name,School\n"; $result = DB::queryRaw('SELECT team_id, teams.name AS team_name, schools.name AS school_name FROM teams ' . 'LEFT JOIN schools ON teams.school=schools.school_id WHERE teams.deleted="0" ORDER BY team_id'); $row = mysqli_fetch_assoc($result); while ($row) { $id = htmlentities($row['team_id']); $team_name = htmlentities($row['team_name']); $school_name = htmlentities($row['school_name']); if ($school_name == '') { $school_name = 'None'; } $file .= $id . "," . $team_name . "," . $school_name . "\n"; $row = mysqli_fetch_assoc($result); } // Download File header('Content-Description: File Transfer'); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="Team List.csv"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . strlen($file)); cancel_templateify(); ob_clean(); flush(); echo $file; }
function error_catcher($errno, $errstr, $errfile, $errline) { error_log_print($errno, $errstr, $errfile, $errline); cancel_templateify(); die; //Either way, an error should not let it go on executing. //If you want to have errors within classes, implement a class error-catching system yourself and output it to the user that way. Preferably through alerts. }
function do_download() { $backup_name = 'LMT Backup ' . time() . '.sql'; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $backup_name . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); cancel_templateify(); ob_clean(); flush(); echo 'CREATE DATABASE `lmt-bak` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;' . "\n" . 'USE `lmt-bak`;' . "\n\n\n"; $tables = array(); $result = DB::queryRaw('SHOW TABLES'); while ($row = mysqli_fetch_row($result)) { $tables[] = $row[0]; } foreach ($tables as $table) { $result = DB::queryRaw('SELECT * FROM ' . $table); $num_fields = mysqli_field_count($result); echo 'DROP TABLE IF EXISTS ' . $table . ';'; $row2 = mysqli_fetch_row(DB::queryRaw('SHOW CREATE TABLE ' . $table)); echo "\n\n" . $row2[1] . ";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while ($row = mysqli_fetch_row($result)) { echo 'INSERT INTO ' . $table . ' VALUES('; for ($j = 0; $j < $num_fields; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { echo 'NULL'; } else { $row[$j] = addslashes($row[$j]); $row[$j] = preg_replace("\n", "\\n", $row[$j]); echo '"' . $row[$j] . '"'; } if ($j < $num_fields - 1) { echo ','; } } echo ");\n"; } } echo "\n\n\n"; } }
<?php /* * Admin/Event_Reminder.php * LHS Math Club Website * * A page to be run as a cron job which reminds captains of any events coming up. */ //Currently run every Sunday by https://members.nearlyfreespeech.net/lhsmath/sites/lhsmath/cron //Next steps: Add a field "remind_when" that indicates a time to remind at. Can specify multiple comma-separated, I suppose. //auto_remind will then hold the number of notifications that have so far been sent through this. require_once '../.lib/functions.php'; cancel_templateify(); $current_events = DB::query('SELECT * FROM events WHERE auto_remind = 0 AND %l', DBExt::timeInInterval('date', '', '+17d')); $count = count($current_events); if ($count == 0) { die; } $email_bb = ''; foreach ($current_events as $event) { $description = $event["description"]; if (empty(trim($description))) { $description = "[no description]"; } $email_bb .= "[subheading][i]{$event["title"]}[/i] on {$event["date"]}[/subheading]{$description}\n\n"; } $email_bb = <<<HEREDOC Hi captains! This is a reminder that [b]{$count}[/b] events are coming up within a couple of weeks: {$email_bb}
function show_page() { score_guts(); cancel_templateify(); header('X-LMT-Guts-Data: 42'); //:) ?> <meta http-equiv="refresh" content="7"> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <style type="text/css"> body{ font-family:"Georgia"; } .box{ vertical-align:top; border: solid 2px #000; border-radius: 10px; height: 50px; width: 270px; display: inline-block; margin: 5px; padding: 10px; text-align:left; display:none; } .box .place{ font-size: 1.4em; } .box .team{ font-weight: bold; font-size: 1.2em; } .box .school{ font-size: 0.8em; } .box .score{ float: right; font-size: 2.3em; position:relative; top:-30px; } .box .set{ } h1{ font-size: 3.2em; position:relative; top:-30px; margin-bottom: -10px; } h1 img{ position:relative; top:30px; } h1 #timer{ width: 400px; min-height: 1.2em; border: solid 1px #000; display: inline-block; } .suspense{ font-size: 3em; } </style> <script> console.log((new Date()).getTime()); function formatSeconds(secs){ var h = Math.floor(secs / (60*60)); var m = Math.floor((secs % 3600) / 60); var s = Math.floor(secs % 60); h=h.toString(); m=m.toString(); s=s.toString(); while(h.length < 2) h = "0"+h; while(m.length < 2) m = "0"+m; while(s.length < 2) s = "0"+s; return h+":"+m+":"+s; } var targetTime = 1460180400 + 90 * 60 + 12 * 60 * 60 + 10 * 60 + 60 + 60 + 2 * 60; function updateTime(){ var currTime = (new Date()).getTime()/1000; if(targetTime - currTime > 90*60){ timerOut(formatSeconds(targetTime-currTime-90*60)+" <small style='display:block;font-size:0.4em;'>before start</small>"); } if(targetTime - currTime <= 90*60){ timerOut(formatSeconds(targetTime-currTime)); } if(targetTime - currTime <= 0){ timerOut("END!"); } if(targetTime - currTime <=300){ $(".box").fadeOut(); $(".suspense").fadeIn(); } else{ $(".box").css("display","inline-block"); $(".suspense").hide(); } setTimeout(updateTime,300); } function timerOut(a){ document.getElementById("timer").innerHTML=a; } </script> <center> <h1> <img src="../../../../res/lmt/header.png" alt="LMT" width="525" height="110"> Guts Round <span id="timer">(timer here)</span> </h1> <div class="suspense"><br><br><br>Boxes hidden for awards ceremony suspense. ;)</div> <?php $result = DB::queryRaw('SELECT name, guts_ans_a, (SELECT name FROM schools WHERE schools.school_id=teams.school) AS school_name, ' . '(SELECT MAX(problem_set) FROM guts WHERE team=team_id) AS current_problem, score_guts FROM teams WHERE deleted="0" ORDER BY score_guts DESC'); $n = 1; $row = mysqli_fetch_assoc($result); while ($row) { $place = htmlentities($n++); $team = htmlentities($row['name']); $school = htmlentities($row['school_name']); if ($school == '') { $school = 'Individuals'; } $score = htmlentities($row['score_guts']); $curr = htmlentities($row['current_problem']); if ($curr == '') { $curr = '0'; } if (!is_null($row['guts_ans_a'])) { $curr = '12'; } ?> <div class="box"> <span class="place">[<?php echo $place; ?> ]</span> <span class="team"><?php echo $team; ?> </span> <span class="set">(<?php echo $curr; ?> /12)</span><br> <span class="school"><?php echo $school; ?> </span> <span class="score"><?php echo $score; ?> </span> </div> <?php $row = mysqli_fetch_assoc($result); } ?> <script> $(function(){ updateTime(); }); </script> <?php }
function location($path_from_root) { cancel_templateify(); //so it doesn't mess up alerts, etc. header('Location: ' . URL::root() . '/' . $path_from_root); die; }
function sendfile($downloadname, $content) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $downloadname . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . strlen($content)); cancel_templateify(); ob_clean(); echo $content; }
function do_download() { if (isset($_GET['Backup'])) { restrict_access('A'); $time = (int) $_GET['Backup']; $code = $_GET['Code']; if (!preg_match('#[a-z0-9]{4}#', $code)) { trigger_error('Invalid backup', E_USER_ERROR); } $name = 'db-backup-' . $time . '-' . $code . '.sql'; $file = './.content/backups/' . $name; } else { $query = 'SELECT filename, permissions FROM files WHERE file_id="' . mysqli_real_escape_string(DB::get(), $_GET['ID']) . '"'; $result = DB::queryRaw($query); if (mysqli_num_rows($result) != 1) { trigger_error('Incorrect number of categories match ID', E_USER_ERROR); } $row = mysqli_fetch_assoc($result); if ($row['permissions'] == 'P') { restrict_access('XLRA'); } else { if ($row['permissions'] == 'M') { restrict_access('LRA'); } else { // 'A' restrict_access('A'); } } if ($row['permissions'] == 'C' && !isset($_SESSION['is_captain'])) { page_header('Download'); echo <<<HEREDOC <h1>Access Blocked</h1> <div>The captains have requested that you not view this file.</div> HEREDOC; die; } $name = $row['filename']; $file = './.content/uploads/' . $name; } if (file_exists($file)) { $encoding = 'application/octet-stream'; if (preg_match('#\\.pdf$#', $name)) { $encoding = 'application/pdf'; } header('Content-Description: File Transfer'); header('Content-Type: ' . $encoding); header('Content-Disposition: inline; filename="' . $name . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); cancel_templateify(); ob_clean(); readfile($file); flush(); } else { trigger_error('File does not exist', E_USER_ERROR); } }