membershipadmin

The Membership 2 membershipadmin class.

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/classes/membershipadmin.php  
  1. class membershipadmin { 
  2.  
  3. var $build = 14; 
  4. var $db; 
  5.  
  6. // 
  7. var $showposts = 25; 
  8. var $showpages = 100; 
  9.  
  10. var $tables = array('membership_levels', 'membership_rules', 'subscriptions', 'subscriptions_levels', 'membership_relationships', 'membermeta', 'communications', 'urlgroups', 'ping_history', 'pings', 'coupons'); 
  11.  
  12. var $membership_levels; 
  13. var $membership_rules; 
  14. var $membership_relationships; 
  15. var $subscriptions; 
  16. var $subscriptions_levels; 
  17. var $membermeta; 
  18. var $communications; 
  19. var $urlgroups; 
  20. var $ping_history; 
  21. var $pings; 
  22. var $coupons; 
  23.  
  24. // Class variable to hold a link to the tooltips class 
  25. var $_tips; 
  26.  
  27. // The Wizard 
  28. var $potter; 
  29.  
  30. // The tutorial 
  31. var $tutorial; 
  32.  
  33. // Coupons 
  34. var $_coupons; 
  35.  
  36. // For the coupons datepicker 
  37. var $language; 
  38.  
  39.  
  40. function __construct() { 
  41.  
  42. global $wpdb; 
  43.  
  44. $this->db =& $wpdb; 
  45.  
  46. foreach($this->tables as $table) { 
  47. $this->$table = membership_db_prefix($this->db, $table); 
  48.  
  49. // Instantiate the tooltips class and set the icon 
  50. $this->_tips = new WpmuDev_HelpTooltips(); 
  51. $this->_tips->set_icon_url(membership_url('membershipincludes/images/information.png')); 
  52.  
  53. // Initiate the wizard class 
  54. $this->potter = new M_Wizard(); 
  55.  
  56. // Add administration actions 
  57. add_action('init', array(&$this, 'initialise_plugin'), 1); 
  58.  
  59. // Add in admin area membership levels 
  60. add_action('init', array(&$this, 'initialise_membership_protection'), 999); 
  61.  
  62. if( (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('membership/membership.php')) && (defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true)) { 
  63. add_action('network_admin_menu', array(&$this, 'add_admin_menu')); 
  64. } else { 
  65. add_action('admin_menu', array(&$this, 'add_admin_menu')); 
  66.  
  67. add_action( 'plugins_loaded', array(&$this, 'load_textdomain')); 
  68.  
  69. // Header actions for users page 
  70. add_action( 'load-users.php', array(&$this, 'add_header_users_page')); 
  71.  
  72. // Custom header actions 
  73. add_action('load-toplevel_page_membership', array(&$this, 'add_admin_header_membership')); 
  74. add_action('load-membership_page_membershipmembers', array(&$this, 'add_admin_header_members')); 
  75. add_action('load-membership_page_membershiplevels', array(&$this, 'add_admin_header_membershiplevels')); 
  76. add_action('load-membership_page_membershipsubs', array(&$this, 'add_admin_header_membershipsubs')); 
  77. add_action('load-membership_page_membershipcoupons', array(&$this, 'add_admin_header_membershipcoupons')); 
  78. add_action('load-membership_page_membershipgateways', array(&$this, 'add_admin_header_membershipgateways')); 
  79. add_action('load-membership_page_membershipoptions', array(&$this, 'add_admin_header_membershipoptions')); 
  80. add_action('load-membership_page_membershipcommunication', array(&$this, 'add_admin_header_membershipcommunication')); 
  81. add_action('load-membership_page_membershipurlgroups', array(&$this, 'add_admin_header_membershipurlgroups')); 
  82. add_action('load-membership_page_membershippings', array(&$this, 'add_admin_header_membershippings')); 
  83.  
  84. add_action('load-users_page_membershipuser', array(&$this, 'add_admin_header_membershipuser')); 
  85.  
  86. add_filter('membership_level_sections', array(&$this, 'default_membership_sections')); 
  87.  
  88. // Media management additional fields 
  89. add_filter('attachment_fields_to_edit', array(&$this, 'add_media_protection_settings'), 99, 2); 
  90. add_filter('attachment_fields_to_save', array(&$this, 'save_media_protection_settings'), 99, 2); 
  91.  
  92. // rewrites 
  93. add_action('generate_rewrite_rules', array(&$this, 'add_rewrites')); 
  94. add_filter('query_vars', array(&$this, 'add_queryvars') ); 
  95.  
  96. // profile field for feeds 
  97. add_action('show_user_profile', array(&$this, 'add_profile_feed_key') ); 
  98.  
  99. // Pings 
  100. add_action('membership_subscription_form_after_levels', array(&$this, 'show_subscription_ping_information')); 
  101. add_action('membership_subscription_add', array(&$this, 'update_subscription_ping_information')); 
  102. add_action('membership_subscription_update', array(&$this, 'update_subscription_ping_information')); 
  103.  
  104. add_action('membership_level_form_after_rules', array(&$this, 'show_level_ping_information')); 
  105. add_action('membership_level_add', array(&$this, 'update_level_ping_information')); 
  106. add_action('membership_level_update', array(&$this, 'update_level_ping_information')); 
  107.  
  108. // Ajax calls have to go here because admin-ajax.php is an admin call even though we're calling it from the front end. 
  109. add_action( 'wp_ajax_nopriv_buynow', array(&$this, 'popover_signup_form') ); 
  110.  
  111. //login and register are no-priv only because, well they aren't logged in or registered 
  112. add_action( 'wp_ajax_nopriv_register_user', array(&$this, 'popover_register_process') ); 
  113. add_action( 'wp_ajax_nopriv_login_user', array(&$this, 'popover_login_process') ); 
  114.  
  115. // if logged in: 
  116. add_action( 'wp_ajax_buynow', array(&$this, 'popover_sendpayment_form') ); 
  117. add_action( 'wp_ajax_extra_form', array(&$this, 'popover_extraform_process') ); 
  118. add_action( 'wp_ajax_register_user', array(&$this, 'popover_register_process') ); 
  119. add_action( 'wp_ajax_login_user', array(&$this, 'popover_login_process') ); 
  120.  
  121. // Helper actions 
  122. add_action( 'membership_activate_addon', array(&$this, 'activate_addon'), 10, 1 ); 
  123. add_action( 'membership_deactivate_addon', array(&$this, 'deactivate_addon'), 10, 1 ); 
  124.  
  125. // Level shortcodes filters 
  126. add_filter( 'membership_level_shortcodes', array(&$this, 'build_level_shortcode_list' ) ); 
  127.  
  128. add_action( 'plugins_loaded', array(&$this, 'load_tutorial'), 11); //init tutorial after translation loaded 
  129.  
  130.  
  131. // Remove relationships when user gets deleted 
  132. add_action( 'delete_user', array(&$this, 'remove_relationships_on_delete' ) ); 
  133.  
  134.  
  135.  
  136. function membershipadmin() { 
  137. $this->__construct(); 
  138.  
  139. function load_textdomain() { 
  140.  
  141. $locale = apply_filters( 'membership_locale', get_locale() ); 
  142. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" ); 
  143.  
  144. if ( file_exists( $mofile ) ) { 
  145. load_textdomain( 'membership', $mofile ); 
  146.  
  147. //setup language code for jquery datepicker translation 
  148. $temp_locales = explode('_', get_locale()); 
  149. $this->language = ($temp_locales[0]) ? $temp_locales[0] : 'en'; 
  150.  
  151.  
  152. function load_tutorial() { 
  153. // Add in pointer tutorial 
  154. $this->tutorial = new M_Tutorial(); 
  155. $this->tutorial->serve(); 
  156.  
  157. function initialise_plugin() { 
  158.  
  159. global $user, $M_options; 
  160.  
  161. $installed = get_option('M_Installed', false); 
  162.  
  163. if(empty($user) || !method_exists($user, 'has_cap')) { 
  164. $user = wp_get_current_user(); 
  165.  
  166. if($installed === false || $installed != $this->build) { 
  167. include_once(membership_dir('membershipincludes/classes/upgrade.php') ); 
  168.  
  169. M_Upgrade($installed); 
  170. update_option('M_Installed', $this->build); 
  171.  
  172. // Add in our new capability 
  173. if(!$user->has_cap('membershipadmin') && defined('MEMBERSHIP_SETACTIVATORAS_ADMIN') && MEMBERSHIP_SETACTIVATORAS_ADMIN == 'yes') { 
  174. $user->add_cap('membershipadmin'); 
  175.  
  176. $this->create_defaults(); 
  177.  
  178. // Add in our new capability 
  179. if($user->user_login == MEMBERSHIP_MASTER_ADMIN && !$user->has_cap('membershipadmin')) { 
  180. $user->add_cap('membershipadmin'); 
  181.  
  182. // Update the membership capabillities for the new layout 
  183. if($user->has_cap('membershipadmin') && !$user->has_cap('membershipadminupdatepermissions') ) { 
  184. // We are here is the user has the old permissions but doesn't have the new default dashboard permissions 
  185. // Which likely means that they have not been upgraded - so let's do that :) 
  186.  
  187. $updated = get_user_meta( $user->ID, 'membership_permissions_updated', true ); 
  188.  
  189. if(empty($updated) || $updated != 'yes') { 
  190. $user->add_cap('membershipadmindashboard'); 
  191. $user->add_cap('membershipadminmembers'); 
  192. $user->add_cap('membershipadminlevels'); 
  193. $user->add_cap('membershipadminsubscriptions'); 
  194. $user->add_cap('membershipadmincoupons'); 
  195. $user->add_cap('membershipadminpurchases'); 
  196. $user->add_cap('membershipadmincommunications'); 
  197. $user->add_cap('membershipadmingroups'); 
  198. $user->add_cap('membershipadminpings'); 
  199. $user->add_cap('membershipadmingateways'); 
  200. $user->add_cap('membershipadminoptions'); 
  201. // New permissions setting 
  202. $user->add_cap('membershipadminupdatepermissions'); 
  203.  
  204. update_user_meta( $user->ID, 'membership_permissions_updated', 'yes'); 
  205.  
  206.  
  207. if($user->has_cap('membershipadminupdatepermissions')) { 
  208. // user permissions on the user form 
  209. add_filter( 'manage_users_columns', array(&$this, 'add_user_permissions_column') ); 
  210. add_filter( 'wpmu_users_columns', array(&$this, 'add_user_permissions_column') ); 
  211. add_filter( 'manage_users_custom_column', array(&$this, 'show_user_permissions_column'), 10, 3 ); 
  212.  
  213. add_action( 'wp_ajax_editusermembershippermissions', array(&$this, 'edit_user_permissions') ); 
  214.  
  215. if($user->has_cap('membershipadmin')) { 
  216. // If the user is a membershipadmin user then we can add in notices 
  217. add_action('all_admin_notices', array(&$this, 'show_membership_status_notice')); 
  218.  
  219. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  220. if(function_exists('get_blog_option')) { 
  221. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  222. } else { 
  223. $M_options = get_option('membership_options', array()); 
  224. } else { 
  225. $M_options = get_option('membership_options', array()); 
  226.  
  227. // Short codes 
  228. if(!empty($M_options['membershipshortcodes'])) { 
  229. foreach($M_options['membershipshortcodes'] as $key => $value) { 
  230. if(!empty($value)) { 
  231. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_fake_shortcode') ); 
  232.  
  233. // Admin only Shortcodes setup 
  234. if(!empty($M_options['membershipadminshortcodes'])) { 
  235. foreach($M_options['membershipadminshortcodes'] as $key => $value) { 
  236. if(!empty($value)) { 
  237. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_fake_shortcode') ); 
  238.  
  239. do_action('membership_register_shortcodes'); 
  240.  
  241. add_action( 'wp_ajax_m_set_coupon', array(&$this, 'set_membership_coupon_cookie')); 
  242. add_action( 'wp_ajax_nopriv_m_set_coupon', array(&$this, 'set_membership_coupon_cookie')); 
  243.  
  244.  
  245. function add_user_permissions_column( $columns ) { 
  246. $columns['membershippermissions'] = __('Permissions', 'membership'); 
  247.  
  248. return $columns; 
  249.  
  250. function show_user_permissions_column( $content, $column_name, $user_id ) { 
  251.  
  252. if($column_name == 'membershippermissions') { 
  253. // We are on our column 
  254. $theuser = get_user_by( 'id', $user_id ); 
  255.  
  256. $perms = array(); 
  257. if( $theuser->has_cap('membershipadmindashboard') ) { 
  258. $perms[] = __('Dashboard', 'membership'); 
  259. if( $theuser->has_cap('membershipadminmembers') ) { 
  260. $perms[] = __('Members', 'membership'); 
  261. if( $theuser->has_cap('membershipadminlevels') ) { 
  262. $perms[] = __('Levels', 'membership'); 
  263. if( $theuser->has_cap('membershipadminsubscriptions') ) { 
  264. $perms[] = __('Subscriptions', 'membership'); 
  265. if( $theuser->has_cap('membershipadmincoupons') ) { 
  266. $perms[] = __('Coupons', 'membership'); 
  267.  
  268. if( $theuser->has_cap('membershipadminpurchases') ) { 
  269. $perms[] = __('Purchases', 'membership'); 
  270. if( $theuser->has_cap('membershipadmincommunications') ) { 
  271. $perms[] = __('Communications', 'membership'); 
  272. if( $theuser->has_cap('membershipadmingroups') ) { 
  273. $perms[] = __('URL Groups', 'membership'); 
  274. if( $theuser->has_cap('membershipadminpings') ) { 
  275. $perms[] = __('Pings', 'membership'); 
  276. if( $theuser->has_cap('membershipadmingateways') ) { 
  277. $perms[] = __('Gateways', 'membership'); 
  278.  
  279. if( $theuser->has_cap('membershipadminoptions') ) { 
  280. $perms[] = __('Options', 'membership'); 
  281.  
  282. if( $theuser->has_cap('membershipadminupdatepermissions') ) { 
  283. $perms[] = __('Permissions', 'membership'); 
  284.  
  285.  
  286. if(empty($perms)) { 
  287. $perms[] = __('None', 'membership'); 
  288.  
  289. $content .= implode( ', ', $perms ); 
  290.  
  291. $content .= '<div class="row-actions">'; 
  292. $content .= '<span class="edit">'; 
  293. $content .= '<a class="membershipeditlink" href="' . wp_nonce_url( admin_url("admin-ajax.php?action=editusermembershippermissions&user_id=" . $user_id . ""), 'edit_user_membership_' . $user_id) . '">' . __('Edit', 'membership') . '</a>'; 
  294. $content .= '</span>'; 
  295. $content .= '</div>'; 
  296.  
  297. /** 
  298. if($user->has_cap('membershipadmin') && !$user->has_cap('membershipadmincoupons') ) { 
  299. // We are here is the user has the old permissions but doesn't have the new default dashboard permissions 
  300. // Which likely means that they have not been upgraded - so let's do that :) 
  301. $user->add_cap('membershipadmindashboard'); 
  302. $user->add_cap('membershipadminmembers'); 
  303. $user->add_cap('membershipadminlevels'); 
  304. $user->add_cap('membershipadminsubscriptions'); 
  305. $user->add_cap('membershipadmincoupons'); 
  306. $user->add_cap('membershipadminpurchases'); 
  307. $user->add_cap('membershipadmincommunications'); 
  308. $user->add_cap('membershipadmingroups'); 
  309. $user->add_cap('membershipadminpings'); 
  310. $user->add_cap('membershipadmingateways'); 
  311. $user->add_cap('membershipadminoptions'); 
  312. */ 
  313.  
  314.  
  315.  
  316. return $content; 
  317.  
  318.  
  319. // Code from this function based on code from AJAX Media Upload function 
  320. function edit_user_permissions() { 
  321.  
  322. _wp_admin_html_begin(); 
  323. ?> 
  324. <title><?php _e('Post Indexer Settings', 'postindexer'); ?></title> 
  325. <?php 
  326.  
  327. wp_enqueue_style( 'colors' ); 
  328. //wp_enqueue_style( 'media' ); 
  329. //wp_enqueue_style( 'ie' ); 
  330. wp_enqueue_script( 'jquery' ); 
  331.  
  332. do_action('admin_print_styles'); 
  333. do_action('admin_print_scripts'); 
  334. do_action('admin_head'); 
  335.  
  336. ?> 
  337. </head> 
  338. <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js"> 
  339. <script type="text/javascript"> 
  340. document.body.className = document.body.className.replace('no-js', 'js'); 
  341. </script> 
  342. <?php 
  343. $this->edit_users_permissions_content(); 
  344.  
  345. do_action('admin_print_footer_scripts'); 
  346. ?> 
  347. <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> 
  348. </body> 
  349. </html> 
  350. <?php 
  351. exit; 
  352.  
  353. function edit_users_permissions_content() { 
  354.  
  355. if( !isset($_GET['user_id'])) { 
  356. wp_die( __( 'Cheatin’ uh?' ) ); 
  357. } else { 
  358.  
  359. $user_id = $_GET['user_id']; 
  360. check_admin_referer( 'edit_user_membership_' . $user_id ); 
  361.  
  362. ?> 
  363. <form action="" class="" id="membership-form" method='get'> 
  364.  
  365. <input type='hidden' name='action' value='updatemembershippermissionsesettings' /> 
  366. <input type='hidden' name='user_id' value='<?php echo $user_id; ?>' /> 
  367. <input type='hidden' name='comefrom' value='<?php echo esc_attr( wp_get_referer() ); ?>' /> 
  368. <?php 
  369. wp_nonce_field('membership_update_permissions_settings_' . $user_id); 
  370. ?> 
  371.  
  372. <h3 class="media-title"><?php echo __("Membership Permissions", "membership"); ?></h3> 
  373. <p class='description'><?php _e('Select the areas you want this user to be able to administrate.', 'membership'); ?></p> 
  374.  
  375. <table> 
  376. <tbody> 
  377. <tr> 
  378. <th style='min-width: 150px; vertical-align: top;'><?php _e('Current Permissions', 'membership'); ?></th> 
  379. <td> 
  380. <?php 
  381. $theuser = get_user_by( 'id', $user_id ); 
  382.  
  383. $perms = array(); 
  384. if( $theuser->has_cap('membershipadmindashboard') ) { 
  385. $perms[] = 'dashboard'; 
  386. if( $theuser->has_cap('membershipadminmembers') ) { 
  387. $perms[] = 'members'; 
  388. if( $theuser->has_cap('membershipadminlevels') ) { 
  389. $perms[] = 'levels'; 
  390. if( $theuser->has_cap('membershipadminsubscriptions') ) { 
  391. $perms[] = 'subscriptions'; 
  392. if( $theuser->has_cap('membershipadmincoupons') ) { 
  393. $perms[] = 'coupons'; 
  394. if( $theuser->has_cap('membershipadminpurchases') ) { 
  395. $perms[] = 'purchases'; 
  396. if( $theuser->has_cap('membershipadmincommunications') ) { 
  397. $perms[] = 'communications'; 
  398. if( $theuser->has_cap('membershipadmingroups') ) { 
  399. $perms[] = 'urlgroups'; 
  400. if( $theuser->has_cap('membershipadminpings') ) { 
  401. $perms[] = 'pings'; 
  402. if( $theuser->has_cap('membershipadmingateways') ) { 
  403. $perms[] = 'gateways'; 
  404. if( $theuser->has_cap('membershipadminoptions') ) { 
  405. $perms[] = 'options'; 
  406. if( $theuser->has_cap('membershipadminupdatepermissions') ) { 
  407. $perms[] = 'permissions'; 
  408.  
  409.  
  410. $headings = array(); 
  411. $headings['dashboard'] = __('Dashboard', 'membership'); 
  412. $headings['members'] = __('Members', 'membership'); 
  413. $headings['levels'] = __('Levels', 'membership'); 
  414. $headings['subscriptions'] = __('Subscriptions', 'membership'); 
  415. $headings['coupons'] = __('Coupons', 'membership'); 
  416. $headings['purchases'] = __('Purchases', 'membership'); 
  417. $headings['communications'] = __('Communications', 'membership'); 
  418. $headings['urlgroups'] = __('URL Groups', 'membership'); 
  419. $headings['pings'] = __('Pings', 'membership'); 
  420. $headings['gateways'] = __('Gateways', 'membership'); 
  421. $headings['options'] = __('Options', 'membership'); 
  422. $headings['permissions'] = __('Permissions', 'membership'); 
  423.  
  424. ?> 
  425. <ul style='margin:0; padding:0;'> 
  426. <?php 
  427. foreach($headings as $heading => $label) { 
  428. ?> 
  429. <li><label><input style='margin-top: 0; margin-right: 5px;' type='checkbox' name='membership_permission[]' value='<?php echo $heading; ?>' <?php if(in_array($heading, $perms)) { echo "checked='checked'"; } ?> /> <?php echo $label; ?></label></li> 
  430. <?php 
  431. ?> 
  432. </ul> 
  433. <?php 
  434.  
  435. ?> 
  436. </td> 
  437. </tr> 
  438. </tbody> 
  439. </table> 
  440.  
  441.  
  442. <p class="savebutton ml-submit"> 
  443. <input name="save" id="save" class="button-primary" value="<?php _e('Save all changes', 'postindexer'); ?>" type="submit"> 
  444. </p> 
  445. </form> 
  446.  
  447. <?php 
  448.  
  449.  
  450. function show_membership_status_notice() { 
  451.  
  452. global $user, $M_options; 
  453.  
  454. // Membership active check 
  455. $membershipactive = M_get_membership_active(); 
  456. if($membershipactive == 'no') { 
  457. 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&action=activate", 'toggle-plugin')) . '</p></div>'; 
  458.  
  459. // Membership admin check 
  460. if(empty($user) || !method_exists($user, 'has_cap')) { 
  461. $user = wp_get_current_user(); 
  462.  
  463. if($user->has_cap('membershipadmin')) { 
  464. // Show a notice to say that they are logged in as the membership admin user and protection isn't enabled on the front end 
  465. 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>'; 
  466.  
  467.  
  468.  
  469. function add_admin_menu() { 
  470.  
  471. global $menu, $admin_page_hooks; 
  472.  
  473. if(current_user_can('membershipadmindashboard')) { 
  474. // Add the menu page 
  475. add_menu_page(__('Membership', 'membership'), __('Membership', 'membership'), 'membershipadmindashboard', 'membership', array(&$this, 'handle_membership_panel'), membership_url('membershipincludes/images/members.png')); 
  476. //echo $hook; 
  477. // Fix WP translation hook issue 
  478. if(isset($admin_page_hooks['membership'])) { 
  479. $admin_page_hooks['membership'] = 'membership'; 
  480.  
  481. do_action('membership_add_menu_items_top'); 
  482. // Add the sub menu 
  483. add_submenu_page('membership', __('Members', 'membership'), __('All Members', 'membership'), 'membershipadminmembers', "membershipmembers", array(&$this, 'handle_members_panel')); 
  484. do_action('membership_add_menu_items_after_members'); 
  485.  
  486. add_submenu_page('membership', __('Membership Levels', 'membership'), __('Access Levels', 'membership'), 'membershipadminlevels', "membershiplevels", array(&$this, 'handle_levels_panel')); 
  487. do_action('membership_add_menu_items_after_levels'); 
  488.  
  489. add_submenu_page('membership', __('Membership Subscriptions', 'membership'), __('Subscription Plans', 'membership'), 'membershipadminsubscriptions', "membershipsubs", array(&$this, 'handle_subs_panel')); 
  490. do_action('membership_add_menu_items_after_subscriptions'); 
  491.  
  492. add_submenu_page('membership', __('Membership URL Groups', 'membership'), __('URL Groups', 'membership'), 'membershipadmingroups', "membershipurlgroups", array(&$this, 'handle_urlgroups_panel')); 
  493. do_action('membership_add_menu_items_after_urlgroups'); 
  494.  
  495. add_submenu_page('membership', __('Membership Pings', 'membership'), __('Remote Pings', 'membership'), 'membershipadminpings', "membershippings", array(&$this, 'handle_pings_panel')); 
  496. do_action('membership_add_menu_items_after_pings'); 
  497.  
  498. add_submenu_page('membership', __('Membership Gateways', 'membership'), __('Payment Gateways', 'membership'), 'membershipadmingateways', "membershipgateways", array(&$this, 'handle_gateways_panel')); 
  499. do_action('membership_add_menu_items_after_gateways'); 
  500.  
  501. add_submenu_page('membership', __('Membership Options', 'membership'), __('Options', 'membership'), 'membershipadminoptions', "membershipoptions", array(&$this, 'handle_options_panel')); 
  502. do_action('membership_add_menu_items_after_options'); 
  503.  
  504. do_action('membership_add_menu_items_bottom'); 
  505.  
  506.  
  507.  
  508. // Admin area protection 
  509. function initialise_membership_protection() { 
  510.  
  511. global $user, $member, $M_options, $M_Rules, $wp_query, $wp_rewrite, $M_active; 
  512. // Set up some common defaults 
  513.  
  514. static $initialised = false; 
  515.  
  516. if($initialised) { 
  517. // ensure that this is only called once, so return if we've been here already. 
  518. return; 
  519.  
  520. $M_options = get_option('membership_options', array()); 
  521. // Check if the membership plugin is active 
  522. $M_active = get_option('membership_active', 'no'); 
  523.  
  524. if(empty($user) || !method_exists($user, 'has_cap')) { 
  525. $user = wp_get_current_user(); 
  526.  
  527. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin') || $M_active == 'no') { 
  528. // Admins can see everything 
  529. return; 
  530.  
  531. // Users 
  532. $member = new M_Membership($user->ID); 
  533.  
  534. if($user->ID > 0 && $member->has_levels()) { 
  535. // Load the levels for this member - and associated rules 
  536. $member->load_admin_levels( true ); 
  537. } else { 
  538. // need to grab the stranger settings 
  539. if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) { 
  540. $member->assign_admin_level($M_options['strangerlevel'], true ); 
  541.  
  542. do_action('membership-admin-add-shortcodes'); 
  543.  
  544. // Set the initialisation status 
  545. $initialised = true; 
  546.  
  547.  
  548. // Add admin headers 
  549.  
  550. function add_admin_header_core() { 
  551.  
  552. // Add in help pages 
  553. $screen = get_current_screen(); 
  554. $help = new M_Help( $screen ); 
  555. $help->attach(); 
  556.  
  557. // Add in default style sheet with common styling elements 
  558. wp_enqueue_style('defaultcss', membership_url('membershipincludes/css/default.css'), array(), $this->build); 
  559.  
  560.  
  561. function add_header_users_page() { 
  562.  
  563. wp_enqueue_script('thickbox'); 
  564.  
  565. wp_register_script('membership-users-js', membership_url('membershipincludes/js/users.js'), array('jquery', 'thickbox')); 
  566. wp_enqueue_script('membership-users-js'); 
  567.  
  568. wp_localize_script('membership-users-js', 'membership', array( 'useredittitle' => __('Membership Permissions', 'membership') )); 
  569. wp_enqueue_style('thickbox'); 
  570.  
  571. $this->process_users_page(); 
  572.  
  573. function process_users_page() { 
  574.  
  575. if( isset( $_GET['action'] ) ) { 
  576. switch( $_GET['action'] ) { 
  577. case 'updatemembershippermissionsesettings': 
  578.  
  579. $user_id = $_GET['user_id']; 
  580. //check_admin_referer( 'membership_update_permissions_settings_' . $user_id ); 
  581. $theuser = get_user_by( 'id', $user_id ); 
  582.  
  583.  
  584. if(!empty( $_GET['membership_permission'] )) { 
  585. $new = (array) $_GET['membership_permission']; 
  586. } else { 
  587. $new = array(); 
  588.  
  589. if( in_array('dashboard', $new ) ) { 
  590. $theuser->add_cap('membershipadmindashboard'); 
  591. } else { 
  592. $theuser->remove_cap('membershipadmindashboard'); 
  593. if( in_array('members', $new ) ) { 
  594. $theuser->add_cap('membershipadminmembers'); 
  595. } else { 
  596. $theuser->remove_cap('membershipadminmembers'); 
  597. if( in_array('levels', $new ) ) { 
  598. $theuser->add_cap('membershipadminlevels'); 
  599. } else { 
  600. $theuser->remove_cap('membershipadminlevels'); 
  601. if( in_array('subscriptions', $new ) ) { 
  602. $theuser->add_cap('membershipadminsubscriptions'); 
  603. } else { 
  604. $theuser->remove_cap('membershipadminsubscriptions'); 
  605. if( in_array('coupons', $new ) ) { 
  606. $theuser->add_cap('membershipadmincoupons'); 
  607. } else { 
  608. $theuser->remove_cap('membershipadmincoupons'); 
  609. if( in_array('purchases', $new ) ) { 
  610. $theuser->add_cap('membershipadminpurchases'); 
  611. } else { 
  612. $theuser->remove_cap('membershipadminpurchases'); 
  613. if( in_array('communications', $new ) ) { 
  614. $theuser->add_cap('membershipadmincommunications'); 
  615. } else { 
  616. $theuser->remove_cap('membershipadmincommunications'); 
  617. if( in_array('urlgroups', $new ) ) { 
  618. $theuser->add_cap('membershipadmingroups'); 
  619. } else { 
  620. $theuser->remove_cap('membershipadmingroups'); 
  621. if( in_array('pings', $new ) ) { 
  622. $theuser->add_cap('membershipadminpings'); 
  623. } else { 
  624. $theuser->remove_cap('membershipadminpings'); 
  625. if( in_array('gateways', $new ) ) { 
  626. $theuser->add_cap('membershipadmingateways'); 
  627. } else { 
  628. $theuser->remove_cap('membershipadmingateways'); 
  629. if( in_array('options', $new ) ) { 
  630. $theuser->add_cap('membershipadminoptions'); 
  631. } else { 
  632. $theuser->remove_cap('membershipadminoptions'); 
  633.  
  634. if( in_array('permissions', $new ) ) { 
  635. $theuser->add_cap('membershipadminupdatepermissions'); 
  636. } else { 
  637. $theuser->remove_cap('membershipadminupdatepermissions'); 
  638.  
  639. wp_safe_redirect( $_GET['comefrom'] ); 
  640. break; 
  641.  
  642.  
  643. function add_admin_header_membership() { 
  644. // The dashboard - top level menu 
  645.  
  646. global $wp_version; 
  647.  
  648. // Load the core first 
  649. $this->add_admin_header_core(); 
  650.  
  651. wp_enqueue_script('dashjs', membership_url('membershipincludes/js/dashboard.js'), array( 'jquery' ), $this->build); 
  652.  
  653. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) { 
  654. wp_enqueue_style('dashcss', membership_url('membershipincludes/css/dashboard.css'), array('widgets'), $this->build); 
  655. } else { 
  656. wp_enqueue_style('dashcss', membership_url('membershipincludes/css/dashboard.css'), array(), $this->build); 
  657. // Add localisation for the wizard 
  658. wp_localize_script('dashjs', 'membershipwizard', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  659. 'membershiploading' => __('Loading...', 'membership'),  
  660. 'membershipnextstep' => __('Next Step »', 'membership'),  
  661. 'membershipgonewrong' => __('Something has gone wrong with the Wizard, please try clicking the button again.', 'membership'),  
  662. 'membershiplevel' => __('Level', 'membership'),  
  663. )); 
  664.  
  665. $this->handle_membership_dashboard_updates(); 
  666.  
  667. function add_admin_header_membershiplevels() { 
  668.  
  669. global $wp_version; 
  670.  
  671. $this->add_admin_header_core(); 
  672.  
  673. wp_enqueue_script('levelsjs', membership_url('membershipincludes/js/levels.js'), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), $this->build); 
  674.  
  675. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) { 
  676. wp_enqueue_style('levelscss', membership_url('membershipincludes/css/levels.css'), array('widgets'), $this->build); 
  677. } else { 
  678. wp_enqueue_style('levelscss', membership_url('membershipincludes/css/levels.css'), array(), $this->build); 
  679.  
  680. wp_localize_script( 'levelsjs', 'membership', array( 'deletelevel' => __('Are you sure you want to delete this level?', 'membership'),  
  681. 'deactivatelevel' => __('Are you sure you want to deactivate this level?', 'membership'),  
  682. 'movetopositive' => __('Moving to the Positive area will remove any Negative rules you have set - is that ok?', 'membership'),  
  683. 'movetonegative' => __('Moving to the Negative area will remove any Positive rules you have set - is that ok?', 'membership') 
  684. ) ); 
  685.  
  686. $this->handle_levels_updates(); 
  687.  
  688. function add_admin_header_membershipsubs() { 
  689.  
  690. global $wp_version; 
  691. // Run the core header 
  692. $this->add_admin_header_core(); 
  693.  
  694. // Queue scripts and localise 
  695. wp_enqueue_script('subsjs', membership_url('membershipincludes/js/subscriptions.js'), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), $this->build); 
  696.  
  697. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) { 
  698. wp_enqueue_style('subscss', membership_url('membershipincludes/css/subscriptions.css'), array('widgets'), $this->build); 
  699. } else { 
  700. wp_enqueue_style('subscss', membership_url('membershipincludes/css/subscriptions.css'), array(), $this->build); 
  701.  
  702. 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') ) ); 
  703.  
  704. $this->handle_subscriptions_updates(); 
  705.  
  706.  
  707. function add_admin_header_members() { 
  708.  
  709. global $wp_version; 
  710. // Run the core header 
  711. $this->add_admin_header_core(); 
  712.  
  713. wp_enqueue_script('membersjs', membership_url('membershipincludes/js/members.js'), array(), $this->build); 
  714.  
  715. if(version_compare( preg_replace('/-.*$/', '', $wp_version), "3.3", '<')) { 
  716. // Using the level css file for now - maybe switch to a members specific one later 
  717. wp_enqueue_style('memberscss', membership_url('membershipincludes/css/levels.css'), array('widgets'), $this->build); 
  718. } else { 
  719. // Using the level css file for now - maybe switch to a members specific one later 
  720. wp_enqueue_style('memberscss', membership_url('membershipincludes/css/levels.css'), array(), $this->build); 
  721.  
  722. wp_localize_script( 'membersjs', 'membership', array( 'deactivatemember' => __('Are you sure you want to deactivate this member?', 'membership') ) ); 
  723.  
  724.  
  725. $this->handle_members_updates(); 
  726.  
  727.  
  728. function add_admin_header_membershipgateways() { 
  729. $this->add_admin_header_core(); 
  730.  
  731. $this->handle_gateways_panel_updates(); 
  732.  
  733. function add_admin_header_membershipoptions() { 
  734. $this->add_admin_header_core(); 
  735.  
  736. wp_enqueue_style('optionscss', membership_url('membershipincludes/css/options.css'), array(), $this->build); 
  737.  
  738. $this->handle_options_panel_updates(); 
  739.  
  740. function add_admin_header_membershipuser() { 
  741. $this->add_admin_header_core(); 
  742.  
  743. wp_enqueue_style('optionscss', membership_url('membershipincludes/css/options.css'), array(), $this->build); 
  744.  
  745. function add_admin_header_membershipurlgroups() { 
  746. // Run the core header 
  747. $this->add_admin_header_core(); 
  748.  
  749. wp_enqueue_script('groupsjs', membership_url('membershipincludes/js/urlgroup.js'), array(), $this->build); 
  750. wp_localize_script( 'groupsjs', 'membership', array( 'deletegroup' => __('Are you sure you want to delete this url group?', 'membership') ) ); 
  751.  
  752.  
  753. $this->handle_urlgroups_updates(); 
  754.  
  755. function add_admin_header_membershippings() { 
  756. // Run the core header 
  757. $this->add_admin_header_core(); 
  758.  
  759. wp_enqueue_script('pingsjs', membership_url('membershipincludes/js/ping.js'), array(), $this->build); 
  760. wp_localize_script( 'pingsjs', 'membership', array( 'deleteping' => __('Are you sure you want to delete this ping and the associated history?', 'membership') ) ); 
  761.  
  762. $this->handle_ping_updates(); 
  763.  
  764. // Panel handling functions 
  765.  
  766. function build_signup_stats() { 
  767.  
  768. $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 ); 
  769.  
  770. $results = $this->db->get_results( $sql ); 
  771.  
  772. if(!empty($results)) { 
  773.  
  774. $stats = array(); 
  775. $ticks = array(); 
  776. $data = array(); 
  777. foreach($results as $key => $res) { 
  778.  
  779. $stats[strtotime($res->year . "-" . $res->month . "-" . $res->day)] = (int) $res->signedup; 
  780.  
  781.  
  782. $startat = time(); 
  783. for($n = 0; $n < 11; $n++) { 
  784. $switch = 10 - $n; 
  785. $rdate = strtotime('-' . $switch . ' DAYS', $startat); 
  786.  
  787. $ticks[$n] = '"' . date('n', $rdate) . "/" . date('j', $rdate) . '"'; 
  788.  
  789. if(isset($stats[strtotime(date("Y", $rdate) . "-" . date("n", $rdate) . "-" . date("j", $rdate))])) { 
  790. $data[$n] = $stats[strtotime(date("Y", $rdate) . "-" . date("n", $rdate) . "-" . date("j", $rdate))]; 
  791. } else { 
  792. $data[$n] = 0; 
  793.  
  794. $stats = $data; 
  795.  
  796. return compact('stats', 'ticks'); 
  797.  
  798. } else { 
  799. return false; 
  800.  
  801.  
  802. function build_levels_stats() { 
  803.  
  804. $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"; 
  805.  
  806. $results = $this->db->get_results( $sql ); 
  807.  
  808. if(!empty($results)) { 
  809.  
  810. $stats = array(); 
  811. $ticks = array(); 
  812. foreach($results as $key => $res) { 
  813.  
  814. $stats[] = (int) $res->users; 
  815. $ticks[] = '"' . esc_html($res->level_title) . '"'; 
  816.  
  817. return compact('stats', 'ticks'); 
  818.  
  819. } else { 
  820. return false; 
  821.  
  822.  
  823. function build_subs_stats() { 
  824.  
  825. $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"; 
  826.  
  827. $results = $this->db->get_results( $sql ); 
  828.  
  829. if(!empty($results)) { 
  830.  
  831. $stats = array(); 
  832. $ticks = array(); 
  833. foreach($results as $key => $res) { 
  834.  
  835. $stats[] = (int) $res->users; 
  836. $ticks[] = '"' . esc_html($res->sub_name) . '"'; 
  837.  
  838. return compact('stats', 'ticks'); 
  839.  
  840. } else { 
  841. return false; 
  842.  
  843.  
  844. function get_data($results) { 
  845.  
  846. $data = array(); 
  847.  
  848. foreach( (array) $results as $key => $res) { 
  849. $data[] = "[ " . $key . ", " . $res . " ]"; 
  850.  
  851. return "[ " . implode(", ", $data) . " ]"; 
  852.  
  853.  
  854. function handle_membership_dashboard_updates() { 
  855.  
  856. global $page, $action; 
  857.  
  858. wp_reset_vars( array('action', 'page') ); 
  859.  
  860. switch($action) { 
  861.  
  862. case 'activate': check_admin_referer('toggle-plugin'); 
  863. update_option('membership_active', 'yes'); 
  864. wp_safe_redirect( wp_get_referer() ); 
  865. break; 
  866.  
  867. case 'deactivate': check_admin_referer('toggle-plugin'); 
  868. update_option('membership_active', 'no'); 
  869. wp_safe_redirect( wp_get_referer() ); 
  870. break; 
  871.  
  872. default: do_action('membership_dashboard_' . $action); 
  873. break; 
  874.  
  875.  
  876. wp_enqueue_script('flot_js', membership_url('membershipincludes/js/jquery.flot.min.js'), array('jquery')); 
  877. wp_enqueue_script('mdash_js', membership_url('membershipincludes/js/dashboard.js'), array('jquery')); 
  878.  
  879. wp_localize_script( 'mdash_js', 'membership', array( 'signups' => __('Signups', 'membership'), 'members' => __('Members', 'membership') ) ); 
  880.  
  881.  
  882. add_action ('admin_head', array(&$this, 'dashboard_iehead')); 
  883. add_action ('admin_head', array(&$this, 'dashboard_chartdata')); 
  884.  
  885.  
  886. function dashboard_chartdata() { 
  887. $returned = $this->build_signup_stats(); 
  888. $levels = $this->build_levels_stats(); 
  889. $subs = $this->build_subs_stats(); 
  890.  
  891. echo "\n" . '<script type="text/javascript">'; 
  892. echo "\n" . '/* <![CDATA[ */ ' . "\n"; 
  893.  
  894. echo "var membershipdata = {\n"; 
  895. echo "chartonestats : " . $this->get_data($returned['stats']) . ", \n"; 
  896. echo "chartoneticks : " . $this->get_data($returned['ticks']) . ", \n"; 
  897.  
  898. echo "charttwostats : " . $this->get_data($levels['stats']) . ", \n"; 
  899. echo "charttwoticks : " . $this->get_data($levels['ticks']) . ", \n"; 
  900.  
  901. echo "chartthreestats : " . $this->get_data($subs['stats']) . ", \n"; 
  902. echo "chartthreeticks : " . $this->get_data($subs['ticks']) . "\n"; 
  903. echo "};\n"; 
  904.  
  905. echo "\n" . '/* ]]> */ '; 
  906. echo '</script>'; 
  907.  
  908. function dashboard_iehead() { 
  909. echo '<!--[if IE]><script language="javascript" type="text/javascript" src="' . membership_url('membershipincludes/js/excanvas.min.js') . '"></script><![endif]-->'; 
  910.  
  911. function dashboard_members() { 
  912.  
  913. global $page, $action; 
  914.  
  915. $plugin = get_plugin_data(membership_dir('membership.php')); 
  916.  
  917. $membershipactive = M_get_membership_active(); 
  918.  
  919. echo __('Membership protection ', 'membership'); 
  920. echo __(' is ', 'membership'); 
  921.  
  922. // Membership active toggle 
  923. if($membershipactive == 'no') { 
  924. echo '<strong>' . __('disabled', 'membership') . '</strong> <a id="enablemembership" href="' . wp_nonce_url("?page=" . $page. "&action=activate", 'toggle-plugin') . '" title="' . __('Click here to enable the plugin', 'membership') . '">' . __('[Enable it]', 'membership') . '</a>'; 
  925. } else { 
  926. echo '<strong>' . __('enabled', 'membership') . '</strong> <a id="enablemembership" href="' . wp_nonce_url("?page=" . $page. "&action=deactivate", 'toggle-plugin') . '" title="' . __('Click here to enable the plugin', 'membership') . '">' . __('[Disable it]', 'membership') . '</a>'; 
  927.  
  928. echo '<br/><br/>'; 
  929.  
  930. echo "<strong>" . __('Member breakdown', 'membership') . "</strong><br/>"; 
  931.  
  932. $detail = $this->get_subscriptions_and_levels(array('sub_status' => 'active')); 
  933. $subs = $this->get_subscriptions(array('sub_status' => 'active')); 
  934.  
  935. $levels = $this->get_membership_levels(array('level_id' => 'active')); 
  936.  
  937. echo "<table style='width: 100%;'>"; 
  938. echo "<tbody>"; 
  939. echo "<tr>"; 
  940. echo "<td style='width: 48%' valign='top'>"; 
  941. if($levels) { 
  942. $levelcount = 0; 
  943. echo "<table style='width: 100%;'>"; 
  944. echo "<tbody>"; 
  945. echo "<tr>"; 
  946. echo "<td colspan='2'><strong>" . __('Levels', 'membership') . "</strong></td>"; 
  947. echo "</tr>"; 
  948. foreach($levels as $key => $level) { 
  949. echo "<tr>"; 
  950. echo "<td><a href='" . admin_url('admin.php?page=membershiplevels&action=edit&level_id=') . $level->id . "'>" . esc_html($level->level_title) . "</a></td>"; 
  951. // find out how many people are in this level 
  952. $thiscount = $this->count_on_level( $level->id ); 
  953.  
  954. echo "<td style='text-align: right;'>" . (int) $thiscount . "</td>"; 
  955. $levelcount += (int) $thiscount; 
  956. echo "</tr>"; 
  957. echo "</tbody>"; 
  958. echo "</table>"; 
  959. echo "</td>"; 
  960.  
  961. echo "<td style='width: 48%' valign='top'>"; 
  962. if($subs) { 
  963. $subcount = 0; 
  964. echo "<table style='width: 100%;'>"; 
  965. echo "<tbody>"; 
  966. echo "<tr>"; 
  967. echo "<td colspan='2'><strong>" . __('Subscriptions', 'membership') . "</strong></td>"; 
  968. echo "</tr>"; 
  969. foreach($subs as $key => $sub) { 
  970. echo "<tr>"; 
  971. echo "<td><a href='" . admin_url('admin.php?page=membershipsubs&action=edit&sub_id=') . $sub->id . "'>" . $sub->sub_name . "</a></td>"; 
  972. // find out how many people are in this sub 
  973. $thiscount = $this->count_on_sub( $sub->id ); 
  974.  
  975. echo "<td style='text-align: right;'>" . (int) $thiscount . "</td>"; 
  976. $subcount += (int) $thiscount; 
  977. echo "</tr>"; 
  978. echo "</tbody>"; 
  979. echo "</table>"; 
  980. echo "</td>"; 
  981.  
  982. echo "</tr>"; 
  983. echo "</tbody>"; 
  984. echo "</table>"; 
  985.  
  986. echo "<br/><strong>" . __('Member counts', 'membership') . "</strong><br/>"; 
  987.  
  988. echo "<table style='width: 100%;'>"; 
  989. echo "<tbody>"; 
  990. echo "<tr>"; 
  991. echo "<td style='width: 48%' valign='top'>"; 
  992.  
  993. echo "<table style='width: 100%;'>"; 
  994. echo "<tbody>"; 
  995.  
  996. $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'" ); 
  997.  
  998. echo "<tr>"; 
  999. echo "<td>" . __('Total Members', 'membership') . "</td>"; 
  1000. echo "<td style='text-align: right;'>" . $usercount . "</td>"; 
  1001. echo "</tr>"; 
  1002.  
  1003. $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') ); 
  1004.  
  1005. echo "<tr>"; 
  1006. echo "<td>" . __('Deactivated Members', 'membership') . "</td>"; 
  1007. echo "<td style='text-align: right;'>" . $deactivecount . "</td>"; 
  1008. echo "</tr>"; 
  1009.  
  1010. echo "</tbody>"; 
  1011. echo "</table>"; 
  1012.  
  1013. echo "</td>"; 
  1014.  
  1015. echo "<td style='width: 48%' valign='top'></td>"; 
  1016.  
  1017. echo "</tr>"; 
  1018. echo "</tbody>"; 
  1019. echo "</table>"; 
  1020.  
  1021.  
  1022. function dashboard_statistics() { 
  1023.  
  1024. echo "<div id='memchartone'></div>"; 
  1025. echo "<div id='memcharttwo'></div>"; 
  1026. echo "<div id='memchartthree'></div>"; 
  1027.  
  1028. do_action( 'membership_dashboard_statistics' ); 
  1029.  
  1030. function handle_membership_panel() { 
  1031.  
  1032. ?> 
  1033. <div class='wrap nosubsub'> 
  1034. <div class="icon32" id="icon-index"><br></div> 
  1035. <h2><?php _e('Membership dashboard', 'membership'); ?></h2> 
  1036.  
  1037. <?php 
  1038. $this->potter->conditional_show(); 
  1039. ?> 
  1040.  
  1041. <div id="dashboard-widgets-wrap"> 
  1042.  
  1043. <div class="metabox-holder" id="dashboard-widgets"> 
  1044. <div style="width: 49%;" class="postbox-container"> 
  1045. <div class="meta-box-sortables ui-sortable" id="normal-sortables"> 
  1046.  
  1047. <div class="postbox " id="dashboard_right_now"> 
  1048. <h3 class="hndle"><span><?php _e('Members', 'membership'); ?></span></h3> 
  1049. <div class="inside"> 
  1050. <?php $this->dashboard_members(); ?> 
  1051. <br class="clear"> 
  1052. </div> 
  1053. </div> 
  1054.  
  1055. <?php 
  1056. do_action( 'membership_dashboard_left' ); 
  1057. ?> 
  1058. </div> 
  1059. </div> 
  1060.  
  1061. <div style="width: 49%;" class="postbox-container"> 
  1062. <div class="meta-box-sortables ui-sortable" id="side-sortables"> 
  1063.  
  1064. <?php 
  1065. do_action( 'membership_dashboard_right_top' ); 
  1066. ?> 
  1067.  
  1068. <div class="postbox " id="dashboard_quick_press"> 
  1069. <h3 class="hndle"><span><?php _e('Statistics', 'membership'); ?></span></h3> 
  1070. <div class="inside"> 
  1071. <?php $this->dashboard_statistics(); ?> 
  1072. <br class="clear"> 
  1073. </div> 
  1074. </div> 
  1075.  
  1076. <?php 
  1077. do_action( 'membership_dashboard_right' ); 
  1078. ?> 
  1079.  
  1080. </div> 
  1081. </div> 
  1082.  
  1083. <div style="display: none; width: 49%;" class="postbox-container"> 
  1084. <div class="meta-box-sortables ui-sortable" id="column3-sortables" style=""> 
  1085. </div> 
  1086. </div> 
  1087.  
  1088. <div style="display: none; width: 49%;" class="postbox-container"> 
  1089. <div class="meta-box-sortables ui-sortable" id="column4-sortables" style=""> 
  1090. </div> 
  1091. </div> 
  1092. </div> 
  1093.  
  1094. <div class="clear"></div> 
  1095. </div> 
  1096.  
  1097. </div> <!-- wrap --> 
  1098. <?php 
  1099.  
  1100.  
  1101. function handle_members_updates() { 
  1102.  
  1103. global $action, $page; 
  1104.  
  1105. wp_reset_vars( array('action', 'page') ); 
  1106.  
  1107. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  1108. if(addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') { 
  1109. $action = 'bulk-toggle'; 
  1110.  
  1111. switch(addslashes($action)) { 
  1112.  
  1113. case 'removeheader': $this->dismiss_user_help( $page ); 
  1114. wp_safe_redirect( remove_query_arg( 'action' ) ); 
  1115. break; 
  1116.  
  1117. case 'toggle': if(isset($_GET['member_id'])) { 
  1118. $user_id = (int) $_GET['member_id']; 
  1119.  
  1120. check_admin_referer('toggle-member_' . $user_id); 
  1121.  
  1122. $member = new M_Membership($user_id); 
  1123.  
  1124. if( $member->toggle_activation() ) { 
  1125. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  1126. } else { 
  1127. wp_safe_redirect( add_query_arg( 'msg', 8, wp_get_referer() ) ); 
  1128.  
  1129. break; 
  1130.  
  1131. case 'bulk-toggle': 
  1132. check_admin_referer('bulk-members'); 
  1133. foreach($_GET['users'] AS $value) { 
  1134. if(is_numeric($value)) { 
  1135. $user_id = (int) $value; 
  1136.  
  1137. $member = new M_Membership($user_id); 
  1138.  
  1139. $member->toggle_activation(); 
  1140.  
  1141. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  1142. break; 
  1143.  
  1144. case 'bulkaddlevel-level-complete': 
  1145. case 'addlevel-level-complete': 
  1146. check_admin_referer($action); 
  1147. $members_id = $_POST['member_id']; 
  1148.  
  1149. $members = explode(', ', $members_id); 
  1150. if($members) { 
  1151. foreach($members as $member_id) { 
  1152. $member = new M_Membership($member_id); 
  1153.  
  1154. $tolevel_id = (int) $_POST['tolevel_id']; 
  1155. if($tolevel_id) { 
  1156. $member->add_level($tolevel_id); 
  1157.  
  1158. $this->update_levelcounts(); 
  1159.  
  1160. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1161. break; 
  1162.  
  1163. case 'bulkdroplevel-level-complete': 
  1164. case 'droplevel-level-complete': 
  1165. check_admin_referer($action); 
  1166. $members_id = $_POST['member_id']; 
  1167.  
  1168. $members = explode(', ', $members_id); 
  1169. if($members) { 
  1170. foreach($members as $member_id) { 
  1171. $member = new M_Membership($member_id); 
  1172.  
  1173. $fromlevel_id = (int) $_POST['fromlevel_id']; 
  1174. if($fromlevel_id) { 
  1175. $member->drop_level($fromlevel_id); 
  1176.  
  1177. $this->update_levelcounts(); 
  1178.  
  1179. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1180. break; 
  1181.  
  1182. case 'bulkmovelevel-level-complete': 
  1183. case 'movelevel-level-complete': 
  1184. check_admin_referer($action); 
  1185. $members_id = $_POST['member_id']; 
  1186.  
  1187. $members = explode(', ', $members_id); 
  1188. if($members) { 
  1189. foreach($members as $member_id) { 
  1190. $member = new M_Membership($member_id); 
  1191.  
  1192. $fromlevel_id = (int) $_POST['fromlevel_id']; 
  1193. $tolevel_id = (int) $_POST['tolevel_id']; 
  1194. if($fromlevel_id && $tolevel_id) { 
  1195. $member->move_level($fromlevel_id, $tolevel_id); 
  1196.  
  1197. $this->update_levelcounts(); 
  1198.  
  1199. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1200. break; 
  1201.  
  1202. case 'bulkaddsub-sub-complete': 
  1203. case 'addsub-sub-complete': 
  1204. check_admin_referer($action); 
  1205. $members_id = $_POST['member_id']; 
  1206.  
  1207. $members = explode(', ', $members_id); 
  1208. if($members) { 
  1209. foreach($members as $member_id) { 
  1210. $member = new M_Membership($member_id); 
  1211.  
  1212. $tosub_id = $_POST['tosub_id']; 
  1213. if($tosub_id) { 
  1214. $subs = explode('-', $tosub_id); 
  1215. if(count($subs) == 3) { 
  1216. $member->add_subscription($subs[0], $subs[1], $subs[2]); 
  1217.  
  1218. $this->update_levelcounts(); 
  1219. $this->update_subcounts(); 
  1220.  
  1221. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1222. break; 
  1223.  
  1224. case 'bulkdropsub-sub-complete': 
  1225. case 'dropsub-sub-complete': 
  1226. check_admin_referer($action); 
  1227. $members_id = $_POST['member_id']; 
  1228.  
  1229. $members = explode(', ', $members_id); 
  1230. if($members) { 
  1231. foreach($members as $member_id) { 
  1232. $member = new M_Membership($member_id); 
  1233.  
  1234. $fromsub_id = (int) $_POST['fromsub_id']; 
  1235. if($fromsub_id) { 
  1236. $member->drop_subscription($fromsub_id); 
  1237.  
  1238. $this->update_levelcounts(); 
  1239. $this->update_subcounts(); 
  1240.  
  1241. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1242. break; 
  1243.  
  1244. case 'bulkmovesub-sub-complete': 
  1245. case 'movesub-sub-complete': 
  1246. check_admin_referer($action); 
  1247. $members_id = $_POST['member_id']; 
  1248.  
  1249. $members = explode(', ', $members_id); 
  1250. if($members) { 
  1251. foreach($members as $member_id) { 
  1252. $member = new M_Membership($member_id); 
  1253.  
  1254. $fromsub_id = (int) $_POST['fromsub_id']; 
  1255. $tosub_id = $_POST['tosub_id']; 
  1256. if($fromsub_id && $tosub_id) { 
  1257. $subs = explode('-', $tosub_id); 
  1258. if(count($subs) == 3) { 
  1259. $member->move_subscription($fromsub_id, $subs[0], $subs[1], $subs[2]); 
  1260.  
  1261. $this->update_levelcounts(); 
  1262. $this->update_subcounts(); 
  1263.  
  1264. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1265. break; 
  1266.  
  1267. case 'bulkmovegateway-gateway-complete': 
  1268. case 'movegateway-gateway-complete': 
  1269.  
  1270. check_admin_referer($action); 
  1271. $members_id = $_POST['member_id']; 
  1272.  
  1273. $members = explode(', ', $members_id); 
  1274. if($members) { 
  1275. foreach($members as $member_id) { 
  1276. $member = new M_Membership($member_id); 
  1277.  
  1278. $fromgateway = $_POST['fromgateway']; 
  1279. $togateway = $_POST['togateway']; 
  1280. if(!empty($fromgateway) && !empty($togateway)) { 
  1281.  
  1282. $relationships = $member->get_relationships(); 
  1283. foreach($relationships as $rel) { 
  1284. if($rel->usinggateway == $fromgateway) { 
  1285. $member->update_relationship_gateway( $rel->rel_id, $fromgateway, $togateway ); 
  1286.  
  1287.  
  1288. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_original_referer() ) ); 
  1289. break; 
  1290.  
  1291.  
  1292.  
  1293. function handle_edit_member() { 
  1294.  
  1295. global $action, $page; 
  1296.  
  1297. wp_reset_vars( array('action', 'page') ); 
  1298.  
  1299.  
  1300. function handle_member_gateway_op( $operation = 'move', $member_id = false ) { 
  1301.  
  1302. global $action, $page, $action2, $M_Gateways; 
  1303.  
  1304. wp_reset_vars( array('action', 'page', 'action2') ); 
  1305.  
  1306. if(empty($action) && !empty($action2)) $action = $action2; 
  1307.  
  1308. $gateways = apply_filters('M_gateways_list', array()); 
  1309.  
  1310. $active = get_option('membership_activated_gateways', array()); 
  1311.  
  1312. if(isset($_GET['fromgateway']) && !empty($_GET['fromgateway'])) { 
  1313. $fromgateway = stripslashes($_GET['fromgateway']); 
  1314. } else { 
  1315. $fromgateway = ''; 
  1316.  
  1317. switch($operation) { 
  1318.  
  1319. case 'move': $title = __('Move subscription to another gateway', 'membership'); 
  1320. $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/>"; 
  1321.  
  1322. $html = "<h3>" . __('Gateway to move from for this / these member(s)', 'membership') . "</h3>"; 
  1323. $html .= "<div class='level-details'>"; 
  1324. $html .= "<select name='fromgateway' id='fromgateway' class='wide'>\n"; 
  1325. $html .= "<option value='0'>" . __('Select the gateway to move from.', 'membership') . "</option>\n"; 
  1326. $html .= "<option value='admin'>" . esc_html('admin' . " - " . "admin default gateway") . "</option>\n"; 
  1327. if($gateways) { 
  1328. foreach($gateways as $key => $gateway) { 
  1329. if(in_array($key, $active)) { 
  1330. $html .= "<option value='" . esc_attr($key) . "'"; 
  1331. if( $fromgateway == $key ) { 
  1332. $html .= " selected='selected'"; 
  1333. $html .= ">" . esc_html($key . " - " . $gateway) . "</option>\n"; 
  1334. $html .= "</select>\n"; 
  1335. $html .= "</div>"; 
  1336.  
  1337. $html .= "<h3>" . __('Gateway to move to for this / these member(s)', 'membership') . "</h3>"; 
  1338. $html .= "<div class='level-details'>"; 
  1339. $html .= "<select name='togateway' id='togateway' class='wide'>\n"; 
  1340. $html .= "<option value='0'>" . __('Select the gateway to move to.', 'membership') . "</option>\n"; 
  1341. $html .= "<option value='admin'>" . esc_html('admin' . " - " . "admin default gateway") . "</option>\n"; 
  1342. reset($gateways); 
  1343. if($gateways) { 
  1344. foreach($gateways as $key => $gateway) { 
  1345. if(in_array($key, $active)) { 
  1346. $html .= "<option value='" . esc_attr($key) . "'>" . esc_html($key . " - " . $gateway) . "</option>\n"; 
  1347. $html .= "</select>\n"; 
  1348. $html .= "</div>"; 
  1349.  
  1350. $button = "Move"; 
  1351. break; 
  1352.  
  1353.  
  1354. ?> 
  1355. <div class='wrap nosubsub'> 
  1356. <div class="icon32" id="icon-users"><br></div> 
  1357. <h2><?php echo $title; ?></h2> 
  1358. <form action='admin.php?page=<?php echo $page; ?>' method='post'> 
  1359.  
  1360. <div class='level-liquid-left'> 
  1361.  
  1362. <div id='level-left'> 
  1363. <div id='edit-level' class='level-holder-wrap'> 
  1364. <div class='sidebar-name no-movecursor'> 
  1365. <h3><?php echo esc_html($title); ?></h3> 
  1366. </div> 
  1367. <div class='level-holder'> 
  1368. <br /> 
  1369. <p class='description'><?php echo $formdescription; ?></p> 
  1370. <?php 
  1371. echo $html; 
  1372. ?> 
  1373.  
  1374. <div class='buttons'> 
  1375. <?php 
  1376. wp_original_referer_field(true, 'previous'); wp_nonce_field($action . '-gateway-complete'); 
  1377. ?> 
  1378. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a> 
  1379. <input type='submit' value='<?php _e($button, 'membership'); ?>' class='button-primary' /> 
  1380. <input type='hidden' name='action' value='<?php esc_attr_e($action . '-gateway-complete'); ?>' /> 
  1381. <?php 
  1382. if(is_array($member_id)) { 
  1383. ?> 
  1384. <input type='hidden' name='member_id' value='<?php esc_attr_e(implode(', ', $member_id)); ?>' /> 
  1385. <?php 
  1386. } else { 
  1387. ?> 
  1388. <input type='hidden' name='member_id' value='<?php esc_attr_e($member_id); ?>' /> 
  1389. <?php 
  1390.  
  1391. ?> 
  1392. </div> 
  1393.  
  1394. </div> 
  1395. </div> 
  1396. </div> 
  1397.  
  1398. </div> <!-- level-liquid-left --> 
  1399.  
  1400. </form> 
  1401. </div> <!-- wrap --> 
  1402. <?php 
  1403.  
  1404.  
  1405. function handle_member_level_op($operation = 'add', $member_id = false) { 
  1406.  
  1407. global $action, $page, $action2; 
  1408.  
  1409. wp_reset_vars( array('action', 'page', 'action2') ); 
  1410.  
  1411. if(empty($action) && !empty($action2)) $action = $action2; 
  1412.  
  1413. if(isset($_GET['fromlevel']) && !empty($_GET['fromlevel'])) { 
  1414. $fromlevel = $_GET['fromlevel']; 
  1415. } else { 
  1416. $fromlevel = ''; 
  1417.  
  1418. switch($operation) { 
  1419.  
  1420. case 'add': $title = __('Add member to a level', 'membership'); 
  1421. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.', 'membership') . "<br/><br/>"; 
  1422. $formdescription .= __('By adding a membership level, you may actually be removing existing access to content.', 'membership'); 
  1423.  
  1424. $html = "<h3>" . __('Level to add for this / these member(s)', 'membership') . "</h3>"; 
  1425. $html .= "<div class='level-details'>"; 
  1426. $html .= "<select name='tolevel_id' id='tolevel_id' class='wide'>\n"; 
  1427. $html .= "<option value='0'>" . __('Select the level to add.', 'membership') . "</option>\n"; 
  1428. $levels = $this->get_membership_levels(array('level_id' => 'active')); 
  1429. if($levels) { 
  1430. foreach($levels as $key => $level) { 
  1431. $html .= "<option value='" . esc_attr($level->id) . "'"; 
  1432. $html .= ">" . esc_html($level->level_title) . "</option>\n"; 
  1433. $html .= "</select>\n"; 
  1434. $html .= "</div>"; 
  1435.  
  1436. $button = "Add"; 
  1437.  
  1438. break; 
  1439.  
  1440. case 'move': $title = __('Move member to another level', 'membership'); 
  1441. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.', 'membership') . "<br/><br/>"; 
  1442.  
  1443. $html = "<h3>" . __('Level to move from for this / these member(s)', 'membership') . "</h3>"; 
  1444. $html .= "<div class='level-details'>"; 
  1445. $html .= "<select name='fromlevel_id' id='fromlevel_id' class='wide'>\n"; 
  1446. $html .= "<option value='0'>" . __('Select the level to move from.', 'membership') . "</option>\n"; 
  1447. $levels = $this->get_membership_levels(array('level_id' => 'active')); 
  1448. if($levels) { 
  1449. foreach($levels as $key => $level) { 
  1450. $html .= "<option value='" . esc_attr($level->id) . "'"; 
  1451. if($fromlevel == $level->id) $html .= " selected='selected'"; 
  1452. $html .= ">" . esc_html($level->level_title) . "</option>\n"; 
  1453. $html .= "</select>\n"; 
  1454. $html .= "</div>"; 
  1455.  
  1456. $html .= "<h3>" . __('Level to move to for this / these member(s)', 'membership') . "</h3>"; 
  1457. $html .= "<div class='level-details'>"; 
  1458. $html .= "<select name='tolevel_id' id='tolevel_id' class='wide'>\n"; 
  1459. $html .= "<option value='0'>" . __('Select the level to move to.', 'membership') . "</option>\n"; 
  1460. reset($levels); 
  1461. if($levels) { 
  1462. foreach($levels as $key => $level) { 
  1463. $html .= "<option value='" . esc_attr($level->id) . "'"; 
  1464. $html .= ">" . esc_html($level->level_title) . "</option>\n"; 
  1465. $html .= "</select>\n"; 
  1466. $html .= "</div>"; 
  1467.  
  1468. $button = "Move"; 
  1469. break; 
  1470.  
  1471. case 'drop': $title = __('Drop member from level', 'membership'); 
  1472.  
  1473. $formdescription = __('A membership level controls the amount of access to the sites content this member will have.', 'membership') . "<br/><br/>"; 
  1474. $formdescription .= __('By removing a membership level, you may actually be increasing existing access to content.', 'membership'); 
  1475.  
  1476. $html = "<h3>" . __('Level to drop for this / these member(s)', 'membership') . "</h3>"; 
  1477. $html .= "<div class='level-details'>"; 
  1478. $html .= "<select name='fromlevel_id' id='fromlevel_id' class='wide'>\n"; 
  1479. $html .= "<option value=''>" . __('Select the level to remove.', 'membership') . "</option>\n"; 
  1480. $levels = $this->get_membership_levels(array('level_id' => 'active')); 
  1481. if($levels) { 
  1482. foreach($levels as $key => $level) { 
  1483. $html .= "<option value='" . esc_attr($level->id) . "'"; 
  1484. if($fromlevel == $level->id) $html .= " selected='selected'"; 
  1485. $html .= ">" . esc_html($level->level_title) . "</option>\n"; 
  1486. $html .= "</select>\n"; 
  1487. $html .= "</div>"; 
  1488.  
  1489. $button = "Drop"; 
  1490.  
  1491. break; 
  1492.  
  1493.  
  1494.  
  1495. ?> 
  1496. <div class='wrap nosubsub'> 
  1497. <div class="icon32" id="icon-users"><br></div> 
  1498. <h2><?php echo $title; ?></h2> 
  1499. <form action='admin.php?page=<?php echo $page; ?>' method='post'> 
  1500.  
  1501. <div class='level-liquid-left'> 
  1502.  
  1503. <div id='level-left'> 
  1504. <div id='edit-level' class='level-holder-wrap'> 
  1505. <div class='sidebar-name no-movecursor'> 
  1506. <h3><?php echo esc_html($title); ?></h3> 
  1507. </div> 
  1508. <div class='level-holder'> 
  1509. <br /> 
  1510. <p class='description'><?php echo $formdescription; ?></p> 
  1511. <?php 
  1512. echo $html; 
  1513. ?> 
  1514.  
  1515. <div class='buttons'> 
  1516. <?php 
  1517. wp_original_referer_field(true, 'previous'); wp_nonce_field($action . '-level-complete'); 
  1518. ?> 
  1519. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a> 
  1520. <input type='submit' value='<?php _e($button, 'membership'); ?>' class='button-primary' /> 
  1521. <input type='hidden' name='action' value='<?php esc_attr_e($action . '-level-complete'); ?>' /> 
  1522. <?php 
  1523. if(is_array($member_id)) { 
  1524. ?> 
  1525. <input type='hidden' name='member_id' value='<?php esc_attr_e(implode(', ', $member_id)); ?>' /> 
  1526. <?php 
  1527. } else { 
  1528. ?> 
  1529. <input type='hidden' name='member_id' value='<?php esc_attr_e($member_id); ?>' /> 
  1530. <?php 
  1531.  
  1532. ?> 
  1533. </div> 
  1534.  
  1535. </div> 
  1536. </div> 
  1537. </div> 
  1538.  
  1539. </div> <!-- level-liquid-left --> 
  1540.  
  1541. </form> 
  1542. </div> <!-- wrap --> 
  1543. <?php 
  1544.  
  1545.  
  1546. function handle_member_subscription_op($operation = 'add', $member_id = false) { 
  1547.  
  1548. global $action, $page, $action2; 
  1549.  
  1550. wp_reset_vars( array('action', 'page', 'action2') ); 
  1551.  
  1552. if(empty($action) && !empty($action2)) $action = $action2; 
  1553.  
  1554. if(isset($_GET['fromsub']) && !empty($_GET['fromsub'])) { 
  1555. $fromsub = $_GET['fromsub']; 
  1556. } else { 
  1557. $fromsub = ''; 
  1558.  
  1559. switch($operation) { 
  1560.  
  1561. case 'add': $title = __('Add member to a subscription', 'membership'); 
  1562. $formdescription = __('A subscription controls the levels a site member has access to / passes through.', 'membership') . "<br/><br/>"; 
  1563. $formdescription .= __('Depending on your payment gateway, adding a subscription here may not set up a payment subscription.', 'membership'); 
  1564.  
  1565. $html = "<h3>" . __('Subscription and level to add for this / these member(s)', 'membership') . "</h3>"; 
  1566. $html .= "<div class='level-details'>"; 
  1567. $html .= "<select name='tosub_id' id='tosub_id' class='wide'>\n"; 
  1568. $html .= "<option value='0'>" . __('Select the level to add.', 'membership') . "</option>\n"; 
  1569.  
  1570. $subs = $this->get_subscriptions_and_levels( array('sub_status' => 'active') ); 
  1571. if($subs) { 
  1572. $sub_id = false; 
  1573. foreach($subs as $key => $sub) { 
  1574. if($sub_id != $sub->sub_id) { 
  1575. $sub_id = $sub->sub_id; 
  1576.  
  1577. $html .= "<optgroup label='"; 
  1578. $html .= $sub->sub_name; 
  1579. $html .= "'>"; 
  1580.  
  1581. $html .= "<option value='" . esc_attr($sub->sub_id) . "-" . esc_attr($sub->level_id) . "-" . esc_attr($sub->level_order) . "'"; 
  1582. $html .= ">" . $sub->level_order . " : " . esc_html($sub->sub_name . " - " . $sub->level_title) . "</option>\n"; 
  1583. $html .= "</select>\n"; 
  1584. $html .= "</div>"; 
  1585.  
  1586. $button = "Add"; 
  1587. break; 
  1588.  
  1589. case 'move': $title = __('Move member to another subscription level', 'membership'); 
  1590. $formdescription = __('A subscription controls the levels a site member has access to / passes through.', 'membership') . "<br/><br/>"; 
  1591. $formdescription .= __('Depending on your payment gateway, moving a subscription here may not alter a members existing payment subscription.', 'membership'); 
  1592.  
  1593. $html = "<h3>" . __('Subscription to move from for this / these member(s)', 'membership') . "</h3>"; 
  1594. $html .= "<div class='level-details'>"; 
  1595. $html .= "<select name='fromsub_id' id='fromsub_id' class='wide'>\n"; 
  1596. $html .= "<option value='0'>" . __('Select the subscription to move from.', 'membership') . "</option>\n"; 
  1597. $subs = $this->get_subscriptions( array('sub_status' => 'active')); 
  1598. if($subs) { 
  1599. foreach($subs as $key => $sub) { 
  1600. $html .= "<option value='" . esc_attr($sub->id) . "'"; 
  1601. if($fromsub == $sub->id) $html .= " selected='selected'"; 
  1602. $html .= ">" . esc_html($sub->sub_name) . "</option>\n"; 
  1603. $html .= "</select>\n"; 
  1604. $html .= "</div>"; 
  1605.  
  1606. $html .= "<h3>" . __('Subscription and Level to move to for this / these member(s)', 'membership') . "</h3>"; 
  1607. $html .= "<div class='level-details'>"; 
  1608. $html .= "<select name='tosub_id' id='tosub_id' class='wide'>\n"; 
  1609. $html .= "<option value='0'>" . __('Select the level to move to.', 'membership') . "</option>\n"; 
  1610. $subs = $this->get_subscriptions_and_levels( array('sub_status' => 'active') ); 
  1611. if($subs) { 
  1612. $sub_id = false; 
  1613. foreach($subs as $key => $sub) { 
  1614. if($sub_id != $sub->sub_id) { 
  1615. $sub_id = $sub->sub_id; 
  1616.  
  1617. $html .= "<optgroup label='"; 
  1618. $html .= $sub->sub_name; 
  1619. $html .= "'>"; 
  1620.  
  1621. $html .= "<option value='" . esc_attr($sub->sub_id) . "-" . esc_attr($sub->level_id) . "-" . esc_attr($sub->level_order) . "'>" . $sub->level_order . " : " . esc_html($sub->sub_name . " - " . $sub->level_title) . "</option>\n"; 
  1622. $html .= "</select>\n"; 
  1623. $html .= "</div>"; 
  1624.  
  1625. $button = "Move"; 
  1626. break; 
  1627.  
  1628. case 'drop': $title = __('Drop member from subscription', 'membership'); 
  1629.  
  1630. $formdescription = __('A subscription controls the levels a site member has access to / passes through.', 'membership') . "<br/><br/>"; 
  1631. $formdescription .= __('Depending on the payment gateway, removing a subscription will not automatically cancel a payment subscription.', 'membership'); 
  1632.  
  1633. $html = "<h3>" . __('Subscription to drop for this / these member(s)', 'membership') . "</h3>"; 
  1634. $html .= "<div class='level-details'>"; 
  1635. $html .= "<select name='fromsub_id' id='fromsub_id' class='wide'>\n"; 
  1636. $html .= "<option value=''>" . __('Select the subscription to remove.', 'membership') . "</option>\n"; 
  1637. $subs = $this->get_subscriptions( array('sub_status' => 'active')); 
  1638. if($subs) { 
  1639. foreach($subs as $key => $sub) { 
  1640. $html .= "<option value='" . esc_attr($sub->id) . "'"; 
  1641. if($fromsub == $sub->id) $html .= " selected='selected'"; 
  1642. $html .= ">" . esc_html($sub->sub_name) . "</option>\n"; 
  1643. $html .= "</select>\n"; 
  1644. $html .= "</div>"; 
  1645.  
  1646. $button = "Drop"; 
  1647. break; 
  1648.  
  1649.  
  1650.  
  1651. ?> 
  1652. <div class='wrap nosubsub'> 
  1653. <div class="icon32" id="icon-users"><br></div> 
  1654. <h2><?php echo $title; ?></h2> 
  1655. <form action='admin.php?page=<?php echo $page; ?>' method='post'> 
  1656.  
  1657. <div class='level-liquid-left'> 
  1658.  
  1659. <div id='level-left'> 
  1660. <div id='edit-level' class='level-holder-wrap'> 
  1661. <div class='sidebar-name no-movecursor'> 
  1662. <h3><?php echo esc_html($title); ?></h3> 
  1663. </div> 
  1664. <div class='level-holder'> 
  1665. <br /> 
  1666. <p class='description'><?php echo $formdescription; ?></p> 
  1667. <?php 
  1668. echo $html; 
  1669. ?> 
  1670.  
  1671. <div class='buttons'> 
  1672. <?php 
  1673. wp_original_referer_field(true, 'previous'); wp_nonce_field($action . '-sub-complete'); 
  1674. ?> 
  1675. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a> 
  1676. <input type='submit' value='<?php _e($button, 'membership'); ?>' class='button-primary' /> 
  1677. <input type='hidden' name='action' value='<?php esc_attr_e($action . '-sub-complete'); ?>' /> 
  1678. <?php 
  1679. if(is_array($member_id)) { 
  1680. ?> 
  1681. <input type='hidden' name='member_id' value='<?php esc_attr_e(implode(', ', $member_id)); ?>' /> 
  1682. <?php 
  1683. } else { 
  1684. ?> 
  1685. <input type='hidden' name='member_id' value='<?php esc_attr_e($member_id); ?>' /> 
  1686. <?php 
  1687.  
  1688. ?> 
  1689. </div> 
  1690.  
  1691. </div> 
  1692. </div> 
  1693. </div> 
  1694.  
  1695. </div> <!-- level-liquid-left --> 
  1696.  
  1697. </form> 
  1698. </div> <!-- wrap --> 
  1699. <?php 
  1700.  
  1701.  
  1702.  
  1703. function handle_members_panel() { 
  1704.  
  1705. global $action, $page; 
  1706.  
  1707. wp_reset_vars( array('action', 'page') ); 
  1708.  
  1709. require_once('class.membersearch.php'); 
  1710.  
  1711. // bulk actions 
  1712. if(isset($_GET['doaction'])) { 
  1713. $action = $_GET['action']; 
  1714.  
  1715. } elseif(isset($_GET['doaction2'])) { 
  1716. $action = $_GET['action2']; 
  1717.  
  1718. switch(addslashes($action)) { 
  1719.  
  1720. case 'addlevel': if(isset($_GET['member_id'])) { 
  1721. $member_id = (int) $_GET['member_id']; 
  1722. $this->handle_member_level_op('add', $member_id); 
  1723. return; 
  1724. break; 
  1725.  
  1726. case 'movelevel': if(isset($_GET['member_id'])) { 
  1727. $member_id = (int) $_GET['member_id']; 
  1728. check_admin_referer('movelevel-member-' . $member_id); 
  1729. $this->handle_member_level_op('move', $member_id); 
  1730. return; 
  1731. break; 
  1732.  
  1733. case 'droplevel': if(isset($_GET['member_id'])) { 
  1734. $member_id = (int) $_GET['member_id']; 
  1735. check_admin_referer('droplevel-member-' . $member_id); 
  1736. $this->handle_member_level_op('drop', $member_id); 
  1737. return; 
  1738. break; 
  1739.  
  1740. case 'bulkaddlevel': 
  1741. if(isset($_GET['users'])) { 
  1742. check_admin_referer('bulk-members'); 
  1743. $this->handle_member_level_op('add', $_GET['users']); 
  1744. return; 
  1745. break; 
  1746.  
  1747. case 'bulkmovelevel': 
  1748. if(isset($_GET['users'])) { 
  1749. check_admin_referer('bulk-members'); 
  1750. $this->handle_member_level_op('move', $_GET['users']); 
  1751. return; 
  1752. break; 
  1753.  
  1754. case 'bulkdroplevel': 
  1755. if(isset($_GET['users'])) { 
  1756. check_admin_referer('bulk-members'); 
  1757. $this->handle_member_level_op('drop', $_GET['users']); 
  1758. return; 
  1759. break; 
  1760.  
  1761. case 'addsub': if(isset($_GET['member_id'])) { 
  1762. $member_id = (int) $_GET['member_id']; 
  1763. $this->handle_member_subscription_op('add', $member_id); 
  1764. return; 
  1765. break; 
  1766.  
  1767. case 'movesub': if(isset($_GET['member_id'])) { 
  1768. $member_id = (int) $_GET['member_id']; 
  1769. check_admin_referer('movesub-member-' . $member_id); 
  1770. $this->handle_member_subscription_op('move', $member_id); 
  1771. return; 
  1772. break; 
  1773.  
  1774. case 'dropsub': if(isset($_GET['member_id'])) { 
  1775. $member_id = (int) $_GET['member_id']; 
  1776. check_admin_referer('dropsub-member-' . $member_id); 
  1777. $this->handle_member_subscription_op('drop', $member_id); 
  1778. return; 
  1779. break; 
  1780.  
  1781. case 'bulkaddsub': if(isset($_GET['users'])) { 
  1782. check_admin_referer('bulk-members'); 
  1783. $this->handle_member_subscription_op('add', $_GET['users']); 
  1784. return; 
  1785. break; 
  1786. case 'bulkmovesub': 
  1787. if(isset($_GET['users'])) { 
  1788. check_admin_referer('bulk-members'); 
  1789. $this->handle_member_subscription_op('move', $_GET['users']); 
  1790. return; 
  1791. break; 
  1792. case 'bulkdropsub': 
  1793. if(isset($_GET['users'])) { 
  1794. check_admin_referer('bulk-members'); 
  1795. $this->handle_member_subscription_op('drop', $_GET['users']); 
  1796. return; 
  1797. break; 
  1798.  
  1799. case 'bulkmovegateway': 
  1800. if(isset($_GET['users'])) { 
  1801. check_admin_referer('bulk-members'); 
  1802. $this->handle_member_gateway_op('move', $_GET['users']); 
  1803. return; 
  1804. break; 
  1805.  
  1806. case 'movegateway': 
  1807. if(isset($_GET['member_id'])) { 
  1808. $member_id = (int) $_GET['member_id']; 
  1809. check_admin_referer('movegateway-member-' . $member_id); 
  1810. $this->handle_member_gateway_op('move', $member_id); 
  1811. return; 
  1812. break; 
  1813.  
  1814. case 'edit': if(isset($_GET['level_id'])) { 
  1815. $level_id = (int) $_GET['level_id']; 
  1816. $this->handle_level_edit_form($level_id); 
  1817. return; // So we don't see the rest of this page 
  1818. break; 
  1819.  
  1820.  
  1821. $filter = array(); 
  1822.  
  1823. if(isset($_GET['s'])) { 
  1824. $s = stripslashes($_GET['s']); 
  1825. $filter['s'] = $s; 
  1826. } else { 
  1827. $s = ''; 
  1828.  
  1829. $sub_id = null; $level_id = null; 
  1830.  
  1831. if(isset($_GET['doactionsub'])) { 
  1832. if(addslashes($_GET['sub_op']) != '') { 
  1833. $sub_id = addslashes($_GET['sub_op']); 
  1834.  
  1835. if(isset($_GET['doactionsub2'])) { 
  1836. if(addslashes($_GET['sub_op2']) != '') { 
  1837. $sub_id = addslashes($_GET['sub_op2']); 
  1838.  
  1839. if(isset($_GET['doactionlevel'])) { 
  1840. if(addslashes($_GET['level_op']) != '') { 
  1841. $level_id = addslashes($_GET['level_op']); 
  1842.  
  1843. if(isset($_GET['doactionlevel2'])) { 
  1844. if(addslashes($_GET['level_op2']) != '') { 
  1845. $level_id = addslashes($_GET['level_op2']); 
  1846.  
  1847. if(isset($_GET['doactionactive'])) { 
  1848. if(addslashes($_GET['active_op']) != '') { 
  1849. $active_op = addslashes($_GET['active_op']); 
  1850.  
  1851. if(isset($_GET['doactionactive2'])) { 
  1852. if(addslashes($_GET['active_op2']) != '') { 
  1853. $active_op = addslashes($_GET['active_op2']); 
  1854.  
  1855. $usersearch = isset($_GET['s']) ? $_GET['s'] : null; 
  1856. $userspage = isset($_GET['userspage']) ? $_GET['userspage'] : null; 
  1857. $role = null; 
  1858.  
  1859. if(empty($active_op)) $active_op = ''; 
  1860.  
  1861. // Query the users 
  1862. $wp_user_search = new M_Member_Search($usersearch, $userspage, $sub_id, $level_id, $active_op); 
  1863.  
  1864. $messages = array(); 
  1865. $messages[1] = __('Member added.', 'membership'); 
  1866. $messages[2] = __('Member deleted.', 'membership'); 
  1867. $messages[3] = __('Member updated.', 'membership'); 
  1868. $messages[4] = __('Member not added.', 'membership'); 
  1869. $messages[5] = __('Member not updated.', 'membership'); 
  1870. $messages[6] = __('Member not deleted.', 'membership'); 
  1871.  
  1872. $messages[7] = __('Member activation toggled.', 'membership'); 
  1873. $messages[8] = __('Member activation not toggled.', 'membership'); 
  1874.  
  1875. $messages[9] = __('Members updated.', 'membership'); 
  1876.  
  1877. ?> 
  1878. <div class='wrap nosubsub'> 
  1879. <div class="icon32" id="icon-users"><br></div> 
  1880. <h2><?php _e('Edit Members', 'membership'); ?></h2> 
  1881.  
  1882. <?php 
  1883. if ( isset($_GET['msg']) ) { 
  1884. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  1885. $_SERVER['REQUEST_URI'] = remove_query_arg(array('msg'), $_SERVER['REQUEST_URI']); 
  1886.  
  1887. if($this->show_user_help( $page )) { 
  1888. ?> 
  1889. <div class='screenhelpheader'> 
  1890. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  1891. <?php 
  1892. ob_start(); 
  1893. include_once(membership_dir('membershipincludes/help/header.members.php')); 
  1894. echo ob_get_clean(); 
  1895. ?> 
  1896. </div> 
  1897. <?php 
  1898. ?> 
  1899.  
  1900. <form method="get" action="?page=<?php echo esc_attr($page); ?>" class="search-form"> 
  1901. <p class="search-box"> 
  1902. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  1903. <label for="membership-search-input" class="screen-reader-text"><?php _e('Search Members', 'membership'); ?>:</label> 
  1904. <input type="text" value="<?php echo esc_attr($s); ?>" name="s" id="membership-search-input"> 
  1905. <input type="submit" class="button" value="<?php _e('Search Members', 'membership'); ?>"> 
  1906. </p> 
  1907. </form> 
  1908.  
  1909. <br class='clear' /> 
  1910.  
  1911. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="members-filter"> 
  1912.  
  1913. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  1914.  
  1915. <div class="tablenav"> 
  1916.  
  1917. <?php if ( $wp_user_search->results_are_paged() ) : ?> 
  1918. <div class="tablenav-pages"><?php $wp_user_search->page_links(); ?></div> 
  1919. <?php endif; ?> 
  1920.  
  1921. <div class="alignleft actions"> 
  1922. <select name="action"> 
  1923. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  1924. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  1925.  
  1926. <optgroup label="<?php _e('Subscriptions', 'membership'); ?>"> 
  1927. <option value="bulkaddsub"><?php _e('Add subscription', 'membership'); ?></option> 
  1928. <option value="bulkmovesub"><?php _e('Move subscription', 'membership'); ?></option> 
  1929. <option value="bulkdropsub"><?php _e('Drop subscription', 'membership'); ?></option> 
  1930. </optgroup> 
  1931.  
  1932. <optgroup label="<?php _e('Levels', 'membership'); ?>"> 
  1933. <option value="bulkaddlevel"><?php _e('Add level', 'membership'); ?></option> 
  1934. <option value="bulkmovelevel"><?php _e('Move level', 'membership'); ?></option> 
  1935. <option value="bulkdroplevel"><?php _e('Drop level', 'membership'); ?></option> 
  1936. </optgroup> 
  1937.  
  1938. <optgroup label="<?php _e('Gateways', 'membership'); ?>"> 
  1939. <option value="bulkmovegateway"><?php _e('Move gateway', 'membership'); ?></option> 
  1940. </optgroup> 
  1941. </select> 
  1942. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply', 'membership'); ?>" /> 
  1943.  
  1944. <select name="sub_op" style='float:none;'> 
  1945. <option value=""><?php _e('Filter by subscription', 'membership'); ?></option> 
  1946. <?php 
  1947. $subs = $this->get_subscriptions(); 
  1948. if($subs) { 
  1949. foreach($subs as $key => $sub) { 
  1950. ?> 
  1951. <option value="<?php echo $sub->id; ?>" <?php if(isset($_GET['sub_op']) && $_GET['sub_op'] == $sub->id) echo 'selected="selected"'; ?>><?php echo esc_html($sub->sub_name); ?></option> 
  1952. <?php 
  1953. ?> 
  1954. </select> 
  1955. <input type="submit" class="button-secondary action" id="doactionsub" name="doactionsub" value="<?php _e('Filter', 'membership'); ?>"> 
  1956.  
  1957. <select name="level_op" style='float:none;'> 
  1958. <option value=""><?php _e('Filter by level', 'membership'); ?></option> 
  1959. <?php 
  1960. $levels = $this->get_membership_levels(); 
  1961. if($levels) { 
  1962. foreach($levels as $key => $level) { 
  1963. ?> 
  1964. <option value="<?php echo $level->id; ?>" <?php if(isset($_GET['level_op']) && $_GET['level_op'] == $level->id) echo 'selected="selected"'; ?>><?php echo esc_html($level->level_title); ?></option> 
  1965. <?php 
  1966. ?> 
  1967. </select> 
  1968. <input type="submit" class="button-secondary action" id="doactionlevel" name="doactionlevel" value="<?php _e('Filter', 'membership'); ?>"> 
  1969.  
  1970. <select name="active_op" style='float:none;'> 
  1971. <option value=""><?php _e('Filter by status', 'membership'); ?></option> 
  1972. <option value="yes" <?php if(isset($_GET['active_op']) && $_GET['active_op'] == 'yes') echo 'selected="selected"'; ?>><?php _e('Active', 'membership'); ?></option> 
  1973. <option value="no" <?php if(isset($_GET['active_op']) && $_GET['active_op'] == 'no') echo 'selected="selected"'; ?>><?php _e('Inactive', 'membership'); ?></option> 
  1974. </select> 
  1975. <input type="submit" class="button-secondary action" id="doactionactive" name="doactionactive" value="<?php _e('Filter', 'membership'); ?>"> 
  1976.  
  1977.  
  1978. </div> 
  1979.  
  1980. <div class="alignright actions"> 
  1981. <!-- <input type="button" class="button-secondary addnewlevelbutton" value="<?php _e('Add New', 'membership'); ?>" name="addnewlevel"> --> 
  1982. </div> 
  1983.  
  1984. <br class="clear"> 
  1985. </div> 
  1986. <?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?> 
  1987. <div class="error"> 
  1988. <ul> 
  1989. <?php 
  1990. foreach ( $wp_user_search->search_errors->get_error_messages() as $message ) 
  1991. echo "<li>$message</li>"; 
  1992. ?> 
  1993. </ul> 
  1994. </div> 
  1995. <?php endif; ?> 
  1996.  
  1997. <?php if ( $wp_user_search->is_search() ) : ?> 
  1998. <p><a href="?page=<?php echo $page; ?>"><?php _e('← Back to All Users', 'membership'); ?></a></p> 
  1999. <?php endif; ?> 
  2000.  
  2001. <div class="clear"></div> 
  2002.  
  2003. <?php 
  2004. wp_nonce_field('bulk-members'); 
  2005.  
  2006. $columns = array( "username" => __('Username', 'membership'),  
  2007. "name" => __('Name', 'membership'),  
  2008. "email" => __('E-mail', 'membership'),  
  2009. "active" => __('Active', 'membership'),  
  2010. "sub" => __('Subscription', 'membership'),  
  2011. "level" => __('Membership Level', 'membership'),  
  2012. "expires" => __('Level Expires', 'membership'),  
  2013. "gateway" => __('Gateway', 'membership') 
  2014. ); 
  2015.  
  2016. $columns = apply_filters('members_columns', $columns); 
  2017.  
  2018. //$levels = $this->get_membership_levels($filter); 
  2019.  
  2020. ?> 
  2021.  
  2022. <table cellspacing="0" class="widefat fixed"> 
  2023. <thead> 
  2024. <tr> 
  2025. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  2026. <?php 
  2027. foreach($columns as $key => $col) { 
  2028. ?> 
  2029. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  2030. <?php 
  2031. ?> 
  2032. </tr> 
  2033. </thead> 
  2034.  
  2035. <tfoot> 
  2036. <tr> 
  2037. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  2038. <?php 
  2039. reset($columns); 
  2040. foreach($columns as $key => $col) { 
  2041. ?> 
  2042. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  2043. <?php 
  2044. ?> 
  2045. </tr> 
  2046. </tfoot> 
  2047.  
  2048. <tbody> 
  2049. <?php 
  2050.  
  2051. $style = ''; 
  2052. foreach ( $wp_user_search->get_results() as $userid ) { 
  2053. $user_object = new M_Membership($userid); 
  2054. $roles = $user_object->roles; 
  2055. $role = array_shift($roles); 
  2056.  
  2057. $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 
  2058. ?> 
  2059. <tr id='user-<?php echo $user_object->ID; ?>' <?php echo $style; ?>> 
  2060. <th scope='row' class='check-column'> 
  2061. <input type='checkbox' name='users[]' id='user_<?php echo $user_object->ID; ?>' class='$role' value='<?php echo $user_object->ID; ?>' /> 
  2062. </th> 
  2063. <td <?php echo $style; ?>> 
  2064. <strong><a href='<?php echo admin_url('user-edit.php?user_id=' . $user_object->ID); ?>' title='User ID: <?php echo $user_object->ID; ?>'><?php echo $user_object->user_login; ?></a></strong> 
  2065. <?php 
  2066. $actions = array(); 
  2067. //$actions['id'] = "<strong>" . __('ID : ', 'membership') . $user_object->ID . "</strong>"; 
  2068. $actions['edit'] = "<span class='edit'><a href='" . admin_url('user-edit.php?user_id=' . $user_object->ID) . "'>" . __('Edit', 'membership') . "</a></span>"; 
  2069. if($user_object->active_member()) { 
  2070. $actions['activate'] = "<span class='edit deactivate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&member_id=" . $user_object->ID . "", 'toggle-member_' . $user_object->ID) . "'>" . __('Deactivate', 'membership') . "</a></span>"; 
  2071. } else { 
  2072. $actions['activate'] = "<span class='edit activate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&member_id=" . $user_object->ID . "", 'toggle-member_' . $user_object->ID) . "'>" . __('Activate', 'membership') . "</a></span>"; 
  2073. //$actions['history'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=history&member_id=" . $user_object->ID . "", 'history-member_' . $user_object->ID) . "'>" . __('History', 'membership') . "</a></span>"; 
  2074. ?> 
  2075. <div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  2076. </td> 
  2077. <td <?php echo $style; ?>><?php echo $user_object->first_name . " " . $user_object->last_name; ?></td> 
  2078. <td <?php echo $style; ?>><a href='mailto:<?php echo $user_object->user_email; ?>' title='<?php echo sprintf( __('e-mail: %s', 'membership' ), $user_object->user_email ); ?>'><?php echo $user_object->user_email; ?></a></td> 
  2079. <td <?php echo $style; ?>> 
  2080. <?php if($user_object->active_member()) { 
  2081. echo "<span class='membershipactivestatus'>" . __('Active', 'membership') . "</span>"; 
  2082. } else { 
  2083. echo "<span class='membershipinactivestatus'>" . __('Inactive', 'membership') . "</span>"; 
  2084. ?> 
  2085. </td> 
  2086. <td <?php echo $style; ?>> 
  2087. <?php 
  2088. $subs = $user_object->get_subscription_ids(); 
  2089. if(!empty($subs)) { 
  2090. $rows = array(); 
  2091. foreach((array) $subs as $key) { 
  2092. $sub = new M_Subscription ( $key ); 
  2093. if(!empty($sub)) { 
  2094. $rows[] = $sub->sub_name(); 
  2095. echo implode(", ", $rows); 
  2096.  
  2097. $actions = array(); 
  2098.  
  2099. if(!$user_object->has_cap('membershipadmin')) { 
  2100. $actions['add'] = "<span class='edit'><a href='?page={$page}&action=addsub&member_id={$user_object->ID}'>" . __('Add', 'membership') . "</a></span>"; 
  2101.  
  2102. if(!empty($subs)) { 
  2103. if(count($subs) == 1) { 
  2104. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movesub&member_id=" . $user_object->ID . "&fromsub=" . $subs[0], 'movesub-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2105. $actions['drop'] = "<span class='edit delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=dropsub&member_id=" . $user_object->ID . "&fromsub=" . $subs[0], 'dropsub-member-' . $user_object->ID) . "'>" . __('Drop', 'membership') . "</a></span>"; 
  2106. } else { 
  2107. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movesub&member_id=" . $user_object->ID . "", 'movesub-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2108. $actions['drop'] = "<span class='edit delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=dropsub&member_id=" . $user_object->ID . "", 'dropsub-member-' . $user_object->ID) . "'>" . __('Drop', 'membership') . "</a></span>"; 
  2109.  
  2110. ?> 
  2111. <div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  2112. </td> 
  2113. <td <?php echo $style; ?>> 
  2114. <?php 
  2115. $levels = $user_object->get_level_ids(); 
  2116. if(!empty($levels)) { 
  2117. $rows = array(); 
  2118. foreach((array) $levels as $key => $value) { 
  2119. $level = new M_Level ( $value->level_id ); 
  2120. if(!empty($level)) { 
  2121. if((int) $value->sub_id != 0) { 
  2122. $rows[] = "<strong>" . $level->level_title() . "</strong>"; 
  2123. } else { 
  2124. $rows[] = $level->level_title(); 
  2125. echo implode(", ", $rows); 
  2126.  
  2127. $actions = array(); 
  2128. if(!$user_object->has_cap('membershipadmin')) { 
  2129. $actions['add'] = "<span class='edit'><a href='?page={$page}&action=addlevel&member_id={$user_object->ID}'>" . __('Add', 'membership') . "</a></span>"; 
  2130.  
  2131. if(!empty($levels)) { 
  2132. if(count($levels) == 1) { 
  2133. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movelevel&member_id=" . $user_object->ID . "&fromlevel=" . $levels[0]->level_id, 'movelevel-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2134. $actions['drop'] = "<span class='edit delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=droplevel&member_id=" . $user_object->ID . "&fromlevel=" . $levels[0]->level_id, 'droplevel-member-' . $user_object->ID) . "'>" . __('Drop', 'membership') . "</a></span>"; 
  2135. } else { 
  2136. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movelevel&member_id=" . $user_object->ID . "", 'movelevel-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2137. $actions['drop'] = "<span class='edit delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=droplevel&member_id=" . $user_object->ID . "", 'droplevel-member-' . $user_object->ID) . "'>" . __('Drop', 'membership') . "</a></span>"; 
  2138.  
  2139. ?> 
  2140. <div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  2141. </td> 
  2142. <td <?php echo $style; ?>> 
  2143. <?php 
  2144. $subs = $user_object->get_relationships(); 
  2145. if($subs) { 
  2146. $exps = array(); 
  2147. foreach($subs as $sub) { 
  2148. $exps[] = date("Y-m-d H:i", mysql2date("U", $sub->expirydate)); 
  2149. echo implode(", ", $exps); 
  2150.  
  2151. ?> 
  2152. </td> 
  2153. <td <?php echo $style; ?>> 
  2154. <?php 
  2155. $subs = $user_object->get_relationships(); 
  2156. //print_r($subs); 
  2157. if($subs) { 
  2158. $gates = array(); 
  2159. foreach($subs as $sub) { 
  2160. $gates[] = $sub->usinggateway; 
  2161. echo implode(", ", $gates); 
  2162.  
  2163. if($user_object->has_cap('membershipadmin')) { 
  2164. $actions = array(); 
  2165. } else { 
  2166. $actions = array(); 
  2167.  
  2168. if(count($gates) == 1) { 
  2169. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movegateway&member_id=" . $user_object->ID . "&fromgateway=" . $gates[0], 'movegateway-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2170. } else { 
  2171. $actions['move'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page. "&action=movegateway&member_id=" . $user_object->ID . "", 'movegateway-member-' . $user_object->ID) . "'>" . __('Move', 'membership') . "</a></span>"; 
  2172.  
  2173.  
  2174. ?> 
  2175. <div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  2176. <?php 
  2177. ?> 
  2178. </td> 
  2179. </tr> 
  2180. <?php 
  2181. ?> 
  2182. </tbody> 
  2183. </table> 
  2184.  
  2185.  
  2186. <div class="tablenav"> 
  2187.  
  2188. <div class="alignleft actions"> 
  2189. <select name="action2"> 
  2190. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  2191. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  2192.  
  2193. <optgroup label="<?php _e('Subscriptions', 'membership'); ?>"> 
  2194. <option value="bulkaddsub"><?php _e('Add subscription', 'membership'); ?></option> 
  2195. <option value="bulkmovesub"><?php _e('Move subscription', 'membership'); ?></option> 
  2196. <option value="bulkdropsub"><?php _e('Drop subscription', 'membership'); ?></option> 
  2197. </optgroup> 
  2198.  
  2199. <optgroup label="<?php _e('Levels', 'membership'); ?>"> 
  2200. <option value="bulkaddlevel"><?php _e('Add level', 'membership'); ?></option> 
  2201. <option value="bulkmovelevel"><?php _e('Move level', 'membership'); ?></option> 
  2202. <option value="bulkdroplevel"><?php _e('Drop level', 'membership'); ?></option> 
  2203. </optgroup> 
  2204.  
  2205. <optgroup label="<?php _e('Gateways', 'membership'); ?>"> 
  2206. <option value="bulkmovegateway"><?php _e('Move gateway', 'membership'); ?></option> 
  2207. </optgroup> 
  2208. </select> 
  2209. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="Apply"> 
  2210.  
  2211. <select name="sub_op2"> 
  2212. <option value=""><?php _e('Filter by subscription', 'membership'); ?></option> 
  2213. <?php 
  2214. $subs = $this->get_subscriptions(); 
  2215. if($subs) { 
  2216. foreach($subs as $key => $sub) { 
  2217. ?> 
  2218. <option value="<?php echo $sub->id; ?>" <?php if(isset($_GET['sub_op2']) && $_GET['sub_op2'] == $sub->id) echo 'selected="selected"'; ?>><?php echo esc_html($sub->sub_name); ?></option> 
  2219. <?php 
  2220. ?> 
  2221. </select> 
  2222. <input type="submit" class="button-secondary action" id="doactionsub2" name="doactionsub2" value="<?php _e('Filter', 'membership'); ?>"> 
  2223.  
  2224. <select name="level_op2"> 
  2225. <option value=""><?php _e('Filter by level', 'membership'); ?></option> 
  2226. <?php 
  2227. $levels = $this->get_membership_levels(); 
  2228. if($levels) { 
  2229. foreach($levels as $key => $level) { 
  2230. ?> 
  2231. <option value="<?php echo $level->id; ?>" <?php if(isset($_GET['level_op2']) && $_GET['level_op2'] == $level->id) echo 'selected="selected"'; ?>><?php echo esc_html($level->level_title); ?></option> 
  2232. <?php 
  2233. ?> 
  2234. </select> 
  2235. <input type="submit" class="button-secondary action" id="doactionlevel2" name="doactionlevel2" value="<?php _e('Filter', 'membership'); ?>"> 
  2236.  
  2237. <select name="active_op2"> 
  2238. <option value=""><?php _e('Filter by status', 'membership'); ?></option> 
  2239. <option value="yes" <?php if(isset($_GET['active_op2']) && $_GET['active_op2'] == 'yes') echo 'selected="selected"'; ?>><?php _e('Active', 'membership'); ?></option> 
  2240. <option value="no" <?php if(isset($_GET['active_op2']) && $_GET['active_op2'] == 'no') echo 'selected="selected"'; ?>><?php _e('Inactive', 'membership'); ?></option> 
  2241. </select> 
  2242. <input type="submit" class="button-secondary action" id="doactionactive2" name="doactionactive2" value="<?php _e('Filter', 'membership'); ?>"> 
  2243.  
  2244.  
  2245. </div> 
  2246. <div class="alignright actions"> 
  2247.  
  2248. </div> 
  2249. <br class="clear"> 
  2250. </div> 
  2251.  
  2252. </form> 
  2253.  
  2254. </div> <!-- wrap --> 
  2255. <?php 
  2256.  
  2257.  
  2258. function handle_options_panel_updates() { 
  2259.  
  2260. global $action, $page, $wp_rewrite; 
  2261.  
  2262. wp_reset_vars( array('action', 'page') ); 
  2263.  
  2264. if($action == 'updateoptions') { 
  2265.  
  2266. check_admin_referer('update-membership-options'); 
  2267.  
  2268. if(isset($_GET['tab'])) { 
  2269. $tab = $_GET['tab']; 
  2270. } else { 
  2271. $tab = 'general'; 
  2272.  
  2273. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  2274. if(function_exists('get_blog_option')) { 
  2275. if(function_exists('switch_to_blog')) { 
  2276. switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE); 
  2277.  
  2278. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  2279. } else { 
  2280. $M_options = get_option('membership_options', array()); 
  2281. } else { 
  2282. $M_options = get_option('membership_options', array()); 
  2283.  
  2284. switch($tab) { 
  2285.  
  2286. case 'general': $M_options['strangerlevel'] = (isset($_POST['strangerlevel'])) ? (int) $_POST['strangerlevel'] : ''; 
  2287. $M_options['freeusersubscription'] = (isset($_POST['freeusersubscription'])) ? (int) $_POST['freeusersubscription'] : ''; 
  2288. $M_options['enableincompletesignups'] = (isset($_POST['enableincompletesignups'])) ? $_POST['enableincompletesignups'] : ''; 
  2289. break; 
  2290.  
  2291. case 'pages': $M_options['nocontent_page'] = (isset($_POST['nocontent_page'])) ? $_POST['nocontent_page'] : ''; 
  2292. $M_options['account_page'] = (isset($_POST['account_page'])) ? $_POST['account_page'] : ''; 
  2293. $M_options['registration_page'] = (isset($_POST['registration_page'])) ? $_POST['registration_page'] : ''; 
  2294. $M_options['registrationcompleted_page'] = (isset($_POST['registrationcompleted_page'])) ? $_POST['registrationcompleted_page'] : ''; 
  2295. $M_options['subscriptions_page'] = (isset($_POST['subscriptions_page'])) ? $_POST['subscriptions_page'] : ''; 
  2296. $M_options['formtype'] = (isset($_POST['formtype'])) ? $_POST['formtype'] : ''; 
  2297. break; 
  2298.  
  2299. case 'posts': $M_options['membershipshortcodes'] = (isset($_POST['membershipshortcodes'])) ? explode("\n", $_POST['membershipshortcodes']) : array(); 
  2300. $M_options['membershipadminshortcodes'] = (isset($_POST['membershipadminshortcodes'])) ? explode("\n", $_POST['membershipadminshortcodes']) : array(); 
  2301. $M_options['shortcodemessage'] = (isset($_POST['shortcodemessage'])) ? $_POST['shortcodemessage'] : ''; 
  2302. $M_options['moretagdefault'] = (isset($_POST['moretagdefault'])) ? $_POST['moretagdefault'] : ''; 
  2303. $M_options['moretagmessage'] = (isset($_POST['moretagmessage'])) ? $_POST['moretagmessage'] : ''; 
  2304. break; 
  2305.  
  2306. case 'downloads': $M_options['original_url'] = (isset($_POST['original_url'])) ? $_POST['original_url'] : ''; 
  2307. $M_options['masked_url'] = (isset($_POST['masked_url'])) ? $_POST['masked_url'] : ''; 
  2308. $M_options['membershipdownloadgroups'] = (isset($_POST['membershipdownloadgroups'])) ? explode("\n", $_POST['membershipdownloadgroups']) : array(); 
  2309. $M_options['protection_type'] = (isset($_POST['protection_type'])) ? $_POST['protection_type'] : ''; 
  2310.  
  2311. // Refresh the rewrite rules in case they've switched to hybrid from an earlier version 
  2312. flush_rewrite_rules(); 
  2313. break; 
  2314.  
  2315. case 'users': $wp_user_search = new WP_User_Query( array( 'role' => 'administrator' ) ); 
  2316. $admins = $wp_user_search->get_results(); 
  2317. $user_id = get_current_user_id(); 
  2318. foreach($admins as $admin) { 
  2319. if($user_id == $admin->ID) { 
  2320. continue; 
  2321. } else { 
  2322. if(in_array( $admin->ID, (array) $_POST['admincheck'])) { 
  2323. $user = new WP_User( $admin->ID ); 
  2324. if(!$user->has_cap('membershipadmin')) { 
  2325. $user->add_cap('membershipadmin'); 
  2326. } else { 
  2327. $user = new WP_User( $admin->ID ); 
  2328. if($user->has_cap('membershipadmin')) { 
  2329. $user->remove_cap('membershipadmin'); 
  2330. break; 
  2331.  
  2332. case 'extras': $M_options['paymentcurrency'] = (isset($_POST['paymentcurrency'])) ? $_POST['paymentcurrency'] : ''; 
  2333. $M_options['upgradeperiod'] = (isset($_POST['upgradeperiod'])) ? $_POST['upgradeperiod'] : ''; 
  2334. $M_options['renewalperiod'] = (isset($_POST['renewalperiod'])) ? $_POST['renewalperiod'] : ''; 
  2335.  
  2336. if(isset($_POST['membershipwizard']) && $_POST['membershipwizard'] == 'yes') { 
  2337. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  2338. if(function_exists('update_blog_option')) { 
  2339. update_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_wizard_visible', 'yes'); 
  2340. } else { 
  2341. update_option('membership_wizard_visible', 'yes'); 
  2342. } else { 
  2343. update_option('membership_wizard_visible', 'yes'); 
  2344. break; 
  2345.  
  2346. default: 
  2347. break; 
  2348.  
  2349.  
  2350. // included an action here so that it is processed for all tabs 
  2351. do_action('membership_option_menu_process_' . $tab); 
  2352.  
  2353. // For future upgrades 
  2354. $M_options['registration_tos'] = (isset($_POST['registration_tos'])) ? $_POST['registration_tos'] : ''; 
  2355.  
  2356. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  2357. if(function_exists('update_blog_option')) { 
  2358. update_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', $M_options); 
  2359. } else { 
  2360. update_option('membership_options', $M_options); 
  2361. } else { 
  2362. update_option('membership_options', $M_options); 
  2363.  
  2364. do_action( 'membership_options_page_process' ); 
  2365.  
  2366. // Always flush the rewrite rules 
  2367. $wp_rewrite->flush_rules(); 
  2368.  
  2369. wp_safe_redirect( add_query_arg('msg', 1, wp_get_referer()) ); 
  2370.  
  2371. } elseif( !empty($action) ) { 
  2372.  
  2373. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  2374. if(function_exists('get_blog_option')) { 
  2375. if(function_exists('switch_to_blog')) { 
  2376. switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE); 
  2377.  
  2378. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  2379. } else { 
  2380. $M_options = get_option('membership_options', array()); 
  2381. } else { 
  2382. $M_options = get_option('membership_options', array()); 
  2383.  
  2384. switch($action) { 
  2385. case 'createregistrationpage': check_admin_referer('create-registrationpage'); 
  2386. $pagedetails = array('post_title' => __('Register', 'membership'), 'post_name' => 'register', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => ''); 
  2387. $id = wp_insert_post( $pagedetails ); 
  2388. $M_options['registration_page'] = $id; 
  2389. break; 
  2390.  
  2391. case 'createaccountpage': check_admin_referer('create-accountpage'); 
  2392. $pagedetails = array('post_title' => __('Account', 'membership'), 'post_name' => 'account', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => ''); 
  2393. $id = wp_insert_post( $pagedetails ); 
  2394. $M_options['account_page'] = $id; 
  2395. break; 
  2396.  
  2397. case 'createsubscriptionspage': check_admin_referer('create-subscriptionspage'); 
  2398. $pagedetails = array('post_title' => __('Subscriptions', 'membership'), 'post_name' => 'subscriptions', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => ''); 
  2399. $id = wp_insert_post( $pagedetails ); 
  2400. $M_options['subscriptions_page'] = $id; 
  2401. break; 
  2402.  
  2403. case 'createnoaccesspage': check_admin_referer('create-noaccesspage'); 
  2404. $content = '<p>' . __('The content you are trying to access is only available to members. Sorry.', 'membership') . '</p>'; 
  2405. $pagedetails = array('post_title' => __('Protected Content', 'membership'), 'post_name' => 'protected', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $content); 
  2406. $id = wp_insert_post( $pagedetails ); 
  2407. $M_options['nocontent_page'] = $id; 
  2408. break; 
  2409.  
  2410. case 'createregistrationcompletedpage': 
  2411. check_admin_referer('create-registrationcompletedpage'); 
  2412. $content = '<p>' . __('Thank you for subscribing. We hope you enjoy the content.', 'membership') . '</p>'; 
  2413. $pagedetails = array('post_title' => __('Welcome', 'membership'), 'post_name' => 'welcome', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $content); 
  2414. $id = wp_insert_post( $pagedetails ); 
  2415. $M_options['registrationcompleted_page'] = $id; 
  2416. break; 
  2417.  
  2418. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  2419. if(function_exists('update_blog_option')) { 
  2420. update_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', $M_options); 
  2421. } else { 
  2422. update_option('membership_options', $M_options); 
  2423. } else { 
  2424. update_option('membership_options', $M_options); 
  2425.  
  2426. do_action( 'membership_options_pagecreation_process' ); 
  2427.  
  2428. wp_safe_redirect( add_query_arg('msg', 2, wp_get_referer()) ); 
  2429.  
  2430.  
  2431.  
  2432. function show_general_options() { 
  2433. global $action, $page, $M_options; 
  2434.  
  2435. $messages = array(); 
  2436. $messages[1] = __('Your options have been updated.', 'membership'); 
  2437.  
  2438. ?> 
  2439. <div class="icon32" id="icon-options-general"><br></div> 
  2440. <h2><?php _e('General Options', 'membership'); ?></h2> 
  2441.  
  2442. <?php 
  2443. if ( isset($_GET['msg']) ) { 
  2444. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  2445. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  2446. ?> 
  2447. <div id="poststuff" class="metabox-holder m-settings"> 
  2448. <form action='' method='post'> 
  2449.  
  2450. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  2451. <input type='hidden' name='action' value='updateoptions' /> 
  2452.  
  2453. <?php 
  2454. wp_nonce_field('update-membership-options'); 
  2455. ?> 
  2456. <div class="postbox"> 
  2457. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Stranger settings', 'membership'); ?></span></h3> 
  2458. <div class="inside"> 
  2459. <p class='description'><?php _e('A "stranger" is a visitor to your website who is either not logged in, or does not have an active membership or subscription to your website.', 'membership'); ?></p> 
  2460. <table class="form-table"> 
  2461. <tbody> 
  2462. <tr valign="top"> 
  2463. <th scope="row"><?php _e('Use membership level', 'membership'); ?></th> 
  2464. <td> 
  2465. <select name='strangerlevel' id='strangerlevel'> 
  2466. <option value="0"><?php _e('None - No access to content', 'membership'); ?></option> 
  2467. <?php 
  2468. $levels = $this->get_membership_levels(); 
  2469. if($levels) { 
  2470. foreach($levels as $key => $level) { 
  2471. ?> 
  2472. <option value="<?php echo $level->id; ?>" <?php if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] == $level->id) echo "selected='selected'"; ?>><?php echo esc_html($level->level_title); ?></option> 
  2473. <?php 
  2474. ?> 
  2475. </select> 
  2476. </td> 
  2477. </tr> 
  2478. </tbody> 
  2479. </table> 
  2480. <p class='description'><?php _e('If the above is set to "None" then you can pick the page you want strangers directed to below in the "Membership Pages" options.', 'membership'); ?></p> 
  2481.  
  2482. </div> 
  2483. </div> 
  2484.  
  2485. <div class="postbox"> 
  2486. <h3 class="hndle" style='cursor:auto;'><span><?php _e('User registration', 'membership'); ?></span></h3> 
  2487. <div class="inside"> 
  2488. <p class='description'><?php _e('If you have free user registration enabled on your site, select the subscription they will be assigned to initially.', 'membership'); ?></p> 
  2489. <p class='description'><?php _e('If you are using a paid subscription model - it is probably best to set this to "none".', 'membership'); ?></p> 
  2490.  
  2491. <table class="form-table"> 
  2492. <tbody> 
  2493. <tr valign="top"> 
  2494. <th scope="row"><?php _e('Use subscription', 'membership'); ?></th> 
  2495. <td> 
  2496. <select name='freeusersubscription' id='freeusersubscription'> 
  2497. <option value="0"><?php _e('None', 'membership'); ?></option> 
  2498. <?php 
  2499. $subs = $this->get_subscriptions( array('sub_status' => 'active')); 
  2500. if($subs) { 
  2501. foreach($subs as $key => $sub) { 
  2502. ?> 
  2503. <option value="<?php echo $sub->id; ?>" <?php if(isset($M_options['freeusersubscription']) && $M_options['freeusersubscription'] == $sub->id) echo "selected='selected'"; ?>><?php echo esc_html($sub->sub_name); ?></option> 
  2504. <?php 
  2505. ?> 
  2506. </select> 
  2507. </td> 
  2508. </tr> 
  2509. </tbody> 
  2510. </table> 
  2511.  
  2512. <?php 
  2513. /** 
  2514. <p class='description'><?php _e('The default setting for the membership plugin is to disable user accounts that do not complete their subscription signup.', 'membership'); ?></p> 
  2515. <p class='description'><?php _e('If you want to change this, then use the option below.', 'membership'); ?></p> 
  2516.   
  2517. <table class="form-table"> 
  2518. <tbody> 
  2519. <tr valign="top"> 
  2520. <th scope="row"><?php _e('Enable incomplete signup accounts', 'membership'); ?> 
  2521. </em> 
  2522. </th> 
  2523. <td> 
  2524. <?php 
  2525. if(!isset($M_options['enableincompletesignups'])) { 
  2526. $M_options['enableincompletesignups'] = 'no'; 
  2527. ?> 
  2528. <input type='checkbox' name='enableincompletesignups' id='enableincompletesignups' value='yes' <?php checked('yes', $M_options['enableincompletesignups']); ?> /> 
  2529. </td> 
  2530. </tr> 
  2531. </tbody> 
  2532. </table> 
  2533. */ 
  2534. ?> 
  2535. </div> 
  2536. </div> 
  2537.  
  2538. <?php 
  2539. do_action( 'membership_generaloptions_page' ); 
  2540. ?> 
  2541.  
  2542. <p class="submit"> 
  2543. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  2544. </p> 
  2545.  
  2546. </form> 
  2547. </div> 
  2548. <?php 
  2549.  
  2550. function show_page_options() { 
  2551. global $action, $page, $M_options; 
  2552.  
  2553. $messages = array(); 
  2554. $messages[1] = __('Your options have been updated.', 'membership'); 
  2555. $messages[2] = __('Your page has been created.', 'membership'); 
  2556.  
  2557. ?> 
  2558. <div class="icon32" id="icon-options-general"><br></div> 
  2559. <h2><?php _e('Membership Page Options', 'membership'); ?></h2> 
  2560.  
  2561. <?php 
  2562. if ( isset($_GET['msg']) ) { 
  2563. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  2564. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  2565. ?> 
  2566. <div id="poststuff" class="metabox-holder m-settings"> 
  2567. <form action='' method='post'> 
  2568.  
  2569. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  2570. <input type='hidden' name='action' value='updateoptions' /> 
  2571.  
  2572. <?php 
  2573. wp_nonce_field('update-membership-options'); 
  2574. ?> 
  2575.  
  2576. <div class="postbox"> 
  2577. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Registration page', 'membership'); ?></span></h3> 
  2578. <div class="inside"> 
  2579. <p class='description'><?php _e('This is the page a new user will be redirected to when they want to register on your site.', 'membership'); ?></p> 
  2580. <p class='description'><?php _e('You can include an introduction on the page, for more advanced content around the registration form then you <strong>should</strong> include the [subscriptionform] shortcode in some location on that page. Alternatively leave the page blank for the standard Membership subscription forms.', 'membership'); ?></p> 
  2581.  
  2582. <table class="form-table"> 
  2583. <tbody> 
  2584. <tr valign="top"> 
  2585. <th scope="row"><?php _e('Registration page', 'membership'); ?> 
  2586. <?php echo $this->_tips->add_tip( __('Select a page to use for the registration form. If you do not have one already, then click on <strong>Create Page</strong> to make one.', 'membership') ); ?> 
  2587. </th> 
  2588. <td> 
  2589. <?php 
  2590. if(!isset($M_options['registration_page'])) { 
  2591. $M_options['registration_page'] = ''; 
  2592. $pages = wp_dropdown_pages(array('post_type' => 'page', 'selected' => $M_options['registration_page'], 'name' => 'registration_page', 'show_option_none' => __('None', 'membership'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0)); 
  2593. echo $pages; 
  2594. ?> 
  2595.  <a href='<?php echo wp_nonce_url("admin.php?page=" . $page. "&tab=pages&action=createregistrationpage", 'create-registrationpage'); ?>' class='button-primary' title='<?php _e('Create a default page for the registration page and assign it here.', 'membership'); ?>'><?php _e('Create page', 'membership'); ?></a> 
  2596. <?php if(!empty($M_options['registration_page'])) { ?> 
  2597. <br/> 
  2598. <a href='<?php echo get_permalink($M_options['registration_page']); ?>'><?php _e('view page', 'membership'); ?></a> | <a href='<?php echo admin_url('post.php?post=' . $M_options['registration_page'] . '&action=edit'); ?>'><?php _e('edit page', 'membership'); ?></a> 
  2599. <?php } ?> 
  2600. </td> 
  2601. </tr> 
  2602. </tbody> 
  2603. </table> 
  2604.  
  2605. <p class='description'><?php _e('There are two forms of registration form available, select the one you would like to use on your site below.', 'membership'); ?></p> 
  2606.  
  2607. <table class="form-table"> 
  2608. <tbody> 
  2609. <tr valign="top"> 
  2610. <th scope="row"><?php _e('Form type', 'membership'); ?> 
  2611. <?php echo $this->_tips->add_tip( __('Choose between the original multi-page or Pop up registration methods.', 'membership') ); ?> 
  2612. </th> 
  2613. <td> 
  2614. <select name='formtype' id='formtype'> 
  2615. <option value="original" <?php if(isset($M_options['formtype']) && $M_options['formtype'] == 'original') echo "selected='selected'"; ?>><?php _e('Original membership form', 'membership'); ?></option> 
  2616. <option value="new" <?php if(isset($M_options['formtype']) && $M_options['formtype'] == 'new') echo "selected='selected'"; ?>><?php _e('Popup registration form', 'membership'); ?></option> 
  2617. </select> 
  2618. </td> 
  2619. </tr> 
  2620. </tbody> 
  2621. </table> 
  2622. </div> 
  2623. </div> 
  2624.  
  2625. <div class="postbox"> 
  2626. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Registration completed page', 'membership'); ?></span></h3> 
  2627. <div class="inside"> 
  2628. <p class='description'><?php _e('When a user has signed up for membership and completed any payments required, they will be redirected to this page.', 'membership'); ?></p> 
  2629. <p class='description'><?php _e('You should include a welcome message on this page and some details on what to do next.', 'membership'); ?></p> 
  2630.  
  2631. <table class="form-table"> 
  2632. <tbody> 
  2633. <tr valign="top"> 
  2634. <th scope="row"><?php _e('Registration completed page', 'membership'); ?> 
  2635. <?php echo $this->_tips->add_tip( __('Select a page to use for the Registration completed page. If you do not have one already, then click on <strong>Create Page</strong> to make one.', 'membership') ); ?> 
  2636. </th> 
  2637. <td> 
  2638. <?php 
  2639. if(!isset($M_options['registrationcompleted_page'])) { 
  2640. $M_options['registrationcompleted_page'] = ''; 
  2641. $pages = wp_dropdown_pages(array('post_type' => 'page', 'selected' => $M_options['registrationcompleted_page'], 'name' => 'registrationcompleted_page', 'show_option_none' => __('Select a page', 'membership'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0)); 
  2642. echo $pages; 
  2643. ?> 
  2644.  <a href='<?php echo wp_nonce_url("admin.php?page=" . $page. "&tab=pages&action=createregistrationcompletedpage", 'create-registrationcompletedpage'); ?>' class='button-primary' title='<?php _e('Create a default page for the registration completed page and assign it here.', 'membership'); ?>'><?php _e('Create page', 'membership'); ?></a> 
  2645. <?php if(!empty($M_options['registrationcompleted_page'])) { ?> 
  2646. <br/> 
  2647. <a href='<?php echo get_permalink($M_options['registrationcompleted_page']); ?>'><?php _e('view page', 'membership'); ?></a> | <a href='<?php echo admin_url('post.php?post=' . $M_options['registrationcompleted_page'] . '&action=edit'); ?>'><?php _e('edit page', 'membership'); ?></a> 
  2648. <?php } ?> 
  2649. </td> 
  2650. </tr> 
  2651. </tbody> 
  2652. </table> 
  2653. </div> 
  2654. </div> 
  2655.  
  2656. <div class="postbox"> 
  2657. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Account page', 'membership'); ?></span></h3> 
  2658. <div class="inside"> 
  2659. <p class='description'><?php _e('This is the page a user will be redirected to when they want to view their account or make a payment on their account.', 'membership'); ?></p> 
  2660. <p class='description'><?php _e('It can be left blank to use the standard Membership interface, otherwise it can contain any content you want but <strong>should</strong> contain the [accountform] shortcode in some location.', 'membership'); ?></p> 
  2661.  
  2662. <table class="form-table"> 
  2663. <tbody> 
  2664. <tr valign="top"> 
  2665. <th scope="row"><?php _e('Account page', 'membership'); ?> 
  2666. <?php echo $this->_tips->add_tip( __('Select a page to use for the account form. If you do not have one already, then click on <strong>Create Page</strong> to make one.', 'membership') ); ?> 
  2667. </th> 
  2668. <td> 
  2669. <?php 
  2670. if(!isset($M_options['account_page'])) { 
  2671. $M_options['account_page'] = ''; 
  2672. $pages = wp_dropdown_pages(array('post_type' => 'page', 'selected' => $M_options['account_page'], 'name' => 'account_page', 'show_option_none' => __('Select a page', 'membership'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0)); 
  2673. echo $pages; 
  2674. ?> 
  2675.  <a href='<?php echo wp_nonce_url("admin.php?page=" . $page. "&tab=pages&action=createaccountpage", 'create-accountpage'); ?>' class='button-primary' title='<?php _e('Create a default page for the account page and assign it here.', 'membership'); ?>'><?php _e('Create page', 'membership'); ?></a> 
  2676. <?php if(!empty($M_options['account_page'])) { ?> 
  2677. <br/> 
  2678. <a href='<?php echo get_permalink($M_options['account_page']); ?>'><?php _e('view page', 'membership'); ?></a> | <a href='<?php echo admin_url('post.php?post=' . $M_options['account_page'] . '&action=edit'); ?>'><?php _e('edit page', 'membership'); ?></a> 
  2679. <?php } ?> 
  2680. </td> 
  2681. </tr> 
  2682. </tbody> 
  2683. </table> 
  2684. </div> 
  2685. </div> 
  2686.  
  2687. <div class="postbox"> 
  2688. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Subscriptions page', 'membership'); ?></span></h3> 
  2689. <div class="inside"> 
  2690. <p class='description'><?php _e('This is the page a user will be redirected to when they want to view their subscription details and upgrade / renew them.', 'membership'); ?></p> 
  2691. <p class='description'><?php _e('It can be left blank to use the standard Membership interface, otherwise it can contain any content you want but <strong>should</strong> contain the [renewform] shortcode in some location.', 'membership'); ?></p> 
  2692.  
  2693. <table class="form-table"> 
  2694. <tbody> 
  2695. <tr valign="top"> 
  2696. <th scope="row"><?php _e('Subscriptions page', 'membership'); ?> 
  2697. <?php echo $this->_tips->add_tip( __('Select a page to use for the upgrade form. If you do not have one already, then click on <strong>Create Page</strong> to make one.', 'membership') ); ?> 
  2698. </th> 
  2699. <td> 
  2700. <?php 
  2701. if(!isset($M_options['subscriptions_page'])) { 
  2702. $M_options['subscriptions_page'] = ''; 
  2703. $pages = wp_dropdown_pages(array('post_type' => 'page', 'selected' => $M_options['subscriptions_page'], 'name' => 'subscriptions_page', 'show_option_none' => __('Select a page', 'membership'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0)); 
  2704. echo $pages; 
  2705. ?> 
  2706.  <a href='<?php echo wp_nonce_url("admin.php?page=" . $page. "&tab=pages&action=createsubscriptionspage", 'create-subscriptionspage'); ?>' class='button-primary' title='<?php _e('Create a default page for the upgrade / renewal page and assign it here.', 'membership'); ?>'><?php _e('Create page', 'membership'); ?></a> 
  2707. <?php if(!empty($M_options['subscriptions_page'])) { ?> 
  2708. <br/> 
  2709. <a href='<?php echo get_permalink($M_options['subscriptions_page']); ?>'><?php _e('view page', 'membership'); ?></a> | <a href='<?php echo admin_url('post.php?post=' . $M_options['subscriptions_page'] . '&action=edit'); ?>'><?php _e('edit page', 'membership'); ?></a> 
  2710. <?php } ?> 
  2711. </td> 
  2712. </tr> 
  2713. </tbody> 
  2714. </table> 
  2715. </div> 
  2716. </div> 
  2717.  
  2718. <div class="postbox"> 
  2719. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Protected content page', 'membership'); ?></span></h3> 
  2720. <div class="inside"> 
  2721. <p class='description'><?php _e('If a post / page / content is not available to a user, this is the page that they user will be directed to.', 'membership'); ?></p> 
  2722. <p class='description'><?php _e('This page will only be displayed if the user has tried to access the post / page / content directly or via a link.', 'membership'); ?></p> 
  2723.  
  2724. <table class="form-table"> 
  2725. <tbody> 
  2726. <tr valign="top"> 
  2727. <th scope="row"><?php _e('Protected content page', 'membership'); ?> 
  2728. <?php echo $this->_tips->add_tip( __('Select a page to use for the Protected Content message. If you do not have one already, then click on <strong>Create Page</strong> to make one.', 'membership') ); ?> 
  2729. </th> 
  2730. <td> 
  2731. <?php 
  2732. if(!isset($M_options['nocontent_page'])) { 
  2733. $M_options['nocontent_page'] = ''; 
  2734. $pages = wp_dropdown_pages(array('post_type' => 'page', 'selected' => $M_options['nocontent_page'], 'name' => 'nocontent_page', 'show_option_none' => __('Select a page', 'membership'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0)); 
  2735. echo $pages; 
  2736. ?> 
  2737.  <a href='<?php echo wp_nonce_url("admin.php?page=" . $page. "&tab=pages&action=createnoaccesspage", 'create-noaccesspage'); ?>' class='button-primary' title='<?php _e('Create a default page for the protected content page and assign it here.', 'membership'); ?>'><?php _e('Create page', 'membership'); ?></a> 
  2738. <?php if(!empty($M_options['nocontent_page'])) { ?> 
  2739. <br/> 
  2740. <a href='<?php echo get_permalink($M_options['nocontent_page']); ?>'><?php _e('view page', 'membership'); ?></a> | <a href='<?php echo admin_url('post.php?post=' . $M_options['nocontent_page'] . '&action=edit'); ?>'><?php _e('edit page', 'membership'); ?></a> 
  2741. <?php } ?> 
  2742. </td> 
  2743. </tr> 
  2744. </tbody> 
  2745. </table> 
  2746. </div> 
  2747. </div> 
  2748.  
  2749. <?php 
  2750. do_action( 'membership_pageoptions_page' ); 
  2751. ?> 
  2752.  
  2753. <p class="submit"> 
  2754. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  2755. </p> 
  2756.  
  2757. </form> 
  2758. </div> 
  2759. <?php 
  2760.  
  2761. function show_downloads_options() { 
  2762. global $action, $page, $M_options; 
  2763.  
  2764. $messages = array(); 
  2765. $messages[1] = __('Your options have been updated.', 'membership'); 
  2766.  
  2767. ?> 
  2768. <div class="icon32" id="icon-options-general"><br></div> 
  2769. <h2><?php _e('Download / Media Options', 'membership'); ?></h2> 
  2770.  
  2771. <?php 
  2772. if ( isset($_GET['msg']) ) { 
  2773. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  2774. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  2775. ?> 
  2776.  
  2777. <div id="poststuff" class="metabox-holder m-settings"> 
  2778. <form action='' method='post'> 
  2779.  
  2780. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  2781. <input type='hidden' name='action' value='updateoptions' /> 
  2782.  
  2783. <?php 
  2784. wp_nonce_field('update-membership-options'); 
  2785. ?> 
  2786.  
  2787. <div class="postbox"> 
  2788. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Downloads / Media protection', 'membership'); ?></span></h3> 
  2789. <div class="inside"> 
  2790.  
  2791. <p class='description'><?php _e('Downloads and media files can be protected by remapping their perceived location.', 'membership'); ?></p> 
  2792. <p class='description'><?php _e('Note: If a user determines a files actual location on your server, there is very little we can do to prevent its download, so please be careful about giving out URLs.', 'membership'); ?></p> 
  2793.  
  2794. <table class="form-table"> 
  2795. <tbody> 
  2796. <tr valign="top"> 
  2797. <th scope="row"><?php _e('Protection method', 'membership'); ?> 
  2798. <?php echo $this->_tips->add_tip( __('The method of protection can be changed depending on your needs. Membership offers three methods, <strong>Basic</strong> masks your media directory but leaves any filenames the same, <strong>Complete</strong> masks the media directory and changes the image filename as well and <strong>Hybrid</strong> is for use if you are using a host or server that has a problem with the system (such as some installs of nginx).', 'membership') ); ?> 
  2799. </th> 
  2800. <td> 
  2801. <?php if( empty($M_options['protection_type']) ) $M_options['protection_type'] = 'basic'; ?> 
  2802. <input type='radio' name='protection_type' value='basic' <?php checked($M_options['protection_type'], 'basic'); ?> />  <?php echo __('Basic protection', 'membership'); ?><br/> 
  2803. <input type='radio' name='protection_type' value='complete' <?php checked($M_options['protection_type'], 'complete'); ?>/>  <?php echo __('Complete protection', 'membership'); ?><br/> 
  2804. <input type='radio' name='protection_type' value='hybrid' <?php checked($M_options['protection_type'], 'hybrid'); ?>/>  <?php echo __('Hybrid protection', 'membership'); ?><br/> 
  2805. </td> 
  2806. </tr> 
  2807. <tr valign="top"> 
  2808. <th scope="row"><?php _e('Your uploads location', 'membership'); ?> 
  2809. <?php echo $this->_tips->add_tip( __('This is where membership thinks you have your images stored, if this is not correct then download protection may not work correctly.', 'membership') ); ?> 
  2810. </th> 
  2811. <td> 
  2812. <?php echo membership_upload_url(); ?> 
  2813. </td> 
  2814. </tr> 
  2815. <tr valign="top"> 
  2816. <th scope="row"><?php _e('Masked download URL', 'membership'); ?> 
  2817. <?php echo $this->_tips->add_tip( __('This is the URL that the user will see. You can change the end part to something unique.', 'membership') ); ?> 
  2818. </th> 
  2819. <td> 
  2820. <?php 
  2821. if(!isset($M_options['masked_url'])) { 
  2822. $M_options['masked_url'] = ''; 
  2823. esc_html_e(trailingslashit(get_option('home'))); ?> <input type='text' name='masked_url' id='masked_url' value='<?php esc_attr_e($M_options['masked_url']); 
  2824. ?>' /> / 
  2825. </td> 
  2826. </tr> 
  2827.  
  2828. <tr valign="top"> 
  2829. <th scope="row"><?php _e('Protected groups', 'membership'); ?> 
  2830. <?php echo $this->_tips->add_tip( __('Place each download group name on a new line, removing used groups will leave content visible to all users/members.', 'membership') ); ?> 
  2831. </th> 
  2832. <td> 
  2833. <textarea name='membershipdownloadgroups' id='membershipdownloadgroups' rows='10' cols='40'><?php 
  2834. if(!empty($M_options['membershipdownloadgroups'])) { 
  2835. foreach($M_options['membershipdownloadgroups'] as $key => $value) { 
  2836. if(!empty($value)) { 
  2837. esc_html_e(stripslashes($value)) . "\n"; 
  2838. ?></textarea> 
  2839. </td> 
  2840. </tr> 
  2841.  
  2842. </tbody> 
  2843. </table> 
  2844. </div> 
  2845. </div> 
  2846.  
  2847. <?php 
  2848. do_action( 'membership_downloadsoptions_page' ); 
  2849. ?> 
  2850.  
  2851. <p class="submit"> 
  2852. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  2853. </p> 
  2854.  
  2855. </form> 
  2856. </div> 
  2857. <?php 
  2858.  
  2859. function show_posts_options() { 
  2860. global $action, $page, $M_options; 
  2861.  
  2862. $messages = array(); 
  2863. $messages[1] = __('Your options have been updated.', 'membership'); 
  2864.  
  2865. ?> 
  2866. <div class="icon32" id="icon-options-general"><br></div> 
  2867. <h2><?php _e('Content Protection Options', 'membership'); ?></h2> 
  2868.  
  2869. <?php 
  2870. if ( isset($_GET['msg']) ) { 
  2871. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  2872. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  2873. ?> 
  2874.  
  2875. <div id="poststuff" class="metabox-holder m-settings"> 
  2876. <form action='' method='post'> 
  2877.  
  2878. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  2879. <input type='hidden' name='action' value='updateoptions' /> 
  2880.  
  2881. <?php 
  2882. wp_nonce_field('update-membership-options'); 
  2883. ?> 
  2884. <div class="postbox"> 
  2885. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Shortcode protected content', 'membership'); ?></span></h3> 
  2886. <div class="inside"> 
  2887. <p class='description'><?php _e('You can protect parts of a post or pages content by enclosing it in WordPress shortcodes.', 'membership'); ?></p> 
  2888. <p class='description'><?php _e("Each level you create has it's own shortcode.", 'membership'); ?></p> 
  2889.  
  2890. <table class="form-table"> 
  2891. <tbody> 
  2892. <?php if(!empty($M_options['membershipshortcodes'])) { ?> 
  2893. <tr valign="top"> 
  2894. <th scope="row"><?php _e('Legacy Shortcodes', 'membership'); ?> 
  2895. <?php echo $this->_tips->add_tip( __('Each shortcode can be used to wrap protected content such as [shortcode] Protected content [/shortcode]', 'membership') ); ?> 
  2896. </th> 
  2897. <td> 
  2898. <?php 
  2899. $written = false; 
  2900. if(!empty($M_options['membershipshortcodes'])) { 
  2901. ?> 
  2902. <input name='membershipshortcodes' type='hidden' value='<?php 
  2903. foreach($M_options['membershipshortcodes'] as $key => $value) { 
  2904. if(!empty($value)) { 
  2905. $written = true; 
  2906. echo esc_html(stripslashes($value)) . "\n"; 
  2907. ?>' /> 
  2908. <?php 
  2909. if($written == true) { 
  2910. foreach($M_options['membershipshortcodes'] as $key => $value) { 
  2911. if(!empty($value)) { 
  2912. echo "[" . esc_html(stripslashes($value)) . "]<br/>"; 
  2913. // Bring in the level based shortcodes to the list here 
  2914. $shortcodes = apply_filters('membership_level_shortcodes', array() ); 
  2915. if(!empty($shortcodes)) { 
  2916. foreach($shortcodes as $key => $value) { 
  2917. if(!empty($value)) { 
  2918. $written = true; 
  2919. echo "[" . esc_html(stripslashes($value)) . "]<br/>"; 
  2920.  
  2921.  
  2922. if($written == false) { 
  2923. echo __('No shortcodes available.', 'membership'); 
  2924. ?> 
  2925. </td> 
  2926. </tr> 
  2927. <?php } ?> 
  2928. <tr valign="top"> 
  2929. <th scope="row"><?php _e('Protected content message', 'membership'); ?> 
  2930. <?php echo $this->_tips->add_tip( __("This is the message that is displayed when the content protected by the shortcode can't be shown. Leave blank for no message. HTML allowed.", 'membership') ); ?> 
  2931. </th> 
  2932. <td> 
  2933. <?php 
  2934. $args = array("textarea_name" => "shortcodemessage"); 
  2935. if(!isset($M_options['shortcodemessage'])) { 
  2936. $M_options['shortcodemessage'] = ''; 
  2937. wp_editor( __(stripslashes($M_options['shortcodemessage']), 'membership'), "shortcodemessage", $args ); 
  2938. /** 
  2939. ?> 
  2940. <textarea name='shortcodemessage' id='shortcodemessage' rows='10' cols='80'><?php esc_html_e(stripslashes($M_options['shortcodemessage'])); ?></textarea> 
  2941. <?php 
  2942. */ 
  2943. ?> 
  2944. </td> 
  2945. </tr> 
  2946. </tbody> 
  2947. </table> 
  2948. </div> 
  2949. </div> 
  2950.  
  2951. <div class="postbox"> 
  2952. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Admin only shortcodes', 'membership'); ?></span></h3> 
  2953. <div class="inside"> 
  2954. <p class='description'><?php _e('Sometimes plugins create custom shortcodes but only register them in the public part of your site. This means that the Membership plugin admin interface will not be able to show them in the Shortcode rule.', 'membership'); ?></p> 
  2955. <p class='description'><?php _e('If you find that a shortcode you want to protect is missing from the shortcode rule, then you can add it here.', 'membership'); ?></p> 
  2956.  
  2957. <table class="form-table"> 
  2958. <tbody> 
  2959. <tr valign="top"> 
  2960. <th scope="row"><?php _e('Admin Only Shortcodes', 'membership'); ?> 
  2961. <?php echo $this->_tips->add_tip( __("Place each shortcode text (without the square brackets) on a new line, removing used shortcodes could leave content visible to all users/members.", 'membership') ); ?> 
  2962. </th> 
  2963. <td> 
  2964. <textarea name='membershipadminshortcodes' id='membershipadminshortcodes' rows='10' cols='40'><?php 
  2965. if(!empty($M_options['membershipadminshortcodes'])) { 
  2966. foreach($M_options['membershipadminshortcodes'] as $key => $value) { 
  2967. if(!empty($value)) { 
  2968. esc_html_e(stripslashes($value)) . "\n"; 
  2969. ?></textarea> 
  2970. </td> 
  2971. </tr> 
  2972. </tbody> 
  2973. </table> 
  2974. </div> 
  2975. </div> 
  2976.  
  2977. <div class="postbox"> 
  2978. <h3 class="hndle" style='cursor:auto;'><span><?php _e('More tag default', 'membership'); ?></span></h3> 
  2979. <div class="inside"> 
  2980. <p class='description'><?php _e('Content placed after the More tag in a post or page can be protected by setting the visibility below. This setting can be overridden within each individual level.', 'membership'); ?></p> 
  2981.  
  2982. <table class="form-table"> 
  2983. <tbody> 
  2984. <tr valign="top"> 
  2985. <th scope="row"><?php _e('Show content after the More tag', 'membership'); ?></th> 
  2986. <td> 
  2987. <select name='moretagdefault' id='moretagdefault'> 
  2988. <option value="yes" <?php if(isset($M_options['moretagdefault']) && $M_options['moretagdefault'] == 'yes') echo "selected='selected'"; ?>><?php _e('Yes - More tag content is visible', 'membership'); ?></option> 
  2989. <option value="no" <?php if(isset($M_options['moretagdefault']) && $M_options['moretagdefault'] == 'no') echo "selected='selected'"; ?>><?php _e('No - More tag content not visible', 'membership'); ?></option> 
  2990. </select> 
  2991. </td> 
  2992. </tr> 
  2993.  
  2994. <tr valign="top"> 
  2995. <th scope="row"><?php _e('No access message', 'membership'); ?> 
  2996. <?php echo $this->_tips->add_tip( __("This is the message that is displayed when the content protected by the moretag can't be shown. Leave blank for no message. HTML allowed.", 'membership') ); ?> 
  2997. </th> 
  2998. <td> 
  2999. <?php 
  3000. $args = array("textarea_name" => "moretagmessage"); 
  3001. if(!isset($M_options['moretagmessage'])) { 
  3002. $M_options['moretagmessage'] = ''; 
  3003. wp_editor( __(stripslashes($M_options['moretagmessage']), 'membership'), "moretagmessage", $args ); 
  3004. /** 
  3005. ?> 
  3006. <textarea name='moretagmessage' id='moretagmessage' rows='5' cols='40'><?php esc_html_e(stripslashes($M_options['moretagmessage'])); ?></textarea> 
  3007. <?php 
  3008. */ 
  3009. ?> 
  3010. </td> 
  3011. </tr> 
  3012. </tbody> 
  3013. </table> 
  3014. </div> 
  3015. </div> 
  3016.  
  3017. <?php 
  3018. do_action( 'membership_postoptions_page' ); 
  3019. ?> 
  3020.  
  3021. <p class="submit"> 
  3022. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  3023. </p> 
  3024.  
  3025. </form> 
  3026. </div> 
  3027. <?php 
  3028.  
  3029. function show_extras_options() { 
  3030. global $action, $page, $M_options; 
  3031.  
  3032. $messages = array(); 
  3033. $messages[1] = __('Your options have been updated.', 'membership'); 
  3034.  
  3035. ?> 
  3036. <div class="icon32" id="icon-options-general"><br></div> 
  3037. <h2><?php _e('Extra Options', 'membership'); ?></h2> 
  3038.  
  3039. <?php 
  3040. if ( isset($_GET['msg']) ) { 
  3041. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  3042. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  3043. ?> 
  3044. <div id="poststuff" class="metabox-holder m-settings"> 
  3045. <form action='' method='post'> 
  3046.  
  3047. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  3048. <input type='hidden' name='action' value='updateoptions' /> 
  3049.  
  3050. <?php 
  3051. wp_nonce_field('update-membership-options'); 
  3052. ?> 
  3053. <div class="postbox"> 
  3054. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Payments currency', 'membership'); ?></span></h3> 
  3055. <div class="inside"> 
  3056. <p class='description'><?php _e('This is the currency that will be used across all gateways. Note: Some gateways have a limited number of currencies available.', 'membership'); ?></p> 
  3057.  
  3058. <table class="form-table"> 
  3059. <tbody> 
  3060. <tr valign="top"> 
  3061. <th scope="row"><?php _e('Payment currencys', 'membership'); ?></th> 
  3062. <td> 
  3063. <select name="paymentcurrency"> 
  3064. <?php 
  3065. $currency = $M_options['paymentcurrency']; 
  3066. $sel_currency = empty($currency) ? 'USD' : $currency; 
  3067. $currencies = array( 
  3068. 'AUD' => __('AUD - Australian Dollar', 'membership'),  
  3069. 'BRL' => __('BRL - Brazilian Real', 'membership'),  
  3070. 'CAD' => __('CAD - Canadian Dollar', 'membership'),  
  3071. 'CHF' => __('CHF - Swiss Franc', 'membership'),  
  3072. 'CZK' => __('CZK - Czech Koruna', 'membership'),  
  3073. 'DKK' => __('DKK - Danish Krone', 'membership'),  
  3074. 'EUR' => __('EUR - Euro', 'membership'),  
  3075. 'GBP' => __('GBP - Pound Sterling', 'membership'),  
  3076. 'HKD' => __('HKD - Hong Kong Dollar', 'membership'),  
  3077. 'HUF' => __('HUF - Hungarian Forint', 'membership'),  
  3078. 'ILS' => __('ILS - Israeli Shekel', 'membership'),  
  3079. 'JPY' => __('JPY - Japanese Yen', 'membership'),  
  3080. 'MYR' => __('MYR - Malaysian Ringgits', 'membership'),  
  3081. 'MXN' => __('MXN - Mexican Peso', 'membership'),  
  3082. 'NOK' => __('NOK - Norwegian Krone', 'membership'),  
  3083. 'NZD' => __('NZD - New Zealand Dollar', 'membership'),  
  3084. 'PHP' => __('PHP - Philippine Pesos', 'membership'),  
  3085. 'PLN' => __('PLN - Polish Zloty', 'membership'),  
  3086. 'SEK' => __('SEK - Swedish Krona', 'membership'),  
  3087. 'SGD' => __('SGD - Singapore Dollar', 'membership'),  
  3088. 'TWD' => __('TWD - Taiwan New Dollars', 'membership'),  
  3089. 'THB' => __('THB - Thai Baht', 'membership'),  
  3090. 'USD' => __('USD - U.S. Dollar', 'membership'),  
  3091. 'ZAR' => __('ZAR - South African Rand') 
  3092. ); 
  3093.  
  3094. $currencies = apply_filters('membership_available_currencies', $currencies); 
  3095.  
  3096. foreach ($currencies as $key => $value) { 
  3097. echo '<option value="' . esc_attr($key) . '"'; 
  3098. if($key == $sel_currency) echo 'selected="selected"'; 
  3099. echo '>' . esc_html($value) . '</option>' . "\n"; 
  3100. ?> 
  3101. </select> 
  3102. </td> 
  3103. </tr> 
  3104. </tbody> 
  3105. </table> 
  3106. </div> 
  3107. </div> 
  3108.  
  3109. <div class="postbox"> 
  3110. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Membership renewal', 'membership'); ?></span></h3> 
  3111. <div class="inside"> 
  3112. <p class='description'><?php _e('If you are using single payment gateways, then you should set the number of days before expiry that the renewal form is displayed on the Account page.', 'membership'); ?></p> 
  3113.  
  3114.  
  3115. <table class="form-table"> 
  3116. <tbody> 
  3117. <tr valign="top"> 
  3118. <th scope="row"><?php _e('Renewal period limit', 'membership'); ?></th> 
  3119. <td> 
  3120. <select name="renewalperiod"> 
  3121. <?php 
  3122. $renewalperiod = $M_options['renewalperiod']; 
  3123.  
  3124. for($n=1; $n <= 365; $n++) { 
  3125. echo '<option value="' . esc_attr($n) . '"'; 
  3126. if($n == $renewalperiod) echo 'selected="selected"'; 
  3127. echo '>' . esc_html($n) . '</option>' . "\n"; 
  3128. ?> 
  3129. </select> <?php _e('day(s)', 'membership'); ?> 
  3130. </td> 
  3131. </tr> 
  3132. </tbody> 
  3133. </table> 
  3134. </div> 
  3135. </div> 
  3136.  
  3137. <div class="postbox"> 
  3138. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Membership upgrades', 'membership'); ?></span></h3> 
  3139. <div class="inside"> 
  3140. <p class='description'><?php _e('You should limit the amount of time allowed between membership upgrades in order to prevent members abusing the upgrade process.', 'membership'); ?></p> 
  3141.  
  3142.  
  3143. <table class="form-table"> 
  3144. <tbody> 
  3145. <tr valign="top"> 
  3146. <th scope="row"><?php _e('Upgrades period limit', 'membership'); ?></th> 
  3147. <td> 
  3148. <select name="upgradeperiod"> 
  3149. <?php 
  3150. $upgradeperiod = $M_options['upgradeperiod']; 
  3151. // Set a default of 1 day, but allow the selection of 0 days 
  3152. if(empty($upgradeperiod) && $upgradeperiod != 0) { 
  3153. $upgradeperiod = 1; 
  3154.  
  3155. for($n=0; $n <= 365; $n++) { 
  3156. echo '<option value="' . esc_attr($n) . '"'; 
  3157. if($n == $upgradeperiod) echo 'selected="selected"'; 
  3158. echo '>' . esc_html($n) . '</option>' . "\n"; 
  3159. ?> 
  3160. </select> <?php _e('day(s)', 'membership'); ?> 
  3161. </td> 
  3162. </tr> 
  3163. </tbody> 
  3164. </table> 
  3165. </div> 
  3166. </div> 
  3167.  
  3168. <div class="postbox"> 
  3169. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Membership wizard', 'membership'); ?></span></h3> 
  3170. <div class="inside"> 
  3171. <p class='description'><?php _e('If you accidentally dismissed the membership wizard and would like to show it again, then check the box below.', 'membership'); ?></p> 
  3172.  
  3173.  
  3174. <table class="form-table"> 
  3175. <tbody> 
  3176. <tr valign="top"> 
  3177. <th scope="row"><?php _e('Show membership wizard', 'membership'); ?></th> 
  3178. <td> 
  3179. <?php 
  3180. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  3181. if(function_exists('get_blog_option')) { 
  3182. if(function_exists('switch_to_blog')) { 
  3183. switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE); 
  3184. $wizard_visible = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_wizard_visible', 'yes'); 
  3185. if(function_exists('restore_current_blog')) { 
  3186. restore_current_blog(); 
  3187. } else { 
  3188. $wizard_visible = get_option('membership_wizard_visible', 'yes'); 
  3189. } else { 
  3190. $wizard_visible = get_option('membership_wizard_visible', 'yes'); 
  3191. ?> 
  3192. <input type='checkbox' name='membershipwizard' value='yes' <?php if($wizard_visible == 'yes') echo "checked='checked'"; ?>/> 
  3193. </td> 
  3194. </tr> 
  3195. </tbody> 
  3196. </table> 
  3197. </div> 
  3198. </div> 
  3199.  
  3200. <?php 
  3201. do_action( 'membership_extrasoptions_page' ); 
  3202. ?> 
  3203.  
  3204. <p class="submit"> 
  3205. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  3206. </p> 
  3207.  
  3208. </form> 
  3209. </div> 
  3210. <?php 
  3211.  
  3212. function show_users_options() { 
  3213. global $action, $page, $M_options; 
  3214.  
  3215. $messages = array(); 
  3216. $messages[1] = __('Membership admins have been updated.', 'membership'); 
  3217.  
  3218. ?> 
  3219. <div class="icon32" id="icon-options-general"><br></div> 
  3220. <h2><?php _e('Membership Admin Users', 'membership'); ?></h2> 
  3221.  
  3222. <?php 
  3223. if ( isset($_GET['msg']) ) { 
  3224. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  3225. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  3226. ?> 
  3227. <div id="poststuff" class="metabox-holder m-settings"> 
  3228. <form action='' method='post'> 
  3229.  
  3230. <input type='hidden' name='page' value='<?php echo $page; ?>' /> 
  3231. <input type='hidden' name='action' value='updateoptions' /> 
  3232.  
  3233. <?php 
  3234. wp_nonce_field('update-membership-options'); 
  3235. ?> 
  3236. <div class="postbox"> 
  3237. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Membership Admin Users', 'membership'); ?></span></h3> 
  3238. <div class="inside"> 
  3239. <p class='description'><?php _e('You can add or remove the ability for specific admin user accounts to manage the Membership plugin by checking or unchecking the boxes next to the relevant username.', 'membership'); ?></p> 
  3240.  
  3241. <?php 
  3242. $columns = array( "name" => __('User Login', 'membership') 
  3243. ); 
  3244.  
  3245. $columns = apply_filters('membership_adminuserscolumns', $columns); 
  3246.  
  3247. $wp_user_search = new WP_User_Query( array( 'role' => 'administrator' ) ); 
  3248. $admins = $wp_user_search->get_results(); 
  3249.  
  3250. ?> 
  3251.  
  3252. <table cellspacing="0" class="widefat fixed"> 
  3253. <thead> 
  3254. <tr> 
  3255. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  3256. <?php 
  3257. foreach($columns as $key => $col) { 
  3258. ?> 
  3259. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  3260. <?php 
  3261. ?> 
  3262. </tr> 
  3263. </thead> 
  3264.  
  3265. <tfoot> 
  3266. <tr> 
  3267. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  3268. <?php 
  3269. reset($columns); 
  3270. foreach($columns as $key => $col) { 
  3271. ?> 
  3272. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  3273. <?php 
  3274. ?> 
  3275. </tr> 
  3276. </tfoot> 
  3277.  
  3278. <tbody> 
  3279. <?php 
  3280. if(!empty($admins)) { 
  3281. $user_id = get_current_user_id(); 
  3282. foreach($admins as $key => $admin) { 
  3283. ?> 
  3284. <tr valign="middle" class="alternate" id="admin-<?php echo $admin->ID; ?>"> 
  3285. <th class="check-column" scope="row"> 
  3286. <?php if($user_id != $admin->ID) { 
  3287. $user = new WP_User( $admin->ID ); 
  3288. if($user->has_cap('membershipadmin')) { 
  3289. ?> 
  3290. <input type="checkbox" value="<?php echo esc_attr($admin->ID); ?>" name="admincheck[]" checked='checked'> 
  3291. <?php 
  3292. } else { 
  3293. ?> 
  3294. <input type="checkbox" value="<?php echo esc_attr($admin->ID); ?>" name="admincheck[]" > 
  3295. <?php 
  3296. } ?> 
  3297. </th> 
  3298. <td class="column-name"> 
  3299. <strong><?php echo esc_html(stripslashes($admin->user_login)); ?></strong><br/> 
  3300. <?php 
  3301. if($user_id == $admin->ID) { 
  3302. _e('You can not remove your own permissions to manage the membership system whilst logged in.', 'membership'); 
  3303. ?> 
  3304. </td> 
  3305. </tr> 
  3306. <?php 
  3307. } else { 
  3308. $columncount = count($columns) + 1; 
  3309. ?> 
  3310. <tr valign="middle" class="alternate" > 
  3311. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('There are no Admin users - something may have gone wrong.', 'membership'); ?></td> 
  3312. </tr> 
  3313. <?php 
  3314. ?> 
  3315.  
  3316. </tbody> 
  3317. </table> 
  3318.  
  3319. </div> 
  3320. </div> 
  3321.  
  3322. <?php 
  3323. do_action( 'membership_adminusersoptions_page' ); 
  3324. ?> 
  3325.  
  3326. <p class="submit"> 
  3327. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'membership'); ?>" /> 
  3328. </p> 
  3329.  
  3330. </form> 
  3331. </div> 
  3332. <?php 
  3333.  
  3334. function handle_options_panel() { 
  3335.  
  3336. global $action, $page, $M_options; 
  3337.  
  3338. wp_reset_vars( array('action', 'page') ); 
  3339.  
  3340. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  3341. if(function_exists('get_blog_option')) { 
  3342. if(function_exists('switch_to_blog')) { 
  3343. switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE); 
  3344.  
  3345. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  3346. } else { 
  3347. $M_options = get_option('membership_options', array()); 
  3348. } else { 
  3349. $M_options = get_option('membership_options', array()); 
  3350.  
  3351. $tab = (isset($_GET['tab'])) ? $_GET['tab'] : ''; 
  3352. if(empty($tab)) { 
  3353. $tab = 'general'; 
  3354.  
  3355. ?> 
  3356. <div class='wrap nosubsub'> 
  3357. <?php 
  3358. $menus = array(); 
  3359. $menus['general'] = __('General', 'membership'); 
  3360. $menus['pages'] = __('Membership Pages', 'membership'); 
  3361. $menus['posts'] = __('Content Protection', 'membership'); 
  3362. $menus['downloads'] = __('Downloads / Media', 'membership'); 
  3363. $menus['users'] = __('Membership Admins', 'membership'); 
  3364. $menus['extras'] = __('Extras', 'membership'); 
  3365.  
  3366. $menus = apply_filters('membership_options_menus', $menus); 
  3367. ?> 
  3368.  
  3369. <?php 
  3370. if ( current_user_can('manage_options') && !get_option('permalink_structure') ) { 
  3371. echo '<div class="error"><p>'.__('You must enable Pretty Permalinks for Membership to function correctly - <a href="options-permalink.php">Enable now »</a>', 'membership').'</p></div>'; 
  3372.  
  3373. ?> 
  3374.  
  3375. <h3 class="nav-tab-wrapper"> 
  3376. <?php 
  3377. foreach($menus as $key => $menu) { 
  3378. ?> 
  3379. <a class="nav-tab<?php if($tab == $key) echo ' nav-tab-active'; ?>" href="admin.php?page=<?php echo $page; ?>&tab=<?php echo $key; ?>"><?php echo $menu; ?></a> 
  3380. <?php 
  3381.  
  3382. ?> 
  3383. </h3> 
  3384.  
  3385. <?php 
  3386.  
  3387. switch($tab) { 
  3388.  
  3389. case 'general': $this->show_general_options(); 
  3390. break; 
  3391.  
  3392. case 'pages': $this->show_page_options(); 
  3393. break; 
  3394.  
  3395. case 'posts': $this->show_posts_options(); 
  3396. break; 
  3397.  
  3398. case 'downloads': $this->show_downloads_options(); 
  3399. break; 
  3400.  
  3401. case 'extras': $this->show_extras_options(); 
  3402. break; 
  3403.  
  3404. case 'users': $this->show_users_options(); 
  3405. break; 
  3406.  
  3407. default: do_action('membership_option_menu_' . $tab); 
  3408. break; 
  3409.  
  3410.  
  3411.  
  3412. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  3413. if(function_exists('restore_current_blog')) { 
  3414. restore_current_blog(); 
  3415.  
  3416. ?> 
  3417.  
  3418. </div> <!-- wrap --> 
  3419. <?php 
  3420.  
  3421. function default_membership_sections($sections) { 
  3422.  
  3423. $sections['main'] = array( "title" => __('Main rules', 'membership') ); 
  3424.  
  3425. $sections['content'] = array( "title" => __('Content rules', 'membership') ); 
  3426.  
  3427. return $sections; 
  3428.  
  3429. function handle_level_edit_form($level_id = false, $clone = false) { 
  3430.  
  3431. global $page, $M_Rules, $M_SectionRules; 
  3432.  
  3433. if($level_id && !$clone) { 
  3434. $mlevel = new M_Level( $level_id ); 
  3435. $level = $mlevel->get(); 
  3436. } else { 
  3437.  
  3438. if($clone) { 
  3439. $mlevel = new M_Level( $level_id ); 
  3440. $level = $mlevel->get(); 
  3441.  
  3442. $level->level_title .= __(' clone', 'membership'); 
  3443. } else { 
  3444. $level = new stdclass; 
  3445. $level->level_title = __('new level', 'membership'); 
  3446. $level->id = time() * -1; 
  3447.  
  3448.  
  3449. // Get the relevant parts 
  3450. if(isset($mlevel)) { 
  3451. $positives = $mlevel->get_rules('positive'); 
  3452. $negatives = $mlevel->get_rules('negative'); 
  3453.  
  3454. // Re-arrange the rules 
  3455. $rules = array(); $p = array(); $n = array(); 
  3456. if(!empty($positives)) { 
  3457. foreach($positives as $positive) { 
  3458. $rules[$positive->rule_area] = maybe_unserialize($positive->rule_value); 
  3459. $p[$positive->rule_area] = maybe_unserialize($positive->rule_value); 
  3460. if(!empty($negatives)) { 
  3461. foreach($negatives as $negative) { 
  3462. $rules[$negative->rule_area] = maybe_unserialize($negative->rule_value); 
  3463. $n[$negative->rule_area] = maybe_unserialize($negative->rule_value); 
  3464.  
  3465. // Check which tab we should open the edit form with 
  3466. if(!empty($p) && !empty($n)) { 
  3467. // We have content in both areas - so start with advanced open 
  3468. $advancedtab = 'activetab'; 
  3469. $negativetab = ''; 
  3470. $positivetab = ''; 
  3471.  
  3472. $advancedcontent = 'activecontent'; 
  3473. $negativecontent = 'activecontent'; 
  3474. $positivecontent = 'activecontent'; 
  3475. } else { 
  3476. if(!empty($n)) { 
  3477. // We have content in the negative area - so start with that 
  3478. $advancedtab = ''; 
  3479. $negativetab = 'activetab'; 
  3480. $positivetab = ''; 
  3481.  
  3482. $advancedcontent = 'inactivecontent'; 
  3483. $negativecontent = 'activecontent'; 
  3484. $positivecontent = 'inactivecontent'; 
  3485. } else { 
  3486. // Default to the positive area 
  3487. $advancedtab = ''; 
  3488. $negativetab = ''; 
  3489. $positivetab = 'activetab'; 
  3490.  
  3491. $advancedcontent = 'inactivecontent'; 
  3492. $negativecontent = 'inactivecontent'; 
  3493. $positivecontent = 'activecontent'; 
  3494.  
  3495. ?> 
  3496. <div class='wrap nosubsub'> 
  3497. <div class="icon32" id="icon-link-manager"><br></div> 
  3498. <h2><?php echo __('Edit ', 'membership') . " - " . esc_html($level->level_title); ?></h2> 
  3499.  
  3500. <?php 
  3501. if ( isset($usemsg) ) { 
  3502. echo '<div id="message" class="updated fade"><p>' . $messages[$usemsg] . '</p></div>'; 
  3503. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  3504. ?> 
  3505.  
  3506. <div class='level-liquid-left'> 
  3507.  
  3508. <div id='level-left'> 
  3509. <form action='?page=<?php echo $page; ?>' name='leveledit' method='post'> 
  3510. <input type='hidden' name='level_id' id='level_id' value='<?php echo $level->id; ?>' /> 
  3511.  
  3512. <input type='hidden' name='ontab' id='ontab' value='positive' /> 
  3513.  
  3514. <input type='hidden' name='beingdragged' id='beingdragged' value='' /> 
  3515. <input type='hidden' name='in-positive-rules' id='in-positive-rules' value=', <?php echo implode(', ', array_keys($p)); ?>' /> 
  3516. <input type='hidden' name='in-negative-rules' id='in-negative-rules' value=', <?php echo implode(', ', array_keys($n)); ?>' /> 
  3517.  
  3518. <input type='hidden' name='postive-rules-order' id='postive-rules-order' value='' /> 
  3519. <input type='hidden' name='negative-rules-order' id='negative-rules-order' value='' /> 
  3520.  
  3521. <div id='edit-level' class='level-holder-wrap'> 
  3522. <div class='sidebar-name no-movecursor'> 
  3523. <h3><?php echo esc_html($level->level_title); ?></h3> 
  3524. </div> 
  3525. <div class='level-holder'> 
  3526. <div class='level-details'> 
  3527. <label for='level_title'><?php _e('Level title', 'membership'); ?></label><?php //echo $this->_tips->add_tip( __('This is the title used throughout the system to identify this level.', 'membership') ); ?><br/> 
  3528. <input class='wide' type='text' name='level_title' id='level_title' value='<?php echo esc_attr($level->level_title); ?>' /> 
  3529. <br/><br/> 
  3530. <label for='level_shortcode'><?php _e('Level shortcode', 'membership'); ?></label><?php echo $this->_tips->add_tip( __('The shortcode for this level is based on the title (above). It can be used to wrap content that you only want to be seen by members on this level e.g. [levelshortcode] protected content [/levelshortcode]', 'membership') ); ?> 
  3531. <?php if($level->id > 0) { 
  3532. echo "[" . M_normalize_shortcode($level->level_title) . "]"; 
  3533. } else { 
  3534. _e('Save your level to create the shortcode', 'membership'); 
  3535. } ?> 
  3536. </div> 
  3537.  
  3538. <?php do_action('membership_level_form_before_rules', $level->id); ?> 
  3539.  
  3540. <ul class='leveltabs'> 
  3541. <li class='positivetab <?php echo $positivetab; ?>'><div class='downarrow'></div><a href='#positive'><div><?php _e('Positive Rules', 'membership'); ?></div></a></li> 
  3542. <li class='negativetab <?php echo $negativetab; ?>'><div class='downarrow'></div><a href='#negative'><div><?php _e('Negative Rules', 'membership'); ?></div></a></li> 
  3543. <li class='advancedtab <?php echo $advancedtab; ?>'><div class='downarrow'></div><a href='#advanced'><div><?php _e('Advanced (both)', 'membership'); ?></div></a></li> 
  3544. </ul> 
  3545.  
  3546. <div class='advancedtabwarning <?php echo $advancedcontent; ?>'> 
  3547. <?php _e('<strong>Warning:</strong> using both positive and negative rules on the same level can cause conflicts and unpredictable behaviour.', 'membership'); ?> 
  3548. </div> 
  3549.  
  3550. <div class='positivecontent <?php echo $positivecontent; ?>'> 
  3551. <h3 class='positive positivetitle <?php echo $advancedcontent; ?>'><?php _e('Positive rules', 'membership'); ?></h3> 
  3552. <p class='description'><?php _e('These are the areas / elements that a member of this level can access.', 'membership'); ?></p> 
  3553.  
  3554. <div id='positive-rules' class='level-droppable-rules levels-sortable'> 
  3555. <?php _e('Drop here', 'membership'); ?> 
  3556. </div> 
  3557.  
  3558. <div id='positive-rules-holder'> 
  3559. <?php do_action('membership_level_form_before_positive_rules', $level->id); ?> 
  3560. <?php 
  3561. if(!empty($p)) { 
  3562. foreach($p as $key => $value) { 
  3563.  
  3564. if(isset($M_Rules[$key])) { 
  3565. $rule = new $M_Rules[$key](); 
  3566.  
  3567. $rule->admin_main($value); 
  3568. ?> 
  3569. <?php do_action('membership_level_form_after_positive_rules', $level->id); ?> 
  3570. </div> 
  3571. </div> 
  3572.  
  3573. <div class='negativecontent <?php echo $negativecontent; ?>'> 
  3574. <h3 class='negative negativetitle <?php echo $advancedcontent; ?>'><?php _e('Negative rules', 'membership'); ?></h3> 
  3575. <p class='description'><?php _e('These are the areas / elements that a member of this level doesn\'t have access to.', 'membership'); ?></p> 
  3576.  
  3577. <div id='negative-rules' class='level-droppable-rules levels-sortable'> 
  3578. <?php _e('Drop here', 'membership'); ?> 
  3579. </div> 
  3580.  
  3581. <div id='negative-rules-holder'> 
  3582. <?php do_action('membership_level_form_before_negative_rules', $level->id); ?> 
  3583.  
  3584. <?php 
  3585. if(!empty($n)) { 
  3586. foreach($n as $key => $value) { 
  3587. if(isset($M_Rules[$key])) { 
  3588. $rule = new $M_Rules[$key](); 
  3589.  
  3590. $rule->admin_main($value); 
  3591. ?> 
  3592.  
  3593. <?php do_action('membership_level_form_after_negative_rules', $level->id); ?> 
  3594.  
  3595. </div> 
  3596. </div> 
  3597.  
  3598. <div class='advancedcontent <?php echo $advancedcontent; ?>'> 
  3599. <h3><?php _e('Custom shortcode protected content message', 'membership'); ?></h3> 
  3600. <p class='description'><?php _e('If you want a protected content message to be displayed for this level then you can enter it here.', 'membership'); ?></p> 
  3601. <?php 
  3602. $args = array("textarea_name" => "level_protectedcontent", "textarea_rows" => 20); 
  3603. if(!empty($mlevel)) { 
  3604. $level_protectedcontent = $mlevel->get_meta( 'level_protectedcontent' ); 
  3605. if(empty($level_protectedcontent)) { 
  3606. $level_protectedcontent = ''; 
  3607. wp_editor( stripslashes($level_protectedcontent), "level_protectedcontent", $args ); 
  3608. ?> 
  3609. </div> 
  3610.  
  3611. <div class='advancedcontent <?php echo $advancedcontent; ?>'> 
  3612. <?php do_action('membership_level_form_after_rules', $level->id); ?> 
  3613. </div> 
  3614.  
  3615. <div class='buttons'> 
  3616. <?php 
  3617. if($level->id > 0) { 
  3618. wp_original_referer_field(true, 'previous'); wp_nonce_field('update-' . $level->id); 
  3619. ?> 
  3620. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel edit'><?php _e('Cancel', 'membership'); ?></a> 
  3621. <input type='submit' value='<?php _e('Update', 'membership'); ?>' class='button-primary' /> 
  3622. <input type='hidden' name='action' value='updated' /> 
  3623. <?php 
  3624. } else { 
  3625. wp_original_referer_field(true, 'previous'); wp_nonce_field('add-' . $level->id); 
  3626. ?> 
  3627. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a> 
  3628. <input type='submit' value='<?php _e('Add', 'membership'); ?>' class='button-primary' /> 
  3629. <input type='hidden' name='action' value='added' /> 
  3630. <?php 
  3631. ?> 
  3632. </div> 
  3633.  
  3634. </div> 
  3635. </div> 
  3636. </form> 
  3637. </div> 
  3638.  
  3639.  
  3640. <div id='hiden-actions'> 
  3641. <?php 
  3642.  
  3643. $sections = apply_filters('membership_level_sections', array()); 
  3644.  
  3645. foreach($sections as $key => $section) { 
  3646.  
  3647. if(isset($M_SectionRules[$key])) { 
  3648. foreach($M_SectionRules[$key] as $mrule => $mclass) { 
  3649. $rule = new $mclass(); 
  3650.  
  3651. if(!array_key_exists($mrule, $rules)) { 
  3652. $rule->admin_main(false); 
  3653.  
  3654.  
  3655. ?> 
  3656. </div> <!-- hidden-actions --> 
  3657.  
  3658. </div> <!-- level-liquid-left --> 
  3659.  
  3660. <div class='level-liquid-right'> 
  3661. <div class="level-holder-wrap"> 
  3662. <?php 
  3663.  
  3664. do_action( 'membership_sidebar_top_level' ); 
  3665. do_action( 'membership_sidebar_top', 'level' ); 
  3666.  
  3667. $sections = apply_filters('membership_level_sections', array()); 
  3668.  
  3669. foreach($sections as $key => $section) { 
  3670. ?> 
  3671.  
  3672. <div class="sidebar-name no-movecursor"> 
  3673. <h3><?php echo $section['title']; ?></h3> 
  3674. </div> 
  3675. <div class="section-holder" id="sidebar-<?php echo $key; ?>" style="min-height: 98px;"> 
  3676. <ul class='levels level-levels-draggable'> 
  3677. <?php 
  3678.  
  3679. if(isset($M_SectionRules[$key])) { 
  3680. foreach($M_SectionRules[$key] as $mrule => $mclass) { 
  3681. $rule = new $mclass(); 
  3682.  
  3683. if(!array_key_exists($mrule, $rules)) { 
  3684. $rule->admin_sidebar(false); 
  3685. } else { 
  3686. $rule->admin_sidebar(true); 
  3687.  
  3688. ?> 
  3689. </ul> 
  3690. </div> 
  3691. <?php 
  3692. ?> 
  3693. </div> <!-- level-holder-wrap --> 
  3694.  
  3695. </div> <!-- level-liquid-left --> 
  3696.  
  3697. </div> <!-- wrap --> 
  3698.  
  3699. <?php 
  3700.  
  3701. function handle_levels_updates() { 
  3702.  
  3703. global $action, $page; 
  3704.  
  3705. wp_reset_vars( array('action', 'page') ); 
  3706.  
  3707. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  3708. if(addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') { 
  3709. $action = 'bulk-delete'; 
  3710.  
  3711. if(addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') { 
  3712. $action = 'bulk-toggle'; 
  3713.  
  3714. switch(addslashes($action)) { 
  3715.  
  3716. case 'removeheader': $this->dismiss_user_help( $page ); 
  3717. wp_safe_redirect( remove_query_arg( 'action' ) ); 
  3718. break; 
  3719.  
  3720. case 'added': $levels = $levels = $this->get_membership_levels(); 
  3721. if(count($levels) >= 3) { 
  3722. wp_die( __( 'Cheatin’ uh?' ) ); 
  3723. } else { 
  3724. $id = (int) $_POST['level_id']; 
  3725. check_admin_referer('add-' . $id); 
  3726. if($id) { 
  3727.  
  3728. $level = new M_Level($id); 
  3729.  
  3730. if($level->add()) { 
  3731. // Add in the meta information 
  3732. if(!empty($_POST['level_protectedcontent'])) { 
  3733. $level->update_meta( 'level_protectedcontent', $_POST['level_protectedcontent'] ); 
  3734. // redirect 
  3735. wp_safe_redirect( add_query_arg( 'msg', 1, 'admin.php?page=' . $page ) ); 
  3736. } else { 
  3737. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  3738. } else { 
  3739. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  3740. break; 
  3741. case 'updated': $id = (int) $_POST['level_id']; 
  3742. check_admin_referer('update-' . $id); 
  3743. if($id) { 
  3744.  
  3745. $level = new M_Level($id); 
  3746.  
  3747. if($level->update()) { 
  3748. // update the meta information 
  3749. if(!empty($_POST['level_protectedcontent'])) { 
  3750. $level->update_meta( 'level_protectedcontent', $_POST['level_protectedcontent'] ); 
  3751. } else { 
  3752. $level->delete_meta( 'level_protectedcontent' ); 
  3753. // redirect 
  3754. wp_safe_redirect( add_query_arg( 'msg', 3, 'admin.php?page=' . $page ) ); 
  3755. } else { 
  3756. wp_safe_redirect( add_query_arg( 'msg', 5, 'admin.php?page=' . $page ) ); 
  3757. } else { 
  3758. wp_safe_redirect( add_query_arg( 'msg', 5, 'admin.php?page=' . $page ) ); 
  3759. break; 
  3760.  
  3761. case 'delete': if(isset($_GET['level_id'])) { 
  3762. $level_id = (int) $_GET['level_id']; 
  3763.  
  3764. check_admin_referer('delete-level_' . $level_id); 
  3765.  
  3766. $level = new M_Level($level_id); 
  3767.  
  3768. if($level->delete($level_id)) { 
  3769. // delete the meta information 
  3770. $level->delete_meta( 'level_protectedcontent' ); 
  3771. // redirect 
  3772. wp_safe_redirect( add_query_arg( 'msg', 2, wp_get_referer() ) ); 
  3773. } else { 
  3774. wp_safe_redirect( add_query_arg( 'msg', 6, wp_get_referer() ) ); 
  3775.  
  3776. break; 
  3777.  
  3778. case 'toggle': if(isset($_GET['level_id'])) { 
  3779. $level_id = (int) $_GET['level_id']; 
  3780.  
  3781. check_admin_referer('toggle-level_' . $level_id); 
  3782.  
  3783. $level = new M_Level($level_id); 
  3784.  
  3785. if( $level->toggleactivation() ) { 
  3786. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  3787. } else { 
  3788. wp_safe_redirect( add_query_arg( 'msg', 8, wp_get_referer() ) ); 
  3789.  
  3790. break; 
  3791.  
  3792. case 'bulk-delete': 
  3793. check_admin_referer('bulk-levels'); 
  3794. foreach($_GET['levelcheck'] AS $value) { 
  3795. if(is_numeric($value)) { 
  3796. $level_id = (int) $value; 
  3797.  
  3798. $level = new M_Level($level_id); 
  3799.  
  3800. $level->delete(); 
  3801.  
  3802. wp_safe_redirect( add_query_arg( 'msg', 2, wp_get_referer() ) ); 
  3803. break; 
  3804.  
  3805. case 'bulk-toggle': 
  3806. check_admin_referer('bulk-levels'); 
  3807. foreach($_GET['levelcheck'] AS $value) { 
  3808. if(is_numeric($value)) { 
  3809. $level_id = (int) $value; 
  3810.  
  3811. $level = new M_Level($level_id); 
  3812.  
  3813. $level->toggleactivation(); 
  3814.  
  3815. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  3816. break; 
  3817.  
  3818.  
  3819.  
  3820. function handle_levels_panel() { 
  3821.  
  3822. global $action, $page; 
  3823.  
  3824. switch(addslashes($action)) { 
  3825.  
  3826. case 'edit': if(isset($_GET['level_id'])) { 
  3827. $level_id = (int) $_GET['level_id']; 
  3828. $this->handle_level_edit_form($level_id); 
  3829. return; // So we don't see the rest of this page 
  3830. break; 
  3831.  
  3832. case 'clone': if(isset($_GET['clone_id'])) { 
  3833. $level_id = (int) $_GET['clone_id']; 
  3834. $this->handle_level_edit_form($level_id, true); 
  3835. return; // So we don't see the rest of this page 
  3836. break; 
  3837.  
  3838. $filter = array(); 
  3839.  
  3840. if(isset($_GET['s'])) { 
  3841. $s = stripslashes($_GET['s']); 
  3842. $filter['s'] = $s; 
  3843. } else { 
  3844. $s = ''; 
  3845.  
  3846. if(isset($_GET['level_id'])) { 
  3847. $filter['level_id'] = stripslashes($_GET['level_id']); 
  3848.  
  3849. if(isset($_GET['order_by'])) { 
  3850. $filter['order_by'] = stripslashes($_GET['order_by']); 
  3851.  
  3852. $messages = array(); 
  3853. $messages[1] = __('Membership Level added.', 'membership'); 
  3854. $messages[2] = __('Membership Level deleted.', 'membership'); 
  3855. $messages[3] = __('Membership Level updated.', 'membership'); 
  3856. $messages[4] = __('Membership Level not added.', 'membership'); 
  3857. $messages[5] = __('Membership Level not updated.', 'membership'); 
  3858. $messages[6] = __('Membership Level not deleted.', 'membership'); 
  3859.  
  3860. $messages[7] = __('Membership Level activation toggled.', 'membership'); 
  3861. $messages[8] = __('Membership Level activation not toggled.', 'membership'); 
  3862.  
  3863. $messages[9] = __('Membership Levels updated.', 'membership'); 
  3864.  
  3865. $levels = $this->get_membership_levels($filter); 
  3866.  
  3867. ?> 
  3868. <div class='wrap nosubsub'> 
  3869. <div class="icon32" id="icon-link-manager"><br></div> 
  3870. <h2><?php _e('Access Levels', 'membership'); ?><?php if(count($levels) <= 3) { ?><a class="add-new-h2" href="admin.php?page=<?php echo $page; ?>&action=edit&level_id="><?php _e('Add New', 'membership'); ?></a><<?php } ?>/h2> 
  3871.  
  3872. <?php 
  3873. if ( isset($_GET['msg']) ) { 
  3874. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  3875. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  3876.  
  3877. if($this->show_user_help( $page )) { 
  3878. ?> 
  3879. <div class='screenhelpheader'> 
  3880. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  3881. <?php 
  3882. ob_start(); 
  3883. include_once(membership_dir('membershipincludes/help/header.levels.php')); 
  3884. echo ob_get_clean(); 
  3885. ?> 
  3886. </div> 
  3887. <?php 
  3888.  
  3889. ?> 
  3890.  
  3891. <form method="get" action="?page=<?php echo esc_attr($page); ?>" class="search-form"> 
  3892. <p class="search-box"> 
  3893. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  3894. <label for="membership-search-input" class="screen-reader-text"><?php _e('Search Levels', 'membership'); ?>:</label> 
  3895. <input type="text" value="<?php echo esc_attr($s); ?>" name="s" id="membership-search-input"> 
  3896. <input type="submit" class="button" value="<?php _e('Search Levels', 'membership'); ?>"> 
  3897. </p> 
  3898. </form> 
  3899.  
  3900. <br class='clear' /> 
  3901.  
  3902. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="posts-filter"> 
  3903.  
  3904. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  3905.  
  3906. <div class="tablenav"> 
  3907.  
  3908. <div class="alignleft actions"> 
  3909. <select name="action"> 
  3910. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  3911. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  3912. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  3913. </select> 
  3914. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply', 'membership'); ?>"> 
  3915.  
  3916. <select name="level_id"> 
  3917. <option <?php if(isset($_GET['level_id']) && addslashes($_GET['level_id']) == 'all') echo "selected='selected'"; ?> value="all"><?php _e('View all Levels', 'membership'); ?></option> 
  3918. <option <?php if(isset($_GET['level_id']) && addslashes($_GET['level_id']) == 'active') echo "selected='selected'"; ?> value="active"><?php _e('View active Levels', 'membership'); ?></option> 
  3919. <option <?php if(isset($_GET['level_id']) && addslashes($_GET['level_id']) == 'inactive') echo "selected='selected'"; ?> value="inactive"><?php _e('View inactive Levels', 'membership'); ?></option> 
  3920.  
  3921. </select> 
  3922.  
  3923. <select name="order_by"> 
  3924. <option <?php if(isset($_GET['order_by']) && addslashes($_GET['order_by']) == 'order_id') echo "selected='selected'"; ?> value="order_id"><?php _e('Order by Level ID', 'membership'); ?></option> 
  3925. <option <?php if(isset($_GET['order_by']) && addslashes($_GET['order_by']) == 'order_name') echo "selected='selected'"; ?> value="order_name"><?php _e('Order by Level Name', 'membership'); ?></option> 
  3926. </select> 
  3927. <input type="submit" class="button-secondary" value="<?php _e('Filter'); ?>" id="post-query-submit"> 
  3928.  
  3929. </div> 
  3930.  
  3931. <div class="alignright actions"> 
  3932. </div> 
  3933.  
  3934. <br class="clear"> 
  3935. </div> 
  3936.  
  3937. <div class="clear"></div> 
  3938.  
  3939. <?php 
  3940. wp_original_referer_field(true, 'previous'); wp_nonce_field('bulk-levels'); 
  3941.  
  3942. $columns = array( "name" => __('Level Name', 'membership'),  
  3943. "active" => __('Active', 'membership'),  
  3944. "users" => __('Users', 'membership'),  
  3945. "shortcode" => __('Shortcode', 'membership') . $this->_tips->add_tip( __('The shortcode for this level is based on the title. It can be used to wrap content that you only want to be seen by members on this level e.g. [levelshortcode] protected content [/levelshortcode], use the [not-levelshortcode] shortcodes to wrap content that should be visible to people not on a particular level.', 'membership') ) 
  3946. ); 
  3947.  
  3948. $columns = apply_filters('membership_levelcolumns', $columns); 
  3949.  
  3950. ?> 
  3951.  
  3952. <table cellspacing="0" class="widefat fixed"> 
  3953. <thead> 
  3954. <tr> 
  3955. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  3956. <?php 
  3957. foreach($columns as $key => $col) { 
  3958. ?> 
  3959. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  3960. <?php 
  3961. ?> 
  3962. </tr> 
  3963. </thead> 
  3964.  
  3965. <tfoot> 
  3966. <tr> 
  3967. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  3968. <?php 
  3969. reset($columns); 
  3970. foreach($columns as $key => $col) { 
  3971. ?> 
  3972. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  3973. <?php 
  3974. ?> 
  3975. </tr> 
  3976. </tfoot> 
  3977.  
  3978. <tbody> 
  3979. <?php 
  3980. if($levels) { 
  3981. $levelcount = 0; 
  3982. foreach($levels as $key => $level) { 
  3983. $levelcount++; if($levelcount >= 4) break; 
  3984. ?> 
  3985. <tr valign="middle" class="alternate" id="level-<?php echo $level->id; ?>"> 
  3986. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $level->id; ?>" name="levelcheck[]"></th> 
  3987. <td class="column-name"> 
  3988. <strong><a title="<?php _e('Level ID:', 'membership'); ?> <?php echo esc_attr($level->id); ?>" href="?page=<?php echo $page; ?>&action=edit&level_id=<?php echo $level->id; ?>" class="row-title"><?php echo esc_html($level->level_title); ?></a></strong> 
  3989. <?php 
  3990. $actions = array(); 
  3991. //$actions['id'] = "<strong>" . __('ID : ', 'membership') . $level->id . "</strong>"; 
  3992. $actions['edit'] = "<span class='edit'><a href='?page=" . $page . "&action=edit&level_id=" . $level->id . "'>" . __('Edit', 'membership') . "</a></span>"; 
  3993. if($level->level_active == 0) { 
  3994. $actions['toggle'] = "<span class='edit activate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&level_id=" . $level->id . "", 'toggle-level_' . $level->id) . "'>" . __('Activate', 'membership') . "</a></span>"; 
  3995. } else { 
  3996. $actions['toggle'] = "<span class='edit deactivate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&level_id=" . $level->id . "", 'toggle-level_' . $level->id) . "'>" . __('Deactivate', 'membership') . "</a></span>"; 
  3997. $actions['clone'] = "<span class='edit'><a href='?page=" . $page . "&action=clone&clone_id=" . $level->id . "'>" . __('Clone', 'membership') . "</a></span>"; 
  3998.  
  3999. $actions['delete'] = "<span class='delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=delete&level_id=" . $level->id . "", 'delete-level_' . $level->id) . "'>" . __('Delete', 'membership') . "</a></span>"; 
  4000.  
  4001. ?> 
  4002. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  4003. </td> 
  4004. <td class="column-active"> 
  4005. <?php 
  4006. switch($level->level_active) { 
  4007. case 0: echo "<span class='membershipinactivestatus'>" . __('Inactive', 'membership') . "</span>"; 
  4008. break; 
  4009. case 1: echo "<span class='membershipactivestatus'>" . __('Active', 'membership') . "</span>"; 
  4010. break; 
  4011. ?> 
  4012. </td> 
  4013. <td class="column-users"> 
  4014. <strong> 
  4015. <?php echo $this->count_on_level( $level->id ); ?> 
  4016. </strong> 
  4017. </td> 
  4018. <td class="column-shortcode"> 
  4019. <?php echo "[" . M_normalize_shortcode($level->level_title) . "]"; ?><br/> 
  4020. <?php echo "[not-" . M_normalize_shortcode($level->level_title) . "]"; ?> 
  4021. </td> 
  4022. </tr> 
  4023. <?php 
  4024. } else { 
  4025. $columncount = count($columns) + 1; 
  4026. ?> 
  4027. <tr valign="middle" class="alternate" > 
  4028. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No Membership levels where found, click above to add one.', 'membership'); ?></td> 
  4029. </tr> 
  4030. <?php 
  4031. ?> 
  4032.  
  4033. </tbody> 
  4034. </table> 
  4035.  
  4036.  
  4037. <div class="tablenav"> 
  4038.  
  4039. <div class="alignleft actions"> 
  4040. <select name="action2"> 
  4041. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  4042. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  4043. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  4044. </select> 
  4045. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="<?php _e('Apply', 'membership'); ?>"> 
  4046. </div> 
  4047. <div class="alignright actions"> 
  4048. </div> 
  4049. <br class="clear"> 
  4050. </div> 
  4051.  
  4052.  
  4053.  
  4054. </form> 
  4055.  
  4056. </div> <!-- wrap --> 
  4057. <?php 
  4058.  
  4059. function handle_sub_edit_form($sub_id = false, $clone = false) { 
  4060.  
  4061. global $page; 
  4062.  
  4063. $msub = new M_Subscription( $sub_id ); 
  4064. if($sub_id && !$clone) { 
  4065. $sub = $msub->get(); 
  4066. } else { 
  4067. if($clone) { 
  4068. $sub = $msub->get(); 
  4069. $sub->sub_name .= __(' clone', 'membership'); 
  4070. } else { 
  4071. $sub = new stdclass; 
  4072. $sub->sub_name = __('new subscription', 'membership'); 
  4073. $sub->id = time() * -1; 
  4074.  
  4075.  
  4076. // Get the relevant parts 
  4077. if(isset($msub)) { 
  4078. $levels = $msub->get_levels(); 
  4079.  
  4080. ?> 
  4081. <div class='wrap nosubsub'> 
  4082. <div class="icon32" id="icon-link-manager"><br></div> 
  4083. <?php 
  4084. if($sub->id < 0) { 
  4085. ?> 
  4086. <h2><?php echo __('Add ', 'membership') . " - " . esc_html($sub->sub_name); ?></h2> 
  4087. <?php 
  4088. } else { 
  4089. ?> 
  4090. <h2><?php echo __('Edit ', 'membership') . " - " . esc_html(stripslashes($sub->sub_name)); ?></h2> 
  4091. <?php 
  4092. ?> 
  4093.  
  4094. <?php 
  4095. if ( isset($usemsg) ) { 
  4096. echo '<div id="message" class="updated fade"><p>' . $messages[$usemsg] . '</p></div>'; 
  4097. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  4098. ?> 
  4099.  
  4100. <div class='sub-liquid-left'> 
  4101.  
  4102. <div id='sub-left'> 
  4103. <form action='?page=<?php echo $page; ?>' name='subedit' method='post'> 
  4104. <input type='hidden' name='sub_id' id='sub_id' value='<?php echo $sub->id; ?>' /> 
  4105.  
  4106. <div id='edit-sub' class='sub-holder-wrap'> 
  4107. <div class='sidebar-name no-movecursor'> 
  4108. <h3><?php echo esc_html(stripslashes($sub->sub_name)); ?></h3> 
  4109. </div> 
  4110. <div class='sub-holder'> 
  4111. <div class='sub-details'> 
  4112. <label for='sub_name'><?php _e('Subscription name', 'membership'); ?></label> 
  4113. <input class='wide' type='text' name='sub_name' id='sub_name' value='<?php echo esc_attr(stripslashes($sub->sub_name)); ?>' /> 
  4114. <br/><br/> 
  4115. <label for='sub_name'><?php _e('Subscription description', 'membership'); ?></label> 
  4116. <?php 
  4117. $args = array("textarea_name" => "sub_description", "textarea_rows" => 5); 
  4118.  
  4119. if(!isset($sub->sub_description)) { 
  4120. $sub->sub_description = ''; 
  4121.  
  4122. wp_editor( stripslashes($sub->sub_description), "sub_description", $args ); 
  4123. ?> 
  4124. <br/> 
  4125. <?php 
  4126. if(!isset($sub->sub_pricetext)) { 
  4127. $sub->sub_pricetext = ''; 
  4128. ?> 
  4129. <label for='sub_pricetext'><?php _e('Subscription price text', 'membership'); ?><?php echo $this->_tips->add_tip( __('The text you want to show as the price on the subscription form. E.G. Only $25 per month.', 'membership') ); ?></label> 
  4130. <input class='wide' type='text' name='sub_pricetext' id='sub_pricetext' value='<?php echo esc_attr(stripslashes($sub->sub_pricetext)); ?>' /> 
  4131. <?php do_action('membership_subscription_form_after_details', $sub->id); ?> 
  4132.  
  4133. </div> 
  4134.  
  4135. <?php do_action('membership_subscription_form_before_levels', $sub->id); ?> 
  4136.  
  4137. <h3><?php _e('Membership levels', 'membership'); ?></h3> 
  4138. <p class='description'><?php _e('These are the levels that are part of this subscription and the order a user will travel through them. Any levels highlighted in red will never be reached due to the settings of previous levels.', 'membership'); ?></p> 
  4139. <div id='membership-levels-start'> 
  4140. <div id="main-start" class="sub-operation" style="display: block;"> 
  4141. <h2 class="sidebar-name"><?php _e('Starting Point', 'membership'); ?></h2> 
  4142. <div class="inner-operation"> 
  4143. <p class='description'><?php _e('A new signup for this subscription will start here and immediately pass to the next membership level listed below.', 'membership'); ?></p> 
  4144. </div> 
  4145. </div> 
  4146. </div> 
  4147.  
  4148. <ul id='membership-levels-holder'> 
  4149. <?php do_action('membership_subscription_form_before_level_list', $sub->id); ?> 
  4150. <?php 
  4151. $msub->sub_details(); 
  4152. ?> 
  4153. <?php do_action('membership_subscription_form_after_level_list', $sub->id); ?> 
  4154. </ul> 
  4155. <div id='membership-levels' class='droppable-levels levels-sortable'> 
  4156. <?php _e('Drop here', 'membership'); ?> 
  4157. </div> 
  4158.  
  4159. <?php 
  4160. // Hidden fields 
  4161. ?> 
  4162. <input type='hidden' name='beingdragged' id='beingdragged' value='' /> 
  4163. <input type='hidden' name='level-order' id='level-order' value=', <?php echo implode(', ', $msub->levelorder); ?>' /> 
  4164.  
  4165. <?php do_action('membership_subscription_form_after_levels', $sub->id); ?> 
  4166.  
  4167. <div class='buttons'> 
  4168. <?php 
  4169. if($sub->id > 0) { 
  4170. wp_original_referer_field(true, 'previous'); wp_nonce_field('update-' . $sub->id); 
  4171. ?> 
  4172. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel edit'><?php _e('Cancel', 'membership'); ?></a> 
  4173. <input type='submit' value='<?php _e('Update', 'membership'); ?>' class='button-primary' /> 
  4174. <input type='hidden' name='action' value='updated' /> 
  4175. <?php 
  4176. } else { 
  4177. wp_original_referer_field(true, 'previous'); wp_nonce_field('add-' . $sub->id); 
  4178. ?> 
  4179. <a href='?page=<?php echo $page; ?>' class='cancellink' title='Cancel add'><?php _e('Cancel', 'membership'); ?></a> 
  4180. <input type='submit' value='<?php _e('Add', 'membership'); ?>' class='button-primary' /> 
  4181. <input type='hidden' name='action' value='added' /> 
  4182. <?php 
  4183. ?> 
  4184. </div> 
  4185.  
  4186. </div> 
  4187. </div> 
  4188. </form> 
  4189. </div> 
  4190.  
  4191.  
  4192. <div id='hiden-actions'> 
  4193.  
  4194. <div id='template-holder'> 
  4195. <?php 
  4196. $msub->sub_template(); 
  4197. ?> 
  4198. </div> 
  4199.  
  4200. </div> <!-- hidden-actions --> 
  4201.  
  4202. </div> <!-- sub-liquid-left --> 
  4203.  
  4204. <div class='sub-liquid-right'> 
  4205. <div class="sub-holder-wrap"> 
  4206.  
  4207. <?php 
  4208. do_action( 'membership_sidebar_top_subscription' ); 
  4209. do_action( 'membership_sidebar_top', 'subscription' ); 
  4210. ?> 
  4211.  
  4212. <div class="sidebar-name no-movecursor"> 
  4213. <h3><?php _e('Membership levels', 'membership'); ?></h3> 
  4214. </div> 
  4215. <div class="level-holder" id="sidebar-levels" style="min-height: 98px;"> 
  4216. <ul class='subs subs-draggable'> 
  4217. <?php 
  4218. $levels = $this->get_membership_levels(); 
  4219. foreach( (array) $levels as $key => $level) { 
  4220. ?> 
  4221. <li class='level-draggable' id='level-<?php echo $level->id; ?>'> 
  4222.  
  4223. <div class='action action-draggable'> 
  4224. <div class='action-top closed'> 
  4225. <a href="#available-actions" class="action-button hide-if-no-js"></a> 
  4226. <?php echo esc_html($level->level_title); ?> 
  4227. </div> 
  4228. <div class='action-body closed'> 
  4229. <p> 
  4230. <a href='#addtosubscription' class='action-to-subscription' title="<?php _e('Add this level to the bottom of the membership levels list.', 'membership'); ?>"><?php _e('Add to Subscription', 'membership'); ?></a> 
  4231. </p> 
  4232. </div> 
  4233. </div> 
  4234. </li> 
  4235. <?php 
  4236. ?> 
  4237. </ul> 
  4238. </div> 
  4239. </div> <!-- sub-holder-wrap --> 
  4240.  
  4241. </div> <!-- sub-liquid-right --> 
  4242.  
  4243. </div> <!-- wrap --> 
  4244.  
  4245. <?php 
  4246.  
  4247. function handle_subscriptions_updates() { 
  4248.  
  4249. global $action, $page; 
  4250.  
  4251. wp_reset_vars( array('action', 'page') ); 
  4252.  
  4253. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  4254. if(addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') { 
  4255. $action = 'bulk-delete'; 
  4256.  
  4257. if(addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') { 
  4258. $action = 'bulk-toggle'; 
  4259.  
  4260. if(addslashes($_GET['action']) == 'togglepublic' || addslashes($_GET['action2']) == 'togglepublic') { 
  4261. $action = 'bulk-togglepublic'; 
  4262.  
  4263. switch(addslashes($action)) { 
  4264.  
  4265. case 'removeheader': $this->dismiss_user_help( $page ); 
  4266. wp_safe_redirect( remove_query_arg( 'action' ) ); 
  4267. break; 
  4268.  
  4269. case 'added': $subs = $this->get_subscriptions(); 
  4270. if(count($subs) >= 3) { 
  4271. wp_die( __( 'Cheatin’ uh?' ) ); 
  4272. } else { 
  4273. $id = (int) $_POST['sub_id']; 
  4274. check_admin_referer('add-' . $id); 
  4275.  
  4276. if($id) { 
  4277. $sub = new M_Subscription( $id ); 
  4278.  
  4279. if($sub->add()) { 
  4280. wp_safe_redirect( add_query_arg( 'msg', 1, 'admin.php?page=' . $page ) ); 
  4281. } else { 
  4282. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  4283. } else { 
  4284. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  4285. break; 
  4286. case 'updated': $id = (int) $_POST['sub_id']; 
  4287. check_admin_referer('update-' . $id); 
  4288. if($id) { 
  4289. $sub = new M_Subscription( $id ); 
  4290.  
  4291. if($sub->update()) { 
  4292. wp_safe_redirect( add_query_arg( 'msg', 3, 'admin.php?page=' . $page ) ); 
  4293. } else { 
  4294. wp_safe_redirect( add_query_arg( 'msg', 5, 'admin.php?page=' . $page ) ); 
  4295. } else { 
  4296. wp_safe_redirect( add_query_arg( 'msg', 5, 'admin.php?page=' . $page ) ); 
  4297. break; 
  4298.  
  4299. case 'delete': if(isset($_GET['sub_id'])) { 
  4300. $sub_id = (int) $_GET['sub_id']; 
  4301.  
  4302. check_admin_referer('delete-sub_' . $sub_id); 
  4303.  
  4304. $sub = new M_Subscription( $sub_id ); 
  4305.  
  4306. if($sub->delete()) { 
  4307. wp_safe_redirect( add_query_arg( 'msg', 2, wp_get_referer() ) ); 
  4308. } else { 
  4309. wp_safe_redirect( add_query_arg( 'msg', 6, wp_get_referer() ) ); 
  4310.  
  4311. break; 
  4312.  
  4313. case 'togglemakepublic': 
  4314. if(isset($_GET['sub_id'])) { 
  4315. $sub_id = (int) $_GET['sub_id']; 
  4316.  
  4317. check_admin_referer('togglemakepublic-sub_' . $sub_id); 
  4318.  
  4319. $sub = new M_Subscription( $sub_id ); 
  4320.  
  4321. $sub->toggleactivation(); 
  4322.  
  4323. if($sub->togglepublic()) { 
  4324. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  4325. } else { 
  4326. wp_safe_redirect( add_query_arg( 'msg', 8, wp_get_referer() ) ); 
  4327.  
  4328. break; 
  4329.  
  4330. case 'toggle': if(isset($_GET['sub_id'])) { 
  4331. $sub_id = (int) $_GET['sub_id']; 
  4332.  
  4333. check_admin_referer('toggle-sub_' . $sub_id); 
  4334.  
  4335. $sub = new M_Subscription( $sub_id ); 
  4336.  
  4337. if($sub->toggleactivation()) { 
  4338. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  4339. } else { 
  4340. wp_safe_redirect( add_query_arg( 'msg', 8, wp_get_referer() ) ); 
  4341.  
  4342. break; 
  4343.  
  4344. case 'togglepublic': 
  4345. if(isset($_GET['sub_id'])) { 
  4346. $sub_id = (int) $_GET['sub_id']; 
  4347.  
  4348. check_admin_referer('toggle-pubsub_' . $sub_id); 
  4349.  
  4350. $sub = new M_Subscription( $sub_id ); 
  4351.  
  4352. if($sub->togglepublic()) { 
  4353. wp_safe_redirect( add_query_arg( 'msg', 9, wp_get_referer() ) ); 
  4354. } else { 
  4355. wp_safe_redirect( add_query_arg( 'msg', 5, wp_get_referer() ) ); 
  4356.  
  4357. break; 
  4358.  
  4359. case 'bulk-delete': 
  4360. check_admin_referer('bulk-subscriptions'); 
  4361. foreach($_GET['subcheck'] AS $value) { 
  4362. if(is_numeric($value)) { 
  4363. $sub_id = (int) $value; 
  4364.  
  4365. $sub = new M_Subscription( $sub_id ); 
  4366.  
  4367. $sub->delete(); 
  4368.  
  4369. wp_safe_redirect( add_query_arg( 'msg', 2, wp_get_referer() ) ); 
  4370. break; 
  4371.  
  4372. case 'bulk-toggle': 
  4373. check_admin_referer('bulk-subscriptions'); 
  4374. foreach($_GET['subcheck'] AS $value) { 
  4375. if(is_numeric($value)) { 
  4376. $sub_id = (int) $value; 
  4377.  
  4378. $sub = new M_Subscription( $sub_id ); 
  4379.  
  4380. $sub->toggleactivation(); 
  4381.  
  4382. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  4383. break; 
  4384.  
  4385. case 'bulk-togglepublic': 
  4386. check_admin_referer('bulk-subscriptions'); 
  4387. foreach($_GET['subcheck'] AS $value) { 
  4388. if(is_numeric($value)) { 
  4389. $sub_id = (int) $value; 
  4390.  
  4391. $sub = new M_Subscription( $sub_id ); 
  4392.  
  4393. $sub->togglepublic(); 
  4394.  
  4395. wp_safe_redirect( add_query_arg( 'msg', 9, wp_get_referer() ) ); 
  4396. break; 
  4397.  
  4398.  
  4399.  
  4400. function handle_subs_panel() { 
  4401.  
  4402. // Subscriptions panel 
  4403. global $action, $page; 
  4404.  
  4405. $filter = array(); 
  4406.  
  4407. if($action == 'edit') { 
  4408. if(isset($_GET['sub_id'])) { 
  4409. $sub_id = (int) $_GET['sub_id']; 
  4410. $this->handle_sub_edit_form($sub_id); 
  4411. return; // So we don't see the rest of this page 
  4412.  
  4413. if(isset($_GET['s'])) { 
  4414. $s = stripslashes($_GET['s']); 
  4415. $filter['s'] = $s; 
  4416. } else { 
  4417. $s = ''; 
  4418.  
  4419. if(isset($_GET['sub_status'])) { 
  4420. $filter['sub_status'] = stripslashes($_GET['sub_status']); 
  4421.  
  4422. if(isset($_GET['order_by'])) { 
  4423. $filter['order_by'] = stripslashes($_GET['order_by']); 
  4424.  
  4425. $messages = array(); 
  4426. $messages[1] = __('Subscription added.', 'membership'); 
  4427. $messages[2] = __('Subscription deleted.', 'membership'); 
  4428. $messages[3] = __('Subscription updated.', 'membership'); 
  4429. $messages[4] = __('Subscription not added.', 'membership'); 
  4430. $messages[5] = __('Subscription not updated.', 'membership'); 
  4431. $messages[6] = __('Subscription not deleted.', 'membership'); 
  4432.  
  4433. $messages[7] = __('Subscription activation toggled.', 'membership'); 
  4434. $messages[8] = __('Subscription activation not toggled.', 'membership'); 
  4435.  
  4436. $messages[9] = __('Subscriptions updated.', 'membership'); 
  4437.  
  4438.  
  4439. $subs = $this->get_subscriptions($filter); 
  4440.  
  4441. ?> 
  4442. <div class='wrap nosubsub'> 
  4443. <div class="icon32" id="icon-link-manager"><br></div> 
  4444. <h2><?php _e('Subscription Plans', 'membership'); ?><?php if(count($subs) < 3) { ?><a class="add-new-h2" href="admin.php?page=<?php echo $page; ?>&action=edit&sub_id="><?php _e('Add New', 'membership'); ?></a><?php } ?></h2> 
  4445.  
  4446. <?php 
  4447. if ( isset($_GET['msg']) ) { 
  4448. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  4449. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  4450.  
  4451. if($this->show_user_help( $page )) { 
  4452. ?> 
  4453. <div class='screenhelpheader'> 
  4454. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  4455. <?php 
  4456. ob_start(); 
  4457. include_once(membership_dir('membershipincludes/help/header.subscriptions.php')); 
  4458. echo ob_get_clean(); 
  4459. ?> 
  4460. </div> 
  4461. <?php 
  4462.  
  4463. ?> 
  4464.  
  4465. <form method="get" action="?page=<?php echo esc_attr($page); ?>" class="search-form"> 
  4466. <p class="search-box"> 
  4467. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  4468. <label for="subscription-search-input" class="screen-reader-text"><?php _e('Search Memberships', 'membership'); ?>:</label> 
  4469. <input type="text" value="<?php echo esc_attr($s); ?>" name="s" id="subscription-search-input"> 
  4470. <input type="submit" class="button" value="<?php _e('Search Subscriptions', 'membership'); ?>"> 
  4471. </p> 
  4472. </form> 
  4473.  
  4474. <br class='clear' /> 
  4475.  
  4476. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="posts-filter"> 
  4477.  
  4478. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  4479.  
  4480. <div class="tablenav"> 
  4481.  
  4482. <div class="alignleft actions"> 
  4483. <select name="action"> 
  4484. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  4485. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  4486. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  4487. <option value="togglepublic"><?php _e('Toggle public status', 'membership'); ?></option> 
  4488. </select> 
  4489. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply'); ?>"> 
  4490.  
  4491. <select name="sub_status"> 
  4492. <option <?php if(isset($_GET['sub_status']) && addslashes($_GET['sub_id']) == 'all') echo "selected='selected'"; ?> value="all"><?php _e('View all subscriptions', 'membership'); ?></option> 
  4493. <option <?php if(isset($_GET['sub_status']) && addslashes($_GET['sub_id']) == 'active') echo "selected='selected'"; ?> value="active"><?php _e('View active subscriptions', 'membership'); ?></option> 
  4494. <option <?php if(isset($_GET['sub_status']) && addslashes($_GET['sub_id']) == 'inactive') echo "selected='selected'"; ?> value="inactive"><?php _e('View inactive subscriptions', 'membership'); ?></option> 
  4495. <option <?php if(isset($_GET['sub_status']) && addslashes($_GET['sub_id']) == 'public') echo "selected='selected'"; ?> value="public"><?php _e('View public subscriptions', 'membership'); ?></option> 
  4496. <option <?php if(isset($_GET['sub_status']) && addslashes($_GET['sub_id']) == 'private') echo "selected='selected'"; ?> value="private"><?php _e('View private subscriptions', 'membership'); ?></option> 
  4497. </select> 
  4498.  
  4499. <select name="order_by"> 
  4500. <option <?php if(isset($_GET['order_by']) && addslashes($_GET['order_by']) == 'order_id') echo "selected='selected'"; ?> value="order_id"><?php _e('Order by subscription ID', 'membership'); ?></option> 
  4501. <option <?php if(isset($_GET['order_by']) && addslashes($_GET['order_by']) == 'order_name') echo "selected='selected'"; ?> value="order_name"><?php _e('Order by subscription name', 'membership'); ?></option> 
  4502. </select> 
  4503. <input type="submit" class="button-secondary" value="<?php _e('Filter', 'membership'); ?>" id="post-query-submit"> 
  4504.  
  4505. </div> 
  4506.  
  4507. <div class="alignright actions"> 
  4508. </div> 
  4509.  
  4510. <br class="clear"> 
  4511. </div> 
  4512.  
  4513. <div class="clear"></div> 
  4514.  
  4515. <?php 
  4516. wp_original_referer_field(true, 'previous'); wp_nonce_field('bulk-subscriptions'); 
  4517.  
  4518. $columns = array( "name" => __('Subscription Name', 'membership'),  
  4519. "active" => __('Active', 'membership'),  
  4520. "public" => __('Public', 'membership'),  
  4521. "users" => __('Users', 'membership') 
  4522. ); 
  4523.  
  4524. $columns = apply_filters('subscription_columns', $columns); 
  4525.  
  4526. ?> 
  4527.  
  4528. <table cellspacing="0" class="widefat fixed"> 
  4529. <thead> 
  4530. <tr> 
  4531. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  4532. <?php 
  4533. foreach($columns as $key => $col) { 
  4534. ?> 
  4535. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  4536. <?php 
  4537. ?> 
  4538. </tr> 
  4539. </thead> 
  4540.  
  4541. <tfoot> 
  4542. <tr> 
  4543. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  4544. <?php 
  4545. reset($columns); 
  4546. foreach($columns as $key => $col) { 
  4547. ?> 
  4548. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  4549. <?php 
  4550. ?> 
  4551. </tr> 
  4552. </tfoot> 
  4553.  
  4554. <tbody> 
  4555. <?php 
  4556. if($subs) { 
  4557. $subcount = 0; 
  4558. foreach($subs as $key => $sub) { 
  4559. $subcount++; if($subcount >= 4) break; 
  4560. ?> 
  4561. <tr valign="middle" class="alternate" id="sub-<?php echo $sub->id; ?>"> 
  4562. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $sub->id; ?>" name="subcheck[]"></th> 
  4563. <td class="column-name"> 
  4564. <strong><a title="<?php _e('Subscription ID:', 'membership'); ?> <?php echo esc_attr($sub->id); ?>" href="?page=<?php echo $page; ?>&action=edit&sub_id=<?php echo $sub->id; ?>" class="row-title"><?php echo esc_html(stripslashes($sub->sub_name)); ?></a></strong> 
  4565. <?php 
  4566. $actions = array(); 
  4567. //$actions['id'] = "<strong>" . __('ID : ', 'membership') . $sub->id . "</strong>"; 
  4568. $actions['edit'] = "<span class='edit'><a href='?page=" . $page . "&action=edit&sub_id=" . $sub->id . "'>" . __('Edit', 'membership') . "</a></span>"; 
  4569.  
  4570. if($sub->sub_active == 0 && $sub->sub_public == 0) { 
  4571. $actions['toggle'] = "<span class='edit activate'><a href='" . wp_nonce_url("?page=" . $page. "&action=togglemakepublic&sub_id=" . $sub->id . "", 'togglemakepublic-sub_' . $sub->id) . "'>" . __('Activate and Make Public', 'membership') . "</a></span>"; 
  4572. } else { 
  4573. if($sub->sub_active == 0) { 
  4574. $actions['toggle'] = "<span class='edit activate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&sub_id=" . $sub->id . "", 'toggle-sub_' . $sub->id) . "'>" . __('Activate', 'membership') . "</a></span>"; 
  4575. } else { 
  4576. $actions['toggle'] = "<span class='edit deactivate'><a href='" . wp_nonce_url("?page=" . $page. "&action=toggle&sub_id=" . $sub->id . "", 'toggle-sub_' . $sub->id) . "'>" . __('Deactivate', 'membership') . "</a></span>"; 
  4577.  
  4578. if($sub->sub_public == 0) { 
  4579. $actions['public'] = "<span class='edit makeprivate'><a href='" . wp_nonce_url("?page=" . $page. "&action=togglepublic&sub_id=" . $sub->id . "", 'toggle-pubsub_' . $sub->id) . "'>" . __('Make public', 'membership') . "</a></span>"; 
  4580. } else { 
  4581. $actions['public'] = "<span class='edit makepublic'><a href='" . wp_nonce_url("?page=" . $page. "&action=togglepublic&sub_id=" . $sub->id . "", 'toggle-pubsub_' . $sub->id) . "'>" . __('Make private', 'membership') . "</a></span>"; 
  4582.  
  4583. $actions['delete'] = "<span class='delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=delete&sub_id=" . $sub->id . "", 'delete-sub_' . $sub->id) . "'>" . __('Delete', 'membership') . "</a></span>"; 
  4584.  
  4585. ?> 
  4586. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  4587. </td> 
  4588. <td class="column-active"> 
  4589. <?php 
  4590. switch($sub->sub_active) { 
  4591. case 0: echo "<span class='membershipinactivestatus'>" . __('Inactive', 'membership') . "</span>"; 
  4592. break; 
  4593. case 1: echo "<span class='membershipactivestatus'>" . __('Active', 'membership') . "</span>"; 
  4594. break; 
  4595. ?> 
  4596. </td> 
  4597. <td class="column-public"> 
  4598. <?php 
  4599. switch($sub->sub_public) { 
  4600. case 0: echo __('Private', 'membership'); 
  4601. break; 
  4602. case 1: echo "<strong>" . __('Public', 'membership') . "</strong>"; 
  4603. break; 
  4604. ?> 
  4605. </td> 
  4606. <td class="column-users"> 
  4607. <strong> 
  4608. <?php echo $this->count_on_sub( $sub->id ); ?> 
  4609. </strong> 
  4610. </td> 
  4611. </tr> 
  4612. <?php 
  4613. } else { 
  4614. $columncount = count($columns) + 1; 
  4615. ?> 
  4616. <tr valign="middle" class="alternate" > 
  4617. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No Subscriptions where found, click above to add one.', 'membership'); ?></td> 
  4618. </tr> 
  4619. <?php 
  4620. ?> 
  4621.  
  4622. </tbody> 
  4623. </table> 
  4624.  
  4625.  
  4626. <div class="tablenav"> 
  4627.  
  4628. <div class="alignleft actions"> 
  4629. <select name="action2"> 
  4630. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  4631. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  4632. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  4633. </select> 
  4634. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="<?php _e('Apply', 'membership'); ?>"> 
  4635. </div> 
  4636. <div class="alignright actions"> 
  4637. </div> 
  4638. <br class="clear"> 
  4639. </div> 
  4640.  
  4641.  
  4642.  
  4643. </form> 
  4644.  
  4645. </div> <!-- wrap --> 
  4646. <?php 
  4647.  
  4648.  
  4649. function handle_urlgroups_updates() { 
  4650.  
  4651. global $action, $page; 
  4652.  
  4653. wp_reset_vars( array('action', 'page') ); 
  4654.  
  4655. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  4656. if(addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') { 
  4657. $action = 'bulk-delete'; 
  4658.  
  4659. switch(addslashes($action)) { 
  4660.  
  4661. case 'removeheader': $this->dismiss_user_help( $page ); 
  4662. wp_safe_redirect( remove_query_arg( 'action' ) ); 
  4663. break; 
  4664.  
  4665. case 'added': check_admin_referer('add-group'); 
  4666.  
  4667. $group = new M_Urlgroup( 0 ); 
  4668.  
  4669. if($group->add()) { 
  4670. wp_safe_redirect( add_query_arg( 'msg', 3, 'admin.php?page=' . $page ) ); 
  4671. } else { 
  4672. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  4673.  
  4674. break; 
  4675. case 'updated': $id = (int) $_POST['ID']; 
  4676. check_admin_referer('update-group-' . $id); 
  4677. if($id) { 
  4678. $group = new M_Urlgroup( $id ); 
  4679.  
  4680. if($group->update()) { 
  4681. wp_safe_redirect( add_query_arg( 'msg', 1, 'admin.php?page=' . $page ) ); 
  4682. } else { 
  4683. wp_safe_redirect( add_query_arg( 'msg', 2, 'admin.php?page=' . $page ) ); 
  4684. } else { 
  4685. wp_safe_redirect( add_query_arg( 'msg', 2, 'admin.php?page=' . $page ) ); 
  4686. break; 
  4687.  
  4688. case 'delete': if(isset($_GET['group'])) { 
  4689. $id = (int) $_GET['group']; 
  4690.  
  4691. check_admin_referer('delete-group_' . $id); 
  4692.  
  4693. $group = new M_Urlgroup( $id ); 
  4694.  
  4695. if($group->delete()) { 
  4696. wp_safe_redirect( add_query_arg( 'msg', 5, wp_get_referer() ) ); 
  4697. } else { 
  4698. wp_safe_redirect( add_query_arg( 'msg', 6, wp_get_referer() ) ); 
  4699.  
  4700. break; 
  4701.  
  4702. case 'bulk-delete': 
  4703. check_admin_referer('bulk-groups'); 
  4704. foreach($_GET['groupcheck'] AS $value) { 
  4705. if(is_numeric($value)) { 
  4706. $id = (int) $value; 
  4707.  
  4708. $group = new M_Urlgroup( $id ); 
  4709.  
  4710. $group->delete(); 
  4711.  
  4712. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  4713. break; 
  4714.  
  4715.  
  4716. function get_urlgroups() { 
  4717.  
  4718. $sql = $this->db->prepare( "SELECT * FROM {$this->urlgroups} WHERE groupname NOT LIKE (%s) ORDER BY id ASC", '\_%' ); 
  4719.  
  4720. $results = $this->db->get_results( $sql ); 
  4721.  
  4722. if(!empty($results)) { 
  4723. return $results; 
  4724. } else { 
  4725. return false; 
  4726.  
  4727.  
  4728. function show_urlgroup_edit( $group_id ) { 
  4729.  
  4730. global $page; 
  4731.  
  4732. if( $group_id === false ) { 
  4733. $add = new M_Urlgroup( 0 ); 
  4734.  
  4735. echo "<div class='wrap'>"; 
  4736. echo "<h2>" . __('Add URL group', 'membership') . "</h2>"; 
  4737.  
  4738. echo '<div id="poststuff" class="metabox-holder">'; 
  4739. ?> 
  4740. <div class="postbox"> 
  4741. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Add URL group', 'membership'); ?></span></h3> 
  4742. <div class="inside"> 
  4743. <?php 
  4744. echo '<form method="post" action="?page=' . $page . '">'; 
  4745. echo '<input type="hidden" name="ID" value="" />'; 
  4746. echo "<input type='hidden' name='action' value='added' />"; 
  4747. wp_nonce_field('add-group'); 
  4748. $add->addform(); 
  4749. echo '<p class="submit">'; 
  4750. echo '<input class="button-primary alignright" type="submit" name="go" value="' . __('Add group', 'membership') . '" /></p>'; 
  4751. echo '</form>'; 
  4752. echo '<br/>'; 
  4753. ?> 
  4754. </div> 
  4755. </div> 
  4756. <?php 
  4757. echo "</div>"; 
  4758. echo "</div>"; 
  4759. } else { 
  4760. $edit = new M_Urlgroup( (int) $group_id ); 
  4761.  
  4762. echo "<div class='wrap'>"; 
  4763. echo "<h2>" . __('Edit URL group', 'membership') . "</h2>"; 
  4764.  
  4765. echo '<div id="poststuff" class="metabox-holder">'; 
  4766. ?> 
  4767. <div class="postbox"> 
  4768. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Edit URL group', 'membership'); ?></span></h3> 
  4769. <div class="inside"> 
  4770. <?php 
  4771. echo '<form method="post" action="?page=' . $page . '">'; 
  4772. echo '<input type="hidden" name="ID" value="' . $group_id . '" />'; 
  4773. echo "<input type='hidden' name='action' value='updated' />"; 
  4774. wp_nonce_field('update-group-' . $group_id); 
  4775. $edit->editform(); 
  4776. echo '<p class="submit">'; 
  4777. echo '<input class="button-primary alignright" type="submit" name="go" value="' . __('Update group', 'membership') . '" /></p>'; 
  4778. echo '</form>'; 
  4779. echo '<br/>'; 
  4780. ?> 
  4781. </div> 
  4782. </div> 
  4783. <?php 
  4784. echo "</div>"; 
  4785. echo "</div>"; 
  4786.  
  4787.  
  4788. function handle_urlgroups_panel() { 
  4789. global $action, $page; 
  4790.  
  4791. wp_reset_vars( array('action', 'page') ); 
  4792.  
  4793. switch(addslashes($action)) { 
  4794.  
  4795. case 'edit': if(!empty($_GET['group'])) { 
  4796. // Make a communication 
  4797. $this->show_urlgroup_edit( $_GET['group'] ); 
  4798. } else { 
  4799. $this->show_urlgroup_edit( false ); 
  4800. return; // so we don't show the list below 
  4801. break; 
  4802.  
  4803.  
  4804.  
  4805. $messages = array(); 
  4806. $messages[1] = __('Group updated.', 'membership'); 
  4807. $messages[2] = __('Group not updated.', 'membership'); 
  4808.  
  4809. $messages[3] = __('Group added.', 'membership'); 
  4810. $messages[4] = __('Group not added.', 'membership'); 
  4811.  
  4812. $messages[5] = __('Group deleted.', 'membership'); 
  4813. $messages[6] = __('Group not deleted.', 'membership'); 
  4814.  
  4815. $messages[7] = __('Groups deleted.', 'membership'); 
  4816.  
  4817.  
  4818. ?> 
  4819. <div class='wrap'> 
  4820. <div class="icon32" id="icon-edit-pages"><br></div> 
  4821. <h2><?php _e('Edit URL Groups', 'membership'); ?><a class="add-new-h2" href="admin.php?page=<?php echo $page; ?>&action=edit&group="><?php _e('Add New', 'membership'); ?></a></h2> 
  4822.  
  4823. <?php 
  4824. if ( isset($_GET['msg']) ) { 
  4825. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  4826. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  4827.  
  4828. $groups = $this->get_urlgroups(); 
  4829. $groups = apply_filters('M_urlgroups_list', $groups); 
  4830.  
  4831. if($this->show_user_help( $page )) { 
  4832. ?> 
  4833. <div class='screenhelpheader'> 
  4834. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  4835. <?php 
  4836. ob_start(); 
  4837. include_once(membership_dir('membershipincludes/help/header.urlgroups.php')); 
  4838. echo ob_get_clean(); 
  4839. ?> 
  4840. </div> 
  4841. <?php 
  4842.  
  4843. ?> 
  4844.  
  4845. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="posts-filter"> 
  4846.  
  4847. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  4848.  
  4849. <div class="tablenav"> 
  4850.  
  4851. <div class="alignleft actions"> 
  4852. <select name="action"> 
  4853. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  4854. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  4855. </select> 
  4856. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply', 'membership'); ?>"> 
  4857.  
  4858. </div> 
  4859.  
  4860. <div class="alignright actions"> 
  4861. </div> 
  4862.  
  4863. <br class="clear"> 
  4864. </div> 
  4865.  
  4866. <div class="clear"></div> 
  4867.  
  4868. <?php 
  4869. wp_original_referer_field(true, 'previous'); wp_nonce_field('bulk-groups'); 
  4870.  
  4871. $columns = array( "name" => __('Group Name', 'membership') 
  4872. ); 
  4873.  
  4874. $columns = apply_filters('membership_groupscolumns', $columns); 
  4875.  
  4876. ?> 
  4877.  
  4878. <table cellspacing="0" class="widefat fixed"> 
  4879. <thead> 
  4880. <tr> 
  4881. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  4882. <?php 
  4883. foreach($columns as $key => $col) { 
  4884. ?> 
  4885. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  4886. <?php 
  4887. ?> 
  4888. </tr> 
  4889. </thead> 
  4890.  
  4891. <tfoot> 
  4892. <tr> 
  4893. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  4894. <?php 
  4895. reset($columns); 
  4896. foreach($columns as $key => $col) { 
  4897. ?> 
  4898. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  4899. <?php 
  4900. ?> 
  4901. </tr> 
  4902. </tfoot> 
  4903.  
  4904. <tbody> 
  4905. <?php 
  4906. if(!empty($groups)) { 
  4907. foreach($groups as $key => $group) { 
  4908. ?> 
  4909. <tr valign="middle" class="alternate" id="group-<?php echo $group->id; ?>"> 
  4910. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo esc_attr($group->id); ?>" name="groupcheck[]"></th> 
  4911. <td class="column-name"> 
  4912. <strong><a title="<?php _e('Edit', 'membership'); ?> <?php echo esc_attr(stripslashes($group->groupname)); ?>" href="?page=<?php echo $page; ?>&action=edit&group=<?php echo $group->id; ?>" class="row-title"><?php echo esc_html(stripslashes($group->groupname)); ?></a></strong> 
  4913. <?php 
  4914. $actions = array(); 
  4915. $actions['edit'] = "<span class='edit'><a href='?page=" . $page . "&action=edit&group=" . $group->id . "'>" . __('Edit', 'membership') . "</a></span>"; 
  4916. $actions['delete'] = "<span class='delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=delete&group=" . $group->id . "", 'delete-group_' . $group->id) . "'>" . __('Delete', 'membership') . "</a></span>"; 
  4917. ?> 
  4918. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  4919. </td> 
  4920. </tr> 
  4921. <?php 
  4922. } else { 
  4923. $columncount = count($columns) + 1; 
  4924. ?> 
  4925. <tr valign="middle" class="alternate" > 
  4926. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No URL groups have been set up.', 'membership'); ?></td> 
  4927. </tr> 
  4928. <?php 
  4929. ?> 
  4930.  
  4931. </tbody> 
  4932. </table> 
  4933.  
  4934. <div class="tablenav"> 
  4935.  
  4936. <div class="alignleft actions"> 
  4937. <select name="action2"> 
  4938. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  4939. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  4940. </select> 
  4941. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="<?php _e('Apply', 'membership'); ?>"> 
  4942. </div> 
  4943. <div class="alignright actions"> 
  4944. </div> 
  4945. <br class="clear"> 
  4946. </div> 
  4947.  
  4948. </form> 
  4949.  
  4950. </div> <!-- wrap --> 
  4951. <?php 
  4952.  
  4953. function handle_ping_updates() { 
  4954.  
  4955. global $action, $page; 
  4956.  
  4957. wp_reset_vars( array('action', 'page') ); 
  4958.  
  4959. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  4960. if(addslashes($_GET['action']) == 'delete' || addslashes($_GET['action2']) == 'delete') { 
  4961. $action = 'bulk-delete'; 
  4962.  
  4963. switch(addslashes($action)) { 
  4964.  
  4965. case 'removeheader': $this->dismiss_user_help( $page ); 
  4966. wp_safe_redirect( remove_query_arg( 'action' ) ); 
  4967. break; 
  4968.  
  4969. case 'added': check_admin_referer('add-ping'); 
  4970.  
  4971. $ping = new M_Ping( 0 ); 
  4972.  
  4973. if($ping->add()) { 
  4974. wp_safe_redirect( add_query_arg( 'msg', 3, 'admin.php?page=' . $page ) ); 
  4975. } else { 
  4976. wp_safe_redirect( add_query_arg( 'msg', 4, 'admin.php?page=' . $page ) ); 
  4977.  
  4978. break; 
  4979. case 'updated': $id = (int) $_POST['ID']; 
  4980. check_admin_referer('update-ping-' . $id); 
  4981. if($id) { 
  4982. $ping = new M_Ping( $id ); 
  4983.  
  4984. if($ping->update()) { 
  4985. wp_safe_redirect( add_query_arg( 'msg', 1, 'admin.php?page=' . $page ) ); 
  4986. } else { 
  4987. wp_safe_redirect( add_query_arg( 'msg', 2, 'admin.php?page=' . $page ) ); 
  4988. } else { 
  4989. wp_safe_redirect( add_query_arg( 'msg', 2, 'admin.php?page=' . $page ) ); 
  4990. break; 
  4991.  
  4992. case 'delete': if(isset($_GET['ping'])) { 
  4993. $id = (int) $_GET['ping']; 
  4994.  
  4995. check_admin_referer('delete-ping_' . $id); 
  4996.  
  4997. $ping = new M_Ping( $id ); 
  4998.  
  4999. if($ping->delete()) { 
  5000. wp_safe_redirect( add_query_arg( 'msg', 5, wp_get_referer() ) ); 
  5001. } else { 
  5002. wp_safe_redirect( add_query_arg( 'msg', 6, wp_get_referer() ) ); 
  5003.  
  5004. break; 
  5005.  
  5006. case 'bulk-delete': 
  5007. check_admin_referer('bulk-pings'); 
  5008. foreach($_GET['pingcheck'] AS $value) { 
  5009. if(is_numeric($value)) { 
  5010. $id = (int) $value; 
  5011.  
  5012. $ping = new M_Ping( $id ); 
  5013.  
  5014. $ping->delete(); 
  5015.  
  5016. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  5017. break; 
  5018.  
  5019. case 'history': 
  5020. if(isset($_GET['history']) && isset($_GET['resend'])) { 
  5021. $history = (int) $_GET['history']; 
  5022. switch($_GET['resend']) { 
  5023. case 'new': $ping = new M_Ping( false ); 
  5024. $ping->resend_historic_ping( $history, true ); 
  5025. wp_safe_redirect( add_query_arg( 'msg', 1, wp_get_referer() ) ); 
  5026. break; 
  5027. case 'over': $ping = new M_Ping( false ); 
  5028. $ping->resend_historic_ping( $history, false ); 
  5029. wp_safe_redirect( add_query_arg( 'msg', 1, wp_get_referer() ) ); 
  5030. break; 
  5031. break; 
  5032.  
  5033.  
  5034.  
  5035.  
  5036. function show_ping_edit( $ping_id ) { 
  5037.  
  5038. global $page; 
  5039.  
  5040. if( $ping_id === false ) { 
  5041. $add = new M_Ping( 0 ); 
  5042.  
  5043. echo "<div class='wrap'>"; 
  5044. echo "<h2>" . __('Add Ping details', 'membership') . "</h2>"; 
  5045.  
  5046. echo '<div id="poststuff" class="metabox-holder">'; 
  5047. ?> 
  5048. <div class="postbox"> 
  5049. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Add ping details', 'membership'); ?></span></h3> 
  5050. <div class="inside"> 
  5051. <?php 
  5052. echo '<form method="post" action="?page=' . $page . '">'; 
  5053. echo '<input type="hidden" name="ID" value="" />'; 
  5054. echo "<input type='hidden' name='action' value='added' />"; 
  5055. wp_nonce_field('add-ping'); 
  5056. $add->addform(); 
  5057. echo '<p class="submit">'; 
  5058. echo '<input class="button-primary alignright" type="submit" name="go" value="' . __('Add ping details', 'membership') . '" /></p>'; 
  5059. echo '</form>'; 
  5060. echo '<br/>'; 
  5061. ?> 
  5062. </div> 
  5063. </div> 
  5064. <?php 
  5065. echo "</div>"; 
  5066. echo "</div>"; 
  5067. } else { 
  5068. $edit = new M_Ping( (int) $ping_id ); 
  5069.  
  5070. echo "<div class='wrap'>"; 
  5071. echo "<h2>" . __('Edit Ping details', 'membership') . "</h2>"; 
  5072.  
  5073. echo '<div id="poststuff" class="metabox-holder">'; 
  5074. ?> 
  5075. <div class="postbox"> 
  5076. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Edit ping details', 'membership'); ?></span></h3> 
  5077. <div class="inside"> 
  5078. <?php 
  5079. echo '<form method="post" action="?page=' . $page . '">'; 
  5080. echo '<input type="hidden" name="ID" value="' . $ping_id . '" />'; 
  5081. echo "<input type='hidden' name='action' value='updated' />"; 
  5082. wp_nonce_field('update-ping-' . $ping_id); 
  5083. $edit->editform(); 
  5084. echo '<p class="submit">'; 
  5085. echo '<input class="button-primary alignright" type="submit" name="go" value="' . __('Update ping details', 'membership') . '" /></p>'; 
  5086. echo '</form>'; 
  5087. echo '<br/>'; 
  5088. ?> 
  5089. </div> 
  5090. </div> 
  5091. <?php 
  5092. echo "</div>"; 
  5093. echo "</div>"; 
  5094.  
  5095.  
  5096. function get_pings() { 
  5097. $sql = "SELECT * FROM {$this->pings} ORDER BY id ASC"; 
  5098.  
  5099. $results = $this->db->get_results( $sql ); 
  5100.  
  5101. if(!empty($results)) { 
  5102. return $results; 
  5103. } else { 
  5104. return false; 
  5105.  
  5106. function handle_ping_history_panel( $ping_id ) { 
  5107. global $action, $page; 
  5108.  
  5109. wp_reset_vars( array('action', 'page') ); 
  5110.  
  5111. $messages = array(); 
  5112. $messages[1] = __('Ping resent.', 'membership'); 
  5113. $messages[2] = __('Ping not resent.', 'membership'); 
  5114.  
  5115. ?> 
  5116. <div class='wrap'> 
  5117. <div class="icon32" id="icon-link-manager"><br></div> 
  5118. <h2><?php _e('Pings History', 'membership'); ?></h2> 
  5119.  
  5120. <?php 
  5121. if ( isset($_GET['msg']) ) { 
  5122. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  5123. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  5124.  
  5125. $ping = new M_Ping( $ping_id ); 
  5126.  
  5127. $history = $ping->get_history(); 
  5128.  
  5129. $columns = array( "name" => __('Ping Name', 'membership'),  
  5130. "url" => __('URL', 'membership'),  
  5131. "status" => __('Status', 'membership'),  
  5132. "date" => __('Date', 'membership') 
  5133. ); 
  5134.  
  5135. $columns = apply_filters('membership_pingscolumns', $columns); 
  5136.  
  5137. ?> 
  5138. <table cellspacing="0" class="widefat fixed"> 
  5139. <thead> 
  5140. <tr> 
  5141. <?php 
  5142. foreach($columns as $key => $col) { 
  5143. ?> 
  5144. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  5145. <?php 
  5146. ?> 
  5147. </tr> 
  5148. </thead> 
  5149.  
  5150. <tfoot> 
  5151. <tr> 
  5152. <?php 
  5153. reset($columns); 
  5154. foreach($columns as $key => $col) { 
  5155. ?> 
  5156. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  5157. <?php 
  5158. ?> 
  5159. </tr> 
  5160. </tfoot> 
  5161.  
  5162. <tbody> 
  5163. <?php 
  5164. if(!empty($history)) { 
  5165. foreach($history as $key => $h) { 
  5166. ?> 
  5167. <tr valign="middle" class="alternate" id="history-<?php echo $h->id; ?>"> 
  5168. <td class="column-name"> 
  5169. <strong><?php echo esc_html(stripslashes($ping->ping_name() )); ?></strong> 
  5170. <?php 
  5171. $actions = array(); 
  5172. $actions['resendnew'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page . "&action=history&resend=new&history=" . $h->id, 'membership_resend_ping_' . $h->id ) . "'>" . __('Resend as new ping', 'membership') . "</a></span>"; 
  5173. $actions['resendover'] = "<span class='edit'><a href='" . wp_nonce_url("?page=" . $page . "&action=history&resend=over&history=" . $h->id, 'membership_resend_ping_' . $h->id ) . "'>" . __('Resend and overwrite', 'membership') . "</a></span>"; 
  5174. ?> 
  5175. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  5176. </td> 
  5177. <td class="column-name"> 
  5178. <?php 
  5179. echo $ping->ping_url(); 
  5180. ?> 
  5181. </td> 
  5182. <td class="column-name"> 
  5183. <?php 
  5184. // Status 
  5185. $status = unserialize($h->ping_return); 
  5186. if(is_wp_error($status)) { 
  5187. // WP error 
  5188. echo "<span style='color: red;'>" . implode("<br/>", $status->get_error_messages() ) . "</span>"; 
  5189. } else { 
  5190. if(!empty($status['response'])) { 
  5191. if($status['response']['code'] == '200') { 
  5192. echo "<span style='color: green;'>" . $status['response']['code'] . " - " . $status['response']['message'] . "</span>"; 
  5193. } else { 
  5194. echo "<span style='color: red;'>" . $status['response']['code'] . " - " . $status['response']['message'] . "</span>"; 
  5195. //echo $ping->ping_url(); 
  5196. ?> 
  5197. </td> 
  5198. <td class="column-name"> 
  5199. <?php 
  5200. echo mysql2date( "Y-m-j H:i:s", $h->ping_sent ); 
  5201. ?> 
  5202. </td> 
  5203. </tr> 
  5204. <?php 
  5205. } else { 
  5206. $columncount = count($columns); 
  5207. ?> 
  5208. <tr valign="middle" class="alternate" > 
  5209. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No History available for this ping.', 'membership'); ?></td> 
  5210. </tr> 
  5211. <?php 
  5212. ?> 
  5213.  
  5214. </tbody> 
  5215. </table> 
  5216.  
  5217. </div> <!-- wrap --> 
  5218. <?php 
  5219.  
  5220. function handle_pings_panel() { 
  5221. global $action, $page; 
  5222.  
  5223. wp_reset_vars( array('action', 'page') ); 
  5224.  
  5225. switch(addslashes($action)) { 
  5226.  
  5227. case 'edit': if(!empty($_GET['ping'])) { 
  5228. // Make a communication 
  5229. $this->show_ping_edit( (int) $_GET['ping'] ); 
  5230. } else { 
  5231. $this->show_ping_edit( false ); 
  5232. return; // so we don't show the list below 
  5233. break; 
  5234.  
  5235. case 'history': 
  5236. if(!empty($_GET['ping'])) { 
  5237. $this->handle_ping_history_panel( (int) $_GET['ping'] ); 
  5238. return; 
  5239. break; 
  5240.  
  5241.  
  5242.  
  5243. $messages = array(); 
  5244. $messages[1] = __('Ping details updated.', 'membership'); 
  5245. $messages[2] = __('Ping details not updated.', 'membership'); 
  5246.  
  5247. $messages[3] = __('Ping details added.', 'membership'); 
  5248. $messages[4] = __('Ping details not added.', 'membership'); 
  5249.  
  5250. $messages[5] = __('Ping details deleted.', 'membership'); 
  5251. $messages[6] = __('Ping details not deleted.', 'membership'); 
  5252.  
  5253. $messages[7] = __('Ping details deleted.', 'membership'); 
  5254.  
  5255. ?> 
  5256. <div class='wrap'> 
  5257. <div class="icon32" id="icon-link-manager"><br></div> 
  5258. <h2><?php _e('Edit Pings', 'membership'); ?><a class="add-new-h2" href="admin.php?page=<?php echo $page; ?>&action=edit&ping="><?php _e('Add New', 'membership'); ?></a></h2> 
  5259.  
  5260. <?php 
  5261. if ( isset($_GET['msg']) ) { 
  5262. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  5263. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  5264.  
  5265. $pings = $this->get_pings(); 
  5266. $pings = apply_filters('M_pings_list', $pings); 
  5267.  
  5268. if($this->show_user_help( $page )) { 
  5269. ?> 
  5270. <div class='screenhelpheader'> 
  5271. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  5272. <?php 
  5273. ob_start(); 
  5274. include_once(membership_dir('membershipincludes/help/header.pings.php')); 
  5275. echo ob_get_clean(); 
  5276. ?> 
  5277. </div> 
  5278. <?php 
  5279.  
  5280. ?> 
  5281.  
  5282. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="posts-filter"> 
  5283.  
  5284. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  5285.  
  5286. <div class="tablenav"> 
  5287.  
  5288. <div class="alignleft actions"> 
  5289. <select name="action"> 
  5290. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  5291. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  5292. </select> 
  5293. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply', 'membership'); ?>"> 
  5294.  
  5295. </div> 
  5296.  
  5297. <div class="alignright actions"> 
  5298. </div> 
  5299.  
  5300. <br class="clear"> 
  5301. </div> 
  5302.  
  5303. <div class="clear"></div> 
  5304.  
  5305. <?php 
  5306. wp_original_referer_field(true, 'previous'); wp_nonce_field('bulk-pings'); 
  5307.  
  5308. $columns = array( "name" => __('Ping Name', 'membership') 
  5309. ); 
  5310.  
  5311. $columns = apply_filters('membership_pingscolumns', $columns); 
  5312.  
  5313. ?> 
  5314.  
  5315. <table cellspacing="0" class="widefat fixed"> 
  5316. <thead> 
  5317. <tr> 
  5318. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  5319. <?php 
  5320. foreach($columns as $key => $col) { 
  5321. ?> 
  5322. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  5323. <?php 
  5324. ?> 
  5325. </tr> 
  5326. </thead> 
  5327.  
  5328. <tfoot> 
  5329. <tr> 
  5330. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  5331. <?php 
  5332. reset($columns); 
  5333. foreach($columns as $key => $col) { 
  5334. ?> 
  5335. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  5336. <?php 
  5337. ?> 
  5338. </tr> 
  5339. </tfoot> 
  5340.  
  5341. <tbody> 
  5342. <?php 
  5343. if(!empty($pings)) { 
  5344. foreach($pings as $key => $ping) { 
  5345. ?> 
  5346. <tr valign="middle" class="alternate" id="ping-<?php echo $ping->id; ?>"> 
  5347. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo esc_attr($ping->id); ?>" name="pingcheck[]"></th> 
  5348. <td class="column-name"> 
  5349. <strong><a title="<?php _e('Edit', 'membership'); ?> <?php echo esc_attr(stripslashes($ping->pingname)); ?>" href="?page=<?php echo $page; ?>&action=edit&ping=<?php echo $ping->id; ?>" class="row-title"><?php echo esc_html(stripslashes($ping->pingname)); ?></a></strong> 
  5350. <?php 
  5351. $actions = array(); 
  5352. $actions['edit'] = "<span class='edit'><a href='?page=" . $page . "&action=edit&ping=" . $ping->id . "'>" . __('Edit', 'membership') . "</a></span>"; 
  5353. $actions['trans'] = "<span class='edit'><a href='?page=" . $page . "&action=history&ping=" . $ping->id . "'>" . __('History', 'membership') . "</a></span>"; 
  5354. $actions['delete'] = "<span class='delete'><a href='" . wp_nonce_url("?page=" . $page. "&action=delete&ping=" . $ping->id . "", 'delete-ping_' . $ping->id) . "'>" . __('Delete', 'membership') . "</a></span>"; 
  5355. ?> 
  5356. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  5357. </td> 
  5358. </tr> 
  5359. <?php 
  5360. } else { 
  5361. $columncount = count($columns) + 1; 
  5362. ?> 
  5363. <tr valign="middle" class="alternate" > 
  5364. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No Pings have been set up.', 'membership'); ?></td> 
  5365. </tr> 
  5366. <?php 
  5367. ?> 
  5368.  
  5369. </tbody> 
  5370. </table> 
  5371.  
  5372. <div class="tablenav"> 
  5373.  
  5374. <div class="alignleft actions"> 
  5375. <select name="action2"> 
  5376. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  5377. <option value="delete"><?php _e('Delete', 'membership'); ?></option> 
  5378. </select> 
  5379. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="<?php _e('Apply', 'membership'); ?>"> 
  5380. </div> 
  5381. <div class="alignright actions"> 
  5382. </div> 
  5383. <br class="clear"> 
  5384. </div> 
  5385.  
  5386. </form> 
  5387.  
  5388. </div> <!-- wrap --> 
  5389. <?php 
  5390.  
  5391.  
  5392. function handle_profile_member_page() { 
  5393. ?> 
  5394. <div class='wrap'> 
  5395. <div class="icon32" id="icon-users"><br></div> 
  5396. <h2><?php _e('Membership details', 'membership'); ?></h2> 
  5397.  
  5398. <?php 
  5399. if ( isset($_GET['msg']) ) { 
  5400. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  5401. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  5402.  
  5403. if(!current_user_is_member()) { 
  5404. // Not a member so show the message and signup forms 
  5405. ?> 
  5406. <div class='nonmembermessage'> 
  5407. <h3><?php _e('Not called yet', 'membership'); ?></h3> 
  5408. <?php _e('Not called yet', 'membership'); ?> 
  5409. </div> 
  5410. <div class='signups'> 
  5411. <h3><?php _e('Select a subscription', 'membership'); ?></h3> 
  5412. <p> 
  5413. <?php _e('Please select a subscription from the options below.', 'membership'); ?> 
  5414. </p> 
  5415. <?php 
  5416. do_action( 'membership_subscription_form_before_subscriptions', $user_id ); 
  5417.  
  5418. $subs = $this->get_subscriptions(); 
  5419.  
  5420. do_action( 'membership_subscription_form_before_paid_subscriptions', $user_id ); 
  5421.  
  5422. foreach((array) $subs as $key => $sub) { 
  5423.  
  5424. $subscription = new M_Subscription($sub->id); 
  5425.  
  5426. ?> 
  5427. <div class="subscription"> 
  5428. <div class="description"> 
  5429. <h3><?php echo $subscription->sub_name(); ?></h3> 
  5430. <p><?php echo $subscription->sub_description(); ?></p> 
  5431. </div> 
  5432.  
  5433. <?php 
  5434. $pricing = $subscription->get_pricingarray(); 
  5435.  
  5436. if($pricing) { 
  5437. ?> 
  5438. <div class='priceforms'> 
  5439. <?php do_action('membership_purchase_button', $subscription, $pricing, $user_id); ?> 
  5440. </div> 
  5441. <?php 
  5442. ?> 
  5443. </div> 
  5444. <?php 
  5445.  
  5446. do_action( 'membership_subscription_form_after_paid_subscriptions', $user_id ); 
  5447. do_action( 'membership_subscription_form_after_subscriptions', $user_id ); 
  5448. ?> 
  5449. </div> 
  5450. <?php 
  5451. } else { 
  5452. if(current_user_has_subscription()) { 
  5453. // User has a subscription already. Display the details - and an action to enable upgrading / not upgrading to take place. 
  5454. ?> 
  5455. <div class='nonmembermessage'> 
  5456. <h3><?php _e('Not called yet', 'membership'); ?></h3> 
  5457. <?php _e('Not called yet', 'membership'); ?> 
  5458. </div> 
  5459. <?php 
  5460.  
  5461. ?> 
  5462. </div> <!-- wrap --> 
  5463. <?php 
  5464.  
  5465. // Media extension options 
  5466. /** 
  5467. add_filter('attachment_fields_to_edit', array(&$this, 'add_media_protection_settings'), 99, 2); 
  5468. add_filter('attachment_fields_to_save', array(&$this, 'save_media_protection_settings'), 99, 2); 
  5469. */ 
  5470. function add_media_protection_settings($fields, $post) { 
  5471.  
  5472. global $M_options; 
  5473.  
  5474. $protected = get_post_meta($post->ID, '_membership_protected_content_group', true); 
  5475. if(empty($protected)) { 
  5476. $protected = 'no'; 
  5477.  
  5478. $html = "<select name='attachments[" . $post->ID . "][protected-content]'>"; 
  5479.  
  5480. $html .= "<option value='no'"; 
  5481. $html .= ">" . __('None', 'membership') . "</option>"; 
  5482.  
  5483. if(!empty($M_options['membershipdownloadgroups'])) { 
  5484. foreach($M_options['membershipdownloadgroups'] as $key => $value) { 
  5485. if(!empty($value)) { 
  5486. $html .= "<option value='" . esc_attr(trim(stripslashes($value))) . "'"; 
  5487. if($protected == esc_attr(trim(stripslashes($value)))) { 
  5488. $html .= " selected='selected'"; 
  5489. $html .= ">" . esc_html(trim(stripslashes($value))) . "</option>"; 
  5490. $html .= "</select>"; 
  5491.  
  5492. $fields['media-protected-content'] = array( 
  5493. 'label' => __('Protected content group', 'membership'),  
  5494. 'input' => 'html',  
  5495. 'html' => $html,  
  5496. 'helps' => __('Is this an item you may want to restrict access to?', 'membership') 
  5497. ); 
  5498. return $fields; 
  5499.  
  5500. function save_media_protection_settings($post, $attachment) { 
  5501. $key = "protected-content"; 
  5502. if ( empty( $attachment[$key] ) || addslashes( $attachment[$key] ) == 'no') { 
  5503. delete_post_meta($post['ID'], '_membership_protected_content_group'); // delete any residual metadata from a free-form field (as inserted below) 
  5504. } else // free-form text was entered, insert postmeta with credit 
  5505. update_post_meta($post['ID'], '_membership_protected_content_group', $attachment['protected-content']); // insert 'media-credit' metadata field for image with free-form text 
  5506. return $post; 
  5507.  
  5508. // Fake shortcode function for administration area - public class has the proper processing function 
  5509. function do_fake_shortcode($atts, $content = null, $code = "") { 
  5510.  
  5511. global $M_options; 
  5512.  
  5513. return $M_options['shortcodemessage']; 
  5514.  
  5515. // Database actions 
  5516.  
  5517. function update_levelcounts() { 
  5518.  
  5519. $sql = $this->db->prepare( "SELECT level_id, count(*) AS number FROM {$this->membership_relationships} WHERE level_id != %d GROUP BY level_id", 0 ); 
  5520.  
  5521. $this->db->query( $this->db->prepare( "UPDATE {$this->membership_levels} SET level_count = %d", 0) ); 
  5522.  
  5523. $levels = $this->db->get_results($sql); 
  5524. if($levels) { 
  5525. foreach($levels as $key => $level) { 
  5526. $this->db->update( $this->membership_levels, array('level_count' => $level->number), array('id' => $level->level_id) ); 
  5527.  
  5528.  
  5529. function update_subcounts() { 
  5530.  
  5531. $sql = $this->db->prepare( "SELECT sub_id, count(*) AS number FROM {$this->membership_relationships} WHERE sub_id != %d GROUP BY sub_id", 0 ); 
  5532.  
  5533. $this->db->query( $this->db->prepare( "UPDATE {$this->subscriptions} SET sub_count = %d", 0) ); 
  5534.  
  5535. $subs = $this->db->get_results($sql); 
  5536. if($subs) { 
  5537. foreach($subs as $key => $sub) { 
  5538. $this->db->update( $this->subscriptions, array('sub_count' => $sub->number), array('id' => $sub->sub_id) ); 
  5539.  
  5540. function get_membership_levels($filter = false) { 
  5541.  
  5542. if($filter) { 
  5543. $where = array(); 
  5544. $orderby = array(); 
  5545.  
  5546. if(isset($filter['s'])) { 
  5547. $where[] = "level_title LIKE '%" . mysql_real_escape_string($filter['s']) . "%'"; 
  5548.  
  5549. if(isset($filter['level_id'])) { 
  5550. switch($filter['level_id']) { 
  5551.  
  5552. case 'active': $where[] = "level_active = 1"; 
  5553. break; 
  5554. case 'inactive': $where[] = "level_active = 0"; 
  5555. break; 
  5556.  
  5557.  
  5558. if(isset($filter['order_by'])) { 
  5559. switch($filter['order_by']) { 
  5560.  
  5561. case 'order_id': $orderby[] = 'id ASC'; 
  5562. break; 
  5563. case 'order_name': $orderby[] = 'level_title ASC'; 
  5564. break; 
  5565.  
  5566.  
  5567.  
  5568. $sql = "SELECT * FROM {$this->membership_levels}"; 
  5569.  
  5570. if(!empty($where)) { 
  5571. $sql .= " WHERE " . implode(' AND ', $where); 
  5572.  
  5573. if(!empty($orderby)) { 
  5574. $sql .= " ORDER BY " . implode(', ', $orderby); 
  5575.  
  5576. return $this->db->get_results($sql); 
  5577.  
  5578.  
  5579.  
  5580. //subscriptions 
  5581.  
  5582. function get_public_subscriptions() { 
  5583.  
  5584. $where = array(); 
  5585. $orderby = array(); 
  5586.  
  5587. $where[] = "sub_public = 1"; 
  5588. $where[] = "sub_active = 1"; 
  5589.  
  5590. $orderby[] = 'id ASC'; 
  5591.  
  5592. $sql = "SELECT * FROM {$this->subscriptions}"; 
  5593.  
  5594. if(!empty($where)) { 
  5595. $sql .= " WHERE " . implode(' AND ', $where); 
  5596.  
  5597. if(!empty($orderby)) { 
  5598. $sql .= " ORDER BY " . implode(', ', $orderby); 
  5599.  
  5600. return $this->db->get_results($sql); 
  5601.  
  5602.  
  5603. function get_subscriptions($filter = false) { 
  5604.  
  5605. if($filter) { 
  5606.  
  5607. $where = array(); 
  5608. $orderby = array(); 
  5609.  
  5610. if(isset($filter['s'])) { 
  5611. $where[] = "sub_name LIKE '%" . mysql_real_escape_string($filter['s']) . "%'"; 
  5612.  
  5613. if(isset($filter['sub_status'])) { 
  5614. switch($filter['sub_status']) { 
  5615.  
  5616. case 'active': $where[] = "sub_active = 1"; 
  5617. break; 
  5618. case 'inactive': $where[] = "sub_active = 0"; 
  5619. break; 
  5620. case 'public': $where[] = "sub_public = 1"; 
  5621. break; 
  5622. case 'private': $where[] = "sub_public = 0"; 
  5623. break; 
  5624.  
  5625.  
  5626. if(isset($filter['order_by'])) { 
  5627. switch($filter['order_by']) { 
  5628.  
  5629. case 'order_id': $orderby[] = 'id ASC'; 
  5630. break; 
  5631. case 'order_name': $orderby[] = 'sub_name ASC'; 
  5632. break; 
  5633.  
  5634.  
  5635.  
  5636. $sql = "SELECT * FROM {$this->subscriptions}"; 
  5637.  
  5638. if(!empty($where)) { 
  5639. $sql .= " WHERE " . implode(' AND ', $where); 
  5640.  
  5641. if(!empty($orderby)) { 
  5642. $sql .= " ORDER BY " . implode(', ', $orderby); 
  5643.  
  5644. return $this->db->get_results($sql); 
  5645.  
  5646.  
  5647.  
  5648. function get_subscriptions_and_levels($filter = false) { 
  5649.  
  5650. if($filter) { 
  5651.  
  5652. $where = array(); 
  5653. $orderby = array(); 
  5654.  
  5655. if(isset($filter['s'])) { 
  5656. $where[] = "sub_name LIKE '%" . mysql_real_escape_string($filter['s']) . "%'"; 
  5657.  
  5658. if(isset($filter['sub_status'])) { 
  5659. switch($filter['sub_status']) { 
  5660.  
  5661. case 'active': $where[] = "sub_active = 1"; 
  5662. break; 
  5663. case 'inactive': $where[] = "sub_active = 0"; 
  5664. break; 
  5665. case 'public': $where[] = "sub_public = 1"; 
  5666. break; 
  5667. case 'private': $where[] = "sub_public = 0"; 
  5668. break; 
  5669.  
  5670.  
  5671.  
  5672. $sql = "SELECT s.id as sub_id, ml.id as level_id, s.*, ml.*, sl.level_order FROM {$this->subscriptions} AS s, {$this->subscriptions_levels} AS sl, {$this->membership_levels} AS ml"; 
  5673.  
  5674. if(!empty($where)) { 
  5675. $sql .= " WHERE " . implode(' AND ', $where); 
  5676.  
  5677. $sql .= " AND s.id = sl.sub_id AND sl.level_id = ml.id ORDER BY s.id ASC, sl.level_order ASC "; 
  5678.  
  5679. return $this->db->get_results($sql); 
  5680.  
  5681.  
  5682. function count_on_level( $level_id ) { 
  5683.  
  5684. $sql = $this->db->prepare( "SELECT count(*) as levelcount FROM {$this->membership_relationships} WHERE level_id = %d AND user_id > 0", $level_id ); 
  5685.  
  5686. return $this->db->get_var( $sql ); 
  5687.  
  5688.  
  5689. function count_on_sub( $sub_id ) { 
  5690.  
  5691. $sql = $this->db->prepare( "SELECT count(*) as levelcount FROM {$this->membership_relationships} WHERE sub_id = %d AND user_id > 0", $sub_id ); 
  5692.  
  5693. return $this->db->get_var( $sql ); 
  5694.  
  5695.  
  5696. // Rewrites 
  5697. function add_rewrites($wp_rewrite) { 
  5698.  
  5699. global $M_options; 
  5700.  
  5701. // This function adds in the api rewrite rules 
  5702. // Note the addition of the namespace variable so that we know these are vent based 
  5703. // calls 
  5704. $new_rules = array(); 
  5705.  
  5706. if(!empty($M_options['masked_url'])) { 
  5707. $new_rules[trailingslashit($M_options['masked_url']) . '(.+)'] = 'index.php?protectedfile=' . $wp_rewrite->preg_index(1); 
  5708.  
  5709. $new_rules['paymentreturn/(.+)'] = 'index.php?paymentgateway=' . $wp_rewrite->preg_index(1); 
  5710.  
  5711. $new_rules = apply_filters('M_rewrite_rules', $new_rules); 
  5712.  
  5713. $wp_rewrite->rules = array_merge($new_rules, $wp_rewrite->rules); 
  5714.  
  5715. return $wp_rewrite; 
  5716.  
  5717. function add_queryvars($vars) { 
  5718. if(!in_array('feedkey', $vars)) $vars[] = 'feedkey'; 
  5719. if(!in_array('protectedfile', $vars)) $vars[] = 'protectedfile'; 
  5720. if(!in_array('paymentgateway', $vars)) $vars[] = 'paymentgateway'; 
  5721.  
  5722. return $vars; 
  5723.  
  5724. // Profile 
  5725. function add_profile_feed_key($profileuser) { 
  5726.  
  5727. $id = $profileuser->ID; 
  5728.  
  5729. $member = new M_Membership($id); 
  5730.  
  5731. if($member->is_member()) { 
  5732. $key = get_user_meta($id, '_membership_key', true); 
  5733.  
  5734. if(empty($key)) { 
  5735. $key = md5($id . $profileuser->user_pass . time()); 
  5736. update_user_meta($id, '_membership_key', $key); 
  5737.  
  5738. ?> 
  5739. <h3><?php _e('Membership key', 'membership'); ?></h3> 
  5740.  
  5741. <table class="form-table"> 
  5742. <tr> 
  5743. <th><label for="description"><?php _e('Membership key', 'membership'); ?></label></th> 
  5744. <td><?php esc_html_e($key); ?> 
  5745. <br /> 
  5746. <span class="description"><?php _e('This key is used to give you access the the members RSS feed, keep it safe and secret.', 'membership'); ?></span></td> 
  5747. </tr> 
  5748. </table> 
  5749. <?php 
  5750.  
  5751.  
  5752.  
  5753. function update_membershipadmin_capability($user_id) { 
  5754.  
  5755. $user = new WP_User( $user_id ); 
  5756.  
  5757. if(!empty($_POST['membershipadmin']) && $_POST['membershipadmin'] == 'yes') { 
  5758. $user->add_cap('membershipadmin'); 
  5759. } else { 
  5760. $user->remove_cap('membershipadmin'); 
  5761.  
  5762.  
  5763. function add_membershipadmin_capability($profileuser) { 
  5764.  
  5765. $id = $profileuser->ID; 
  5766.  
  5767. ?> 
  5768. <h3><?php _e('Membership Administration', 'membership'); ?></h3> 
  5769.  
  5770. <table class="form-table"> 
  5771. <tr> 
  5772. <th><label for="description"><?php _e('Membership Administration', 'membership'); ?></label></th> 
  5773. <td> 
  5774. <input type='checkbox' name='membershipadmin' value='yes' <?php if($profileuser->has_cap('membershipadmin')) echo "checked='checked'"; ?>/> 
  5775.   
  5776. <span class="description"><?php _e('This user has access to administer the Membership system.', 'membership'); ?></span></td> 
  5777. </tr> 
  5778. </table> 
  5779. <?php 
  5780.  
  5781.  
  5782.  
  5783. /** Ping interface */ 
  5784. function update_subscription_ping_information( $sub_id ) { 
  5785.  
  5786. $subscription = new M_Subscription( $sub_id ); 
  5787.  
  5788. $subscription->update_meta( 'joining_ping', $_POST['joiningping'] ); 
  5789. $subscription->update_meta( 'leaving_ping', $_POST['leavingping'] ); 
  5790.  
  5791.  
  5792. function show_subscription_ping_information( $sub_id ) { 
  5793.  
  5794. // Get all the pings 
  5795. $pings = $this->get_pings(); 
  5796.  
  5797. // Get the currentlt set ping for each level 
  5798. $subscription = new M_Subscription( $sub_id ); 
  5799.  
  5800. $joinping = $subscription->get_meta( 'joining_ping', '' ); 
  5801. $leaveping = $subscription->get_meta( 'leaving_ping', '' ); 
  5802.  
  5803. ?> 
  5804. <h3><?php _e('Subscription Pings', 'membership'); ?></h3> 
  5805. <p class='description'><?php _e('If you want any pings to be sent when a member joins and/or leaves this subscription then set them below.', 'membership'); ?></p> 
  5806.  
  5807. <div class='sub-details'> 
  5808.  
  5809. <label for='joiningping'><?php _e('Joining Ping', 'membership'); ?></label> 
  5810. <select name='joiningping'> 
  5811. <option value='' <?php selected($joinping, ''); ?>><?php _e('None', 'membership'); ?></option> 
  5812. <?php 
  5813. if(!empty($pings)) { 
  5814. foreach($pings as $ping) { 
  5815. ?> 
  5816. <option value='<?php echo $ping->id; ?>' <?php selected($joinping, $ping->id); ?>><?php echo stripslashes($ping->pingname); ?></option> 
  5817. <?php 
  5818. ?> 
  5819. </select><br/> 
  5820.  
  5821. <label for='leavingping'><?php _e('Leaving Ping', 'membership'); ?></label> 
  5822. <select name='leavingping'> 
  5823. <option value='' <?php selected($leaveping, ''); ?>><?php _e('None', 'membership'); ?></option> 
  5824. <?php 
  5825. if(!empty($pings)) { 
  5826. foreach($pings as $ping) { 
  5827. ?> 
  5828. <option value='<?php echo $ping->id; ?>' <?php selected($leaveping, $ping->id); ?>><?php echo stripslashes($ping->pingname); ?></option> 
  5829. <?php 
  5830. ?> 
  5831. </select> 
  5832. </div> 
  5833. <?php 
  5834.  
  5835. function update_level_ping_information( $level_id ) { 
  5836.  
  5837. $level = new M_Level( $level_id ); 
  5838.  
  5839. $level->update_meta( 'joining_ping', $_POST['joiningping'] ); 
  5840. $level->update_meta( 'leaving_ping', $_POST['leavingping'] ); 
  5841.  
  5842.  
  5843. function show_level_ping_information( $level_id ) { 
  5844. // Get all the pings 
  5845. $pings = $this->get_pings(); 
  5846.  
  5847. // Get the currentlt set ping for each level 
  5848. $level = new M_Level( $level_id ); 
  5849.  
  5850. $joinping = $level->get_meta( 'joining_ping', '' ); 
  5851. $leaveping = $level->get_meta( 'leaving_ping', '' ); 
  5852.  
  5853. ?> 
  5854. <h3><?php _e('Level Pings', 'membership'); ?></h3> 
  5855. <p class='description'><?php _e('If you want any pings to be sent when a member joins and/or leaves this level then set them below.', 'membership'); ?></p> 
  5856.  
  5857. <div class='level-details'> 
  5858.  
  5859. <label for='joiningping'><?php _e('Joining Ping', 'membership'); ?></label> 
  5860. <select name='joiningping'> 
  5861. <option value='' <?php selected($joinping, ''); ?>><?php _e('None', 'membership'); ?></option> 
  5862. <?php 
  5863. if(!empty($pings)) { 
  5864. foreach($pings as $ping) { 
  5865. ?> 
  5866. <option value='<?php echo $ping->id; ?>' <?php selected($joinping, $ping->id); ?>><?php echo stripslashes($ping->pingname); ?></option> 
  5867. <?php 
  5868. ?> 
  5869. </select><br/> 
  5870.  
  5871. <label for='leavingping'><?php _e('Leaving Ping', 'membership'); ?></label> 
  5872. <select name='leavingping'> 
  5873. <option value='' <?php selected($leaveping, ''); ?>><?php _e('None', 'membership'); ?></option> 
  5874. <?php 
  5875. if(!empty($pings)) { 
  5876. foreach($pings as $ping) { 
  5877. ?> 
  5878. <option value='<?php echo $ping->id; ?>' <?php selected($leaveping, $ping->id); ?>><?php echo stripslashes($ping->pingname); ?></option> 
  5879. <?php 
  5880. ?> 
  5881. </select> 
  5882. </div> 
  5883. <?php 
  5884.  
  5885.  
  5886. function handle_gateways_panel_updates() { 
  5887.  
  5888. global $action, $page, $M_Gateways; 
  5889.  
  5890. wp_reset_vars( array('action', 'page') ); 
  5891.  
  5892. if(isset($_GET['doaction']) || isset($_GET['doaction2'])) { 
  5893. if(addslashes($_GET['action']) == 'toggle' || addslashes($_GET['action2']) == 'toggle') { 
  5894. $action = 'bulk-toggle'; 
  5895.  
  5896. $active = get_option('membership_activated_gateways', array()); 
  5897.  
  5898. switch(addslashes($action)) { 
  5899.  
  5900. case 'deactivate': $key = addslashes($_GET['gateway']); 
  5901. if(!empty($key)) { 
  5902. check_admin_referer('toggle-gateway-' . $key); 
  5903.  
  5904. $found = array_search($key, $active); 
  5905. if($found !== false) { 
  5906. unset($active[$found]); 
  5907. update_option('membership_activated_gateways', array_unique($active)); 
  5908. wp_safe_redirect( add_query_arg( 'msg', 5, wp_get_referer() ) ); 
  5909. } else { 
  5910. wp_safe_redirect( add_query_arg( 'msg', 6, wp_get_referer() ) ); 
  5911. break; 
  5912.  
  5913. case 'activate': $key = addslashes($_GET['gateway']); 
  5914. if(!empty($key)) { 
  5915. check_admin_referer('toggle-gateway-' . $key); 
  5916.  
  5917. if(!in_array($key, $active)) { 
  5918. $active[] = $key; 
  5919. update_option('membership_activated_gateways', array_unique($active)); 
  5920. wp_safe_redirect( add_query_arg( 'msg', 3, wp_get_referer() ) ); 
  5921. } else { 
  5922. wp_safe_redirect( add_query_arg( 'msg', 4, wp_get_referer() ) ); 
  5923. break; 
  5924.  
  5925. case 'bulk-toggle': 
  5926. check_admin_referer('bulk-gateways'); 
  5927. foreach($_GET['gatewaycheck'] AS $key) { 
  5928. $found = array_search($key, $active); 
  5929. if($found !== false) { 
  5930. unset($active[$found]); 
  5931. } else { 
  5932. $active[] = $key; 
  5933. update_option('membership_activated_gateways', array_unique($active)); 
  5934. wp_safe_redirect( add_query_arg( 'msg', 7, wp_get_referer() ) ); 
  5935. break; 
  5936.  
  5937. case 'updated': $gateway = addslashes($_POST['gateway']); 
  5938. check_admin_referer('updated-' . $gateway); 
  5939. if($M_Gateways[$gateway]->update()) { 
  5940. wp_safe_redirect( add_query_arg( 'msg', 1, 'admin.php?page=' . $page ) ); 
  5941. } else { 
  5942. wp_safe_redirect( add_query_arg( 'msg', 2, 'admin.php?page=' . $page ) ); 
  5943.  
  5944. break; 
  5945.  
  5946.  
  5947.  
  5948. function handle_gateways_panel() { 
  5949.  
  5950. global $action, $page, $M_Gateways; 
  5951.  
  5952. wp_reset_vars( array('action', 'page') ); 
  5953.  
  5954. switch(addslashes($action)) { 
  5955.  
  5956. case 'edit': if(isset($M_Gateways[addslashes($_GET['gateway'])])) { 
  5957. $M_Gateways[addslashes($_GET['gateway'])]->settings(); 
  5958. return; // so we don't show the list below 
  5959. break; 
  5960.  
  5961. case 'transactions': 
  5962. if(isset($M_Gateways[addslashes($_GET['gateway'])])) { 
  5963. $M_Gateways[addslashes($_GET['gateway'])]->transactions(); 
  5964. return; // so we don't show the list below 
  5965. break; 
  5966.  
  5967.  
  5968.  
  5969. $messages = array(); 
  5970. $messages[1] = __('Gateway updated.', 'membership'); 
  5971. $messages[2] = __('Gateway not updated.', 'membership'); 
  5972.  
  5973. $messages[3] = __('Gateway activated.', 'membership'); 
  5974. $messages[4] = __('Gateway not activated.', 'membership'); 
  5975.  
  5976. $messages[5] = __('Gateway deactivated.', 'membership'); 
  5977. $messages[6] = __('Gateway not deactivated.', 'membership'); 
  5978.  
  5979. $messages[7] = __('Gateway activation toggled.', 'membership'); 
  5980.  
  5981. ?> 
  5982. <div class='wrap'> 
  5983. <div class="icon32" id="icon-plugins"><br></div> 
  5984. <h2><?php _e('Edit Gateways', 'membership'); ?></h2> 
  5985.  
  5986. <?php 
  5987. if ( isset($_GET['msg']) ) { 
  5988. echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>'; 
  5989. $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); 
  5990.  
  5991. if($this->show_user_help( $page )) { 
  5992. ?> 
  5993. <div class='screenhelpheader'> 
  5994. <a href="admin.php?page=<?php echo $page; ?>&action=removeheader" class="welcome-panel-close"><?php _e('Dismiss', 'membership'); ?></a> 
  5995. <?php 
  5996. ob_start(); 
  5997. include_once(membership_dir('membershipincludes/help/header.gateways.php')); 
  5998. echo ob_get_clean(); 
  5999. ?> 
  6000. </div> 
  6001. <?php 
  6002.  
  6003. ?> 
  6004.  
  6005. <form method="get" action="?page=<?php echo esc_attr($page); ?>" id="posts-filter"> 
  6006.  
  6007. <input type='hidden' name='page' value='<?php echo esc_attr($page); ?>' /> 
  6008.  
  6009. <div class="tablenav"> 
  6010.  
  6011. <div class="alignleft actions"> 
  6012. <select name="action"> 
  6013. <option selected="selected" value=""><?php _e('Bulk Actions', 'membership'); ?></option> 
  6014. <option value="toggle"><?php _e('Toggle activation', 'membership'); ?></option> 
  6015. </select> 
  6016. <input type="submit" class="button-secondary action" id="doaction" name="doaction" value="<?php _e('Apply', 'membership'); ?>"> 
  6017.  
  6018. </div> 
  6019.  
  6020. <div class="alignright actions"></div> 
  6021.  
  6022. <br class="clear"> 
  6023. </div> 
  6024.  
  6025. <div class="clear"></div> 
  6026.  
  6027. <?php 
  6028. wp_original_referer_field(true, 'previous'); wp_nonce_field('bulk-gateways'); 
  6029.  
  6030. $columns = array( "name" => __('Gateway Name', 'membership'),  
  6031. "active" => __('Active', 'membership') 
  6032. ); 
  6033.  
  6034. $columns = apply_filters('membership_gatewaycolumns', $columns); 
  6035.  
  6036. $gateways = get_membership_gateways(); 
  6037.  
  6038. $active = get_option('membership_activated_gateways', array()); 
  6039.  
  6040. ?> 
  6041.  
  6042. <table cellspacing="0" class="widefat fixed"> 
  6043. <thead> 
  6044. <tr> 
  6045. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  6046. <?php 
  6047. foreach($columns as $key => $col) { 
  6048. ?> 
  6049. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  6050. <?php 
  6051. ?> 
  6052. </tr> 
  6053. </thead> 
  6054.  
  6055. <tfoot> 
  6056. <tr> 
  6057. <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th> 
  6058. <?php 
  6059. reset($columns); 
  6060. foreach($columns as $key => $col) { 
  6061. ?> 
  6062. <th style="" class="manage-column column-<?php echo $key; ?>" id="<?php echo $key; ?>" scope="col"><?php echo $col; ?></th> 
  6063. <?php 
  6064. ?> 
  6065. </tr> 
  6066. </tfoot> 
  6067.  
  6068. <tbody> 
  6069. <?php 
  6070. if($gateways) { 
  6071. foreach($gateways as $key => $gateway) { 
  6072. $default_headers = array( 
  6073. 'Name' => 'Addon Name',  
  6074. 'Author' => 'Author',  
  6075. 'Description' => 'Description',  
  6076. 'AuthorURI' => 'Author URI',  
  6077. 'gateway_id' => 'Gateway ID' 
  6078. ); 
  6079.  
  6080. $gateway_data = get_file_data( membership_dir('membershipincludes/gateways/' . $gateway), $default_headers, 'plugin' ); 
  6081.  
  6082. if(empty($gateway_data['Name'])) { 
  6083. continue; 
  6084.  
  6085. ?> 
  6086. <tr valign="middle" class="alternate" id="gateway-<?php echo $gateway_data['gateway_id']; ?>"> 
  6087. <th class="check-column" scope="row"><input type="checkbox" value="<?php echo esc_attr($gateway_data['gateway_id']); ?>" name="gatewaycheck[]"></th> 
  6088. <td class="column-name"> 
  6089. <strong><?php echo esc_html($gateway_data['Name']) ?></strong> 
  6090. <?php if(!empty($gateway_data['Description'])) { 
  6091. ?><br/><?php echo esc_html($gateway_data['Description']); 
  6092.  
  6093. $actions = array(); 
  6094.  
  6095. if(in_array($gateway_data['gateway_id'], $active)) { 
  6096. $actions['edit'] = "<span class='edit'><a href='?page=" . $page . "&action=edit&gateway=" . $gateway_data['gateway_id'] . "'>" . __('Settings', 'membership') . "</a></span>"; 
  6097. $actions['transactions'] = "<span class='edit'><a href='?page=" . $page . "&action=transactions&gateway=" . $gateway_data['gateway_id'] . "'>" . __('View transactions', 'membership') . "</a></span>"; 
  6098. $actions['toggle'] = "<span class='edit deactivate'><a href='" . wp_nonce_url("?page=" . $page. "&action=deactivate&gateway=" . $gateway_data['gateway_id'] . "", 'toggle-gateway-' . $gateway_data['gateway_id']) . "'>" . __('Deactivate', 'membership') . "</a></span>"; 
  6099.  
  6100. } else { 
  6101. $actions['toggle'] = "<span class='edit activate'><a href='" . wp_nonce_url("?page=" . $page. "&action=activate&gateway=" . $gateway_data['gateway_id'] . "", 'toggle-gateway-' . $gateway_data['gateway_id']) . "'>" . __('Activate', 'membership') . "</a></span>"; 
  6102. ?> 
  6103. <br><div class="row-actions"><?php echo implode(" | ", $actions); ?></div> 
  6104. </td> 
  6105.  
  6106. <td class="column-active"> 
  6107. <?php 
  6108. if(in_array($gateway_data['gateway_id'], $active)) { 
  6109. echo "<span class='membershipactivestatus'>" . __('Active', 'membership') . "</span>"; 
  6110. } else { 
  6111. echo "<span class='membershipinactivestatus'>" . __('Inactive', 'membership') . "</span>"; 
  6112. ?> 
  6113. </td> 
  6114. </tr> 
  6115. <?php 
  6116. } else { 
  6117. $columncount = count($columns) + 1; 
  6118. ?> 
  6119. <tr valign="middle" class="alternate" > 
  6120. <td colspan="<?php echo $columncount; ?>" scope="row"><?php _e('No Gateways where found for this install.', 'membership'); ?></td> 
  6121. </tr> 
  6122. <?php 
  6123. ?> 
  6124.  
  6125. </tbody> 
  6126. </table> 
  6127.  
  6128.  
  6129. <div class="tablenav"> 
  6130.  
  6131. <div class="alignleft actions"> 
  6132. <select name="action2"> 
  6133. <option selected="selected" value=""><?php _e('Bulk Actions'); ?></option> 
  6134. <option value="toggle"><?php _e('Toggle activation'); ?></option> 
  6135. </select> 
  6136. <input type="submit" class="button-secondary action" id="doaction2" name="doaction2" value="<?php _e('Apply', 'membership'); ?>"> 
  6137. </div> 
  6138. <div class="alignright actions"></div> 
  6139. <br class="clear"> 
  6140. </div> 
  6141.  
  6142. </form> 
  6143.  
  6144. </div> <!-- wrap --> 
  6145. <?php 
  6146.  
  6147. function get_coupons( $filter = false ) { 
  6148.  
  6149. global $blog_id; 
  6150.  
  6151. $sql = "SELECT * FROM {$this->coupons}"; 
  6152.  
  6153. if(!is_network_admin()) { 
  6154. // We are on a single site admin interface 
  6155. $sql .= $this->db->prepare( " WHERE site_id = %d", $blog_id ); 
  6156.  
  6157. return $this->db->get_results( $sql ); 
  6158.  
  6159.  
  6160.  
  6161. function activate_addon( $addon ) { 
  6162.  
  6163. $active = get_option('membership_activated_addons', array()); 
  6164.  
  6165. if(!in_array($addon, $active)) { 
  6166. $active[] = $addon; 
  6167. update_option('membership_activated_addons', array_unique($active)); 
  6168.  
  6169. function deactivate_addon( $addon ) { 
  6170.  
  6171. $active = get_option('membership_activated_addons', array()); 
  6172.  
  6173. $found = array_search($addon, $active); 
  6174. if($found !== false) { 
  6175. unset($active[$found]); 
  6176. update_option('membership_activated_addons', array_unique($active)); 
  6177.  
  6178. // The popover registration functions added to the bottom of this class until a new more suitable home can be found 
  6179. function popover_signup_form() { 
  6180.  
  6181. $content = ''; 
  6182. $content = apply_filters('membership_popover_signup_form_before_content', $content ); 
  6183. ob_start(); 
  6184. if( defined('MEMBERSHIP_POPOVER_SIGNUP_FORM') && file_exists( MEMBERSHIP_POPOVER_SIGNUP_FORM ) ) { 
  6185. include_once( MEMBERSHIP_POPOVER_SIGNUP_FORM ); 
  6186. } elseif(file_exists( apply_filters('membership_override_popover_signup_form', membership_dir('membershipincludes/includes/popover_signup.form.php')) ) ) { 
  6187. include_once( apply_filters('membership_override_popover_signup_form', membership_dir('membershipincludes/includes/popover_signup.form.php')) ); 
  6188. $content .= ob_get_contents(); 
  6189. ob_end_clean(); 
  6190.  
  6191. $content = apply_filters('membership_popover_signup_form_after_content', $content ); 
  6192. echo $content; 
  6193.  
  6194. die(); 
  6195.  
  6196. function popover_register_process() { 
  6197.  
  6198. global $M_options; 
  6199.  
  6200. //include_once(ABSPATH . WPINC . '/registration.php'); 
  6201.  
  6202. $error = new WP_Error(); 
  6203.  
  6204. if(!wp_verify_nonce( $_POST['nonce'], 'membership_register')) { 
  6205. $error->add('invalid', __('Invalid form submission.', 'membership')); 
  6206.  
  6207. if(!validate_username( $_POST['user_login'] )) { 
  6208. $error->add('usernamenotvalid', __('The username is not valid, sorry.', 'membership')); 
  6209.  
  6210. if(username_exists(sanitize_user($_POST['user_login']))) { 
  6211. $error->add('usernameexists', __('That username is already taken, sorry.', 'membership')); 
  6212.  
  6213. if(!is_email($_POST['email'])) { 
  6214. $error->add('emailnotvalid', __('The email address is not valid, sorry.', 'membership')); 
  6215.  
  6216. if(email_exists($_POST['email'])) { 
  6217. $error->add('emailexists', __('That email address is already taken, sorry.', 'membership')); 
  6218.  
  6219. $error = apply_filters( 'membership_subscription_form_before_registration_process', $error ); 
  6220.  
  6221. if(is_wp_error($error)) { 
  6222. $anyerrors = $error->get_error_messages(); 
  6223. } else { 
  6224. $anyerrors = array(); 
  6225.  
  6226. if( empty($anyerrors) ) { 
  6227. // Pre - error reporting check for final add user 
  6228. $user_id = wp_create_user( sanitize_user($_POST['user_login']), $_POST['password'], $_POST['email'] ); 
  6229.  
  6230. if(is_wp_error($user_id) && method_exists($user_id, 'get_error_message')) { 
  6231. $error->add('userid', $user_id->get_error_message()); 
  6232. } else { 
  6233. $member = new M_Membership( $user_id ); 
  6234. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION') && MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION == true) { 
  6235. $member->deactivate(); 
  6236. } else { 
  6237. $creds = array( 
  6238. 'user_login' => $_POST['user_login'],  
  6239. 'user_password' => $_POST['password'],  
  6240. 'remember' => true 
  6241. ); 
  6242. $is_ssl = (isset($_SERVER['https']) && strtolower($_SERVER['https']) == 'on' ? true : false); 
  6243. $user = wp_signon( $creds, $is_ssl ); 
  6244.  
  6245. if ( is_wp_error($user) && method_exists($user, 'get_error_message') ) { 
  6246. $error->add('userlogin', $user->get_error_message()); 
  6247. } else { 
  6248. // Set the current user up 
  6249. wp_set_current_user( $user_id ); 
  6250.  
  6251. if( has_action('membership_susbcription_form_registration_notification') ) { 
  6252. do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']); 
  6253. } else { 
  6254. wp_new_user_notification($user_id, $_POST['password']); 
  6255.  
  6256. do_action( 'membership_subscription_form_registration_process', $error, $user_id ); 
  6257. } else { 
  6258. do_action( 'membership_subscription_form_registration_process', $error, 0 ); 
  6259.  
  6260. $anyerrors = $error->get_error_code(); 
  6261. if(is_wp_error($error) && !empty($anyerrors)) { 
  6262. // we have an error - output 
  6263. $messages = $error->get_error_messages(); 
  6264. //sendback error 
  6265. echo json_encode( array('errormsg' => $messages[0]) ); 
  6266. } else { 
  6267. // everything seems fine (so far), so we have our queued user so let's 
  6268. // move to picking a subscription - so send back the form. 
  6269. echo $this->popover_sendpayment_form( $user_id ); 
  6270.  
  6271. exit; 
  6272.  
  6273.  
  6274. function popover_login_process() { 
  6275.  
  6276. $error = new WP_Error(); 
  6277.  
  6278. if(!wp_verify_nonce( $_POST['nonce'], 'membership_login')) { 
  6279. $error->add('invalid', __('Invalid form submission.', 'membership')); 
  6280.  
  6281. $userbylogin = get_user_by( 'login', $_POST['user_login'] ); 
  6282.  
  6283. if(!empty($userbylogin)) { 
  6284. $user = wp_authenticate( $userbylogin->user_login, $_POST['password'] ); 
  6285. if(is_wp_error($user)) { 
  6286. $error->add('userlogin', $user->get_error_message()); 
  6287. } else { 
  6288. wp_set_auth_cookie($user->ID); 
  6289. // Set the current user up 
  6290. wp_set_current_user( $user->ID ); 
  6291. } else { 
  6292. $error->add('userlogin', __('User not found.', 'membership') ); 
  6293.  
  6294. $anyerrors = $error->get_error_code(); 
  6295. if(is_wp_error($error) && !empty($anyerrors)) { 
  6296. // we have an error - output 
  6297. $messages = $error->get_error_messages(); 
  6298. //sendback error 
  6299. echo json_encode( array('errormsg' => $messages[0]) ); 
  6300. } else { 
  6301. // everything seems fine (so far), so we have our queued user so let's 
  6302. // move to picking a subscription - so send back the form. 
  6303. echo $this->popover_sendpayment_form($user->ID); 
  6304.  
  6305. exit; 
  6306.  
  6307. function popover_extraform_process() { 
  6308. echo $this->popover_extra_payment_form(); 
  6309. exit; 
  6310. function popover_sendpayment_form( $user_id = false ) { 
  6311.  
  6312. $content = ''; 
  6313. $content = apply_filters('membership_popover_sendpayment_form_before_content', $content ); 
  6314. ob_start(); 
  6315. if( defined('MEMBERSHIP_POPOVER_SENDPAYMENT_FORM') && file_exists( MEMBERSHIP_POPOVER_SENDPAYMENT_FORM ) ) { 
  6316. include_once( MEMBERSHIP_POPOVER_SENDPAYMENT_FORM ); 
  6317. } elseif(file_exists( apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php')) ) ) { 
  6318. include_once( apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php')) ); 
  6319. $content .= ob_get_contents(); 
  6320. ob_end_clean(); 
  6321.  
  6322. $content = apply_filters('membership_popover_sendpayment_form_after_content', $content ); 
  6323. echo $content; 
  6324.  
  6325. exit; 
  6326.  
  6327. function popover_extra_payment_form( $user_id = false ) { 
  6328.  
  6329. $content = ''; 
  6330. $content = apply_filters('membership_popover_extraform_before_content', $content ); 
  6331. ob_start(); 
  6332. if( defined('MEMBERSHIP_POPOVER_SENDPAYMENT_FORM') && file_exists( MEMBERSHIP_POPOVER_SENDPAYMENT_FORM ) ) { 
  6333. include_once( MEMBERSHIP_POPOVER_SENDPAYMENT_FORM ); 
  6334. } elseif(file_exists( apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php')) ) ) { 
  6335. include_once( apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php')) ); 
  6336. $content .= ob_get_contents(); 
  6337. ob_end_clean(); 
  6338.  
  6339. $content = apply_filters('membership_popover_extraform_after_content', $content ); 
  6340. echo $content; 
  6341.  
  6342. exit; 
  6343.  
  6344.  
  6345. function create_defaults() { 
  6346.  
  6347. // Function to create some defaults if they are not set 
  6348.  
  6349. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  6350. if(function_exists('get_blog_option')) { 
  6351. if(function_exists('switch_to_blog')) { 
  6352. switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE); 
  6353.  
  6354. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  6355. } else { 
  6356. $M_options = get_option('membership_options', array()); 
  6357. } else { 
  6358. $M_options = get_option('membership_options', array()); 
  6359.  
  6360. // Make registration and associated pages 
  6361. if(empty($M_options['registration_page'])) { 
  6362.  
  6363. // Check if the buddypress registration page is created or not 
  6364. if(defined('BP_VERSION') && version_compare( preg_replace('/-.*$/', '', BP_VERSION), "1.5", '>=')) { 
  6365. // Get the BP pages 
  6366. $bppages = get_option('bp-pages', array()); 
  6367.  
  6368.  
  6369. $pagedetails = array('post_title' => __('Register', 'membership'), 'post_name' => 'register', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => ''); 
  6370. $id = wp_insert_post( $pagedetails ); 
  6371. $M_options['registration_page'] = $id; 
  6372.  
  6373. $pagedetails = array('post_title' => __('Account', 'membership'), 'post_name' => 'account', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => ''); 
  6374. $id = wp_insert_post( $pagedetails ); 
  6375. $M_options['account_page'] = $id; 
  6376.  
  6377. $content = '<p>' . __('The content you are trying to access is only available to members. Sorry.', 'membership') . '</p>'; 
  6378. $pagedetails = array('post_title' => __('Protected Content', 'membership'), 'post_name' => 'protected', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $content); 
  6379. $id = wp_insert_post( $pagedetails ); 
  6380. $M_options['nocontent_page'] = $id; 
  6381.  
  6382.  
  6383. // Create relevant admin side shortcodes 
  6384. if(empty($M_options['membershipadminshortcodes'])) { 
  6385. if(!is_array($M_options['membershipadminshortcodes'])) { 
  6386. $M_options['membershipadminshortcodes'] = array(); 
  6387.  
  6388. if(class_exists('RGForms')) { 
  6389. // Gravity Forms exists 
  6390. $M_options['membershipadminshortcodes'][] = 'gravityform'; 
  6391.  
  6392. if(defined('WPCF7_VERSION')) { 
  6393. // Contact Form 7 exists 
  6394. $M_options['membershipadminshortcodes'][] = 'contact-form'; 
  6395.  
  6396. if(defined('WPAUDIO_URL')) { 
  6397. // WPAudio exists 
  6398. $M_options['membershipadminshortcodes'][] = 'wpaudio'; 
  6399.  
  6400. // Create a default download group 
  6401. if(empty($M_options['membershipdownloadgroups'])) { 
  6402. if(!is_array($M_options['membershipdownloadgroups'])) { 
  6403. $M_options['membershipdownloadgroups'] = array(); 
  6404. $M_options['membershipdownloadgroups'][] = __('default', 'membership'); 
  6405.  
  6406. // Create a hashed downloads url 
  6407. if(empty($M_options['masked_url'])) { 
  6408. $M_options['masked_url'] = __('downloads', 'membership'); 
  6409.  
  6410. // Update the options 
  6411. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) { 
  6412. if(function_exists('update_blog_option')) { 
  6413. update_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', $M_options); 
  6414. } else { 
  6415. update_option('membership_options', $M_options); 
  6416. } else { 
  6417. update_option('membership_options', $M_options); 
  6418.  
  6419.  
  6420. // Functions to determine whether to show user help on this screen and to disable it if not 
  6421. function show_user_help( $page ) { 
  6422.  
  6423. $user_id = get_current_user_id(); 
  6424.  
  6425. $helpscreens = get_user_meta($user_id, 'membership_show_help_headers', true); 
  6426.  
  6427. if(!is_array($helpscreens)) { 
  6428. $helpscreens = array(); 
  6429.  
  6430. if(!isset($helpscreens[$page])) { 
  6431. return true; 
  6432. } else { 
  6433. return false; 
  6434.  
  6435.  
  6436. function dismiss_user_help( $page ) { 
  6437.  
  6438. $user_id = get_current_user_id(); 
  6439.  
  6440. $helpscreens = get_user_meta($user_id, 'membership_show_help_headers', true); 
  6441.  
  6442. if(!is_array($helpscreens)) { 
  6443. $helpscreens = array(); 
  6444.  
  6445. if(!isset($helpscreens[$page])) { 
  6446. $helpscreens[$page] = 'no'; 
  6447.  
  6448. update_user_meta( $user_id, 'membership_show_help_headers', $helpscreens ); 
  6449.  
  6450. // Level shortcodes function 
  6451. function build_level_shortcode_list( $shortcodes = array() ) { 
  6452.  
  6453. if(!is_array($shortcodes)) { 
  6454. $shortcodes = array(); 
  6455.  
  6456. $levels = $this->get_membership_levels(); 
  6457.  
  6458. if(!empty($levels)) { 
  6459. foreach($levels as $level) { 
  6460. $shortcodes[] = M_normalize_shortcode($level->level_title); 
  6461.  
  6462. return $shortcodes; 
  6463.  
  6464.  
  6465. function start_membership_session() { 
  6466. if (session_id() == "") 
  6467. session_start(); 
  6468.  
  6469.  
  6470. // Remove relationship when user is deleted 
  6471. function remove_relationships_on_delete( $user_id ) { 
  6472. global $wpdb; 
  6473.  
  6474. $sql = $wpdb->prepare( "DELETE FROM ".$wpdb->prefix."m_membership_relationships WHERE user_id = %d", $user_id ); 
  6475. $wpdb->query( $sql ); 
  6476.  
  6477.  
  6478.