PageRenderTime 50ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/osj-osj2dresumesdelete.php

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