6 * Form controller implementation
8 * Copyright (C) 2013 OEMR 501c3 www.oemr.org
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @author Ken Chapple <ken@mi-squared.com>
23 * @author Medical Information Integration, LLC
24 * @link http://www.open-emr.org
27 require_once $GLOBALS['srcdir'].'/ESign/Abstract/Controller.php';
28 require_once $GLOBALS['srcdir'].'/ESign/Form/Configuration.php';
29 require_once $GLOBALS['srcdir'].'/ESign/Form/Factory.php';
30 require_once $GLOBALS['srcdir'].'/ESign/Form/Log.php';
31 require_once $GLOBALS['srcdir'].'/authentication/login_operations.php';
33 class Form_Controller
extends Abstract_Controller
38 public function esign_form_view()
40 $form = new \
stdClass();
41 $form->table
= 'forms';
42 $form->formDir
= $this->getRequest()->getParam('formdir', '');
43 $form->formId
= $this->getRequest()->getParam('formid', 0);
44 $form->encounterId
= $this->getRequest()->getParam('encounterid', 0);
45 $form->userId
= $GLOBALS['authUserID'];
47 $signable = new Form_Signable($form->formId
, $form->formDir
, $form->encounterId
);
48 $form->showLock
= false;
49 if ($signable->isLocked() === false &&
50 $GLOBALS['lock_esign_individual'] &&
51 $GLOBALS['esign_lock_toggle'] ) {
52 $form->showLock
= true;
55 $this->_view
->form
= $form;
56 $this->setViewScript('form/esign_form.php');
60 public function esign_log_view()
62 $formId = $this->getRequest()->getParam('formId', '');
63 $formDir = $this->getRequest()->getParam('formDir', '');
64 $encounterId = $this->getRequest()->getParam('encounterId', '');
65 $factory = new Form_Factory($formId, $formDir, $encounterId);
66 $signable = $factory->createSignable(); // Contains features that make object signable
67 $log = $factory->createLog(); // Make the log behavior
68 $html = $log->getHtml($signable);
75 * @return multitype:string
77 public function esign_form_submit()
80 $status = self
::STATUS_FAILURE
;
81 $password = $this->getRequest()->getParam('password', '');
82 $formId = $this->getRequest()->getParam('formId', '');
83 $formDir = $this->getRequest()->getParam('formDir', '');
84 $encounterId = $this->getRequest()->getParam('encounterId', '');
85 // Always lock, unless esign_lock_toggle option is enable in globals
87 if ($GLOBALS['esign_lock_toggle']) {
88 $lock = ( $this->getRequest()->getParam('lock', '') == 'on' ) ?
true : false;
91 $amendment = $this->getRequest()->getParam('amendment', '');
93 if ($GLOBALS['use_active_directory']) {
94 $valid = active_directory_validation($_SESSION['authUser'], $password);
96 $valid = confirm_user_password($_SESSION['authUser'], $password);
100 $factory = new Form_Factory($formId, $formDir, $encounterId);
101 $signable = $factory->createSignable();
102 if ($signable->sign($_SESSION['authUserID'], $lock, $amendment)) {
103 $message = xlt("Form signed successfully");
104 $status = self
::STATUS_SUCCESS
;
106 $message = xlt("An error occured signing the form");
109 $message = xlt("The password you entered is invalid");
112 $response = new Response($status, $message);
113 $response->formId
= $formId;
114 $response->formDir
= $formDir;
115 $response->encounterId
= $encounterId;
116 $response->locked
= $lock;
117 $response->editButtonHtml
= "";
119 // If we're locking the form, replace the edit button with a "disabled" lock button
120 $response->editButtonHtml
= "<a href=# class='css_button_small form-edit-button-locked' id='form-edit-button-'".attr($formDir)."-".attr($formId)."><span>".xlt('Locked')."</span></a>";
123 echo json_encode($response);