Documentation is available at compmngr_export_v2.php
- #!/usr/local/bin/php
- <?php
- /**
- * CompMngr Export Command-line Script
- *
- * This is a command-line script for exporting registrations to
- * CompMngr. This script requires three command-line arguments
- * - a CompUnix name
- * - a path to a "Export Setup Data" file from CompMngr
- * - an email address to mail the results to
- *
- * This is a rather fickle export process and typically will require
- * massaging.
- *
- * This file is part of CompInaBox.
- * @package CommandLine-Scripts
- * @author Eric D. Nielsen <nielsene@alum.mit.edu>
- * @copyright CompInaBox Copyright 2005, Eric D. Nielsen. All Rights Reserved.
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @filesource
- * @todo Compare against {@link compmngr_export.php} and delete it not needed
- */
- /**
- * Format a timestamp into the CompMngr required format
- * @param int $input a standard unix timestamp
- * @return string a text formatted time representation readable by CompMngr
- */
- function getFormattedTime($input)
- {
- return date("n.j.Y.H.i.s",$input);
- }
- include("../include/paths.inc");
- echo "$CIB_CONFIG_PATH";
- if ($argv[1]=="") die("No Comp Name provided\n");
- if ($argv[2]=="") die("No Comp File provided\n");
- if ($argv[3]=="") die("No email address provided for document delivery\n");
- $unixname=$argv[1];
- if (!ereg("^[-a-zA-Z0-9_]*$",$unixname)) die ("Badly formed compname\n");
- $mailto = $argv[3];
- $CIB_TOOL_ROLE="register";
- ini_alter("include_path", "$CIB_CLASS_PATH:$CIB_PREFIX/include:$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixname/PREPARSED");
- include "$CIB_CONFIG_PATH/comps/{$unixname}_config.inc";
- if (!isset($SD_compname)) die ("Invalid Comp Name.");
- include "$CIB_INCLUDE_PATH/tools/SlidingDoors_header.inc";
- ini_alter("include_path", "$CIB_WEB_PATH/$CIB_WEB_INSTALL/$CIB_TOOL_ROLE/$unixname/PREPARSED");
- // build up the event categories keys from the imported file
- $compmngr_lines = file($argv[2]);
- $danceCats=array();
- echo "<pre>";
- foreach ($compmngr_lines as $aLine)
- {
- $fields = explode('|',$aLine);
- if ($fields[0]!="DC") continue;
- $danceCat = $fields[3];
- $danceCatName = $fields[4];
- $numDances = $fields[5];
- $danceCodes=array();
- for ($i=0;$i<$numDances;$i++)
- {
- $danceCode=$fields[6+$i*2];
- $danceName=$fields[6+$i*2+1];
- $danceCodes[$danceName]=$danceCode;
- }
- $levelOffset=6+2*$numDances;
- $numLevels = $fields[$levelOffset];
- $levelCodes=array();
- for ($i=0;$i<$numLevels;$i++)
- {
- $levelCode=$fields[$levelOffset+1+$i*2];
- $levelName=$fields[$levelOffset+1+$i*2+1];
- $levelCodes[$levelName]=$levelCode;
- }
- $ageOffset=$levelOffset+1+2*$numLevels;
- $numAges = $fields[$ageOffset];
- $ageCodes=array();
- for ($i=0;$i<$numAges;$i++)
- {
- $ageCode=$fields[$ageOffset+1+$i*3];
- $ageName=$fields[$ageOffset+1+$i*3+1];
- $ageChunks = explode (" ",$ageName);
- $ageCodes[$ageChunks[0]]=$ageCode;
- }
- $danceCats[]=array("DanceCat"=>$danceCat,
- "DanceCatName"=>$danceCatName,
- "Dances"=>$danceCodes,
- "Levels"=>$levelCodes,
- "Ages"=>$ageCodes);
- }
- print_r($danceCats);
- $query="SELECT eventid, age, eventshortprefix, level, style FROM events NATURAL JOIN events_categories JOIN age_levels ON (age=levelname); ";
- $result=$db->query($query);
- $numEvents=$result->numrows();
- $eventLUT=array();
- for ($i=0;$i<$numEvents;$i++)
- {
- list($eventID, $age, $ageAbbrev, $level, $style) = $result->getRowAt($i);
- $query = "SELECT dancename, abbreviation FROM events_dances JOIN
- abbreviations ON (dancename=fulltext) WHERE eventid=$eventID ORDER BY danceorder;";
- $subResult = $db->query($query);
- $numDances=$subResult->numrows();
- $danceName=""; $danceAbbrev="(";
- for ($j=0; $j<$numDances; $j++)
- {
- if ($j!=0)
- {
- $danceName.="/ "; $danceAbbrev.='/';
- }
- list($aDance,$anAbbrev) = $subResult->getRowAt($j);
- $danceName.=$aDance;
- $danceAbbrev.=$anAbbrev;
- }
- // echo "Trying to match : $eventID -- $age $level $style $danceName\n";
- $danceAbbrev.=")";
- $eventMatched=FALSE;
- foreach($danceCats as $aCat)
- {
- // echo "--{$aCat["DanceCatName"]}\n";
- $anAgeCode=""; $aDanceCode=""; $aLevelCode="";
- if ($aCat["Ages"][$ageAbbrev]!="")
- {
- $anAgeCode=$aCat["Ages"][$ageAbbrev];
- // echo "----Age matched\n";
- }
- // else "----Age not-matched\n";
- if ($aCat["Dances"][$danceName]!="")
- {
- $aDanceCode=$aCat["Dances"][$danceName];
- // echo "----Dance matched\n";
- }
- // else "----Dance not-matched\n";
- if ($aDanceCode=="" && $aCat["Dances"][$danceAbbrev]!="")
- {
- $aDanceCode=$aCat["Dances"][$danceAbbrev];
- // echo "----Dance matched\n";
- }
- // else if ($aDanceCode=="") echo "----Dance not-matched\n";
- if ($aCat["Levels"][$level]!="")
- {
- $aLevelCode=$aCat["Levels"][$level];
- // echo "----Level matched\n";
- }
- // else "----Level not-matched\n";
- $styleMatched=FALSE;
- if (preg_match("/$style/",$aCat["DanceCatName"]))
- {
- $styleMatched=TRUE;
- // echo "----Style matched\n";
- }
- // else echo "----Style not-matched\n";
- if ($styleMatched && $anAgeCode!="" &&
- $aDanceCode!="" && $aLevelCode!="")
- {
- $eventLUT[$eventID]=array("DanceCat"=>$aCat["DanceCat"],
- "DanceCode"=>$aDanceCode,
- "AgeCode"=>$anAgeCode,
- "LevelCode"=>$aLevelCode);
- $eventMatched=TRUE;
- break;
- }
- }
- if (!$eventMatched)
- {
- echo "NOT MATCHED -- $eventID -- $age $level $style $danceName\n";
- }
- else
- {
- echo "MATCHED -- $eventID\n";
- }
- }
- echo "</pre>";
- /*
- $query =<<<END_QUERY
- SELECT DISTINCT eventid,
- l.firstname, l.lastname, lo.name, ln.idnumber, lb.year,
- f.firstname, f.lastname, fo.name, fn.idnumber, fb.year,
- leader,follower,lo.orgid,fo.orgid
- FROM events_registration NATURAL JOIN
- couples JOIN
- people AS l ON (leader=l.peopleid) LEFT JOIN
- organizations AS lo ON (l.organization=lo.orgid) LEFT JOIN
- people_id_numbers AS ln ON (l.peopleid = ln.peopleid) LEFT JOIN
- people_birthdays AS lb ON (l.peopleid = lb.peopleid) JOIN
- people AS f ON (follower=f.peopleid) LEFT JOIN
- organizations AS fo ON (f.organization=fo.orgid) LEFT JOIN
- people_id_numbers AS fn ON (f.peopleid = fn.peopleid) LEFT JOIN
- people_birthdays AS fb ON (f.peopleid = fb.peopleid)
- ORDER BY eventid, l.lastname, l.firstname, f.lastname, f.firstname;
- END_QUERY;
- $result=$db->query($query);
- $numrows=$result->numrows();
- $partSeperator=md5(uniqid(time()));
- $body.=<<<END_BODY
- This is a MIME Encoded Email\n\n--$partSeperator
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- This email was sent via SlidingDoors, the on-line registration
- component of CompInaBox. Attached are raw text files containing the
- registration data, suitible for importing directly into COMPMNGR. Pipes
- ('|') are used to delimit the data.
- Reply to this message to get in touch with the CompInaBox Server Administrator.
- $CIB_SERVER_ADMIN_NAME
- $CIB_SERVER_HOST_NAME CompInaBox Server Administrator
- END_BODY;
- $body.=<<<END_PART_HEADER
- --$partSeperator
- Content-Type: text/plain; charset=us-ascii; name="by-school.txt"
- Content-Transfer-Encoding: 7bit
- END_PART_HEADER;
- $file1="";
- $studioBase=mktime(0,0,0,1,0,2000);
- $entryBase=mktime(0,0,0,0,0,2000);
- $personBase=mktime(0,0,0,0,0,2001);
- for ($i=0;$i<$numrows;$i++)
- {
- list ($eventID, $lfname, $llname, $lorg, $lusabda, $lyear,
- $ffname, $flname, $forg, $fusabda, $fyear,
- $lid, $fid, $loid, $foid) = $result->getRowAt($i);
- $danceCategory = $eventLUT[$eventID]["danceCat"];
- $danceCode = $eventLUT[$eventID]["DanceCode"];
- $levelCode = $eventLUT[$eventID]["LevelCode"];
- $ageCode = $eventLUT[$eventID]["AgeCode"]
- $leTime = getFormattedTime($personBase+$lid);
- $foTime = getFormattedTime($personBase+$fid);
- $enTime = getFormattedTime($entryBase+$i);
- if ($lorg==$forg)
- {
- $studio=$lorg;
- $stTime = getFormattedTime($studioBase+$loid*3600+$loid);
- }
- else
- {
- $studio="$lorg/$forg";
- $stTime = getFormattedTime($studioBase + $loid*36000+$foid);
- }
- $file1.="EN|$danceCategory|$danceCode|$levelCode|$ageCode|||N||$userCode|$enTime|";
- $file1.="ST|$studio|||||||||||1|$userCode|$stTime|"; // studio
- $file1.="PR|M|A|$lfname|$llname||$lusabda||1|$userCode|$leTime|"; // leader
- $file1.="PR|F|A|$ffname|$flname||$fusabda||1|$userCode|$foTime|"; // follower
- $file1.="PR|||||||||||"; // coach
- $file1.="\n";
- }
- $body.="$file1\n";
- $body.="\n--$partSeperator--\n";
- $headers="";
- $headers.=<<<END_HEADERS
- From: $CIB_SERVER_ADMIN_EMAIL\r
- X-mailer: CompInaBox (via PHP)\r
- MIME-Version: 1.0\r
- Content-Type: multipart/mixed;\r
- boundary="$partSeperator"
- END_HEADERS;
- mail("$mailto","[$unixname Competition] COMPMNGR Export",$body,$headers);
- */
- ?>
Documentation generated on Tue, 25 Apr 2006 13:00:38 -0400 by phpDocumentor 1.3.0RC3