function runMatching($contacts) { // Read data from jva_contacts table and store it in a object $jva_data = array(); $jvaQuery = "SELECT * FROM jva_contacts"; $DBResource = getDBConnection(); $jva_resultSet = $resultSet = execSQL($DBResource, $jvaQuery); if (mysqli_num_rows($jva_resultSet) > 0) { while ($jva_r = mysqli_fetch_row($jva_resultSet)) { $jva_row = new TempContact(); $jva_row->jva_id = $jva_r[0]; $jva_row->jva_first_name = $jva_r[1]; $jva_row->jva_middle_name = $jva_r[2]; $jva_row->jva_last_name = $jva_r[3]; $jva_row->jva_salutation = $jva_r[4]; $jva_row->jva_phone_no = $jva_r[5]; $jva_row->jva_fax_no = $jva_r[6]; $jva_row->jva_country = $jva_r[7]; $jva_row->jva_zipcode = $jva_r[8]; $jva_row->jva_email = $jva_r[9]; array_push($jva_data, $jva_row); } closeDBConnection($DBResource); // To compare each record in jva_contacts with all records in the file foreach ($jva_data as $jva_row) { foreach ($contacts as $contacts_row) { $c_last = $contacts_row->con_last_name; $j_last = $jva_row->jva_last_name; $DBResource = getDBConnection(); if ($jva_row->jva_last_name == $contacts_row->con_last_name && $jva_row->jva_country == $contacts_row->con_country && $jva_row->jva_email == $contacts_row->con_email) { $nQuery = "INSERT INTO notifications(src_id,src_con_id,jva_id,match_case,pending_notification) values('" . $contacts_row->src_id . "','" . $contacts_row->src_con_id . "'," . $jva_row->jva_id . ",'Perfect',1)"; $resultSet = execSQL($DBResource, $nQuery); } else { if ($jva_row->jva_country == $contacts_row->con_country && $jva_row->jva_email == $contacts_row->con_email) { if (strpos($j_last, $c_last) !== FALSE || strpos($c_last, $j_last) !== FALSE) { $nQuery = "INSERT INTO notifications(src_id,src_con_id,jva_id,match_case,pending_notification) values('" . $contacts_row->src_id . "','" . $contacts_row->src_con_id . "'," . $jva_row->jva_id . ",'Partial',1)"; $resultSet = execSQL($DBResource, $nQuery); } } else { $nQuery = "INSERT INTO notifications(src_id,src_con_id,jva_id,match_case,pending_notification) values('" . $contacts_row->src_id . "','" . $contacts_row->src_con_id . "',0,'New',1)"; $resultSet = execSQL($DBResource, $nQuery); } } closeDBConnection($DBResource); } // end of inner for each loop } // end of outer for each loop } else { foreach ($contacts as $contacts_row) { $nQuery = "INSERT INTO notifications(src_id,src_con_id,jva_id,match_case,pending_notification) values('" . $contacts_row->src_id . "','" . $contacts_row->src_con_id . "',0,'New',1)"; execSQL($DBResource, $nQuery); } } }
function loadAllUsersAndVoice() { $conn = getDBConnection(); $sql = "SELECT * FROM users WHERE user_voice IS NOT NULL "; $result = mysql_query($sql, $conn) or die(mysql_error()); $users = null; $i = 0; while ($row = mysql_fetch_array($result)) { $users[$i][0] = $row['id']; $users[$i][1] = $row['first_name']; $users[$i][2] = $row['picture']; $users[$i][3] = $row['user_voice']; $i++; } closeDBConnection($conn); return $users; }
function setNotificationDeatils($friends, $msg) { if (isset($_SESSION['user_id'])) { $user_id = $_SESSION['user_id']; } else { $user_id = 0; } $userdetails = getUserNameById($user_id); $conn = getDBConnection(); try { $notify = mysql_query("select * from users where id in ({$friends})", $conn); if (mysql_num_rows($notify) > 0) { while ($row = mysql_fetch_array($notify)) { $to = $row['push_notify_id']; //registration ID of the device $title = $userdetails[0]; $message = $msg; $this->sendPushNotification($to, $title, $message); } } closeDBConnection($conn); } catch (Exception $ex) { echo $ex->getMessage(); } }
private function insert_CommentLink() { //$GLOBALS['log'] .= "<br/>****************** <span class='startCall'> Call CommentLink->insert_CommentLink() </span>"; try { if (!$this->commentID) { throw new Exception('commentID is Null!'); } if (!$this->AFDID) { throw new Exception('AFDID is Null!'); } if (!$this->link_Html) { throw new Exception('link_Html is Null!'); } $this->link_Html = trim($this->link_Html); $conn_NeedToClose = false; openDBConnection($this->conn, $conn_NeedToClose); $sql = "INSERT INTO `commentLink` ( commentID, AFDID, link_Html, giveComment_Html, link_Sentance, link_Title, link_Label, link_URL, link_URLPosition, link_User, link_DateTime, link_External, link_Policy, link_Class, link_PolarityGrade, link_PolarityKeyword, link_ToOtherUser) \n VALUES ( '{$this->commentID}', '" . mysql_real_escape_string($this->AFDID) . "', '" . mysql_real_escape_string($this->link_Html) . "', '" . mysql_real_escape_string($this->giveComment_Html) . "', '" . mysql_real_escape_string($this->link_Sentance) . "', '" . mysql_real_escape_string($this->link_Title) . "', '" . mysql_real_escape_string($this->link_Label) . "', '" . mysql_real_escape_string($this->link_URL) . "', '" . mysql_real_escape_string($this->link_URLPosition) . "', '" . mysql_real_escape_string($this->link_User) . "', '" . $this->link_DateTime . "', '" . $this->link_External . "', '" . $this->link_Policy . "', '" . $this->link_Class . "', '" . $this->link_PolarityGrade . "', '" . $this->link_PolarityKeyword . "', '" . $this->link_ToOtherUser . "' )"; //$GLOBALS['log'] .= "<br/>sql: $sql"; if (mysqli_query($this->conn, $sql)) { $this->commentLinkID = $this->conn->insert_id; //$GLOBALS['log'] .= "<br/> CommentLink Inserted <span class='good'>successfully</span> to DB AFDID=". $this->AFDID.", commentID=$this->commentID, commentLinkID=$this->commentLinkID"; } else { $GLOBALS['log'] .= "<br/> CommentLink <span class='bad'>Failed</span> to insert to DB"; $GLOBALS['log'] .= "<br/> <span class='bad'> Error description: " . mysqli_error($this->conn) . "</span>"; } closeDBConnection($this->conn, $conn_NeedToClose); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
static function getHTMLByURL($AFDURL) { $output = ""; try { $AFDURL = trim($AFDURL); if (!$AFDURL) { throw new Exception('AFDURL=$AFDURL is Null!'); } $conn = ""; $conn_NeedToClose = false; openDBConnection($conn, $conn_NeedToClose); $GLOBALS['log'] .= "<br/> AFD::getHTMLByURL({$AFDURL})"; $sql = "select AFDID, AFDURL, AFDHTML\n from afd\n where AFDURL='{$AFDURL}'"; //echo $sql; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while ($row = $result->fetch_assoc()) { $output = $row['']; $output .= "<br/><br/><a href='" . $row['AFDURL'] . "'>" . $row['AFDURL'] . "</a><br/><br/>"; $GLOBALS['log'] .= "<br/>" . basename(__FILE__, '.php') . ".php AFD::getHTMLByURL() AFDID:" . $row["AFDID"] . " AFDURL: " . $row["AFDURL"] . " </br>"; } } else { throw new Exception('There is no record in DB for AFDURL=$AFDURL!'); } closeDBConnection($conn, $conn_NeedToClose); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } return $output; }
$row = mysqli_fetch_assoc($result); $emailAddr = $row["email"]; $sql = "INSERT INTO Friends (email, type, type_id) \n VALUES ('{$emailAddr}', 'RECIPE','{$recipeId}');"; $conn->query($sql); } $success = addIngredientsToDB($conn, $recipeId); //if error in inserting ingredients into db if (!$success) { exit("Sorry, could not access database when adding ingredients. Please try again."); } $success = addTagsToDB($conn, $recipeId); //if error in inserting tags into db if (!$success) { exit("Sorry, could not access database when adding tags. Please try again."); } closeDBConnection($conn); redirectToViewRecipe($recipeId); } ?> <head> <meta charset="UTF-8"> <meta name="description" content="A virtual cookbook that allows user's to view, create and share recipes."> <meta name="keywords" content="recipe, cookbook, food, ingredients"> <meta name="author" content="Cookbook Network Inc."> <link rel="stylesheet" type="text/css" href="page_style.css"> <link href='http://fonts.googleapis.com/css?family=Tangerine:700' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=IM+Fell+Double+Pica' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>
private function insert_Comment() { //$GLOBALS['log'] .= "<br/>****************** <span class='startCall'> Call afd->insert_Comment() </span>"; try { if (!$this->AFDID) { throw new Exception('AFDID is Null!'); } if (!$this->debateDateListID) { throw new Exception('debateDateListID is Null!'); } if (!$this->AFDTitleID) { throw new Exception('AFDTitleID is Null!'); } if (!$this->comment_Html) { throw new Exception('comment_Html is Null!'); } $this->AFDTitleID = trim($this->AFDTitleID); $this->debateDateListID = trim($this->debateDateListID); $this->comment_Html = trim($this->comment_Html); $this->comment_User = trim($this->comment_User); $this->comment_DateTime = trim($this->comment_DateTime); $conn_NeedToClose = false; openDBConnection($this->conn, $conn_NeedToClose); $sql = "INSERT INTO `comment` ( AFDID, debateDateListID, AFDTitleID, comment_Html, comment_User, comment_DateTime) \n VALUES ( '{$this->AFDID}', '" . mysql_real_escape_string($this->debateDateListID) . "', '" . mysql_real_escape_string($this->AFDTitleID) . "', '" . mysql_real_escape_string($this->comment_Html) . "', '" . mysql_real_escape_string($this->comment_User) . "', '" . $this->comment_DateTime . "' )"; //$GLOBALS['log'] .= "<br/>sql: $sql"; if (mysqli_query($this->conn, $sql)) { $this->commentID = $this->conn->insert_id; $GLOBALS['log'] .= "<br/>Comment Inserted <span class='good'>successfully</span> to DB AFDID=" . $this->AFDID . ", commentID={$this->commentID}"; } else { $GLOBALS['log'] .= "<br/> Comment <span class='bad'>Failed</span> to insert to DB"; $GLOBALS['log'] .= "<br/> <span class='bad'> Error description: " . mysqli_error($this->conn) . "</span>"; } closeDBConnection($this->conn, $conn_NeedToClose); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
if (is_null($contact->con_created_date) || empty($contact->con_created_date)) { $contact->con_created_date = date("m/d/y"); } $contact->src_id = $_SESSION['username']; $contact->con_created_by = $_SESSION['username']; if (validateContact($contact)) { array_push($contacts, $contact); } else { $recordsInvalid = true; } } } if (!empty($contacts)) { $DBResource = getDBConnection(); insertData($DBResource, $contacts); closeDBConnection($DBResource); runMatching($contacts); if ($recordsInvalid) { echo "File uploaded successfully (discarding invalid data)"; } else { echo "File uploaded successfully."; } } else { echo "No records uploaded."; } // end of if loop } // end of else loop for success } else { echo "Invalid file type or size exceeds the limit"; }