return $r;
}
+ /**
+ * Add a category using supplied parameters
+ *
+ * @param string $name Category Name
+ *
+ * @return integer ID of new category or false if failed
+ *
+ * @access public
+ */
+
+ public function addCategory($name) {
+
+ $categoryID = false;
+
+ // Filter new category name
+ $name = filter_var($name);
+ if ($name == false || trim($name) == '') {
+ return false;
+ }
+
+ // Check if the new category name already exists
+ $sql = "
+ SELECT id
+ FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories
+ WHERE name = '$name'";
+ $existing = $this->wpdb->get_row($sql, ARRAY_A);
+
+ if ($existing['id']) {
+
+ $categoryID = $existing['id'];
+
+ } else {
+
+ // Try to add the new category
+ $sql = "
+ INSERT INTO ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories
+ ( name )
+ VALUES
+ ( '".addslashes($name)."' )
+ ;";
+ $this->wpdb->query($sql);
+ $categoryID = $this->wpdb->insert_id;
+
+ }
+
+ if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+ glmMembersAdmin::addNotice("Category added: name = $name, ID = $categoryID", 'DataBlock', "addCategory()");
+ }
+
+ return $categoryID;
+
+ }
+
}
case 'insert':
$coupon = $this->insertEntry();
- $this->couponID = $coupon['fieldData']['id'];
- $this->updateCategories();
- $categories = $Categories->getList(false);
+ if ( $coupon ) {
+ $this->couponID = $coupon['fieldData']['id'];
+ $this->updateCategories();
+ $categories = $Categories->getList(false);
- if ($coupon['status']) {
- $haveCoupon = true;
- $couponAdded = true;
+ if ($coupon['status']) {
+ $haveCoupon = true;
+ $couponAdded = true;
- // Update created timestamp and name slug for URLs
- $this->updateTimestamp('created', $this->couponID);
- $this->updateSlug($this->couponID);
+ // 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);
+ // Get this again so we have the created date
+ $coupon = $this->editEntry($this->couponID);
- $option = 'edit';
- $couponAdded = true;
+ $option = 'edit';
+ $couponAdded = true;
+ } else {
+ $option = 'add';
+ $couponAddError = true;
+ }
} else {
$option = 'add';
$couponAddError = true;
$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);
+ $categoryID = $Categories->addCategory($category);
// If we got a new category ID, add it to the array of currently selected couponCategory records
if ($categoryID) {
if ($newCategory) {
// Get the full category list again
- $this->categories = $Categories->getListSortedParentChild();
+ $this->categories = $Categories->getList();
}
{if $lockedToMember}
<form action="{$thisUrl}?page=glm-members-admin-menu-coupons-list" method="post" enctype="multipart/form-data">
<input type="hidden" name="glm_action" value="list">
+ <input type="hidden" name="status" value="20">
{else}
<form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
<input type="hidden" name="glm_action" value="list">
<!-- Add new category dialog -->
- <div id="newCategoryButton" class="button button-secondary glm-right">Add a new Category</div>
+ {if !$lockedToMember}
+ <div id="newCategoryButton" class="button button-secondary glm-right">Add a new Category</div>
+ {/if}
<div id="newCategoryDialog" class="glm-dialog-box" title="Enter a New Category">
<table class="glm-admin-table">
<tr>