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

/osj-osj2dcategoriesdelete.php

http://osjobber.googlecode.com/
PHP | 529 lines | 392 code | 64 blank | 73 comment | 59 complexity | 3e9c181cd0053fdc9002243a4df4f491 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?php
  2. define("EW_PAGE_ID", "delete", TRUE); // Page ID
  3. define("EW_TABLE_NAME", 'osj-categories', TRUE);
  4. ?>
  5. <?php
  6. session_start(); // Initialize session data
  7. ob_start(); // Turn on output buffering
  8. ?>
  9. <?php include "osj-ewcfg50.php" ?>
  10. <?php include "osj-ewmysql50.php" ?>
  11. <?php include "osj-phpfn50.php" ?>
  12. <?php include "osj-osj2dcategoriesinfo.php" ?>
  13. <?php include "osj-userfn50.php" ?>
  14. <?php include "osj-osj2dusersinfo.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. $Security->LoadCurrentUserLevel('osj-categories');
  32. if (!$Security->IsLoggedIn()) {
  33. $Security->SaveLastUrl();
  34. Page_Terminate("osj-login.php");
  35. }
  36. if (!$Security->CanDelete()) {
  37. $Security->SaveLastUrl();
  38. Page_Terminate("osj-osj2dcategorieslist.php");
  39. }
  40. ?>
  41. <?php
  42. // Common page loading event (in userfn*.php)
  43. Page_Loading();
  44. ?>
  45. <?php
  46. // Page load event, used in current page
  47. Page_Load();
  48. ?>
  49. <?php
  50. $osj2Dcategories->Export = @$_GET["export"]; // Get export parameter
  51. $sExport = $osj2Dcategories->Export; // Get export parameter, used in header
  52. $sExportFile = $osj2Dcategories->TableVar; // Get export file, used in header
  53. ?>
  54. <?php
  55. // Load Key Parameters
  56. $sKey = "";
  57. $bSingleDelete = TRUE; // Initialize as single delete
  58. $arRecKeys = array();
  59. $nKeySelected = 0; // Initialize selected key count
  60. $sFilter = "";
  61. if (@$_GET["category_id"] <> "") {
  62. $osj2Dcategories->category_id->setQueryStringValue($_GET["category_id"]);
  63. if (!is_numeric($osj2Dcategories->category_id->QueryStringValue)) {
  64. Page_Terminate($osj2Dcategories->getReturnUrl()); // Prevent sql injection, exit
  65. }
  66. $sKey .= $osj2Dcategories->category_id->QueryStringValue;
  67. } else {
  68. $bSingleDelete = FALSE;
  69. }
  70. if ($bSingleDelete) {
  71. $nKeySelected = 1; // Set up key selected count
  72. $arRecKeys[0] = $sKey;
  73. } else {
  74. if (isset($_POST["key_m"])) { // Key in form
  75. $nKeySelected = count($_POST["key_m"]); // Set up key selected count
  76. $arRecKeys = ew_StripSlashes($_POST["key_m"]);
  77. }
  78. }
  79. if ($nKeySelected <= 0) Page_Terminate($osj2Dcategories->getReturnUrl()); // No key specified, exit
  80. // Build filter
  81. foreach ($arRecKeys as $sKey) {
  82. $sFilter .= "(";
  83. // Set up key field
  84. $sKeyFld = $sKey;
  85. if (!is_numeric($sKeyFld)) {
  86. Page_Terminate($osj2Dcategories->getReturnUrl()); // Prevent sql injection, exit
  87. }
  88. $sFilter .= "`category_id`=" . ew_AdjustSql($sKeyFld) . " AND ";
  89. if (substr($sFilter, -5) == " AND ") $sFilter = substr($sFilter, 0, strlen($sFilter)-5) . ") OR ";
  90. }
  91. if (substr($sFilter, -4) == " OR ") $sFilter = substr($sFilter, 0, strlen($sFilter)-4);
  92. // Set up filter (Sql Where Clause) and get Return Sql
  93. // Sql constructor in osj2Dcategories class, osj2Dcategoriesinfo.php
  94. $osj2Dcategories->CurrentFilter = $sFilter;
  95. // Get action
  96. if (@$_POST["a_delete"] <> "") {
  97. $osj2Dcategories->CurrentAction = $_POST["a_delete"];
  98. } else {
  99. $osj2Dcategories->CurrentAction = "I"; // Display record
  100. }
  101. switch ($osj2Dcategories->CurrentAction) {
  102. case "D": // Delete
  103. $osj2Dcategories->SendEmail = TRUE; // Send email on delete success
  104. if (DeleteRows()) { // delete rows
  105. $_SESSION[EW_SESSION_MESSAGE] = "Delete Successful"; // Set up success message
  106. Page_Terminate($osj2Dcategories->getReturnUrl()); // Return to caller
  107. }
  108. }
  109. // Load records for display
  110. $rs = LoadRecordset();
  111. $nTotalRecs = $rs->RecordCount(); // Get record count
  112. if ($nTotalRecs <= 0) { // No record found, exit
  113. $rs->Close();
  114. Page_Terminate($osj2Dcategories->getReturnUrl()); // Return to caller
  115. }
  116. ?>
  117. <?php include "osj-header.php" ?>
  118. <script type="text/javascript">
  119. <!--
  120. var EW_PAGE_ID = "delete"; // Page id
  121. var EW_SHOW_HIGHLIGHT = "Show highlight";
  122. var EW_HIDE_HIGHLIGHT = "Hide highlight";
  123. //-->
  124. </script>
  125. <script language="JavaScript" type="text/javascript">
  126. <!--
  127. // Write your client script here, no need to add script tags.
  128. // To include another .js script, use:
  129. // ew_ClientScriptInclude("my_javascript.js");
  130. //-->
  131. </script>
  132. <p><span class="phpmaker">Delete from TABLE: Categories<br><br><a href="<?php echo $osj2Dcategories->getReturnUrl() ?>">Go Back</a></span></p>
  133. <?php
  134. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
  135. ?>
  136. <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
  137. <?php
  138. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
  139. }
  140. ?>
  141. <form action="osj-osj2dcategoriesdelete.php" method="post">
  142. <p>
  143. <input type="hidden" name="a_delete" id="a_delete" value="D">
  144. <?php foreach ($arRecKeys as $sKey) { ?>
  145. <input type="hidden" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($sKey) ?>">
  146. <?php } ?>
  147. <table class="ewTable">
  148. <tr class="ewTableHeader">
  149. <td valign="top">category id</td>
  150. <td valign="top">parent id</td>
  151. <td valign="top">Category Name</td>
  152. </tr>
  153. <?php
  154. $nRecCount = 0;
  155. $i = 0;
  156. while (!$rs->EOF) {
  157. $nRecCount++;
  158. // Set row class and style
  159. $osj2Dcategories->CssClass = "ewTableRow";
  160. $osj2Dcategories->CssStyle = "";
  161. // Display alternate color for rows
  162. if ($nRecCount % 2 <> 1) {
  163. $osj2Dcategories->CssClass = "ewTableAltRow";
  164. }
  165. // Get the field contents
  166. LoadRowValues($rs);
  167. // Render row value
  168. $osj2Dcategories->RowType = EW_ROWTYPE_VIEW; // view
  169. RenderRow();
  170. ?>
  171. <tr<?php echo $osj2Dcategories->DisplayAttributes() ?>>
  172. <td<?php echo $osj2Dcategories->category_id->CellAttributes() ?>>
  173. <div<?php echo $osj2Dcategories->category_id->ViewAttributes() ?>><?php echo $osj2Dcategories->category_id->ViewValue ?></div>
  174. </td>
  175. <td<?php echo $osj2Dcategories->parent_id->CellAttributes() ?>>
  176. <div<?php echo $osj2Dcategories->parent_id->ViewAttributes() ?>><?php echo $osj2Dcategories->parent_id->ViewValue ?></div>
  177. </td>
  178. <td<?php echo $osj2Dcategories->category_name->CellAttributes() ?>>
  179. <div<?php echo $osj2Dcategories->category_name->ViewAttributes() ?>><?php echo $osj2Dcategories->category_name->ViewValue ?></div>
  180. </td>
  181. </tr>
  182. <?php
  183. $rs->MoveNext();
  184. }
  185. $rs->Close();
  186. ?>
  187. </table>
  188. <p>
  189. <input type="submit" name="Action" id="Action" value="Confirm Delete">
  190. </form>
  191. <script language="JavaScript" type="text/javascript">
  192. <!--
  193. // Write your table-specific startup script here
  194. // document.write("page loaded");
  195. //-->
  196. </script>
  197. <?php include "osj-footer.php" ?>
  198. <?php
  199. // If control is passed here, simply terminate the page without redirect
  200. Page_Terminate();
  201. // -----------------------------------------------------------------
  202. // Subroutine Page_Terminate
  203. // - called when exit page
  204. // - clean up connection and objects
  205. // - if url specified, redirect to url, otherwise end response
  206. function Page_Terminate($url = "") {
  207. global $conn;
  208. // Page unload event, used in current page
  209. Page_Unload();
  210. // Global page unloaded event (in userfn*.php)
  211. Page_Unloaded();
  212. // Close Connection
  213. $conn->Close();
  214. // Go to url if specified
  215. if ($url <> "") {
  216. ob_end_clean();
  217. header("Location: $url");
  218. }
  219. exit();
  220. }
  221. ?>
  222. <?php
  223. // ------------------------------------------------
  224. // Function DeleteRows
  225. // - Delete Records based on current filter
  226. function DeleteRows() {
  227. global $conn, $Security, $osj2Dcategories;
  228. $DeleteRows = TRUE;
  229. $sWrkFilter = $osj2Dcategories->CurrentFilter;
  230. // Set up filter (Sql Where Clause) and get Return Sql
  231. // Sql constructor in osj2Dcategories class, osj2Dcategoriesinfo.php
  232. $osj2Dcategories->CurrentFilter = $sWrkFilter;
  233. $sSql = $osj2Dcategories->SQL();
  234. $conn->raiseErrorFn = 'ew_ErrorFn';
  235. $rs = $conn->Execute($sSql);
  236. $conn->raiseErrorFn = '';
  237. if ($rs === FALSE) {
  238. return FALSE;
  239. } elseif ($rs->EOF) {
  240. $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
  241. $rs->Close();
  242. return FALSE;
  243. }
  244. $conn->BeginTrans();
  245. WriteAuditTrailDummy("*** batch delete begin ***"); // Batch delete begin
  246. // Clone old rows
  247. $rsold = ($rs) ? $rs->GetRows() : array();
  248. if ($rs) $rs->Close();
  249. // Call row deleting event
  250. if ($DeleteRows) {
  251. foreach ($rsold as $row) {
  252. $DeleteRows = $osj2Dcategories->Row_Deleting($row);
  253. if (!$DeleteRows) break;
  254. }
  255. }
  256. if ($DeleteRows) {
  257. $sKey = "";
  258. foreach ($rsold as $row) {
  259. $sThisKey = "";
  260. if ($sThisKey <> "") $sThisKey .= EW_COMPOSITE_KEY_SEPARATOR;
  261. $sThisKey .= $row['category_id'];
  262. $conn->raiseErrorFn = 'ew_ErrorFn';
  263. $DeleteRows = $conn->Execute($osj2Dcategories->DeleteSQL($row)); // Delete
  264. $conn->raiseErrorFn = '';
  265. if ($DeleteRows === FALSE)
  266. break;
  267. if ($sKey <> "") $sKey .= ", ";
  268. $sKey .= $sThisKey;
  269. }
  270. } else {
  271. // Set up error message
  272. if ($osj2Dcategories->CancelMessage <> "") {
  273. $_SESSION[EW_SESSION_MESSAGE] = $osj2Dcategories->CancelMessage;
  274. $osj2Dcategories->CancelMessage = "";
  275. } else {
  276. $_SESSION[EW_SESSION_MESSAGE] = "Delete cancelled";
  277. }
  278. }
  279. if ($DeleteRows) {
  280. $conn->CommitTrans(); // Commit the changes
  281. if ($DeleteRows) {
  282. foreach ($rsold as $row) {
  283. WriteAuditTrailOnDelete($row);
  284. }
  285. }
  286. WriteAuditTrailDummy("*** batch delete success ***"); // Batch delete success
  287. } else {
  288. $conn->RollbackTrans(); // Rollback changes
  289. WriteAuditTrailDummy("*** batch delete rollback ***"); // Batch delete rollback
  290. }
  291. // Call recordset deleted event
  292. if ($DeleteRows) {
  293. foreach ($rsold as $row) {
  294. $osj2Dcategories->Row_Deleted($row);
  295. }
  296. }
  297. return $DeleteRows;
  298. }
  299. ?>
  300. <?php
  301. // Load recordset
  302. function LoadRecordset($offset = -1, $rowcnt = -1) {
  303. global $conn, $osj2Dcategories;
  304. // Call Recordset Selecting event
  305. $osj2Dcategories->Recordset_Selecting($osj2Dcategories->CurrentFilter);
  306. // Load list page sql
  307. $sSql = $osj2Dcategories->SelectSQL();
  308. if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";
  309. // Load recordset
  310. $conn->raiseErrorFn = 'ew_ErrorFn';
  311. $rs = $conn->Execute($sSql);
  312. $conn->raiseErrorFn = '';
  313. // Call Recordset Selected event
  314. $osj2Dcategories->Recordset_Selected($rs);
  315. return $rs;
  316. }
  317. ?>
  318. <?php
  319. // Load row based on key values
  320. function LoadRow() {
  321. global $conn, $Security, $osj2Dcategories;
  322. $sFilter = $osj2Dcategories->SqlKeyFilter();
  323. if (!is_numeric($osj2Dcategories->category_id->CurrentValue)) {
  324. return FALSE; // Invalid key, exit
  325. }
  326. $sFilter = str_replace("@category_id@", ew_AdjustSql($osj2Dcategories->category_id->CurrentValue), $sFilter); // Replace key value
  327. // Call Row Selecting event
  328. $osj2Dcategories->Row_Selecting($sFilter);
  329. // Load sql based on filter
  330. $osj2Dcategories->CurrentFilter = $sFilter;
  331. $sSql = $osj2Dcategories->SQL();
  332. if ($rs = $conn->Execute($sSql)) {
  333. if ($rs->EOF) {
  334. $LoadRow = FALSE;
  335. } else {
  336. $LoadRow = TRUE;
  337. $rs->MoveFirst();
  338. LoadRowValues($rs); // Load row values
  339. // Call Row Selected event
  340. $osj2Dcategories->Row_Selected($rs);
  341. }
  342. $rs->Close();
  343. } else {
  344. $LoadRow = FALSE;
  345. }
  346. return $LoadRow;
  347. }
  348. // Load row values from recordset
  349. function LoadRowValues(&$rs) {
  350. global $osj2Dcategories;
  351. $osj2Dcategories->category_id->setDbValue($rs->fields('category_id'));
  352. $osj2Dcategories->parent_id->setDbValue($rs->fields('parent_id'));
  353. $osj2Dcategories->category_name->setDbValue($rs->fields('category_name'));
  354. }
  355. ?>
  356. <?php
  357. // Render row values based on field settings
  358. function RenderRow() {
  359. global $conn, $Security, $osj2Dcategories;
  360. // Call Row Rendering event
  361. $osj2Dcategories->Row_Rendering();
  362. // Common render codes for all row types
  363. // category_id
  364. $osj2Dcategories->category_id->CellCssStyle = "";
  365. $osj2Dcategories->category_id->CellCssClass = "";
  366. // parent_id
  367. $osj2Dcategories->parent_id->CellCssStyle = "";
  368. $osj2Dcategories->parent_id->CellCssClass = "";
  369. // category_name
  370. $osj2Dcategories->category_name->CellCssStyle = "";
  371. $osj2Dcategories->category_name->CellCssClass = "";
  372. if ($osj2Dcategories->RowType == EW_ROWTYPE_VIEW) { // View row
  373. // category_id
  374. $osj2Dcategories->category_id->ViewValue = $osj2Dcategories->category_id->CurrentValue;
  375. $osj2Dcategories->category_id->CssStyle = "";
  376. $osj2Dcategories->category_id->CssClass = "";
  377. $osj2Dcategories->category_id->ViewCustomAttributes = "";
  378. // parent_id
  379. if (!is_null($osj2Dcategories->parent_id->CurrentValue)) {
  380. $sSqlWrk = "SELECT `category_name` FROM `osj-categories` WHERE `category_id` = " . ew_AdjustSql($osj2Dcategories->parent_id->CurrentValue) . "";
  381. $sSqlWrk .= " AND (" . "`parent_id` = 0 OR `parent_id` = -1" . ")";
  382. $sSqlWrk .= " ORDER BY `category_name` ";
  383. $rswrk = $conn->Execute($sSqlWrk);
  384. if ($rswrk) {
  385. if (!$rswrk->EOF) {
  386. $osj2Dcategories->parent_id->ViewValue = $rswrk->fields('category_name');
  387. }
  388. $rswrk->Close();
  389. } else {
  390. $osj2Dcategories->parent_id->ViewValue = $osj2Dcategories->parent_id->CurrentValue;
  391. }
  392. } else {
  393. $osj2Dcategories->parent_id->ViewValue = NULL;
  394. }
  395. $osj2Dcategories->parent_id->CssStyle = "";
  396. $osj2Dcategories->parent_id->CssClass = "";
  397. $osj2Dcategories->parent_id->ViewCustomAttributes = "";
  398. // category_name
  399. $osj2Dcategories->category_name->ViewValue = $osj2Dcategories->category_name->CurrentValue;
  400. $osj2Dcategories->category_name->CssStyle = "";
  401. $osj2Dcategories->category_name->CssClass = "";
  402. $osj2Dcategories->category_name->ViewCustomAttributes = "";
  403. // category_id
  404. $osj2Dcategories->category_id->HrefValue = "";
  405. // parent_id
  406. $osj2Dcategories->parent_id->HrefValue = "";
  407. // category_name
  408. $osj2Dcategories->category_name->HrefValue = "";
  409. } elseif ($osj2Dcategories->RowType == EW_ROWTYPE_ADD) { // Add row
  410. } elseif ($osj2Dcategories->RowType == EW_ROWTYPE_EDIT) { // Edit row
  411. } elseif ($osj2Dcategories->RowType == EW_ROWTYPE_SEARCH) { // Search row
  412. }
  413. // Call Row Rendered event
  414. $osj2Dcategories->Row_Rendered();
  415. }
  416. ?>
  417. <?php
  418. // Write Audit Trail start/end for grid update
  419. function WriteAuditTrailDummy($typ) {
  420. $table = 'osj-categories';
  421. // Write Audit Trail
  422. $filePfx = "log";
  423. $curDate = date("Y/m/d");
  424. $curTime = date("H:i:s");
  425. $id = ew_ScriptName();
  426. $user = CurrentUserID();
  427. $action = $typ;
  428. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
  429. }
  430. ?>
  431. <?php
  432. // Write Audit Trail (delete page)
  433. function WriteAuditTrailOnDelete(&$rs) {
  434. global $osj2Dcategories;
  435. $table = 'osj-categories';
  436. // Get key value
  437. $key = "";
  438. if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
  439. $key .= $rs['category_id'];
  440. // Write Audit Trail
  441. $filePfx = "log";
  442. $curDate = date("Y/m/d");
  443. $curTime = date("H:i:s");
  444. $id = ew_ScriptName();
  445. $user = CurrentUserID();
  446. $action = "D";
  447. $newvalue = "";
  448. foreach (array_keys($rs) as $fldname) {
  449. if ($osj2Dcategories->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
  450. $oldvalue = ($osj2Dcategories->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) ? "<MEMO>" : $rs[$fldname]; // Memo Field
  451. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
  452. }
  453. }
  454. }
  455. ?>
  456. <?php
  457. // Page Load event
  458. function Page_Load() {
  459. //echo "Page Load";
  460. }
  461. // Page Unload event
  462. function Page_Unload() {
  463. //echo "Page Unload";
  464. }
  465. ?>