Highway to PSR2
[openemr.git] / interface / modules / zend_modules / module / Application / src / Application / Plugin / CommonPlugin.php
blobc5a6f686cd219b40c240f199cfcec6dec0175003
1 <?php
2 /* +-----------------------------------------------------------------------------+
3 * OpenEMR - Open Source Electronic Medical Record
4 * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @author Remesh Babu S <remesh@zhservices.com>
19 * @author Chandni Babu <chandnib@zhservices.com>
20 * +------------------------------------------------------------------------------+
22 namespace Application\Plugin;
24 use Zend\Mvc\Controller\Plugin\AbstractPlugin;
25 use Application\Model\ApplicationTable;
26 use Application\Listener\Listener;
28 class CommonPlugin extends AbstractPlugin
30 protected $application;
32 /**
33 * Application Table Object
34 * Listener Oblect
35 * @param type $sm Service Manager
37 public function __construct($sm)
39 $sm->get('Zend\Db\Adapter\Adapter');
40 $this->application = new ApplicationTable();
41 $this->listenerObject = new Listener;
44 /**
45 * Function checkACL
46 * Plugin functions are easily access from any where in the project
47 * Call the ACL Check function zAclCheck from ApplicationTable
49 * @param int $useID
50 * @param string $sectionID
51 * @return type
53 public function checkACL($useID, $sectionID)
55 return $this->application->zAclCheck($useID, $sectionID);
58 /**
59 * Keyword color hightlight (primary keyword and secondary)
60 * ? - The question mark used for omit the error.
61 * Error occur in second word of the search keyword,
62 * if maches any of the letter in the html element
64 public function hightlight($str, $keywords = '')
67 $keywords = preg_replace('/\s\s+/', ' ', strip_tags(trim($keywords)));
68 $style = '???';
69 $style_i = 'highlight_i';
70 $var = '';
71 foreach (explode(' ', $keywords) as $keyword) {
72 $replacement = "<?? ?='" . $style . "'>" . trim($keyword). "</??>";
73 $var .= $replacement . " ";
74 $str = str_ireplace($keyword, $replacement, $str);
77 $str = str_ireplace(rtrim($var), "<?? ?='" . $style_i . "'>" . trim($keywords) . "</??>", $str);
78 $str = str_ireplace('???', 'highlight_i', $str);
79 $str = str_ireplace('??', 'span', $str);
80 $str = str_ireplace('?', 'class', $str);
81 return $str;
84 public function date_format($date, $output_format, $input_format)
86 $this->application = new ApplicationTable();
87 $date_formatted = $this->application->fixDate($date, $output_format, $input_format);
88 return $date_formatted;
91 public function escapeLimit($val)
93 return escape_limit($val);
97 * Insert the imprted data to audit master table
99 * @param var Array Details parsed from the CCR xml file
100 * @return audit_master_id Integer ID from audit_master table
102 public function insert_ccr_into_audit_data($var)
104 $appTable = new ApplicationTable();
105 $audit_master_id_to_delete = $var['audit_master_id_to_delete'];
106 $approval_status = $var['approval_status'];
107 $type = $var['type'];
108 $ip_address = $var['ip_address'];
109 $field_name_value_array = $var['field_name_value_array'];
110 $entry_identification_array = $var['entry_identification_array'];
112 if ($audit_master_id_to_delete) {
113 $qry = "DELETE from audit_details WHERE audit_master_id=?";
114 $appTable->zQuery($qry, array($audit_master_id_to_delete));
116 $qry = "DELETE from audit_master WHERE id=?";
117 $appTable->zQuery($qry, array($audit_master_id_to_delete));
120 $master_query = "INSERT INTO audit_master SET pid = ?,approval_status = ?,ip_address = ?,type = ?";
121 $result = $appTable->zQuery($master_query, array(0,$approval_status,$ip_address,$type));
122 $audit_master_id = $result->getGeneratedValue();
123 $detail_query = "INSERT INTO `audit_details` (`table_name`, `field_name`, `field_value`, `audit_master_id`, `entry_identification`) VALUES ";
124 $detail_query_array = '';
125 foreach ($field_name_value_array as $key => $val) {
126 foreach ($field_name_value_array[$key] as $cnt => $field_details) {
127 foreach ($field_details as $field_name => $field_value) {
128 $detail_query .= "(? ,? ,? ,? ,?),";
129 $detail_query_array[] = $key;
130 $detail_query_array[] = trim($field_name);
131 if (is_array($field_value)) {
132 if ($field_value['status']||$field_value['enddate']) {
133 $detail_query_array[] = trim($field_value['value'])."|".trim($field_value['status'])."|".trim($field_value['begdate']);
134 } else {
135 $detail_query_array[] = trim($field_value['value']);
137 } else {
138 $detail_query_array[] = trim($field_value);
141 $detail_query_array[] = $audit_master_id;
142 $detail_query_array[] = trim($entry_identification_array[$key][$cnt]);
147 $detail_query = substr($detail_query, 0, -1);
148 $detail_query = $detail_query.';';
149 $appTable->zQuery($detail_query, $detail_query_array);
150 return $audit_master_id;
153 public function getList($list_id, $selected = '', $opt = '')
155 $appTable = new ApplicationTable();
156 $this->listenerObject = new Listener;
157 $res = $appTable->zQuery("SELECT * FROM list_options WHERE list_id=? ORDER BY seq, title", array($list_id));
158 $i = 0;
159 if ($opt == 'search') {
160 $rows[$i] = array (
161 'value' => 'all',
162 'label' => $this->listenerObject->z_xlt('All'),
163 'selected' => true,
165 $i++;
166 } elseif ($opt == '') {
167 $rows[$i] = array (
168 'value' => '',
169 'label' => $this->listenerObject->z_xlt('Unassigned'),
170 'disabled' => false
172 $i++;
175 foreach ($res as $row) {
176 $sel = ($row['option_id']==$selected) ? true : false;
177 $rows[$i] = array (
178 'value' => htmlspecialchars($row['option_id'], ENT_QUOTES),
179 'label' => $this->listenerObject->z_xlt($row['title']),
180 'selected' => $sel,
182 $i++;
185 return $rows;
189 * $this->escapeHtml() cannot be used in any files other than view.
190 * This function will enable a user to use escapeHtml in any files like controller model etc.
192 public function escape($string)
194 $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
195 $escapeHtml = $viewHelperManager->get('escapeHtml'); // $escapeHtml can be called as function because of its __invoke method
196 return $escapeHtml($string);
199 public function getListtitle($listId, $listOptionId)
201 $appTable = new ApplicationTable();
202 $sql = "SELECT title FROM list_options WHERE list_id = ? AND option_id = ? ";
203 $result = $appTable->zQuery($sql, array($listId,$listOptionId));
204 $row = $result->current();
205 $return = xl_list_label($row['title']);
206 return $return;