PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website bán áo đồng phục PHP/lamao/modules/search.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 307 lines | 276 code | 2 blank | 29 comment | 42 complexity | a77c5e9a3fe4992d57c46eca480f620d MD5 | raw file
  1. <?php if (substr_count($_SERVER['PHP_SELF'],'/search.php')>0) die ("You can't access this file directly..."); ?>
  2. <div class="bo">
  3. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  4. <?php
  5. if (isset($_REQUEST['module']))
  6. {
  7. ?>
  8. <tr id="content" style="display: ;">
  9. <td align="right" valign="top">
  10. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  11. <?php
  12. if($_REQUEST['choice']=='news')
  13. $tblname='news';
  14. if($_REQUEST['choice']=='articles')
  15. $tblname='articles';
  16. $itemonrow=1;
  17. $rows=12;
  18. $curpage=1;
  19. $title='&raquo; '.$display['search'].' '.$display['articles'];
  20. //---------------------------- Query --------------------------
  21. //Tim kiem theo ngay
  22. if (isset($_POST['sday'],$_POST['smonth'],$_POST['syear']) and $_POST['sday']!='' and $_POST['smonth']!='' and $_POST['syear']!='')
  23. {
  24. if ($where==false)
  25. {
  26. $search.=' where';
  27. $where=true;
  28. }
  29. if ($condition!=0)
  30. {
  31. $search.=' and';
  32. }
  33. $search.=' log like "'.$_POST['syear'].'-'.$_POST['smonth'].'-'.$_POST['sday'].'%"';
  34. $condition++;
  35. $type.='<p class="formindex"><strong>- Thời gian : <font color="#ff0000">'.$_POST['sday'].'-'.$_POST['smonth'].'-'.$_POST['syear'].'</font></strong></p>';
  36. }
  37. if (isset($_REQUEST['category']))
  38. {
  39. $query='select * from '.$tblname.'_cat where id='.$_REQUEST['category'].'';
  40. if ($doquery=mysql_query($query,$link))
  41. {
  42. $result=mysql_fetch_array($doquery);
  43. $level=$result['level'];
  44. }
  45. else
  46. $level='';
  47. $query1='select * from '.$tblname.'_cat where level like "'.$level.'%" ';
  48. $ids='';
  49. $counter=0;
  50. if ($doquery1=mysql_query($query1,$link))
  51. while ($result1=mysql_fetch_array($doquery1))
  52. {
  53. $counter++;
  54. if ($counter>1)
  55. $ids.=',';
  56. $ids.='"'.$result1['id'].'"';
  57. }
  58. $getfield=array('title','content');
  59. $strs = explode(" ",$_POST['sstring']);
  60. $query='select * from '.$tblname.' where(';
  61. for ($j=0;$j<count($getfield);$j++)
  62. {
  63. if ($j>0)
  64. $query.=' or';
  65. //$query.=' '.$getfield[$j].' like "%'.$_POST['sstring'].'%"';
  66. for ($k=0;$k<count($strs);$k++)
  67. {
  68. //echo $strs;
  69. if ($k>0)
  70. $query.=' and';
  71. $query.=' '.$getfield[$j].' like "%'.$strs[$k].'%"';
  72. }
  73. }
  74. $query.=') and lang='.get_langID().'';
  75. if (isset($_POST['searchbydate']) and strlen($_POST['searchbydate'])>=10)
  76. {
  77. if ($searchbydate=datetime_conv($_POST['searchbydate'],'%d-%m-%y','%y-%m-%d'))
  78. $query.=' and log like "'.$searchbydate.'%"';
  79. }
  80. $query.=' and category in ('.$ids.')';
  81. $query.=' order by log DESC';
  82. //echo $query;
  83. //---------------- Show item -----------------
  84. function show_item($result)
  85. {
  86. //global $_POST['sstring'];
  87. global $obj;
  88. global $display;
  89. global $getfield;
  90. global $strs;
  91. $items=5;
  92. $url='?module=detailnews';
  93. $url.='&newscatID='.$result['category'];
  94. $url.='&artID='.$result['id'];
  95. echo '<p class="content1" style="font-size : 12px;">';
  96. for ($i=0;$i<count($getfield);$i++)
  97. {
  98. if (strlen($result[$getfield[$i]])>127)
  99. $result[$getfield[$i]]=get($result[$getfield[$i]],60).'...';
  100. if ($i==0)
  101. echo "<strong>";
  102. $keyword="";
  103. for ($m=0;$m<count($strs);$m++)
  104. {
  105. if ($m>0)
  106. $keyword.=" ";
  107. $keyword.=$strs[$m];
  108. $memo=str_replace($strs[$m],'<font color="#FF6600"><b>'.$strs[$m].'</b></font>');
  109. //echo $memo;
  110. }
  111. //echo $keyword;
  112. $memo=str_replace($keyword,'<font color="#FF6600"><b>'.$keyword.'</b></font>',strip_tags(stripslashes($result[$getfield[$i]])));
  113. //$memo=str_replace($strs[$m],'<font color="#FF6600"><b>'.$strs[$m].'</b></font>',strip_tags(stripslashes($memo)));
  114. echo $memo;
  115. if ($i==0)
  116. echo "</strong>";
  117. echo '<br>';
  118. }
  119. //.$field2.'&nbsp;&nbsp;'.$field3.'&nbsp;&nbsp;'.$field4.'&nbsp;&nbsp;'.$field5.'&nbsp;&nbsp;'.$field6.'';
  120. //echo '&nbsp;&nbsp;'.$result[$_REQUEST['cbox'.$i]].'&nbsp;&nbsp;
  121. echo '<a href="'.$url.'" target="_blank">&raquo; '.$display['view_more'].'</a>';
  122. echo '</p>';
  123. }
  124. }
  125. ?>
  126. <tr>
  127. <td height="22" colspan="3" style="border-bottom: solid 1px #FFFFFF;">
  128. <p><font class="title15">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $display['searchresult']; ?>&nbsp;&nbsp;&nbsp;&nbsp;</font></p>
  129. </td>
  130. </tr>
  131. <tr><td colspan="3" height="20" align="right">
  132. <?php include ($module_dir.'navigator.php'); ?></td></tr>
  133. <tr>
  134. <td width="20">&nbsp;</td>
  135. <td align="center" valign="top">
  136. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  137. <tr>
  138. <?php
  139. //show_content();
  140. if (isset($_REQUEST['curpage'],$_REQUEST['totalpage'],$_REQUEST['found']))
  141. {
  142. $found=$_REQUEST['found'];
  143. $totalpage=$_REQUEST['totalpage'];
  144. $curpage=$_REQUEST['curpage'];
  145. $from=($curpage-1) * $itemonrow * $rows;
  146. $to=$from + $itemonrow*$rows;
  147. $limit=' limit '.$from.','.$to;
  148. }
  149. if (isset($limit,$query))
  150. $query.=$limit;
  151. //echo $query;
  152. //exit;
  153. $doquery=mysql_query($query,$link);
  154. if ($doquery and mysql_num_rows($doquery)>0)
  155. {
  156. if (!isset($found))
  157. $found=mysql_num_rows($doquery);
  158. if (!isset($totalpage))
  159. {
  160. if ($found<($itemonrow*$rows))
  161. $totalpage=1;
  162. else
  163. {
  164. if ($found%($itemonrow*$rows)==0)
  165. $totalpage=$found/($itemonrow*$rows);
  166. else
  167. $totalpage=(int)($found/($itemonrow*$rows))+1;
  168. }
  169. }
  170. if (isset($found) and $found!=0)
  171. {
  172. echo '<tr><td colspan="'.($itemonrow+($itemonrow-1)).'" align="right" valign="top" style="padding: 0 0 0 0; border-bottom: solid 1px #1C891C;">';
  173. echo '<p class="title3" style="color: #336699;">';
  174. //echo $display['searchresult'].' : ';
  175. echo $display['found'].' : '.$found.' '.$display['articles'];
  176. echo ' ( '.$totalpage.' '.$display['page'].' )';
  177. echo '';
  178. echo "</p></td></tr>\n";
  179. //echo "<tr><td height=\"10\" colspan=\"3\"></td></tr>\n";
  180. }
  181. $i=0;
  182. while ($result=mysql_fetch_array($doquery) and $i<=($itemonrow*$rows))
  183. {
  184. //Show item
  185. ?>
  186. <td width="<?php echo round(96/$itemonrow,1); ?>%" style="padding: 6 6 0 6; border-bottom: 1px solid #DDDDDD; border-top: solid 1px #FFFFFF; background-color: #EEEEEE;" valign="top">
  187. <?php @show_item($result); ?>
  188. </td>
  189. <?php
  190. $i++;
  191. if ($i%$itemonrow==0)
  192. {
  193. ?>
  194. </tr>
  195. <!-- <tr><td colspan="<?php echo ($itemonrow+($itemonrow-1)); ?>" height="10"></td></tr> -->
  196. <?php
  197. }
  198. else
  199. echo '<td width="30"></td>';
  200. if ($i==$rows*$itemonrow)
  201. break;
  202. }
  203. ?>
  204. </tr>
  205. <tr><td align="left" colspan="<?php echo ($itemonrow+($itemonrow-1)); ?>">
  206. <p class="title4" style="font-weight: bold; text-align: right;">
  207. <?php
  208. /*
  209. if (isset($found) and $found!=0)
  210. echo $display['found'].' '.$found.' '.$display['articles'];
  211. */
  212. if (isset($totalpage))
  213. {
  214. for ($i=1; $i<=$totalpage; $i++)
  215. {
  216. if ($i%20==1)
  217. echo '</p><p class="title4" style="font-weight: bold; text-align: right;">';
  218. echo '<input type="button" value="';
  219. if ($i<10)
  220. echo '0';
  221. echo $i.'"';
  222. if ($i!=$curpage)
  223. {
  224. echo ' class="button"';
  225. echo ' onClick="browse('.$i;
  226. /*
  227. if ($cat=='')
  228. echo ",''";
  229. else
  230. echo ",'".$cat."'";
  231. */
  232. echo ')"';
  233. echo ' onmouseover="this.className=\'button_over\'" onmouseout="this.className=\'button\'"';
  234. }
  235. else
  236. echo ' class="button_down"';
  237. echo ">&nbsp;\n";
  238. }
  239. }
  240. ?>
  241. <script language="Javascript">
  242. function browse(curpage)
  243. {
  244. document.browsesearch.curpage.value=curpage;
  245. //document.browsesearch.cat.value=cat;
  246. document.browsesearch.submit();
  247. }
  248. </script>
  249. <form name="browsesearch" method="post" action="?module=search">
  250. <input type="hidden" name="module" value="search">
  251. <input type="hidden" name="object" value="<?php echo $obj; ?>">
  252. <input type="hidden" name="found" value="<?php echo $found; ?>">
  253. <input type="hidden" name="totalpage" value="<?php echo $totalpage; ?>">
  254. <input type="hidden" name="curpage" value="">
  255. <?php
  256. if (isset($_POST['total']))
  257. {
  258. echo "<input type=\"hidden\" name=\"total\" value=\"".$_POST['total']."\">\n";
  259. for ($i=0;$i<$_POST['total'];$i++)
  260. {
  261. if (isset($_REQUEST['cbox'.$i]))
  262. {
  263. //echo 'hehe';
  264. echo "<input type=\"hidden\" name=\"cbox".$i."\" value=\"".$_REQUEST['cbox'.$i]."\">\n";
  265. }
  266. }
  267. }
  268. if (isset($_REQUEST['tblname']))
  269. echo "<input type=\"hidden\" name=\"tblname\" value=\"".$_REQUEST['tblname']."\">\n";
  270. if (isset($_POST['category']))
  271. echo "<input type=\"hidden\" name=\"category\" value=\"".$_POST['category']."\">\n";
  272. if (isset($_REQUEST['title']))
  273. echo "<input type=\"hidden\" name=\"title\" value=\"".$_REQUEST['title']."\">\n";
  274. if (isset($_REQUEST['catID']))
  275. echo "<input type=\"hidden\" name=\"catID\" value=\"".$_REQUEST['catID']."\">\n";
  276. if (isset($_POST['sstring']))
  277. echo "<input type=\"hidden\" name=\"sstring\" value=\"".$_POST['sstring']."\">\n";
  278. ?>
  279. </form>
  280. </p></td></tr>
  281. <?php
  282. }
  283. else
  284. {
  285. ?>
  286. <script>
  287. alert("<?php echo $display['searchresult'].' \" '.$_REQUEST['sstring'].' \" : 0 '; ?>")
  288. //window.history.go(-1)
  289. </script>
  290. <?php
  291. }
  292. ?>
  293. </tr>
  294. </table>
  295. </td>
  296. <td width="20">&nbsp;</td>
  297. </tr>
  298. </table>
  299. <?php
  300. }
  301. ?>
  302. </td>
  303. </tr>
  304. </table>
  305. </div>