Source for file chester_export.php

Documentation is available at chester_export.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4. * Chester Export Command-line Script
  5. *
  6. * This is a command-line script for exporting registrations to
  7. * Chester. This script requires three command-line arguments
  8. * - a CompUnix name
  9. * - a path to a simple CIB->Chester label file
  10. * - an email address to mail the results to
  11. *
  12. * This file is part of CompInaBox.
  13. * @package CommandLine-Scripts
  14. * @author Eric D. Nielsen <nielsene@alum.mit.edu>
  15. * @copyright CompInaBox Copyright 2005, Eric D. Nielsen. All Rights Reserved.
  16. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  17. * @filesource
  18. */
  19. /**
  20. * Include path information.
  21. */
  22. include("paths.inc");
  23. if ($argv[1]=="") die("No Comp Name provided\n");
  24. if ($argv[2]=="") die("No Comp File provided\n");
  25. if ($argv[3]=="") die("No email address provided for document delivery\n");
  26. $unixname=$argv[1];
  27. if (!ereg("^[-a-zA-Z0-9_]*$",$unixname)) die ("Badly formed compname\n");
  28. $mailto = $argv[3];
  29.  
  30.  
  31. $CIB_TOOL_ROLE="register";
  32. include "$CIB_CONFIG_PATH/comps/{$unixname}_config.inc";
  33. if (!isset($SD_compname)) die ("Invalid Comp Name.");
  34.  
  35. include "$CIB_INCLUDE_PATH/tools/SlidingDoors_header.inc";
  36. ini_alter("include_path", "$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixname/PREPARSED");
  37.  
  38. $partSeperator=md5(uniqid(time()));
  39.  
  40. $body.=<<<END_BODY
  41. This is a MIME Encoded Email\n\n--$partSeperator
  42. Content-Type: text/plain; charset=us-ascii
  43. Content-Transfer-Encoding: 7bit
  44.  
  45. This email was sent via SlidingDoors, the on-line registration
  46. component of CompInaBox. Attached are raw text files containing the
  47. registration data, suitible for importing directly into the Chester
  48. scrutineering program.
  49.  
  50. Reply to this message to get in touch with the CompInaBox Server Administrator.
  51.  
  52. $CIB_SERVER_ADMIN_NAME
  53. $CIB_SERVER_HOST_NAME CompInaBox Server Administrator
  54.  
  55.  
  56. END_BODY;
  57. $body.=<<<END_PART_HEADER
  58. --$partSeperator
  59. Content-Type: text/plain; charset=us-ascii; name="by-school.txt"
  60. Content-Transfer-Encoding: 7bit
  61.  
  62.  
  63. END_PART_HEADER;
  64.  
  65. $query =<<<END_QUERY
  66. SELECT COUNT(*) FROM judges_info;
  67. END_QUERY;
  68. $result=$db->query($query);
  69. list($numJudges)=$result->getRowAt(0);
  70. $file = "Adjudicators\t$numJudges\tEvery export will reassign numbers to judges\n";
  71. $query =<<<END_QUERY
  72. SELECT judgeid,lastname,firstname
  73. FROM judges_info JOIN people ON (peopleid=judgeid)
  74. ORDER BY lastname, firstname;
  75. END_QUERY;$result=$db->query($query);
  76. for ($i=0;$i < $numJudges;$i++)
  77. {
  78. list($id,$lastname,$firstname) = $result->getRowAt($i);
  79. $subQuery ="UPDATE judges_info SET abbrev='$i' WHERE judgeid=$id;";
  80. $db->query($subQuery);
  81. $file.="$i\t$firstname $lastname\n";
  82. }
  83.  
  84. $query =<<<END_QUERY
  85. SELECT eventid, programnumber, class, level,
  86. style, age, type
  87. FROM events NATURAL JOIN
  88. events_categories
  89. ORDER BY programnumber;
  90. END_QUERY;$result = $db->query($query);
  91. $numEvents=$result->numrows();
  92. $file.="\nEvents\t$numEvents\n";
  93.  
  94. for ($i=0;$i < $numEvents;$i++)
  95. {
  96. list ($eventID, $eventNumber, $class, $level,
  97. $style, $age, $type) = $result->getRowAt($i);
  98. // HACKED
  99. include ($argv[2]); // very insecure
  100. $file .="\nEvent $eventNumber $eventCat $eventLevel $eventStyle ";
  101. $query = "SELECT dancename FROM events_dances WHERE eventid=$eventID ORDER BY danceorder;";
  102. $danceResult = $db->query($query);
  103. $numDances = $danceResult->numrows();
  104. $file .="$numDances ";
  105. $query = "SELECT competitornumber FROM events_registration WHERE eventid=$eventID ORDER BY competitornumber;";
  106. $entrantsResult = $db->query($query);
  107. $numEntrants = $entrantsResult->numrows();
  108. $file .= "$numEntrants\tDB EventID:$eventID\n";
  109. for ($j=0;$j<$numDances;$j++)
  110. {
  111. list($dance) = $danceResult->getRowAt($j);
  112. $file .= "$dance\n";
  113. }
  114. for ($j=0;$j<$numEntrants;$j++)
  115. {
  116. if ($j!=0 && ($j%10)==0)
  117. $file .= "\n";
  118. else if ($j!=0) $file .=" ";
  119. list($number) = $entrantsResult->getRowAt($j);
  120. $file .= $number;
  121. }
  122. $file .= "\n";
  123. }
  124. $body.="$file\n";
  125.  
  126. $body.="\n--$partSeperator--\n";
  127. $headers="";
  128. $headers.=<<<END_HEADERS
  129. From: $CIB_SERVER_ADMIN_EMAIL\r
  130. X-mailer: CompInaBox (via PHP)\r
  131. MIME-Version: 1.0\r
  132. Content-Type: multipart/mixed;\r
  133. boundary="$partSeperator"
  134. END_HEADERS;mail("$mailto","[$unixname Competition] Chester Export",$body,$headers);
  135.  
  136.  
  137.  
  138.  
  139. ?>

Documentation generated on Tue, 25 Apr 2006 12:59:08 -0400 by phpDocumentor 1.3.0RC3