Skip to content

Commit

Permalink
Admin Tools Refined & Debugged
Browse files Browse the repository at this point in the history
Also testing transition to Laravel 7.
  • Loading branch information
rockhopsoft committed May 9, 2020
1 parent da5aeed commit 23fdd48
Show file tree
Hide file tree
Showing 43 changed files with 1,560 additions and 942 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# FlexYourRights/OpenPolice

[![Laravel](https://img.shields.io/badge/Laravel-5.8-orange.svg?style=flat-square)](http://laravel.com)
[![Laravel](https://img.shields.io/badge/Laravel-7.6-orange.svg?style=flat-square)](http://laravel.com)
[![SurvLoop](https://img.shields.io/badge/SurvLoop-0.2-orange.svg?style=flat-square)](https://github.com/rockhopsoft/survloop)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Expand Down Expand Up @@ -53,8 +53,8 @@ XML included an automatically generated schema, eg.<br />
# <a name="requirements"></a>Requirements

* php: >=7.2
* <a href="https://packagist.org/packages/laravel/laravel" target="_blank">laravel/laravel</a>: 5.8.*
* <a href="https://packagist.org/packages/rockhopsoft/survloop" target="_blank">rockhopsoft/survloop</a>: >=0.2.13
* <a href="https://packagist.org/packages/laravel/laravel" target="_blank">laravel/laravel</a>: 7.6.*
* <a href="https://packagist.org/packages/rockhopsoft/survloop" target="_blank">rockhopsoft/survloop</a>: >=0.2.14
* <a href="https://packagist.org/packages/flexyourrights/openpolice-departments" target="_blank">flexyourrights/openpolice-departments</a>: 0.1.*
* <a href="https://packagist.org/packages/flexyourrights/openpolice-website" target="_blank">flexyourrights/openpolice-website</a>: 0.1.*

Expand All @@ -66,7 +66,7 @@ XML included an automatically generated schema, eg.<br />

### Install Laravel Using Composer
```
$ composer create-project laravel/laravel openpolice "5.8.*"
$ composer create-project laravel/laravel openpolice "7.6.*"
$ cd openpolice
```
Expand Down Expand Up @@ -97,8 +97,8 @@ $ nano composer.json
...
"require": {
...
"rockhopsoft/survloop": "^0.2.13",
"flexyourrights/openpolice": "^0.2.13",
"rockhopsoft/survloop": "^0.2.14",
"flexyourrights/openpolice": "^0.2.14",
...
},
...
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"rockhopsoft/survloop": "^v0.2.13",
"rockhopsoft/survloop": "^v0.2.14",
"flexyourrights/openpolice-departments": "^v0.1.2",
"flexyourrights/openpolice-website": "^v0.1.1"
},
Expand Down
10 changes: 10 additions & 0 deletions src/Controllers/DepartmentScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ public function recalcAllDepts()
$this->stats[$type]++;
}
}
if (isset($this->deptOvers[$dept->dept_id]->over_email)
&& trim($this->deptOvers[$dept->dept_id]->over_email) != ''
&& isset($this->deptOvers[$dept->dept_id]->over_way_sub_email)
&& intVal($this->deptOvers[$dept->dept_id]->over_way_sub_email) == 1
&& isset($this->deptOvers[$dept->dept_id]->over_official_form_not_req)
&& intVal($this->deptOvers[$dept->dept_id]->over_official_form_not_req) == 1) {
$this->scoreDepts[$i]->dept_op_compliant = 1;
} else {
$this->scoreDepts[$i]->dept_op_compliant = 0;
}
$this->scoreDepts[$i]->save();
$this->stats["score"] += $this->scoreDepts[$i]->dept_score_openness;
$this->stats["count"]++;
Expand Down
70 changes: 38 additions & 32 deletions src/Controllers/OpenComplaintConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,18 @@ protected function condPrintAnonOnly($complaint)
*/
protected function condPrintIncidentLocation()
{
if ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
if (!$GLOBALS["SL"]->REQ->has('publicView')) {
return 1;
}
}
if (isset($this->sessData->dataSets["incidents"])
&& isset($this->sessData->dataSets["incidents"][0])
&& isset($this->sessData->dataSets["incidents"][0]->inc_public)
&& intVal($this->sessData->dataSets["incidents"][0]->inc_public) == 1) {
return 1;
}
if ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
if (!$GLOBALS["SL"]->REQ->has('publicView')) {
return 1;
}
}
return 0;
}

Expand All @@ -587,23 +587,7 @@ protected function condPrintIncidentLocation()
*/
protected function condPrintCivilianName()
{
if ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
if (!$GLOBALS["SL"]->REQ->has('publicView')) {
return 1;
}
}
if ($this->currCivIsCreator()
&& isset($this->sessData->dataSets["complaints"])
&& isset($this->sessData->dataSets["complaints"][0])) {
$com = $this->sessData->dataSets["complaints"][0];
if (isset($com->com_publish_user_name)
&& intVal($com->com_publish_user_name) == 1
&& in_array($com->com_status, [200, 201, 203, 204])) {
return 1;
}
}
return 0;
return $this->condPrintName('user');
}

