PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Places.php

https://github.com/Elieser/choosing-guides
PHP | 310 lines | 261 code | 38 blank | 11 comment | 54 complexity | 8634372a8d98882a4e81800a97c47f1d MD5 | raw file
  1. <?php require_once('Connections/ChoosingGuidesConnection.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8. }
  9. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10. switch ($theType) {
  11. case "text":
  12. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13. break;
  14. case "long":
  15. case "int":
  16. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17. break;
  18. case "double":
  19. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  20. break;
  21. case "date":
  22. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23. break;
  24. case "defined":
  25. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26. break;
  27. }
  28. return $theValue;
  29. }
  30. }
  31. $currentPage = $_SERVER["PHP_SELF"];
  32. $maxRows_Places = 10;
  33. $pageNum_Places = 0;
  34. if (isset($_GET['pageNum_Places'])) {
  35. $pageNum_Places = $_GET['pageNum_Places'];
  36. }
  37. $startRow_Places = $pageNum_Places * $maxRows_Places;
  38. $WebLanguage_Places = "-1";
  39. if (isset($_POST['weblanguage'])) {
  40. $WebLanguage_Places = $_POST['weblanguage'];
  41. }
  42. else
  43. {
  44. if (isset($_SESSION['MM_WebLanguageId'])){
  45. $WebLanguage_Places = $_SESSION['MM_WebLanguageId'];
  46. }
  47. }
  48. $country_Places = "";
  49. if (isset($_POST['country']) && $_POST['country']!='0') {
  50. $country_Places = 'AND tblplaces.CountryId='.$_POST['country'];
  51. }
  52. else
  53. {
  54. if (isset($_SESSION['MM_CountryId']) && $_SESSION['MM_CountryId']!='0'){
  55. $country_Places = ' AND tblplaces.CountryId='.$_SESSION['MM_CountryId'];
  56. }
  57. }
  58. $state_Places = "";
  59. if (isset($_POST['state']) && $_POST['state']!='0') {
  60. $state_Places = ' AND tblplaces.StateId='.$_POST['state'];
  61. }
  62. else
  63. {
  64. if (isset($_SESSION['MM_StateId']) && $_SESSION['MM_StateId']!='0'){
  65. $state_Places = ' AND tblplaces.StateId='.$_SESSION['MM_StateId'];
  66. }
  67. }
  68. $location_Places = "";
  69. if (isset($_POST['location']) && $_POST['location']!='0') {
  70. $location_Places = ' AND tblplaces.LocationId='.$_POST['location'];
  71. }
  72. else
  73. {
  74. if (isset($_SESSION['MM_LocationId']) && $_SESSION['MM_LocationId']!='0'){
  75. $location_Places = ' AND tblplaces.LocationId='.$_SESSION['MM_LocationId'];
  76. }
  77. }
  78. $word_Places = "";
  79. if (isset($_POST['wordfilter'])) {
  80. $word_Places = $_POST['wordfilter'];
  81. }
  82. else
  83. {
  84. if (isset($_SESSION['MM_Word'])){
  85. $word_Places =$_SESSION['MM_Word'];
  86. }
  87. }
  88. $sorted_Places = "1";
  89. $SortId=0;
  90. if (isset($_POST['queryorder'])){
  91. $SortId=$_POST['queryorder'];
  92. }
  93. else
  94. {
  95. if (isset($_SESSION['MM_SortId'])) {
  96. $SortId=$_SESSION['MM_SortId'];
  97. }
  98. }
  99. switch ($SortId){
  100. case 0: $sorted_Places = "Rand()";
  101. break;
  102. case 1: $sorted_Places = "ClickCounter DESC";
  103. break;
  104. case 2: $sorted_Places = "1";
  105. break;
  106. case 3: $sorted_Places = "(select count(*) from tblplacescomments where PlaceId=tblplaces.PlaceId) DESC";
  107. break;
  108. case 4: $sorted_Places = "(select round(avg(Points),2) from tblplacescomments where PlaceId=tblplaces.PlaceId) DESC";
  109. break;
  110. }
  111. mysql_select_db($database_ChoosingGuidesConnection, $ChoosingGuidesConnection);
  112. $query_Places = sprintf("SELECT tblplaces.PlaceId, tblplacesdet.WebLanguageId, tblplaces.CountryId, tblplaces.StateId, tblplaces.LocationId, tblplacesdet.PlaceName, CONVERT(tblplacesdet.PlaceDesc, char(290)) AS PlaceDesc, tblplacespictures.PictureName, tblplacespictures.PicturePath,
  113. (select round(avg(Points),2) from tblplacescomments where PlaceId=tblplaces.PlaceId) as avgPoints,
  114. (select count(*) from tblplacescomments where PlaceId=tblplaces.PlaceId) as countPoints
  115. FROM tblplaces LEFT OUTER JOIN tblplacespictures ON tblplaces.PlaceId = tblplacespictures.PlaceId LEFT OUTER JOIN tblplacesdet ON tblplaces.PlaceId = tblplacesdet.PlaceId WHERE WebLanguageId = %s %s %s %s AND (tblplacesdet.PlaceName like %s or tblplacesdet.PlaceDesc like %s) GROUP BY tblplaces.PlaceId ORDER BY %s", GetSQLValueString($WebLanguage_Places, "int"),$country_Places,$state_Places,$location_Places,GetSQLValueString("%" . $word_Places . "%", "text"),GetSQLValueString("%" . $word_Places . "%", "text"),$sorted_Places);
  116. $query_limit_Places = sprintf("%s LIMIT %d, %d", $query_Places, $startRow_Places, $maxRows_Places);
  117. $Places = mysql_query($query_limit_Places, $ChoosingGuidesConnection) or die(mysql_error());
  118. $row_Places = mysql_fetch_assoc($Places);
  119. /*if (isset($_GET['totalRows_Places'])) {
  120. $totalRows_Places = $_GET['totalRows_Places'];
  121. } else {*/
  122. $all_Places = mysql_query($query_Places);
  123. $totalRows_Places = mysql_num_rows($all_Places);
  124. $_GET['totalRows_Places']=mysql_num_rows($all_Places);
  125. //}
  126. $totalPages_Places = ceil($totalRows_Places/$maxRows_Places)-1;
  127. $queryString_Places = "";
  128. if (!empty($_SERVER['QUERY_STRING'])) {
  129. $params = explode("&", $_SERVER['QUERY_STRING']);
  130. $newParams = array();
  131. foreach ($params as $param) {
  132. if (stristr($param, "pageNum_Places") == false &&
  133. stristr($param, "totalRows_Places") == false) {
  134. array_push($newParams, $param);
  135. }
  136. }
  137. if (count($newParams) != 0) {
  138. $queryString_Places = "&" . htmlentities(implode("&", $newParams));
  139. }
  140. }
  141. $queryString_Places = sprintf("&totalRows_Places=%d%s", $totalRows_Places, $queryString_Places);
  142. if ($pageNum_Places > $totalPages_Places) {
  143. $PrimeraPag = $currentPage."?pageNum_Places=0&totalRows_Places=".$totalRows_Places;
  144. header(sprintf("Location: %s", $PrimeraPag));
  145. }
  146. ?>
  147. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  148. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/GlobalTemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->
  149. <head><link rel="Shortcut Icon" href="images/cg.ico" type="image/x-icon" />
  150. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  151. <!-- InstanceBeginEditable name="doctitle" -->
  152. <title>Choosing Guides</title>
  153. <!-- InstanceEndEditable -->
  154. <link href="CSS/twoColLiqLtHdr.css" rel="stylesheet" type="text/css" />
  155. <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
  156. <!--[if lte IE 7]>
  157. <style>
  158. .content { margin-right: -1px; } /* this 1px negative margin can be placed on any of the columns in this layout with the same corrective effect. */
  159. ul.nav a { zoom: 1; } /* the zoom property gives IE the hasLayout trigger it needs to correct extra whiltespace between the links */
  160. </style>
  161. <![endif]-->
  162. <!-- InstanceBeginEditable name="head" -->
  163. <!-- InstanceEndEditable -->
  164. <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
  165. </head>
  166. <body bgcolor="#D2D2FF">
  167. <div class="container">
  168. <div class="header">
  169. <div class="logo">
  170. <a href="Index.php"><img src="images/LogoChoosingGuides.gif" alt="Logo" name="logo" width="300" height="100" class="logo" id="logo" style="background-color: #8090AB; display:block;" /></a>
  171. <!-- end .header -->
  172. </div>
  173. <div class="weblanguage">
  174. <?php
  175. //if (is_file("Includes/SelectLanguage.php"))
  176. //{
  177. include ("Includes/SelectLanguage.php");
  178. /*}
  179. else
  180. {
  181. include ("../Includes/SelectLanguage.php");
  182. }*/
  183. ?>
  184. </div>
  185. </div>
  186. <div class="menu">
  187. <ul id="MenuBar1" class="MenuBarHorizontal">
  188. <li><a href="#">Guides</a></li>
  189. <li><a href="#">Travel Agencies</a></li>
  190. <li><a href="Tours.php">Tours</a></li>
  191. <li><a href="Places.php">Interesting Places</a></li>
  192. </ul>
  193. </div>
  194. <div class="content"><!-- InstanceBeginEditable name="Body" -->
  195. <?php
  196. include ("Includes/filter.php");
  197. if (mysql_num_rows($all_Places)==0)
  198. {
  199. echo "No Results were found ...";
  200. }
  201. else
  202. {
  203. ?>
  204. <table border="0" align="right">
  205. <tr>
  206. <td>Found <?php echo mysql_num_rows($all_Places)?> Results</td>
  207. <td width="460">&nbsp;</td>
  208. <td><?php if ($pageNum_Places > 0) { // Show if not first page ?>
  209. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, 0, $queryString_Places); ?>"><img src="images/First.gif" /></a>
  210. <?php } else {?><img src="images/First_disable.gif" /> <?php } // Show if not first page ?></td>
  211. <td><?php if ($pageNum_Places > 0) { // Show if not first page ?>
  212. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, max(0, $pageNum_Places - 1), $queryString_Places); ?>"><img src="images/Previous.gif" /></a>
  213. <?php } else {?><img src="images/Previous_disable.gif" /> <?php } // Show if not first page ?></td>
  214. <td><?php echo $pageNum_Places+1 ?> of <?php echo $totalPages_Places+1 ?></td>
  215. <td><?php if ($pageNum_Places < $totalPages_Places) { // Show if not last page ?>
  216. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, min($totalPages_Places, $pageNum_Places + 1), $queryString_Places); ?>"><img src="images/Next.gif" /></a>
  217. <?php } else {?><img src="images/Next_disable.gif" /> <?php }// Show if not last page ?></td>
  218. <td><?php if ($pageNum_Places < $totalPages_Places) { // Show if not last page ?>
  219. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, $totalPages_Places, $queryString_Places); ?>"><img src="images/Last.gif" /></a>
  220. <?php } else {?><img src="images/Last_disable.gif" /> <?php }// Show if not last page ?></td>
  221. </tr>
  222. </table>
  223. <?php do { ?>
  224. <div class="placesList"> <div class="placeImage"> <a href="PlacesDetails.php?place=<?php echo $row_Places['PlaceId']; ?>"><img src="<?php echo $row_Places['PicturePath']; ?>" width="196" height="156" alt="<?php echo $row_Places['PictureName']; ?>" /></a> </div>
  225. <div class="placeDesc">
  226. <div class="Valoration">
  227. <div class="stars">
  228. <?php echo '('.$row_Places['countPoints'].' Votes) '. $row_Places['avgPoints']?>
  229. <img src="images/Stars.png" width="100" height="20" alt="Stars" style="background-image:url(images/StarsBack.png); background-position:<?php echo 100+$row_Places['avgPoints']*20 ?>px 0px; margin-left:10px; vertical-align:central"/>
  230. </div>
  231. </div>
  232. <h4><a href="PlacesDetails.php?place=<?php echo $row_Places['PlaceId']; ?>"><?php echo $row_Places['PlaceName']; ?></a></h4>
  233. <p class="placeDesc"><?php echo $row_Places['PlaceDesc']; ?> ...</p>
  234. </div>
  235. </div>
  236. <?php } while ($row_Places = mysql_fetch_assoc($Places)); ?>
  237. <p>
  238. <table border="0" align="right">
  239. <tr>
  240. <td><?php if ($pageNum_Places > 0) { // Show if not first page ?>
  241. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, 0, $queryString_Places); ?>"><img src="images/First.gif" /></a>
  242. <?php } else {?><img src="images/First_disable.gif" /> <?php } // Show if not first page ?></td>
  243. <td><?php if ($pageNum_Places > 0) { // Show if not first page ?>
  244. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, max(0, $pageNum_Places - 1), $queryString_Places); ?>"><img src="images/Previous.gif" /></a>
  245. <?php } else {?><img src="images/Previous_disable.gif" /> <?php } // Show if not first page ?></td>
  246. <td><?php echo $pageNum_Places+1 ?> of <?php echo $totalPages_Places+1 ?></td>
  247. <td><?php if ($pageNum_Places < $totalPages_Places) { // Show if not last page ?>
  248. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, min($totalPages_Places, $pageNum_Places + 1), $queryString_Places); ?>"><img src="images/Next.gif" /></a>
  249. <?php } else {?><img src="images/Next_disable.gif" /> <?php }// Show if not last page ?></td>
  250. <td><?php if ($pageNum_Places < $totalPages_Places) { // Show if not last page ?>
  251. <a href="<?php printf("%s?pageNum_Places=%d%s", $currentPage, $totalPages_Places, $queryString_Places); ?>"><img src="images/Last.gif" /></a>
  252. <?php } else {?><img src="images/Last_disable.gif" /> <?php }// Show if not last page ?></td>
  253. </tr>
  254. </table>
  255. </p>
  256. <!-- InstanceEndEditable --><!-- end .content --></div>
  257. <div class="sidebar1">
  258. <p>Barra Lateral aaa</p>
  259. </div>
  260. <div class="footer">
  261. <p>&nbsp;</p>
  262. <!-- end .footer --></div>
  263. <!-- end .container --></div>
  264. <script type="text/javascript">
  265. var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
  266. </script>
  267. </body>
  268. <!-- InstanceEnd --></html>
  269. <?php
  270. }
  271. mysql_free_result($Places);
  272. ?>