Highway to PSR2
[openemr.git] / interface / main / holidays / import_holidays.php
blobad44923bec750b2a70e4e414655e65f37ea25d64
1 <?php
2 /**
3 * interface/main/holidays/import_holidays.php holidays/clinic handle import/download holidays files
5 * Copyright (C) 2016 Sharon Cohen <sharonco@matrix.co.il>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the 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 General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author sharonco <sharonco@matrix.co.il>
20 * @link http://www.open-emr.org
23 set_time_limit(0);
25 require_once('../../globals.php');
26 require_once($GLOBALS['srcdir'] . '/acl.inc');
27 require_once("Holidays_Controller.php");
29 if (!acl_check('admin', 'super')) {
30 die(xlt('Not authorized'));
33 $holidays_controller = new Holidays_Controller();
34 $csv_file_data = $holidays_controller->get_file_csv_data();
36 //this part download the CSV file after the click on the href link
37 if ($_GET['download_file']==1) {
38 $target_file=$holidays_controller->get_target_file();
39 if (! file_exists($target_file)) {
40 echo xlt('file missing');
41 } else {
42 header('HTTP/1.1 200 OK');
43 header('Cache-Control: no-cache, must-revalidate');
44 header("Pragma: no-cache");
45 header("Expires: 0");
46 header("Content-type: text/csv");
47 header("Content-Disposition: attachment; filename=holiday.csv");
48 readfile($target_file);
49 exit;
52 die();
55 // end download section
57 // Handle uploads.
59 if (!empty($_POST['bn_upload'])) {
60 //Upload and save the csv
61 $saved = $holidays_controller->upload_csv($_FILES);
62 if ($saved) {
63 $csv_file_data = $holidays_controller->get_file_csv_data();
67 if (!empty($_POST['import_holidays'])) {
68 //Import from the csv file to the calendar external table
69 $saved = $holidays_controller->import_holidays_from_csv();
72 if (!empty($_POST['sync'])) {
73 //Upload and save the csv
74 $saved = $holidays_controller->create_holiday_event();
80 <html>
81 <head>
82 <title><?php echo xlt('Holidays management'); ?></title>
83 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
85 </head>
87 <body class="body_top">
88 <?php
89 if ($saved) {
90 echo "<p style='color:green'>" .
91 xlt('Successfully Completed');
92 "</p>\n";
93 } elseif (!empty($_POST['bn_upload']) &&
94 !empty($_POST['import_holidays']) &&
95 !empty($_POST['sync'])
96 ) {
97 echo "<p style='color:red'>" .
98 xlt('Operation Failed');
99 "</p>\n";
102 <form method='post' action='import_holidays.php' enctype='multipart/form-data'
103 onsubmit='return top.restoreSession()'>
105 <p class='text'>
106 <table border='1' cellpadding='4'>
107 <tr bgcolor='#dddddd' class='dehead'>
108 <td align='center' colspan='2'>
109 <?php echo xlt('CSV'); ?>
110 </td>
111 </tr>
112 <tr>
113 <td class='detail' nowrap>
114 <?php echo htmlspecialchars(xl('CSV File')); ?>
115 <input type="hidden" name="MAX_FILE_SIZE" value="350000000" />
116 </td>
117 <td class='detail' nowrap>
118 <input type="file" name="form_file" size="40" />
119 </td>
120 </tr>
121 <tr>
122 <td class='detail' nowrap>
123 <?php echo xlt('File on server (modification date)'); ?>
124 </td>
125 <td class='detail' nowrap>
126 <?php
127 if (!empty($csv_file_data)) {?>
129 <?php $path=explode("/", $holidays_controller->get_target_file());?>
130 <?php $filename=$path[count($path)-1];?>
131 <?php unset($path[count($path)-1]);?>
133 <a href="#" onclick='window.open("import_holidays.php?download_file=1")'><?php echo text($csv_file_data['date']);?></a>
134 <?php
135 } else {
136 echo htmlspecialchars(xl('File not found'));
137 } ?>
138 </td>
139 </tr>
141 <tr bgcolor='#dddddd'>
142 <td align='center' class='detail' colspan='2'>
143 <input type='submit' name='bn_upload' value='<?php echo xla('Upload / Save') ?>' />
144 </td>
145 </tr>
146 </table>
147 </p>
148 </form>
149 <table border='1'>
151 <tr >
152 <td >
153 <form method='post' action='import_holidays.php' onsubmit='return top.restoreSession()'>
154 <input type='submit' name='import_holidays' value='<?php echo xla('Import holiday events') ?>'></br>
156 </form>
157 </td>
159 <td>
160 <?php echo xlt('CSV to calendar_external table'); ?></br>
161 <?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')?>
162 </td>
163 </tr>
164 <tr >
165 <td >
166 <form method='post' action='import_holidays.php' onsubmit='return top.restoreSession()'>
167 <input type='submit' name='sync' value='<?php echo xla('Synchronize') ?>' /></br>
168 </form>
169 </td>
170 <td >
171 <?php echo xlt('calendar_external to events'); ?></br>
172 <?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')?>
173 </td>
174 </tr>
175 </table>
176 </body>
177 </html>