/**
Expand All @@ -614,21 +598,38 @@ protected function condPrintCivilianName()
*/
protected function condPrintOfficerName()
{
if ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
if (!$GLOBALS["SL"]->REQ->has('publicView')) {
return 1;
}
}
return $this->condPrintName('officer');
}

/**
* Checks whether or not the current Officer or Civilian
* name should be printed for the current page load.
*
* @return int
*/
protected function condPrintName($type = 'user')
{
if (isset($this->sessData->dataSets["complaints"])
&& isset($this->sessData->dataSets["complaints"][0])) {
$com = $this->sessData->dataSets["complaints"][0];
if (isset($com->com_publish_officer_name)
&& intVal($com->com_publish_officer_name) == 1
if ($GLOBALS["SL"]->REQ->has('publicView')) {
if (!isset($com->{ 'com_publish_' . $type . '_name' })
|| intVal($com->{ 'com_publish_' . $type . '_name' }) == 0) {
return 0;
} elseif ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
return 1;
}
} elseif (isset($com->{ 'com_publish_' . $type . '_name' })
&& intVal($com->{ 'com_publish_' . $type . '_name' }) == 1
&& in_array($com->com_status, [200, 201, 203, 204])) {
return 1;
}
}
if ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"])) {
return 1;
}
return 0;
}

