Skip to content

Commit

Permalink
Bugfixes. SO many bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinaldhar committed Mar 20, 2016
1 parent b31d23f commit 82fc369
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 38 deletions.
3 changes: 2 additions & 1 deletion css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ body, html {

}
body {
margin-bottom: 50px;
background: url('../bgtile.png');

}
Expand Down Expand Up @@ -152,4 +153,4 @@ input {
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
}
4 changes: 4 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
session_start();
require_once("./utils/ldap.php");
require_once("./utils/userhelper.php");
if (isLoggedIn()) {
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/home.php'; // the user is redirected to the home page if logged in
header('Location: ' . $home_url);
}
?>
<!--

Expand Down
6 changes: 3 additions & 3 deletions js/all_trips.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function getPublicTrips() {
for (var x=0; x<results.length; x++) {
var current = results[x];
$('#matched_results').append('<li>\
<span class="matched_name">'+current["userid"]+'</span>\
<span class="matched_name">'+current["username"]+'</span>\
<span class="matched_contact"><a href="mailto:'+current["userid"]+'">'+current["userid"]+'</a> &bull; '+current["phone"]+'</span>\
<span class="matched_route">'+getShortAddr(current["source_addr"])+' to '+getShortAddr(current["dest_addr"])+' &bull; '+ getAMPM(current["start_time"])+' - '+ getAMPM(current["end_time"])+'</span>\
<span class="matched_details">'+current["travellers"]+' travellers &bull; '+current["comment"] +'</span></li>');
<span class="matched_details">'+current["travellers"]+' travellers on '+current["date"]+' &bull; '+current["comment"] +'</span></li>');

}
}
Expand All @@ -52,4 +52,4 @@ function getPublicTrips() {
}


}
}
27 changes: 18 additions & 9 deletions js/new_trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,28 @@ $('#form_table').submit(function() { // What kind of name is form_table a
phone_number: $('#phone').val(),
travellers: $('#num_cotravel').val(),
comment: $('#comments').val(),
"private": $('#privacy').val()
"private": $('#privacy').val().split(' - ')[0]
}
console.log(data);
var result = ajaxCall(API_dir+API_addTrip, data, "POST", false);
if (data["source_addr"]!="" && data["dest_addr"]!="" && data["data"]!="" && data["start_time"]!="" && data["end_time"]!="") {
$('#submit_btn').val("Adding trip and finding matches...");
var result = ajaxCall(API_dir+API_addTrip, data, "POST", true);
console.log(result);
if (result["status"] == 0) {
window.location="./home.php";
}
else {
alert("Problem. ");
}
// if (result["status"] == 0) {
window.setTimeout(function() {
window.location="./home.php";
}, 5000);
// }
// else {
// alert("Problem. Retry maybe? ");
//return false;
// }
}
else {
alert("Some required fields were left empty.");
return false;
}
});
function submitform_addTrip() {

}
}
4 changes: 2 additions & 2 deletions js/new_trip_maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function initMap() {
};
// document.getElementById('autocomplete2').addEventListener('change', function() { console.log('hi'); });
// document.getElementById('start').addEventListener('onFocus', onChangeHandler);
document.getElementById('autocomplete').addEventListener('change', onChangeHandler);
// document.getElementById('autocomplete').addEventListener('change', onChangeHandler);

document.getElementById('autocomplete2').addEventListener('change', onChangeHandler);
}
Expand All @@ -94,4 +94,4 @@ function calculateAndDisplayRoute(directionsService, directionsDisplay) {
console.log('Directions request failed due to ' + status);
}
});
}
}
6 changes: 3 additions & 3 deletions new_trip.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@
</td>
<td width="30%">
<select class="select_input" id="privacy" name="privacy">
<option> Yes - DONT show this trip on public page. </option>
<option> No - ALLOW other people to see this trip on public page. </option>
<option> Yes - DONT show this trip on public page. </option>
</select>
</td>
</tr>

<tr>
<td valign="top" width="30%" colspan="2" style="vertical-align: top;">
<input type="submit" class="btn anim" value="Add this trip" />
<input id="submit_btn" type="submit" class="btn anim" value="Add this trip" />
</td>
</tr>

