/plugins/product/PREPAID.php

https://github.com/axxtel/agilebill · PHP · 154 lines · 107 code · 17 blank · 30 comment · 9 complexity · eda6bf7c6004d8cabb97c797c98b422e MD5 · raw file

  1. <?php
  2. /**
  3. * AgileBill - Open Billing Software
  4. *
  5. * This body of work is free software; you can redistribute it and/or
  6. * modify it under the terms of the Open AgileBill License
  7. * License as published at http://www.agileco.com/agilebill/license1-4.txt
  8. *
  9. * For questions, help, comments, discussion, etc., please join the
  10. * Agileco community forums at http://forum.agileco.com/
  11. *
  12. * @link http://www.agileco.com/
  13. * @copyright 2004-2008 Agileco, LLC.
  14. * @license http://www.agileco.com/agilebill/license1-4.txt
  15. * @author Tony Landis <tony@agileco.com>
  16. * @package AgileBill
  17. * @version 1.4.93
  18. */
  19. require_once PATH_MODULES.'voip/base_voip_plugin.inc.php';
  20. class plgn_prov_PREPAID extends base_voip_plugin
  21. {
  22. function plgn_prov_PREPAID()
  23. {
  24. $this->name = 'PREPAID';
  25. $this->task_based = false;
  26. $this->remote_based = true;
  27. }
  28. function delete_cart($VAR, $cart)
  29. {
  30. parent::delete_cart($VAR, $cart, true);
  31. }
  32. function validate_cart($VAR, $product)
  33. {
  34. // check if prepaid type is ani or pin, if so, escape:
  35. $unserial = unserialize($product->fields['prod_plugin_data']);
  36. if(!empty($unserial['type']) && ( $unserial['type']=='ani' || $unserial['type']=='pin' ) ) return true;
  37. // verify that attr['station'] is defined and numeric
  38. @$did = $VAR['attr']['station'];
  39. $ported = 0;
  40. if (@$VAR['attr']['ported']) {
  41. $did = $VAR['attr']['ported'];
  42. $ported = 1;
  43. }
  44. if(empty($did) || !is_numeric($did))
  45. return "Sorry, the DID format specified is incorrect.";
  46. // check if user owns did && is in did pool
  47. $db =& DB();
  48. $didrs = $db->Execute(sqlSelect($db,"voip_did","id,did","did = ::{$did}:: AND account_id=".SESS_ACCOUNT));
  49. if($didrs && $didrs->RecordCount()>0) return true;
  50. return parent::validate_cart($VAR, $product, $did, $ported);
  51. }
  52. # add new service
  53. function p_new()
  54. {
  55. # todo: check that the pin is random!
  56. include_once(PATH_MODULES.'voip_prepaid/voip_prepaid.inc.php');
  57. $prepaid= new voip_prepaid;
  58. # determine the prepaid type:
  59. switch($this->product_attr['type']) {
  60. case 'did':
  61. return $prepaid->provision_did_new($this);
  62. break;
  63. case 'ani':
  64. return $prepaid->provision_ani_new($this);
  65. break;
  66. case 'pin':
  67. return $prepaid->provision_pin_new($this);
  68. break;
  69. }
  70. return false;
  71. }
  72. # edit service
  73. function p_edit()
  74. {
  75. # determine the prepaid type:
  76. switch($this->product_attr['type']) {
  77. case 'did':
  78. include_once(PATH_PLUGINS.'product/VOIP.php');
  79. $voip = new plgn_prov_VOIP;
  80. if(!$voip->p_one($this->service_id)) return false;
  81. break;
  82. }
  83. return true;
  84. }
  85. # activate service
  86. function p_inactive()
  87. {
  88. $db=&DB();
  89. $rs = $db->Execute(sqlSelect($db,"voip_did","id,did","service_id = $this->service_id"));
  90. $did_id = $rs->fields['id'];
  91. $fields=Array('in_use'=>2);
  92. $db->Execute(sqlUpdate($db,"voip_prepaid",$fields,"voip_did_id = {$did_id}"));
  93. return true;
  94. }
  95. # deactivate service
  96. function p_active()
  97. {
  98. $db=&DB();
  99. $rs = $db->Execute(sqlSelect($db,"voip_did","id,did","service_id = $this->service_id"));
  100. $did_id = $rs->fields['id'];
  101. $fields=Array('in_use'=>0);
  102. $db->Execute(sqlUpdate($db,"voip_prepaid",$fields,"voip_did_id = {$did_id}"));
  103. return true;
  104. }
  105. # delete service
  106. function p_delete()
  107. {
  108. $db =& DB();
  109. # determine the prepaid type:
  110. switch($this->product_attr['type']) {
  111. case 'ani':
  112. $sql = sqlDelete($db,"voip_prepaid","pin=::{$this->prod_attr_cart['ani_new']}::");
  113. $db->Execute($sql);
  114. break;
  115. case 'did':
  116. include_once(PATH_PLUGINS.'product/VOIP.php');
  117. $voip = new plgn_prov_VOIP;
  118. $voip->p_one($this->service_id);
  119. break;
  120. }
  121. $rs = $db->Execute($sql=sqlSelect($db,"voip_did","id,did","service_id = $this->service_id"));
  122. $did_id = $rs->fields['id'];
  123. $db->Execute($sql=sqlDelete($db,"voip_prepaid","voip_did_id = {$did_id}"));
  124. return true;
  125. }
  126. function p_one($id)
  127. {
  128. $db =& DB();
  129. # Get the asterisk global configuration
  130. $sql = sqlSelect($db, "voip", "voip_vm_passwd, voip_secret_gen", "");
  131. $rs = $db->Execute($sql);
  132. $this->voip_vm_passwd = $rs->fields['voip_vm_passwd'];
  133. $this->voip_secret_gen = $rs->fields['voip_secret_gen'];
  134. parent::p_one($id);
  135. }
  136. }
  137. ?>