PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/base3.php

https://github.com/crocus/virpl
PHP | 224 lines | 205 code | 7 blank | 12 comment | 12 complexity | 503a43468cf1d1bad3e0e952c624b49c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. require_once('_scriptsphp/r_conn.php');
  3. function utf8_JSON_russian_cyr($str){
  4. $arr_replace_symbols = array
  5. (
  6. '\u0410' => 'А', '\u0430' => 'а',
  7. '\u0411' => 'Б', '\u0431' => 'б',
  8. '\u0412' => 'В', '\u0432' => 'в',
  9. '\u0413' => 'Г', '\u0433' => 'г',
  10. '\u0414' => 'Д', '\u0434' => 'д',
  11. '\u0415' => 'Е', '\u0435' => 'е',
  12. '\u0401' => 'Ё', '\u0451' => 'ё',
  13. '\u0416' => 'Ж', '\u0436' => 'ж',
  14. '\u0417' => 'З', '\u0437' => 'з',
  15. '\u0418' => 'И', '\u0438' => 'и',
  16. '\u0419' => 'Й', '\u0439' => 'й',
  17. '\u041a' => 'К', '\u043a' => 'к',
  18. '\u041b' => 'Л', '\u043b' => 'л',
  19. '\u041c' => 'М', '\u043c' => 'м',
  20. '\u041d' => 'Н', '\u043d' => 'н',
  21. '\u041e' => 'О', '\u043e' => 'о',
  22. '\u041f' => 'П', '\u043f' => 'п',
  23. '\u0420' => 'Р', '\u0440' => 'р',
  24. '\u0421' => 'С', '\u0441' => 'с',
  25. '\u0422' => 'Т', '\u0442' => 'т',
  26. '\u0423' => 'У', '\u0443' => 'у',
  27. '\u0424' => 'Ф', '\u0444' => 'ф',
  28. '\u0425' => 'Х', '\u0445' => 'х',
  29. '\u0426' => 'Ц', '\u0446' => 'ц',
  30. '\u0427' => 'Ч', '\u0447' => 'ч',
  31. '\u0428' => 'Ш', '\u0448' => 'ш',
  32. '\u0429' => 'Щ', '\u0449' => 'щ',
  33. '\u042a' => 'Ъ', '\u044a' => 'ъ',
  34. '\u042d' => 'Ы', '\u044b' => 'ы',
  35. '\u042c' => 'Ь', '\u044c' => 'ь',
  36. '\u042d' => 'Э', '\u044d' => 'э',
  37. '\u042e' => 'Ю', '\u044e' => 'ю',
  38. '\u042f' => 'Я', '\u044f' => 'я'
  39. );
  40. foreach($arr_replace_symbols as $from_gluk => $to_normal){
  41. $str = str_replace ($from_gluk,$to_normal,$str);
  42. }
  43. return $str;
  44. };
  45. $age = $_GET['agency'];
  46. $typ = $_GET['type'];
  47. $rom = $_GET['room'];
  48. $region = $_GET['region'];
  49. $bal = $_GET['balcon'];
  50. $flr = $_GET['floor'];
  51. $ord = $_GET['order'];
  52. /* echo "$age "; */
  53. $GenerQuery = "SELECT f.flats_cod, f.flats_date, f.So, f.Sz, f.Sk, f.flats_price, f.foto, f.flats_floor, f.flats_floorest, t.type_s, r.room_cod, a.region_name, s.street_name, w.wc_short, b.balcon_short, m.material_short".
  54. " FROM tbl_flats f, tbl_type t, tbl_room r, tbl_region a, tbl_street s, tbl_wc w, tbl_balcon b, tbl_material m, tbl_agency g, tbl_agent n ".
  55. "WHERE f.type_cod = t.type_cod AND f.room_cod = r.room_cod AND f.street_cod = s.street_cod AND s.region_cod = a.region_cod AND f.agent_cod = n.agent_cod AND n.agency_cod = g.agency_cod AND f.wc_cod = w.wc_cod AND f.balcon_cod = b.balcon_cod".
  56. " AND f.material_cod = m.material_cod";
  57. $WhereQuery = " And";
  58. $acon = " And";
  59. $rcon = " And";
  60. $bcon = " And";
  61. $regcon = " And";
  62. $flrcon = " And";
  63. switch ( $age ) {
  64. case NULL:
  65. $AgeQuery = (" f.agent_cod IS NOT NULL ");
  66. break;
  67. case "значение не задано":
  68. $AgeQuery = (" f.agent_cod IS NOT NULL ");
  69. break;
  70. default :
  71. $AgeQuery = " n.agency_cod = {$age}";
  72. break;
  73. }
  74. switch ( $typ ) {
  75. case NULL:
  76. $TypQuery = (" f.type_cod IS NOT NULL ");
  77. break;
  78. case "значение не задано":
  79. $TypQuery = (" f.type_cod IS NOT NULL ");
  80. break;
  81. default :
  82. $TypQuery = " f.type_cod = {$typ}";
  83. break;
  84. }
  85. switch ( $rom ) {
  86. case NULL:
  87. $romQuery = (" f.room_cod IS NOT NULL ");
  88. break;
  89. case "значение не задано":
  90. $romQuery = (" f.room_cod IS NOT NULL ");
  91. break;
  92. default :
  93. $romQuery = " f.room_cod = {$rom}";
  94. break;
  95. }
  96. switch ( $bal ) {
  97. case NULL:
  98. $balQuery = (" f.balcon_cod IS NOT NULL ");
  99. break;
  100. case "значение не задано":
  101. $balQuery = (" f.balcon_cod IS NOT NULL ");
  102. break;
  103. default :
  104. $balQuery = " f.balcon_cod = {$bal}";
  105. break;
  106. }
  107. switch ( $region ) {
  108. case NULL:
  109. $regQuery = (" f.street_cod IS NOT NULL ");
  110. break;
  111. case "значение не задано":
  112. $regQuery = (" f.street_cod IS NOT NULL ");
  113. break;
  114. default :
  115. $regQuery = " s.region_cod = {$region}";
  116. break;
  117. }
  118. switch ( $flr ) {
  119. case NULL:
  120. $flrQuery = (" f.flats_floor IS NOT NULL ");
  121. break;
  122. case "значение не задано":
  123. $flrQuery = (" f.flats_floor IS NOT NULL ");
  124. break;
  125. case "noferst":
  126. $flrQuery = (" f.flats_floor<>0 AND f.flats_floor<>1 ");
  127. break;
  128. case "nolast":
  129. $flrQuery = (" f.flats_floor<>f.flats_floorest ");
  130. break;
  131. case "middle":
  132. $flrQuery = (" f.flats_floor<>0 AND f.flats_floor<>1 AND f.flats_floor<>f.flats_floorest ");
  133. break;
  134. default :
  135. $flrQuery = " f.flats_floor IS NOT NULL ";
  136. break;
  137. }
  138. switch ( $ord ) {
  139. case NULL:
  140. $ordQuery = (" ORDER BY f.flats_price");
  141. break;
  142. case "значение не задано":
  143. $ordQuery = (" ORDER BY r.room_cod");
  144. break;
  145. case "type":
  146. $ordQuery = (" ORDER BY t.type_s");
  147. break;
  148. case "date":
  149. $ordQuery = (" ORDER BY f.flats_date DESC");
  150. break;
  151. case "room":
  152. $ordQuery = (" ORDER BY r.room_cod");
  153. break;
  154. case "price":
  155. $ordQuery = (" ORDER BY f.flats_price DESC");
  156. break;
  157. default :
  158. $ordQuery = " ORDER BY {$ord }";
  159. break;
  160. }
  161. $SQLQuery = $GenerQuery . $WhereQuery . $AgeQuery . $acon. $TypQuery . $rcon . $romQuery . $bcon . $balQuery . $regcon . $regQuery . $flrcon . $flrQuery . $ordQuery;
  162. /* echo $SQLQuery; */
  163. $num=0;
  164. $Recordset3 = @mysql_query($GenerQuery , $realtorplus) or die(mysql_error());
  165. $row_Recordset3 = mysql_fetch_assoc($Recordset3);
  166. $num=mysql_affected_rows();
  167. function getJSON($resultSet,$affectedRecords){
  168. $numberRows=0;
  169. $arrfieldName=array();
  170. $i=0;
  171. $json="";
  172. //print("Test");
  173. while ($i < mysql_num_fields($resultSet)) {
  174. $meta = mysql_fetch_field($resultSet, $i);
  175. if (!$meta) {
  176. }else{
  177. $arrfieldName[$i]=$meta->name;
  178. }
  179. $i++;
  180. }
  181. $i=0;
  182. // $json="{'". records ."':[";
  183. // $json="{'". records ."':[";
  184. while($row=mysql_fetch_array($resultSet, MYSQL_NUM)) {
  185. $i++;
  186. //print("Ind ".$i."-$affectedRecords<br>"); 'name':'marco'
  187. $json.="{";
  188. for($r=0;$r < count($arrfieldName);$r++) {
  189. $json.="'" . $arrfieldName[$r] . "':'" . $row[$r]. "'";
  190. if($r < count($arrfieldName)-1){
  191. $json.=",";
  192. }else{
  193. $json.="";
  194. }
  195. }
  196. if($i!=$affectedRecords-1){
  197. $json.="},";
  198. }else{
  199. $json.="}";
  200. }
  201. }
  202. //$json.="]}";
  203. return $json;
  204. }
  205. /*$m_json = getJSON($Recordset3,$num);
  206. $first_json_str = json_encode($m_json);
  207. $last_json_str = utf8_JSON_russian_cyr($first_json_str);
  208. echo trim($last_json_str, "\"");*/
  209. $arr = array();
  210. //$last_json_str = "{ \"aaData\":";
  211. while($obj = mysql_fetch_assoc($Recordset3)){
  212. $arr[] = $obj;
  213. }
  214. $first_json_str = json_encode($arr);
  215. $last_json_str = utf8_JSON_russian_cyr($first_json_str);
  216. echo $last_json_str;
  217. ?>