/app_old/membershipincludes/includes/renew.form.php

  1. <?php 
  2.  
  3. if(!is_user_logged_in()) { 
  4. // The user isn't logged in so display a message here 
  5. ?> 
  6. <div id='membership-wrapper'> 
  7. <form class="form-membership" action="<?php echo get_permalink(); ?>" method="post"> 
  8. <fieldset> 
  9. <legend><?php echo __('Your Subscriptions', 'membership'); ?></legend> 
  10. <div class="alert alert-error"> 
  11. <?php echo __('You are not currently logged in. Please login to view your subscriptions.', 'membership'); ?> 
  12. </div> 
  13.  
  14. </fieldset> 
  15. </form> 
  16. </div> 
  17. <?php 
  18. } else { 
  19. // The user is logged in so go forward to the next check 
  20. if(!current_user_has_subscription()) { 
  21. // The user doesn't have a subscription so we should display a nice message and then the subscription form(?) 
  22. ?> 
  23. <div id='membership-wrapper'> 
  24. <form class="form-membership" action="<?php echo get_permalink(); ?>" method="post"> 
  25. <fieldset> 
  26. <legend><?php echo __('Your Subscriptions', 'membership'); ?></legend> 
  27. <div class="alert alert-error"> 
  28. <?php echo __('You do not currently have any subscriptions in place. You can sign up for a new subscription by selecting one below', 'membership'); ?> 
  29. </div> 
  30.  
  31. <div class="priceboxes"> 
  32. <?php 
  33. do_action( 'membership_subscription_form_before_subscriptions' ); 
  34.  
  35. $subs = $this->get_subscriptions(); 
  36.  
  37. $subs = apply_filters( 'membership_override_subscriptions', $subs ); 
  38.  
  39. foreach((array) $subs as $key => $sub) { 
  40.  
  41. $subscription = new M_Subscription($sub->id); 
  42.  
  43. ?> 
  44. <div class="pricebox subscriptionbox" id='subscriptionbox-<?php echo $subscription->id; ?>'> 
  45. <div class="topbar"><span class='title'><?php echo $subscription->sub_name(); ?></span></div> 
  46. <div class="pricedetails"><?php echo $subscription->sub_description(); ?></div> 
  47. <div class="bottombar"><span class='price'><?php echo $subscription->sub_pricetext(); ?></span> 
  48. <?php 
  49. $pricing = $subscription->get_pricingarray(); 
  50.  
  51. if($pricing) { 
  52. ?> 
  53. <span class='link'> 
  54. <?php 
  55.  
  56. if($M_options['formtype'] == 'new') { 
  57. // pop up form 
  58. $link = admin_url( 'admin-ajax.php' ); 
  59. $link .= '?action=buynow&subscription=' . (int) $sub->id; 
  60. $class = 'popover'; 
  61. } else { 
  62. // original form 
  63. $link = get_permalink($M_options['registration_page']); 
  64. $link .= '?action=registeruser&subscription=' . (int) $sub->id; 
  65. $class = ''; 
  66.  
  67. if(empty($linktext)) { 
  68. $linktext = apply_filters('membership_subscription_signup_text', __('Sign Up', 'membership')); 
  69.  
  70. $html = "<a href='" . $link . "' class='button " . $class . " " . apply_filters('membership_subscription_button_color', 'blue') . "'>" . $linktext . "</a>"; 
  71. echo $html; 
  72. ?> 
  73. <?php //do_action('membership_purchase_button', $subscription, $pricing, $user_id); ?> 
  74. </span> 
  75. <?php 
  76. ?> 
  77. </div> 
  78. </div> 
  79.  
  80.  
  81. <?php 
  82. do_action( 'membership_subscription_form_after_subscriptions' ); 
  83. ?> 
  84. </div> <!-- price boxes --> 
  85.  
  86. </fieldset> 
  87. </form> 
  88. </div> 
  89. <?php 
  90. } else { 
  91. // The user has a subscription so we can display it with the information 
  92. $member = current_member(); 
  93.  
  94. //Handle the processing if needed 
  95. if(isset($_POST['action'])) { 
  96. switch(addslashes($_POST['action'])) { 
  97. case 'unsubscribe': // Unsubscribe button has been clicked for solo gateways 
  98. $sub_id = (int) $_POST['subscription']; 
  99. $user = (int) $_POST['user']; 
  100. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'cancel-sub_' . $sub_id) && $user == $member->ID ) { 
  101. $member->mark_for_expire( $sub_id ); 
  102. break; 
  103.  
  104. case 'renewfree': // Renew a free level on this subscription 
  105. $sub_id = (int) $_POST['subscription']; 
  106. $user = (int) $_POST['user']; 
  107. $level = (int) $_POST['level']; 
  108. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'renew-sub_' . $sub_id) && $user == $member->ID ) { 
  109. $member->record_active_payment( $sub_id, $level, time() ); 
  110. //update_user_meta( $member->ID, '_membership_last_upgraded', time()); 
  111. break; 
  112.  
  113. case 'upgradesolo': // Upgrade a solo subscription 
  114. $sub_id = (int) $_POST['subscription']; 
  115. $user = (int) $_POST['user']; 
  116. $fromsub_id = (int) $_POST['fromsub_id']; 
  117. $gateway = $_POST['gateway']; 
  118. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'upgrade-sub_' . $sub_id) && $user == $member->ID ) { 
  119. // Join the new subscription 
  120. $member->create_subscription($sub_id, $gateway); 
  121. // Remove the old subscription 
  122. $member->drop_subscription($fromsub_id); 
  123. // Timestamp the update 
  124. update_user_meta( $user, '_membership_last_upgraded', time()); 
  125. break; 
  126. case 'upgradefromfree': 
  127. $sub_id = (int) $_POST['subscription']; 
  128. $user = (int) $_POST['user']; 
  129. $fromsub_id = (int) $_POST['fromsub_id']; 
  130. $gateway = $_POST['gateway']; 
  131. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'upgrade-sub_' . $sub_id) && $user == $member->ID ) { 
  132. // Join the new subscription 
  133. $member->create_subscription($sub_id, $gateway); 
  134. // Remove the old subscription 
  135. $member->drop_subscription($fromsub_id); 
  136. // Timestamp the update 
  137. update_user_meta( $user, '_membership_last_upgraded', time()); 
  138. break; 
  139.  
  140.  
  141. ?> 
  142. <div id='membership-wrapper'> 
  143. <legend><?php echo __('Your Subscriptions', 'membership'); ?></legend> 
  144. <div class="alert alert-success"> 
  145. <?php echo __('Your current subscriptions are listed here. You can renew, cancel or upgrade your subscriptions by using the forms below.', 'membership'); ?> 
  146. </div> 
  147. <div class="priceboxes"> 
  148. <?php 
  149.  
  150. $rels = $member->get_relationships(); 
  151. foreach( (array) $rels as $rel ) { 
  152.  
  153. $sub = new M_Subscription( $rel->sub_id ); 
  154.  
  155. $nextlevel = $sub->get_next_level( $rel->level_id, $rel->order_instance ); 
  156. $currentlevel = $sub->get_level_at( $rel->level_id, $rel->order_instance ); 
  157.  
  158. if( !empty( $rel->usinggateway ) && ($rel->usinggateway != 'admin') ) { 
  159. $gateway = M_get_class_for_gateway( $rel->usinggateway ); 
  160.  
  161. if( !empty( $gateway ) && $gateway->issingle ) { 
  162. $gatewayissingle = 'yes'; 
  163. } else { 
  164. $gatewayissingle = 'no'; 
  165. } else { 
  166. $gatewayissingle = 'admin'; 
  167.  
  168. ?> 
  169. <div class="pricebox subscribedbox" id='subscribedbox-<?php echo $sub->id; ?>'> 
  170. <div class="topbar"><span class='title'><?php echo $sub->sub_name(); ?></span></div> 
  171. <div class="pricedetails"><?php 
  172. if($member->is_marked_for_expire($rel->sub_id)) { 
  173. echo __('Your membership has been cancelled and will expire on : ', 'membership'); 
  174. echo date( "jS F Y", mysql2date("U", $rel->expirydate)); 
  175. } else { 
  176. if($gatewayissingle == 'yes') { 
  177. switch($currentlevel->sub_type) { 
  178. case 'serial': 
  179. case 'finite': echo __('Your membership is due to expire on : ', 'membership'); 
  180. echo "<strong>" . date( "jS F Y", mysql2date("U", $rel->expirydate)) . "</strong>"; 
  181. break; 
  182.  
  183. case 'indefinite': echo __('You are on an <strong>indefinite</strong> membership.', 'membership'); 
  184. break; 
  185.  
  186.  
  187. } elseif($gatewayissingle == 'admin') { 
  188. switch($currentlevel->sub_type) { 
  189. case 'serial': echo __('Your membership is set to <strong>automatically renew</strong>', 'membership'); 
  190. break; 
  191.  
  192. case 'finite': echo __('Your membership is due to expire on : ', 'membership'); 
  193. echo "<strong>" . date( "jS F Y", mysql2date("U", $rel->expirydate)) . "</strong>"; 
  194. break; 
  195.  
  196. case 'indefinite': echo __('You are on an <strong>indefinite</strong> membership.', 'membership'); 
  197. break; 
  198.  
  199. } else { 
  200. // Serial gateway 
  201. switch($currentlevel->sub_type) { 
  202. case 'serial': echo __('Your membership is set to <strong>automatically renew</strong>', 'membership'); 
  203. break; 
  204.  
  205. case 'finite': echo __('Your membership is due to expire on : ', 'membership'); 
  206. echo "<strong>" . date( "jS F Y", mysql2date("U", $rel->expirydate)) . "</strong>"; 
  207. break; 
  208.  
  209. case 'indefinite': echo __('You are on an <strong>indefinite</strong> membership.', 'membership'); 
  210. break; 
  211.  
  212.  
  213. // Get the last upgrade time 
  214. $upgradedat = get_user_meta( $member->ID, '_membership_last_upgraded', true); 
  215. if(empty($upgradedat)) $upgradedat = strtotime('-1 year'); 
  216. $period = $M_options['upgradeperiod']; 
  217. if(empty($period) && $period != 0) $period = 1; 
  218.  
  219. if(!$member->is_marked_for_expire($rel->sub_id)) { 
  220. switch( $gatewayissingle ) { 
  221.  
  222. case 'no': // Don't need to display a renewal for this gateway as it will automatically handle it for us 
  223. break; 
  224.  
  225. case 'yes': if(empty($M_options['renewalperiod'])) $M_options['renewalperiod'] = 7; 
  226. $renewalperiod = strtotime('-' . $M_options['renewalperiod'] . ' days', mysql2date("U", $rel->expirydate)); 
  227.  
  228. if($nextlevel && time() >= $renewalperiod ) { 
  229. // we have a next level so we can display the details and form for it 
  230. if( $member->has_active_payment( $rel->sub_id, $nextlevel->level_id, $nextlevel->level_order )) { 
  231. ?> 
  232. <legend><?php echo __('Renewal your subscription', 'membership'); ?></legend> 
  233. <div class='renew-form'> 
  234. <div class="formleft"> 
  235. <p><?php 
  236. echo __('Renewal for the ', 'membership') . "<strong>" . $nextlevel->level_period; 
  237. switch($nextlevel->level_period_unit) { 
  238. case 'd': _e(' day(s)', 'membership'); 
  239. break; 
  240. case 'w': _e(' week(s)', 'membership'); 
  241. break; 
  242. case 'm': _e(' month(s)', 'membership'); 
  243. break; 
  244. case 'y': _e(' year(s)', 'membership'); 
  245. break; 
  246. echo "</strong> " . __('following', 'membership') . " " . date( "jS F Y", mysql2date("U", $rel->expirydate)) . " "; 
  247. _e('has been completed.', 'membership'); 
  248. ?></p> 
  249. </div> 
  250. </div> <!-- renew-form --> 
  251. <?php 
  252. } else { 
  253. ?> 
  254. <div class='renew-form'> 
  255. <div class="formleft"> 
  256. <p><?php 
  257. echo __('To renew your subscription for another ', 'membership') . "<strong>" . $nextlevel->level_period; 
  258. switch($nextlevel->level_period_unit) { 
  259. case 'd': _e(' day(s)', 'membership'); 
  260. break; 
  261. case 'w': _e(' week(s)', 'membership'); 
  262. break; 
  263. case 'm': _e(' month(s)', 'membership'); 
  264. break; 
  265. case 'y': _e(' year(s)', 'membership'); 
  266. break; 
  267. echo "</strong> " . __('following', 'membership') . " " . date( "jS F Y", mysql2date("U", $rel->expirydate)) . " "; 
  268. if( $nextlevel->level_price > 0 ) { 
  269. _e('you will need to pay', 'membership'); 
  270. echo " <strong>" . $nextlevel->level_price . " " . apply_filters('membership_real_currency_display', $M_options['paymentcurrency'] ) . "</strong>"; 
  271. } else { 
  272. _e('click on the button to the right.', 'membership'); 
  273. $pricing = $sub->get_pricingarray(); 
  274. // Need to put in coupon code bit here in case they have signed up with one 
  275. $gateway->display_subscribe_button($sub, $pricing, $member->ID, $nextlevel->level_order); 
  276. ?></p> 
  277. </div> 
  278. </div> <!-- renew-form --> 
  279. <?php 
  280. break; 
  281.  
  282.  
  283. ?></div> 
  284. <div class=""><span class='price' style='float:right; margin-right: 10px;'><?php 
  285. if($gatewayissingle != 'admin' && method_exists( $gateway, 'display_cancel_button' ) && !$member->is_marked_for_expire($rel->sub_id)) { 
  286. $pricing = $sub->get_pricingarray(); 
  287. $gateway->display_cancel_button( $sub, $pricing, $member->ID ); 
  288. ?></span> 
  289. </div> 
  290. </div> <!-- price box --> 
  291. <?php 
  292. if( $upgradedat <= strtotime('-' . $period . ' days') ) { 
  293. // Show upgrades 
  294. ?> 
  295. <legend class='upgradefrom-<?php echo $sub->id; ?>'><?php echo __('Upgrade from ', 'membership') . $sub->sub_name(); ?></legend> 
  296. <?php 
  297. $upgradesubs = $this->get_subscriptions(); 
  298. $upgradesubs = apply_filters( 'membership_override_upgrade_subscriptions', $upgradesubs ); 
  299.  
  300. foreach((array) $upgradesubs as $key => $upgradesub) { 
  301. if($upgradesub->id == $rel->sub_id ) { 
  302. // Don't want to show our current subscription as we will display this above. 
  303. } else { 
  304. $subscription = new M_Subscription($upgradesub->id); 
  305. ?> 
  306. <div class="pricebox upgradebox upgradefrom-<?php echo $sub->id; ?>" id='upgradebox-<?php echo $subscription->id; ?>'> 
  307. <div class="topbar"><span class='title'><strong><?php _e('Move to : ', 'membership'); ?></strong><?php echo $subscription->sub_name(); ?></span></div> 
  308. <div class="pricedetails"> 
  309. <?php echo $subscription->sub_description(); ?> 
  310. </div> 
  311. <div class=""><span class='price' style='float:right; margin-right: 10px;'><?php 
  312. // do an upgrade button 
  313. $pricing = $subscription->get_pricingarray(); 
  314. if($pricing) { 
  315. if($currentlevel->level_price < 1) { 
  316. // We are on a free level, so need to do an upgrade from free 
  317. if($gatewayissingle != 'admin' && method_exists($gateway, 'display_upgrade_from_free_button')) { 
  318. $gateway->display_upgrade_from_free_button( $subscription, $pricing, $member->ID, $rel->sub_id, $sub->id ); 
  319.  
  320. } else { 
  321. // We want a normal upgrade button 
  322. if($gatewayissingle != 'admin' && method_exists($gateway, 'display_upgrade_button')) { 
  323. $gateway->display_upgrade_button( $subscription, $pricing, $member->ID, $rel->sub_id ); 
  324. ?></span> 
  325. </div> 
  326. </div> <!-- pricebox --> 
  327. <?php 
  328. ?> 
  329. <?php 
  330. ?> 
  331. </div> <!-- price boxes --> 
  332. </div> <!-- membership wrapper --> 
  333. <?php 
  334. ?> 
.