function formatArray($par1, $par2 = 0, $par3 = false, $par4 = true) { if (is_array($par1)) { $v1 = ""; $v2 = ""; /*if (is_int($par2)) { for ($i=0; $i < $par2; $i++) { $v2 .= "\t"; }; };*/ if (!$par3) { foreach ($par1 as $key => $val) { if (is_array($val)) { $v1 .= $v2 . "{" . formatArray($val, $par2 + 1, $par3) . "},"; } else { $v1 .= $v2 . "\"" . $key . "\":\"" . $val . "\","; } } } else { if ($par4) { foreach ($par1 as $key => $val) { if (is_array($val)) { $v1 .= $v2 . "{" . formatArray($val, $par2 + 1, $par3) . "},"; } else { $v1 .= $v2 . "\"" . $key . "\":\"" . $val . "\","; } } } else { foreach ($par1 as $key => $val) { echo $key . " = " . $val; if (is_array($val)) { $v1 .= $v2 . "{" . formatArray($val, $par2 + 1) . "},"; } else { $v1 .= $v2 . "\"" . $key . "\":\"" . $val . "\","; } } } } $v1 = str_replace(',}', '}', $v1); $v1 = str_replace(',]', ']', $v1); return $v1; } else { return "ERROR: Array expected as \$par1, " . gettype($par1) . " given.\n"; } }
function updateEntry($link) { unset($_POST['btnUpdateEntry']); $queryString = array(); foreach ($_POST as $key => $value) { // sanitize values $value = sanitizeValues($value, $link); // format values if ($key == 'contact_phonenumber') { $value = formatPhoneNumber($value); } if ($key == 'event_tags' || $key == 'event_categories' || $key == 'open_to') { $value = formatArray($value); } if ($key == 'event_startdate') { $value = formatStartDate($value); } if ($key == 'event_enddate') { $value = formatEndDate($value); } // save values to session variables $_SESSION[$key] = ""; $_SESSION[$key] = $value; // set key name as variable, save value to this variable ${$key} = $value; //echo "$key - $value<br>"; // add key (element/column name) and value to queryString array $queryString[] = "{$key} = '{$value}'"; //var_dump($queryString); } // get string from elements of queryString array $implodedArray = implode(', ', $queryString); $query = "UPDATE tbl_entries SET {$implodedArray} WHERE id = {$_SESSION['event_id']}"; //print_r($query); $result = mysqli_query($link, $query) or trigger_error(mysqli_error()); return $result; mysqli_close($link); }
$startTime = strtotime($start); $startTime = date("g:i a", $startTime); $startDate = strtotime($start); $startDate = date("l, F j, Y", $startDate); $endTime = strtotime($end); $endTime = date("g:i a", $endTime); $endDate = strtotime($end); $endDate = date("l, F j, Y", $endDate); // compare event tag IDs with lists of names stored in arrays // if event has a tag ID, add the tag name to another array $tags = formatArray($tags); $depts = array(); $facs = array(); $categories = formatArray($categories); $cats = array(); $opentos = formatArray($opentos); $opens = array(); foreach ($tags as $tag) { if ($facList[$tag]) { $facs[] = $facList[$tag]; } if ($deptList[$tag]) { $depts[] = $deptList[$tag]; } } foreach ($categories as $category) { if ($catList[$category]) { $cats[] = $catList[$category]; } } foreach ($opentos as $opento) {
return $employees; } function getPaddedString($piece1, $piece2, $piece3) { $line = str_pad($piece1, 28) . str_pad($piece2, 50) . str_pad($piece3, 10) . PHP_EOL; return $line; } $contentsString = readLines('report.txt'); $rows = explode("\n", $contentsString); $reportName = array_shift($rows); $reportDate = array_shift($rows); $officeName = array_shift($rows); $rows = removeKruft($rows); // Remove the existing column header names from the output array_shift($rows); $employeesArray = formatArray($rows); $arrayOfSales = array_column($employeesArray, 'sales'); $arrayOfNames = array_column($employeesArray, 'name'); $arrayOfEmployeeNumbers = array_column($employeesArray, 'employee_number'); arsort($arrayOfSales); $employeeSalesOrder = array_keys($arrayOfSales); $totalSales = array_sum($arrayOfSales); foreach ($employeeSalesOrder as $order) { $employeesOrderedByProduction[] = getPaddedString($arrayOfSales[$order], $arrayOfNames[$order], $arrayOfEmployeeNumbers[$order]); } $numberOfEmployees = count($employeesOrderedByProduction); $avgSalesPerEmployee = $totalSales / $numberOfEmployees; echo getPaddedString($reportName, $officeName, $reportDate); echo getPaddedString("Total Units: " . $totalSales, "Number of Employees: {$numberOfEmployees}", "Average Units per employee: " . floor($avgSalesPerEmployee)); foreach ($employeesOrderedByProduction as $employee) { echo ' ' . $employee;
function PrintIncidentDetail($incidentId) { include 'dbConn.php'; try { // PHP PDO SQL Statement $sql = "SELECT * FROM incidentreporting.incident WHERE incident_id = :incidentId"; $stm = $dbh->prepare($sql); $stm->bindParam(':incidentId', $incidentId); $stm->execute(); // Fetch the results in a numbered array $getIncidents = $stm->fetchALL(PDO::FETCH_NUM); $print = ''; foreach ($getIncidents as $row) { $incidentLocationGeneric = json_decode($row[8], TRUE); $respondingOrganization = json_decode($row[11], TRUE); $print .= '<button type="button" class="btn btn-info printClose" style="margin:0px auto; position:relative; width:200px;">Close</button>'; $print .= "<div class='row' style='border:solid 1px #ccc;'>"; $print .= "<div class='col-sm-6'>"; $print .= "<h2>Submitter Information</h2>"; $print .= "<p>Name: " . $row[1] . "</p>"; $print .= "<p>Status: " . $row[2] . "</p>"; $print .= "<p>Phone number: " . $row[3] . "</p>"; $print .= "<p>E-mail address: " . $row[4] . "</p>"; $print .= "<p>Date submitted: " . $row[12] . "</p></div>"; $print .= "<div class='col-sm-6'>"; $print .= "<h2>Incident Details</h2>"; $print .= "<p>Priority:"; // show only Normal or Urgent if ($row[6] == 1) { $print .= " Urgent</p>"; } if ($row[6] == 0) { $print .= " Normal</p>"; } $print .= "<p>Date/Time of incident: " . $row[7] . "</p>"; $print .= "<p>Location (generic): " . formatArray($incidentLocationGeneric) . "</p>"; $print .= "<p>Location (specific): " . $row[9] . "</p>"; $print .= "<p>Public Safety response: "; // show only Yes or No if ($row[10] == 1) { $print .= " Yes</p>"; } if ($row[10] == 0) { $print .= " No</p>"; } $print .= "<p>Responding organization[s]: " . formatArray($respondingOrganization) . "</p></div>"; $print .= "<div class='col-sm-12'>"; $print .= "<h2>Incident description</h2>"; $print .= "<p>" . $row[5] . "</p></div></div>"; } // PHP PDO SQL Statement $sql2 = "SELECT * FROM incidentreporting.involved_parties WHERE incident_id = :incidentId"; $stmt = $dbh->prepare($sql2); $stmt->bindParam(':incidentId', $incidentId); $stmt->execute(); // Fetch the results in a numbered array $getParties = $stmt->fetchALL(PDO::FETCH_NUM); if ($getParties != FALSE) { $print .= "<div class='row' style='border:solid 1px #ccc;'>"; $print .= "<div class='col-sm-12'><h2>Involved Parties</h2></div>"; foreach ($getParties as $row) { $print .= "<div class='col-sm-6'>"; $print .= "<p>Name: " . $row[1] . "</p>"; $print .= "<p>Role: " . $row[2] . "</p>"; $print .= "<p>Gender: " . $row[3] . "</p>"; $print .= "<p>E-mail address: " . $row[4] . "</p>"; $print .= "<p>Phone Number: " . $row[5] . "</p>"; $print .= "<br /></div>"; } $print .= "</div>"; } echo $print; // Close the dbh connection $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die; } }
function ViewIncidentDetail($incidentId) { include 'dbConn.php'; try { // PHP PDO SQL Statement $sql = "SELECT * FROM incidentreporting.incident WHERE incident_id = :incidentId"; $stm = $dbh->prepare($sql); $stm->bindParam(':incidentId', $incidentId); $stm->execute(); // Fetch the results in a numbered array $getIncidents = $stm->fetchALL(PDO::FETCH_NUM); $modal = ''; foreach ($getIncidents as $row) { $incidentLocationGeneric = json_decode($row[8], TRUE); $respondingOrganization = json_decode($row[11], TRUE); $modal .= '<button id="' . $row[0] . '" type="button" class="btn btn-info printView">Print</button>'; $modal .= "<h2>Submitter Information</h2>"; $modal .= "<p><span class='label label-primary'>Name:</span> " . $row[1] . "</p>"; $modal .= "<p><span class='label label-primary'>Status:</span> " . $row[2] . "</p>"; $modal .= "<p><span class='label label-primary'>Phone number:</span> " . $row[3] . "</p>"; $modal .= "<p><span class='label label-primary'>E-mail address:</span> " . $row[4] . "</p>"; $modal .= "<p><span class='label label-primary'>Date submitted:</span> " . $row[12] . "</p><hr/>"; $modal .= "<h2>Incident Details</h2>"; $modal .= "<p><span class='label label-info'>Incident description:</span> " . $row[5] . "</p>"; $modal .= "<p><span class='label label-info'>Priority:</span>"; // show only Normal or Urgent if ($row[6] == 1) { $modal .= " Urgent</p>"; } if ($row[6] == 0) { $modal .= " Normal</p>"; } $modal .= "<p><span class='label label-info'>Date/Time of incident:</span> " . $row[7] . "</p>"; $modal .= "<p><span class='label label-info'>Location (generic):</span> " . formatArray($incidentLocationGeneric) . "</p>"; $modal .= "<p><span class='label label-info'>Location (specific):</span> " . $row[9] . "</p>"; $modal .= "<p><span class='label label-info'>Public Safety response:</span>"; // show only Yes or No if ($row[10] == 1) { $modal .= " Yes</p>"; } if ($row[10] == 0) { $modal .= " No</p>"; } $modal .= "<p><span class='label label-info'>Responding organization[s]:</span> " . formatArray($respondingOrganization) . "</p>"; } // PHP PDO SQL Statement $sql2 = "SELECT * FROM incidentreporting.involved_parties WHERE incident_id = :incidentId"; $stmt = $dbh->prepare($sql2); $stmt->bindParam(':incidentId', $incidentId); $stmt->execute(); // Fetch the results in a numbered array $getParties = $stmt->fetchALL(PDO::FETCH_NUM); if ($getParties != FALSE) { $modal .= "<hr/><h2>Involved Parties</h2>"; } foreach ($getParties as $row) { $modal .= "<p><span class='label label-default'>Name:</span> " . $row[1] . "</p>"; $modal .= "<p><span class='label label-default'>Role:</span> " . $row[2] . "</p>"; $modal .= "<p><span class='label label-default'>Gender:</span> " . $row[3] . "</p>"; $modal .= "<p><span class='label label-default'>E-mail address:</span> " . $row[4] . "</p>"; $modal .= "<p><span class='label label-default'>Phone Number:</span> " . $row[5] . "</p>"; $modal .= "<br />"; } echo $modal; // Close the dbh connection $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die; } }
} else { // 2.a. Process post values // - - - - - - - - - - - - - - - - - - - - - - - - - // create db query string array $queryString = array(); $queryStringRpt = array(); $weekdays = array(); foreach ($_POST as $key => $value) { // sanitize values $value = sanitizeValues($value, $link); // format values if ($key == 'contact_phonenumber') { $value = formatPhoneNumber($value); } if ($key == 'event_tags' || $key == 'event_categories' || $key == 'open_to') { $value = formatArray($value); } if ($key == 'event_startdate' && $value) { $value = formatStartDate($value); $queryStringRpt[] = $value; } if ($key == 'event_enddate' && $value) { $value = formatEndDate($value); $queryStringRpt[] = $value; } // save values to session variables $_SESSION[$key] = ""; $_SESSION[$key] = $value; // set key name as variable, save value to this variable ${$key} = $value; // INSERT INTO `event_calendar`.`rec_repeats` (`parent_id`, `repeat_startdate`, `repeat_enddate`, `repeat_day`, `repeat_freq`, `repeat_until`, `repeat_until_date`, `repeat_until_num`)
function renderDepts($link, $type, $checked) { if ($checked) { $checked = formatArray($checked); } if ($type == 'cat') { $tagQuery = "SELECT * FROM tbl_categories WHERE is_faculty = '0' AND is_category = '1' AND is_opento = '0'"; $result = mysqli_query($link, $tagQuery); $tagDisplay = ''; while ($row = mysqli_fetch_array($result)) { $departmentid = $row['id']; $department = $row['department']; $tagDisplay .= "<label for='dept_" . $departmentid . "'><input type='hidden' name='event_categories[]' value='0'><input type='checkbox' id='dept_" . $departmentid . "' name='event_categories[]' value='" . $departmentid . "' "; foreach ($checked as $check) { if ($check == $departmentid) { $tagDisplay .= "checked='checked'"; } } $tagDisplay .= " />" . $department . "</label>"; } } else { if ($type == 'fac') { $tagQuery = "SELECT * FROM tbl_categories WHERE is_faculty = '1' AND is_category = '0' AND is_opento = '0'"; $result = mysqli_query($link, $tagQuery); $tagDisplay = ''; while ($row = mysqli_fetch_array($result)) { $departmentid = $row['id']; $department = $row['department']; $tagDisplay .= "<label for='dept_" . $departmentid . "'><input type='hidden' name='event_tags[]' value='0'><input type='checkbox' id='dept_" . $departmentid . "' name='event_tags[]' value='" . $departmentid . "' "; foreach ($checked as $check) { if ($check == $departmentid) { $tagDisplay .= "checked='checked'"; } } $tagDisplay .= " />" . $department . "</label>"; } } else { if ($type == 'dept') { $tagQuery = "SELECT * FROM tbl_categories WHERE is_faculty = '0' AND is_category = '0' AND is_opento = '0'"; $result = mysqli_query($link, $tagQuery); $tagDisplay = ''; while ($row = mysqli_fetch_array($result)) { $departmentid = $row['id']; $department = $row['department']; $tagDisplay .= "<label for='dept_" . $departmentid . "'><input type='hidden' name='event_tags[]' value='0'><input type='checkbox' id='dept_" . $departmentid . "' name='event_tags[]' value='" . $departmentid . "' "; foreach ($checked as $check) { if ($check == $departmentid) { $tagDisplay .= "checked='checked'"; } } $tagDisplay .= " />" . $department . "</label>"; } } else { if ($type == 'open') { $tagQuery = "SELECT * FROM tbl_categories WHERE is_faculty = '0' AND is_category = '0' AND is_opento = '1'"; $result = mysqli_query($link, $tagQuery); $tagDisplay = ''; while ($row = mysqli_fetch_array($result)) { $departmentid = $row['id']; $department = $row['department']; $tagDisplay .= "<li><label for='opento_" . $departmentid . "'><input type='hidden' name='open_to[]' value='0'><input type='checkbox' id='opento_" . $departmentid . "' name='open_to[]' value='" . $departmentid . "' "; foreach ($checked as $check) { if ($check == $departmentid) { $tagDisplay .= "checked='checked'"; } } $tagDisplay .= " />" . $department . "</label></li>"; } } } } } echo $tagDisplay; }