Expand All @@ -641,7 +642,12 @@ protected function condPrintOfficerName()
protected function condPrintFullReport()
{
if ($this->canPrintFullReport()) {
if (!$GLOBALS["SL"]->REQ->has('publicView')) {
return 1;
}
if ($GLOBALS["SL"]->REQ->has('publicView')) {
if ($this->canPrintFullReportByRecSettings()
&& ((isset($this->v["isAdmin"]) && $this->v["isAdmin"])
|| (isset($this->v["isOwner"]) && $this->v["isOwner"]))) {
return 1;
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/Controllers/OpenComplaintEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,16 @@ protected function swapBlurbsDynamo($emailBody, $dy, $deptID)
$this->coreID,
$deptUser->id
);
$swap = $url . '/complaint/read-' . $this->corePublicID . '/full/t-' . $token;
$swap = $url . '/complaint/read-'
. $this->corePublicID . '/full/t-' . $token;
}
$swap = '<a href="' . $swap . '" target="_blank">' . $swap . '</a>';
break;
case '[{ Oversight Complaint Secure MFA }]':
$deptUser = $this->getDeptUser($deptID);
if (!isset($deptUser->id)) {
$swap = '<span style="color: red;">* DEPARTMENT IS NOT OPENPOLICE-COMPATIBLE *</span>';
$swap = '<span style="color: red;">* '
. 'DEPARTMENT IS NOT OPENPOLICE-COMPATIBLE *</span>';
} else {
$swap = $this->createToken(
'MFA',
Expand Down Expand Up @@ -626,19 +628,22 @@ public function prepEmailComDataRow($deptRow, $cnt)
}
}
$this->v["comDepts"][$cnt]["overDates"]
= OPLinksComplaintOversight::where('lnk_com_over_complaint_id', $this->coreID)
= OPLinksComplaintOversight::where(
'lnk_com_over_complaint_id', $this->coreID)
->where('lnk_com_over_dept_id', $deptRow->dept_id)
->where('lnk_com_over_over_id', $this->v["comDepts"][0][$w]->over_id)
//->where('lnk_com_over_over_id', $this->v["comDepts"][0][$w]->over_id)
->first();
/*
if (!$this->v["comDepts"][$cnt]["overDates"]
|| !isset($this->v["comDepts"][$cnt]["overDates"]->lnk_com_over_id)) {
|| !isset($this->v["comDepts"][$cnt]["overDates"]->lnk_com_dept_id)) {
$lnk = new OPLinksComplaintOversight;
$lnk->lnk_com_over_complaint_id = $this->coreID;
$lnk->lnk_com_over_dept_id = $deptRow->dept_id;
$lnk->lnk_com_over_over_id = $this->v["comDepts"][0][$w]->over_id;
$this->v["comDepts"][$cnt]["overDates"] = $lnk;
$this->v["comDepts"][$cnt]["overDates"]->save();
}
*/
return true;
}

Expand Down
8 changes: 7 additions & 1 deletion src/Controllers/OpenComplaintPrints.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected function customLabels($nIDtxt = '', $str = '')
}
if (strpos($str, '[ForceType]') !== false) {
$row = $this->sessData->getLatestDataBranchRow();
//echo 'customLabels(' . $nIDtxt . ', row: <pre>'; print_r($row); echo '</pre>'; exit;
$forceDesc = $GLOBALS["SL"]->def->getVal('Force Type', $row->for_type);
if ($forceDesc == 'Other') {
$forceDesc = $row->for_type_other;
Expand Down Expand Up @@ -349,8 +350,13 @@ protected function getReportUploads($nID)
$cnt = $this->v["uploadPrintMap"]["img"]
+$this->v["uploadPrintMap"]["vid"]
+$this->v["uploadPrintMap"]["fil"];
$GLOBALS["SL"]->pageAJAX .= ' setTimeout(function() { '
. 'document.getElementById("uploadDelayed").innerHTML="' . $GLOBALS["SL"]->addSlashLines($ret)
. '"; }, 1500); ';
return '<h3 class="mT0 slBlueDark">'
. (($cnt > 1) ? 'Uploads' : 'Upload') . '</h3>' . $ret;
. (($cnt > 1) ? 'Uploads' : 'Upload') . '</h3>'
. '<div id="uploadDelayed" class="w100"><div class="w100 taC">'
. $GLOBALS["SL"]->sysOpts["spinner-code"] . '</div></div>';
}

/* Double-Checking [For Now] */
Expand Down
4 changes: 4 additions & 0 deletions src/Controllers/OpenComplaintSaves.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ protected function saveForceTypes($nID)
}
}
}
// This delete may just be needed for older complaints:
OPForce::where('for_com_id', $this->coreID)
->whereNull('for_type')
->delete();
if ($nID == 743) {
$this->sessData->refreshDataSets();
return false;
Expand Down
63 changes: 52 additions & 11 deletions src/Controllers/OpenDashAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function printDashTopLevStats()
->count();
$chk = OPComplaints::select('com_id', 'com_public_id', 'com_status', 'com_record_submitted')
->where('com_status', '>', 0)
->whereNotNull('com_summary')
->where('com_summary', 'NOT LIKE', '')
->whereIn('com_type', [
$GLOBALS["SL"]->def->getID('Complaint Type', 'Police Complaint'),
$GLOBALS["SL"]->def->getID('Complaint Type', 'Unreviewed'),
Expand Down Expand Up @@ -148,12 +150,15 @@ public function printDashTopLevStats()
public function printDashSessGraph()
{
$this->v["isDash"] = true;
$grapher = new SurvTrends('' . rand(1000000, 10000000) . '');
$grapher = new SurvTrends('' . rand(1000000, 10000000) . '', '', 28);
$grapher->addDataLineType('complete', 'Complete', '', '#29B76F', '#29B76F');
$grapher->addDataLineType('incomplete', 'Incomplete', '', '#F0AD4E', '#F0AD4E');
$grapher->addDataLineType('incomplete', 'Incomplete', '', '#EC2327', '#EC2327');
$grapher->addDataLineType('submitted', 'Submitted to Oversight', '', '#2B3493', '#2B3493');
$grapher->addDataLineType('received', 'Received by Oversight', '', '#333333', '#333333');
$grapher->addDataLineType('contacts', 'Followup Contacts', '', '#63C6FF', '#63C6FF');
$grapher->addDataLineType('received', 'Received by Oversight', '', '#63C6FF', '#63C6FF');
$grapher->addDataLineType('contacts', 'Staff Emails', '', '#416CBD', '#416CBD');
$grapher->addDataLineType('notes', 'Staff Notes', '', '#333333', '#333333');
$grapher->addDataLineType('owners', 'User Followups', '', '#F0AD4E', '#F0AD4E');
$grapher->addDataLineType('oversights', 'Oversight Followups', '', '#EB9316', '#EB9316');
$startDate = $grapher->getPastStartDate() . ' 00:00:00';
$recentAttempts = OPComplaints::whereNotNull('com_summary')
->where('com_summary', 'NOT LIKE', '')
Expand Down Expand Up @@ -190,19 +195,53 @@ public function printDashSessGraph()
$grapher->addDayTally('received', $rec->lnk_com_over_received);
}
}
$contacts = DB::table('op_z_complaint_reviews')
->where('com_rev_type', 'LIKE', 'Update')
->whereNotNull('com_rev_note')
->where('com_rev_note', 'NOT LIKE', 'Update')
$contacts = DB::table('sl_emailed')
->where('emailed_tree', 1)
->whereNotNull('emailed_body')
->whereIn('emailed_tree', [1, 42])
->whereNotIn('emailed_email_id', [1, 5, 28])
->where('created_at', '>=', $startDate)
->distinct('com_rev_complaint')
->distinct('emailed_rec_id')
->get();
if ($contacts->isNotEmpty()) {
foreach ($contacts as $i => $rec) {
$grapher->addDayTally('contacts', $rec->created_at);
}
}

$notes = DB::table('op_z_complaint_reviews')
->where('com_rev_type', 'LIKE', 'Update')
->whereNotNull('com_rev_note')
->whereIn('com_rev_note', ['Update', 'First'])
->where('created_at', '>=', $startDate)
->distinct('com_rev_complaint')
->get();
if ($notes->isNotEmpty()) {
foreach ($notes as $i => $rec) {
$grapher->addDayTally('notes', $rec->created_at);
}
}
$notes = DB::table('op_z_complaint_reviews')
->where('com_rev_type', 'LIKE', 'Owner')
->where('created_at', '>=', $startDate)
->distinct('com_rev_complaint')
->get();
if ($notes->isNotEmpty()) {
foreach ($notes as $i => $rec) {
$grapher->addDayTally('owners', $rec->created_at);
}
}
$notes = DB::table('op_z_complaint_reviews')
->where('com_rev_type', 'LIKE', 'Oversight')
->where('created_at', '>=', $startDate)
->distinct('com_rev_complaint')
->get();
if ($notes->isNotEmpty()) {
foreach ($notes as $i => $rec) {
$grapher->addDayTally('oversights', $rec->created_at);
}
}

return '<div id="dailyGraphWrap">'
. $grapher->printDailyGraph(420) . '</div>';
}
Expand Down Expand Up @@ -244,6 +283,8 @@ public function printDashTopStats()
}
$chk = OPComplaints::select('com_id', 'com_public_id', 'com_status', 'com_record_submitted')
->where('com_status', '>', 0)
->whereNotNull('com_summary')
->where('com_summary', 'NOT LIKE', '')
->whereIn('com_type', [
$GLOBALS["SL"]->def->getID('Complaint Type', 'Police Complaint'),
$GLOBALS["SL"]->def->getID('Complaint Type', 'Unreviewed'),
Expand Down Expand Up @@ -385,7 +426,7 @@ public function volunStatsDailyGraph()
$this->volunDeptsRecent();
}
$this->recalcVolunStats();
$grapher = new SurvTrends('1349', 'volun_stat_date');
$grapher = new SurvTrends('1349', 'volun_stat_date', 28);
$grapher->addDataLineType('depts', 'Unique Depts', 'volun_stat_depts_unique', '#2b3493', '#2b3493');
$grapher->addDataLineType('users', 'Unique Users', 'volun_stat_users_unique', '#63c6ff', '#63c6ff');
$grapher->addDataLineType('edits', 'Total Edits', 'volun_stat_total_edits', '#c3ffe1', '#c3ffe1');
Expand Down Expand Up @@ -428,7 +469,7 @@ public function volunStatsInitDay()

public function recalcVolunStats()
{
$past = 100;
$past = 35;
$startDate = date("Y-m-d", mktime(0, 0, 0, date("n"), date("j")-$past, date("Y")));
$days = [];
for ($i = 0; $i < $past; $i++) {
Expand Down
Loading

0 comments on commit 23fdd48

Please sign in to comment.