function modulus($a, $b) { $error = errorCheck($a, $b); if ($error) { if ($a != 0 && $b != 0) { return $a % $b; } else { echo "ERROR: Cannot divide by 0\n"; } } }
function modulus($a, $b) { $noError = errorCheck($a, $b); if ($noError) { if ($a == 0 || $b == 0) { return "ERROR: cannot use zero as a variable" . PHP_EOL; } else { return $a % $b . PHP_EOL; } } }
function sendData() { global $return, $data_contact, $url_curl, $userpwd, $content, $to_error, $headers, $modify; /* Pass JSON to web server If the data is a new record use, Hobson requires the Post Method. If it is exisiting record, Hobson requires the Put Method */ $ch = curl_init($url_curl); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); if ($modify == 'True') { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($content))); //prep data for put by including content length } else { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); } curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); curl_setopt($ch, CURLOPT_TIMEOUT, 30); if ($modify == 'True') { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); } else { curl_setopt($ch, CURLOPT_POST, 1); } curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close($ch); var_dump($return); /* $ch = curl_init($url_curl); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close($ch); var_dump($return); */ errorCheck(); }
personalReport($csv, $roster); } else { echo '<h1>No class roster selected <a href=\'javascript:history.go(-1)\'>Return</a></h1>'; } break; case 'popStudents': if (isset($_POST['roster'])) { $roster = $_POST['roster']; popStudents($csv, $roster); } else { $output = ['success' => false, 'error' => 'No class roster selected']; echo json_encode($output); } break; case 'error': errorCheck($csv); break; case 'class list': getClassList($csv); break; default: echo 'No action chosen'; break; } } else { echo '<h2>No action chosen <a href=\'javascript:history.go(-1)\'>Return</a></h2>'; } } else { echo '<h2>No CSV data found <a href=\'javascript:history.go(-1)\'>Return</a></h2>'; } function buildArray($csv)
echo "<tr>"; for ($j = 0; $j < $maxmult1 - $minmult1 + 2; $j++) { echo "<td>"; if ($j == 0 & $i == 0) { echo "_"; } if ($j != 0 & $i == 0) { echo $minmult1 + $counter; $counter++; } if ($j != 0 & $i != 0) { echo ($minmult1 + $counter2) * ($mincand1 - 1 + $counter3); $counter2++; } if ($j == 0 & $i != 0) { echo $mincand1 + $counter1; $counter1++; } echo "</td>"; } $counter3++; echo "</tr>"; } echo "</table>"; } errorCheck($maxmult, $minmult, $maxcand, $mincand); ?> </body> </html>
function run() { set_include_path("../Composer/files/facebook/php-sdk-v4/facebook-facebook-php-sdk-v4-e2dc662"); include "autoload.php"; error_reporting(E_ALL); if (!isset($_SESSION["token"])) { header("Location:login.php"); } $err = errorCheck(); if ($err != "") { echo $err; return; } $tmp = new DateTime($_POST["todate"]); $date = $tmp->modify('+1 day'); //in the Facebook request, "until" is exclusive //Equivalent, if PHP>=5.4 is available: //$date=(new DateTime($_POST["todate"]))->modify('+1 day'); $_POST["todate"] = $date->format('Y-m-d'); FacebookSession::setDefaultApplication('777065655684035', '3648579cf4a413d1dfe490304456cd4c'); //app ID, app secret $session = new FacebookSession($_SESSION["token"]); $request = new FacebookRequest($session, 'GET', "/" . $_POST["group"] . "/feed?since=" . $_POST["fromdate"] . "&until=" . $_POST["todate"]); try { $response = $request->execute(); $graphObject = $response->getGraphObject(GraphUser::className()); $outcome = $graphObject->getProperty('data'); $temp = array(); while ($outcome) { $temp = array_merge($temp, $graphObject->getProperty('data')->asArray()); //merge array with the previous block $next = $graphObject->getProperty('paging')->asArray(); //get the link to the next results page $request = new FacebookRequest($session, 'GET', substr($next["next"], 31)); //request the next page $response = $request->execute(); $graphObject = $response->getGraphObject(GraphUser::className()); $outcome = $graphObject->getProperty('data'); $j = count($temp); for ($i = $j - 1; $i >= 0; $i--) { //going from less recent to more recent, cut out posts created too early if ($temp[$i]->created_time <= $_POST["fromdate"]) { $outcome = false; $j = $i; } } if ($outcome == false) { $temp = array_slice($temp, 0, $j); } //if anything has been cut, or the page is empty, move on } if ($_POST["members"] != "Everyone") { $j = 0; for ($i = 0; $i < count($temp); $i++) { if ($temp[$i]->from->name == $_POST["members"]) { $temp[$j] = $temp[$i]; $j++; } } $temp = array_slice($temp, 0, $j); } if (count($temp) == 0) { echo "There are no posts in this group matching the entered restrictions. <a href='initialization.php'>Return to the form.</a>"; return; } $cnt = count($temp); $truecount = min($_POST["count"], $cnt); //display the queried number of recent posts, but as many as truly exist $m = getMostRecent($temp); //only returns the index echo "<i>Most Recently Created Post by:</i> <b>" . htmlentities($temp[$m]->from->name) . "</b>"; echo "<i><br><br>Most Recent Post Created time:</i> <b>" . date_format(date_create_from_format('Y-m-d\\TH:i:sO', $temp[$m]->created_time), 'r') . "</b>"; echo "<i><br><br>Total Number of Posts:</i> <b> " . $cnt . "</b>"; echo "<i><br><br> Last " . $truecount . " Posts: <br></i>"; $arr = array(array()); for ($i = 0; $i < $cnt; $i++) { $arr[$i][0] = $temp[$i]->created_time; $arr[$i][1] = $i; } sort($arr); //sort the indexes of posts, from most to least recent for ($k = $truecount - 1; $k >= 0; $k--) { echo "<br>" . ($truecount - $k) . ". " . date_format(date_create_from_format('Y-m-d\\TH:i:sO', $arr[$k + $cnt - $truecount][0]), 'r') . "<br>"; if (property_exists($temp[$arr[$k + $cnt - $truecount][1]], "message")) { //not all posts have text, likes or comments echo "<p style='text-align:justify'>" . htmlentities($temp[$arr[$k + $cnt - $truecount][1]]->message) . " "; } if (property_exists($temp[$arr[$k + $cnt - $truecount][1]], "likes")) { echo "<b>(" . count($temp[$arr[$k + $cnt - $truecount][1]]->likes->data) . " <img src='like.png'>, "; } else { echo "<b>(0 <img src='like.png'>, "; } if (property_exists($temp[$arr[$k + $cnt - $truecount][1]], "comments")) { echo count($temp[$arr[$k + $cnt - $truecount][1]]->comments->data) . " <img src='comment.png'>) <ul>"; foreach ($temp[$arr[$k + $cnt - $truecount][1]]->comments->data as $i) { echo "<li>" . htmlentities($i->from->name) . ": "; echo "</b>" . htmlentities($i->message) . "<b></li>"; } echo "</b></ul>"; } else { echo "0 <img src='comment.png'>)</b><br>"; } } $p = getPosters($temp); $namecount = count($p); echo "<i><br><br>Unique Users:</i> <b> " . $namecount . " <br>("; for ($i = 0; $i < $namecount; $i++) { if ($i == $namecount - 1) { echo htmlentities($p[$i]) . ")</b>"; } else { echo htmlentities($p[$i]) . ", "; } } //Display entire feed, for debugging purposes: //var_dump($temp); echo "<br><p align='center'><a href='initialization.php'>Return to the form.</a>"; } catch (Exception $e) { echo "Caught exception: " . $e->getMessage() . "\n"; } }