PageRenderTime 64ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/voip_did/voip_did.inc.php

https://github.com/axxtel/agilebill
PHP | 264 lines | 179 code | 28 blank | 57 comment | 22 complexity | 9a714ac5be841932c8fbd1bb19b4ca92 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> and Thralling Penguin, LLC <http://www.thrallingpenguin.com>
  16. * @package AgileBill
  17. * @version 1.4.93
  18. */
  19. class voip_did
  20. {
  21. # Open the constructor for this mod
  22. function voip_did()
  23. {
  24. # name of this module:
  25. $this->module = "voip_did";
  26. # location of the construct XML file:
  27. $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
  28. # open the construct file for parsing
  29. $C_xml = new CORE_xml;
  30. $construct = $C_xml->xml_to_array($this->xml_construct);
  31. $this->method = $construct["construct"]["method"];
  32. $this->trigger = $construct["construct"]["trigger"];
  33. $this->field = $construct["construct"]["field"];
  34. $this->table = $construct["construct"]["table"];
  35. $this->module = $construct["construct"]["module"];
  36. $this->cache = $construct["construct"]["cache"];
  37. $this->order_by = $construct["construct"]["order_by"];
  38. $this->limit = $construct["construct"]["limit"];
  39. }
  40. ###########################################
  41. ### AJAX Auto-selector
  42. ###########################################
  43. function autoselect($VAR)
  44. {
  45. $db = &DB();
  46. $p = AGILE_DB_PREFIX;
  47. if (empty($VAR['did_search'])) {
  48. $where = "id > 0";
  49. $type = 1;
  50. } else {
  51. $where = "did LIKE ".$db->qstr($VAR['did_search'].'%');
  52. $type = 4;
  53. }
  54. $q = "SELECT id,did FROM {$p}voip_did WHERE
  55. ( $where )
  56. AND
  57. site_id = " .DEFAULT_SITE."
  58. ORDER BY did";
  59. $result = $db->SelectLimit($q, 10);
  60. # Create the alert for no records found
  61. echo '<ul>';
  62. # Create the alert for no records found
  63. if ($result->RecordCount() > 0) {
  64. $i=0;
  65. while(!$result->EOF)
  66. {
  67. echo '<li><div class="name"><b>' . $result->fields['did'] . '</b></div>'.
  68. '<div class="index" style="display:none">'.$result->fields['id']. '</div></li>'."\r\n";
  69. $result->MoveNext();
  70. $i++;
  71. }
  72. }
  73. echo "</ul>";
  74. }
  75. ##############################
  76. ## ADD ##
  77. ##############################
  78. function add($VAR)
  79. {
  80. $type = "add";
  81. $this->method["$type"] = explode(",", $this->method["$type"]);
  82. $db = new CORE_database;
  83. $db->add($VAR, $this, $type);
  84. }
  85. ##############################
  86. ## VIEW ##
  87. ##############################
  88. function view($VAR)
  89. {
  90. global $smarty;
  91. $type = "view";
  92. $this->method["$type"] = explode(",", $this->method["$type"]);
  93. $db = new CORE_database;
  94. $smart = $db->view($VAR, $this, $type);
  95. # echo "<pre>".print_r($smart,true)."</pre>";
  96. $db =& DB();
  97. $rs = $db->Execute(sqlSelect($db, "voip_sip", "*", "sip=::".$smart[0]['did']."::"));
  98. while (!$rs->EOF) {
  99. $smarty->assign('sip_'.$rs->fields['keyword'],$rs->fields['data']);
  100. $rs->MoveNext();
  101. }
  102. $sip_canreinvite_options['yes'] = 'Yes';
  103. $sip_canreinvite_options['no'] = 'No';
  104. $sip_canreinvite_options['update'] = 'Update';
  105. $smarty->assign('sip_canreinvite_options', $sip_canreinvite_options);
  106. $sip_dtmfmode_options['info'] = 'Info';
  107. $sip_dtmfmode_options['rfc2833'] = 'RFC 2833';
  108. $sip_dtmfmode_options['inband'] = 'In-band Audio';
  109. $smarty->assign('sip_dtmfmode_options', $sip_dtmfmode_options);
  110. $sip_nat_options['yes'] = 'Yes';
  111. $sip_nat_options['no'] = 'No';
  112. $sip_nat_options['always'] = 'Always';
  113. $smarty->assign('sip_nat_options', $sip_nat_options);
  114. }
  115. ##############################
  116. ## UPDATE ##
  117. ##############################
  118. function update($VAR)
  119. {
  120. $type = "update";
  121. $this->method["$type"] = explode(",", $this->method["$type"]);
  122. $db = new CORE_database;
  123. $db->update($VAR, $this, $type);
  124. # update the voip_sip table fields
  125. $db =& DB();
  126. $rs = $db->Execute(sqlSelect($db, "voip_did", "did", "id=::".$VAR['id']."::"));
  127. #echo "<pre>".print_r($VAR,true)."</pre>";
  128. $f[0]['username'] = $VAR['sip_username'];
  129. $f[1]['secret'] = $VAR['sip_secret'];
  130. $f[2]['qualify'] = $VAR['sip_qualify'];
  131. $f[3]['mailbox'] = $VAR['sip_mailbox'];
  132. $f[4]['incominglimit'] = $VAR['sip_incominglimit'];
  133. $f[5]['dtmfmode'] = $VAR['sip_dtmfmode'];
  134. $f[6]['canreinvite'] = $VAR['sip_canreinvite'];
  135. $f[7]['callerid'] = $VAR['sip_callerid'];
  136. $f[8]['nat'] = $VAR['sip_nat'];
  137. for ($i = 0; $i < 9; $i++) {
  138. #echo "<pre>".print_r($f[$i],true)."</pre>";
  139. $k = key($f[$i]);
  140. $v = $f[$i][$k];
  141. if (empty($v)) {
  142. $sql = "DELETE FROM ".AGILE_DB_PREFIX."voip_sip WHERE sip=".$db->qstr($rs->fields['did'])." and keyword=".$db->qstr($k)." and site_id=".DEFAULT_SITE;
  143. } else {
  144. $rs2 = $db->Execute(sqlSelect($db, "voip_sip", "id", "sip=::".$rs->fields['did'].":: AND keyword=::".$k."::"));
  145. if ($rs2 && $rs2->fields[0] > 0) {
  146. $sql = "UPDATE ".AGILE_DB_PREFIX."voip_sip SET data=".$db->qstr($v)." WHERE sip=".$db->qstr($rs->fields['did'])." and keyword=".$db->qstr($k)." and site_id=".DEFAULT_SITE;
  147. } else {
  148. $flds['data'] = $v;
  149. $flds['keyword'] = $k;
  150. $flds['sip'] = $rs->fields['did'];
  151. $sql = sqlInsert($db, "voip_sip", $flds);
  152. # $sql = "INSERT INTO ".AGILE_DB_PREFIX."voip_sip SET data=".$db->qstr($v)." WHERE sip=".$db->qstr($rs->fields['did'])." and keyword=".$db->qstr($k)." and site_id=".DEFAULT_SITE;
  153. }
  154. }
  155. if (!$db->Execute($sql)) {
  156. echo $db->ErrorMsg();
  157. }
  158. }
  159. }
  160. ##############################
  161. ## DELETE ##
  162. ##############################
  163. function delete($VAR)
  164. {
  165. $db = new CORE_database;
  166. $db->mass_delete($VAR, $this, "");
  167. }
  168. ##############################
  169. ## SEARCH FORM ##
  170. ##############################
  171. function search_form($VAR)
  172. {
  173. $type = "search";
  174. $this->method["$type"] = explode(",", $this->method["$type"]);
  175. $db = new CORE_database;
  176. $db->search_form($VAR, $this, $type);
  177. }
  178. ##############################
  179. ## SEARCH ##
  180. ##############################
  181. function search($VAR)
  182. {
  183. $type = "search";
  184. $this->method["$type"] = explode(",", $this->method["$type"]);
  185. $db = new CORE_database;
  186. $db->search($VAR, $this, $type);
  187. }
  188. ##############################
  189. ## SEARCH SHOW ##
  190. ##############################
  191. function search_show($VAR)
  192. {
  193. $type = "search";
  194. $this->method["$type"] = explode(",", $this->method["$type"]);
  195. $db = new CORE_database;
  196. $db->search_show($VAR, $this, $type);
  197. }
  198. ##############################
  199. ## SEARCH EXPORT ##
  200. ##############################
  201. function search_export($VAR)
  202. {
  203. # require the export class
  204. require_once (PATH_CORE . "export.inc.php");
  205. # Call the correct export function for inline browser display, download, email, or web save.
  206. if($VAR["format"] == "excel")
  207. {
  208. $type = "export_excel";
  209. $this->method["$type"] = explode(",", $this->method["$type"]);
  210. $export = new CORE_export;
  211. $export->search_excel($VAR, $this, $type);
  212. }
  213. else if ($VAR["format"] == "xml")
  214. {
  215. $type = "export_xml";
  216. $this->method["$type"] = explode(",", $this->method["$type"]);
  217. $export = new CORE_export;
  218. $export->search_xml($VAR, $this, $type);
  219. }
  220. else if ($VAR["format"] == "csv")
  221. {
  222. $type = "export_csv";
  223. $this->method["$type"] = explode(",", $this->method["$type"]);
  224. $export = new CORE_export;
  225. $export->search_csv($VAR, $this, $type);
  226. }
  227. else if ($VAR["format"] == "tab")
  228. {
  229. $type = "export_tab";
  230. $this->method["$type"] = explode(",", $this->method["$type"]);
  231. $export = new CORE_export;
  232. $export->search_tab($VAR, $this, $type);
  233. }
  234. }
  235. }
  236. ?>