display_ratecard.php
上传用户:nathan
上传日期:2014-06-05
资源大小:5900k
文件大小:14k
源码类别:

网络

开发平台:

Unix_Linux

  1. <?php
  2. /*
  3. this ligne is an exemple of wath you must add into the main page to desplay the ratecard
  4. include ("http://localhost/A2Billing_UI/api/display_ratecard.php?key=0951aa29a67836b860b0865bc495225c&page_url=localhost/index.php&field_to_display=t1.destination,t1.dialprefix,t1.rateinitial&column_name=Destination,Prefix,Rate/Min&field_type=,,money&".$_SERVER['QUERY_STRING']);
  5. to change display set css_url in the include ligne
  6.  you can change parameters in /Css/api_ratecard.css 
  7. */
  8. include ("../lib/defines.php");
  9. include ("../lib/module.access.php");
  10.   // The wrapper variables for security
  11.   $security_key = API_SECURITY_KEY;
  12. // The name of the log file
  13. $logfile = API_LOGFILE;
  14. // recipient email to send the alarm
  15. $email_alarm = EMAIL_ADMIN;
  16. $FG_DEBUG = 0;
  17. getpost_ifset(array('key', 'tariffgroupid', 'ratecardid', 'css_url', 'nb_display_lines', 'filter' ,'field_to_display', 'column_name', 'field_type', 'browse_letter', 'prefix_select', 'page_url', 'resulttitle', 'posted', 'stitle', 'current_page', 'order', 'sens', 'choose_currency', 'choose_country', 'letter', 'searchpre', 'currency_select', 'merge_form', 'fullhtmlpage'));
  18. /**variable to set rate display option
  19. ?key 
  20. &ratecardid  "dispaly only this ratecard
  21. &css_url
  22. &nb_display_lines (maximum lignes per page)
  23. &filter (coutryname,prefix)
  24. &field_to_display i.e (countryname,sellingrate=money,buyrate=money, etc...)
  25. &field_type i.e ( ,money,money) (date or money ) is used for display
  26. &column_name      i.e (countryname,sellingrate,buyrate, etc...)
  27. &browse_letter  yes or no (A, B, C)
  28. &prefix_select i.e 32 (only prefix start by 32)
  29. &currency_select "cirency code i.e USD"
  30. &page_url i.e http://mysite.com/rates.php
  31. &merge_form (0 or 1) 1 for merge form search and 1 seaparated search form by default 0
  32. &fullhtmlpage (0 or 1)
  33. */
  34.   $ip_remote = getenv('REMOTE_ADDR'); 
  35.   $mail_content = "[" . date("Y/m/d G:i:s", mktime()) . "] "."Request asked from:$ip_remote with key:$key n";
  36.  // CHECK KEY
  37.  if ($FG_DEBUG > 0) echo "<br> md5(".md5($security_key).") !== $key";
  38. if (md5($security_key) !== $key  || strlen($security_key)==0)
  39.  {
  40.   mail($email_alarm, "ALARM : RATE CARD API - CODE_ERROR 2", $mail_content);
  41.   if ($FG_DEBUG > 0) echo ("[" . date("Y/m/d G:i:s", mktime()) . "] "."[$productid] - CODE_ERROR 2"."n");
  42.   //error_log ("[" . date("Y/m/d G:i:s", mktime()) . "].CODE_ERROR 2"."n", 3, $logfile);
  43.   echo("400 Bad Request");
  44.   exit();  
  45.  } 
  46. //**
  47. //set  default values if not isset vars
  48. if (!isset($nb_display_lines) || strlen($nb_display_lines)==0) $nb_display_lines=1;
  49. if (!isset($field_to_display) || strlen($field_to_display)==0) $field_to_display="t1.destination,t1.dialprefix,t1.rateinitial";
  50. if (!isset($resulttitle) || strlen($resulttitle)==0) $resulttitle="Rate list";
  51. if (!isset($filter) || strlen($filter)==0) $filter="countryname,prefix";
  52. //if (!isset($field_to_display) || strlen ($field_to_display)==0) $field_to_display="t1.destination,t1.dialprefix,t1.rateinitial";
  53. if (!isset($field_type) || strlen ($field_type)==0) $field_type=",,money";
  54. //if (!isset($column_name) || strlen($column_name)==0) $column_name="Destination,Prefix,Rate/Min";
  55. if (!isset($browse_letter) || strlen($browse_letter)==0) $browse_letter="yes";
  56. if (!isset($prefix_select) || strlen($prefix_select)==0) $prefix_select="";
  57. if (!isset($currency_select) || strlen($currency_select)==0) $currency_select=true;else $choose_currency=$currency_select;
  58. if (!isset($css_url) || strlen($css_url)==0) $css_url=substr("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],0,strlen("http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'])-20)."api_ratecard.css";
  59. if (!isset($merge_form) || strlen($merge_form)==0) $merge_form=0;
  60. if (!isset($fullhtmlpage) || strlen($fullhtmlpage)==0) $fullhtmlpage=1;
  61. if (!isset($page_url) || strlen($page_url)==0){ echo "Error : need to define page_url !!!"; exit; }
  62. if ( (substr($page_url,0,7)!='http://') && (substr($page_url,0,8)!='https://') ){ echo "Error : page_url need to start by http:// or https:// "; exit; }
  63. function add_clause(&$sqlclause,$addclause){
  64. if (strlen($sqlclause)==0) $sqlclause=$addclause;
  65. else $sqlclause.=" AND ".$addclause;
  66. }
  67. //end set default
  68. trim($field_to_display);
  69. trim($field_type);
  70. $field=explode(",",$field_to_display);
  71. $type=explode(",",$field_type);
  72. $column=explode(",",$column_name);
  73. $fltr=explode(",",$filter);
  74. if (!isset ($current_page) || ($current_page == "")){
  75. $current_page=0; 
  76. }
  77. $FILTER_COUNTRY=false;
  78. $FILTER_PREFIX=false;
  79. $DISPLAY_LETTER=false;
  80. if (DB_TYPE == "postgres"){
  81.   $REG_EXP = "~*";
  82. }else{
  83. $REG_EXP = "REGEXP";
  84. }
  85. for ($i=0;$i<count($fltr);$i++){
  86. switch ($fltr[$i]){
  87. case "countryname":
  88. $FILTER_COUNTRY=true;
  89. if (isset ($choose_country) && strlen($choose_country) != 0) add_clause($FG_TABLE_CLAUSE,"t1.destination $REG_EXP '$choose_country'");
  90. break;
  91. case "prefix":
  92. $FILTER_PREFIX=true;
  93. if (isset ($searchpre) && strlen($searchpre) != 0) add_clause($FG_TABLE_CLAUSE,"t1.dialprefix $REG_EXP '^$searchpre'");
  94. break;
  95. }
  96. }
  97. if (isset($browse_letter) && strtoupper($browse_letter)=="YES") $DISPLAY_LETTER=true;
  98. if (isset($letter) && strlen($letter)!=0) add_clause($FG_TABLE_CLAUSE,"t1.destination LIKE '".strtolower ($letter)."%'");
  99. if (isset($tariffgroupid) && strlen($tariffgroupid)!=0){
  100. $FG_TABLE_NAME="cc_ratecard t1, cc_tariffplan t4, cc_tariffgroup t5, cc_tariffgroup_plan t6";
  101. add_clause($FG_TABLE_CLAUSE,"t4.id = t6.idtariffplan AND t6.idtariffplan=t1.idtariffplan AND t6.idtariffgroup = '$tariffgroupid'");
  102. }else{
  103. $FG_TABLE_NAME="cc_ratecard t1";
  104. if (isset($ratecardid) && strlen($ratecardid)!=0){ 
  105. $FG_TABLE_NAME="cc_ratecard t1, cc_tariffplan t4";
  106. add_clause($FG_TABLE_CLAUSE,"t4.id = '$ratecardid' AND t1.idtariffplan = t4.id");
  107. }
  108. }
  109. if ($FILTER_COUNTRY || $DISPLAY_LETTER) {
  110. $nb_display_lines=100;
  111. $FG_LIMITE_DISPLAY=$nb_display_lines;
  112. $current_page=0;
  113. }
  114. // this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking)
  115. $FG_DEBUG = 0;
  116. // The variable FG_TABLE_NAME define the table name to use
  117. //$link = DbConnect();
  118. $DBHandle  = DbConnect();
  119. // First Name of the column in the html page, second name of the field
  120. $FG_TABLE_COL = array();
  121. if (count($column)==count($field) && count($field)==count($type) && count($column) != 0)
  122. { for ($i=0; $i<count($column); $i++){
  123. switch ($type[$i]) {
  124. case "money":
  125. $bill="display_2bill"; 
  126. break;
  127. case "date":
  128. $bill="display_dateformat";
  129. break;
  130. default:
  131. $bill="";
  132. }
  133. $FG_TABLE_COL[]=array (gettext($column[$i]), $field[$i], (100/count($column))."%", "center", "sort", "", "", "", "", "", "",$bill);
  134. }
  135. }
  136. $FG_COL_QUERY='DISTINCT '.$field_to_display;
  137. $FG_TABLE_DEFAULT_ORDER = $field[0];
  138. $FG_TABLE_DEFAULT_SENS = "DESC";
  139. // The variable LIMITE_DISPLAY define the limit of record to display by page
  140. $FG_LIMITE_DISPLAY=$nb_display_lines;
  141. // Number of column in the html table
  142. $FG_NB_TABLE_COL=count($FG_TABLE_COL);
  143. //This variable will store the total number of column
  144. $FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL;
  145. //This variable define the Title of the HTML table
  146. $FG_HTML_TABLE_TITLE=gettext($resulttitle);
  147. //This variable define the width of the HTML table
  148. if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME   -  Col_query : $FG_COL_QUERY";
  149. if ( is_null ($order) || is_null($sens) ){
  150. $order = $FG_TABLE_DEFAULT_ORDER;
  151. $sens  = $FG_TABLE_DEFAULT_SENS;
  152. }
  153. $instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY);
  154. $list = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY);
  155. $country_table = new Table("cc_country","countryname");
  156. $country_list = $country_table -> Get_list ($DBHandle);
  157. $QUERY="SELECT count(*) from $FG_TABLE_NAME WHERE $FG_TABLE_CLAUSE";
  158. $list_nrecord=$instance_table->SQLExec($DBHandle,$QUERY,1);
  159. $nb_record = $list_nrecord[0][0];
  160. if ($nb_record<=$FG_LIMITE_DISPLAY){ 
  161. $nb_record_max=1;
  162. }else{ 
  163. if ($nb_record % $FG_LIMITE_DISPLAY == 0){
  164. $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY));
  165. }else{
  166. $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1);
  167. }
  168. }
  169. ?>
  170. <script language="JavaScript" type="text/JavaScript">
  171. <!--
  172. function Search(Source){
  173. if (Source == 'btn01') 
  174. {
  175. if (document.myForm.merge_form.value == 0){
  176. document.myForm.searchpre.value="";
  177. }
  178. }
  179. if (Source == 'btn02') 
  180. {
  181. if (document.myForm.merge_form.value == 0){
  182. var index = document.myForm.choose_country.selectedIndex;
  183. document.myForm.choose_country.options[index].value="";
  184. }
  185. }
  186. document.myForm.submit();
  187. }
  188. //-->
  189. </script>
  190. <?php if ($fullhtmlpage){ ?>
  191. <html><head>
  192. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  193. <link href="<?php echo $css_url;?>" rel="stylesheet" type="text/css">
  194. </head>
  195. <div>
  196. <?php } ?>
  197. <!-- ** ** ** ** ** Part for the research ** ** ** ** ** -->
  198. <FORM METHOD="GET" name="myForm" ACTION="<?php echo "$page_url?order=$order&sens=$sens&current_page=$current_page&css_url=$css_url&page_url=$page_url"?>">
  199. <INPUT TYPE="hidden" NAME="posted" value=1>
  200. <INPUT TYPE="hidden" NAME="merge_form" value=<?php echo $merge_form;?>>
  201. <INPUT TYPE="hidden" NAME="current_page" value=0>
  202. <div class="title"  align="left">
  203. <H1><?php echo gettext("Rate search");?></H1>
  204. </div>
  205. <div class="search">
  206. <?php if ($FILTER_COUNTRY){ ?>
  207. <div class="searchelement"  align="left">
  208. <select NAME="choose_country" class="select" >
  209. <option value="" <?php if (!isset($choose_country)) {?>selected<?php } ?>><?php echo gettext("Select a country");?></option>
  210. <?php
  211. foreach($country_list as $country) {?>
  212. <option value='<?php echo $country[0] ?>' <?php if ($choose_country==$country[0]) {?>selected<?php } ?>><?php echo $country[0] ?><br>
  213. </option>
  214. <?php  } ?></select><input name="btn01" type="button"  align="top" value="Search" class="button" onclick="JavaScript:Search('btn01');">
  215. </div>
  216. <?php } if ($DISPLAY_LETTER){?>
  217. <div class="searchelement"  align="left">
  218. <?php echo gettext("select the first letter of the country you are looking for");?><br>
  219. <?php for ($i=65;$i<=90;$i++) {
  220.   $x = chr($i);
  221. if ($merge_form){
  222.   echo "<a href="$page_url?letter=$x&stitle=$stitle&current_page=$current_page&order=$order&sens=$sens&posted=$posted&choose_currency=$choose_currency&searchpre=$searchpre&choose_country=$choose_country&css_url=$css_url&page_url=$page_url">$x</a> ";
  223. }else{
  224. echo "<a href="$page_url?letter=$x&stitle=$stitle&current_page=$current_page&order=$order&sens=$sens&posted=$posted&choose_currency=$choose_currency&css_url=$css_url&page_url=$page_url">$x</a> ";
  225. }
  226. }?></font>
  227. </div>
  228. <?php } if ($FILTER_PREFIX){ ?>
  229. <div class="searchelement"  align="left">
  230. <?php echo gettext("Enter dial code"); ?><br>
  231. <INPUT TYPE="text" NAME="searchpre" class="textfield" value="<?php echo $searchpre ?>"></INPUT><input name="btn02" type="button"  align="top" value="Search" class="button" onclick="JavaScript:Search('btn02');">
  232. </div>
  233. <?php } if ($currency_select){ ?>
  234. <div class="searchelement"  align="left">
  235. <?php echo gettext("Select a currency");?><br>
  236. <select NAME="choose_currency" class="select">
  237. <?php
  238. $currencies_list = get_currencies();
  239. foreach($currencies_list as $key => $cur_value) {?>
  240. <option value="<?php echo $key ?>" <?php if (($choose_currency==$key) || (!isset($choose_currency) && $key==strtoupper(BASE_CURRENCY))){?>selected<?php } ?>><?php echo $cur_value[1] ?>
  241. </option>
  242. <?php  } ?>
  243. </select>
  244. </div>
  245. <?php } ?>
  246. <div class="searchelement"  align="left">
  247. </div>
  248. </div>
  249. </FORM>
  250. <!-- ** ** ** ** ** Part to display the ratecard ** ** ** ** ** -->
  251. <div class="result" align="left">
  252. <table width="70%" border=0 cellPadding=0 cellSpacing=0>
  253. <TR> 
  254. <TD> 
  255. <?php echo $FG_HTML_TABLE_TITLE?>
  256. </TD>
  257. </TR>
  258. <TR>
  259. <TD>
  260. <TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  261. <TBODY>
  262. <TR> 
  263. <?php if (is_array($list) && count($list)>0){
  264. for($i=0;$i<$FG_NB_TABLE_COL;$i++){ ?>
  265. <TH width="<?php echo $FG_TABLE_COL[$i][2]?>" class="table_title"> 
  266. <center><strong> 
  267. <?php  if (strtoupper($FG_TABLE_COL[$i][4])=="SORT"){?>
  268. <a href="<?php  echo "$page_url?stitle=$stitle&current_page=$current_page&order=".$FG_TABLE_COL[$i][1]."&sens=";if ($sens=="ASC"){echo"DESC";}else{echo"ASC";} echo "&posted=$posted&choose_currency=$choose_currency&searchpre=$searchpre&choose_country=$choose_country&letter=$letter&css_url=$css_url&page_url=$page_url";?>"> 
  269. <?php  } ?>
  270. <?php echo $FG_TABLE_COL[$i][0]?> 
  271. <?php  if (strtoupper($FG_TABLE_COL[$i][4])=="SORT"){?>
  272. </a> 
  273. <?php }?>
  274. </strong></center></TH>
  275.     <?php } ?>
  276. </TR>
  277. <?php
  278.  $alternate=0;
  279.  foreach ($list as $recordset){ 
  280.  $alternate+=M_PI/2;
  281. ?>
  282. <TR> 
  283. <?php for($i=0;$i<$FG_NB_TABLE_COL;$i++){
  284. $record_display = $recordset[$i];
  285. if ( is_numeric($FG_TABLE_COL[$i][5]) && (strlen($record_display) > $FG_TABLE_COL[$i][5])  ){
  286. $record_display = substr($record_display, 0, $FG_TABLE_COL[$i][5]-3)."";  
  287. } ?>
  288.                   <TD class="tabletr_<?echo intval(abs(cos($alternate)));?>" vAlign=top align="<?php echo $FG_TABLE_COL[$i][3]?>"><?php 
  289. if (isset ($FG_TABLE_COL[$i][11]) && strlen($FG_TABLE_COL[$i][11])>1){
  290. call_user_func($FG_TABLE_COL[$i][11], $record_display);
  291. }else{
  292. echo stripslashes($record_display);
  293. }?>
  294. </TD>
  295. <?php  }?>
  296. </TR>
  297. <?php
  298. }//foreach ($list as $recordset)
  299. }else{
  300. echo gettext("No rate found !!!");
  301. }//end_if
  302. ?>
  303. </TBODY>
  304. </TABLE>
  305. </td>
  306. </tr>
  307. <TR>
  308. <TD> 
  309. <?php
  310. $c_url="$page_url?stitle=$stitle&order=$order&sens=$sens&current_page=%s&posted=$posted&letter=$letter&choose_currency=$choose_currency&searchpre=$searchpre&choose_country=$choose_country&css_url=$css_url&page_url=$page_url";
  311. printPages($current_page+1, $nb_record_max, $c_url); 
  312. ?>
  313. </TD>
  314. </TD>
  315. </TR>
  316. </table>
  317. <div>
  318. <?php if ($fullhtmlpage){ ?>
  319. </div>
  320. </html>
  321. <?php } 
  322. echo "current_page=$current_page";
  323. ?>