From a76d9e250615affea2718ecf16c9233f320d87b3 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 10 Dec 2014 10:20:13 -0500 Subject: [PATCH] Adding css files for view and print in admin --- controllers/admin.php | 12 +- controllers/front.php | 135 +++++++++++++++++----- css/admin-print-application.css | 45 ++++++++ css/admin-view-application.css | 15 +++ js/jquery.print-preview.js | 192 +++++++++++++++++++++++++++++++ models/forms/settings.php | 2 +- models/forms/settings2.php | 154 +++++++++++++++++++++++++ views/admin/form_1.php | 85 +++++++------- views/admin/view-application.php | 16 +-- views/front/form_1.php | 12 +- 10 files changed, 574 insertions(+), 94 deletions(-) create mode 100644 css/admin-print-application.css create mode 100644 css/admin-view-application.css create mode 100644 js/jquery.print-preview.js create mode 100644 models/forms/settings2.php diff --git a/controllers/admin.php b/controllers/admin.php index e1e8267..ecb8d9f 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -81,14 +81,18 @@ class glm_employment_admin $data = $this->wpdb->get_row($sql, ARRAY_A); if ($data) { $sql = " - SELECT * - FROM " . $this->wpdb->prefix . GLM_EMP_FORM_TABLE . " - WHERE application = $id"; + SELECT * + FROM " . $this->wpdb->prefix . GLM_EMP_FORM_TABLE . " + WHERE application = $id + ORDER BY form_part"; $formData = $this->wpdb->get_results($sql, ARRAY_A); + foreach ($formData as $form) { + $forms[] = unserialize($formData[0]['form_data']); + } } echo '
'; $viewPath = $this->pluginDirName . 'views/admin/'; - $form1 = unserialize($formData[0]['form_data']); +// $form1 = unserialize($formData[0]['form_data']); include $viewPath . 'view-application.php'; echo '
'; } diff --git a/controllers/front.php b/controllers/front.php index baa4f05..519e260 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -9,7 +9,6 @@ defined('ABSPATH') or die(); */ class glm_employment_front { - public $pluginDirName; public $formSuccess; public $formFail; @@ -39,6 +38,7 @@ class glm_employment_front $this->set_form_state(); $this->formTable = $wpdb->prefix . GLM_EMP_FORM_TABLE; $this->appTable = $wpdb->prefix . GLM_EMP_APPLICATION_TABLE; + add_action('init', array($this, 'startJobSession')); } public function set_form_state() @@ -70,42 +70,70 @@ class glm_employment_front $applyOnline = (isset($_REQUEST[self::FORM_VAR])) ? filter_var($_REQUEST[self::FORM_VAR], FILTER_VALIDATE_INT) : false; + // form Action + $formAction = ''; +// $formPart = $applyOnline; switch ($applyOnline) { case 1: + unset($_SESSION['glmJobsApplication'], $_SESSION['glmJobsAppForm']); include $this->pluginDirName . 'models/forms/settings.php'; + $formPart = 2; include $this->pluginDirName . 'views/front/form_1.php'; break; case 2: if ($this->formSubmitted) { include $this->pluginDirName . 'models/forms/settings.php'; - $this->form_process(1, $form1); - var_dump($this->fname); - if ($this->fname) { - $this->store_application_data($form1); - } - if ($this->appId) { - $this->store_form_data($form1, 1); + $this->form_process(1, $form); + $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); + if (!$appId) { + // insert new application and form data + if ($this->fname) { + $this->store_application_data($form); + } + if ($this->appId) { + $this->store_form_data($form, 1); + } + } else { + // need to update form data } - echo '
'.print_r($this->appId, true).'
'; - echo '
'.print_r($this->formId, true).'
'; -// echo '
'.print_r($form1, true).'
'; -// echo '
'.print_r($_POST, true).'
'; -// extract($_POST); if ($this->errorCount > 0) { include $this->pluginDirName . 'views/front/form_1.php'; } else { - + $formPart = 3; + $appId = $this->appId; + include $this->pluginDirName . 'models/forms/settings2.php'; + include $this->pluginDirName . 'views/front/form_1.php'; } + } else { + wp_die('An Error!:('); } break; case 3: + if ($this->formSubmitted) { + include $this->pluginDirName . 'models/forms/settings2.php'; + $this->form_process(1, $form); + $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); + + if ($this->errorCount > 0) { + include $this->pluginDirName . 'views/front/form_1.php'; + } else { + $formPart = 4; + include $this->pluginDirName . 'models/forms/settings3.php'; + include $this->pluginDirName . 'views/front/form_1.php'; + } + } else { + wp_die('An Error!:('); + } break; } + echo '
'.print_r($_SESSION, true).'
'; } public function store_application_data($form) { - var_dump($this->appTable); + if ($this->appId = filter_var($_SESSION['glmJobsApplication'], FILTER_VALIDATE_INT)) { + return; + } $this->wpdb->insert( $this->appTable, array( @@ -122,26 +150,64 @@ class glm_employment_front ) ); $this->appId = $this->wpdb->insert_id; + $_SESSION['glmJobsApplication'] = $this->appId; } public function store_form_data($form, $form_part) { - $this->wpdb->insert( - $this->formTable, - array( - 'create_time' => date('Y-m-d, h:i:s a'), - 'application' => $this->appId, - 'form_data' => serialize($form), - 'form_part' => $form_part - ), - array( - '%s', - '%d', - '%s', - '%d' - ) - ); + if ( $this->formId = filter_var($_SESSION['glmJobsAppForm']['id'], FILTER_VALIDATE_INT) + && $form_part = $_SESSION['glmJobsAppForm']['part'] + ) { + return; + } + // check if there's one stored first + $sql = " + SELECT id + FROM {$this->formTable} + WHERE application = {$this->appId} + AND form_part = {$form_part}"; + $formData = $this->wpdb->get_row($sql); + if ($formData) { + $this->wpdb->replace( + $this->formTable, + array( + 'id' => $formData['id'], + 'create_time' => date('Y-m-d, h:i:s a'), + 'application' => $this->appId, + 'form_data' => serialize($form), + 'form_part' => $form_part + ), + array( + '%d', + '%s', + '%d', + '%s', + '%d' + ) + ); + } else { + $this->wpdb->insert( + $this->formTable, + array( + 'create_time' => date('Y-m-d, h:i:s a'), + 'application' => $this->appId, + 'form_data' => serialize($form), + 'form_part' => $form_part + ), + array( + '%s', + '%d', + '%s', + '%d' + ) + ); + } + $this->formId = $this->wpdb->insert_id; + $_SESSION['glmJobsAppForm'] = array( + 'id' => $this->formId, + 'part' => $form_part + ); } public function form_process($part, &$form) @@ -150,7 +216,7 @@ class glm_employment_front switch($part) { case 1: include $this->pluginDirName . 'models/forms/settings.php'; - foreach ($form1 as $rowKey => $row) { + foreach ($form as $rowKey => $row) { if ($row['type'] != 'header') { foreach ($row as $fieldKey => $field) { $form[$rowKey][$fieldKey]['value'] @@ -335,4 +401,11 @@ class glm_employment_front $this->pluginDirName = $dir; } + public function startJobSession() + { + if (!session_id()) { + session_start(); + } + } + } diff --git a/css/admin-print-application.css b/css/admin-print-application.css new file mode 100644 index 0000000..c81f03e --- /dev/null +++ b/css/admin-print-application.css @@ -0,0 +1,45 @@ +.large-1 { + width: 8.33333%; } +.large-2 { + width: 16.66667%; } +.large-3 { + width: 25%; } +.large-4 { + width: 33.33333%; } +.large-5 { + width: 41.66667%; } +.large-6 { + width: 50%; } +.large-7 { + width: 58.33333%; } +.large-8 { + width: 66.66667%; } +.large-9 { + width: 75%; } +.large-10 { + width: 83.33333%; } +.large-11 { + width: 91.66667%; } +.large-12 { + width: 100%; } +#adminmenuback, #adminmenuwrap, #wpadminbar, #wpfooter { + display: none; +} +#appForm { + width: 100%; + background-color: #fff; + border-color: 1px solid red; +} +#appForm span { + font-size: 13px; +} +#wpcontent { + margin-left: 0; + padding-left: 0; + margin-top: 0; +} +body {background: white;font-size: 12pt;} +html.wp-toolbar {padding-top: 0;} +div.wrap {padding-top: 0;margin-top:0;} +h3 {page-break-before: auto;} +div.row {page-break-inside: avoid;} \ No newline at end of file diff --git a/css/admin-view-application.css b/css/admin-view-application.css new file mode 100644 index 0000000..dd8f7d6 --- /dev/null +++ b/css/admin-view-application.css @@ -0,0 +1,15 @@ +#appForm { + width: 700px; + max-width: 700px; + background-color: #fff; +} +#appForm span { + font-size: 13px; +} + +div.row { + border:1px solid black; + border-collapse: collapse; + display:table-row; +} +div.row > div {display:table-cell;padding:2px;} diff --git a/js/jquery.print-preview.js b/js/jquery.print-preview.js new file mode 100644 index 0000000..4565a48 --- /dev/null +++ b/js/jquery.print-preview.js @@ -0,0 +1,192 @@ +/*! + * jQuery Print Previw Plugin v1.0.1 + * + * Copyright 2011, Tim Connell + * Licensed under the GPL Version 2 license + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Date: Wed Jan 25 00:00:00 2012 -000 + */ + +(function($) { + + // Initialization + $.fn.printPreview = function() { + this.each(function() { + $(this).bind('click', function(e) { + e.preventDefault(); + if (!$('#print-modal').length) { + $.printPreview.loadPrintPreview(); + } + }); + }); + return this; + }; + + // Private functions + var mask, size, print_modal, print_controls; + $.printPreview = { + loadPrintPreview: function() { + // Declare DOM objects + print_modal = $(''); + print_controls = $('