The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / clickmap / C_AbstractClickmap.php
blobf5e9d64a458d5492f24d7a7b4e8f8a58a16b55fa
1 <?php
2 /*
3 * Copyright Medical Information Integration,LLC info@mi-squared.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * @file C_AbstractClickmap.php
11 * @brief This file contains the C_AbstractClickmap class, used to control smarty.
14 /* for $GLOBALS['concurrent_layout','encounter','fileroot','pid','srcdir','style','webroot']
15 * remember that include paths are calculated relative to the including script, not this file.
16 * to lock the path to this script (so if called from different scripts) use the dirname(FILE) variable
18 require_once('../../globals.php');
20 /* For Controller, the class we're extending. */
21 require_once ($GLOBALS['srcdir'] . '/classes/Controller.class.php');
23 /* For the addform() function */
24 require_once ($GLOBALS['srcdir'] . '/forms.inc');
26 /**
27 * @class C_AbstractClickmap
29 * @brief This class extends the Controller class, which is used to control the smarty templating engine.
32 abstract class C_AbstractClickmap extends Controller {
33 /**
34 * the directory to find our template file in.
36 * @var template_dir
38 var $template_dir;
40 /**
41 * @brief Initialize a newly created object belonging to this class
43 * @param template_mod
44 * template module name, passed to Controller's initializer.
46 function C_AbstractClickmap($template_mod = "general") {
47 parent::Controller();
48 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
49 $this->template_mod = $template_mod;
50 $this->template_dir = $GLOBALS['fileroot'] . "/interface/clickmap/template/";
51 $this->assign("DONT_SAVE_LINK",$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl");
52 $this->assign("FORM_ACTION", $GLOBALS['webroot']);
53 $this->assign("STYLE", $GLOBALS['style']);
56 /**
57 * @brief Override this abstract function with your implementation of createModel.
59 * @param $form_id
60 * An optional id of a form, to populate data from.
62 * @return Model
63 * An AbstractClickmapModel derived Object.
65 abstract public function createModel($form_id="");
67 /**
68 * @brief Override this abstract function with your implememtation of getImage
70 * @return The path to the image backing this form relative to the webroot.
72 abstract function getImage();
74 /**
75 * @brief Override this abstract function to return the label of the optionlists on this form.
77 * @return The label used for all dropdown boxes on this form.
79 abstract function getOptionsLabel();
81 /**
82 * @brief Override this abstract functon to return a hash of the optionlist (key=>value pairs).
84 * @return A hash of key=>value pairs, representing all the possible options in the dropdown boxes on this form.
86 abstract function getOptionList();
88 /**
89 * @brief set up the passed in Model object to model the form.
91 private function set_context( $model ) {
92 $root = $GLOBALS['webroot'] . "/interface/clickmap";
93 $model->saveAction = $GLOBALS['webroot'] . "/interface/forms/" . $model->getCode() . "/save.php";
94 $model->template_dir = $root . "/template";
95 $model->image = $this->getImage();
96 $optionList = $this->getOptionList();
97 $model->optionList = $optionList != null ? json_encode($optionList) : "null";
98 $optionsLabel = $this->getOptionsLabel();
99 $model->optionsLabel = isset($optionsLabel) ? "'" . $optionsLabel . "'" : "null";
101 $data = $model->get_data();
102 $model->data = $data != "" ? "'" . $data . "'" : "null";
103 $model->hideNav = "false";
107 * @brief generate an html document from the 'new form' template
109 * @return the result of smarty's fetch() operation.
111 function default_action() {
112 $model = $this->createModel();
113 $this->assign("form", $model);
114 $this->set_context($model);
115 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
119 * @brief generate an html document from the 'new form' template, populated with form data from the passed in form_id.
121 * @param form_id
122 * The id of the form to populate data from.
124 * @return the result of smarty's fetch() operation.
126 function view_action($form_id) {
127 $model = $this->createModel($form_id);
128 $this->assign("form",$model);
129 $this->set_context($model);
130 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
134 * @brief generate a fragment of an HTML document from the 'new form' template, populated with form data from the passed in form_id.
136 * @param form_id
137 * The id of the form to populate data from.
139 * @return the result of smarty's fetch() operation.
141 function report_action($form_id) {
142 $model = $this->createModel($form_id);
143 $this->assign("form",$model);
144 $this->set_context($model);
145 $model->hideNav = "true";
146 return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
150 * @brief called to store the submitted form's contents to the database, adding the form to the encounter if necissary.
152 function default_action_process() {
153 if ($_POST['process'] != "true") {
154 return;
156 $this->model = $this->createModel($_POST['id']);
157 parent::populate_object($this->model);
158 $this->model->persist();
159 if ($GLOBALS['encounter'] == "") {
160 $GLOBALS['encounter'] = date("Ymd");
162 if(empty($_POST['id'])) {
163 addForm($GLOBALS['encounter'],
164 $this->model->getTitle(),
165 $this->model->id,
166 $this->model->getCode(),
167 $GLOBALS['pid'],
168 $_SESSION['userauthorized']
170 $_POST['process'] = "";