PageRenderTime 61ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 2ms

/wp-content/plugins/membership/membershipincludes/classes/membershipadmin.php

https://github.com/bfay/maniacal-kitten
PHP | 7679 lines | 6042 code | 1458 blank | 179 comment | 829 complexity | abcfed5a5d8add241782e0275b9eaee5 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. if(!class_exists('membershipadmin')) {
  3. class membershipadmin {
  4. var $build = 14;
  5. var $db;
  6. //
  7. var $showposts = 25;
  8. var $showpages = 100;
  9. var $tables = array('membership_levels', 'membership_rules', 'subscriptions', 'subscriptions_levels', 'membership_relationships', 'membermeta', 'communications', 'urlgroups', 'ping_history', 'pings', 'coupons');
  10. var $membership_levels;
  11. var $membership_rules;
  12. var $membership_relationships;
  13. var $subscriptions;
  14. var $subscriptions_levels;
  15. var $membermeta;
  16. var $communications;
  17. var $urlgroups;
  18. var $ping_history;
  19. var $pings;
  20. var $coupons;
  21. // Class variable to hold a link to the tooltips class
  22. var $_tips;
  23. // The Wizard
  24. var $potter;
  25. // The tutorial
  26. var $tutorial;
  27. // Coupons
  28. var $_coupons;
  29. // For the coupons datepicker
  30. var $language;
  31. function __construct() {
  32. global $wpdb;
  33. $this->db =& $wpdb;
  34. foreach($this->tables as $table) {
  35. $this->$table = membership_db_prefix($this->db, $table);
  36. }
  37. // Instantiate the tooltips class and set the icon
  38. $this->_tips = new WpmuDev_HelpTooltips();
  39. $this->_tips->set_icon_url(membership_url('membershipincludes/images/information.png'));
  40. // Initiate the wizard class
  41. $this->potter = new M_Wizard();
  42. // Add administration actions
  43. add_action('init', array(&$this, 'initialise_plugin'), 1);
  44. // Add in admin area membership levels
  45. add_action('init', array(&$this, 'initialise_membership_protection'), 999);
  46. if( (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('membership/membershippremium.php')) && (defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true)) {
  47. add_action('network_admin_menu', array(&$this, 'add_admin_menu'));
  48. } else {
  49. add_action('admin_menu', array(&$this, 'add_admin_menu'));
  50. }
  51. add_action( 'plugins_loaded', array(&$this, 'load_textdomain'));
  52. // Header actions
  53. add_action('load-toplevel_page_membership', array(&$this, 'add_admin_header_membership'));
  54. add_action('load-membership_page_membershipmembers', array(&$this, 'add_admin_header_members'));
  55. add_action('load-membership_page_membershiplevels', array(&$this, 'add_admin_header_membershiplevels'));
  56. add_action('load-membership_page_membershipsubs', array(&$this, 'add_admin_header_membershipsubs'));
  57. add_action('load-membership_page_membershipcoupons', array(&$this, 'add_admin_header_membershipcoupons'));
  58. add_action('load-membership_page_membershipgateways', array(&$this, 'add_admin_header_membershipgateways'));
  59. add_action('load-membership_page_membershipoptions', array(&$this, 'add_admin_header_membershipoptions'));
  60. add_action('load-membership_page_membershipcommunication', array(&$this, 'add_admin_header_membershipcommunication'));
  61. add_action('load-membership_page_membershipurlgroups', array(&$this, 'add_admin_header_membershipurlgroups'));
  62. add_action('load-membership_page_membershippings', array(&$this, 'add_admin_header_membershippings'));
  63. add_action('load-users_page_membershipuser', array(&$this, 'add_admin_header_membershipuser'));
  64. add_filter('membership_level_sections', array(&$this, 'default_membership_sections'));
  65. // Media management additional fields
  66. add_filter('attachment_fields_to_edit', array(&$this, 'add_media_protection_settings'), 99, 2);
  67. add_filter('attachment_fields_to_save', array(&$this, 'save_media_protection_settings'), 99, 2);
  68. // rewrites
  69. add_action('generate_rewrite_rules', array(&$this, 'add_rewrites'));
  70. add_filter('query_vars', array(&$this, 'add_queryvars') );
  71. // profile field for feeds
  72. add_action('show_user_profile', array(&$this, 'add_profile_feed_key') );
  73. // Pings
  74. add_action('membership_subscription_form_after_levels', array(&$this, 'show_subscription_ping_information'));
  75. add_action('membership_subscription_add', array(&$this, 'update_subscription_ping_information'));
  76. add_action('membership_subscription_update', array(&$this, 'update_subscription_ping_information'));
  77. add_action('membership_level_form_after_rules', array(&$this, 'show_level_ping_information'));
  78. add_action('membership_level_add', array(&$this, 'update_level_ping_information'));
  79. add_action('membership_level_update', array(&$this, 'update_level_ping_information'));
  80. // Ajax calls have to go here because admin-ajax.php is an admin call even though we're calling it from the front end.
  81. add_action( 'wp_ajax_nopriv_buynow', array(&$this, 'popover_signup_form') );
  82. //login and register are no-priv only because, well they aren't logged in or registered
  83. add_action( 'wp_ajax_nopriv_register_user', array(&$this, 'popover_register_process') );
  84. add_action( 'wp_ajax_nopriv_login_user', array(&$this, 'popover_login_process') );
  85. // if logged in:
  86. add_action( 'wp_ajax_buynow', array(&$this, 'popover_sendpayment_form') );
  87. add_action( 'wp_ajax_extra_form', array(&$this, 'popover_extraform_process') );
  88. add_action( 'wp_ajax_register_user', array(&$this, 'popover_register_process') );
  89. add_action( 'wp_ajax_login_user', array(&$this, 'popover_login_process') );
  90. // Helper actions
  91. add_action( 'membership_activate_addon', array(&$this, 'activate_addon'), 10, 1 );
  92. add_action( 'membership_deactivate_addon', array(&$this, 'deactivate_addon'), 10, 1 );
  93. // Level shortcodes filters
  94. add_filter( 'membership_level_shortcodes', array(&$this, 'build_level_shortcode_list' ) );
  95. add_action( 'plugins_loaded', array(&$this, 'load_tutorial'), 11); //init tutorial after translation loaded
  96. // Add in the coupon class
  97. $this->_coupons = new M_Coupon();
  98. }
  99. function membershipadmin() {
  100. $this->__construct();
  101. }
  102. function load_textdomain() {
  103. $locale = apply_filters( 'membership_locale', get_locale() );
  104. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" );
  105. if ( file_exists( $mofile ) ) {
  106. load_textdomain( 'membership', $mofile );
  107. }
  108. //setup language code for jquery datepicker translation
  109. $temp_locales = explode('_', get_locale());
  110. $this->language = ($temp_locales[0]) ? $temp_locales[0] : 'en';
  111. }
  112. function load_tutorial() {
  113. // Add in pointer tutorial
  114. $this->tutorial = new M_Tutorial();
  115. $this->tutorial->serve();
  116. }
  117. function initialise_plugin() {
  118. global $user, $M_options;
  119. $installed = get_option('M_Installed', false);
  120. if(empty($user) || !method_exists($user, 'has_cap')) {
  121. $user = wp_get_current_user();
  122. }
  123. if($installed === false || $installed != $this->build) {
  124. include_once(membership_dir('membershipincludes/classes/upgrade.php') );
  125. M_Upgrade($installed);
  126. update_option('M_Installed', $this->build);
  127. // Add in our new capability
  128. if(!$user->has_cap('membershipadmin') && defined('MEMBERSHIP_SETACTIVATORAS_ADMIN') && MEMBERSHIP_SETACTIVATORAS_ADMIN == 'yes') {
  129. $user->add_cap('membershipadmin');
  130. }
  131. $this->create_defaults();
  132. }
  133. // Add in our new capability
  134. if($user->user_login == MEMBERSHIP_MASTER_ADMIN && !$user->has_cap('membershipadmin')) {
  135. $user->add_cap('membershipadmin');
  136. }
  137. if($user->has_cap('membershipadmin')) {
  138. // profile field for capabilities
  139. //add_action( 'edit_user_profile', array(&$this, 'add_membershipadmin_capability') );
  140. //add_action( 'edit_user_profile_update', array(&$this, 'update_membershipadmin_capability'));
  141. // If the user is a membershipadmin user then we can add in notices
  142. add_action('all_admin_notices', array(&$this, 'show_membership_status_notice'));
  143. }
  144. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) {
  145. if(function_exists('get_blog_option')) {
  146. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array());
  147. } else {
  148. $M_options = get_option('membership_options', array());
  149. }
  150. } else {
  151. $M_options = get_option('membership_options', array());
  152. }
  153. // Short codes
  154. if(!empty($M_options['membershipshortcodes'])) {
  155. foreach($M_options['membershipshortcodes'] as $key => $value) {
  156. if(!empty($value)) {
  157. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_fake_shortcode') );
  158. }
  159. }
  160. }
  161. // Admin only Shortcodes setup
  162. if(!empty($M_options['membershipadminshortcodes'])) {
  163. foreach($M_options['membershipadminshortcodes'] as $key => $value) {
  164. if(!empty($value)) {
  165. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_fake_shortcode') );
  166. }
  167. }
  168. }
  169. do_action('membership_register_shortcodes');
  170. add_action( 'wp_ajax_m_set_coupon', array(&$this, 'set_membership_coupon_cookie'));
  171. add_action( 'wp_ajax_nopriv_m_set_coupon', array(&$this, 'set_membership_coupon_cookie'));
  172. }
  173. function show_membership_status_notice() {
  174. global $user, $M_options;
  175. // Membership active check
  176. $membershipactive = M_get_membership_active();
  177. if($membershipactive == 'no') {
  178. echo '<div class="error fade"><p>' . sprintf(__("The Membership plugin is not enabled. To ensure your content is protected you should <a href='%s'>enable it</a>", 'membership'), wp_nonce_url("?page=membership&amp;action=activate", 'toggle-plugin')) . '</p></div>';
  179. }
  180. // Membership admin check
  181. if(empty($user) || !method_exists($user, 'has_cap')) {
  182. $user = wp_get_current_user();
  183. }
  184. if($user->has_cap('membershipadmin')) {
  185. // Show a notice to say that they are logged in as the membership admin user and protection isn't enabled on the front end
  186. echo '<div class="update-nag">' . __("You are logged in as a <strong>Membership Admin</strong> user, you will therefore see all protected content on this site.", 'membership') . '</div>';
  187. }
  188. }
  189. function add_admin_menu() {
  190. global $menu, $admin_page_hooks;
  191. if(current_user_can('membershipadmin')) {
  192. // Add the menu page
  193. add_menu_page(__('Membership','membership'), __('Membership','membership'), 'membershipadmin', 'membership', array(&$this,'handle_membership_panel'), membership_url('membershipincludes/images/members.png'));
  194. //echo $hook;
  195. // Fix WP translation hook issue
  196. if(isset($admin_page_hooks['membership'])) {
  197. $admin_page_hooks['membership'] = 'membership';
  198. }
  199. do_action('membership_add_menu_items_top');
  200. // Add the sub menu
  201. add_submenu_page('membership', __('Members','membership'), __('All Members','membership'), 'membershipadmin', "membershipmembers", array(&$this,'handle_members_panel'));
  202. do_action('membership_add_menu_items_after_members');
  203. add_submenu_page('membership', __('Membership Levels','membership'), __('Access Levels','membership'), 'membershipadmin', "membershiplevels", array(&$this,'handle_levels_panel'));
  204. do_action('membership_add_menu_items_after_levels');
  205. add_submenu_page('membership', __('Membership Subscriptions','membership'), __('Subscription Plans','membership'), 'membershipadmin', "membershipsubs", array(&$this,'handle_subs_panel'));
  206. do_action('membership_add_menu_items_after_subscriptions');
  207. add_submenu_page('membership', __('Membership Coupons','membership'), __('Coupons','membership'), 'membershipadmin', "membershipcoupons", array(&$this,'handle_coupons_panel'));
  208. do_action('membership_add_menu_items_after_coupons');
  209. //add_submenu_page('membership', __('Membership Purchases','membership'), __('Extra Purchases','membership'), 'membershipadmin', "membershippurchases", array(&$this,'handle_purchases_panel'));
  210. do_action('membership_add_menu_items_after_purchases');
  211. add_submenu_page('membership', __('Membership Communication','membership'), __('Communications','membership'), 'membershipadmin', "membershipcommunication", array(&$this,'handle_communication_panel'));
  212. do_action('membership_add_menu_items_after_communications');
  213. add_submenu_page('membership', __('Membership URL Groups','membership'), __('URL Groups','membership'), 'membershipadmin', "membershipurlgroups", array(&$this,'handle_urlgroups_panel'));
  214. do_action('membership_add_menu_items_after_urlgroups');
  215. add_submenu_page('membership', __('Membership Pings','membership'), __('Remote Pings','membership'), 'membershipadmin', "membershippings", array(&$this,'handle_pings_panel'));
  216. do_action('membership_add_menu_items_after_pings');
  217. add_submenu_page('membership', __('Membership Gateways','membership'), __('Payment Gateways','membership'), 'membershipadmin', "membershipgateways", array(&$this,'handle_gateways_panel'));
  218. do_action('membership_add_menu_items_after_gateways');
  219. add_submenu_page('membership', __('Membership Options','membership'), __('Options','membership'), 'membershipadmin', "membershipoptions", array(&$this,'handle_options_panel'));
  220. do_action('membership_add_menu_items_after_options');
  221. do_action('membership_add_menu_items_bottom');
  222. }
  223. }
  224. // Admin area protection
  225. function initialise_membership_protection() {
  226. global $user, $member, $M_options, $M_Rules, $wp_query, $wp_rewrite, $M_active;
  227. // Set up some common defaults
  228. static $initialised = false;
  229. if($initialised) {
  230. // ensure that this is only called once, so return if we've been here already.
  231. return;
  232. }
  233. $M_options = get_option('membership_options', array());
  234. // Check if the membership plugin is active
  235. $M_active = get_option('membership_active', 'no');
  236. if(empty($user) || !method_exists($user, 'has_cap')) {
  237. $user = wp_get_current_user();
  238. }
  239. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin') || $M_active == 'no') {
  240. // Admins can see everything
  241. return;
  242. }
  243. // Users
  244. $member = new M_Membership($user->ID);
  245. if($user->ID > 0 && $member->has_levels()) {
  246. // Load the levels for this member - and associated rules
  247. $member->load_admin_levels( true );
  248. } else {
  249. // need to grab the stranger settings
  250. if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
  251. $member->assign_admin_level($M_options['strangerlevel'], true );
  252. }
  253. }
  254. do_action('membership-admin-add-shortcodes');
  255. // Set the initialisation status
  256. $initialised = true;
  257. }
  258. // Add admin headers
  259. function add_admin_header_core() {
  260. // Add in help pages
  261. $screen = get_current_screen();
  262. $help = new M_Help( $screen );
  263. $help->attach();
  264. // Add in default style sheet with common styling elements
  265. wp_enqueue_style('defaultcss', membership_url('membershipincludes/css/default.css'), array(), $this->build);
  266. }
  267. function add_admin_header_membership() {
  268. // The dashboard - top level menu
  269. global $wp_version;
  270. // Load the core first
  271. $this->add_admin_header_core();
  272. wp_enqueue_script('dashjs', membership_url('membershipincludes/js/dashboard.js'), array( 'jquery' ), $this->build);
  273. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) {
  274. wp_enqueue_style('dashcss', membership_url('membershipincludes/css/dashboard.css'), array('widgets'), $this->build);
  275. } else {
  276. wp_enqueue_style('dashcss', membership_url('membershipincludes/css/dashboard.css'), array(), $this->build);
  277. }
  278. // Add localisation for the wizard
  279. wp_localize_script('dashjs', 'membershipwizard', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  280. 'membershiploading' => __('Loading...', 'membership'),
  281. 'membershipnextstep' => __('Next Step &raquo;','membership'),
  282. 'membershipgonewrong' => __('Something has gone wrong with the Wizard, please try clicking the button again.', 'membership'),
  283. 'membershiplevel' => __('Level', 'membership'),
  284. ));
  285. $this->handle_membership_dashboard_updates();
  286. }
  287. function add_admin_header_membershiplevels() {
  288. global $wp_version;
  289. $this->add_admin_header_core();
  290. wp_enqueue_script('levelsjs', membership_url('membershipincludes/js/levels.js'), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), $this->build);
  291. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) {
  292. wp_enqueue_style('levelscss', membership_url('membershipincludes/css/levels.css'), array('widgets'), $this->build);
  293. } else {
  294. wp_enqueue_style('levelscss', membership_url('membershipincludes/css/levels.css'), array(), $this->build);
  295. }
  296. wp_localize_script( 'levelsjs', 'membership', array( 'deletelevel' => __('Are you sure you want to delete this level?','membership'),
  297. 'deactivatelevel' => __('Are you sure you want to deactivate this level?','membership'),
  298. 'movetopositive' => __('Moving to the Positive area will remove any Negative rules you have set - is that ok?','membership'),
  299. 'movetonegative' => __('Moving to the Negative area will remove any Positive rules you have set - is that ok?','membership')
  300. ) );
  301. $this->handle_levels_updates();
  302. }
  303. function add_admin_header_membershipsubs() {
  304. global $wp_version;
  305. // Run the core header
  306. $this->add_admin_header_core();
  307. // Queue scripts and localise
  308. wp_enqueue_script('subsjs', membership_url('membershipincludes/js/subscriptions.js'), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), $this->build);
  309. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) {
  310. wp_enqueue_style('subscss', membership_url('membershipincludes/css/subscriptions.css'), array('widgets'), $this->build);
  311. } else {
  312. wp_enqueue_style('subscss', membership_url('membershipincludes/css/subscriptions.css'), array(), $this->build);
  313. }
  314. wp_localize_script( 'subsjs', 'membership', array( 'deletesub' => __('Are you sure you want to delete this subscription?','membership'), 'deactivatesub' => __('Are you sure you want to deactivate this subscription?','membership') ) );
  315. $this->handle_subscriptions_updates();
  316. }
  317. function add_admin_header_membershipcoupons() {
  318. global $wp_version;
  319. // Run the core header
  320. $this->add_admin_header_core();
  321. wp_enqueue_script( 'jquery-ui-datepicker' );
  322. wp_enqueue_script( 'jquery-ui-timepicker', membership_url('membershipincludes/js/datepicker/js/jquery.timepicker.min.js'), array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker') , $this->build );
  323. //only load languages for datepicker if not english (or it will show Chinese!)
  324. if ($this->language != 'en')
  325. wp_enqueue_script( 'jquery-datepicker-i18n', membership_url( 'membershipincludes/js/datepicker/js/datepicker-i18n.min.js'), array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), $this->build);
  326. wp_enqueue_style( 'jquery-datepicker-css', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery-ui.css', false, $this->build);
  327. // Queue scripts and localise
  328. wp_enqueue_script('couponsjs', membership_url('membershipincludes/js/coupons.js'), array(), $this->build);
  329. wp_enqueue_style('couponscss', membership_url('membershipincludes/css/coupons.css'), array(), $this->build);
  330. wp_localize_script( 'couponsjs', 'membership', array( 'deletecoupon' => __('Are you sure you want to delete this coupon?','membership'),
  331. 'setlangugae' => $this->language,
  332. 'start_of_week' => (get_option('start_of_week')=='0') ? 7 : get_option('start_of_week')
  333. ) );
  334. $this->handle_coupons_updates();
  335. }
  336. function add_admin_header_members() {
  337. global $wp_version;
  338. // Run the core header
  339. $this->add_admin_header_core();
  340. wp_enqueue_script('membersjs', membership_url('membershipincludes/js/members.js'), array(), $this->build);
  341. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) {
  342. // Using the level css file for now - maybe switch to a members specific one later
  343. wp_enqueue_style('memberscss', membership_url('membershipincludes/css/levels.css'), array('widgets'), $this->build);
  344. } else {
  345. // Using the level css file for now - maybe switch to a members specific one later
  346. wp_enqueue_style('memberscss', membership_url('membershipincludes/css/levels.css'), array(), $this->build);
  347. }
  348. wp_localize_script( 'membersjs', 'membership', array( 'deactivatemember' => __('Are you sure you want to deactivate this member?','membership') ) );
  349. $this->handle_members_updates();
  350. }
  351. function add_admin_header_membershipgateways() {
  352. $this->add_admin_header_core();
  353. $this->handle_gateways_panel_updates();
  354. }
  355. function add_admin_header_membershipoptions() {
  356. $this->add_admin_header_core();
  357. wp_enqueue_style('optionscss', membership_url('membershipincludes/css/options.css'), array(), $this->build);
  358. $this->handle_options_panel_updates();
  359. }
  360. function add_admin_header_membershipuser() {
  361. $this->add_admin_header_core();
  362. wp_enqueue_style('optionscss', membership_url('membershipincludes/css/options.css'), array(), $this->build);
  363. }
  364. function add_admin_header_membershipcommunication() {
  365. // Run the core header
  366. $this->add_admin_header_core();
  367. wp_enqueue_script('commsjs', membership_url('membershipincludes/js/communication.js'), array(), $this->build);
  368. wp_localize_script( 'commsjs', 'membership', array( 'deletecomm' => __('Are you sure you want to delete this message?','membership'), 'deactivatecomm' => __('Are you sure you want to deactivate this message?','membership') ) );
  369. $this->handle_communication_updates();
  370. }
  371. function add_admin_header_membershipurlgroups() {
  372. // Run the core header
  373. $this->add_admin_header_core();
  374. wp_enqueue_script('groupsjs', membership_url('membershipincludes/js/urlgroup.js'), array(), $this->build);
  375. wp_localize_script( 'groupsjs', 'membership', array( 'deletegroup' => __('Are you sure you want to delete this url group?','membership') ) );
  376. $this->handle_urlgroups_updates();
  377. }
  378. function add_admin_header_membershippings() {
  379. // Run the core header
  380. $this->add_admin_header_core();
  381. wp_enqueue_script('pingsjs', membership_url('membershipincludes/js/ping.js'), array(), $this->build);
  382. wp_localize_script( 'pingsjs', 'membership', array( 'deleteping' => __('Are you sure you want to delete this ping and the associated history?','membership') ) );
  383. $this->handle_ping_updates();
  384. }
  385. // Panel handling functions
  386. function build_signup_stats() {
  387. $sql = $this->db->prepare( "SELECT YEAR(startdate) as year, MONTH(startdate)as month, DAY(startdate) as day, count(*) AS signedup FROM {$this->membership_relationships} WHERE startdate > DATE_SUB(CURDATE(), INTERVAL %d DAY) GROUP BY YEAR(startdate), MONTH(startdate), DAY(startdate) ORDER BY startdate DESC", 10 );
  388. $results = $this->db->get_results( $sql );
  389. if(!empty($results)) {
  390. $stats = array();
  391. $ticks = array();
  392. $data = array();
  393. foreach($results as $key => $res) {
  394. $stats[strtotime($res->year . "-" . $res->month . "-" . $res->day)] = (int) $res->signedup;
  395. }
  396. $startat = time();
  397. for($n = 0; $n < 11; $n++) {
  398. $switch = 10 - $n;
  399. $rdate = strtotime('-' . $switch . ' DAYS', $startat);
  400. $ticks[$n] = '"' . date('n', $rdate) . "/" . date('j', $rdate) . '"';
  401. if(isset($stats[strtotime(date("Y", $rdate) . "-" . date("n", $rdate) . "-" . date("j", $rdate))])) {
  402. $data[$n] = $stats[strtotime(date("Y", $rdate) . "-" . date("n", $rdate) . "-" . date("j", $rdate))];
  403. } else {
  404. $data[$n] = 0;
  405. }
  406. }
  407. $stats = $data;
  408. return compact('stats', 'ticks');
  409. } else {
  410. return false;
  411. }
  412. }
  413. function build_levels_stats() {
  414. $sql = "SELECT l.id, l.level_title, count(m.rel_id) as users FROM {$this->membership_levels} as l, {$this->membership_relationships} as m WHERE l.id = m.level_id GROUP BY l.id, l.level_title ORDER BY users DESC";
  415. $results = $this->db->get_results( $sql );
  416. if(!empty($results)) {
  417. $stats = array();
  418. $ticks = array();
  419. foreach($results as $key => $res) {
  420. $stats[] = (int) $res->users;
  421. $ticks[] = '"' . esc_html($res->level_title) . '"';
  422. }
  423. return compact('stats', 'ticks');
  424. } else {
  425. return false;
  426. }
  427. }
  428. function build_subs_stats() {
  429. $sql = "SELECT s.id, s.sub_name, count(m.rel_id) as users FROM {$this->subscriptions} as s, {$this->membership_relationships} as m WHERE s.id = m.sub_id GROUP BY s.id, s.sub_name ORDER BY users DESC";
  430. $results = $this->db->get_results( $sql );
  431. if(!empty($results)) {
  432. $stats = array();
  433. $ticks = array();
  434. foreach($results as $key => $res) {
  435. $stats[] = (int) $res->users;
  436. $ticks[] = '"' . esc_html($res->sub_name) . '"';
  437. }
  438. return compact('stats', 'ticks');
  439. } else {
  440. return false;
  441. }
  442. }
  443. function get_data($results) {
  444. $data = array();
  445. foreach( (array) $results as $key => $res) {
  446. $data[] = "[ " . $key . ", " . $res . " ]";
  447. }
  448. return "[ " . implode(", ", $data) . " ]";
  449. }
  450. function handle_membership_dashboard_updates() {
  451. global $page, $action;
  452. wp_reset_vars( array('action', 'page') );
  453. switch($action) {
  454. case 'activate': check_admin_referer('toggle-plugin');
  455. update_option('membership_active', 'yes');
  456. wp_safe_redirect( wp_get_referer() );
  457. break;
  458. case 'deactivate': check_admin_referer('toggle-plugin');
  459. update_option('membership_active', 'no');
  460. wp_safe_redirect( wp_get_referer() );
  461. break;
  462. default: do_action('membership_dashboard_' . $action);
  463. break;
  464. }
  465. wp_enqueue_script('flot_js', membership_url('membershipincludes/js/jquery.flot.min.js'), array('jquery'));
  466. wp_enqueue_script('mdash_js', membership_url('membershipincludes/js/dashboard.js'), array('jquery'));
  467. wp_localize_script( 'mdash_js', 'membership', array( 'signups' => __('Signups','membership'), 'members' => __('Members','membership') ) );
  468. add_action ('admin_head', array(&$this, 'dashboard_iehead'));
  469. add_action ('admin_head', array(&$this, 'dashboard_chartdata'));
  470. }
  471. function dashboard_chartdata() {
  472. $returned = $this->build_signup_stats();
  473. $levels = $this->build_levels_stats();
  474. $subs = $this->build_subs_stats();
  475. echo "\n" . '<script type="text/javascript">';
  476. echo "\n" . '/* <![CDATA[ */ ' . "\n";
  477. echo "var membershipdata = {\n";
  478. echo "chartonestats : " . $this->get_data($returned['stats']) . ",\n";
  479. echo "chartoneticks : " . $this->get_data($returned['ticks']) . ",\n";
  480. echo "charttwostats : " . $this->get_data($levels['stats']) . ",\n";
  481. echo "charttwoticks : " . $this->get_data($levels['ticks']) . ",\n";
  482. echo "chartthreestats : " . $this->get_data($subs['stats']) . ",\n";
  483. echo "chartthreeticks : " . $this->get_data($subs['ticks']) . "\n";
  484. echo "};\n";
  485. echo "\n" . '/* ]]> */ ';
  486. echo '</script>';
  487. }
  488. function dashboard_iehead() {
  489. echo '<!--[if IE]><script language="javascript" type="text/javascript" src="' . membership_url('membershipincludes/js/excanvas.min.js') . '"></script><![endif]-->';
  490. }
  491. function dashboard_members() {
  492. global $page, $action;
  493. $plugin = get_plugin_data(membership_dir('membershippremium.php'));
  494. $membershipactive = M_get_membership_active();
  495. echo __('Membership protection ','membership');
  496. echo __(' is ', 'membership');
  497. // Membership active toggle
  498. if($membershipactive == 'no') {
  499. echo '<strong>' . __('disabled', 'membership') . '</strong> <a id="enablemembership" href="' . wp_nonce_url("?page=" . $page. "&amp;action=activate", 'toggle-plugin') . '" title="' . __('Click here to enable the plugin','membership') . '">' . __('[Enable it]','membership') . '</a>';
  500. } else {
  501. echo '<strong>' . __('enabled', 'membership') . '</strong> <a id="enablemembership" href="' . wp_nonce_url("?page=" . $page. "&amp;action=deactivate", 'toggle-plugin') . '" title="' . __('Click here to enable the plugin','membership') . '">' . __('[Disable it]','membership') . '</a>';
  502. }
  503. echo '<br/><br/>';
  504. echo "<strong>" . __('Member breakdown', 'membership') . "</strong><br/>";
  505. $detail = $this->get_subscriptions_and_levels(array('sub_status' => 'active'));
  506. $subs = $this->get_subscriptions(array('sub_status' => 'active'));
  507. $levels = $this->get_membership_levels(array('level_id' => 'active'));
  508. echo "<table style='width: 100%;'>";
  509. echo "<tbody>";
  510. echo "<tr>";
  511. echo "<td style='width: 48%' valign='top'>";
  512. if($levels) {
  513. $levelcount = 0;
  514. echo "<table style='width: 100%;'>";
  515. echo "<tbody>";
  516. echo "<tr>";
  517. echo "<td colspan='2'><strong>" . __('Levels','membership') . "</strong></td>";
  518. echo "</tr>";
  519. foreach($levels as $key => $level) {
  520. echo "<tr>";
  521. echo "<td><a href='" . admin_url('admin.php?page=membershiplevels&action=edit&level_id=') . $level->id . "'>" . esc_html($level->level_title) . "</a></td>";
  522. // find out how many people are in this level
  523. $thiscount = $this->count_on_level( $level->id );
  524. echo "<td style='text-align: right;'>" . (int) $thiscount . "</td>";
  525. $levelcount += (int) $thiscount;
  526. echo "</tr>";
  527. }
  528. echo "</tbody>";
  529. echo "</table>";
  530. }
  531. echo "</td>";
  532. echo "<td style='width: 48%' valign='top'>";
  533. if($subs) {
  534. $subcount = 0;
  535. echo "<table style='width: 100%;'>";
  536. echo "<tbody>";
  537. echo "<tr>";
  538. echo "<td colspan='2'><strong>" . __('Subscriptions','membership') . "</strong></td>";
  539. echo "</tr>";
  540. foreach($subs as $key => $sub) {
  541. echo "<tr>";
  542. echo "<td><a href='" . admin_url('admin.php?page=membershipsubs&action=edit&sub_id=') . $sub->id . "'>" . $sub->sub_name . "</a></td>";
  543. // find out how many people are in this sub
  544. $thiscount = $this->count_on_sub( $sub->id );
  545. echo "<td style='text-align: right;'>" . (int) $thiscount . "</td>";
  546. $subcount += (int) $thiscount;
  547. echo "</tr>";
  548. }
  549. echo "</tbody>";
  550. echo "</table>";
  551. }
  552. echo "</td>";
  553. echo "</tr>";
  554. echo "</tbody>";
  555. echo "</table>";
  556. echo "<br/><strong>" . __('Member counts', 'membership') . "</strong><br/>";
  557. echo "<table style='width: 100%;'>";
  558. echo "<tbody>";
  559. echo "<tr>";
  560. echo "<td style='width: 48%' valign='top'>";
  561. echo "<table style='width: 100%;'>";
  562. echo "<tbody>";
  563. $usercount = $this->db->get_var( "SELECT count(*) FROM {$this->db->users} INNER JOIN {$this->db->usermeta} ON {$this->db->users}.ID = {$this->db->usermeta}.user_id WHERE {$this->db->usermeta}.meta_key = '{$this->db->prefix}capabilities'" );
  564. echo "<tr>";
  565. echo "<td>" . __('Total Members', 'membership') . "</td>";
  566. echo "<td style='text-align: right;'>" . $usercount . "</td>";
  567. echo "</tr>";
  568. $deactivecount = $this->db->get_var( $this->db->prepare("SELECT count(*) FROM {$this->db->usermeta} WHERE meta_key = %s AND meta_value = %s", $this->db->prefix . 'membership_active' , 'no') );
  569. echo "<tr>";
  570. echo "<td>" . __('Deactivated Members', 'membership') . "</td>";
  571. echo "<td style='text-align: right;'>" . $deactivecount . "</td>";
  572. echo "</tr>";
  573. echo "</tbody>";
  574. echo "</table>";
  575. echo "</td>";
  576. echo "<td style='width: 48%' valign='top'></td>";
  577. echo "</tr>";
  578. echo "</tbody>";
  579. echo "</table>";
  580. }
  581. function dashboard_statistics() {
  582. echo "<div id='memchartone'></div>";
  583. echo "<div id='memcharttwo'></div>";
  584. echo "<div id='memchartthree'></div>";
  585. do_action( 'membership_dashboard_statistics' );
  586. }
  587. function handle_membership_panel() {
  588. ?>
  589. <div class='wrap nosubsub'>
  590. <div class="icon32" id="icon-index"><br></div>
  591. <h2><?php _e('Membership dashboard','membership'); ?></h2>
  592. <?php
  593. $this->potter->conditional_show();
  594. ?>
  595. <div id="dashboard-widgets-wrap">
  596. <div class="metabox-holder" id="dashboard-widgets">
  597. <div style="width: 49%;" class="postbox-container">
  598. <div class="meta-box-sortables ui-sortable" id="normal-sortables">
  599. <div class="postbox " id="dashboard_right_now">
  600. <h3 class="hndle"><span><?php _e('Members','membership'); ?></span></h3>
  601. <div class="inside">
  602. <?php $this->dashboard_members(); ?>
  603. <br class="clear">
  604. </div>
  605. </div>
  606. <?php
  607. do_action( 'membership_dashboard_left' );
  608. ?>
  609. </div>
  610. </div>
  611. <div style="width: 49%;" class="postbox-container">
  612. <div class="meta-box-sortables ui-sortable" id="side-sortables">
  613. <?php
  614. do_action( 'membership_dashboard_right_top' );
  615. ?>
  616. <div class="postbox " id="dashboard_quick_press">
  617. <h3 class="hndle"><span><?php _e('Statistics','membership'); ?></span></h3>
  618. <div class="inside">
  619. <?php $this->dashboard_statistics(); ?>
  620. <br class="clear">
  621. </div>
  622. </div>
  623. <?php
  624. do_action( 'membership_dashboard_right' );
  625. ?>
  626. </div>
  627. </div>
  628. <div style="display: none; width: 49%;" class="postbox-container">
  629. <div class="meta-box-sortables ui-sortable" id="column3-sortables" style="">
  630. </div>
  631. </div>
  632. <div style="display: none; width: 49%;" class="postbox-container">
  633. <div class="meta-box-sortables ui-sortable" id="column4-sortables" style="">
  634. </div>
  635. </div>
  636. </div>
  637. <div class="clear"></div>
  638. </div>
  639. </div> <!-- wrap -->
  640. <?php
  641. }
  642. function handle_members_updates() {
  643. global $action, $page;
  644. wp_reset_vars( array('action', 'page') );
  645. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) {
  646. if(addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') {
  647. $action = 'bulk-toggle';
  648. }
  649. }
  650. switch(addslashes($action)) {
  651. case 'removeheader': $this->dismiss_user_help( $page );
  652. wp_safe_redirect( remove_query_arg( 'action' ) );
  653. break;
  654. case 'toggle': if(isset($_GET['member_id'])) {
  655. $user_id = (int) $_GET['member_id'];
  656. check_admin_referer('toggle-member_' . $user_id);
  657. $member = new M_Membership($user_id);
  658. if( $member->toggle_activation() ) {
  659. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) );
  660. } else {
  661. wp_safe_redirect( add_query_arg( 'msg', 8, wp_get_referer() ) );
  662. }
  663. }
  664. break;
  665. case 'bulk-toggle':
  666. check_admin_referer('bulk-members');
  667. foreach($_GET['users'] AS $value) {
  668. if(is_numeric($value)) {
  669. $user_id = (int) $value;
  670. $member = new M_Membership($user_id);
  671. $member->toggle_activation();
  672. }
  673. }
  674. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) );
  675. break;
  676. case 'bulkaddlevel-level-complete':
  677. case 'addlevel-level-complete':
  678. check_admin_referer($action);
  679. $members_id = $_POST['member_id'];
  680. $members = explode(',', $members_id);
  681. if($members) {
  682. foreach($members as $member_id) {
  683. $member = new M_Membership($member_id);
  684. $tolevel_id = (int) $_POST['tolevel_id'];
  685. if($tolevel_id) {
  686. $member->add_level($tolevel_id);
  687. }
  688. }
  689. }
  690. $this->update_levelcounts();
  691. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  692. break;
  693. case 'bulkdroplevel-level-complete':
  694. case 'droplevel-level-complete':
  695. check_admin_referer($action);
  696. $members_id = $_POST['member_id'];
  697. $members = explode(',', $members_id);
  698. if($members) {
  699. foreach($members as $member_id) {
  700. $member = new M_Membership($member_id);
  701. $fromlevel_id = (int) $_POST['fromlevel_id'];
  702. if($fromlevel_id) {
  703. $member->drop_level($fromlevel_id);
  704. }
  705. }
  706. }
  707. $this->update_levelcounts();
  708. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  709. break;
  710. case 'bulkmovelevel-level-complete':
  711. case 'movelevel-level-complete':
  712. check_admin_referer($action);
  713. $members_id = $_POST['member_id'];
  714. $members = explode(',', $members_id);
  715. if($members) {
  716. foreach($members as $member_id) {
  717. $member = new M_Membership($member_id);
  718. $fromlevel_id = (int) $_POST['fromlevel_id'];
  719. $tolevel_id = (int) $_POST['tolevel_id'];
  720. if($fromlevel_id && $tolevel_id) {
  721. $member->move_level($fromlevel_id, $tolevel_id);
  722. }
  723. }
  724. }
  725. $this->update_levelcounts();
  726. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  727. break;
  728. case 'bulkaddsub-sub-complete':
  729. case 'addsub-sub-complete':
  730. check_admin_referer($action);
  731. $members_id = $_POST['member_id'];
  732. $members = explode(',', $members_id);
  733. if($members) {
  734. foreach($members as $member_id) {
  735. $member = new M_Membership($member_id);
  736. $tosub_id = $_POST['tosub_id'];
  737. if($tosub_id) {
  738. $subs = explode('-',$tosub_id);
  739. if(count($subs) == 3) {
  740. $member->add_subscription($subs[0], $subs[1], $subs[2]);
  741. }
  742. }
  743. }
  744. }
  745. $this->update_levelcounts();
  746. $this->update_subcounts();
  747. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  748. break;
  749. case 'bulkdropsub-sub-complete':
  750. case 'dropsub-sub-complete':
  751. check_admin_referer($action);
  752. $members_id = $_POST['member_id'];
  753. $members = explode(',', $members_id);
  754. if($members) {
  755. foreach($members as $member_id) {
  756. $member = new M_Membership($member_id);
  757. $fromsub_id = (int) $_POST['fromsub_id'];
  758. if($fromsub_id) {
  759. $member->drop_subscription($fromsub_id);
  760. }
  761. }
  762. }
  763. $this->update_levelcounts();
  764. $this->update_subcounts();
  765. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  766. break;
  767. case 'bulkmovesub-sub-complete':
  768. case 'movesub-sub-complete':
  769. check_admin_referer($action);
  770. $members_id = $_POST['member_id'];
  771. $members = explode(',', $members_id);
  772. if($members) {
  773. foreach($members as $member_id) {
  774. $member = new M_Membership($member_id);
  775. $fromsub_id = (int) $_POST['fromsub_id'];
  776. $tosub_id = $_POST['tosub_id'];
  777. if($fromsub_id && $tosub_id) {
  778. $subs = explode('-',$tosub_id);
  779. if(count($subs) == 3) {
  780. $member->move_subscription($fromsub_id, $subs[0], $subs[1], $subs[2]);
  781. }
  782. }
  783. }
  784. }
  785. $this->update_levelcounts();
  786. $this->update_subcounts();
  787. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  788. break;
  789. case 'bulkmovegateway-gateway-complete':
  790. case 'movegateway-gateway-complete':
  791. check_admin_referer($action);
  792. $members_id = $_POST['member_id'];
  793. $members = explode(',', $members_id);
  794. if($members) {
  795. foreach($members as $member_id) {
  796. $member = new M_Membership($member_id);
  797. $fromgateway = $_POST['fromgateway'];
  798. $togateway = $_POST['togateway'];
  799. if(!empty($fromgateway) && !empty($togateway)) {
  800. $relationships = $member->get_relationships();
  801. foreach($relationships as $rel) {
  802. if($rel->usinggateway == $fromgateway) {
  803. $member->update_relationship_gateway( $rel->rel_id, $fromgateway, $togateway );
  804. }
  805. }
  806. }
  807. }
  808. }
  809. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) );
  810. break;
  811. }
  812. }
  813. function handle_edit_member() {
  814. global $action, $page;
  815. wp_reset_vars( array('action', 'page') );
  816. }
  817. function handle_member_gateway_op( $operation = 'move', $member_id = false ) {
  818. global $action, $page, $action2, $M_Gateways;
  819. wp_reset_vars( array('action', 'page', 'action2') );
  820. if(empty($action) && !empty($action2)) $action = $action2;
  821. $gateways = apply_filters('M_gateways_list', array());
  822. $active = get_option('membership_activated_gateways', array());
  823. if(isset($_GET['fromgateway']) && !empty($_GET['fromgateway'])) {
  824. $fromgateway = stripslashes($_GET['fromgateway']);
  825. } else {
  826. $fromgateway = '';
  827. }
  828. switch($operation) {
  829. case 'move': $title = __('Move subscription to another gateway','membership');
  830. $formdescription = __('A subscription gateway handles the payment and renewal forms displayed for a subscription. Changing this should not be undertaken lightly, it can seriously mess up the subscriptions of your members.','membership') . "<br/><br/>";
  831. $html = "<h3>" . __('Gateway to move from for this / these member(s)','membership') . "</h3>";
  832. $html .= "<div class='level-details'>";
  833. $html .= "<select name='fromgateway' id='fromgateway' class='wide'>\n";
  834. $html .= "<option value='0'>" . __('Select the gateway to move from.','membership') . "</option>\n";
  835. $html .= "<option value='admin'>" . esc_html('admin' . " - " . "admin default gateway") . "</option>\n";
  836. if($gateways) {
  837. foreach($gateways as $key => $gateway) {
  838. if(in_array($key, $active)) {
  839. $html .= "<option value='" . esc_attr($key) . "'";
  840. if( $fromgateway == $key ) {
  841. $html .= " selected='selected'";
  842. }
  843. $html .= ">" . esc_html($key . " - " . $gateway) . "</option>\n";
  844. }
  845. }
  846. }
  847. $html .= "</select>\n";
  848. $html .= "</div>";
  849. $html .= "<h3>" . __('Gateway to move to for this / these member(s)','membership') . "</h3>";
  850. $html .= "<div class='level-details'>";
  851. $html .= "<select name='togateway' id='togateway' class='wide'>\n";
  852. $html .= "<option value='0'>" . __('Select the gateway to move to.','membership') . "</option>\n";
  853. $html .= "<option value='admin'>" . esc_html('admin' . " - " . "admin default gateway") . "</option>\n";
  854. reset($gateways);
  855. if($gateways) {
  856. foreach($gateways as $key => $gateway) {
  857. if(in_array($key, $active)) {
  858. $html .= "<option value='" . esc_attr($key) . "'>" . esc_html($key . " - " . $gateway) . "</option>\n";
  859. }
  860. }
  861. }
  862. $html .= "</select>\n";
  863. $html .= "</div>";
  864. $button = "Move";
  865. break;
  866. }
  867. ?>
  868. <div class='wrap nosubsub'>
  869. <div class="icon32" id="icon-users"><br></div>
  870. <h2><?php echo $title; ?></h2>
  871. <form action='admin.php?page=<?php echo $page; ?>' method='post'>
  872. <div class='level-liquid-left'>
  873. <div id='level-left'>
  874. <div id='edit-level' class='level-holder-wrap'>
  875. <div class='sidebar-name no-movecursor'>
  876. <h3><?php echo esc_html($title); ?></h3>
  877. </div>
  878. <div class='level-holder'>
  879. <br />
  880. <p class='description'><?php echo $formdescription; ?></p>
  881. <?php
  882. echo $html;
  883. ?>
  884. <div class='buttons'>
  885. <?php
  886. wp_original_referer_field(true, 'previous'); wp_nonce_field($action . '-gateway-complete');
  887. ?>
  888. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a>
  889. <input type='submit' value='<?php _e($button, 'membership'); ?>' class='button-primary' />
  890. <input type='hidden' name='action' value='<?php esc_attr_e($action . '-gateway-complete'); ?>' />
  891. <?php
  892. if(is_array($member_id)) {
  893. ?>
  894. <input type='hidden' name='member_id' value='<?php esc_attr_e(implode(',',$member_id)); ?>' />
  895. <?php
  896. } else {
  897. ?>
  898. <input type='hidden' name='member_id' value='<?php esc_attr_e($member_id); ?>' />
  899. <?php
  900. }
  901. ?>
  902. </div>
  903. </div>
  904. </div>
  905. </div>
  906. </div> <!-- level-liquid-left -->
  907. </form>
  908. </div> <!-- wrap -->
  909. <?php
  910. }
  911. function handle_member_level_op($operation = 'add', $member_id = false) {
  912. global $action, $page, $action2;
  913. wp_reset_vars( array('action', 'page', 'action2') );
  914. if(empty($action) && !empty($action2)) $action = $action2;
  915. if(isset($_GET['fromlevel']) && !empty($_GET['fromlevel'])) {
  916. $fromlevel = $_GET['fromlevel'];
  917. } else {
  918. $fromlevel = '';
  919. }
  920. switch($operation) {
  921. case 'add': $title = __('Add member to a level','membership');
  922. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.','membership') . "<br/><br/>";
  923. $formdescription .= __('By adding a membership level, you may actually be removing existing access to content.','membership');
  924. $html = "<h3>" . __('Level to add for this / these member(s)','membership') . "</h3>";
  925. $html .= "<div class='level-details'>";
  926. $html .= "<select name='tolevel_id' id='tolevel_id' class='wide'>\n";
  927. $html .= "<option value='0'>" . __('Select the level to add.','membership') . "</option>\n";
  928. $levels = $this->get_membership_levels(array('level_id' => 'active'));
  929. if($levels) {
  930. foreach($levels as $key => $level) {
  931. $html .= "<option value='" . esc_attr($level->id) . "'";
  932. $html .= ">" . esc_html($level->level_title) . "</option>\n";
  933. }
  934. }
  935. $html .= "</select>\n";
  936. $html .= "</div>";
  937. $button = "Add";
  938. break;
  939. case 'move': $title = __('Move member to another level','membership');
  940. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.','membership') . "<br/><br/>";
  941. $html = "<h3>" . __('Level to move from for this / these member(s)','membership') . "</h3>";
  942. $html .= "<div class='level-details'>";
  943. $html .= "<select name='fromlevel_id' id='fromlevel_id' class='wide'>\n";
  944. $html .= "<option value='0'>" . __('Select the level to move from.','membership') . "</option>\n";
  945. $levels = $this->get_membership_levels(array('level_id' => 'active'));
  946. if($levels) {
  947. foreach($levels as $key => $level) {
  948. $html .= "<option value='" . esc_attr($level->id) . "'";
  949. if($fromlevel == $level->id) $html .= " selected='selected'";
  950. $html .= ">" . esc_html($level->level_title) . "</option>\n";
  951. }
  952. }
  953. $html .= "</select>\n";
  954. $html .= "</div>";
  955. $html .= "<h3>" . __('Level to move to for this / these member(s)','membership') . "</h3>";
  956. $html .= "<div class='level-details'>";
  957. $html .= "<select name='tolevel_id' id='tolevel_id' class='wide'>\n";
  958. $html .= "<option value='0'>" . __('Select the level to move to.','membership') . "</option>\n";
  959. reset($levels);
  960. if($levels) {
  961. foreach($levels as $key => $level) {
  962. $html .= "<option value='" . esc_attr($level->id) . "'";
  963. $html .= ">" . esc_html($level->level_title) . "</option>\n";
  964. }
  965. }
  966. $html .= "</select>\n";
  967. $html .= "</div>";
  968. $button = "Move";
  969. break;
  970. case 'drop': $title = __('Drop member from level','membership');
  971. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.','membership') . "<br/><br/>";
  972. $formdescription .= __('By removing a membership level, you may actually be increasing existing access to content.','membership');
  973. $html = "<h3>" . __('Level to drop for this / these member(s)','membership') . "</h3>";
  974. $html .= "<div class='level-details'>";
  975. $html .= "<select name='fromlevel_id' id='fromlevel_id' class='wide'>\n";
  976. $html .= "<option value=''>" . __('Select the level to remove.','membership') . "</option>\n";
  977. $levels = $this->get_membership_levels(array('level_id' => 'active'));
  978. if($levels) {
  979. foreach($levels as $key => $level) {
  980. $html .= "<option value='" . esc_attr($level->id) . "'";
  981. if($fromlevel == $level->id) $html .= " selected='selected'";
  982. $html .= ">" . esc_html($level->level_title) . "</option>\n";
  983. }
  984. }
  985. $html .= "</select>\n";
  986. $html .= "</div>";
  987. $button = "Drop";
  988. break;
  989. }
  990. ?>
  991. <div class='wrap nosubsub'>
  992. <div class="icon32" id="icon-users"><br></div>
  993. <h2><?php echo $title; ?></h2>
  994. <form action='admin.php?page=<?php echo $page; ?>' method='post'>
  995. <div class='level-liq…

Large files files are truncated, but you can click here to view the full file