Category: Uncategorised
Written by x9494r
$orgHometown = '{add_team___hometown_district}';
$thisHometown = '{add_team___hometown_district}';
$thisNickname = '{add_team___nickname}';
$thisHometown = htmlspecialchars_decode($thisHometown);
$thisNickname = htmlspecialchars_decode($thisNickname);
// SANITIZE INPUT
// replace apostraphes with `
//$thisHometown = str_replace("‚", "`", $thisHometown);
//$thisHometown = preg_replace("/'/", '`', $thisHometown);
$thisHometown = str_replace("'", '`', $thisHometown);
// TEST
$thisTest = preg_replace('/[^\w]/', '', $thisHometown);
//$thisHometown = preg_replace('/[^\w]/', '', $thisHometown); //removes spaces as well as quotes
// ************
// split hometown name into array of words and remove any non alphas from each word
// only needed to remove apostrophes (for some reason can't strig replace apostrophes or html equivalents)
$delimiter = ' ';
$wordsARR = explode($delimiter, $thisHometown);
$cleanedDistrict = "";
$index= -1;
foreach ($wordsARR as $word) {
$index++;
$word = preg_replace('/[^\w]/', '', $word); // removes non alphas in order to expose hidden chars ( => "039")
$wordsARR[$index] = $word . " ";
}
$cleanedDistrict = "";
foreach ($wordsARR as $word) {
$cleanedDistrict .= $word . " ";
}
// remove last space
$cleanedDistrict = str_replace('039', "`", $cleanedDistrict); // replace apostrophes
$cleanedDistrict = rtrim($cleanedDistrict); // remove any end spaces
// replace double spaces with single space
$cleanedDistrict = str_replace(' ', " ", $cleanedDistrict); // this does not work?
// ************
$thisNickname = str_replace("'", "`", $thisNickname);
// replace quotes
$thisHometown = str_replace('"', "", $thisHometown);
$thisNickname = str_replace('"', "", $thisNickname);
// change to title caps
$thisHometown = ucwords(strtolower($thisHometown));
$thisNickname = ucwords(strtolower($thisNickname));
unset($similarTeamsArr);
$thisFullTeamName = $thisHometown . " " . $thisNickname;
// ********************
// split nickname into array of words and remove any non alphas from each word
// only needed to remove apostrophes (for some reason can't strig replace apostrophes or html equivalents)
$delimiter = ' ';
$wordsARR = explode($delimiter, $thisNickname);
$cleanedNickname = "";
$index= -1;
foreach ($wordsARR as $word) {
$index++;
$word = preg_replace('/[^\w]/', '', $word); // removes non alphas in order to expose hidden chars ( => "039")
$wordsARR[$index] = $word . " ";
}
$cleanedNickname = "";
foreach ($wordsARR as $word) {
$cleanedNickname .= $word . " ";
}
// remove last space
$cleanedNickname = str_replace('039', "`", $cleanedNickname); // replace apostrophes
$cleanedNickname = rtrim($cleanedNickname); // remove any end spaces
// replace double spaces with single space
$cleanedNickname = str_replace(' ', " ", $cleanedNickname); // this does not work?
$cleanedDistrict = ucwords(strtolower($cleanedDistrict));
$cleanedNickname = ucwords(strtolower($cleanedNickname));
$cleanedTeamName = $cleanedDistrict . " " . $cleanedNickname;
// **********************
if ($thisHometown !== "") {
// user has entered something
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select('last_name')
->from('world_tracks_individuals')
->where('BINARY last_name = ' . $myDb->quote($cleanedTeamName) );
$myDb->setQuery($myQuery);
$matchingTeam = $myDb->loadResult();
if ($matchingTeam == "") {
// team does not exist
$thisSearchHome = "%" . $thisHometown ."%" ;
$thisSearchNickname = "%" . $thisNickname ."%" ;
// check for similar
$thisSearchTeamName = "%" . $thisHometown ."%" . $thisNickname . "%";
$thisSearchTeamName = "%" . $thisHometown . "%";
// $thisSearchTeamName = $thisSearchHome . " " . $thisSearchNickname;
$searchCleanedTeamName = "%" . $cleanedTeamName . "%";
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select('last_name')
->from('world_tracks_individuals')
->where('last_name LIKE ' . $myDb->quote($searchCleanedTeamName) );
$myDb->setQuery($myQuery);
$similarTeamsArr = $myDb->loadObjectList();
// OUTPUT TEAMS
$nameList = array();
foreach ($similarTeamsArr as $similarTeam) {
$nameList[] = "" .$similarTeam->last_name . "";
}
//return ">" . $thisTeamName. "<
" . print_r($teamsInDrill);
if (count($similarTeamsArr) != 0) {
$summLabel = "" .
" Similar Teams Found: " . $cleanedTeamName . "
";
} else {
$summLabel = ""; // . $thisHometown;
}
// *************************
// OUTPUT
return $summLabel . "" . implode($nameList) . "
";
/*
// return new team
$summLabel = "" .
" Valid Team:
";
return $summLabel . $thisFullTeamName;
*/
} else {
// team already exists
// *************************
// OUTPUT
return "" .
" Sorry that Team Already exists.
";
} // end if matchingTeam
} else {
// user has not entered anything yet
//$summLabel = "" . $thisFullTeamName;
// *************************
// OUTPUT
return "" ;
}