4 * interface/main/holidays/import_holidays.php holidays/clinic handle import/download holidays files
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
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")]);
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');
43 header('HTTP/1.1 200 OK');
44 header('Cache-Control: no-cache, must-revalidate');
45 header("Pragma: no-cache");
47 header("Content-type: text/csv");
48 header("Content-Disposition: attachment; filename=holiday.csv");
49 readfile($target_file);
56 // end download section
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);
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();
95 <title
><?php
echo xlt('Holidays management'); ?
></title
>
96 <?php Header
::setupHeader(); ?
>
100 <body
class="body_top">
102 if (!empty($saved)) {
103 echo "<p style='color:green'>" .
104 xlt('Successfully Completed');
107 !empty($_POST['bn_upload']) &&
108 !empty($_POST['import_holidays']) &&
109 !empty($_POST['sync'])
111 echo "<p style='color:red'>" .
112 xlt('Operation Failed');
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'>
124 <th align
='center' colspan
='2'>
125 <?php
echo xlt('CSV'); ?
>
130 <td
class='detail' nowrap
>
131 <?php
echo xlt('CSV File'); ?
>
132 <input type
="hidden" name
="MAX_FILE_SIZE" value
="350000000" />
134 <td
class='detail' nowrap
>
135 <input type
="file" name
="form_file" size
="40" />
139 <td
class='detail' nowrap
>
140 <?php
echo xlt('File on server (modification date)'); ?
>
142 <td
class='detail' nowrap
>
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
>
152 echo xlt('File not found');
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
') ?>' />
165 <div
class="table-responsive">
166 <table
class='table table-bordered'>
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
/>
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')?
>
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
/>
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')?
>