function getActionData($entryid, $actioncode, $defaultamount, $typestring, $defaulttitle = "") { // query the database for matching actions $actiondata = callStoredProcedure("GetEntryActions(" . $entryid . ", '" . $actioncode . "')"); // for streaks and sprints $times = array(); // print them out in a readable format $liststring = ""; $graphstring = ""; $totalamount = 0; $count = 0; $sprintamount = 0; $lasttime = null; $currenttime = new DateTime(); while ($action = mysqli_fetch_array($actiondata)) { $count++; // HTML list stuff $datestring = date("d M Y", strtotime($action['Time'])); $titlestring = $action['TextData'] ? "<b>" . $action['TextData'] . "</b>" : "<i>" . $defaulttitle . "</i>"; // if we don't have a title, always show the amount $amountstring = $action['AmountData'] != $defaultamount || $titlestring == "<i></i>" ? " <i>" . $action['AmountData'] . " " . $typestring . "</i>" : ""; $liststring .= "<span class='listdate'>{$datestring}</span>\n <span class='listtitle'>{$titlestring}</span>\n <span class='listamount'>{$amountstring}</span><br>"; // streaks and sprints array_push($times, $action['Time']); // JAVASCRIPT graph stuff $thistime = strtotime($action['Time']); // if two entries have exactly the same time, bump one up/make it later $time = date("c", $lasttime == null || $lasttime != $thistime ? $thistime : ++$thistime); $lasttime = $thistime; $amount = $action['AmountData']; $title = $action['TextData'] ? $action['TextData'] : $defaulttitle; $graphstring .= "{'time': '{$time}', 'amount': {$amount}, 'title': \"{$title}\"},"; // activity during the last fortnight $datetime = new DateTime($action['Time']); if ($datetime->diff($currenttime)->days <= 14) { $sprintamount += $amount; } } $graphstring = substr_replace($graphstring, "", -1); // redefine action data and set the different parts $actiondata = array(); $actiondata['List'] = $liststring; $actiondata['Graph'] = $graphstring; $actiondata['Count'] = $count; $actiondata['Type'] = $typestring; $actiondata['Times'] = $times; $actiondata['Sprint'] = $sprintamount; return $actiondata; }
function processReportUpload() { // Build filepath $uploadfile = getcwd() . '/tmp/' . basename($_FILES['file']['name']); // If move from temp PHP directory == success, then true if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { // Check to see if this is a duplicate report $isDuplicate = getReportData(NULL, gps('report_name')); if ($isDuplicate) { unlink($uploadfile); // Put result in a encoded JSON return $out = array("result" => 'duplicate', "report_name" => $isDuplicate['report_name'], "description" => $isDuplicate['short_description'], "report_id" => $out['report_id']); return json_encode($out); } //// Start building query // Get the file as binary $report_data = file_get_contents($uploadfile); // Report Name - Used to check for duplicates $report_name = gps('report_name'); // Report Short Description $short_description = gps('short_description'); // New Report? $reportStatus = gps('reportNew'); // Author ID $aud = gps('report_author_id'); $report_owner_author_id = $aud; $report_the_user_id = $aud; // Scope of Data $report_type_id = gps('report_type_id'); // Scope of Data $report_scope_id = gps('report_scope_id'); // Publication Number $pid = gps('report_number'); // Filename $report_file_name = basename($_FILES['file']['name']); // Publication Date. Tenatively date of import. $report_publication_date = date("m-d-y"); // xx-xx-xxxx // report filesize $report_file_size = filesize($uploadfile); // set report ID to null if it is a new report, otherwise, use $stored_report_id //$report_id = ($reportStatus == 0) ? NULL : $reportStatus; // Build Parameters $spParams = array(array(NULL, 1), array(NULL, 1), array($report_owner_author_id, 1), array($report_id, 1), array($report_name, 1), array($short_description, 1), array($pid, 1), array($report_publication_date, 1), array(1, 1), array($report_type_id, 1), array('http://', 1), array(1, 1), array($report_file_size, 1), array($report_file_name, 1), array($report_file_name, 1), array('pdf', 1), array('application/pdf', 1), array(1, 1), array($report_data, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY)), array(1, 1), array($report_scope_id, 1), array($report_the_user_id, 1)); // call the procedure $result = callStoredProcedure(sqlsrvConnect(), 'Report_WyomingTobaccoEdit_SP', $spParams); // if JSON result TRUE if ($result['success']) { unlink($uploadfile); // Delete uploaded file as its now in DB // prepare JSON data pairs in to array $out = array("result" => 'success', "post_ID" => gps('post_ID'), "description" => gps('short_description'), "category" => gps('category'), "scope" => gps('sod'), "publication_number" => gps('pid'), "report_id" => $result['report_id'], "report_name" => $result['report_name']); // return array as json return json_encode($out); } else { $error = print_r($result, TRUE); // if anything else, return error $out = array("result" => "error" . $error); return json_encode($out); } } }
function printLanguages() { $count = 0; $languagedata = callStoredProcedure("GetLanguages()"); while ($info = mysqli_fetch_array($languagedata)) { $code = $info['Code']; $name = $info['Name']; print "<span class='languagecode'>" . $code . "</span>" . $name . "<br>"; // show the first three and then hide the rest if ($count++ == 2) { print "<div class='hideable' id='languages'>"; } } print "</div>"; }