/** * Interface processor for the customer list screen * * Handles processing customer list actions and displaying the * customer list screen * * @author Jonathan Davis * @return void **/ function memeberships() { $Shopp = Shopp::object(); $defaults = array('page' => false, 'deleting' => false, 'delete' => false, 'pagenum' => 1, 'per_page' => 20, 's' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); if ($page == $this->Admin->pagename('memberships') && !empty($deleting) && !empty($delete) && is_array($delete)) { foreach ($delete as $deletion) { $MemberPlan = new MemberPlan($deletion); $MemberPlan->delete(); } } if (!empty($_POST['save'])) { check_admin_referer('shopp-save-membership'); if ($_POST['id'] != "new") { $MemberPlan = new MemberPlan($_POST['id']); } else { $MemberPlan = new MemberPlan(); } $MemberPlan->updates($_POST); $MemberPlan->save(); $MemberPlan->load_stages(); $stages = array_keys($MemberPlan->stages); // Process updates foreach ($_POST['stages'] as $i => $stage) { if (empty($stage['id'])) { $Stage = new MemberStage($MemberPlan->id); $stage['parent'] = $MemberPlan->id; } else { $Stage = new MemberStage($MemberPlan->id, $stage['id']); } $Stage->updates($stage); $Stage->sortorder = $i; $Stage->save(); $Stage->content = array(); $stage_updates[] = $Stage->id; // If the stage data did not save, go to the next stage record if (empty($Stage->id)) { continue; } foreach ($stage['rules'] as $type => $rules) { foreach ($rules as $rule) { $AccessRule = new MemberAccess($Stage->id, $type, $rule['access']); if (empty($AccessRule->id)) { $AccessRule->save(); } // If access rule applies to all content, skip content cataloging if (strpos($AccessRule->value, '-all') !== false) { continue; } // Catalog content access rules for this access taxonomy foreach ($rule['content'] as $id => $name) { $CatalogEntry = new MemberContent($id, $AccessRule->id, $Stage->id); if (empty($CatalogEntry->id)) { $CatalogEntry->save(); } $Stage->content[$AccessRule->id][$id] = $name; } // endforeach $rule['content'] } // endforeach $rules } // endforeach $stage['rules'] $Stage->save(); // Secondary save for specific content rules } // endforeach $_POST['stages'] } $stageids = array_diff($stages, $stage_updates); if (!empty($stageids)) { $stagelist = join(',', $stageids); // Delete Catalog entries $ContentRemoval = new MemberContent(); sDB::query("DELETE FROM {$ContentRemoval->_table} WHERE 0 < FIND_IN_SET(parent,'{$stagelist}')"); // Delete Access taxonomies $AccessRemoval = new MemberAccess(); sDB::query("DELETE FROM {$AccessRemoval->_table} WHERE 0 < FIND_IN_SET(parent,'{$stagelist}')"); // Remove old stages $StageRemoval = new MemberStage(); sDB::query("DELETE FROM {$StageRemoval->_table} WHERE 0 < FIND_IN_SET(id,'{$stagelist}')"); } $pagenum = absint($pagenum); if (empty($pagenum)) { $pagenum = 1; } if (!$per_page || $per_page < 0) { $per_page = 20; } $index = $per_page * ($pagenum - 1); if (!empty($start)) { $startdate = $start; list($month, $day, $year) = explode("/", $startdate); $starts = mktime(0, 0, 0, $month, $day, $year); } if (!empty($end)) { $enddate = $end; list($month, $day, $year) = explode("/", $enddate); $ends = mktime(23, 59, 59, $month, $day, $year); } $membership_table = ShoppDatabaseObject::tablename(MemberPlan::$table); $MemberPlan = new MemberPlan(); $where = ''; // if (!empty($s)) { // $s = stripslashes($s); // if (preg_match_all('/(\w+?)\:(?="(.+?)"|(.+?)\b)/',$s,$props,PREG_SET_ORDER)) { // foreach ($props as $search) { // $keyword = !empty($search[2])?$search[2]:$search[3]; // switch(strtolower($search[1])) { // case "company": $where .= ((empty($where))?"WHERE ":" AND ")."c.company LIKE '%$keyword%'"; break; // case "login": $where .= ((empty($where))?"WHERE ":" AND ")."u.user_login LIKE '%$keyword%'"; break; // case "address": $where .= ((empty($where))?"WHERE ":" AND ")."(b.address LIKE '%$keyword%' OR b.xaddress='%$keyword%')"; break; // case "city": $where .= ((empty($where))?"WHERE ":" AND ")."b.city LIKE '%$keyword%'"; break; // case "province": // case "state": $where .= ((empty($where))?"WHERE ":" AND ")."b.state='$keyword'"; break; // case "zip": // case "zipcode": // case "postcode": $where .= ((empty($where))?"WHERE ":" AND ")."b.postcode='$keyword'"; break; // case "country": $where .= ((empty($where))?"WHERE ":" AND ")."b.country='$keyword'"; break; // } // } // } elseif (strpos($s,'@') !== false) { // $where .= ((empty($where))?"WHERE ":" AND ")."c.email='$s'"; // } else $where .= ((empty($where))?"WHERE ":" AND ")." (c.id='$s' OR CONCAT(c.firstname,' ',c.lastname) LIKE '%$s%' OR c.company LIKE '%$s%')"; // // } // if (!empty($starts) && !empty($ends)) $where .= ((empty($where))?"WHERE ":" AND ").' (UNIX_TIMESTAMP(c.created) >= '.$starts.' AND UNIX_TIMESTAMP(c.created) <= '.$ends.')'; $count = sDB::query("SELECT count(*) as total FROM {$MemberPlan->_table} AS c {$where}"); $query = "SELECT *\n\t\t\t\t\tFROM {$MemberPlan->_table}\n\t\t\t\t\tWHERE parent='{$MemberPlan->parent}'\n\t\t\t\t\t\tAND context='{$MemberPlan->context}'\n\t\t\t\t\t\tAND type='{$MemberPlan->type}'\n\t\t\t\t\tLIMIT {$index},{$per_page}"; $MemberPlans = sDB::query($query, 'array'); $num_pages = ceil($count->total / $per_page); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum)); $authentication = shopp_setting('account_system'); include SHOPP_ADMIN_PATH . "/memberships/memberships.php"; }