Support for Active Directory (#463)
[openemr.git] / library / ESign / Form / Controller.php
blobf31d27f3fb1ad516627d144bbadaf2ed83834865
1 <?php
3 namespace ESign;
5 /**
6 * Form controller implementation
7 *
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>;.
21 * @package OpenEMR
22 * @author Ken Chapple <ken@mi-squared.com>
23 * @author Medical Information Integration, LLC
24 * @link http://www.open-emr.org
25 **/
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
35 /**
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'];
46 $form->action = '#';
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;
54 $this->_view->form = $form;
55 $this->setViewScript( 'form/esign_form.php' );
56 $this->render();
59 public function esign_log_view()
61 $formId = $this->getRequest()->getParam( 'formId', '' );
62 $formDir = $this->getRequest()->getParam( 'formDir', '' );
63 $encounterId = $this->getRequest()->getParam( 'encounterId', '' );
64 $factory = new Form_Factory( $formId, $formDir, $encounterId );
65 $signable = $factory->createSignable(); // Contains features that make object signable
66 $log = $factory->createLog(); // Make the log behavior
67 $html = $log->getHtml( $signable );
68 echo $html;
69 exit;
72 /**
74 * @return multitype:string
76 public function esign_form_submit()
78 $message = '';
79 $status = self::STATUS_FAILURE;
80 $password = $this->getRequest()->getParam( 'password', '' );
81 $formId = $this->getRequest()->getParam( 'formId', '' );
82 $formDir = $this->getRequest()->getParam( 'formDir', '' );
83 $encounterId = $this->getRequest()->getParam( 'encounterId', '' );
84 // Always lock, unless esign_lock_toggle option is enable in globals
85 $lock = true;
86 if ( $GLOBALS['esign_lock_toggle'] ) {
87 $lock = ( $this->getRequest()->getParam( 'lock', '' ) == 'on' ) ? true : false;
89 $amendment = $this->getRequest()->getParam( 'amendment', '' );
91 if($GLOBALS['use_active_directory']) {
92 $valid = active_directory_validation($_SESSION['authUser'], $password);
93 }else {
94 $valid = confirm_user_password($_SESSION['authUser'], $password);
97 if ($valid) {
98 $factory = new Form_Factory( $formId, $formDir, $encounterId );
99 $signable = $factory->createSignable();
100 if ( $signable->sign( $_SESSION['authUserID'], $lock, $amendment ) ) {
101 $message = xlt( "Form signed successfully" );
102 $status = self::STATUS_SUCCESS;
103 } else {
104 $message = xlt( "An error occured signing the form" );
107 } else {
108 $message = xlt( "The password you entered is invalid" );
110 $response = new Response( $status, $message );
111 $response->formId = $formId;
112 $response->formDir = $formDir;
113 $response->encounterId = $encounterId;
114 $response->locked = $lock;
115 $response->editButtonHtml = "";
116 if ( $lock ) {
117 // If we're locking the form, replace the edit button with a "disabled" lock button
118 $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>";
120 echo json_encode( $response );
121 exit;