function setvar(&$id, $tag, &$val) { if (getField("vars", "count(*)", "where uid={$id} and tag='{$tag}'") < 1) { dbExec("insert into vars (uid, tag, val) values({$id}, '{$tag}', 0)"); } dbExec("update vars set val={$val} where uid={$id} and tag='{$tag}'"); }
function group_name($gid) { if (!isset($group_name_cache[$gid])) { $rs = dbExec("select name from groups where id={$gid} limit 1"); $group_name_cache[$gid] = $rs->fields("name"); } return $group_name_cache[$gid]; }
function sql2csv($sql, $pretty_headers = true) { $csv = ""; $rs = dbExec($sql); $quote = array(); $r = ""; $fc = $rs->FieldCount(); for ($i = 0; $i < $fc; $i++) { if ($i != 0) { $r .= ","; } $fld = $rs->FetchField($i); $h = $fld->name; if ($pretty_headers) { $h = ucwords(str_replace('_', ' ', $fld->name)); } $h = addslashes($h); $r .= "\"" . $h . "\""; $type = $fld->type; if ($type == "int" || $type == "float") { $quote[$i] = ""; } else { $quote[$i] = "\""; } } $csv .= "{$r}\n"; while (!$rs->EOF) { $r = ""; for ($i = 0; $i < $fc; $i++) { if ($i != 0) { $r .= ","; } $r .= $quote[$i] . csvesc($rs->fields[$i]) . $quote[$i]; } $csv .= "{$r}\n"; $rs->MoveNext(); } return $csv; }
function insertRecord($table, $fields, $values) { $sql = "insert into {$table} ("; $numf = count($fields); $numv = count($values); for ($i = 0; $i < $numf; $i++) { if ($i != 0) { $sql .= ", "; } $sql .= $fields[$i]; } $sql .= ") values ("; for ($i = 0; $i < $numv; $i++) { if ($i != 0) { $sql .= ", "; } $sql .= $values[$i]; } $sql .= ")"; return dbExec($sql); }
$semester = $sy[0]; $md = $semester == 'Fall' ? '0701' : '0101'; $year = intval($sy[1] . $md); $currDate = intval(date('Ymd')); $cutoffDate = $currDate - 40000; if ($year >= $cutoffDate && $year < $currDate) { echo '<br>' . $year . ' >= ' . $cutoffDate . '<br>'; $statement .= 'update users set ineligible = "Won in ' . $semester . ' ' . $sy[1] . '" where user_type = "s" and ('; foreach ($v as $s) { $name = $s[0]; $city = $s[1]; $state = $s[2]; echo '<br>Won in ' . $k . ' => ' . $name . ', ' . $city . ', ' . $state . '<br>'; $codes = dbExec(' select distinct code from schools where name = "' . $name . '" and city = "' . $city . '" and state = "' . $state . '" '); while (!$codes->EOF) { $o = $codes->FetchNextObj(); $c = $o->code; echo ' ' . $c; $statement .= 'school_code = ' . $c . ' or '; } } $statement = substr($statement, 0, -4); $statement .= ');'; dbExec($statement); } }
<?php } else { $sql = "select code from schools where city=\"{$school_city}\" and state=\"{$school_state}\" and name=\"{$school_name}\""; $rs = dbExec($sql); if ($rs->RecordCount() > 1) { // xxx this is OK for now - there are multiple entries for many schools, but that's OK. //fail("unexpected record count: ".$rs->RecordCount()); } if ($rs->RecordCount() < 1) { assert(false); // shouldn't get here right now because all selections are drop-downs - user can't actually enter any data that doesn't already exist in db. // add school record and generate school code $school_code = gen_school_code(); $sql = "insert into schools (code, name,city,state,country) values ({$school_code}, \"{$school_name}\", \"{$school_city}\", \"{$school_state}\", \"USA\")"; $rs = dbExec($sql); dbg("New school added to db with code {$school_code}"); } else { $school_code = $rs->fields("code"); } $user_type = "t"; include "teachreg.php"; } } } } } else { if ($week > 0) { ?> Registration for the most recent challenge is now closed.
$td = dbExec("select * from users where user_type='t' and teacher_code={$tc}"); $tn = $td->fields("first_name") . ' ' . $td->fields("last_name"); $te = $td->fields("email"); $tp = $td->fields("phone"); $rst = dbExec("select * from users where group_id={$gid} and active = 1"); while (!$rst->EOF) { $studentArray[] = $rst->fields("first_name") . ' ' . $rst->fields("last_name"); if ($rst->fields("ineligible") != "") { $ineligible = $rst->fields("ineligible"); } $rst->MoveNext(); } $rst = dbExec("select school_code from users where active=1 and user_type='t' and teacher_code={$tc}"); $sc = $rst->fields("school_code"); if ($sc != "") { $rst = dbExec("select name,city,state from schools where code={$sc}"); $sn = $rst->fields("name"); $city = $rst->fields("city"); $state = $rst->fields("state"); $rank = $rs->CurrentRow() + 1; $tid = "tc"; if ($rank <= 20) { $tid = "top20"; } $rslt = ""; if ($ineligible == "") { $rslt = placeStr($winrank); if ($winrank <= 3) { $rslt .= ""; $tid = "gold"; ?>
<br> MAX task set to <?php echo $w; ?> <br> <br> <?php } else { if ($action == "setweekmin") { $w = (int) rt("w"); $sql = "update config set val={$w} where tag='weekmin'"; dbExec($sql); $sql = "update users set week={$w} where week < {$w}"; dbExec($sql); $sql = "update groups set week={$w} where week < {$w}"; dbExec($sql); getconfig(); ?> <br> MIN task set to <?php echo $w; ?> <br> <br> <?php } } } ?> </div>
$cr = $rs->CurrentRow() - 1; if (!isset($lastval) || $o->val != $lastval) { $below = $cr; $above = $rc - $below - 1; $bp = $below * 100 / $total; $ap = 100 - $above * 100 / $total; $p = ($bp + $ap) / 2; //$p = floor(($bp + $ap) / 2); $lastval = $o->val; $same = 0; //dbg("val=".$o->val." cr=$cr below=$below above=$above bp=$bp ap=$ap p=$p"); } else { $same++; //dbg("(val=".$o->val." cr=$cr below=$below above=$above bp=$bp ap=$ap p=$p)"); } //dbg($o->uid.": ".$o->val." - ".$p); dbExec("update results set p_uber={$p} where uid=" . $o->uid); //setvar($o->uid, 'UBER_pcntl', $p); if ($cr % $j == 0) { echo $cr . "—"; } ob_flush(); flush(); } p("Done"); b("updating final scores/ranking for students"); dbExec("update results set p_final=((p_raised+p_uber)/2) where p_final is NULL"); p("Done"); b("Marking Previous Winners"); include "previous_winners.php"; b("<br>SCORING COMPLETE");
function deleteRecord($id) { dbExec("DELETE FROM list WHERE id={$id}"); }
<tr> <td class=sutdh > Since </td> <td class=sutdh > Records </td> <td class=sutdh > Green </td> <td class=sutdh > Yellow </td> <td class=sutdh > Red </td> <td class=sutdh > Port 80 </td> <td class=sutdh > Port 443 </td> <td class=sutdh > Port 2714 </td> <td class=sutdh > Port 27140 </td> </tr> <?php //$dates = array("01/01", "09/19", "09/27"); $dates = array("2012-06-01"); foreach ($dates as $dt) { $rs = dbExec("select\n\t\t\t\t\tcount(*) as c,\n\t\t\t\t\tsum(port_80) as p80,\n\t\t\t\t\tsum(port_443) as p443,\n\t\t\t\t\tsum(port_2714) as p2714,\n\t\t\t\t\tsum(port_27140) as p27140,\n\t\t\t\t\tsum(green) as g,\n\t\t\t\t\tsum(yellow) as y,\n\t\t\t\t\tsum(red) as r\n\t\t\t\t\tfrom hwtest\n\t\t\t\t\twhere stamp >= '{$dt} 00:00:00'\n\t\t\t\t\t"); $o = $rs->FetchNextobj(); if ($o->c > 0) { $green = (int) ($o->g * 100 / $o->c); $yellow = (int) ($o->y * 100 / $o->c); $red = (int) ($o->r * 100 / $o->c); $p80 = (int) ($o->p80 * 100 / $o->c); $p443 = (int) ($o->p443 * 100 / $o->c); $p2714 = (int) ($o->p2714 * 100 / $o->c); $p27140 = (int) ($o->p27140 * 100 / $o->c); ?> <tr> <td class=sutd><?php echo $dt; ?> </td>
function getconfig() { global $config, $dbg; if (false) { $o = cacheGet("vtc.config"); if (!$o) { //dbg("fetching config ..."); $config = array(); $rs = dbExec("select * from config"); while ($o = $rs->FetchNextObj()) { $config[$o->tag] = $o->val; } cacheSet("vtc.config", $config, 10); } else { //dbg("returning cached config ..."); $config = array(); foreach ($o as $k => $v) { $config[$k] = $v; } } } else { $config = array(); $rs = dbExec("select * from config"); while ($o = $rs->FetchNextObj()) { $config[$o->tag] = $o->val; } } //dbg($config); }
function vrfy($sid, $jp = "", $xm = 30) { $rs = dbExec("select * from auth_users where sid=\"{$sid}\""); if ($rs->RecordCount() == 1) { dbg("sid freshened: {$sid}"); setcook("sid", $sid, $xm); // freshen sid return true; } dbg("*** bad sid: {$sid}"); if ($jp != "") { jmp($jp); } return false; }
$rc = $rs->RecordCount(); wl("Analyzing {$rc} user records ..."); $found = 0; $list = array(); while (!$rs->EOF) { $p = floor($rs->CurrentRow() * 100 / $rc); if ($rs->CurrentRow() % 100 == 0) { w("\n{$p}%: "); } $on = $rs->FetchNextObj(); //wl($num." [".$p."%]: ".$on->school_code.": ".$on->last_name.", ".$on->first_name); $rs2 = dbExec("\n\t\tselect\n\t\t\tid,\n\t\t\tfirst_name,\n\t\t\tlast_name,\n\t\t\tteacher_code,\n\t\t\tschool_code,\n\t\t\temail\n\t\tfrom\n\t\t\tusers\n\t\twhere\n\t\t\tschool_code = '" . $on->school_code . "'\n\t\t\tand\n\t\t\tflag3=0\n\t\t\tand\n\t\t\tflag2=1\n\t\t\tand\n\t\t\tlast_name like '%" . $on->last_name . "%'\n\t\t\tand\n\t\t\tfirst_name like '%" . $on->first_name . "%'\n\t"); if ($rs2->RecordCount() > 1) { $found++; array_push($list, $on); dbExec("update users set flag3=1 where id={$on->id}"); w("[" . $on->id . "]"); } else { //w("."); } } wl("\nfound {$found} possible dupes"); ?> <style> #x_table { border-collapse: collapse; } #x_head, #x_cell { padding: 2px 8px 2px 8px; border: solid 1px #aaa; }
<?php include 'model.php'; $name = 'image'; if (!empty($_FILES)) { if (isset($_FILES[$name])) { if (0 == $_FILES[$name]['error']) { $newFileName = $_FILES[$name]['name']; $newFilePath = __DIR__ . '/img/' . $_FILES[$name]['name']; move_uploaded_file($_FILES[$name]['tmp_name'], $newFilePath); $title = 'Test image'; dbExec("\n INSERT INTO `images`(`title`, `file`)\n VALUES ('{$title}', '{$newFileName}')\n "); } } } header('Location: /lesson8/index.php');
$sql = "select id,raisedmoney from groups where raisedmoney != 0 order by id"; $rs = dbExec($sql); echo $rs->RecordCount() . " groups with raisedmoney != 0<p><br/>"; while (!$rs->EOF) { $gid = $rs->fields("id"); /*$rs2 = dbExec("select count(id) from users where group_id=$gid and active=1 and user_type='s' and auth_count!=0 and teacher_code != 0"); $c = $rs2->fields[0]; */ $c = $t[$gid]; if ($c < 1 || $c > 4) { echo "<p><font color=red>ERROR: c == {$c}, gid={$gid}</font><p><br/>"; exit; } if ($c == 2 || $c == 3) { $before = $rs->fields("raisedmoney"); $avg = (int) ($before / $c); //$after = (int)($before + ($avg * (4 - $c))); $after = $before + $avg; echo $rs->CurrentRow() . ": GID-{$gid} students={$c} before={$before} avg={$avg} after={$after}<br/>"; dbExec("update groups set raisedmoney={$after} where id={$gid}"); } else { //dbg($rs->CurrentRow().": GID-$gid students=$c"); } flush(); $rs->MoveNext(); } ?> <br> <br> <br>
<?php include "db.php"; $lmk = trim($_REQUEST["letmeknow"]); dbExec("insert\n\t\tinto prospects\n\t\t\t(created,email) \n\t\t\tvalues \n\t\t\t(now(),'{$lmk}')\n\t\t\t");
function school_code_given_teacher_code($teacher_code) { global $db; $sql = "select * from users where user_type='t' and teacher_code='{$teacher_code}'"; $rs = dbExec($sql); if ($rs->RecordCount() != 1) { fail("Unexpected # of records: " . $rs->RecordCount() . " for teacher with code " . $teacher_code); } $sc = $rs->fields("school_code"); dbg("school_code returning {$sc}"); return $sc; }
$ref = array(); foreach ($students as $s) { $c = $s->school_code; if (!$ref[$c]) { $ref[$c] = true; $o = getrecobj("schools", "where code = {$c}"); $schools[$o->name] = $o; } } $teachers = array(); $ref = array(); foreach ($students as $s) { $c = $s->teacher_code; if (!$ref[$c]) { $ref[$c] = true; $rs = dbExec("select\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tlast_name,\n\t\t\t\t\t\t\tfirst_name,\n\t\t\t\t\t\t\tconcat(last_name,', ',first_name) as name,\n\t\t\t\t\t\t\tusername,\n\t\t\t\t\t\t\tschool_code,\n\t\t\t\t\t\t\tteacher_code,\n\t\t\t\t\t\t\tusername,\n\t\t\t\t\t\t\tpassword,\n\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t\tphone\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\tusers\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`active` = 1\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t`user_type` = 't'\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\tteacher_code = {$c}\n\t\t\t\t\t\torder by\n\t\t\t\t\t\t\tlast_name\n\t\t\t\t\t\t\t"); $o = $rs->FetchNextObj(); $teachers[$o->name] = $o; } } ?> <style> .school { font-weight: bold; } .teacher { color: maroon; font-size: 90%; margin-left: 2em; } .student {
<?php $studs = array(); $sql = "select * from users where active=1 and user_type='s' and teacher_code={$teacher_code} and group_id != 0 order by last_name"; $rs_studs = dbExec($sql); while (!$rs_studs->EOF) { $o = $rs_studs->FetchNextObj(); $o->eid = "stud" . $o->id; $o->role = roleName($o->class); $o->name = $o->last_name . ", " . $o->first_name; $o->tracking = getrecobj("tracking", "where user_id=" . $o->id); $studs[$o->id] = $o; } $teams = array(); $sql = "select * from groups where teacher_code={$teacher_code} order by name"; $rs_teams = dbExec($sql); while (!$rs_teams->EOF) { $o = $rs_teams->FetchNextObj(); $o->eid = "team" . $o->id; $o->studs = array(); $teams[$o->id] = $o; } foreach ($studs as $o) { $t = $teams[$o->group_id]; $o->team = $t; array_push($t->studs, $o); } ?> <style> #x_table, #s_table { border-collapse: collapse;
$os = snip("/os ([^\n]+)/i", $rep); $cpu_reg = snip("|cycles/sec \\(([^\n]+)\\)|i", $rep); $cpu_bogo = snip("|cpuspeed CPU (\\d+)|i", $rep); $dx_version = snip("|DirectX version ([^\n]+)|i", $rep); $mem_sys = snip("|System RAM (\\d+) MB|i", $rep); $mem_free = snip("|freemem (\\d+)MB|i", $rep); $mem_load = snip("|memload (\\d+)%|i", $rep); $ip_internal = snip("|localip ([.\\d]+)|i", $rep); $ip_external = snip("|external ip ([.\\d]+)|i", $rep); $port_80 = snip("|httpout ([^\n]+)|i", $rep) == "yes" ? 1 : 0; $port_443 = snip("|httpout443 ([^\n]+)|i", $rep) == "yes" ? "1" : "0"; $port_2714 = snip("|loportout ([^\n]+)|i", $rep) == "yes" ? "1" : "0"; $port_27140 = snip("|hiportout ([^\n]+)|i", $rep) == "yes" ? "1" : "0"; $dl_speed = snip("|Download speed (\\d+)|i", $rep); $green = $final == "G" ? 1 : 0; $yellow = $final == "Y" ? 1 : 0; $red = $final == "R" ? 1 : 0; dbExec("insert into hwtest (\n\t\t\t\tfinal,\n\t\t\t\thostname,\n\t\t\t\tusername,\n\t\t\t\tos,\n\t\t\t\tcpu_reg,\n\t\t\t\tcpu_bogo,\n\t\t\t\tdx_version,\n\t\t\t\tmem_sys,\n\t\t\t\tmem_free,\n\t\t\t\tmem_load,\n\t\t\t\tip_internal,\n\t\t\t\tip_external,\n\t\t\t\tport_80,\n\t\t\t\tport_443,\n\t\t\t\tport_2714,\n\t\t\t\tport_27140,\n\t\t\t\tdl_speed,\n\t\t\t\tgreen,\n\t\t\t\tyellow,\n\t\t\t\tred\n\t\t\t) values (\n\t\t\t\t'{$final}',\n\t\t\t\t'{$hostname}',\n\t\t\t\t'{$username}',\n\t\t\t\t'{$os}',\n\t\t\t\t{$cpu_reg},\n\t\t\t\t{$cpu_bogo},\n\t\t\t\t{$dx_version},\n\t\t\t\t{$mem_sys},\n\t\t\t\t{$mem_free},\n\t\t\t\t{$mem_load},\n\t\t\t\t'{$ip_internal}',\n\t\t\t\t'{$ip_external}',\n\t\t\t\t{$port_80},\n\t\t\t\t{$port_443},\n\t\t\t\t{$port_2714},\n\t\t\t\t{$port_27140},\n\t\t\t\t{$dl_speed},\n\t\t\t\t{$green},\n\t\t\t\t{$yellow},\n\t\t\t\t{$red}\n\t\t\t)"); $host = $_SERVER['SERVER_NAME']; $from = "*****@*****.**"; $to = "*****@*****.**"; $cc = "jh@sleepless.com, pete@semilogic.com"; $subj = "HW TEST RESULTS ({$final})"; $hdrs = ""; $msg = ""; $msg .= "\r\n"; $msg .= "\r\n"; $msg .= $rep; $msg .= "\r\n"; $msg .= "\r\n"; send_mail($to, $from, "", $subj, $msg, $cc);
foreach ($u->tracking as $k => $v) { $txt .= "{$k} = {$v}\n"; } $t->set("<pre>{$txt}</pre>", "left"); $txt = ""; foreach ($u->progress as $k => $v) { $txt .= "{$k} = {$v}\n"; } $t->set("<pre>{$txt}</pre>", "left"); $t->nextrow(); $t->dump(); } exit; } if ($userqry) { $rs = dbExec("select\n\t\t\t\t\t\t\tu.id,\n\t\t\t\t\t\t\tu.user_type,\n\t\t\t\t\t\t\tu.username,\n\t\t\t\t\t\t\tu.password,\n\t\t\t\t\t\t\tu.first_name,\n\t\t\t\t\t\t\tu.last_name,\n\t\t\t\t\t\t\tu.email,\n\t\t\t\t\t\t\tt.name as grp,\n\t\t\t\t\t\t\tu.group_id gid,\n\t\t\t\t\t\t\tu.status,\n\t\t\t\t\t\t\tu.task_progress,\n\t\t\t\t\t\t\tu.active\n\t\t\t\t\t\tfrom users as u\n\t\t\t\t\t\tleft outer join groups as t on \n\t\t\t\t\t\t\tt.id = u.group_id\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\tu.active = 1\n\t\t\t\t\t\t\tand\n\t\t\t\t\t\t\tconcat_ws(\n\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\tu.first_name,\n\t\t\t\t\t\t\t\tu.last_name,\n\t\t\t\t\t\t\t\tu.username,\n\t\t\t\t\t\t\t\tu.email,\n\t\t\t\t\t\t\t\tt.name\n\t\t\t\t\t\t\t\t) like '%{$userqry}%'\n\t\t\t"); $t = new Table("s"); if ($rs->RecordCount() > 0) { //$t->set("ID"); //$t->set("Active"); //$t->set("Type"); $t->set("First"); $t->set("Last"); $t->set("User"); $t->set("Pass"); $t->set("EMail"); $t->set("Team / Status"); //$t->set("Team ID"); $t->nextrow(); while (!$rs->EOF) { $o = $rs->FetchNextobj();
<td><center><b>Email Alt:</b></center></td> <td><center><b>Student Count:</b></center></td> </tr> <?php $rs = dbExec("select distinct teacher_code from users where active=1 and auth_count>0 and gamedata!=''"); while (!$rs->EOF) { $tc = $rs->fields("teacher_code"); $r = dbExec("select * from users where active=1 and teacher_code={$tc} and id>99 and user_type='t'"); $rst = dbExec("select count( id ) from users where active=1 and user_type='s' and teacher_code={$tc} and gamedata!=''"); $sc = intval($rst->fields("count( id )")); if ($sc > 0) { $rslt = dbExec("select count( user_id ) from users left outer join tracking on user_id = users.id where active=1 and auth_count>0 and gamedata!='' and teacher_code={$tc} and (w1cost>0 and w1vendor!='') and (w2cost>0 and w2vendor!='') and (w3vendor!='')"); $fc = intval($rslt->fields("count( user_id )")); $ratio = 0.5; $bar = round($sc * $ratio); if ($fc >= $bar) { $tn = $r->fields("first_name") . " " . $r->fields("last_name"); $tp = $r->fields("phone"); $te = $r->fields("email"); $te2 = $r->fields("email2"); $sc = $r->fields("school_code"); $result = dbExec("select * from schools where code={$sc}"); $sn = $result->fields("name") . "<br>" . $result->fields("address") . "<br>" . $result->fields("city") . ", " . $result->fields("state") . " " . $result->fields("zip"); echo "<tr>" . "<td><center>" . $tc . "</center></td>" . "<td>" . $tn . "</td>" . "<td>" . $sn . "</td>" . "<td>" . $tp . "</td>" . "<td>" . $te . "</td>" . "<td>" . $te2 . "</td>" . "<td><center>" . $fc . " / " . $sc . "</center></td>" . "</tr>"; } } $rs->MoveNext(); } ?> </table>
function gettrk($id) { $rs = dbExec("select * from tracking where user_id={$id}"); return $rs->FetchNextObj(); }
<td>Students Completed Task1 & Task2:</td> <td>Students Completed Task1, Task2 & Task3:</td> <td>Students Completed Only Task2:</td> <td>Students Completed Only Task3:</td> <td>Students Completed Task2 & Task3:</td> <td>Students Completed Task1 & Task3:</td> <tr> <?php $completed_none = dbExec("select Count( user_id ) from users left outer join tracking on user_id = users.id where active = 1 and gamedata != '' and ( (w1cost=0 and w1vendor!='') or (w1cost=0 and w1vendor='') ) and ( ( w2cost=0 and w2vendor!='') or ( w2cost=0 and w2vendor='') ) and (w3vendor='')")->fields("Count( user_id )"); $completed_t1 = dbExec('select Count( user_id ) from users left outer join tracking on user_id = users.id where active = 1 and gamedata != "" and (w1cost>0 and w1vendor!="") and ( (w2cost=0 and w2vendor="") or (w2cost=0 and w2vendor!="") ) and (w3vendor="")')->fields("Count( user_id )"); $completed_t1_t2 = dbExec('select Count( user_id ) from users left outer join tracking on user_id = users.id where active = 1 and gamedata != "" and (w1cost>0 and w1vendor!="") and (w2cost>0 and w2vendor!="") and (w3vendor="")')->fields("Count( user_id )"); $completed_t1_t2_t3 = dbExec('select Count( user_id ) from users left outer join tracking on user_id = users.id where active = 1 and gamedata != "" and (w1cost>0 and w1vendor!="") and (w2cost>0 and w2vendor!="") and (w3vendor!="")')->fields("Count( user_id )"); $completed_t2 = dbExec('select Count( users.id ) from users left outer join tracking on user_id = users.id where active=1 and timeplayed>0 and user_type="s" and gamedata != "" and (w1cost=0 and w2cost>0 and w3vendor="")')->fields("Count( users.id )"); $completed_t3 = dbExec('select Count( users.id ) from users left outer join tracking on user_id = users.id where active=1 and timeplayed>0 and user_type="s" and gamedata != "" and (w1cost=0 and w2cost=0 and w3vendor!="")')->fields("Count( users.id )"); $completed_t2_t3 = dbExec('select Count( users.id ) from users left outer join tracking on user_id = users.id where active=1 and timeplayed>0 and user_type="s" and gamedata != "" and (w1cost=0 and w2cost>0 and w3vendor!="")')->fields("Count( users.id )"); $completed_t1_t3 = dbExec('select Count( users.id ) from users left outer join tracking on user_id = users.id where active=1 and timeplayed>0 and user_type="s" and gamedata != "" and (w1cost>0 and w2cost=0 and w3vendor!="")')->fields("Count( users.id )"); ?> <tr> <td><?php echo $completed_none; ?> </td> <td><?php echo $completed_t1; ?> </td> <td><?php echo $completed_t1_t2; ?> </td> <td><?php
function exp_query($sql) { $rs = dbExec($sql); header('Content-Type: text/csv'); header("Content-Disposition: attachment; filename=\"export.csv\""); // Dump column names $fc = $rs->FieldCount(); for ($i = 0; $i < $fc; $i++) { $f = $rs->FetchField($i); $fn = $f->name; if ($i != 0) { print ","; } print csv_encoded($fn); } print "\n"; // Dump data $rc = $rs->RecordCount(); while (!$rs->EOF) { for ($i = 0; $i < $fc; $i++) { $v = $rs->Fields($i); if ($i != 0) { print ","; } print csv_encoded($v); } print "\n"; $rs->MoveNext(); } }
function raisedbyteam($gid) { //dbg("group: $gid"); $raised = 0; $sql = "select id, last_name from users where active=1 and group_id={$gid} and user_type='s'"; $rs = dbExec($sql); $rc = $rs->RecordCount(); if ($rc >= 1) { //dbg("rc=$rc"); assert($rc <= 4); $add = 0; $avg = 0; $raised = 0; $addedComp = false; for ($i = 0; $i < 4; $i++) { if ($i < $rc) { $stud = $rs->FetchNextObj(); $name = $stud->last_name; $tvc = 0; $rm = raisedbystudent($stud->id, $tvc); $raised += $rm; $add += $rm; $avg = $add / ($i + 1); //dbg("id=".$stud->id." name=$name raised=$rm tot=$raised add=$add avg=$avg"); } else { if ($addedComp == false) { $raised += $avg; //dbg("(no one) tot=$raised ($raised + $avg)"); $addedComp = true; } } } $raised = round($raised); //dbg("final tot=$raised"); } dbExec("update groups set raisedmoney={$raised} where id=" . $gid); return $raised; }
if ($flag) { w("{$m}"); } if ($flag) { dbExec("update users set flag=flag+1 where id={$id}\n"); $num++; } if ($fixed) { dbExec("update users set fixed=1 where id={$id}\n"); } // if($rs->CurrentRow() >= 500) break; } w("User recs with potentially wrong data: {$num}\n"); w("User recs that were fixed/modified: {$num_fixed}\n"); w("\n"); $rs = dbExec("select\n\t\t\t\tu.id,\n\t\t\t\tu.class as cls,\n\t\t\t\tu.first_name as fn,\n\t\t\t\tu.last_name as ln,\n\t\t\t\tu.gamedata,\n\t\t\t\tt.w1vendor as w1v,\n\t\t\t\tt.w2vendor as w2v,\n\t\t\t\tt.w3vendor as w3v,\n\t\t\t\tt.w1cost as w1c,\n\t\t\t\tt.w2cost as w2c,\n\t\t\t\tt.w3cost as w3c\n\t\t\tfrom\n\t\t\t\tusers as u\n\t\t\tleft outer join tracking as t on\n\t\t\t\tu.id = t.user_id\n\t\t\twhere\n\t\t\t\tu.flag=1\n\t\t\t\t"); $rc = $rs->RecordCount(); w("Flagged user records: {$rc}\n"); w("\n"); /* while(!$rs->EOF) { $o = $rs->FetchNextObj(); $id = $o->id; $gd = gdDecodeAssoc($o->gamedata); //print_r($gd); break; w($o->fn." ".$o->ln." [ id=$o->id cls=$o->cls ]:\n"); $flag = 0;
if ($t == "tracking") { // only these fields are strings $qv = $v; switch ($c) { case "w1vendor": case "w2vendor": case "w3vendor": case "w4vendor": $qv = $db->qstr($v); } } if ($t == "progress") { // all fields are strings $qv = $db->qstr($v); } } if (!isset($qv)) { // fallback to old behavior ... hopefully never $mc = $db->MetaColumns($t); $fld = $mc[strtoupper($c)]; $type = $fld->type; $qv = $v; if ($type == "char" || $type == "varchar" || $type == "text") { $qv = $db->qstr($v); } } $sql = "update {$t} set {$c} = {$qv} where user_id = {$uid}"; //dbgt($sql); $rs = dbExec($db, $sql); echo "0 OK\n"; exit;
e("Schools in NYC area (zip prefixes 112,104,100,101,102,110,111,113,114,116,103): " . $rs->RecordCount()); e(""); while (!$rs->EOF) { $school = $rs->FetchNextObj(); $sql = "select * from users\n\t\t\t\twhere active=1 and user_type='t' and school_code=" . $school->code; $rs2 = dbExec($sql); if ($rs2->RecordCount() > 0) { e(""); e("<b>" . $rs->CurrentRow() . ": [" . $school->code . "] " . $school->name . ", " . $school->city . ", " . $school->state . ", " . $school->zip . "</b>"); } while (!$rs2->EOF) { $teach++; $teacher = $rs2->FetchNextObj(); e("<u>- - - - Teacher " . $teach . ": " . $teacher->last_name . "</u>"); $sql = "select * from users where active=1 and user_type='s' and teacher_code=" . $teacher->teacher_code; $rs3 = dbExec($sql); while (!$rs3->EOF) { $stud++; $student = $rs3->FetchNextObj(); e("- - - - - - - - Student " . $stud . ": " . $student->last_name . ", " . $student->first_name); if ($s->auth_count > 0) { $stud_auth++; } } ob_flush(); flush(); } } e("------------------------------------------------------"); e("NYC area Student count: " . $stud); e("NYC area Students who've logged in: " . $stud_auth);