PageRenderTime 73ms CodeModel.GetById 20ms RepoModel.GetById 8ms app.codeStats 0ms

/trunk/ zhss --username xi.david/postsview.php

https://gitlab.com/BGCX261/zhss-svn-to-git
PHP | 468 lines | 349 code | 55 blank | 64 comment | 53 complexity | 49001a84577a7211565c9edbff57dce3 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. define("EW_PAGE_ID", "view", TRUE); // Page ID
  3. define("EW_TABLE_NAME", 'posts', TRUE);
  4. ?>
  5. <?php
  6. session_start(); // Initialize session data
  7. ob_start(); // Turn on output buffering
  8. ?>
  9. <?php include "ewcfg50.php" ?>
  10. <?php include "ewmysql50.php" ?>
  11. <?php include "phpfn50.php" ?>
  12. <?php include "postsinfo.php" ?>
  13. <?php include "userfn50.php" ?>
  14. <?php include "userinfo.php" ?>
  15. <?php
  16. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  17. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
  18. header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
  19. header("Cache-Control: post-check=0, pre-check=0", false);
  20. header("Pragma: no-cache"); // HTTP/1.0
  21. ?>
  22. <?php
  23. // Open connection to the database
  24. $conn = ew_Connect();
  25. ?>
  26. <?php
  27. $Security = new cAdvancedSecurity();
  28. ?>
  29. <?php
  30. if (!$Security->IsLoggedIn()) $Security->AutoLogin();
  31. if (!$Security->IsLoggedIn()) {
  32. $Security->SaveLastUrl();
  33. Page_Terminate("login.php");
  34. }
  35. ?>
  36. <?php
  37. // Common page loading event (in userfn*.php)
  38. Page_Loading();
  39. ?>
  40. <?php
  41. // Page load event, used in current page
  42. Page_Load();
  43. ?>
  44. <?php
  45. $posts->Export = @$_GET["export"]; // Get export parameter
  46. $sExport = $posts->Export; // Get export parameter, used in header
  47. $sExportFile = $posts->TableVar; // Get export file, used in header
  48. ?>
  49. <?php
  50. if (@$_GET["id"] <> "") {
  51. $posts->id->setQueryStringValue($_GET["id"]);
  52. } else {
  53. Page_Terminate("postslist.php"); // Return to list page
  54. }
  55. // Get action
  56. if (@$_POST["a_view"] <> "") {
  57. $posts->CurrentAction = $_POST["a_view"];
  58. } else {
  59. $posts->CurrentAction = "I"; // Display form
  60. }
  61. switch ($posts->CurrentAction) {
  62. case "I": // Get a record to display
  63. if (!LoadRow()) { // Load record based on key
  64. $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // Set no record message
  65. Page_Terminate("postslist.php"); // Return to list
  66. }
  67. }
  68. $key = trim(@$_GET[EW_TABLE_BASIC_SEARCH]);
  69. $type = @$_GET[EW_TABLE_BASIC_SEARCH_TYPE];
  70. if( $key != '' ) {
  71. if( $type == 'OR' || $type == 'AND' ) {
  72. $key = explode(' ',$key);
  73. }
  74. }
  75. // Set return url
  76. $posts->setReturnUrl("postsview.php");
  77. // Render row
  78. $posts->RowType = EW_ROWTYPE_VIEW;
  79. RenderRow();
  80. ?>
  81. <?php include "header.php" ?>
  82. <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  83. <tr>
  84. <!-- left column (begin) -->
  85. <td valign="top" class="ewMenuColumn">
  86. </td>
  87. <!-- left column (end) -->
  88. <!-- right column (begin) -->
  89. <td valign="top" class="ewContentColumn">
  90. <p><b>中和集成监控系统</b></p>
  91. <script type="text/javascript">
  92. <!--
  93. var EW_PAGE_ID = "view"; // Page id
  94. //-->
  95. </script>
  96. <script language="JavaScript" type="text/javascript">
  97. <!--
  98. // Write your client script here, no need to add script tags.
  99. // To include another .js script, use:
  100. // ew_ClientScriptInclude("my_javascript.js");
  101. //-->
  102. </script>
  103. <p><span class="phpmaker">
  104. <a href="postslist.php">返回列表</a>&nbsp;
  105. <?php if ($Security->CanAdd()) { ?>
  106. <a href="postsadd.php">添加</a>&nbsp;
  107. <?php } ?>
  108. <?php if ($Security->CanEdit()) { ?>
  109. <a href="<?php echo $posts->EditUrl() ?>">编辑</a>&nbsp;
  110. <?php } ?>
  111. <?php if ($Security->CanDelete()) { ?>
  112. <a href="<?php echo $posts->DeleteUrl() ?>">删除</a>&nbsp;
  113. <?php } ?>
  114. </span>
  115. </p>
  116. <?php
  117. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
  118. ?>
  119. <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
  120. <?php
  121. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
  122. }
  123. ?>
  124. <p>
  125. <form>
  126. <table class="ewTable">
  127. <tr class="ewTableRow">
  128. <td class="ewTableHeader">id</td>
  129. <td<?php echo $posts->id->CellAttributes() ?>>
  130. <div<?php echo $posts->id->ViewAttributes() ?>><?php echo $posts->id->ViewValue ?></div>
  131. </td>
  132. </tr>
  133. <tr class="ewTableAltRow">
  134. <td class="ewTableHeader">来源</td>
  135. <td<?php echo $posts->url->CellAttributes() ?>>
  136. <div<?php echo $posts->url->ViewAttributes() ?>><?php echo $posts->url->ViewValue ?></div>
  137. </td>
  138. </tr>
  139. <tr class="ewTableRow">
  140. <td class="ewTableHeader">时间</td>
  141. <td<?php echo $posts->datetime->CellAttributes() ?>>
  142. <div<?php echo $posts->datetime->ViewAttributes() ?>><?php echo $posts->datetime->ViewValue ?></div>
  143. </td>
  144. </tr>
  145. <tr class="ewTableAltRow">
  146. <td class="ewTableHeader">标题</td>
  147. <td<?php echo $posts->title->CellAttributes() ?>>
  148. <div<?php echo $posts->title->ViewAttributes() ?>><?php echo $posts->title->ViewValue ?><?php echo countword( $posts->content->ViewValue,$key) ?></div>
  149. </td>
  150. </tr>
  151. </tr>
  152. <tr class="ewTableRow">
  153. <td class="ewTableHeader">内容</td>
  154. <td<?php echo $posts->content->CellAttributes() ?>>
  155. <div<?php echo $posts->content->ViewAttributes() ?>><?php echo highlight($posts->content->ViewValue,$key) ?></div>
  156. </td>
  157. </tr>
  158. </table>
  159. </form>
  160. <p>
  161. <script language="JavaScript" type="text/javascript">
  162. <!--
  163. // Write your table-specific startup script here
  164. // document.write("page loaded");
  165. //-->
  166. </script>
  167. <?php include "footer.php" ?>
  168. <?php
  169. // If control is passed here, simply terminate the page without redirect
  170. Page_Terminate();
  171. // -----------------------------------------------------------------
  172. // Subroutine Page_Terminate
  173. // - called when exit page
  174. // - clean up connection and objects
  175. // - if url specified, redirect to url, otherwise end response
  176. function Page_Terminate($url = "") {
  177. global $conn;
  178. // Page unload event, used in current page
  179. Page_Unload();
  180. // Global page unloaded event (in userfn*.php)
  181. Page_Unloaded();
  182. // Close Connection
  183. $conn->Close();
  184. // Go to url if specified
  185. if ($url <> "") {
  186. ob_end_clean();
  187. header("Location: $url");
  188. }
  189. exit();
  190. }
  191. ?>
  192. <?php
  193. // Load row based on key values
  194. function LoadRow() {
  195. global $conn, $Security, $posts;
  196. $sFilter = $posts->SqlKeyFilter();
  197. if (!is_numeric($posts->id->CurrentValue)) {
  198. return FALSE; // Invalid key, exit
  199. }
  200. $sFilter = str_replace("@id@", ew_AdjustSql($posts->id->CurrentValue), $sFilter); // Replace key value
  201. // Call Row Selecting event
  202. $posts->Row_Selecting($sFilter);
  203. // Load sql based on filter
  204. $posts->CurrentFilter = $sFilter;
  205. $sSql = $posts->SQL();
  206. if ($rs = $conn->Execute($sSql)) {
  207. if ($rs->EOF) {
  208. $LoadRow = FALSE;
  209. } else {
  210. $LoadRow = TRUE;
  211. $rs->MoveFirst();
  212. LoadRowValues($rs); // Load row values
  213. // Call Row Selected event
  214. $posts->Row_Selected($rs);
  215. }
  216. $rs->Close();
  217. } else {
  218. $LoadRow = FALSE;
  219. }
  220. return $LoadRow;
  221. }
  222. // Load row values from recordset
  223. function LoadRowValues(&$rs) {
  224. global $posts;
  225. $posts->id->setDbValue($rs->fields('id'));
  226. $posts->url->setDbValue($rs->fields('url'));
  227. $posts->datetime->setDbValue($rs->fields('datetime'));
  228. $posts->title->setDbValue($rs->fields('title'));
  229. $posts->digest->setDbValue($rs->fields('digest'));
  230. $posts->counter->setDbValue($rs->fields('counter'));
  231. $posts->content->setDbValue($rs->fields('content'));
  232. }
  233. ?>
  234. <?php
  235. // Render row values based on field settings
  236. function RenderRow() {
  237. global $conn, $Security, $posts;
  238. // Call Row Rendering event
  239. $posts->Row_Rendering();
  240. // Common render codes for all row types
  241. // id
  242. $posts->id->CellCssStyle = "";
  243. $posts->id->CellCssClass = "";
  244. // url
  245. $posts->url->CellCssStyle = "";
  246. $posts->url->CellCssClass = "";
  247. // datetime
  248. $posts->datetime->CellCssStyle = "";
  249. $posts->datetime->CellCssClass = "";
  250. // title
  251. $posts->title->CellCssStyle = "";
  252. $posts->title->CellCssClass = "";
  253. // digest
  254. $posts->digest->CellCssStyle = "";
  255. $posts->digest->CellCssClass = "";
  256. // counter
  257. $posts->counter->CellCssStyle = "";
  258. $posts->counter->CellCssClass = "";
  259. // content
  260. $posts->content->CellCssStyle = "";
  261. $posts->content->CellCssClass = "";
  262. if ($posts->RowType == EW_ROWTYPE_VIEW) { // View row
  263. // id
  264. $posts->id->ViewValue = $posts->id->CurrentValue;
  265. $posts->id->CssStyle = "";
  266. $posts->id->CssClass = "";
  267. $posts->id->ViewCustomAttributes = "";
  268. // url
  269. $posts->url->ViewValue = $posts->url->CurrentValue;
  270. $posts->url->CssStyle = "";
  271. $posts->url->CssClass = "";
  272. $posts->url->ViewCustomAttributes = "";
  273. // projectname
  274. $posts->projectname->ViewValue = $posts->projectname->CurrentValue;
  275. $posts->projectname->CssStyle = "";
  276. $posts->projectname->CssClass = "";
  277. $posts->projectname->ViewCustomAttributes = "";
  278. // datetime
  279. $posts->datetime->ViewValue = $posts->datetime->CurrentValue;
  280. $posts->datetime->ViewValue = ew_FormatDateTime($posts->datetime->ViewValue, 9);
  281. $posts->datetime->CssStyle = "";
  282. $posts->datetime->CssClass = "";
  283. $posts->datetime->ViewCustomAttributes = "";
  284. // title
  285. $posts->title->ViewValue = $posts->title->CurrentValue;
  286. $posts->title->CssStyle = "";
  287. $posts->title->CssClass = "";
  288. $posts->title->ViewCustomAttributes = "";
  289. // digest
  290. $posts->digest->ViewValue = $posts->digest->CurrentValue;
  291. $posts->digest->CssStyle = "";
  292. $posts->digest->CssClass = "";
  293. $posts->digest->ViewCustomAttributes = "";
  294. // counter
  295. $posts->counter->ViewValue = $posts->counter->CurrentValue;
  296. $posts->counter->CssStyle = "";
  297. $posts->counter->CssClass = "";
  298. $posts->counter->ViewCustomAttributes = "";
  299. // content
  300. $posts->content->ViewValue = $posts->content->CurrentValue;
  301. if (!is_null($posts->content->ViewValue)) $posts->content->ViewValue = str_replace("\n", "<br>", $posts->content->ViewValue);
  302. $posts->content->CssStyle = "";
  303. $posts->content->CssClass = "";
  304. $posts->content->ViewCustomAttributes = "";
  305. // id
  306. $posts->id->HrefValue = "";
  307. // url
  308. $posts->url->HrefValue = "";
  309. // datetime
  310. $posts->datetime->HrefValue = "";
  311. // title
  312. $posts->title->HrefValue = "";
  313. // digest
  314. $posts->digest->HrefValue = "";
  315. // counter
  316. $posts->counter->HrefValue = "";
  317. // content
  318. $posts->content->HrefValue = "";
  319. } elseif ($posts->RowType == EW_ROWTYPE_ADD) { // Add row
  320. } elseif ($posts->RowType == EW_ROWTYPE_EDIT) { // Edit row
  321. } elseif ($posts->RowType == EW_ROWTYPE_SEARCH) { // Search row
  322. }
  323. // Call Row Rendered event
  324. $posts->Row_Rendered();
  325. }
  326. ?>
  327. <?php
  328. // Set up Starting Record parameters based on Pager Navigation
  329. function SetUpStartRec() {
  330. global $nDisplayRecs, $nStartRec, $nTotalRecs, $nPageNo, $posts;
  331. if ($nDisplayRecs == 0) return;
  332. // Check for a START parameter
  333. if (@$_GET[EW_TABLE_START_REC] <> "") {
  334. $nStartRec = $_GET[EW_TABLE_START_REC];
  335. $posts->setStartRecordNumber($nStartRec);
  336. } elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
  337. $nPageNo = $_GET[EW_TABLE_PAGE_NO];
  338. if (is_numeric($nPageNo)) {
  339. $nStartRec = ($nPageNo-1)*$nDisplayRecs+1;
  340. if ($nStartRec <= 0) {
  341. $nStartRec = 1;
  342. } elseif ($nStartRec >= intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) {
  343. $nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
  344. }
  345. $posts->setStartRecordNumber($nStartRec);
  346. } else {
  347. $nStartRec = $posts->getStartRecordNumber();
  348. }
  349. } else {
  350. $nStartRec = $posts->getStartRecordNumber();
  351. }
  352. // Check if correct start record counter
  353. if (!is_numeric($nStartRec) || $nStartRec == "") { // Avoid invalid start record counter
  354. $nStartRec = 1; // Reset start record counter
  355. $posts->setStartRecordNumber($nStartRec);
  356. } elseif (intval($nStartRec) > intval($nTotalRecs)) { // Avoid starting record > total records
  357. $nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to last page first record
  358. $posts->setStartRecordNumber($nStartRec);
  359. } elseif (($nStartRec-1) % $nDisplayRecs <> 0) {
  360. $nStartRec = intval(($nStartRec-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to page boundary
  361. $posts->setStartRecordNumber($nStartRec);
  362. }
  363. }
  364. ?>
  365. <?php
  366. // Page Load event
  367. function Page_Load() {
  368. //echo "Page Load";
  369. }
  370. // Page Unload event
  371. function Page_Unload() {
  372. //echo "Page Unload";
  373. }
  374. function highlight($str,$key) {
  375. if( is_array($key) ){
  376. foreach($key as $k ) {
  377. $str = highlight($str,trim($k));
  378. }
  379. return $str;
  380. }
  381. else if ( is_string($key) ) {
  382. if( $key == '' ) return $str;
  383. //return(str_ireplace($key,'<span style="color:#f00;font-weight:bold;text-decoration:underline">'.$key.'</span>',$str));
  384. return(preg_replace("/($key)/isU","<span style=\"color:#f00;font-weight:bold;text-decoration:underline\">$1</span>",$str));
  385. }
  386. return $str;
  387. }
  388. function countword($str,$key) {
  389. $count = count_word($str,$key);
  390. if( $count == 0 ){
  391. return "";
  392. }
  393. else {
  394. return "<span style=\"color:#f00;font-weight:bold;text-decoration:underline\">($count)</span>";
  395. }
  396. return "";
  397. }
  398. function count_word($str,$key) {
  399. $count = 0;
  400. if( is_array($key) ){
  401. foreach($key as $k ) {
  402. $count = $count + substr_count($str, $k);
  403. }
  404. return $count;
  405. }
  406. else if ( is_string($key) ) {
  407. if( $key == '' ) return 0;
  408. //return(str_ireplace($key,'<span style="color:#f00;font-weight:bold;text-decoration:underline">'.$key.'</span>',$str));
  409. return(substr_count($str, $key));
  410. }
  411. return $count;
  412. }
  413. ?>