Source for file compmngr_export_v2.php

Documentation is available at compmngr_export_v2.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4. * CompMngr Export Command-line Script
  5. *
  6. * This is a command-line script for exporting registrations to
  7. * CompMngr. This script requires three command-line arguments
  8. * - a CompUnix name
  9. * - a path to a "Export Setup Data" file from CompMngr
  10. * - an email address to mail the results to
  11. *
  12. * This is a rather fickle export process and typically will require
  13. * massaging.
  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. * @filesource
  21. * @todo Compare against {@link compmngr_export.php} and delete it not needed
  22. */
  23.  
  24. /**
  25. * Format a timestamp into the CompMngr required format
  26. * @param int $input a standard unix timestamp
  27. * @return string a text formatted time representation readable by CompMngr
  28. */
  29. function getFormattedTime($input)
  30. {
  31. return date("n.j.Y.H.i.s",$input);
  32. }
  33.  
  34. include("../include/paths.inc");
  35. echo "$CIB_CONFIG_PATH";
  36. if ($argv[1]=="") die("No Comp Name provided\n");
  37. if ($argv[2]=="") die("No Comp File provided\n");
  38. if ($argv[3]=="") die("No email address provided for document delivery\n");
  39. $unixname=$argv[1];
  40. if (!ereg("^[-a-zA-Z0-9_]*$",$unixname)) die ("Badly formed compname\n");
  41. $mailto = $argv[3];
  42.  
  43.  
  44. $CIB_TOOL_ROLE="register";
  45. ini_alter("include_path", "$CIB_CLASS_PATH:$CIB_PREFIX/include:$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixname/PREPARSED");
  46. include "$CIB_CONFIG_PATH/comps/{$unixname}_config.inc";
  47. if (!isset($SD_compname)) die ("Invalid Comp Name.");
  48.  
  49. include "$CIB_INCLUDE_PATH/tools/SlidingDoors_header.inc";
  50. ini_alter("include_path", "$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixname/PREPARSED");
  51.  
  52.  
  53.  
  54. // build up the event categories keys from the imported file
  55. $compmngr_lines = file($argv[2]);
  56. $danceCats=array();
  57. echo "<pre>";
  58. foreach ($compmngr_lines as $aLine)
  59. {
  60. $fields = explode('|',$aLine);
  61. if ($fields[0]!="DC") continue;
  62. $danceCat = $fields[3];
  63. $danceCatName = $fields[4];
  64. $numDances = $fields[5];
  65. $danceCodes=array();
  66. for ($i=0;$i<$numDances;$i++)
  67. {
  68. $danceCode=$fields[6+$i*2];
  69. $danceName=$fields[6+$i*2+1];
  70. $danceCodes[$danceName]=$danceCode;
  71. }
  72. $levelOffset=6+2*$numDances;
  73. $numLevels = $fields[$levelOffset];
  74. $levelCodes=array();
  75. for ($i=0;$i<$numLevels;$i++)
  76. {
  77. $levelCode=$fields[$levelOffset+1+$i*2];
  78. $levelName=$fields[$levelOffset+1+$i*2+1];
  79. $levelCodes[$levelName]=$levelCode;
  80. }
  81. $ageOffset=$levelOffset+1+2*$numLevels;
  82. $numAges = $fields[$ageOffset];
  83. $ageCodes=array();
  84. for ($i=0;$i<$numAges;$i++)
  85. {
  86. $ageCode=$fields[$ageOffset+1+$i*3];
  87. $ageName=$fields[$ageOffset+1+$i*3+1];
  88. $ageChunks = explode (" ",$ageName);
  89. $ageCodes[$ageChunks[0]]=$ageCode;
  90. }
  91. $danceCats[]=array("DanceCat"=>$danceCat,
  92. "DanceCatName"=>$danceCatName,
  93. "Dances"=>$danceCodes,
  94. "Levels"=>$levelCodes,
  95. "Ages"=>$ageCodes);
  96. }
  97. print_r($danceCats);
  98. $query="SELECT eventid, age, eventshortprefix, level, style FROM events NATURAL JOIN events_categories JOIN age_levels ON (age=levelname); ";
  99. $result=$db->query($query);
  100. $numEvents=$result->numrows();
  101. $eventLUT=array();
  102. for ($i=0;$i<$numEvents;$i++)
  103. {
  104. list($eventID, $age, $ageAbbrev, $level, $style) = $result->getRowAt($i);
  105. $query = "SELECT dancename, abbreviation FROM events_dances JOIN
  106. abbreviations ON (dancename=fulltext) WHERE eventid=$eventID ORDER BY danceorder;";
  107. $subResult = $db->query($query);
  108. $numDances=$subResult->numrows();
  109. $danceName=""; $danceAbbrev="(";
  110. for ($j=0; $j<$numDances; $j++)
  111. {
  112. if ($j!=0)
  113. {
  114. $danceName.="/ "; $danceAbbrev.='/';
  115. }
  116. list($aDance,$anAbbrev) = $subResult->getRowAt($j);
  117. $danceName.=$aDance;
  118. $danceAbbrev.=$anAbbrev;
  119. }
  120. // echo "Trying to match : $eventID -- $age $level $style $danceName\n";
  121.  
  122. $danceAbbrev.=")";
  123. $eventMatched=FALSE;
  124. foreach($danceCats as $aCat)
  125. {
  126. // echo "--{$aCat["DanceCatName"]}\n";
  127. $anAgeCode=""; $aDanceCode=""; $aLevelCode="";
  128. if ($aCat["Ages"][$ageAbbrev]!="")
  129. {
  130. $anAgeCode=$aCat["Ages"][$ageAbbrev];
  131. // echo "----Age matched\n";
  132. }
  133. // else "----Age not-matched\n";
  134. if ($aCat["Dances"][$danceName]!="")
  135. {
  136. $aDanceCode=$aCat["Dances"][$danceName];
  137. // echo "----Dance matched\n";
  138. }
  139. // else "----Dance not-matched\n";
  140. if ($aDanceCode=="" && $aCat["Dances"][$danceAbbrev]!="")
  141. {
  142. $aDanceCode=$aCat["Dances"][$danceAbbrev];
  143. // echo "----Dance matched\n";
  144. }
  145. // else if ($aDanceCode=="") echo "----Dance not-matched\n";
  146. if ($aCat["Levels"][$level]!="")
  147. {
  148. $aLevelCode=$aCat["Levels"][$level];
  149. // echo "----Level matched\n";
  150. }
  151. // else "----Level not-matched\n";
  152. $styleMatched=FALSE;
  153. if (preg_match("/$style/",$aCat["DanceCatName"]))
  154. {
  155. $styleMatched=TRUE;
  156. // echo "----Style matched\n";
  157. }
  158. // else echo "----Style not-matched\n";
  159. if ($styleMatched && $anAgeCode!="" &&
  160. $aDanceCode!="" && $aLevelCode!="")
  161. {
  162. $eventLUT[$eventID]=array("DanceCat"=>$aCat["DanceCat"],
  163. "DanceCode"=>$aDanceCode,
  164. "AgeCode"=>$anAgeCode,
  165. "LevelCode"=>$aLevelCode);
  166. $eventMatched=TRUE;
  167. break;
  168. }
  169. }
  170. if (!$eventMatched)
  171. {
  172. echo "NOT MATCHED -- $eventID -- $age $level $style $danceName\n";
  173. }
  174. else
  175. {
  176. echo "MATCHED -- $eventID\n";
  177. }
  178.  
  179. }
  180. echo "</pre>";
  181.  
  182. /*
  183. $query =<<<END_QUERY
  184. SELECT DISTINCT eventid,
  185. l.firstname, l.lastname, lo.name, ln.idnumber, lb.year,
  186. f.firstname, f.lastname, fo.name, fn.idnumber, fb.year,
  187. leader,follower,lo.orgid,fo.orgid
  188. FROM events_registration NATURAL JOIN
  189. couples JOIN
  190. people AS l ON (leader=l.peopleid) LEFT JOIN
  191. organizations AS lo ON (l.organization=lo.orgid) LEFT JOIN
  192. people_id_numbers AS ln ON (l.peopleid = ln.peopleid) LEFT JOIN
  193. people_birthdays AS lb ON (l.peopleid = lb.peopleid) JOIN
  194. people AS f ON (follower=f.peopleid) LEFT JOIN
  195. organizations AS fo ON (f.organization=fo.orgid) LEFT JOIN
  196. people_id_numbers AS fn ON (f.peopleid = fn.peopleid) LEFT JOIN
  197. people_birthdays AS fb ON (f.peopleid = fb.peopleid)
  198. ORDER BY eventid, l.lastname, l.firstname, f.lastname, f.firstname;
  199. END_QUERY;
  200.  
  201. $result=$db->query($query);
  202. $numrows=$result->numrows();
  203. $partSeperator=md5(uniqid(time()));
  204.  
  205. $body.=<<<END_BODY
  206. This is a MIME Encoded Email\n\n--$partSeperator
  207. Content-Type: text/plain; charset=us-ascii
  208. Content-Transfer-Encoding: 7bit
  209.  
  210. This email was sent via SlidingDoors, the on-line registration
  211. component of CompInaBox. Attached are raw text files containing the
  212. registration data, suitible for importing directly into COMPMNGR. Pipes
  213. ('|') are used to delimit the data.
  214.  
  215. Reply to this message to get in touch with the CompInaBox Server Administrator.
  216.  
  217. $CIB_SERVER_ADMIN_NAME
  218. $CIB_SERVER_HOST_NAME CompInaBox Server Administrator
  219.  
  220.  
  221. END_BODY;
  222.  
  223. $body.=<<<END_PART_HEADER
  224. --$partSeperator
  225. Content-Type: text/plain; charset=us-ascii; name="by-school.txt"
  226. Content-Transfer-Encoding: 7bit
  227.  
  228.  
  229. END_PART_HEADER;
  230. $file1="";
  231. $studioBase=mktime(0,0,0,1,0,2000);
  232. $entryBase=mktime(0,0,0,0,0,2000);
  233. $personBase=mktime(0,0,0,0,0,2001);
  234.  
  235.  
  236. for ($i=0;$i<$numrows;$i++)
  237. {
  238. list ($eventID, $lfname, $llname, $lorg, $lusabda, $lyear,
  239. $ffname, $flname, $forg, $fusabda, $fyear,
  240. $lid, $fid, $loid, $foid) = $result->getRowAt($i);
  241. $danceCategory = $eventLUT[$eventID]["danceCat"];
  242. $danceCode = $eventLUT[$eventID]["DanceCode"];
  243. $levelCode = $eventLUT[$eventID]["LevelCode"];
  244. $ageCode = $eventLUT[$eventID]["AgeCode"]
  245. $leTime = getFormattedTime($personBase+$lid);
  246. $foTime = getFormattedTime($personBase+$fid);
  247. $enTime = getFormattedTime($entryBase+$i);
  248. if ($lorg==$forg)
  249. {
  250. $studio=$lorg;
  251. $stTime = getFormattedTime($studioBase+$loid*3600+$loid);
  252. }
  253. else
  254. {
  255. $studio="$lorg/$forg";
  256. $stTime = getFormattedTime($studioBase + $loid*36000+$foid);
  257. }
  258. $file1.="EN|$danceCategory|$danceCode|$levelCode|$ageCode|||N||$userCode|$enTime|";
  259. $file1.="ST|$studio|||||||||||1|$userCode|$stTime|"; // studio
  260. $file1.="PR|M|A|$lfname|$llname||$lusabda||1|$userCode|$leTime|"; // leader
  261. $file1.="PR|F|A|$ffname|$flname||$fusabda||1|$userCode|$foTime|"; // follower
  262. $file1.="PR|||||||||||"; // coach
  263. $file1.="\n";
  264. }
  265. $body.="$file1\n";
  266.  
  267. $body.="\n--$partSeperator--\n";
  268. $headers="";
  269. $headers.=<<<END_HEADERS
  270. From: $CIB_SERVER_ADMIN_EMAIL\r
  271. X-mailer: CompInaBox (via PHP)\r
  272. MIME-Version: 1.0\r
  273. Content-Type: multipart/mixed;\r
  274. boundary="$partSeperator"
  275. END_HEADERS;
  276. mail("$mailto","[$unixname Competition] COMPMNGR Export",$body,$headers);
  277.  
  278. */
  279.  
  280.  
  281. ?>

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