From: Anthony Talarico Date: Fri, 21 Jul 2017 20:52:55 +0000 (-0400) Subject: add, edit, delete update functionality X-Git-Tag: v1.0.0^2~8 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=405fe292d09fa3381cfaab3c690c6a48b1aa2d7a;p=WP-Plugins%2Fglm-member-db-trailreports.git add, edit, delete update functionality adding the admin side of the plugin --- diff --git a/assets/calIcon.png b/assets/calIcon.png new file mode 100644 index 0000000..d50b0fc Binary files /dev/null and b/assets/calIcon.png differ diff --git a/classes/data/dataTrailReports.php b/classes/data/dataTrailReports.php index 057ea8e..c6b378c 100644 --- a/classes/data/dataTrailReports.php +++ b/classes/data/dataTrailReports.php @@ -83,7 +83,7 @@ class GlmDataTrailReports extends GlmDataAbstract * @access public */ public $fields = false; - + /** * Constructor * @@ -111,7 +111,7 @@ class GlmDataTrailReports extends GlmDataAbstract /* * Table Name */ - + $this->table = GLM_MEMBERS_TRAIL_REPORTS_PLUGIN_DB_PREFIX . 'reports'; // -- Conditions Table @@ -139,134 +139,134 @@ class GlmDataTrailReports extends GlmDataAbstract 'report_date' => array ( 'field' => 'report_date', 'type' => 'date', - 'default' => true, + 'default' => false, 'use' => 'a' ), 'report_notes' => array ( 'field' => 'report_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'big_bay_cond' => array ( 'field' => 'big_bay_cond', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'big_bay_groom' => array ( 'field' => 'big_bay_groom', 'type' => 'date', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'big_bay_base' => array ( 'field' => 'big_bay_base', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'big_bay_notes' => array ( 'field' => 'big_bay_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'alston_cond' => array ( 'field' => 'alston_cond', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'alston_groom' => array ( 'field' => 'alston_groom', 'type' => 'date', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'alston_base' => array ( 'field' => 'alston_base', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'alston_notes' => array ( 'field' => 'alston_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'nestoria_cond' => array ( 'field' => 'nestoria_cond', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'nestoria_groom' => array ( 'field' => 'nestoria_groom', 'type' => 'date', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'nestoria_base' => array ( 'field' => 'nestoria_base', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'nestoria_notes' => array ( 'field' => 'nestoria_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'chassell_cond' => array ( 'field' => 'chassell_cond', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'chassell_groom' => array ( 'field' => 'chassell_groom', 'type' => 'date', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'chassell_base' => array ( 'field' => 'chassell_base', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'chassell_notes' => array ( 'field' => 'chassell_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'pinery_base' => array ( 'field' => 'pinery_base', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'pinery_notes' => array ( 'field' => 'pinery_notes', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'pinery_groom' => array ( 'field' => 'pinery_groom', 'type' => 'date', - 'required' => true, + 'required' => false, 'use' => 'a' ), 'report_blurb' => array ( 'field' => 'report_blurb', 'type' => 'text', - 'required' => true, + 'required' => false, 'use' => 'a' ), diff --git a/css/admin.css b/css/admin.css new file mode 100644 index 0000000..dd6539d --- /dev/null +++ b/css/admin.css @@ -0,0 +1,23 @@ +#report-tabs{ + opacity: 0; + max-width: 725px; +} +.trail-notes{ + height: 100px; +} +.trail-conditions{ + margin-bottom: 20px; +} +.condition-label{ + margin-bottom: 5px; +} +.ui-datepicker-trigger{ + margin-left: 5px; + position: absolute; +} +.ui-tabs-panel .groom-date{ + margin-bottom: 20px; +} +.ui-tabs-panel .snow-base{ + margin-bottom: 20px; +} \ No newline at end of file diff --git a/models/admin/trailreports/index.php b/models/admin/trailreports/index.php index 2d7f9b0..ce608fd 100644 --- a/models/admin/trailreports/index.php +++ b/models/admin/trailreports/index.php @@ -34,27 +34,12 @@ class GlmMembersAdmin_trailreports_index extends GlmDataTrailReports */ public $config; /** - * Contact Info + * Report ID * - * @var $contactInfo + * @var $report ID * @access public */ - public $contactInfo = false; - /** - * Member ID - * - * @var $memberID - * @access public - */ - public $memberID = false; - /** - * Contact ID - * - * @var $contactID - * @access public - */ - public $contactID = false; - + public $report_id = false; /* * Constructor @@ -96,35 +81,135 @@ class GlmMembersAdmin_trailreports_index extends GlmDataTrailReports * Note, the third parameter is a flag that indicates to the Contacts * data class that it should flag a group of fields as 'view_only'. */ -// parent::__construct(false, false, true); + parent::__construct(false, false, true); } public function modelAction($actionData = false) { + if( ! wp_script_is( 'jquery-ui', 'enqueued' ) ){ + wp_enqueue_script('jquery-ui-datepicker', false, array('jquery'), false, true); + wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); + wp_enqueue_script("jquery-ui-tabs"); + } $success_message = ""; + $haveReport = false; $option = false; + $report = false; + $reportUpdated = false; + $reportUpdateError = false; + $reportAdded = false; + $reportAddError = false; + + if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { $option = $_REQUEST['option']; } - - $view_file = 'index'; + + // get the report id for use in the edit, add and delete options + $this->report_id = ( isset( $_REQUEST['report'] ) ? filter_var( $_REQUEST['report'], FILTER_SANITIZE_STRING) : ''); + + $trail_data = $this->getList(); + switch ($option) { - case "edit": + case 'add': + + $report = $this->newEntry(); $view_file = 'edit'; break; - + + case 'insert': + + $report = $this->insertEntry(); +// echo '
', print_r($report), '
'; + $this->report_id = $report['fieldData']['id']; + + if ($report['status']) { + $haveReport = true; + $reportAdded = true; + + // Update created timestamp and name slug for URLs + //$this->updateSlug($this->reportID); + + // Get this again so we have the created date + $report = $this->editEntry($this->report_id); + + $option = 'edit'; + $reportAdded = true; + + } else { + $option = 'add'; + $reportAddError = true; + } + + $view_file = 'edit'; + + break; + + case 'edit': + + + + $report = $this->editEntry($this->report_id); + + // If we have a good report + if ($report['status']) { + $haveReport = true; + } + + $view_file = 'edit'; + break; + + case 'update': + + // Try to update this report + $report = $this->updateEntry($this->report_id); + + // Check if that was successful + if ($report['status']) { + $reportUpdated = true; + + $report = $this->editEntry($this->report_id); + } else { + $reportUpdateError = true; + } + + $haveReport = true; + $view_file = 'edit'; + + break; + + case 'delete': + + $report = $this->deleteObit($this->report_id); + + if ($report) { + $reportDeleted = true; + } else { + $reportDeleteError = true; + } + break; default: - + $trail_data = $this->getList(); + $view_file = 'index'; break; } // Compile template data $templateData = array( - + 'trailData' => $trail_data, + 'haveReport' => $haveReport, + 'reportUpdated' => $reportUpdated, + 'reportUpdateError' => $reportUpdateError, + 'reportAdded' => $reportAdded, + 'reportAddError' => $reportAddError, + 'option' => $option, + 'report' => $report, + 'assetsUrl' => GLM_MEMBERS_TRAIL_REPORTS_PLUGIN_URL . 'assets/', + ); // Return status, any suggested view, and any data to controller diff --git a/models/admin/trailreports/list.php b/models/admin/trailreports/list.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/models/admin/trailreports/list.php @@ -0,0 +1,8 @@ +getList(); - $trails = $this->getList(); - print_r($trails); $view_file = 'index'; switch ($option) { @@ -128,7 +128,7 @@ class GlmMembersFront_trailreports_list extends GlmDataTrailReports // Compile template data $templateData = array( - + 'trailData' => $trail_data ); // Return status, any suggested view, and any data to controller diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index 1f988e7..d5814fb 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -14,28 +14,28 @@ -- Conditions Table CREATE TABLE {prefix}reports ( id INT NOT NULL AUTO_INCREMENT, - report_date DATE NULL, - report_notes TEXT NULL, - big_bay_cond TEXT NULL, - big_bay_groom DATE NULL, - big_bay_base TINYTEXT NULL, - big_bay_notes TEXT NULL, - alston_cond TEXT NULL, - alston_groom DATE NULL, - alston_base TINYTEXT NULL, - alston_notes TEXT NULL, - nestoria_cond TEXT NULL, - nestoria_groom DATE NULL, - nestoria_base TINYTEXT NULL, - nestoria_notes TEXT NULL, - chassell_cond TEXT NULL, - chassell_groom DATE NULL, - chassell_base TINYTEXT NULL, - chassell_notes TEXT NULL, - pinery_groom DATE NULL, - pinery_base TINYTEXT NULL, - pinery_notes TEXT NULL, - report_blurb TEXT NULL, + report_date DATE NOT NULL, + report_notes TEXT NOT NULL, + big_bay_cond TEXT NOT NULL, + big_bay_groom DATE NOT NULL, + big_bay_base TINYTEXT NOT NULL, + big_bay_notes TEXT NOT NULL, + alston_cond TEXT NOT NULL, + alston_groom DATE NOT NULL, + alston_base TINYTEXT NOT NULL, + alston_notes TEXT NOT NULL, + nestoria_cond TEXT NOT NULL, + nestoria_groom DATE NOT NULL, + nestoria_base TINYTEXT NOT NULL, + nestoria_notes TEXT NOT NULL, + chassell_cond TEXT NOT NULL, + chassell_groom DATE NOT NULL, + chassell_base TINYTEXT NOT NULL, + chassell_notes TEXT NOT NULL, + pinery_groom DATE NOT NULL, + pinery_base TINYTEXT NOT NULL, + pinery_notes TEXT NOT NULL, + report_blurb TEXT NOT NULL, PRIMARY KEY (id) ); @@ -43,4 +43,4 @@ CREATE TABLE {prefix}reports ( -- Trail Reports default entries in table INSERT INTO {prefix}reports ( id,report_date,report_notes,big_bay_cond,big_bay_groom,big_bay_base,big_bay_notes,alston_cond,alston_groom,alston_base,alston_notes,nestoria_cond,nestoria_groom,nestoria_base,nestoria_notes,chassell_cond,chassell_groom,chassell_base,chassell_notes,pinery_groom,pinery_base,pinery_notes,report_blurb) VALUES -(1,NOW(),'Trail Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'Notes','Grooming'); \ No newline at end of file +(1,NOW(),'Trail Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes','Fair',NOW(),'8"-12"','Notes',NOW(),'8"-12"','Notes','Grooming'); \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php index 02edcd4..7326e97 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,7 +60,8 @@ $glmMembersTrailReportsAddOnValidActions = array( 'adminActions' => array( 'trailreports' => array( - 'index' => GLM_MEMBERS_TRAIL_REPORTS_PLUGIN_SLUG + 'index' => GLM_MEMBERS_TRAIL_REPORTS_PLUGIN_SLUG, + 'list' => GLM_MEMBERS_TRAIL_REPORTS_PLUGIN_SLUG, ), ), 'frontActions' => array( diff --git a/views/admin/header.html b/views/admin/header.html new file mode 100644 index 0000000..4f7785f --- /dev/null +++ b/views/admin/header.html @@ -0,0 +1,8 @@ +
+

Trail Report

+ +
+ + diff --git a/views/admin/trailreports/edit.html b/views/admin/trailreports/edit.html new file mode 100644 index 0000000..f0c5ab2 --- /dev/null +++ b/views/admin/trailreports/edit.html @@ -0,0 +1,142 @@ +{include file='admin/header.html'} + +{if ($option == 'add' || $haveReport)} + + Return to Reports List + + {if $option == 'edit' || $option == 'update'} + Delete this Report +

Edit Trail Report + {else} +

Add New Trail Report + {/if} +     + {if $reportUpdated}Obit Updated{/if} + {if $reportUpdateError}Obit Update Error{/if} + {if $reportAdded}Obit Added{/if} + {if $reportAddError}Obit Add Error{/if} +

+ + {if $reportUpdateError || $reportAddError} +

NOTICE: Your report has not yet been submitted.
Please select the tabs indicating a problem, correct the indicated fields and resubmit.

+ {else} + {/if} + +
+ + + {if $haveReport} + + + {else} + + {/if} + + + + + + + + + + + + + + + + +
Report Date: + + {if $report.fieldFail.report_date.date}

{$report.fieldFail.report_date.date}

{/if}
+
Report Blurb: + + {if $report.fieldFail.report_blurb}

{$report.fieldFail.report_blurb}

{/if}
+
Report Notes: + + {if $report.fieldFail.report_notes}

{$report.fieldFail.report_notes}

{/if}
+
+
+ + {include file='admin/trailreports/parts/bigBay.html'} + {include file='admin/trailreports/parts/alston.html'} + {include file='admin/trailreports/parts/nestoria.html'} + {include file='admin/trailreports/parts/chassell.html'} + {include file='admin/trailreports/parts/pinery.html'} +
+ +
+ +{else} + +

Sorry, no report found or permission not granted.

+ +{/if} + + + +
+
+

Cancel

+

+
+
+

WARNING:

+

+ Clicking the "Delete this Obit" button above will + delete all of the data and images associated with this report. + +

+

+ + Once deleted, this information will no longer be available and cannot be retrieved! + If you are unsure that you want to completely remove this data, consider changing the status + of this report to "Archived" instead. + +

+
+
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/trailreports/index.html b/views/admin/trailreports/index.html index e69de29..a82dad3 100644 --- a/views/admin/trailreports/index.html +++ b/views/admin/trailreports/index.html @@ -0,0 +1,38 @@ +{include file='admin/header.html'} + + + + + + + + +
 
New Report
+ {if $trailData} + + + + + + + + {foreach $trailData as $record=>$data} + + + + + + + {/foreach} +
Report DateReport BlurbReport Notes
{$data.report_date.date}{$data.report_blurb}{$data.report_notes}EditDelete
+ + + {else if} +
No Trail Information
+ {/if} +{include file='admin/footer.html'} + diff --git a/views/admin/trailreports/parts/alston.html b/views/admin/trailreports/parts/alston.html new file mode 100644 index 0000000..50589c5 --- /dev/null +++ b/views/admin/trailreports/parts/alston.html @@ -0,0 +1,16 @@ +
+
+ {$a_con = $report.fieldData.alston_cond} +
Conditions
+ Poor + Fair + Good + Very Good +
+
Date Groomed
+ +
Snow Base
+ +
Trail Notes
+ +
\ No newline at end of file diff --git a/views/admin/trailreports/parts/bigBay.html b/views/admin/trailreports/parts/bigBay.html new file mode 100644 index 0000000..17170b3 --- /dev/null +++ b/views/admin/trailreports/parts/bigBay.html @@ -0,0 +1,16 @@ +
+
+
Conditions
+ {$b_con = $report.fieldData.big_bay_cond} + Poor + Fair + Good + Very Good +
+
Date Groomed
+ +
Snow Base
+ +
Trail Notes
+ +
\ No newline at end of file diff --git a/views/admin/trailreports/parts/chassell.html b/views/admin/trailreports/parts/chassell.html new file mode 100644 index 0000000..b5f7fde --- /dev/null +++ b/views/admin/trailreports/parts/chassell.html @@ -0,0 +1,16 @@ +
+
+ {$c_con = $report.fieldData.chassell_cond} +
Conditions
+ Poor + Fair + Good + Very Good +
+
Date Groomed
+ +
Snow Base
+ +
Trail Notes
+ +
\ No newline at end of file diff --git a/views/admin/trailreports/parts/nestoria.html b/views/admin/trailreports/parts/nestoria.html new file mode 100644 index 0000000..ea095d2 --- /dev/null +++ b/views/admin/trailreports/parts/nestoria.html @@ -0,0 +1,16 @@ +
+
+
Conditions
+ {$n_con = $report.fieldData.nestoria_cond} + Poor + Fair + Good + Very Good +
+
Date Groomed
+ +
Snow Base
+ +
Trail Notes
+ +
\ No newline at end of file diff --git a/views/admin/trailreports/parts/pinery.html b/views/admin/trailreports/parts/pinery.html new file mode 100644 index 0000000..789904d --- /dev/null +++ b/views/admin/trailreports/parts/pinery.html @@ -0,0 +1,16 @@ +
+ +
Date Groomed
+ +
Snow Base
+ +
Trail Notes
+ +
\ No newline at end of file