PageRenderTime 49ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/wiki-plugins/wikiplugin_registermemberpayment.php

https://gitlab.com/ElvisAns/tiki
PHP | 207 lines | 173 code | 26 blank | 8 comment | 27 complexity | 8e09b212bf906e70a6e344330eaf8b35 MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. function wikiplugin_registermemberpayment_info()
  8. {
  9. require_once('lib/wiki-plugins/wikiplugin_memberpayment.php');
  10. $infoFromParent = wikiplugin_memberpayment_info();
  11. return [
  12. 'name' => tra('Register Member Payment'),
  13. 'documentation' => 'PluginRegisterMemberPayment',
  14. 'validate' => 'all',
  15. 'description' => tra('Register and make a member payment at the same time'),
  16. 'prefs' => [ 'wikiplugin_registermemberpayment', 'payment_feature' ],
  17. 'body' => tra('NA'),
  18. 'iconname' => 'money',
  19. 'introduced' => 9.1,
  20. 'params' => array_merge(
  21. $infoFromParent['params'],
  22. [
  23. 'fixedperiods' => [
  24. 'required' => false,
  25. 'name' => tra('Fixed Periods'),
  26. 'description' => tra('Give specific periods that can be chosen with a dropdown list.
  27. Example:') . " <code>name:value;name:value;value;value;</code>",
  28. 'since' => '9.1',
  29. 'filter' => 'text',
  30. 'default' => 'Number of periods:',
  31. ],
  32. ]
  33. )
  34. ];
  35. }
  36. function wikiplugin_registermemberpayment($data, $params, $offset)
  37. {
  38. global $user, $tiki_p_payment_view;
  39. $headerlib = TikiLib::lib('header');
  40. $smarty = TikiLib::lib('smarty');
  41. static $i;
  42. $i++;
  43. if ($tiki_p_payment_view != 'y') {
  44. return tr('Insufficient Privileges');
  45. }
  46. if (empty($user) && isset($_REQUEST['wp_member_users']) == true) {
  47. $user = end(explode('|', $_REQUEST['wp_member_users']));
  48. $_SESSION['forceanon'] = 'y';
  49. $_REQUEST['price'] = $_POST['price'] = $_GET['price'] = $params['price'];
  50. }
  51. $periodslabel = (isset($params['periodslabel']) ? tr($params['periodslabel']) : 'Number of periods:');
  52. $fixedperiodsDDL = '';
  53. $fixedperiods = explode(';', isset($params['fixedperiods']) ? $params['fixedperiods'] : '');
  54. foreach ($fixedperiods as $fixedperiod) {
  55. if (! empty($fixedperiod)) {
  56. $fixedperiod = explode(':', $fixedperiod);
  57. $name = $fixedperiod[0];
  58. $value = (! empty($fixedperiod[1]) ? $fixedperiod[1] : $fixedperiod[0]);
  59. $fixedperiodsDDL .= '<option value="' . trim($value) . '">' . trim($name) . '</option>';
  60. }
  61. }
  62. if (empty($fixedperiodsDDL)) {
  63. $periods = '<input id="memberDuration' . $i . '" name="duration" value="1" />';
  64. } else {
  65. $periods = '<select id="memberDuration' . $i . '" name="duration">' . $fixedperiodsDDL . '</select>';
  66. }
  67. //force current user to not be used
  68. $params['currentuser'] = 'n';
  69. $memberPayment = TikiLib::lib('parser')->parse_data(wikiplugin_memberpayment($data, $params, $offset), ['is_html' => true]);
  70. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  71. if (isset($_POST['msg'])) {
  72. $_POST['msg'] = addslashes(htmlspecialchars($_POST['msg']));
  73. $headerlib->add_jq_onready("$.notify('" . $_POST['msg'] . "')");
  74. }
  75. if (empty($user)) {
  76. include_once('lib/smarty_tiki/function.user_registration.php');
  77. $register = smarty_function_user_registration([], $smarty->getEmptyInternalTemplate());
  78. } else {
  79. $register = "<table>
  80. <tr class='registerSubmitTr'>
  81. <td colspan='2'>
  82. <input type='hidden' id='name' value='$user' />
  83. <input type='submit' value='" . tr('Submit') . "' class='registerSubmit'/>
  84. </td>
  85. </tr>
  86. </table>";
  87. }
  88. }
  89. $group = $params['group'];
  90. $headerlib->add_jq_onready(<<<JS
  91. var reg = $('#memberRegister$i'),
  92. pay = $('#memberPayment$i'),
  93. user = "$user";
  94. pay.find('.warning').insertAfter(pay); //just in case there are any warnings
  95. var submitBtn = reg.find('input.registerSubmit'),
  96. //both with and without trackers
  97. submitBtnTr = reg.find('tr.registerSubmitTr,div.input_submit_container'),
  98. trackerForm = $('table.wikiplugin_tracker').parent('form');
  99. if (!user) {
  100. $('<tr class="grpMmbChk">\
  101. <td>$group Membership:</td>\
  102. <td>\
  103. <input type="checkbox" id="memberType$i" />\
  104. </td>\
  105. </tr>').insertBefore(submitBtnTr);
  106. } else {
  107. $('<tr>\
  108. <td><b>$group Membership</b></td>\
  109. </tr>').insertBefore(submitBtnTr);
  110. }
  111. $('<tr style="display: none;">\
  112. <td>$periodslabel</td>\
  113. <td>$periods</td>\
  114. </tr>')
  115. .insertBefore(submitBtnTr);
  116. $('#memberType$i')
  117. .click(function() {
  118. $('tr.grpMmbChk').next()
  119. .stop()
  120. .fadeToggle();
  121. })
  122. .click();
  123. reg
  124. .bind('continueToPurchase', function() {
  125. pay.find('input[name="wp_member_users"]').val($('#memberRegister$i #name').val());
  126. pay.find('input[name="wp_member_periods"]').val($('#memberDuration$i').val());
  127. pay.find('input:last').click();
  128. })
  129. .find('input:last').click(function() {
  130. var frmData = reg.find('form').serialize(),
  131. invokeRegistration = function() {
  132. if (frmData) {
  133. $.getJSON($.service('user', 'register') + '&' + frmData + '&noTemplate', function(data) {
  134. if (typeof data.result == "string") {
  135. if ($('#memberType$i').is(':checked')) {
  136. $('<input name="msg" />')
  137. .val(data.result)
  138. .prependTo(pay.find('form'));
  139. reg.trigger('continueToPurchase');
  140. } else { //registered
  141. $.notify(data.result);
  142. $.notify(tr('You will be redirected in 5 seconds'));
  143. setTimeout(function() {
  144. document.location = 'tiki-index.php';
  145. }, 5000);
  146. }
  147. } else { //errors
  148. $.each(data.result, function(i) {
  149. $.notify(data.result[i].msg);
  150. });
  151. }
  152. });
  153. } else {
  154. reg.trigger('continueToPurchase');
  155. }
  156. };
  157. //this is from a tracker, lets go ahead and submit the tracker data, then we will submit the other
  158. if (trackerForm.length > 0) {
  159. $.post(trackerForm.attr('action'), trackerForm.serialize(), function(data) {
  160. console.log(data);
  161. invokeRegistration();
  162. });
  163. } else {
  164. invokeRegistration();
  165. }
  166. return false;
  167. });
  168. JS
  169. );
  170. $paymentStyle = '';
  171. $registerStyle = '';
  172. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  173. $registerStyle = 'display: none;';
  174. } else {
  175. $paymentStyle = 'display: none;';
  176. }
  177. return "~np~
  178. <div id='memberPayment$i' style='$paymentStyle'>$memberPayment</div>
  179. <div id='memberRegister$i' style='$registerStyle'>$register</div>
  180. ~/np~";
  181. }