/app/view/member/class-ms-view-member-dialog.php

  1. <?php 
  2.  
  3. /** 
  4. * Dialog: Member Profile 
  5. * 
  6. * Extends MS_View for rendering methods and magic methods. 
  7. * 
  8. * @since 1.0.0 
  9. * @package Membership2 
  10. * @subpackage View 
  11. */ 
  12. class MS_View_Member_Dialog extends MS_Dialog { 
  13.  
  14. const ACTION_SAVE = 'ms_save_member'; 
  15.  
  16. /** 
  17. * Generate/Prepare the dialog attributes. 
  18. * 
  19. * @since 1.0.0 
  20. */ 
  21. public function prepare() { 
  22. $member_id = $_POST['member_id']; 
  23. $member = MS_Factory::load( 'MS_Model_Member', $member_id ); 
  24.  
  25. $data = array( 
  26. 'model' => $member,  
  27. ); 
  28.  
  29. $data = apply_filters( 'ms_view_member_dialog_data', $data ); 
  30.  
  31. // Dialog Title 
  32. $this->title = sprintf( 
  33. __( 'Profile: %1$s %2$s', 'membership2' ),  
  34. esc_html( $member->first_name ),  
  35. esc_html( $member->last_name ) 
  36. ); 
  37.  
  38. // Dialog Size 
  39. $this->width = 940; 
  40. $this->height = 500; 
  41.  
  42. // Contents 
  43. $this->content = $this->get_contents( $data ); 
  44.  
  45. // Make the dialog modal 
  46. $this->modal = true; 
  47.  
  48. /** 
  49. * Save the gateway details. 
  50. * 
  51. * @since 1.0.0 
  52. * @return string 
  53. */ 
  54. public function submit() { 
  55. $data = $_POST; 
  56. $res = MS_Helper_Member::MEMBER_MSG_NOT_UPDATED; 
  57.  
  58. unset( $data['action'] ); 
  59. unset( $data['dialog'] ); 
  60.  
  61. // Update the memberships 
  62. if ( isset( $_POST['dialog_action'] ) 
  63. && $this->verify_nonce( $_POST['dialog_action'] ) 
  64. && isset( $_POST['member_id'] ) 
  65. ) { 
  66. // No input fields, so we cannot save anything... 
  67. $res = MS_Helper_Member::MEMBER_MSG_UPDATED; 
  68.  
  69. return $res; 
  70.  
  71. /** 
  72. * Returns the contens of the dialog 
  73. * 
  74. * @since 1.0.0 
  75. * 
  76. * @return object 
  77. */ 
  78. public function get_contents( $data ) { 
  79. $member = $data['model']; 
  80.  
  81. $currency = MS_Plugin::instance()->settings->currency; 
  82. $show_trial = MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_TRIAL ); 
  83.  
  84. $all_subscriptions = MS_Model_Relationship::get_subscriptions( 
  85. array( 
  86. 'user_id' => $member->id,  
  87. 'status' => 'all',  
  88. 'meta_key' => 'expire_date',  
  89. 'orderby' => 'meta_value',  
  90. 'order' => 'DESC',  
  91. ); 
  92.  
  93. // Prepare the form fields. 
  94. $inp_dialog = array( 
  95. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  96. 'name' => 'dialog',  
  97. 'value' => 'View_Member_Dialog',  
  98. ); 
  99.  
  100. $inp_id = array( 
  101. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  102. 'name' => 'member_id',  
  103. 'value' => $member->id,  
  104. ); 
  105.  
  106. $inp_nonce = array( 
  107. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  108. 'name' => '_wpnonce',  
  109. 'value' => wp_create_nonce( self::ACTION_SAVE ),  
  110. ); 
  111.  
  112. $inp_action = array( 
  113. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  114. 'name' => 'dialog_action',  
  115. 'value' => self::ACTION_SAVE,  
  116. ); 
  117.  
  118. $inp_save = array( 
  119. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  120. 'value' => __( 'Save', 'membership2' ),  
  121. 'class' => 'ms-submit-form',  
  122. 'data' => array( 
  123. 'form' => 'ms-edit-member',  
  124. ); 
  125.  
  126. $inp_cancel = array( 
  127. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  128. 'value' => __( 'Close', 'membership2' ),  
  129. 'class' => 'close',  
  130. ); 
  131.  
  132. ob_start(); 
  133. ?> 
  134. <div> 
  135. <form class="ms-form wpmui-ajax-update ms-edit-member" data-wpmui-ajax="<?php echo esc_attr( 'save' ); ?>"> 
  136. <div class="ms-form wpmui-form wpmui-grid-8"> 
  137. <table class="widefat"> 
  138. <thead> 
  139. <tr> 
  140. <th class="column-membership"> 
  141. <?php _e( 'Membership', 'membership2' ); ?> 
  142. </th> 
  143. <th class="column-status"> 
  144. <?php _e( 'Status', 'membership2' ); ?> 
  145. </th> 
  146. <th class="column-start"> 
  147. <?php _e( 'Subscribed on', 'membership2' ); ?> 
  148. </th> 
  149. <th class="column-expire"> 
  150. <?php _e( 'Expires on', 'membership2' ); ?> 
  151. </th> 
  152. <?php if ( $show_trial ) : ?> 
  153. <th class="column-trialexpire"> 
  154. <?php _e( 'Trial until', 'membership2' ); ?> 
  155. </th> 
  156. <?php endif; ?> 
  157. <th class="column-payments"> 
  158. <?php _e( 'Payments', 'membership2' ); ?> 
  159. </th> 
  160. </tr> 
  161. </thead> 
  162. <tbody> 
  163. <?php 
  164. foreach ( $all_subscriptions as $subscription ) : 
  165. $membership = $subscription->get_membership(); 
  166. $payments = $subscription->get_payments(); 
  167.  
  168. $num_payments = count( $payments ); 
  169. $amount_payments = 0; 
  170. foreach ( $payments as $payment ) { 
  171. $amount_payments += $payment['amount']; 
  172.  
  173. $subscription_info = array( 
  174. 'subscription_id' => $subscription->id,  
  175. ); 
  176. $update_info = array( 
  177. 'subscription_id' => $subscription->id,  
  178. 'statuscheck' => 'yes',  
  179. ); 
  180. ?> 
  181. <tr> 
  182. <td class="column-membership"> 
  183. <?php $membership->name_tag(); ?> 
  184. </td> 
  185. <td class="column-status"> 
  186. <?php 
  187. printf( 
  188. '<a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%2$s">%1$s</a> 
  189. <a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%3$s" title="%5$s">%4$s</a>',  
  190. $subscription->status,  
  191. esc_attr( json_encode( $subscription_info ) ),  
  192. esc_attr( json_encode( $update_info ) ),  
  193. '<i class="dashicons dashicons-update"></i>',  
  194. __( 'Check and update subscription status', 'membership2' ) 
  195. ); 
  196. ?> 
  197. </td> 
  198. <td class="column-start"> 
  199. <?php echo $subscription->start_date; ?> 
  200. </td> 
  201. <td class="column-expire"> 
  202. <?php echo $subscription->expire_date; ?> 
  203. </td> 
  204. <?php if ( $show_trial ) : ?> 
  205. <td class="column-trialexpire"> 
  206. <?php 
  207. if ( $subscription->start_date == $subscription->trial_expire_date ) { 
  208. echo '-'; 
  209. } else { 
  210. echo $subscription->trial_expire_date; 
  211. ?> 
  212. </td> 
  213. <?php endif; ?> 
  214. <td class="column-payments"> 
  215. <?php 
  216. $total = sprintf( 
  217. '<b>%1$s</b> (%3$s %2$s)',  
  218. $num_payments,  
  219. MS_Helper_Billing::format_price( $amount_payments ),  
  220. $currency 
  221. ); 
  222.  
  223. printf( 
  224. '<a href="#" data-ms-dialog="View_Member_Payment" data-ms-data="%1$s">%2$s</a>',  
  225. esc_attr( json_encode( $subscription_info ) ),  
  226. $total 
  227. ); 
  228. ?> 
  229. </td> 
  230. </tr> 
  231. <?php endforeach; ?> 
  232. </tbody> 
  233. </table> 
  234. </div> 
  235. <?php 
  236. MS_Helper_Html::html_element( $inp_id ); 
  237. MS_Helper_Html::html_element( $inp_dialog ); 
  238. MS_Helper_Html::html_element( $inp_nonce ); 
  239. MS_Helper_Html::html_element( $inp_action ); 
  240. ?> 
  241. </form> 
  242. <div class="buttons"> 
  243. <?php 
  244. MS_Helper_Html::html_element( $inp_cancel ); 
  245. // MS_Helper_Html::html_element( $inp_save ); 
  246. ?> 
  247. </div> 
  248. </div> 
  249. <?php 
  250. $html = ob_get_clean(); 
  251. return apply_filters( 'ms_view_member_dialog_to_html', $html ); 
  252.  
  253. }; 
.