Source for file team-summary-lists.php

Documentation is available at team-summary-lists.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4. * Generate Team Summary Lists
  5. *
  6. * This is a command-line script for generating printed lists.
  7. * It expectes two commandline arguments
  8. * - a CompUnix name
  9. * - an email address to deliver the export to, NOT USED
  10. *
  11. * These lists show each team's entries in each events, with a rough
  12. * guess of the likely number of rounds, for tracking callbacks, or
  13. * videotaping, or placements, etc
  14. *
  15. * This file is part of CompInaBox.
  16. * @package CommandLine-Scripts
  17. * @author Eric D. Nielsen <nielsene@alum.mit.edu>
  18. * @copyright CompInaBox Copyright 2005, Eric D. Nielsen. All Rights Reserved.
  19. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  20. * @todo remove email address requirement
  21. */
  22. /**
  23. * Include path information
  24. */
  25. function latexHeader($title)
  26. {
  27. $header=<<<END_HEADER
  28. \\documentclass{report}
  29. \\usepackage{fullpage,graphics,array,color,colortbl,nopageno,longtable,pdflscape}
  30. \\definecolor{light}{gray}{.8}
  31. \\begin{document}
  32. \\begin{landscape}
  33. END_HEADER; return $header;
  34. }
  35.  
  36. function getEventData($eventid,$orgid)
  37. {
  38. GLOBAL $db;
  39. $eventData=array();
  40.  
  41. $result = $db->query("SELECT level, style FROM events NATURAL JOIN events_categories WHERE eventid=$eventid;");
  42. list($eventData["Level"],$eventData["Style"])=$result->getRowAt(0);
  43. $result = $db->query("SELECT COUNT(*) FROM events_registration WHERE eventid=$eventid;");
  44. list($eventData["NumCouples"])=$result->getRowAt(0);
  45.  
  46. $result = $db->query("
  47. SELECT COUNT(DISTINCT competitornumber)
  48. FROM events_registration NATURAL JOIN couples
  49. JOIN people AS l ON (leader=l.peopleid)
  50. JOIN people AS f ON (follower=f.peopleid)
  51. WHERE (l.organization=$orgid OR f.organization=$orgid)
  52. AND eventid=$eventid;");
  53. list( $eventData["NumOwnCouples"])=$result->getRowAt(0);
  54.  
  55.  
  56. $numCouples =$eventData["NumCouples"];
  57. if ($numCouples <9) $eventData["NumRounds"]=1;
  58. else if ($numCouples < 16 ) $eventData["NumRounds"]=2;
  59. else if ($numCouples < 27 ) $eventData["NumRounds"]=3;
  60. else if ($numCouples < 51 ) $eventData["NumRounds"]=4;
  61. else $eventData["NumRounds"]=5;
  62.  
  63. switch ($eventData["Level"])
  64. {
  65. case "Newcomer" :
  66. switch ($eventData["Style"])
  67. {
  68. case "Standard" : $eventData["Dances"]=array("W"); break;
  69. case "Latin" : $eventData["Dances"]=array("R"); break;
  70. case "Smooth" : $eventData["Dances"]=array("F"); break;
  71. case "Rhythm" : $eventData["Dances"]=array("S"); break;
  72. default: break;
  73. }
  74. break;
  75. case "Championship" :
  76. switch ($eventData["Style"])
  77. {
  78. case "Standard" : $eventData["Dances"]=array("W/T/V/F/Q"); break;
  79. case "Latin" : $eventData["Dances"]=array("C/S/R/P/J"); break;
  80. case "Smooth" : $eventData["Dances"]=array("W/T/F/V"); break;
  81. case "Rhythm" : $eventData["Dances"]=array("C/R/S/B/M"); break;
  82. default: break;
  83. }
  84. break;
  85. default:
  86. switch ($eventData["Style"])
  87. {
  88. case "Standard" : $eventData["Dances"]=array("W","T","V","F","Q"); break;
  89. case "Latin" : $eventData["Dances"]=array("C","S","R","P","J"); break;
  90. case "Smooth" : $eventData["Dances"]=array("W","T","F","V"); break;
  91. case "Rhythm" : $eventData["Dances"]=array("C","R","S","B","M"); break;
  92. default: break;
  93. }
  94. break;
  95. }
  96. return $eventData;
  97. }
  98.  
  99. function eventHeader($eventData)
  100. {
  101. $numRounds = $eventData["NumRounds"];
  102. $numDances = count($eventData["Dances"]);
  103. $numBlocks = $numRounds*$numDances;
  104. if ($numRounds==5)
  105. $numBlocks -= ($eventData["Style"]=="Smooth" ? 2 : 3);
  106.  
  107. $header = "\\begin{tabular}{l|";
  108. for ($i=0;$i<$numRounds;$i++)
  109. {
  110. $header .= "|";
  111. if ($numRounds==5 && $i==0)
  112. {
  113. $header.="l|l|";
  114. }
  115. else
  116. {
  117. for ($j=0;$j<$numDances;$j++)
  118. $header.="l|";
  119. }
  120. if ($i%2==1) $header .= "|l|";
  121. }
  122. $header .="}\n";
  123. $header2 = " ";
  124. $header3 = "\\textbf{Couple} ";
  125. for ($i=0;$i<$numRounds;$i++)
  126. {
  127. if ($numRounds==5 && $i==0)
  128. {
  129. $header2 .= "& \\multicolumn{2}{c}{Pre-Lim} ";
  130. switch ($eventData["Style"])
  131. {
  132. case "Standard" : $header3.= "&W & Q "; break;
  133. case "Latin" : $header3.= "&R & C "; break;
  134. case "Smooth" : $header3.= "&W & F "; break;
  135. case "Rhythm" : $header3.= "&R & S "; break;
  136. default: break;
  137. }
  138. }
  139. else
  140. {
  141. switch ($numRounds-$i)
  142. {
  143. case 1: $name="Final"; break;
  144. case 2: $name="Semi-Final"; break;
  145. case 3: $name="Quarter-Final"; break;
  146. case 4: $name="1/8-Final"; break;
  147. default:break;
  148. }
  149.  
  150. $header2.="&\\multicolumn{{$numDances}}{c}{{$name}} ";
  151. $header3 .= "&" . str_replace(",","&",
  152. arrayToCSL($eventData["Dances"]));
  153. }
  154. if ($i%2==1)
  155. {
  156. $header2 .= "&";
  157. $header3 .=" & Num ";
  158. }
  159. }
  160. $header2 .= "\\\\ \n";
  161. $header3 .= "\\\\ \n";
  162. $header .= $header2 . $header3 . "\\hline\n";
  163. return $header;
  164. }
  165. function eventRow($couple, $eventData)
  166. {
  167. $numRounds = $eventData["NumRounds"];
  168. $numDances = count($eventData["Dances"]);
  169. $numBlocks = $numRounds*$numDances;
  170. $number = substr($couple,0,3);
  171. if ($numRounds==5)
  172. $numBlocks -= ($eventData["Style"]=="Smooth" ? 2 : 3);
  173.  
  174. $row = "$couple ";
  175.  
  176.  
  177. for ($i=0;$i<$numRounds;$i++)
  178. {
  179. if ($numRounds==5 && $i==0)
  180. {
  181. $row.="& & ";
  182. }
  183. else
  184. {
  185. for ($j=0;$j<$numDances;$j++)
  186. $row.=" & ";
  187. }
  188. if ($i%2==1) $row .= "& $number ";
  189. }
  190. $row .= "\\\\ \\hline\n";
  191. return $row;
  192. }
  193. function eventFinals($eventData)
  194. {
  195. $numDances = count($eventData["Dances"]);
  196. $box = "\begin{tabular}{l||p{.75in}|p{.75in}|p{.75in}|p{.75in}|p{.75in}|p{.75in}|p{.75in}|p{.75in}|p{.75in}|}\n";;
  197. $box .= "Event & 9th & 8th & 7th & 6th & 5th & 4th & 3rd & 2nd & 1st \\\\\hline\n";
  198. for ($i=0;$i<$numDances;$i++)
  199. {
  200. $box .= $eventData["Dances"][$i]."& & & & & & & & & \\\\ \\hline\n";
  201. }
  202. $box .= "\\end{tabular}\n";
  203. return $box;
  204. }
  205.  
  206.  
  207.  
  208. include("paths.inc");
  209. if ($argv[1]=="") die("No Comp Name provided\n");
  210. if ($argv[2]=="") die("No email address provided for document delivery\n");
  211. $unixname=$argv[1];
  212. if (!ereg("^[-a-zA-Z0-9_]*$",$unixname)) die ("Badly formed compname\n");
  213. $mailto = $argv[2];
  214.  
  215. $CIB_TOOL_ROLE="register";
  216. include "$CIB_CONFIG_PATH/comps/{$unixname}_config.inc";
  217. if (!isset($SD_compname)) die ("Invalid Comp Name.");
  218.  
  219. include "$CIB_INCLUDE_PATH/tools/SlidingDoors_header.inc";
  220. ini_alter("include_path", "$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixna
  221. me/PREPARSED");
  222.  
  223.  
  224. $query = "SELECT distinct orgid,name FROM organizations JOIN people on (orgid=organization) join couples on (leader=peopleid);";
  225.  
  226. $result=$db->query($query);
  227. $numAffils = $result->numrows();
  228. for ($i=0;$i< $numAffils;$i++)
  229. {
  230.  
  231.  
  232.  
  233.  
  234. list($orgid,$orgname) = $result->getRowAt($i);
  235. $page=latexHeader("Team Record Sheets");
  236.  
  237. $page .= "\\begin{center}\n";
  238. $page .="\\LARGE Team Record Sheets\\\\ \\normalsize for\\\\ \\Huge $orgname\\\\
  239. \\normalsize
  240. \\end{center}\n";
  241. $page .= "These ``Team Record'' sheets are provided as an experimental
  242. CompInaBox service. They were designed for use by team historians, coaches,
  243. or videographers to quickly track all of their members in a given event at
  244. once. Annotate your team's callbacks, record taping times, track
  245. results, take notes on your couple's dancing, dar cartoon charicatures of the judges in the margins,
  246. or what ever else you come up with.
  247.  
  248. In the future these sheets may be availible ahead of time from the
  249. Studio/Team Options page of competitions using CompInaBox for their on-line registration needs. If you need more
  250. copies of these sheets at the competition, there is a photocopy shop in the
  251. student center -- ask the workers at the registration desk for directions.
  252.  
  253. You can email nielsene@mit.edu with suggestions for improvements to these
  254. sheets, or ideas for other helpful competition aides.
  255. \\newpage\n";
  256.  
  257. $query =<<<END_QUERY
  258. SELECT DISTINCT competitornumber, l.firstname,
  259. f.firstname, longname, eventid, programnumber
  260. FROM events_registration NATURAL JOIN couples
  261. JOIN people AS l ON (leader=l.peopleid)
  262. JOIN people AS f ON (follower=f.peopleid)
  263. NATURAL JOIN events_names
  264. NATURAL JOIN events
  265. WHERE l.organization=$orgid OR f.organization=$orgid
  266. ORDER BY programnumber, competitornumber;
  267. END_QUERY; $innerResult = $db->query($query);
  268. $curEvent=0;
  269. $couples =array();
  270. $numRows = $innerResult->numrows();
  271. for ($j=0;$j<$numRows;$j++)
  272. {
  273. list($compNum, $leader, $follower,
  274. $eventname, $eventid, $progNum) = $innerResult->getRowAt($j);
  275. if ($follower=="TBA")$follower="\\_\\_\\_\\_\\_\\_\\_\\_";
  276. if ($leader=="TBA")$leader="\\_\\_\\_\\_\\_\\_\\_\\_";
  277. if ($curEvent!=$eventid)
  278. {
  279. if ($curEvent!=0)
  280. {
  281. $page .= eventRow("",$eventData);
  282. $page .= eventRow("",$eventData);
  283. $page .= "\end{tabular}\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n";
  284. $page .= eventFinals($eventData);
  285. $page .= "\\newpage\n";
  286. }
  287. $eventData = getEventData($eventid,$orgid);
  288.  
  289.  
  290. $numRounds = $eventData["NumRounds"];
  291. $numCouples = $eventData["NumCouples"];
  292. $numOwnCouples = $eventData["NumOwnCouples"];
  293.  
  294. $page.="\\begin{center}\n\\large 2003 MIT Open Ballroom Dance Competition\n$orgname\\\\\nEvent Number $progNum -- $eventname ($numOwnCouples of $numCouples Couples)\n\end{center}\n\\normalsize\n";
  295. $page .= eventHeader($eventData);
  296. $curEvent=$eventid;
  297. $couples=array();
  298. }
  299. $couple = "$compNum $leader \\& $follower";
  300. $couples[]=$couple;
  301.  
  302. $page .= ($j%2==0? "\\rowcolor{light}":"").eventRow($couple,$eventData);
  303. }
  304. $page .= "\\end{tabular}\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n";
  305. $page .= eventFinals($eventData);
  306. $page .= "\\end{landscape}\n";
  307. $page .= "\\end{document}";
  308. $directory = "{$CIB_WEB_PATH}register/$unixname/group/Records/";
  309. chdir($directory);
  310. $filename=str_replace(" ","_",$orgname);
  311. $filename=ereg_replace("[^-A-Za-z0-9_]","",$filename);
  312. echo "$filename <br />\n";
  313. $fp = fopen("{$directory}{$filename}.tex","w");
  314. fwrite($fp,$page);
  315. fclose($fp);
  316. exec("pdflatex $filename.tex");
  317. unlink("$filename.tex");
  318. unlink("$filename.log");
  319. unlink("$filename.aux");
  320.  
  321. }
  322.  
  323.  
  324. echo "done";
  325. ?>

Documentation generated on Tue, 25 Apr 2006 13:11:37 -0400 by phpDocumentor 1.3.0RC3