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

/includes/pages/admin/subscriptions.php

https://github.com/AndyRixon/LayerBulletin
PHP | 246 lines | 227 code | 8 blank | 11 comment | 14 complexity | 0b30e8f0c10496edbc955b891c94554c MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------------
  4. | LayerBulletin
  5. | ========================================
  6. | By The LayerBulletin team
  7. | Released under the Artistic License 2.0
  8. | http://layerbulletin.com/
  9. | ========================================
  10. |+--------------------------------------------------------------------------
  11. | subscriptions.php - create/edit/delete Paypal subscriptions
  12. */
  13. if (!defined('LB_RUN'))
  14. {
  15. exit('<h1>ACCESS DENIED</h1>You cannot access this file directly.');
  16. }
  17. template_hook("pages/admin/subscriptions.template.php", "start");
  18. if($_GET['success']=="created"){
  19. template_hook("pages/admin/subscriptions.template.php", "successCreated");
  20. }elseif($_GET['success']=="updated"){
  21. template_hook("pages/admin/subscriptions.template.php", "successUpdated");
  22. }elseif($_GET['success']=="deleted"){
  23. template_hook("pages/admin/subscriptions.template.php", "successDeleted");
  24. }
  25. if ($can_change_site_settings == 0)
  26. {
  27. lb_redirect("index.php?page=error&error=11","error/11");
  28. }
  29. if ($_POST['subscription_name'] != '' && $_GET['func'] == 'edit')
  30. {
  31. $upgrade_id = escape_string($_POST['upgrade_id']);
  32. $token_id = $_POST['token_id'];
  33. $token_id = escape_string($token_id);
  34. $token_name = "token_subscriptions_$upgrade_id$token_id";
  35. if (isset($_POST[$token_name]) && isset($_SESSION[$token_name]) && $_SESSION[$token_name] == $_POST[$token_name])
  36. {
  37. $subscription_name = escape_string($_POST['subscription_name']);
  38. $subscription_features = escape_string($_POST['subscription_features']);
  39. $upgrade_from = (int) $_POST['upgrade_from'];
  40. $upgrade_to = (int)$_POST['upgrade_to'];
  41. $cost = escape_string($_POST['cost']);
  42. $currency = escape_string($_POST['currency']);
  43. $frequency_one = (int) $_POST['frequency_one'];
  44. $frequency_two = escape_string($_POST['frequency_two']);
  45. $paypal_email = escape_string($_POST['paypal_email']);
  46. $upgrade_id = (int) $_POST['upgrade_id'];
  47. if ($_POST['frequency_two'] != 'Once')
  48. {
  49. mysql_query("UPDATE {$db_prefix}group_upgrade SET upgrade_name='$subscription_name', upgrade_features='$subscription_features', upgrade_from='$upgrade_from', upgrade_to='$upgrade_to', upgrade_cost='$cost', upgrade_currency='$currency', upgrade_period='$frequency_one', upgrade_period_two='$frequency_two', paypal_email='$paypal_email' WHERE upgrade_id='$upgrade_id'");
  50. }
  51. else
  52. {
  53. mysql_query("UPDATE {$db_prefix}group_upgrade SET upgrade_name='$subscription_name', upgrade_features='$subscription_features', upgrade_from='$upgrade_from', upgrade_to='$pgrade_to, upgrade_cost='$cost', upgrade_currency='$currency', upgrade_period='0', upgrade_period_two='Once', paypal_email='$paypal_email' WHERE upgrade_id='$upgrade_id'");
  54. }
  55. template_hook("pages/admin/subscriptions.template.php", "form_1");
  56. lb_redirect("index.php?page=admin&act=subscriptions&success=updated","admin/subscriptions/success/updated");
  57. }
  58. else
  59. {
  60. lb_redirect("index.php?page=error&error=28","error/28");
  61. }
  62. }
  63. elseif ($_POST['subscription_name'] != '')
  64. {
  65. $token_id = $_POST['token_id'];
  66. $token_id = escape_string($token_id);
  67. $token_name = "token_subscriptions_new_$token_id";
  68. if (isset($_POST[$token_name]) && isset($_SESSION[$token_name]) && $_SESSION[$token_name] == $_POST[$token_name])
  69. {
  70. $subscription_name = escape_string($_POST['subscription_name']);
  71. $subscription_features = escape_string($_POST['subscription_features']);
  72. $upgrade_from = (int) $_POST['upgrade_from'];
  73. $upgrade_to = (int)$_POST['upgrade_to'];
  74. $cost = escape_string($_POST['cost']);
  75. $currency = escape_string($_POST['currency']);
  76. $frequency_one = (int) $_POST['frequency_one'];
  77. $frequency_two = escape_string($_POST['frequency_two']);
  78. $paypal_email = escape_string($_POST['paypal_email']);
  79. $upgrade_id = (int) $_POST['upgrade_id'];
  80. if ($_POST['frequency_two'] != 'Once')
  81. {
  82. mysql_query("INSERT INTO {$db_prefix}group_upgrade (upgrade_name, upgrade_features, upgrade_from, upgrade_to, upgrade_cost, upgrade_currency, upgrade_period, upgrade_period_two, paypal_email) VALUES ('$subscription_name', '$subscription_features','$upgrade_from', '$upgrade_to', '$cost', '$currency', '$frequency_one', '$frequency_two', '$paypal_email')");
  83. }
  84. else
  85. {
  86. mysql_query("INSERT INTO {$db_prefix}group_upgrade (upgrade_name, upgrade_features, upgrade_from, upgrade_to, upgrade_cost, upgrade_currency, upgrade_period, upgrade_period_two, paypal_email) VALUES ('$subscription_name', '$subscription_features','$upgrade_from', '$upgrade_to', '$cost', '$currency', '0', 'Once', '$paypal_email')");
  87. }
  88. template_hook("pages/admin/subscriptions.template.php", "form_2");
  89. lb_redirect("index.php?page=admin&act=subscriptions&success=created","admin/subscriptions/success/created");
  90. }
  91. else
  92. {
  93. lb_redirect("index.php?page=error&error=28","error/28");
  94. }
  95. }
  96. elseif ($_GET['func']=='new')
  97. {
  98. $token_id = md5(microtime());
  99. $token = md5(uniqid(rand(),true));
  100. $token_name = "token_subscriptions_new_$token_id";
  101. $_SESSION[$token_name] = $token;
  102. template_hook("pages/admin/subscriptions.template.php", "3");
  103. $query2 = "select GROUP_ID, GROUP_NAME from {$db_prefix}groups ORDER BY GROUP_NAME desc" ;
  104. $result2 = mysql_query($query2) or die("upgrade.php - Error in query: $query2") ;
  105. while ($results2 = mysql_fetch_array($result2))
  106. {
  107. $group_id = $results2['GROUP_ID'];
  108. $group_name = strip_slashes($results2['GROUP_NAME']);
  109. template_hook("pages/admin/subscriptions.template.php", "4");
  110. }
  111. template_hook("pages/admin/subscriptions.template.php", "5");
  112. $query2 = "select GROUP_ID, GROUP_NAME from {$db_prefix}groups ORDER BY GROUP_NAME desc" ;
  113. $result2 = mysql_query($query2) or die("upgrade.php - Error in query: $query2") ;
  114. while ($results2 = mysql_fetch_array($result2))
  115. {
  116. $group_id = $results2['GROUP_ID'];
  117. $group_name = strip_slashes($results2['GROUP_NAME']);
  118. template_hook("pages/admin/subscriptions.template.php", "4");
  119. }
  120. template_hook("pages/admin/subscriptions.template.php", "6");
  121. }
  122. elseif($_POST['subscriptions_delete'] == 1)
  123. {
  124. $id = (int) $_POST['subscription_id'];
  125. if (tokenCheck('subscriptions_delete', $id))
  126. {
  127. mysql_query("DELETE FROM {$db_prefix}group_upgrade WHERE upgrade_id ='$id'");
  128. template_hook("pages/admin/subscriptions.template.php", "form_3");
  129. lb_redirect("index.php?page=admin&act=subscriptions&success=deleted","admin/subscriptions/success/deleted");
  130. }
  131. else
  132. {
  133. lb_redirect('index.php?page=error&error=28', 'error/28');
  134. }
  135. }
  136. elseif($_GET['func']=='edit')
  137. {
  138. $token_id = md5(microtime());
  139. $token = md5(uniqid(rand(),true));
  140. $upgrade_id = escape_string($_GET['id']);
  141. $token_name = "token_subscriptions_$upgrade_id$token_id";
  142. $_SESSION[$token_name] = $token;
  143. $query29 = "select UPGRADE_ID, UPGRADE_NAME, UPGRADE_FEATURES, UPGRADE_FROM, UPGRADE_TO, UPGRADE_COST, UPGRADE_CURRENCY, UPGRADE_PERIOD, UPGRADE_PERIOD_TWO, PAYPAL_EMAIL from {$db_prefix}group_upgrade WHERE UPGRADE_ID='$upgrade_id'" ;
  144. $result29 = mysql_query($query29) or die("upgrade.php - Error in query: $query29") ;
  145. while ($results29 = mysql_fetch_array($result29))
  146. {
  147. $upgrade_id = strip_slashes($results29['UPGRADE_ID']);
  148. $upgrade_name = strip_slashes($results29['UPGRADE_NAME']);
  149. $upgrade_features = strip_slashes($results29['UPGRADE_FEATURES']);
  150. $upgrade_from = strip_slashes($results29['UPGRADE_FROM']);
  151. $upgrade_to = strip_slashes($results29['UPGRADE_TO']);
  152. $upgrade_cost = strip_slashes($results29['UPGRADE_COST']);
  153. $upgrade_currency = strip_slashes($results29['UPGRADE_CURRENCY']);
  154. $upgrade_period = strip_slashes($results29['UPGRADE_PERIOD']);
  155. $upgrade_period_two = strip_slashes($results29['UPGRADE_PERIOD_TWO']);
  156. $paypal_email = strip_slashes($results29['PAYPAL_EMAIL']);
  157. template_hook("pages/admin/subscriptions.template.php", "8");
  158. $query2 = "select GROUP_ID, GROUP_NAME from {$db_prefix}groups ORDER BY GROUP_NAME asc" ;
  159. $result2 = mysql_query($query2) or die("upgrade.php - Error in query: $query2") ;
  160. while ($results2 = mysql_fetch_array($result2))
  161. {
  162. $group_id = $results2['GROUP_ID'];
  163. $group_name = strip_slashes($results2['GROUP_NAME']);
  164. template_hook("pages/admin/subscriptions.template.php", "9");
  165. }
  166. template_hook("pages/admin/subscriptions.template.php", "10");
  167. $query2 = "select GROUP_ID, GROUP_NAME from {$db_prefix}groups ORDER BY GROUP_NAME asc" ;
  168. $result2 = mysql_query($query2) or die("upgrade.php - Error in query: $query2") ;
  169. while ($results2 = mysql_fetch_array($result2))
  170. {
  171. $group_id = $results2['GROUP_ID'];
  172. $group_name = strip_slashes($results2['GROUP_NAME']);
  173. template_hook("pages/admin/subscriptions.template.php", "11");
  174. }
  175. template_hook("pages/admin/subscriptions.template.php", "12");
  176. }
  177. }
  178. else
  179. {
  180. template_hook("pages/admin/subscriptions.template.php", "13");
  181. $query2 = "select UPGRADE_ID, UPGRADE_NAME, UPGRADE_FEATURES, UPGRADE_FROM, UPGRADE_TO, UPGRADE_COST, UPGRADE_CURRENCY, UPGRADE_PERIOD, UPGRADE_PERIOD_TWO, PAYPAL_EMAIL from {$db_prefix}group_upgrade ORDER BY UPGRADE_ID desc" ;
  182. $result2 = mysql_query($query2) or die("upgrade.php - Error in query: $query2") ;
  183. while ($results2 = mysql_fetch_array($result2))
  184. {
  185. $upgrade_id = strip_slashes($results2['UPGRADE_ID']);
  186. $upgrade_name = strip_slashes($results2['UPGRADE_NAME']);
  187. $upgrade_features = strip_slashes($results2['UPGRADE_FEATURES']);
  188. $upgrade_from = strip_slashes($results2['UPGRADE_FROM']);
  189. $upgrade_to = strip_slashes($results2['UPGRADE_TO']);
  190. $upgrade_cost = strip_slashes($results2['UPGRADE_COST']);
  191. $upgrade_currency = strip_slashes($results2['UPGRADE_CURRENCY']);
  192. $upgrade_period = strip_slashes($results2['UPGRADE_PERIOD']);
  193. $upgrade_period_two = strip_slashes($results2['UPGRADE_PERIOD_TWO']);
  194. $paypal_email = strip_slashes($results2['PAYPAL_EMAIL']);
  195. list($token_id, $token, $token_name) = tokenCreate('subscriptions_delete', $upgrade_id);
  196. template_hook("pages/admin/subscriptions.template.php", "14");
  197. }
  198. template_hook("pages/admin/subscriptions.template.php", "15");
  199. }
  200. template_hook("pages/admin/subscriptions.template.php", "end");
  201. ?>