fix: fix ci (#7614)
[openemr.git] / interface / main / holidays / import_holidays.php
blobd0f42c5b2fecd82bbea91e371403cc06eb66f37c
1 <?php
3 /**
4 * interface/main/holidays/import_holidays.php holidays/clinic handle import/download holidays files
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author sharonco <sharonco@matrix.co.il>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2016 Sharon Cohen <sharonco@matrix.co.il>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 set_time_limit(0);
17 require_once('../../globals.php');
18 require_once("Holidays_Controller.php");
20 use OpenEMR\Common\Acl\AclMain;
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Common\Twig\TwigContainer;
23 use OpenEMR\Core\Header;
25 if (!AclMain::aclCheckCore('admin', 'super')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Holidays management")]);
27 exit;
30 $holidays_controller = new Holidays_Controller();
31 $csv_file_data = $holidays_controller->get_file_csv_data();
33 //this part download the CSV file after the click on the href link
34 if (!empty($_GET['download_file']) && ($_GET['download_file'] == 1)) {
35 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
36 CsrfUtils::csrfNotVerified();
39 $target_file = $holidays_controller->get_target_file();
40 if (! file_exists($target_file)) {
41 echo xlt('file missing');
42 } else {
43 header('HTTP/1.1 200 OK');
44 header('Cache-Control: no-cache, must-revalidate');
45 header("Pragma: no-cache");
46 header("Expires: 0");
47 header("Content-type: text/csv");
48 header("Content-Disposition: attachment; filename=holiday.csv");
49 readfile($target_file);
50 exit;
53 die();
56 // end download section
58 // Handle uploads.
60 if (!empty($_POST['bn_upload'])) {
61 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
62 CsrfUtils::csrfNotVerified();
65 //Upload and save the csv
66 $saved = $holidays_controller->upload_csv($_FILES);
67 if ($saved) {
68 $csv_file_data = $holidays_controller->get_file_csv_data();
72 if (!empty($_POST['import_holidays'])) {
73 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
74 CsrfUtils::csrfNotVerified();
77 //Import from the csv file to the calendar external table
78 $saved = $holidays_controller->import_holidays_from_csv();
81 if (!empty($_POST['sync'])) {
82 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
83 CsrfUtils::csrfNotVerified();
86 //Upload and save the csv
87 $saved = $holidays_controller->create_holiday_event();
93 <html>
94 <head>
95 <title><?php echo xlt('Holidays management'); ?></title>
96 <?php Header::setupHeader(); ?>
98 </head>
100 <body class="body_top">
101 <?php
102 if (!empty($saved)) {
103 echo "<p style='color:green'>" .
104 xlt('Successfully Completed');
105 "</p>\n";
106 } elseif (
107 !empty($_POST['bn_upload']) &&
108 !empty($_POST['import_holidays']) &&
109 !empty($_POST['sync'])
111 echo "<p style='color:red'>" .
112 xlt('Operation Failed');
113 "</p>\n";
116 <div class="container-fluid">
117 <form method='post' action='import_holidays.php' enctype='multipart/form-data'
118 onsubmit='return top.restoreSession()'>
119 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
120 <div class="table-responsive">
121 <table class='table table-bordered text' cellpadding='4'>
122 <thead class='thead-light'>
123 <tr>
124 <th align='center' colspan='2'>
125 <?php echo xlt('CSV'); ?>
126 </th>
127 </tr>
128 </thead>
129 <tr>
130 <td class='detail' nowrap>
131 <?php echo xlt('CSV File'); ?>
132 <input type="hidden" name="MAX_FILE_SIZE" value="350000000" />
133 </td>
134 <td class='detail' nowrap>
135 <input type="file" name="form_file" size="40" />
136 </td>
137 </tr>
138 <tr>
139 <td class='detail' nowrap>
140 <?php echo xlt('File on server (modification date)'); ?>
141 </td>
142 <td class='detail' nowrap>
143 <?php
144 if (!empty($csv_file_data)) {?>
145 <?php $path = explode("/", $holidays_controller->get_target_file());?>
146 <?php $filename = $path[count($path) - 1];?>
147 <?php unset($path[count($path) - 1]);?>
149 <a href="#" onclick='window.open("import_holidays.php?download_file=1&csrf_token_form=<?php echo attr_url(CsrfUtils::collectCsrfToken()); ?>")'><?php echo text($csv_file_data['date']);?></a>
150 <?php
151 } else {
152 echo xlt('File not found');
153 } ?>
154 </td>
155 </tr>
157 <tr class='table-light'>
158 <td align='center' class='detail' colspan='2'>
159 <input class='btn btn-primary' type='submit' name='bn_upload' value='<?php echo xla('Upload / Save') ?>' />
160 </td>
161 </tr>
162 </table>
163 </div>
164 </form>
165 <div class="table-responsive">
166 <table class='table table-bordered'>
168 <tr>
169 <td>
170 <form method='post' action='import_holidays.php' onsubmit='return top.restoreSession()'>
171 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
172 <input type='submit' class='btn btn-primary' name='import_holidays' value='<?php echo xla('Import holiday events') ?>'><br />
174 </form>
175 </td>
177 <td>
178 <?php echo xlt('CSV to calendar_external table'); ?><br />
179 <?php echo xlt('If the csv file has been uploaded, then click on the "Import holiday events" button. NOTE that clicking on the button will remove all the existing rows in the calendar_external table')?>
180 </td>
181 </tr>
182 <tr>
183 <td>
184 <form method='post' action='import_holidays.php' onsubmit='return top.restoreSession()'>
185 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
186 <input type='submit' class='btn btn-primary' name='sync' value='<?php echo xla('Synchronize') ?>' /><br />
187 </form>
188 </td>
189 <td >
190 <?php echo xlt('calendar_external to events'); ?><br />
191 <?php echo xlt('If you have already filled the calendar_external table, then click on "Synchronize" button to have the holidays in the calendar view. NOTE that clicking on the button will remove all the existing items in the calendar view related to holidays')?>
192 </td>
193 </tr>
194 </table>
195 </div>
196 </div>
197 </body>
198 </html>