function query($sql) { $q = mysql_query($sql); //die('SQL: '.$sql.'<br/>Error: '.mysql_error()); if (!$q) { RestUtils::error(500, mysql_error() . "\n" . $sql); } // die(mysql_error()."\n".$sql); // throw new Exception('SQL: '.$sql.'<br/>Error: '.mysql_error()); return $q; }
public function distanceFromContact() { $userID = RestUtils::authentication(); if (!$userID) { RestUtils::error(401, "Authentication Error"); } $OK = 200; $EMPT = 201; $ERRO = 500; $query = "SELECT distance, username\n\t\t FROM n_usertouser INNER JOIN n_nebulauser\n\t\t WHERE ((n_usertouser.contactID = n_nebulauser.id\n\t\t AND ownerID = {$userID}))\n\t\t AND distance !=0"; $execQuery = $this->nebulaDB->query($query); if (mysql_num_rows($execQuery) < 0) { return new Response($ERROR, "Impossible to retrieve contacts distance"); } if (mysql_num_rows($execQuery) == 0) { return new Response($EMPT, "No contacts to retrieve distance from"); } $result = array(); while ($ind = mysql_fetch_assoc($execQuery)) { /* if($ind['distance']<0.010){ if(!isset($result['0.010'])) $result['0.010'] = 0; $result['0.010'] += 1; } else */ if ($ind['distance'] < 0.02) { if (!isset($result['0.020'])) { $result['0.020'] = 0; } $result['0.020'] += 1; } else { if ($ind['distance'] < 0.05) { if (!isset($result['0.050'])) { $result['0.050'] = 0; } $result['0.050'] += 1; } else { if ($ind['distance'] < 0.1) { if (!isset($result['0.100'])) { $result['0.100'] = 0; } $result['0.100'] += 1; } else { if ($ind['distance'] < 0.25) { if (!isset($result['0.250'])) { $result['0.250'] = 0; } $result['0.250'] += 1; } else { if ($ind['distance'] < 0.5) { if (!isset($result['0.500'])) { $result['0.500'] = 0; } $result['0.500'] += 1; } else { if ($ind['distance'] < 1) { if (!isset($result['1'])) { $result['1'] = 0; } $result['1'] += 1; } else { if ($ind['distance'] < 2) { if (!isset($result['2'])) { $result['2'] = 0; } $result['2'] += 1; } else { if ($ind['distance'] < 5) { if (!isset($result['5'])) { $result['5'] = 0; } $result['5'] += 1; } else { if ($ind['distance'] < 10) { if (!isset($result['10'])) { $result['10'] = 0; } $result['10'] += 1; } else { if ($ind['distance'] < 20) { if (!isset($result['20'])) { $result['20'] = 0; } $result['20'] += 1; } elseif ($ind['distance'] < 50) { if (!isset($result['50'])) { $result['50'] = 0; } $result['50'] += 1; } else { if ($ind['distance'] < 100) { if (!isset($result['100'])) { $result['100'] = 0; } $result['100'] += 1; } else { if ($ind['distance'] < 250) { if (!isset($result['250'])) { $result['250'] = 0; } $result['250'] += 1; } else { if ($ind['distance'] < 500) { if (!isset($result['500'])) { $result['500'] = 0; } $result['500'] += 1; } } } } } } } } } } } } } } return new Response($OK, $result); }
function myErrorHandler($errno, $errstr, $errfile, $errline) { $report = "Error Number: {$errno}<br/>\n\tError: {$errstr}<br/>\n\tFile: {$errfile}<br/>\n\tLine: {$errline}"; RestUtils::error(500, $report); }
public function retrieveContacts($data) { // Get the ID of the user from the autentication data $userID = RestUtils::authentication(); if (!$userID) { RestUtils::error(401, "Authentication Error"); } $result = array(); $sql = "SELECT n_nebulacontacts.contactUsername AS contactUsername,\n\t\t\t\t\t\tn_nebulauser.username AS username,\n\t\t\t\t\t\t n_nebulauser.status AS userStatus,\n\t\t\t\t\t\t n_groupcontact.groupID as groupID\n\t\t\t\t\t\t FROM n_nebulacontacts\n\t\t\t\t\t\tLEFT JOIN n_nebulauser\n\t\t\t\t\t\t ON n_nebulauser.id = n_nebulacontacts.contactID\n\t\t\t\t\t\t LEFT JOIN n_groupcontact\n\t\t\t\t\t\t ON n_groupcontact.userContactID = n_nebulacontacts.contactID\n\t\t\t\t\t\t WHERE n_nebulacontacts.userID = {$userID}"; $ind = $this->nebulaDB->query($sql); $status = 200; while ($ris = mysql_fetch_assoc($ind)) { $result[] = $ris; } return new Response($status, $result); }
public function retrieveAllGroupsMembers($data) { // Get the ID of the user from the autentication data and return //an error message if it's not authenticated $userID = RestUtils::authentication(); if (!$userID) { RestUtils::error(401, "Authentication Error"); } $status = 200; $result = ""; //retrive groups members information $sql = "SELECT n_nebulauser.id, n_nebulauser.username, n_nebulauser.domain, n_nebulauser.fullName, n_nebulauser.status, n_nebulauser.phoneNumber, n_nebulauser.address, n_nebulauser.email_address, n_nebulagroup.groupName FROM n_nebulagroup LEFT OUTER JOIN n_groupuser ON n_groupuser.groupID = n_nebulagroup.id LEFT OUTER JOIN n_usertouser ON n_groupuser.userToUserID = n_usertouser.id LEFT OUTER JOIN n_nebulauser ON n_nebulauser.id = n_usertouser.contactID WHERE n_nebulagroup.ownerUserID={$userID} UNION ALL SELECT n_nebulauser.id, n_nebulauser.username, n_nebulauser.domain, n_nebulauser.fullName, n_nebulauser.status, n_nebulauser.phoneNumber, n_nebulauser.address, n_nebulauser.email_address, 'ungrouped' as groupName FROM n_nebulauser INNER JOIN n_usertouser ON n_nebulauser.id = n_usertouser.contactID where n_usertouser.ID not in (SELECT userToUserID from n_groupuser) and n_usertouser.ownerId={$userID}"; $query = $this->nebulaDB->query($sql); //retrieve group information $groupInfo = "SELECT n_nebulagroup.id, n_nebulagroup.groupName, n_nebulagroup.status\n\t\t\t\t \t FROM n_usertouser RIGHT OUTER JOIN n_groupuser\n\t\t\t\t \t ON n_groupuser.userToUserID = n_usertouser.id\n\t\t\t\t\t RIGHT OUTER JOIN n_nebulagroup\n\t\t\t\t \t ON n_nebulagroup.id = n_groupuser.groupID\n\t\t\t\t \t WHERE n_nebulagroup.ownerUserID = {$userID}"; $ask = $this->nebulaDB->query($groupInfo); $infos = array(); while ($info = mysql_fetch_assoc($ask)) { $infos[$info['groupName']] = array(); $infos[$info['groupName']]['id'] = $info['id']; $infos[$info['groupName']]['status'] = $info['status']; } while ($ris = mysql_fetch_assoc($query)) { if (!isset($ris['username']) || $ris['username'] == null || $ris['username'] == "") { $result[$ris["groupName"]] = ""; } else { $result[$ris["groupName"]][] = $ris; } //$result[$ris["groupName"]]["id"] = $info["id"]; //$result[$ris["groupName"]]["status"] = $info["status"]; if ($ris["groupName"] != 'ungrouped') { $result[$ris["groupName"]]["id"] = $infos[$ris["groupName"]]['id']; $result[$ris["groupName"]]["status"] = $infos[$ris["groupName"]]['status']; } else { $result[$ris["groupName"]]["id"] = 0; $result[$ris["groupName"]]["status"] = 'Available'; } } return new Response($status, $result); }