Expand All @@ -152,4 +152,4 @@
<script src="./js/new_trip_maps.js"></script>
<script src="./js/helper.js"></script>
<script src="./js/endpoints.js"></script>
</html>
</html>
74 changes: 74 additions & 0 deletions newcabs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-- phpMyAdmin SQL Dump
-- version 4.2.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 20, 2016 at 02:18 AM
-- Server version: 5.6.20
-- PHP Version: 5.5.27

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `cab`
--

-- --------------------------------------------------------

--
-- Table structure for table `new_cab_share`
--

CREATE TABLE IF NOT EXISTS `new_cab_share` (
`id` int(6) unsigned NOT NULL,
`userid` varchar(50) NOT NULL,
`source_addr` longtext NOT NULL,
`dest_addr` longtext NOT NULL,
`date` varchar(50) NOT NULL,
`start_time` varchar(50) NOT NULL,
`end_time` varchar(50) NOT NULL,
`travellers` varchar(50) NOT NULL,
`phone` varchar(50) NOT NULL,
`comment` varchar(50) NOT NULL,
`state` int(6) unsigned NOT NULL,
`private` varchar(50) NOT NULL,
`username` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

--
-- Dumping data for table `new_cab_share`
--

INSERT INTO `new_cab_share` (`id`, `userid`, `source_addr`, `dest_addr`, `date`, `start_time`, `end_time`, `travellers`, `phone`, `comment`, `state`, `private`, `username`) VALUES
(15, '[email protected]', 'IIIT, Gachibowli', 'Inorbit Mall Road', '12/18/2015', '0809', '1605', '2', '1231231232', '2 bags', 0, 'No', ''),
(16, '[email protected]', 'Inorbit Mall Road, HITEC City, Hyderabad, Telangana, India', 'Airport Plaza Complex, Begumpet, Hyderabad, Telangana, India', '01/20/2016', '0646', '1700', '2', '7893550837', 'lalal', 0, 'Yes', '');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `new_cab_share`
--
ALTER TABLE `new_cab_share`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `new_cab_share`
--
ALTER TABLE `new_cab_share`
MODIFY `id` int(6) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=17;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Binary file added utils/.matchTrip.php.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion utils/addTrip.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function addTripToDb($source, $destination, $date, $start_time, $end_time, $phon

include "config.php";

$query = "INSERT INTO new_cab_share (userid, source_addr, dest_addr, date, start_time, end_time, phone, travellers, comment, private, state) VALUES ('". getUid() . "', '" . $source . "', '" . $destination . "', '" . $date . "', '" . $start_time . "', '" . $end_time ."', '" . $phone . "', '" . $travellers . "', '" . $comment . "', '" . $private . "', 0)";
$query = "INSERT INTO new_cab_share (userid, source_addr, dest_addr, date, start_time, end_time, phone, travellers, comment, private, state, username) VALUES ('". getUid() . "', '" . $source . "', '" . $destination . "', '" . $date . "', '" . $start_time . "', '" . $end_time ."', '" . $phone . "', '" . $travellers . "', '" . $comment . "', '" . $private . "', 0, '". getName() . "')";

$success = mysqli_query($link, $query);
if($success) {
Expand Down
6 changes: 3 additions & 3 deletions utils/config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
$db_mysql_host='localhost';//Default MySQL db at localhost
$db_mysql_user='cab';//db user name
$db_mysql_password='callTHEcabbie';//db password for auth
$db_mysql_name='cab';
$db_mysql_user='root';//db user name
$db_mysql_password='!@#OsDgMySqLSeRvEr!@#';//db password for auth
$db_mysql_name='cab_share';
$db_mysql_table_name='new_cab_share';
$link = mysqli_connect($db_mysql_host, $db_mysql_user, $db_mysql_password, $db_mysql_name) or die("OOPS");
if(!$link)
Expand Down
11 changes: 6 additions & 5 deletions utils/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ function getShortAddr($longAddr) {


function send_email($to, $result) {

var_dump($result);
$result = json_decode($result, true);

var_dump($result);
if ($result["status"] == 0) {
$headers = array("From: [email protected]",
"Reply-To: no-reply@cabs.iiit.ac.in",
"Reply-To: mdhr@osdg.iiit.ac.in",
"X-Mailer: PHP/" . PHP_VERSION,
"Content-Type: text/html; charset=ISO-8859-1",
"MIME-Version: 1.0"
Expand All @@ -36,7 +36,7 @@ function send_email($to, $result) {
$message .= ' <table width="60%">';
$message .= ' <tr>';
$message .= ' <td width="100%" align="center">';
$message .= ' <h1> <a href="http://cabs.iiit.ac.in/" style="color: #3e3e3e;">CabShare</a> </h1>';
$message .= ' <h1> <a href="http://osdg.iiit.ac.in/cabs/" style="color: #3e3e3e;">CabShare</a> </h1>';
$message .= ' </td>';
$message .= ' </tr>';
$message .= ' <tr>';
Expand All @@ -52,7 +52,7 @@ function send_email($to, $result) {

foreach($data as $current) {
$message .= ' <li style="display: block; color: rgba(0,0,0,0.5); border-bottom-width: 1px; border-bottom-color: #4a4a4a; border-bottom-style: dashed; padding: 20px;">';
$message .= ' <span class="matched_name" style="display: block; width: 100%; color: rgba(0,0,0,1); font-size: 1.5em;">' . $current["userid"] . '</span>';
$message .= ' <span class="matched_name" style="display: block; width: 100%; color: rgba(0,0,0,1); font-size: 1.5em;">' . $current["username"] . '</span>';
$message .= ' <span class="matched_contact" style="display: block; width: 100%; color: rgba(0,0,0,1); margin-bottom: 5px; font-size: 0.9em;"><a href="mailto:' . $current["userid"] . '" style="color: black;">' . $current["userid"] . '</a> &bull; ' . $current["phone"] . '</span>';
$message .= ' <span class="matched_route" style="display: block; width: 100%; font-size: 0.9em; color: rgba(0,0,0,0.5);">' . getShortAddr($current["source_addr"]) . ' to ' . getShortAddr($current["dest_addr"]) . ' &bull; ' . $current["start_time"] . ' - ' . $current["end_time"] . '</span>';
$message .= ' <span class="matched_details" style="display: block; width: 100%; font-size: 0.9em;">' . $current["travellers"] . ' travellers &bull; ' . $current["comment"] . '</span>';
Expand Down Expand Up @@ -84,6 +84,7 @@ function send_email($to, $result) {
// "status" => 0,
// "data" => array(
// array(
// "username" => "Mrinal Dhar",
// "userid" => "mrinal.dhar",
// "start_time" => 1211,
// "end_time" => 1222,
Expand Down
28 changes: 17 additions & 11 deletions utils/matchTrip.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,29 @@ function matchTrip($tripId) {

$query = "SELECT * FROM " . $db_mysql_table_name .
" WHERE state=0" .
" AND userid!='" . getUid() . "'" .
// " AND userid!='" . getUid() . "'" .
" AND date='" . getTripDate($matchTrip) . "'"; // Ensures rides are on the same day.

$success = mysqli_query($link, $query);
$rows = array();
if($success) {
$rows = array();
while ($row = mysqli_fetch_assoc($success)) {
if(timeCoincides($row, $matchTrip)) { // Ensures that they start at around the same time.
if(getDistance(getDestAddr($row), getDestAddr($matchTrip)) <= 3000) {
if(getDistance(getSourceAddr($row), getSourceAddr($matchTrip)) <= 3000) {
$rows[] = $row;
while ($row = mysqli_fetch_assoc($success)) {
if(timeCoincides($row, $matchTrip)) { // Ensures that they start at around the same time.
if(getDistance(getDestAddr($row), getDestAddr($matchTrip)) <= 3000) {
if(getDistance(getSourceAddr($row), getSourceAddr($matchTrip)) <= 3000) {
$rows[] = $row;
}
}
}
}
}
}
$rows = json_encode($rows);
send_email(getMailId(), $rows);
$response = array(
"status" => 0,
"data" => $rows);
$response = json_encode($response);
foreach ($rows as $match) {
send_email(getUserId($match), $response);
}
send_email(getMailId(), $response);
}
else {
$response = array(
Expand Down

0 comments on commit 82fc369

Please sign in to comment.