[insert_php]
/*
* Code Last Modified by Bao Phan
* Date: Nov-22-2006
*/
require_once( ‘../wp-config.php’);
require_once( ‘header.php’);
// Parses string such that it prepares the SQL statement to search for ‘any’ keywords
function parseAnyString($keyword){
$string_array = explode(” “, $keyword);
$message = “AND (“;
$first = false;
foreach ($string_array as $word){
if (!empty($word) && $first == false){
$message .= “Description LIKE ‘%$word%’ OR Course_Name LIKE ‘%$word%’ “;
$first = true;
}else if (!empty($word) && $first == true){
$message .= “OR Description LIKE ‘%$word%’ OR Course_Name LIKE ‘%$word%’ “;
}
}
$message .= “)”;
return $message;
}
// if variable ‘otherTrainerBrowse’ is empty (null), it defaults to ‘1’
$number = ($_POST[‘otherTrainerBrowse’]) ? $_POST[‘otherTrainerBrowse’] : ‘1’;
// method ‘get_trainerdata’ is refered at ../wp-includes/pluggable-function.php
$coursedata = get_trainerdata($number, ‘trainers’);
if(!$_POST&&!$_GET[‘select’])
{
[/insert_php]
Welcome
Brought to you by Collision Repair Magazine, this Training Guide will help you find training in the collision repair industry.
Use the menu below to begin searching for courses.
[insert_php]
}else {
[/insert_php]
}
// Getting keyword if typed and check what search contraint the user picked (‘any’,’all’ or blank)
if ($_POST[‘condition_keyword’]) $keyword_condition = $_POST[‘condition_keyword’];
// This is where users pick what to courses to view by province or/and training provider
if($_POST[‘category’]) $acat = $_POST[‘category’];
if($_POST[‘province’]) $prov = $_POST[‘province’];
if($_POST[‘otherTrainerBrowse’]) $train = $_POST[‘otherTrainerBrowse’];
// Check whether user want I-Card Certified or non certified courses
if($_POST[‘ICardCertified’]) $ICardCertified = $_POST[‘ICardCertified’];
// Construct ‘search’ message accordingly
// Example: If user chose Ontario and view all courses from BASF it would show:
// “Your search for courses in Alberta from BASF returned the following results.”
if($coursedata) $TrainerName= $coursedata->Name;
if ($prov) $pstate = ” in “.$provinces[$prov];
if ($acat) $catstate = ” within the category ‘$acat'”;
if ($train) $trastate = ” from $TrainerName”;
$searchresult = “
Your search for courses $pstate $catstate $trastate returned the following results.
“;
// To prepare for SQL statement with respect to what constraints the users want to view
// into variable $and
// Parses the keywords into SQL statement according to ‘any’ or ‘all’
if(!empty($keyword)){
if ($keyword_condition == ‘all’) $and .= ” AND Description LIKE ‘%$keyword%’ AND Course_Name Like ‘%$keyword%'”;
else $and .= parseAnyString($keyword); // Defaults keyword search to ‘any’
}
if(!empty($acat)) $and .= ” AND Category=’$acat'”;
if(!empty($prov)) $and .= ” AND Province=’$prov'”;
if(!empty($train)) $and .= ” AND TrainerID=’$train'”;
if(!empty($ICardCertified) && $ICardCertified == ‘Yes’) $and .= ” AND ICar_Alliance=’Yes'”;
elseif (!empty($ICardCertified) && $ICardCertified == ‘No’) $and .= ” AND ICar_Alliance=’No'”;
elseif($select) $and = “”;
// Description Length of 145 characters
$desclength = 145;
// SQL query to fetch info from database (16 fields)
$query = ” SELECT `TrainerID`,`Category`,`Name`,`Address`,`City`,`Province`,`Postal_Code`,`Website`,
`Phone1`,`Phone2`, `Course_Name`,`Length`, `Level`, `Prerequisites`,
`Certification`,`CourseID` ,SUBSTRING(`Description`, 1, $desclength) AS `Description`
FROM {$wpdb->trainers}, {$wpdb->courses}
WHERE {$wpdb->trainers}.ID ={$wpdb->courses}.TrainerID $and
ORDER BY Category, Name “; #limit 0, 20”; # ,`Email`, `Delivery_Method`, ICar_Alliance
$profilevars =10;
$vars1 =$profilevars + 1;
// Enter SQL query into database
$wpdb->query($query);
// Perform SQL querty and store results into $results
$results = $wpdb->get_results($query);
$fields = $wpdb->num_fields;
if(!$results){
// results return nothing
echo ‘
Sorry, No results for that query.
‘;
}else {
// results return at least 1 entry
// Prepare table to present data
// For each category ‘ff’…..
foreach($results as $ff) {
($cnt % 2) ? $row_color= “#ffffff” : $row_color=”#d5d5d5″; #$row_color=”#E8E9F0″; ALTERNATE COLOURS
$cnt++;
$urltest = get_bloginfo(‘url’); #$user_idtd =”;
$fieldcount=0;
// PRINT EACH DATA CELL ******************************************
foreach($ff as $label=>$td){ // For each Category and field name (
$fieldcount++;
// $td = trainer ID
if($fieldcount==1) {
if($td==$user_idtd) $setnew=true;
else $setnew=false;
$user_idtd = trim($td);
}
// $td = category
elseif($fieldcount==2) { #$searchresult .= “$category = $td”;
if (strcmp($td, $category) !== 0) $newcat=true; # if($td!==$category) $newcat=true;
else $newcat=false; #if($newcat)$searchresult .= “$category = $td”;
$category = trim($td);
}
// $td = {`Name`,`Address`,`City`,`Province`,`Postal_Code`,`Website`,`Phone1`,`Phone2`}
// fieldcount from 3 to 10
elseif($fieldcount>2&&$fieldcount<$vars1) { # elseif($label=='Name') within profile limit
if(!$setnew|| $newcat) { #IF NEW PROVIDER OR CATEGORY add data
if($cnt!==1&&$fieldcount==3) $searchresult .= "\t\t
\n
“;
if($newcat&&$fieldcount==3) $searchresult .=”\n
$category
“;
#if($fieldcount==$profilevars)
// Print Name of Company and make it larger
if($fieldcount==3) $searchresult .= “\n\t
$td“;
// Print out Contact Info (Address, Phone Number, Phone Number) in order // Field #8 = website // Add link to website if a website is in profile }else $searchresult .= “$td”; // Last field ‘Phone Number2’ |
\n “; # PREVIOUS AND NEXT LINKS ################# /*$theend=$start+$limit; if($start>0) { if (($theend+$limit)>=$nums) $thenextend=$nums; $start+= $limit+ $limit; $startend= $nums-$limit; |
“; }*/ // Output table with resulted categories, schools and courses |
[insert_php]
// method ‘browse_form’ is refered at file ../wp-includes/pluggable-function.php
// Outputs the HTML code to browse courses
browse_form($coursedata);
[/insert_php]
Media Matters Inc. acknowledges
the assistance
of the OMDC Magazine Fund, an initiative of
Ontario Media
Development Corporation.