Test

[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]

[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

\n\t\t

$td“;

// Print out Contact Info (Address, Phone Number, Phone Number) in order
// TODO: Clean up code… way too complicated
if($fieldcount>3&&$fieldcount<$vars1) { $searchresult .= ($fieldcount!==6) ? "
” : “, “;

// Field #8 = website
if ($fieldcount==8) {

// Add link to website if a website is in profile
if (!empty($td)){
if (!preg_match(‘/^http:/’,$td)) $td = ‘http://’.$td;
$searchresult .= “
Visit website” ;
}

}else $searchresult .= “$td”;
}

// Last field ‘Phone Number2’
if($fieldcount==$profilevars) {
$newcat=false;
$searchresult .= ”

“;

$searchresult .= “

“;
}
} // END IF not setnew
} //end elseif within profile limit

// Keeps track of courseID
elseif($label==’CourseID’) $theCourse = “$td”; # if not within profile limit, then is it the CourseID?

// Info of data is added to table (eg. Course Name, Length, Level, Prereq, Certificate, Description) in order
elseif($fieldcount>$profilevars) {
if($fieldcount==$vars1) $searchresult .= ” \n\t\t

“;

// if the field is not the last field… add it to table
if($fieldcount!==17) $searchresult .= “\n\t\t\t

“;

// if description characters passes $desclength (eg. 145 char.), then, add “…” and add link
elseif(strlen($td)==$desclength) $searchresult .= “\n\t\t\t

“;
else $searchresult .= “\n\t\t\t

“;
}

// Last field and add ending row tag… continue to the next course
if($fieldcount==17) $searchresult .= ” \n\t\t

“;

}
}
$searchresult .= “\t\t

Course Name Length Level Prereq Certificate Description
$td $td…
More Details » »
$td
More Details » »

\n “;
}

# PREVIOUS AND NEXT LINKS #################
/*if(!empty($what)) {
$where=$_GET[‘where’];
$morevars = “&what=$what&where=$where”;
} # */

/*$theend=$start+$limit;
if ($theend>$nums) $theend=$nums;
# echo ‘Showing records ‘.$start.’-‘.$theend.’ of ‘.$nums.’
‘;

if($start>0) {
$start-=$limit; ($start < 0) ? $start2 = 0: $start2 = $start; $theprevend=$start+$limit; $navlinks = "
|< < -- previous ($start2-$theprevend)        “;
}else $start-=$limit;

if (($theend+$limit)>=$nums) $thenextend=$nums;
else $thenextend=$start+$limit+$limit+$limit;

$start+= $limit+ $limit; $startend= $nums-$limit;
if($nums>$limit&&!($start>=$nums)) $navlinks .= ”  next ($start-$thenextend) — >all“;
$limitlinks .= ” | 50“;
$limitlinks .= ” | 100“; #

“;
}*/

// Output table with resulted categories, schools and courses
// The if statement is to prevent displaying all courses when user enters site
if (isset($_POST[‘submit’]) && !isset($_GET[‘select’]) ){
echo $searchresult;
}else if (isset($_GET[‘select’])){
echo $searchresult;
}
[/insert_php]

[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.