function message_len() { global $id; $ex = new Exchange(array("action" => "get", "id" => $id)); $ex_inf = $ex->run(); $conv = json_decode($ex_inf[0]["messages"], true); $conv_d = is_array($conv) ? $conv : array(); return count($conv_d); }
<?php include_once $_SERVER["DOC_ROOT"] . "/scripts/php/core.php"; if (!isset($_SESSION["userid"])) { die; } ?> <a href="#postbox" class="icon uk-icon-plus" data-uk-modal></a> <?php $my_exchanges = new Exchange(array("action" => "find")); $exchange_array = $my_exchanges->run(); ?> <div onclick="display_menu('#exchange_menu', this);" id="exchange_icon" class="<?php if (count($exchange_array) != 0) { ?> static_active <?php } ?> icon uk-icon-exchange"> <?php if (count($exchange_array) != 0) { ?> <div class="badge" onclick="display_menu('#exchange_menu', this);"><?php echo count($exchange_array); ?> </div> <?php } ?>
// 4) Rating widget include_once $_SERVER["DOC_ROOT"] . "/scripts/php/widget/exchange/rater.php"; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ //Connect to MySQL for our non-API related queries $con = mysqli_connect(host(), username(), password(), mainDb()); //Will remove if (!isset($_SESSION)) { session_start(); } //Resume the session // $oid = $_GET["offerid"]; //Retrieve the offer ID $currentExchange = new Exchange(array("action" => "get", "id" => $oid)); //Get info about the exchange $getExchange = $currentExchange->run(); //Read the info into an array //If no info can be found about the exchange... if (!is_array($getExchange) || count($getExchange) == 0) { header("Location: /notfound.php"); //...go to a not found page exit; //Exit } //who_ranked keeps info about who has ranked the other thus far. It is stored in an array in the database. //If the array is null, then just make it empty. If it isn't, store it in the variable. $who_ranked = is_array(json_decode($getExchange[0]["who_ranked"], true)) ? json_decode($getExchange[0]["who_ranked"], true) : array(); //If the user has already ranked the other user, the exchange (for them) is over //Take them to a "special page" if (in_array($_SESSION["userid"], $who_ranked)) { include_once $_SERVER["DOC_ROOT"] . "/gameover.php";
if (isset($_SESSION["userid"])) { //Get items available for offer $user_itemReq = new Item(array("action" => "get", "filter" => array("usr" => $_SESSION["userid"], "status" => "1"))); $user_items = $user_itemReq->run(); } //Store the owner's privacy settings in an array $privacy = is_array(json_decode($userGet[0]["privacy"], true)) ? json_decode($userGet[0]["privacy"], true) : array(); //Get the join date of the user $jdate = $userGet[0]["join_date"]; //Get the full page URL $full_url = urlencode("https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); /* * * ACCEPTING AN ITEM * * */ if (isset($_POST["accept"]) && trim($_POST["accept"]) != "") { //Create a new exchange $acceptExchange = new Exchange(array("action" => "create", "item1" => $_GET["itemid"], "item2" => $_POST["accept"])); $acceptExchange->run(); //Redirect to the new exchange page header("Location: /" . $url); exit; } /* * * WITHDRAWING AN ITEM * * */ if (isset($_POST["withdraw"]) && trim($_POST["withdraw"]) != "") { //Get info about the withdrawl item $wdRequest = new Item(array("action" => "get", "filter" => array("id" => $_POST["withdraw"]))); $wdInfo = $wdRequest->run(true); //If the user doesn't own this item if ($wdInfo[0]["usr"] != $_SESSION["userid"]) { //Just refresh the page header("Location: /" . $url); exit; } else {
break; case "login": $library = new Login($_GET); $return = $library->run(); break; case "listener": $library = new Listener($_GET); $return = $library->listen(); break; case "messenger": $library = new Messenger($_GET); $return = $library->run(); break; case "exchange": $library = new Exchange($_GET); $return = $library->run(); break; case "feed": $library = new Feed($_GET); $return = $library->run(); break; default: $return = 405; break; } header('Content-type: text/html; charset=UTF-8'); //If the return value isn't still null if ($return) { if (is_array($return)) { echo json_encode($return); //Return the JSON data
function output() { global $id; //Initialize output html and write header to variable $html = <<<WAT \t\t<div class="hdr btxt">Meeting Date</div> \t\t<div class="head">When are you free?</div> WAT; //Initialize empty set of day columns for the table $days = ""; for ($x = 1; $x <= 7; $x++) { $day_of_week = date("l", strtotime("+" . $x . " day")); //Calculate the day of week $date = date("n/j", strtotime("+" . $x . " day")); //Calculate the date $days .= "<td>{$day_of_week}<span>{$date}</span></td>"; //Write html and append to the master date header } //Initialize empty set of time cells $times = ""; //Get the information for this exchange $thisExchange = new Exchange(array("action" => "get", "id" => $id)); $exchangeInfo = $thisExchange->run(); //Decode the available dates between users $availableArray = json_decode($exchangeInfo[0]["availability"], true); //If there is no date array currently on the server... if (!is_array($availableArray)) { $availableArray = array(); //Initialize an empty arreay } //Loop through the next 13 hours, starting at 9 AM for ($i = 9; $i < 22; $i++) { $class = $i % 2 == 0 ? "odd" : "even"; //Allows for alternating row colors $time_str = date("g A", strtotime($i . ":00")); //Calculate a 12-hour time string based on index //Begin html for each row, beginning with a time header $times .= <<<EOF \t\t\t\t\t\t<tr class="{$class}"> \t\t\t\t\t\t\t<td class="time_hcell">{$time_str}</td> EOF; //Loop through the next seven days (again) per row for ($j = 1; $j <= 7; $j++) { //Generate a string in the form Y-m-d H:i:s using the given date/time information $calculated_timestring = date("Y-m-d", strtotime("+" . $j . "day")) . " " . date("H:i:s", strtotime($i . ":00")); //Generate a timestamp from that string $calculated_timestamp = strtotime($calculated_timestring); $cell_class = ""; //By default, the cell will have no additional classes $visited_dates = array(); //An array of dates that the iterator has gone through foreach ($availableArray as $user => $dates) { foreach ($dates as $d) { if ($d == $exchangeInfo[0]["date"]) { $cell_class = "selected"; //...select it } else { if ($d == $calculated_timestamp) { //Make it bright if it belongs to the current user, //and dull if it belongs to the other user $cell_class = $user == $_SESSION["userid"] ? "bright" : "faded"; } } } } $dt_cell = "<td data-timestamp=\"{$calculated_timestamp}\" class=\"timecell {$cell_class}\"></td>"; //Write an html string for the cell $times .= $dt_cell; //Append it to the times row } $times .= "</tr>"; //End the times row } //Finish writing the HTML $html .= <<<EOD \t\t\t\t<table class="btxt" style="font-size:12px;border-spacing:0px;"> \t\t\t\t\t<tr style="text-align:center;"> \t\t\t\t\t\t<td></td> \t\t\t\t\t\t{$days} \t\t\t\t\t</tr> \t\t\t\t\t{$times} \t\t\t\t</table> \t\t\t\t<script> \t\t\t\t</script> EOD; echo $html; //Output the HTML return; //Return null }