<label for="startdatepicker">Start date:</label> <input id="startdatepicker" type="text"> <input id="startdate" name="startdate" type="hidden" value="{$s_startdate}"> <label for="enddatepicker">End date:</label> <input id="enddatepicker" type="text"> <input id="enddate" name="enddate" type="hidden" value="{$s_enddate}"> <input name="submit" type="submit" value="Search"> </form> <table class="signin_stats"> END_DOC1; print " <tr><td>Number of signins:</td><td>{$num_signins}</td></tr>\n"; if ($userid === NULL) { $num_unique = count($user_dict); print " <tr><td>Unique customers:</td><td>{$num_unique}</td></tr>\n"; } print <<<END_DOC2 </table> <table class="searchresults"> <tr><th id="col_name">Name</th><th>Date</th></tr> END_DOC2; foreach ($all_signins as $row) { $name = combine_name($row['first_name'], $row['middle_name'], $row['last_name']); $date = new DateTime($row['signin_date']); $date = $date->format('Y-m-d h:i a T'); $cid = $row['cid']; print " <tr><td><a href=\"view.php?userid={$cid}\">{$name}</a></td><td>{$date}</td></tr>\n"; } print <<<END_DOC3 </table> END_DOC3; require 'foot.php';
try { $user = db_Customer::load($dbh, $userid); if ($user !== NULL) { $title = htmlspecialchars(combine_name($user->first_name, $user->middle_name, $user->last_name)); $user_data = $user->to_array(); } } catch (PDOException $e) { print "Database error: " . htmlspecialchars($e->getMessage()); die; } } $labelclass = "formlabel"; $s_title = "{$title} - {$s_organization}"; require 'head.php'; if ($user_data !== NULL) { $name = htmlspecialchars(combine_name($user->first_name, $user->middle_name, $user->last_name)); echo " <h1>{$name}</h1>"; echo " <table class=\"formtable\">"; foreach ($formfields as $fname => $field) { if (array_key_exists($fname, $user_data)) { $field->SetValue($user_data[$fname]); } if ($fname != 'first_name' && $fname != 'middle_name' && $fname != 'last_name') { $value = htmlspecialchars($field->GetReadableValue()); echo " <tr>\n"; echo " <td class=\"{$labelclass}\">" . $field->getLabelElement() . "</td>\n"; echo " <td class=\"formfield\">" . htmlspecialchars($value) . "</td>\n"; echo " </tr>\n"; } } $barcode = $user->barcode;
<?php require_once 'config.php'; require_once 'lib.php'; try { $dbh = new PDO($db_conn, $db_user, $db_pass, array(PDO::ATTR_PERSISTENT => TRUE, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (PDOException $e) { print "Error connecting to database: " . htmlspecialchars($e->getMessage()); die; } $sth = $dbh->query("SELECT c.id AS cid, c.first_name AS first_name, c.middle_name AS middle_name, " . "c.last_name AS last_name, s.signin_date AS signin_date, s.id AS sid, " . "c.dietary_needs AS dietary_needs, " . "c.num_adults AS num_adults, c.num_children AS num_children " . "FROM t_customers AS c INNER JOIN t_signins AS s ON s.customer = c.id " . "WHERE s.signin_date > (now() - interval 'PT4H') AND s.completed IS NULL " . "ORDER BY s.signin_date;"); $signins = array(); $idx = 0; while ($row = $sth->fetch()) { $signin_date = new DateTime($row['signin_date']); $signins[$idx++] = array('name' => combine_name($row['first_name'], $row['middle_name'], $row['last_name']), 'id' => $row['cid'], 'signin_id' => $row['sid'], 'time' => $signin_date->format('c'), 'dietary_needs' => $row['dietary_needs'], 'num_adults' => $row['num_adults'], 'num_children' => $row['num_children']); } header('Content-Type: application/json; charset=UTF-8'); header('Cache-Control: max-age=0, no-cache, no-store'); header('Expires: Sat, 01 Jan 2000 00:00:00 GMT'); print json_encode($signins, JSON_PRETTY_PRINT);
if (!preg_match('/^[0-9]+$/', $userid)) { print "Invalid userid"; } else { try { $name = $userid; $sth = $dbh->prepare('SELECT barcode,first_name,middle_name,last_name FROM t_customers WHERE id = :userid'); $sth->execute(array('userid' => $userid)); if ($row = $sth->fetch()) { # Insert the barcode the first time if ($row['barcode'] == '') { $sth = $dbh->prepare('UPDATE t_customers SET barcode = :barcode WHERE id = :userid'); $sth->execute(array('userid' => $userid, 'barcode' => $barcode)); } else { $barcode = $row['barcode']; } $name = htmlspecialchars(combine_name($row['first_name'], $row['middle_name'], $row['last_name'])); $now = new DateTime('now', $timezone); $date = $now->format('n/j/Y'); print " <div class=\"organization\">Sunshine Pantry</div>\n"; print " <div class=\"name\">{$name}</div>"; print " <div class=\"date\">{$date}</div>"; print " <div><img class=\"barcode\" src=\"barcode.php?render={$barcode}\" alt=\"{$barcode}\"></div>\n"; print " <div class=\"contact\">{$s_contact}</div>\n"; } else { print "User {$userid} not found.\n"; } } catch (PDOException $e) { print "Database error: " . htmlspecialchars($e->getMessage()); } } print <<<END_FOOT
} } catch (PDOException $e) { print "Database error: " . htmlspecialchars($e->getMessage()); die; } } try { if ($barcode == "") { $barcode = "__INVALID__"; } $sth = $dbh->prepare("SELECT c.id,c.first_name,c.middle_name,c.last_name,date_trunc('day',MAX(s.signin_date))=date_trunc('day',now()) FROM t_customers AS c LEFT OUTER JOIN t_signins AS s ON c.id = s.customer WHERE (concat_ws(' ', c.first_name, c.middle_name, c.last_name) ILIKE :search OR c.barcode = :barcode) GROUP BY c.id LIMIT 100;"); $sth->execute(array(':search' => "%{$search}%", ':barcode' => $barcode)); $count = 0; while ($row = $sth->fetch()) { $id = $row[0]; $name = htmlspecialchars(combine_name($row[1], $row[2], $row[3])); $signed_in = $row[4]; print " <tr><td>{$name}</td><td>"; print "<a href=\"view.php?userid={$id}\">View</a> "; print "<a href=\"edit.php?userid={$id}\">Edit</a> "; if ($signed_in) { print "Signed in"; } else { print "<a href=\"#\" onclick=\"signin({$id});\" id=\"signin_{$id}\" class=\"bold\">Sign In</a>"; } print "</td></tr>\n"; $count++; } if ($count == 0) { print " <tr><td>No results found</td><td></td></tr>\n"; }