From: Steve Sutton Date: Thu, 17 Nov 2016 18:17:31 +0000 (-0500) Subject: Update db tables. X-Git-Tag: v1.0.0^2~27 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=05f93516ed94d7b1e3d35c1385ed841e4d28fc4c;p=WP-Plugins%2Fglm-member-db-coupons.git Update db tables. Had some defines not setup correctly for the table name prefixes. Updated the database now to have a table for the coupon to category relationship (many to many). WIP on the edit coupon page. --- diff --git a/classes/data/dataCoupons.php b/classes/data/dataCoupons.php index 2cf4d77..b7637cf 100644 --- a/classes/data/dataCoupons.php +++ b/classes/data/dataCoupons.php @@ -85,7 +85,6 @@ class GlmDataCoupons extends GlmDataAbstract * @var bool * @access public */ - public $postCategories = true; /** * Constructor @@ -162,23 +161,26 @@ class GlmDataCoupons extends GlmDataAbstract // Date Start Date 'start_date' => array( - 'field' => 'start_date', - 'type' => 'date', - 'use' => 'a' + 'field' => 'start_date', + 'type' => 'date', + 'required' => true, + 'use' => 'a' ), // Date End Date 'end_date' => array( - 'field' => 'end_date', - 'type' => 'date', - 'use' => 'a' + 'field' => 'end_date', + 'type' => 'date', + 'required' => true, + 'use' => 'a' ), // Date Expire Date 'expire' => array( - 'field' => 'expire', - 'type' => 'date', - 'use' => 'a' + 'field' => 'expire', + 'type' => 'date', + 'required' => true, + 'use' => 'a' ), // Reference Type - Insert new record @@ -273,26 +275,6 @@ class GlmDataCoupons extends GlmDataAbstract */ public function entryPostProcessing($r, $a) { - - // Get Member Category data for this entry - if ($this->postCategories) { - $sql = " - SELECT EC.coupon AS coupon_id, C.id, C.name, C.descr, - COALESCE ( - ( - SELECT name - FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "categories - WHERE id = C.parent - ), '' - ) AS parent_name - FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "categories AS C, - ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "coupon_categories AS EC - WHERE C.id = EC.category - AND EC.coupon = ".$r['id']." - ;"; - $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); - } - return $r; } @@ -443,9 +425,6 @@ class GlmDataCoupons extends GlmDataAbstract public function getIdName($where = 'true') { $savedFields = $this->fields; - $savedCategories = $this->postCategories; - - $this->postCategories = false; $this->fields = array( 'id' => $savedFields['id'], @@ -455,7 +434,6 @@ class GlmDataCoupons extends GlmDataAbstract $r = $this->getList($where); $this->fields = $savedFields; - $this->postCategories = $savedCategories; return $r; diff --git a/defines.php b/defines.php index d430da2..3c50f2e 100644 --- a/defines.php +++ b/defines.php @@ -13,7 +13,7 @@ define('GLM_MEMBERS_COUPONS_PLUGIN_SLUG', 'glm-member-db-coupons'); // Database table prefixes - change if using add-on tables global $wpdb; -define('GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glmMembersCoupons'); +define('GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_membersCoupons_'); define('GLM_MEMBERS_COUPONS_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersCouponsDbVersion'); // Determine which system we're running on - If not provided, assume PRODUCTION diff --git a/index.php b/index.php index f28eda8..1be5c74 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_COUPONS_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_COUPONS_PLUGIN_DB_VERSION', '0.0.1'); +define('GLM_MEMBERS_COUPONS_PLUGIN_DB_VERSION', '0.0.2'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_COUPONS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/coupons/index.php b/models/admin/coupons/index.php index 6205278..89b9e59 100644 --- a/models/admin/coupons/index.php +++ b/models/admin/coupons/index.php @@ -107,15 +107,13 @@ class GlmMembersAdmin_coupons_index extends GlmDataCoupons $lockedWhere = 'ref_type = '.$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID; } - /* // Check for required Coupon Categories - require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'; - $CouponCategories = new GlmDataCouponsCategories($this->wpdb, $this->config); + require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponCategories.php'; + $CouponCategories = new GlmDataCouponCategories($this->wpdb, $this->config); $couponCategoriesStats = $CouponCategories->getStats(); if ($couponCategoriesStats && $couponCategoriesStats > 0) { $haveCategories = true; } - */ // Get full list of names matching this where clause for search box $namesList = $this->getIdName($lockedWhereT); diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php new file mode 100644 index 0000000..8d3ba50 --- /dev/null +++ b/models/admin/coupons/list.php @@ -0,0 +1,623 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Contacts data class +require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php'; + +// Load coupon categories data class +require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponCategories.php'; + +class GlmMembersAdmin_coupons_list extends GlmDataCoupons +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Coupon ID + * + * @var $couponID + * @access public + */ + public $couponID = false; + + /** + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + /* + * Run constructor for the Contacts data class + * + * 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); + + } + + public function modelAction($actionData = false) + { + + $lockedToMember = false; + $numbCoupons = 0; + $option = 'list'; + $coupons = false; + $haveCoupons = false; + $coupon = false; + $haveCoupon = false; + $this->couponID = false; + $couponUpdated = false; + $couponUpdateError = false; + $couponAdded = false; + $couponAddError = false; + $view = 'list'; + $fromDate = false; + $toDate = false; + $filterArchived = false; + $filterPending = false; + $couponDeleted = false; + $couponDeleteError = false; + $locations = false; + $haveLocations = false; + $numbLocations = 0; + $recurrences = false; + $haveRecurrences = false; + $numbRecurrences = 0; + $times = false; + $haveTimes = false; + $firstTime = false; + $lastTime = false; + $memberID = false; + $haveMember = false; + $memberName = false; + $memberData = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $namesList = false; + $enable_members = $this->config['settings']['enable_members']; + + // Check if there's a logged in user who is locked to their own entity + $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); + if ($lockedToMember) { + $memberID = $lockedToMember; + $this->fields['admin_name']['required'] = true; + $this->fields['admin_email']['required'] = true; + $this->fields['admin_phone']['required'] = true; + + // Check for Member Menu Use + } elseif (defined('GLM_COUPONS_MEMBER_MENU')) { + + // Try to get member ID + $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0); + + // If there's no valid member ID, we can't continue + if ($memberID == 0) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member ID was provided.' + ) + ); + } + } + + // If not a valid member ID + if ($memberID > 0) { + + // Get base member information + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + $Member = new GlmDataMembers($this->wpdb, $this->config); + $memberData = $Member->getEntry($memberID); + + if (!$memberData) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member data found for provided member ID.' + ) + ); + } else{ + $haveMember = true; + $memberName = $memberData['name']; + } + + } + + // Get a list of categories + $Categories = new GlmDataCouponCategories($this->wpdb, $this->config); + $categories = $Categories->getList(false); + + // Get any provided option + if (isset($_REQUEST['option'])) { + $option = $_REQUEST['option']; + } + + // Get coupon ID if supplied + if (isset($_REQUEST['coupon'])) { + + // Make sure it's numeric + $this->couponID = ($_REQUEST['coupon'] - 0); + + if ($this->couponID <= 0) { + $this->couponID = false; + } + + } + + // Check for specific_dates submission + + // Do selected option + switch ($option) { + + case 'add': + + $coupon = $this->newEntry(); + + $view = 'edit'; + + break; + + case 'insert': + + $coupon = $this->insertEntry(); + + $this->couponID = $coupon['fieldData']['id']; + + $this->updateCategories(); + $categories = $Categories->getList(false); + + if ($coupon['status']) { + $haveCoupon = true; + $couponAdded = true; + + // Update created timestamp and name slug for URLs + $this->updateTimestamp('created', $this->couponID); + $this->updateSlug($this->couponID); + + // Get this again so we have the created date + $coupon = $this->editEntry($this->couponID); + + $option = 'edit'; + $couponAdded = true; + + } else { + $option = 'add'; + $couponAddError = true; + } + + $view = 'edit'; + + break; + + case 'edit': + + $coupon = $this->editEntry($this->couponID); + + if ($coupon['status']) { + $haveCoupon = true; + } + + $view = 'edit'; + break; + + case 'update': + + // Get the original Coupon Status. Before the update. + $old_coupon_status = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT status + FROM " . GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . "coupons + WHERE id = %d", + $this->couponID + ) + ); + + $this->updateCategories(); + $categories = $Categories->getListSortedParentChild(false); + + if ( $this->config['settings']['use_coupon_amenities'] ) { + $this->updateAmenities(); + $amenities = $Amenities->getList(false); + } + + // Try to update this coupon + $coupon = $this->updateEntry($this->couponID); + + // Check if that was successful + if ($coupon['status']) { + $couponUpdated = true; + + // Check if the coupon is being approved + if ( $coupon['fieldData']['status']['value'] && $old_coupon_status ) { + $new_status = $coupon['fieldData']['status']['value']; + if ( $old_coupon_status == 20 && $new_status == 10 ) { + // Update approved timestamp. + $this->updateTimestamp('approved', $this->couponID); + } + } + + // Update updated timestamp and name slug for URLs + $this->updateTimestamp('updated', $this->couponID); + $this->updateSlug($this->couponID); + + $coupon = $this->editEntry($this->couponID); + } else { + $couponUpdateError = true; + } + + $haveCoupon = true; + $view = 'edit'; + + break; + + case 'delete': + + $coupon = $this->deleteCoupon($this->couponID); + + if ($coupon) { + $couponDeleted = true; + } else { + $couponDeleteError = true; + } + + case 'list': + default: + + $where = 'true'; + + // Check for Archived filter + if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') { + $filterArchived = true; + $where .= " AND status = " . $this->config['status_numb']['Archived']; + } + + // Check for Pending filter + if (isset($_REQUEST['filterPending']) && $_REQUEST['filterPending'] == 'on') { + $filterPending = true; + $where .= " AND status = " . $this->config['status_numb']['Pending']; + } + + // Add "selected" element default false; + reset($categories); + while (list($k, $v) = each($categories)) { + $categories[$k]['selected'] = false; + } + + // Check if there is a category filter (multi-select) + if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) { + + $cats = ''; + $catsSep = ''; + + // For each selected category + foreach($_REQUEST['filterCategories'] as $c) { + $cats .= $catsSep.$c; + $catsSep = ','; + $categories[$c]['selected'] = true; + } + + $where .= " AND id in ( + SELECT DISTINCT(EC.coupon) + FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories EC, + ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories C + WHERE ( + EC.category in ($cats) + OR (C.parent in ($cats) AND EC.category = C.id) + ) + )"; + } + + // Check if we have a Text Search string + if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') { + $textSearch = trim($_REQUEST['textSearch']); + $where .= " AND name LIKE '%$textSearch%'"; + } + + + // If we have a From date + $dateWhere = ''; + if (isset($_REQUEST['fromDate']) && trim($_REQUEST['fromDate']) != '') { + $fromDate = date('m/d/Y', strtotime($_REQUEST['fromDate'])); + $fromMYSQL = date('Y-m-d', strtotime($fromDate)); + $dateWhere = " end_time >= '$fromMYSQL' "; + } + + // If we have a to Date + if (isset($_REQUEST['toDate']) && trim($_REQUEST['toDate']) != '') { + + $toDate = date('m/d/Y', strtotime($_REQUEST['toDate'])); + $toMYSQL = date('Y-m-d', strtotime($toDate." +1 day")); + + // If we have a from date then we need Parens and AND + if ($dateWhere != '') { + $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )"; + + // Otherwise we don't + } else { + $dateWhere = " start_time <= '$toMYSQL' "; + } + } + + // If we have from and to dates, do search for those inclusive + if ($dateWhere != '') { + $where .= " + AND id in ( + SELECT DISTINCT(coupon) + FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."times + WHERE $dateWhere + AND active + ) + "; + } + + // Check if the list is for a specific member + if (defined('GLM_COUPONS_MEMBER_MENU') || $memberID) { + $where .= " AND ref_dest = $memberID"; + } + + // Get the total number of coupons listed + $numbCoupons = $this->getStats($where); + + // If the number of coupons is less than a page, don't do paging + if ($numbCoupons <= $limit) { + $paging = false; + } + + // Get full list of names matching this where clause for search box + $namesList = $this->getIdName($where); + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } + } + + // Get the list of coupons and determine number of coupons in list + //$saveFLT = $this->postFirstAndLastTimes; + //$this->postFirstAndLastTimes = true; + $couponsResult = $this->getList($where, 'name', true, 'id', $start, $limit); + //$this->postFirstAndLastTimes = $saveFLT; + + // Get paging results + $numbDisplayed = $couponsResult['returned']; + $lastDisplayed = $couponsResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($couponsResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // since we're doing paging, we have to break out just the coupons data + $coupons = $couponsResult['list']; + if (count($coupons)>0) { + $haveCoupons = true; + } + unset($couponsResult); + + break; + + } + // + // If we have an coupon ID + if ($this->couponID) { + + } + $templateData = array( + 'enable_members' => $enable_members, + 'lockedToMember' => $lockedToMember, + 'option' => $option, + 'coupons' => $coupons, + 'haveCoupons' => $haveCoupons, + 'coupon' => $coupon, + 'haveCoupon' => $haveCoupon, + 'couponID' => $this->couponID, + 'couponUpdated' => $couponUpdated, + 'couponUpdateError' => $couponUpdateError, + 'couponAdded' => $couponAdded, + 'couponAddError' => $couponAddError, + 'numbCoupons' => $numbCoupons, + 'categories' => $categories, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + 'filterArchived' => $filterArchived, + 'filterPending' => $filterPending, + 'couponDeleted' => $couponDeleted, + 'couponDeleteError' => $couponDeleteError, + 'locations' => $locations, + 'haveLocations' => $haveLocations, + 'numbLocations' => $numbLocations, + 'memberID' => $memberID, + 'haveMember' => $haveMember, + 'memberName' => $memberName, + 'memberData' => $memberData, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start = 1, + 'limit' => $limit, + 'namesList' => $namesList, + + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => "admin/coupons/$view.html", + 'data' => $templateData + ); + + } + + /** + * Update categories for the current submission + * + * @return void + */ + public function updateCategories() + { + + // Instatiate the dataCategories class + $Categories = new GlmDataCouponsCategories($this->wpdb, $this->config); + + // Instatiate Coupon/Categories data class + $CouponCategories = new GlmDataCouponsCouponCategories($this->wpdb, $this->config); + + // Get any selected categories + $selectedCategories = array(); + $newCategory = false; + if (isset($_REQUEST['category']) && is_array($_REQUEST['category']) && count($_REQUEST['category']) > 0) { + + /* + * For each selected category + * + * Note that categories are submitted with either a positive key, which indicates + * that it represents an existing category, or a negative key, which indicates + * that the user is trying to add it to the list of categories. + * + */ + foreach ($_REQUEST['category'] as $key) { + + // Make sure key is an integer + $key = intval($key -0); + + // If negative, this is a new category that needs to be added to the category table + if ($key < 0) { + + $newCategory = true; + + // Check if a parent is specified + $parent = 0; + if ($_REQUEST['newCatParent'][$key] != '') { + $parent = $_REQUEST['newCatParent'][$key] -0; + } elseif ($_REQUEST['newCatParentName'][$key]) { + $parent = $_REQUEST['newCatParentName'][$key]; + } + + // Clean up the category name + $category = filter_var($_REQUEST['newCategory'][$key]); + + // Add it to the category table and get the new category ID + $categoryID = $Categories->addCategory($category, $parent); + + // If we got a new category ID, add it to the array of currently selected couponCategory records + if ($categoryID) { + $selectedCategories[$categoryID] = $categoryID; + } + + // Otherwise if it's positive, the category is an existing one + } else if ($key > 0) { + + $selectedCategories[$key] = $key; + + } + + // If there's selected categories + if (count($selectedCategories) > 0) { + + // Update the selected categories for this coupon record, returns new list + $CouponCategories->setCouponCategories($this->couponID, $selectedCategories); + + } + + // If there's been a new category + if ($newCategory) { + + // Get the full category list again + $this->categories = $Categories->getListSortedParentChild(); + + } + + } // For each category being submitted + + // Otherwise if this is a submission and there's no categories submitted, so make sure there's none stored + } elseif ( isset($_REQUEST['option']) && ( $_REQUEST['option'] === 'submit' || $_REQUEST['option'] === 'update' ) ) { + $CouponCategories->clearCouponCategories($this->couponID); + } + + } + +} diff --git a/models/admin/settings/couponCategories.php b/models/admin/settings/couponCategories.php index 45e80be..ef3bccb 100644 --- a/models/admin/settings/couponCategories.php +++ b/models/admin/settings/couponCategories.php @@ -38,7 +38,7 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories */ public $config; - /* + /** * Constructor * * This contructor sets up this model. At this time that only includes @@ -61,7 +61,7 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories } - /* + /** * Perform Model Action * * This method does the work for this model and returns any resulting data @@ -128,14 +128,6 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories case 'delete': if ($id > 0) { $this->deleteEntry($id, true); - - // Also delete from member info - $this->wpdb->delete( - GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'coupon_categories', - array( - 'category' => $id - ) - ); } break; diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql deleted file mode 100644 index d916acf..0000000 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ /dev/null @@ -1,66 +0,0 @@ --- Gaslight Media Members Database - Coupons Add-On --- File Created: 11/15/16 --- Database Version: 0.0.1 --- Database Creation Script --- --- This file is called to create a new set of tables for this --- add-on for the most recent database version for this add-on. --- --- There should only be one such file in this directory --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashes - - --- Coupons -CREATE TABLE {prefix}coupons ( - id INT NOT NULL AUTO_INCREMENT, - status INT NULL, -- Status of the Coupon (Active Pending) - created DATETIME NULL, -- Create date - updated DATETIME NULL, -- Update date - approved DATETIME NULL, -- Approved date - start_date DATE NULL, -- Starting date of the coupon - end_date DATE NULL, -- Ending date of the coupon - expire DATE NULL, -- Expire date of the coupon - name TINYTEXT NULL, -- Coupon name - name_slug TINYTEXT NULL, -- Coupon name slug - ref_type INT NULL, -- Ref type - ref_dest INT NULL, -- Id from ref type table - descr TEXT NULL, -- Description of the coupon - image TINYTEXT NULL, -- Coupon image - url TINYTEXT NULL, -- website of the coupon - PRIMARY KEY(id), - INDEX(ref_type), - INDEX(ref_dest), - INDEX(start_date), - INDEX(end_date) -); - ----- - --- Categories -CREATE TABLE {prefix}categories ( - id INT NOT NULL AUTO_INCREMENT, - name TINYTEXT NULL, -- Category Name - PRIMARY KEY (id), - INDEX(name(20)) -); - ----- - --- Settings -CREATE TABLE {prefix}settings ( - id INT NOT NULL AUTO_INCREMENT, - notify_to TINYTEXT NULL, -- To for the notify email - notify_from TINYTEXT NULL, -- From header for notify email - notify_message TEXT NULL, -- Message to add to the notify email - PRIMARY KEY (id) -); - ----- - --- Data for Settings -INSERT INTO {prefix}settings -(id,notify_to,notify_from,notify_message) -VALUES -(1, '', '', ''); diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql new file mode 100644 index 0000000..d309c90 --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.2.sql @@ -0,0 +1,78 @@ +-- Gaslight Media Members Database - Coupons Add-On +-- File Created: 11/15/16 +-- Database Version: 0.0.2 +-- Database Creation Script +-- +-- This file is called to create a new set of tables for this +-- add-on for the most recent database version for this add-on. +-- +-- There should only be one such file in this directory +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + + +-- Coupons +CREATE TABLE {prefix}coupons ( + id INT NOT NULL AUTO_INCREMENT, + status INT NULL, -- Status of the Coupon (Active Pending) + created DATETIME NULL, -- Create date + updated DATETIME NULL, -- Update date + approved DATETIME NULL, -- Approved date + start_date DATE NULL, -- Starting date of the coupon + end_date DATE NULL, -- Ending date of the coupon + expire DATE NULL, -- Expire date of the coupon + name TINYTEXT NULL, -- Coupon name + name_slug TINYTEXT NULL, -- Coupon name slug + ref_type INT NULL, -- Ref type + ref_dest INT NULL, -- Id from ref type table + descr TEXT NULL, -- Description of the coupon + image TINYTEXT NULL, -- Coupon image + url TINYTEXT NULL, -- website of the coupon + PRIMARY KEY(id), + INDEX(ref_type), + INDEX(ref_dest), + INDEX(start_date), + INDEX(end_date) +); + +---- + +-- Categories +CREATE TABLE {prefix}categories ( + id INT NOT NULL AUTO_INCREMENT, + name TINYTEXT NULL, -- Category Name + PRIMARY KEY (id), + INDEX(name(20)) +); + +---- + +-- Coupon-Category - Categories for specific coupon records +CREATE TABLE {prefix}coupon_categories ( + id INT NOT NULL AUTO_INCREMENT, + coupon INT NULL, -- Pointer to the coupon + category INT NULL, -- Pointer to the category + PRIMARY KEY (id), + INDEX(coupon), + INDEX(category) +); + +---- + +-- Settings +CREATE TABLE {prefix}settings ( + id INT NOT NULL AUTO_INCREMENT, + notify_to TINYTEXT NULL, -- To for the notify email + notify_from TINYTEXT NULL, -- From header for notify email + notify_message TEXT NULL, -- Message to add to the notify email + PRIMARY KEY (id) +); + +---- + +-- Data for Settings +INSERT INTO {prefix}settings +(id,notify_to,notify_from,notify_message) +VALUES +(1, '', '', ''); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 03688e7..8f3f69c 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -15,5 +15,6 @@ $glmMembersCouponsDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 3), + '0.0.2' => array('version' => '0.0.2', 'tables' => 4), ); diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql new file mode 100644 index 0000000..952023a --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.2.sql @@ -0,0 +1,18 @@ +-- Gaslight Media Members Database - Coupons Add-On +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + + +-- Coupon-Category - Categories for specific coupon records +CREATE TABLE {prefix}coupon_categories ( + id INT NOT NULL AUTO_INCREMENT, + coupon INT NULL, -- Pointer to the coupon + category INT NULL, -- Pointer to the category + PRIMARY KEY (id), + INDEX(coupon), + INDEX(category) +); diff --git a/setup/validActions.php b/setup/validActions.php index 3e1a9b5..0129c0e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -33,7 +33,8 @@ $glmMembersCouponsAddOnValidActions = array( 'adminActions' => array( 'coupons' => array( - 'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG + 'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, + 'list' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, ), 'dashboard' => array( 'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, diff --git a/views/admin/coupons/edit.html b/views/admin/coupons/edit.html new file mode 100644 index 0000000..bf863e0 --- /dev/null +++ b/views/admin/coupons/edit.html @@ -0,0 +1,448 @@ +{if $haveMember && !$lockedToMember } + {include file='admin/member/header.html'} +{else} + {include file='admin/coupons/header.html'} +{/if} + +{if apply_filters('glm_members_permit_admin_member_coupon', true)} + + {if $haveMember} + Return to Coupons List + {else} + Return to Coupons List + {/if} + + {if $option == 'edit' || $option == 'update'} + Delete this Coupon +

Edit Coupon

+ {else} +

Add new Coupon

+ {/if} + + {if $haveMember && !$lockedToMember} +
+ + {else} + {if $lockedToMember} + + + {else} + + + + {/if} + {/if} + + {if $haveMember} + + {/if} + {if $haveCoupon} + + + {else} + + {/if} + + + {if $haveCoupon} + + + + + + + + + + + + + + + + + {/if} + {if !$lockedToMember} + + + + + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name for URLs:{$coupon.fieldData.name_slug}
Created:{$coupon.fieldData.created.datetime}
Last Updated:{$coupon.fieldData.updated.datetime}
Last Approved:{$coupon.fieldData.approved.datetime}
Status: + + {if $coupon.fieldFail.status}

{$coupon.fieldFail.status}

{/if} +
Coupon Name: + + {if $coupon.fieldFail.name}

{$coupon.fieldFail.name}

{/if}
+
Starting Date: + +
Ending Date: + +
Expire Date: + +
Coupon Text: + +
+ {if $coupon.fieldFail.descr}

{$coupon.fieldFail.descr}

{/if} +
Image: + + {if $coupon.fieldData.image} + + + + + {/if} + +
+
+ +
+
+ Delete Image
+ {$coupon.fieldData.image}
+
New image:
+
+ {if $coupon.fieldData.image} + + {/if} +
+ {if $coupon.fieldFail.image}

{$coupon.fieldFail.image}

{/if} +

+ Best image size to provide is between 500 and 700 pixels wide and stored as a JPG or JPEG file. + Also try to supply images that have a reasonable "aspect ratio" (not too tall, not too wide). + Files provided like this should have a file size of 100 to 250 KB. Images will be automatically + resized for use in the Web site. Images that are too large will be rejected. +

+
Web Address (URL): + + {if $coupon.fieldFail.url}

{$coupon.fieldFail.url}

{/if}
+
+ + + + +
+ +{else} + + + +
Name:{$coupon.fieldData.name}
+ +{/if} + + + +
+
+

Cancel

+

+
+
+

WARNING:

+

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

+

+ + 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 coupon to "Archived" instead. + +

+
+
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/coupons/list.html b/views/admin/coupons/list.html new file mode 100644 index 0000000..b270301 --- /dev/null +++ b/views/admin/coupons/list.html @@ -0,0 +1,186 @@ +{if $haveMember && !$lockedToMember} + {include file='admin/member/header.html'} +{else} + {include file='admin/coupons/header.html'} +{/if} + +{if apply_filters('glm_members_permit_admin_coupons_index_add_coupon', true)} +

+ {if $haveMember} {* This is if we're processing coupons for a specific member *} + Add A New Coupon + {else} + Add A New Coupon + {/if} + {if $couponDeleted}Coupon Deleted{/if} + {if $couponDeleteError}Coupon Delete Error{/if} +

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

+ + From Date: + To Date: + + + Categories:  + + + + Show Archived Only: + Show Pending Only: + + + Text Search: + + +

+

+
+ +

Total found: {$numbCoupons}  

+ + + {if $paging} + + + {/if} + + + + + + + + + + + + + + + {if $haveCoupons} + {assign var="i" value="0"} + {foreach $coupons as $e} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + + + {/foreach} + {else} + + {/if} + +
IDCoupon Name{$terms.term_member_cap}StatusFirst DateLast Date
+ {$e.id} + + {if $haveMember} + {if $lockedToMember} + {$e.name} + {else} + {$e.name} + {/if} + {else} + {$e.name} + {/if} + + {$e.ref_dest} + + {$e.status.name} + + {$e.firstDate} + + {$e.lastDate} + + View Coupon +
(no coupons listed)
+ + {if $paging} + + + {/if} + +
+ + + + +{include file='admin/footer.html'} diff --git a/views/admin/settings/couponCategories.html b/views/admin/settings/couponCategories.html index 7f4be05..cd6bf38 100644 --- a/views/admin/settings/couponCategories.html +++ b/views/admin/settings/couponCategories.html @@ -14,27 +14,6 @@ - - Parent Category: - - - - - - Description: - - - -

* Required

Cancel @@ -64,27 +43,6 @@ - - Parent Category: - - - - - - Description: - - - -

* Required

Cancel @@ -94,41 +52,37 @@

Categories

- +
- -{if $haveCategories} - {assign var="i" value="0"} - {foreach $categories as $t} - {if $i++ is odd by 1} - - {else} - - {/if} + {if $haveCategories} + {assign var="i" value="0"} + {foreach $categories as $t} + {if $i++ is odd by 1} + + {else} + + {/if} - - {/foreach} -{else} + {/foreach} + {else} -{/if} + {/if}
ID CategoryDescription  
{$t.id} - - {$t.name} + - {$t.descr} -
Delete
(no categories listed)
@@ -157,12 +111,8 @@ $('.editCategory').click( function() { var catID = $(this).attr('data-categoryID'); var catName = $(this).text(); - var catParent = $(this).attr('data-categoryParent'); - var catDescr = $('#editCategoryDescr_' + catID).html(); $('#editCategoryID').val(catID); $('#editCategoryName').val(catName.trim()); - $('#editCategoryParent').val(catParent); - $('#editCategoryDescr').val(catDescr.trim()); $("#editCategoryDialog").dialog("open"); }); $('#editCategoryCancel').click( function() {