/app_old/membershipincludes/classes/membershipadmin.php

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