PageRenderTime 28ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/osj-osj2dapplicationsadd.php

http://osjobber.googlecode.com/
PHP | 682 lines | 516 code | 80 blank | 86 comment | 90 complexity | b2b5bf3113a13f06b41e89ff8b116482 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?php
  2. define("EW_PAGE_ID", "add", TRUE); // Page ID
  3. define("EW_TABLE_NAME", 'osj-applications', 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-osj2dapplicationsinfo.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-applications');
  32. if (!$Security->IsLoggedIn()) {
  33. $Security->SaveLastUrl();
  34. Page_Terminate("osj-login.php");
  35. }
  36. if (!$Security->CanAdd()) {
  37. $Security->SaveLastUrl();
  38. Page_Terminate("osj-osj2dapplicationslist.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. $osj2Dapplications->Export = @$_GET["export"]; // Get export parameter
  55. $sExport = $osj2Dapplications->Export; // Get export parameter, used in header
  56. $sExportFile = $osj2Dapplications->TableVar; // Get export file, used in header
  57. ?>
  58. <?php
  59. // Load key values from QueryString
  60. $bCopy = TRUE;
  61. if (@$_GET["application_id"] != "") {
  62. $osj2Dapplications->application_id->setQueryStringValue($_GET["application_id"]);
  63. } else {
  64. $bCopy = FALSE;
  65. }
  66. // Create form object
  67. $objForm = new cFormObj();
  68. // Process form if post back
  69. if (@$_POST["a_add"] <> "") {
  70. $osj2Dapplications->CurrentAction = $_POST["a_add"]; // Get form action
  71. GetUploadFiles(); // Get upload files
  72. LoadFormValues(); // Load form values
  73. } else { // Not post back
  74. if ($bCopy) {
  75. $osj2Dapplications->CurrentAction = "C"; // Copy Record
  76. } else {
  77. $osj2Dapplications->CurrentAction = "I"; // Display Blank Record
  78. LoadDefaultValues(); // Load default values
  79. }
  80. }
  81. // Perform action based on action code
  82. switch ($osj2Dapplications->CurrentAction) {
  83. case "I": // Blank record, no action required
  84. break;
  85. case "C": // Copy an existing record
  86. if (!LoadRow()) { // Load record based on key
  87. $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
  88. Page_Terminate($osj2Dapplications->getReturnUrl()); // Clean up and return
  89. }
  90. break;
  91. case "A": // ' Add new record
  92. $osj2Dapplications->SendEmail = TRUE; // Send email on add success
  93. if (AddRow()) { // Add successful
  94. $_SESSION[EW_SESSION_MESSAGE] = "Add New Record Successful"; // Set up success message
  95. Page_Terminate($osj2Dapplications->KeyUrl($osj2Dapplications->getReturnUrl())); // Clean up and return
  96. } else {
  97. RestoreFormValues(); // Add failed, restore form values
  98. }
  99. }
  100. // Render row based on row type
  101. $osj2Dapplications->RowType = EW_ROWTYPE_ADD; // Render add type
  102. RenderRow();
  103. ?>
  104. <?php include "osj-header.php" ?>
  105. <script type="text/javascript">
  106. <!--
  107. var EW_PAGE_ID = "add"; // Page id
  108. var EW_SHOW_HIGHLIGHT = "Show highlight";
  109. var EW_HIDE_HIGHLIGHT = "Hide highlight";
  110. //-->
  111. </script>
  112. <script type="text/javascript">
  113. <!--
  114. function ew_ValidateForm(fobj) {
  115. if (fobj.a_confirm && fobj.a_confirm.value == "F")
  116. return true;
  117. var i, elm, aelm, infix;
  118. var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
  119. for (i=0; i<rowcnt; i++) {
  120. infix = (fobj.key_count) ? String(i+1) : "";
  121. elm = fobj.elements["x" + infix + "_resume_id"];
  122. if (elm && !ew_HasValue(elm)) {
  123. if (!ew_OnError(elm, "Please enter required field - Resume"))
  124. return false;
  125. }
  126. elm = fobj.elements["x" + infix + "_post_id"];
  127. if (elm && !ew_HasValue(elm)) {
  128. if (!ew_OnError(elm, "Please enter required field - Post ID"))
  129. return false;
  130. }
  131. elm = fobj.elements["x" + infix + "_post_id"];
  132. if (elm && !ew_CheckInteger(elm.value)) {
  133. if (!ew_OnError(elm, "A post id is required."))
  134. return false;
  135. }
  136. elm = fobj.elements["x" + infix + "_application_email"];
  137. if (elm && !ew_HasValue(elm)) {
  138. if (!ew_OnError(elm, "Please enter required field - Application Email"))
  139. return false;
  140. }
  141. elm = fobj.elements["x" + infix + "_application_email"];
  142. if (elm && !ew_CheckEmail(elm.value)) {
  143. if (!ew_OnError(elm, "All applications require an email address."))
  144. return false;
  145. }
  146. elm = fobj.elements["x" + infix + "_application_text"];
  147. if (elm && !ew_HasValue(elm)) {
  148. if (!ew_OnError(elm, "Please enter required field - Application Comments"))
  149. return false;
  150. }
  151. elm = fobj.elements["x" + infix + "_application_file"];
  152. aelm = fobj.elements["a" + infix + "_application_file"];
  153. var chk_application_file = (aelm && aelm[0])?(aelm[2].checked):true;
  154. if (elm && chk_application_file && !ew_HasValue(elm)) {
  155. if (!ew_OnError(elm, "Please enter required field - Application Attachment"))
  156. return false;
  157. }
  158. elm = fobj.elements["x" + infix + "_application_file"];
  159. if (elm && !ew_CheckFileType(elm.value)) {
  160. if (!ew_OnError(elm, "File type is not allowed."))
  161. return false;
  162. }
  163. elm = fobj.elements["x" + infix + "_application_file_name"];
  164. if (elm && !ew_HasValue(elm)) {
  165. if (!ew_OnError(elm, "Please enter required field - Application File Name"))
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. //-->
  172. </script>
  173. <script type="text/javascript">
  174. <!--
  175. var ew_DHTMLEditors = [];
  176. //-->
  177. </script>
  178. <script type="text/javascript">
  179. <!--
  180. // js for Popup Calendar
  181. //-->
  182. </script>
  183. <script type="text/javascript">
  184. <!--
  185. var ew_MultiPagePage = "Page"; // multi-page Page Text
  186. var ew_MultiPageOf = "of"; // multi-page Of Text
  187. var ew_MultiPagePrev = "Prev"; // multi-page Prev Text
  188. var ew_MultiPageNext = "Next"; // multi-page Next Text
  189. //-->
  190. </script>
  191. <script language="JavaScript" type="text/javascript">
  192. <!--
  193. // Write your client script here, no need to add script tags.
  194. // To include another .js script, use:
  195. // ew_ClientScriptInclude("my_javascript.js");
  196. //-->
  197. </script>
  198. <p><span class="phpmaker">Add to TABLE: Applications<br><br><a href="<?php echo $osj2Dapplications->getReturnUrl() ?>">Go Back</a></span></p>
  199. <?php
  200. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Mesasge in Session, display
  201. ?>
  202. <p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
  203. <?php
  204. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
  205. }
  206. ?>
  207. <form name="fosj2Dapplicationsadd" id="fosj2Dapplicationsadd" action="osj-osj2dapplicationsadd.php" method="post" enctype="multipart/form-data" onSubmit="return ew_ValidateForm(this);">
  208. <p>
  209. <input type="hidden" name="a_add" id="a_add" value="A">
  210. <table class="ewTable">
  211. <tr class="ewTableRow">
  212. <td class="ewTableHeader">Resume<span class='ewmsg'>&nbsp;*</span></td>
  213. <td<?php echo $osj2Dapplications->resume_id->CellAttributes() ?>><span id="cb_x_resume_id">
  214. <select id="x_resume_id" name="x_resume_id"<?php echo $osj2Dapplications->resume_id->EditAttributes() ?>>
  215. <!--option value="">Please Select</option-->
  216. <?php
  217. if (is_array($osj2Dapplications->resume_id->EditValue)) {
  218. $arwrk = $osj2Dapplications->resume_id->EditValue;
  219. $rowswrk = count($arwrk);
  220. for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
  221. $selwrk = (strval($osj2Dapplications->resume_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";
  222. ?>
  223. <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
  224. <?php echo $arwrk[$rowcntwrk][1] ?>
  225. </option>
  226. <?php
  227. }
  228. }
  229. ?>
  230. </select>
  231. </span></td>
  232. </tr>
  233. <tr class="ewTableAltRow">
  234. <td class="ewTableHeader">Post ID<span class='ewmsg'>&nbsp;*</span></td>
  235. <td<?php echo $osj2Dapplications->post_id->CellAttributes() ?>><span id="cb_x_post_id">
  236. <input type="text" name="x_post_id" id="x_post_id" size="30" value="<?php echo $osj2Dapplications->post_id->EditValue ?>"<?php echo $osj2Dapplications->post_id->EditAttributes() ?>>
  237. </span></td>
  238. </tr>
  239. <tr class="ewTableRow">
  240. <td class="ewTableHeader">Application Email<span class='ewmsg'>&nbsp;*</span></td>
  241. <td<?php echo $osj2Dapplications->application_email->CellAttributes() ?>><span id="cb_x_application_email">
  242. <input type="text" name="x_application_email" id="x_application_email" title="Email" size="30" maxlength="255" value="<?php echo $osj2Dapplications->application_email->EditValue ?>"<?php echo $osj2Dapplications->application_email->EditAttributes() ?>>
  243. </span></td>
  244. </tr>
  245. <tr class="ewTableAltRow">
  246. <td class="ewTableHeader">Application Comments<span class='ewmsg'>&nbsp;*</span></td>
  247. <td<?php echo $osj2Dapplications->application_text->CellAttributes() ?>><span id="cb_x_application_text">
  248. <textarea name="x_application_text" id="x_application_text" cols="35" rows="4"<?php echo $osj2Dapplications->application_text->EditAttributes() ?>><?php echo $osj2Dapplications->application_text->EditValue ?></textarea>
  249. </span></td>
  250. </tr>
  251. <tr class="ewTableRow">
  252. <td class="ewTableHeader">Application Attachment<span class='ewmsg'>&nbsp;*</span></td>
  253. <td<?php echo $osj2Dapplications->application_file->CellAttributes() ?>><span id="cb_x_application_file">
  254. <input type="file" name="x_application_file" id="x_application_file" title="Resume Attachment" size="30"<?php echo $osj2Dapplications->application_file->EditAttributes() ?>>
  255. </span></td>
  256. </tr>
  257. <tr class="ewTableAltRow">
  258. <td class="ewTableHeader">Application File Name<span class='ewmsg'>&nbsp;*</span></td>
  259. <td<?php echo $osj2Dapplications->application_file_name->CellAttributes() ?>><span id="cb_x_application_file_name">
  260. <input type="text" name="x_application_file_name" id="x_application_file_name" title="Resume Attachment Filename" size="30" maxlength="255" value="<?php echo $osj2Dapplications->application_file_name->EditValue ?>"<?php echo $osj2Dapplications->application_file_name->EditAttributes() ?>>
  261. </span></td>
  262. </tr>
  263. </table>
  264. <p>
  265. <input type="submit" name="btnAction" id="btnAction" value=" Add ">
  266. </form>
  267. <script language="JavaScript" type="text/javascript">
  268. <!--
  269. // Write your table-specific startup script here
  270. // document.write("page loaded");
  271. //-->
  272. </script>
  273. <?php include "osj-footer.php" ?>
  274. <?php
  275. // If control is passed here, simply terminate the page without redirect
  276. Page_Terminate();
  277. // -----------------------------------------------------------------
  278. // Subroutine Page_Terminate
  279. // - called when exit page
  280. // - clean up connection and objects
  281. // - if url specified, redirect to url, otherwise end response
  282. function Page_Terminate($url = "") {
  283. global $conn;
  284. // Page unload event, used in current page
  285. Page_Unload();
  286. // Global page unloaded event (in userfn*.php)
  287. Page_Unloaded();
  288. // Close Connection
  289. $conn->Close();
  290. // Go to url if specified
  291. if ($url <> "") {
  292. ob_end_clean();
  293. header("Location: $url");
  294. }
  295. exit();
  296. }
  297. ?>
  298. <?php
  299. // Function Get upload files
  300. function GetUploadFiles() {
  301. global $objForm, $osj2Dapplications;
  302. // Get upload data
  303. if ($osj2Dapplications->application_file->Upload->UploadFile()) {
  304. // No action required
  305. } else {
  306. echo $osj2Dapplications->application_file->Upload->Message;
  307. exit();
  308. }
  309. }
  310. ?>
  311. <?php
  312. // Load default values
  313. function LoadDefaultValues() {
  314. global $osj2Dapplications;
  315. $osj2Dapplications->user_id->CurrentValue = 0;
  316. $osj2Dapplications->resume_id->CurrentValue = 0;
  317. $osj2Dapplications->post_id->CurrentValue = $_REQUEST["post_id"];
  318. $osj2Dapplications->application_date->CurrentValue = "0000-00-00 00:00:00";
  319. $osj2Dapplications->application_file_name->CurrentValue = NULL; // Clear file related field
  320. }
  321. ?>
  322. <?php
  323. // Load form values
  324. function LoadFormValues() {
  325. // Load from form
  326. global $objForm, $osj2Dapplications;
  327. $osj2Dapplications->user_id->setFormValue($objForm->GetValue("x_user_id"));
  328. $osj2Dapplications->resume_id->setFormValue($objForm->GetValue("x_resume_id"));
  329. $osj2Dapplications->post_id->setFormValue($objForm->GetValue("x_post_id"));
  330. $osj2Dapplications->application_date->setFormValue($objForm->GetValue("x_application_date"));
  331. $osj2Dapplications->application_date->CurrentValue = ew_UnFormatDateTime($osj2Dapplications->application_date->CurrentValue, 6);
  332. $osj2Dapplications->application_email->setFormValue($objForm->GetValue("x_application_email"));
  333. $osj2Dapplications->application_text->setFormValue($objForm->GetValue("x_application_text"));
  334. }
  335. // Restore form values
  336. function RestoreFormValues() {
  337. global $osj2Dapplications;
  338. $osj2Dapplications->user_id->CurrentValue = $osj2Dapplications->user_id->FormValue;
  339. $osj2Dapplications->resume_id->CurrentValue = $osj2Dapplications->resume_id->FormValue;
  340. $osj2Dapplications->post_id->CurrentValue = $osj2Dapplications->post_id->FormValue;
  341. $osj2Dapplications->application_date->CurrentValue = $osj2Dapplications->application_date->FormValue;
  342. $osj2Dapplications->application_date->CurrentValue = ew_UnFormatDateTime($osj2Dapplications->application_date->CurrentValue, 6);
  343. $osj2Dapplications->application_email->CurrentValue = $osj2Dapplications->application_email->FormValue;
  344. $osj2Dapplications->application_text->CurrentValue = $osj2Dapplications->application_text->FormValue;
  345. }
  346. ?>
  347. <?php
  348. // Load row based on key values
  349. function LoadRow() {
  350. global $conn, $Security, $osj2Dapplications;
  351. $sFilter = $osj2Dapplications->SqlKeyFilter();
  352. if (!is_numeric($osj2Dapplications->application_id->CurrentValue)) {
  353. return FALSE; // Invalid key, exit
  354. }
  355. $sFilter = str_replace("@application_id@", ew_AdjustSql($osj2Dapplications->application_id->CurrentValue), $sFilter); // Replace key value
  356. if ($Security->CurrentUserID() <> "" && !$Security->IsAdmin()) { // Non system admin
  357. $sFilter = $osj2Dapplications->AddUserIDFilter($sFilter, $Security->CurrentUserID()); // Add User ID filter
  358. }
  359. // Call Row Selecting event
  360. $osj2Dapplications->Row_Selecting($sFilter);
  361. // Load sql based on filter
  362. $osj2Dapplications->CurrentFilter = $sFilter;
  363. $sSql = $osj2Dapplications->SQL();
  364. if ($rs = $conn->Execute($sSql)) {
  365. if ($rs->EOF) {
  366. $LoadRow = FALSE;
  367. } else {
  368. $LoadRow = TRUE;
  369. $rs->MoveFirst();
  370. LoadRowValues($rs); // Load row values
  371. // Call Row Selected event
  372. $osj2Dapplications->Row_Selected($rs);
  373. }
  374. $rs->Close();
  375. } else {
  376. $LoadRow = FALSE;
  377. }
  378. return $LoadRow;
  379. }
  380. // Load row values from recordset
  381. function LoadRowValues(&$rs) {
  382. global $osj2Dapplications;
  383. $osj2Dapplications->application_id->setDbValue($rs->fields('application_id'));
  384. $osj2Dapplications->user_id->setDbValue($rs->fields('user_id'));
  385. $osj2Dapplications->resume_id->setDbValue($rs->fields('resume_id'));
  386. $osj2Dapplications->post_id->setDbValue($rs->fields('post_id'));
  387. $osj2Dapplications->application_date->setDbValue($rs->fields('application_date'));
  388. $osj2Dapplications->application_email->setDbValue($rs->fields('application_email'));
  389. $osj2Dapplications->application_text->setDbValue($rs->fields('application_text'));
  390. $osj2Dapplications->application_file->Upload->DbValue = $rs->fields('application_file');
  391. $osj2Dapplications->application_file_name->setDbValue($rs->fields('application_file_name'));
  392. }
  393. ?>
  394. <?php
  395. // Render row values based on field settings
  396. function RenderRow() {
  397. global $conn, $Security, $osj2Dapplications;
  398. // Call Row Rendering event
  399. $osj2Dapplications->Row_Rendering();
  400. // Common render codes for all row types
  401. // user_id
  402. $osj2Dapplications->user_id->CellCssStyle = "";
  403. $osj2Dapplications->user_id->CellCssClass = "";
  404. // resume_id
  405. $osj2Dapplications->resume_id->CellCssStyle = "";
  406. $osj2Dapplications->resume_id->CellCssClass = "";
  407. // post_id
  408. $osj2Dapplications->post_id->CellCssStyle = "";
  409. $osj2Dapplications->post_id->CellCssClass = "";
  410. // application_date
  411. $osj2Dapplications->application_date->CellCssStyle = "";
  412. $osj2Dapplications->application_date->CellCssClass = "";
  413. // application_email
  414. $osj2Dapplications->application_email->CellCssStyle = "";
  415. $osj2Dapplications->application_email->CellCssClass = "";
  416. // application_text
  417. $osj2Dapplications->application_text->CellCssStyle = "";
  418. $osj2Dapplications->application_text->CellCssClass = "";
  419. // application_file
  420. $osj2Dapplications->application_file->CellCssStyle = "";
  421. $osj2Dapplications->application_file->CellCssClass = "";
  422. // application_file_name
  423. $osj2Dapplications->application_file_name->CellCssStyle = "";
  424. $osj2Dapplications->application_file_name->CellCssClass = "";
  425. if ($osj2Dapplications->RowType == EW_ROWTYPE_VIEW) { // View row
  426. } elseif ($osj2Dapplications->RowType == EW_ROWTYPE_ADD) { // Add row
  427. // resume_id
  428. $osj2Dapplications->resume_id->EditCustomAttributes = "";
  429. $sSqlWrk = "SELECT `resume_id`, `resume_title` FROM `osj-resumes`";
  430. $sSqlWrk .= " WHERE (" . "`user_id` = ".CurrentUserID()."" . ")";
  431. $sSqlWrk .= " ORDER BY `resume_title` Asc";
  432. $rswrk = $conn->Execute($sSqlWrk);
  433. $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
  434. if ($rswrk) $rswrk->Close();
  435. array_unshift($arwrk, array("", "Please Select"));
  436. $osj2Dapplications->resume_id->EditValue = $arwrk;
  437. // post_id
  438. $osj2Dapplications->post_id->EditCustomAttributes = "";
  439. $osj2Dapplications->post_id->EditValue = ew_HtmlEncode($osj2Dapplications->post_id->CurrentValue);
  440. // application_email
  441. $osj2Dapplications->application_email->EditCustomAttributes = "";
  442. $osj2Dapplications->application_email->EditValue = ew_HtmlEncode($osj2Dapplications->application_email->CurrentValue);
  443. // application_text
  444. $osj2Dapplications->application_text->EditCustomAttributes = "";
  445. $osj2Dapplications->application_text->EditValue = ew_HtmlEncode($osj2Dapplications->application_text->CurrentValue);
  446. // application_file
  447. $osj2Dapplications->application_file->EditCustomAttributes = "";
  448. $osj2Dapplications->application_file->EditValue = $osj2Dapplications->application_file->CurrentValue;
  449. // application_file_name
  450. $osj2Dapplications->application_file_name->EditCustomAttributes = "";
  451. $osj2Dapplications->application_file_name->EditValue = ew_HtmlEncode($osj2Dapplications->application_file_name->CurrentValue);
  452. } elseif ($osj2Dapplications->RowType == EW_ROWTYPE_EDIT) { // Edit row
  453. } elseif ($osj2Dapplications->RowType == EW_ROWTYPE_SEARCH) { // Search row
  454. }
  455. // Call Row Rendered event
  456. $osj2Dapplications->Row_Rendered();
  457. }
  458. ?>
  459. <?php
  460. // Add record
  461. function AddRow() {
  462. global $conn, $Security, $osj2Dapplications;
  463. // Check for duplicate key
  464. $bCheckKey = TRUE;
  465. $sFilter = $osj2Dapplications->SqlKeyFilter();
  466. if (trim(strval($osj2Dapplications->application_id->CurrentValue)) == "") {
  467. $bCheckKey = FALSE;
  468. } else {
  469. $sFilter = str_replace("@application_id@", ew_AdjustSql($osj2Dapplications->application_id->CurrentValue), $sFilter); // Replace key value
  470. }
  471. if (!is_numeric($osj2Dapplications->application_id->CurrentValue)) {
  472. $bCheckKey = FALSE;
  473. }
  474. if ($bCheckKey) {
  475. $rsChk = $osj2Dapplications->LoadRs($sFilter);
  476. if ($rsChk && !$rsChk->EOF) {
  477. $_SESSION[EW_SESSION_MESSAGE] = "Duplicate value for primary key";
  478. $rsChk->Close();
  479. return FALSE;
  480. }
  481. }
  482. $rsnew = array();
  483. // Field user_id
  484. $osj2Dapplications->user_id->SetDbValueDef(CurrentUserID(), 0);
  485. $rsnew['user_id'] =& $osj2Dapplications->user_id->DbValue;
  486. // Field resume_id
  487. $osj2Dapplications->resume_id->SetDbValueDef($osj2Dapplications->resume_id->CurrentValue, 0);
  488. $rsnew['resume_id'] =& $osj2Dapplications->resume_id->DbValue;
  489. // Field post_id
  490. $osj2Dapplications->post_id->SetDbValueDef($osj2Dapplications->post_id->CurrentValue, 0);
  491. $rsnew['post_id'] =& $osj2Dapplications->post_id->DbValue;
  492. // Field application_date
  493. $osj2Dapplications->application_date->SetDbValueDef(ew_CurrentDateTime(), ew_CurrentDate());
  494. $rsnew['application_date'] =& $osj2Dapplications->application_date->DbValue;
  495. // Field application_email
  496. $osj2Dapplications->application_email->SetDbValueDef($osj2Dapplications->application_email->CurrentValue, "");
  497. $rsnew['application_email'] =& $osj2Dapplications->application_email->DbValue;
  498. // Field application_text
  499. $osj2Dapplications->application_text->SetDbValueDef($osj2Dapplications->application_text->CurrentValue, "");
  500. $rsnew['application_text'] =& $osj2Dapplications->application_text->DbValue;
  501. // Field application_file
  502. $osj2Dapplications->application_file->Upload->SaveToSession(); // Save file value to Session
  503. if (is_null($osj2Dapplications->application_file->Upload->Value)) {
  504. $rsnew['application_file'] = NULL;
  505. } else {
  506. $rsnew['application_file'] = $osj2Dapplications->application_file->Upload->GetBinary();
  507. }
  508. $osj2Dapplications->application_file_name->SetDbValueDef($osj2Dapplications->application_file->Upload->FileName, "");
  509. $rsnew['application_file_name'] =& $osj2Dapplications->application_file_name->DbValue;
  510. // Field application_file_name
  511. // Call Row Inserting event
  512. $bInsertRow = $osj2Dapplications->Row_Inserting($rsnew);
  513. if ($bInsertRow) {
  514. // Field application_file
  515. $conn->raiseErrorFn = 'ew_ErrorFn';
  516. $AddRow = $conn->Execute($osj2Dapplications->InsertSQL($rsnew));
  517. $conn->raiseErrorFn = '';
  518. } else {
  519. if ($osj2Dapplications->CancelMessage <> "") {
  520. $_SESSION[EW_SESSION_MESSAGE] = $osj2Dapplications->CancelMessage;
  521. $osj2Dapplications->CancelMessage = "";
  522. } else {
  523. $_SESSION[EW_SESSION_MESSAGE] = "Insert cancelled";
  524. }
  525. $AddRow = FALSE;
  526. }
  527. if ($AddRow) {
  528. $osj2Dapplications->application_id->setDbValue($conn->Insert_ID());
  529. $rsnew['application_id'] =& $osj2Dapplications->application_id->DbValue;
  530. // Call Row Inserted event
  531. $osj2Dapplications->Row_Inserted($rsnew);
  532. WriteAuditTrailOnAdd($rsnew);
  533. if ($osj2Dapplications->SendEmail) SendEmailOnAdd($rsnew);
  534. }
  535. // Field application_file
  536. $osj2Dapplications->application_file->Upload->RemoveFromSession(); // Remove file value from Session
  537. return $AddRow;
  538. }
  539. ?>
  540. <?php
  541. // Write Audit Trail start/end for grid update
  542. function WriteAuditTrailDummy($typ) {
  543. $table = 'osj-applications';
  544. // Write Audit Trail
  545. $filePfx = "log";
  546. $curDate = date("Y/m/d");
  547. $curTime = date("H:i:s");
  548. $id = ew_ScriptName();
  549. $user = CurrentUserID();
  550. $action = $typ;
  551. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
  552. }
  553. ?>
  554. <?php
  555. // Write Audit Trail (add page)
  556. function WriteAuditTrailOnAdd(&$rs) {
  557. global $osj2Dapplications;
  558. $table = 'osj-applications';
  559. // Get key value
  560. $key = "";
  561. if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
  562. $key .= $rs['application_id'];
  563. // Write Audit Trail
  564. $filePfx = "log";
  565. $curDate = date("Y/m/d");
  566. $curTime = date("H:i:s");
  567. $id = ew_ScriptName();
  568. $user = CurrentUserID();
  569. $action = "A";
  570. $oldvalue = "";
  571. foreach (array_keys($rs) as $fldname) {
  572. if ($osj2Dapplications->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
  573. $newvalue = ($osj2Dapplications->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) ? "<MEMO>" : $rs[$fldname]; // Memo Field
  574. ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
  575. }
  576. }
  577. }
  578. ?>
  579. <?php
  580. // Send email after add success
  581. function SendEmailOnAdd(&$rs) {
  582. $sFn = "txt/notify.txt";
  583. $sTable = 'osj-applications';
  584. $sSubject = $sTable . " record inserted";
  585. $sAction = "Inserted";
  586. // Get key value
  587. $sKey = "";
  588. if ($sKey <> "") $sKey .= EW_COMPOSITE_KEY_SEPARATOR;
  589. $sKey .= $rs['application_id'];
  590. ew_SendNotifyEmail($sFn, $sSubject, $sTable, $sKey, $sAction);
  591. }
  592. ?>
  593. <?php
  594. // Page Load event
  595. function Page_Load() {
  596. //echo "Page Load";
  597. }
  598. // Page Unload event
  599. function Page_Unload() {
  600. //echo "Page Unload";
  601. }
  602. ?>