Created
July 7, 2014 22:01
-
-
Save gabrielboley/f38daf64226113a9761e to your computer and use it in GitHub Desktop.
course search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('config.php'); | |
if (isset($_POST['function'])) | |
{ | |
$function = $_POST['function']; | |
} | |
else if (isset($_GET['function'])) | |
{ | |
$function = $_GET['function']; | |
} | |
if($function == "getSchoolByStates"){ | |
$state_id = $_POST['state_id']; | |
$data = array(); | |
$schoolQuery = "select * from tbl_schools WHERE state_id = ".$state_id." order by school_name asc"; | |
$query = mysqli_query($link, $schoolQuery); | |
while($res = mysqli_fetch_array($query, MYSQLI_ASSOC)) { | |
$data[] = $res; | |
} | |
$json = json_encode(array('data'=>$data)); | |
echo $json; | |
} | |
if($function == "getCoursesBySchools"){ | |
$school_id = $_POST['school_id']; | |
$school_id = implode(',',$school_id); | |
$data = array(); | |
if($school_id == 'all') { | |
$sql = "select * FROM tbl_course_schools INNER JOIN tbl_courses ON tbl_courses.course_id = tbl_course_schools.course_id group by course_transfer"; | |
}else { | |
$sql = "select * FROM tbl_course_schools INNER JOIN tbl_courses ON tbl_courses.course_id = tbl_course_schools.course_id WHERE school_id IN ('".$school_id."') group by course_transfer"; | |
} | |
$query = mysql_query($sql); | |
while($res = mysql_fetch_array($query)) { | |
$data[] = $res; | |
} | |
$json = json_encode(array('data'=>$data)); | |
echo $json; | |
} | |
if($function == "getData") { | |
$state_id = $_POST['state_id']; | |
if(isset($_POST['school'])){ | |
$institution = $_POST['school']; | |
} | |
if($institution == "" || $institution == 'all') { | |
$institution = ''; | |
}else{ | |
$institution = implode(',',$institution); | |
} | |
$andClause = ''; | |
if($institution != '') { | |
$andClause = " AND s.school_id IN (".$institution.") "; | |
} | |
$sql = "select c.*,s.school_name FROM tbl_courses c INNER JOIN tbl_course_schools cs ON c.course_id = cs.course_id INNER JOIN tbl_schools s ON s.school_id = cs.school_id INNER JOIN tbl_states st ON st.state_id = s.state_id WHERE (st.state_id = '".$state_id."' ".$andClause.") AND decision !=6 AND show_results = 1 AND decision != 5"; | |
$query = mysqli_query($link, $sql); | |
while($res = mysqli_fetch_array($query, MYSQLI_ASSOC)) { | |
$data[] = $res; | |
} | |
$json = json_encode(array('aaData'=>$data)); | |
echo $json; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// Create the multiselect style for the states / schools | |
$('#select-state').multiselect({ | |
enableCaseInsensitiveFiltering: true, | |
includeSelectAllOption: false, | |
numberDisplayed: 1, | |
maxHeight: 400, | |
selectAllValue: 'all', | |
filterPlaceholder: 'Search', | |
dropRight: true, | |
}); | |
var value = []; | |
$('#select-school').multiselect({ | |
enableCaseInsensitiveFiltering: true, | |
includeSelectAllOption: true, | |
selectAllText: "Select All", | |
numberDisplayed: 1, | |
maxHeight: 400, | |
selectAllValue: 'all', | |
filterPlaceholder: 'Search', | |
dropRight: true, | |
onChange: function(element, checked) { | |
var i = value.indexOf(element[0].value); | |
if(i != -1) { | |
value.splice(i, 1); | |
}else { | |
value.push(element[0].value); | |
} | |
$.ajax({ | |
url : "assets/config/ajax.php", | |
type: "POST", | |
data : {"school_id":value,"function":"getCoursesBySchools"}, | |
success: function(data, textStatus, jqXHR) | |
{ | |
var json = JSON.parse(data); | |
var data = []; | |
for(var i=0;i<json.data.length;i++) { | |
data.push({'label':json.data[i].course_name,'value':json.data[i].course_id}); | |
} | |
$("#courses").multiselect('dataprovider', data); | |
}, | |
error: function (jqXHR, textStatus, errorThrown) | |
{ | |
} | |
}); | |
} | |
}); | |
// Get the list of the states | |
$("#select-state").change(function () { | |
$('#search-bar').removeClass('hidden'); | |
var state_id = $("#select-state option:selected").val(); | |
$.ajax({ | |
url: "assets/config/ajax.php", | |
type: "POST", | |
cache: false, | |
data: { | |
"state_id": state_id, | |
"function": "getSchoolByStates" | |
}, | |
success: function (data, textStatus, jqXHR) { | |
var json = JSON.parse(data); | |
var data = []; | |
for (var i = 0; i < json.data.length; i++) { | |
data.push({ | |
'label': json.data[i].school_name, | |
'value': json.data[i].school_id | |
}); | |
} | |
$("#select-school").multiselect('dataprovider', data); | |
$('#search-bar').addClass('hidden'); | |
}, | |
error: function (jqXHR, textStatus, errorThrown) { | |
} | |
}); | |
}); // End #select-state function | |
$("#search").on('click', function(event){ | |
event.preventDefault(); | |
$('#search-bar').removeClass('hidden'); | |
var state_id = $("#select-state option:selected").val(); | |
// var school_id = []; | |
// school_id = $("#select-school option:selected").val(); | |
$.ajax({ | |
url:"assets/config/ajax.php", | |
type: "POST", | |
//dataType: 'json', | |
data: { | |
"state_id": state_id, | |
"school": value, | |
"function": "getData" | |
}, | |
success: function (data, textStatus, jqXHR) { | |
var json = JSON.parse(data); | |
if (json.aaData == null) { | |
// show the empty table | |
$("#search-bar").addClass('hidden'); | |
$(".no-results-found").removeClass('hidden'); | |
}else { | |
// show the results | |
$("#search-bar").addClass('hidden'); | |
var tableData = ''; | |
tableData += "<tr><th>Transfering Institution</th><th>Course to Transfer</th><th>U of U Course</th><th>Decision</th><th>Required Grade</th><th>Conditions</th><th>Valid From</th><th>Valid Through</th></tr>"; | |
for (var i =0; i < json.aaData.length; i++){ | |
$(".results").removeClass('hidden'); | |
tableData += '<tr><td>' + json.aaData[i].school_name + '</td><td>' + json.aaData[i].course_transfer + ' ' + json.aaData[i].course_number + '</td><td>' + json.aaData[i].course_name + ' ' + json.aaData[i].utah_number + '</td><td>' + json.aaData[i].decision + '</td><td>' + json.aaData[i].grades + '</td><td>' + json.aaData[i].otherCondition + ' | ' + json.aaData[i].Conditions + '</td><td>' + json.aaData[i].valid_from + ' ' + json.aaData[i].valid_from_year + '</td><td>' + json.aaData[i].valid_through + ' ' + json.aaData[i].valid_through_year + '</td></tr>'; | |
} // end for loop | |
//$('#results-table').empty(); | |
$('.rTable').html(tableData); | |
} // end else | |
}, // end success | |
error: function (jqXHR, textStatus, errorThrown) {} | |
}) // end ajax | |
}); // end search | |
}); // end document ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require ('assets/config/config.php'); | |
$stateQuery = "SELECT * from tbl_states order by state_name asc"; | |
$query = mysqli_query($link, $stateQuery); | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>My Website</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- CSS --> | |
<link href="assets/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="assets/css/custom.css" rel="stylesheet"> | |
<link rel="stylesheet" href="assets/css/bootstrap-multiselect.css" type="text/css"/> | |
<!-- JS --> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script src="assets/js/respond.js"></script> | |
<script type="text/javascript" src="assets/js/bootstrap-multiselect.js"></script> | |
<script type="text/javascript" src='assets/js/actions.js'></script> | |
</head> | |
<body> | |
<div class='container'> | |
<table class='table tabl-condensed'> | |
<form role="form"> | |
<tr> | |
<td align="left" width='15%'> | |
<label for="select" class="control-label">Transfer State*</label> | |
</td> | |
<td align="left" width="20%"> | |
<div class="form-group"> | |
<select class="form-control" id="select-state" name="state" required> | |
<option value="-1">State</option> | |
<?php | |
while($res = mysqli_fetch_array($query, MYSQLI_ASSOC)) { | |
?> | |
<option value="<?php echo $res['state_id'] ?>"><?php echo $res['state_name'] ?></option> | |
<?php | |
} | |
?> | |
</select> | |
</div> | |
</td> | |
<td align="left" width="15%"> | |
<label for="select" class="control-label">Transfer School*</label> | |
</td> | |
<td align="left" width="40%"> | |
<div class="form-group"> | |
<select class="form-control multiselect" multiple="multiple" id="select-school" name="school" required> | |
</select> | |
</div> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<button type="submit" name="search" id="search" class="btn btn-default">Search</button> | |
</td> | |
<td colspan='3'> | |
<div class="hidden" id="search-bar"> | |
<img src='assets/img/ajax-loader.gif'> | |
</div> | |
</td> | |
</form> | |
</table> | |
<table class="table table-condensed table-hover results rTable hidden"> | |
<tbody id="results-table"></tbody> | |
</table> | |
<div class='addcourse results hidden'> | |
<div id='no-results'>Still don't see your course? Click <a href="submit/submit_course.php" >here</a> to submit a course for evaluation.</div> | |
</div> | |
<div class="no-results-found hidden"> | |
<div id='no-results'>No result found, please click <a href="submit/submit_course.php">here</a> to submit a course for evaluation.</div> | |
</div> | |
</div> | |
<script src="assets/js/bootstrap.min.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment