Removed '' from download file name (problems in explorer)
[openemr.git] / interface / main / holidays / import_holidays.php
blob0619fe47dd0157a717e2f9d2405061c734572384
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 // Disable magic quotes and fake register globals.
26 $sanitize_all_escapes = true;
27 $fake_register_globals = false;
28 require_once('../../globals.php');
29 require_once($GLOBALS['srcdir'] . '/acl.inc');
30 require_once("Holidays_Controller.php");
32 if (!acl_check('admin', 'super')) die(xlt('Not authorized'));
34 $holidays_controller = new Holidays_Controller();
35 $csv_file_data = $holidays_controller->get_file_csv_data();
37 //this part download the CSV file after the click on the href link
38 if($_GET['download_file']==1) {
39 $target_file=$holidays_controller->get_target_file();
40 if ( ! file_exists($target_file))
42 echo xlt('file missing');
44 else
46 header('HTTP/1.1 200 OK');
47 header('Cache-Control: no-cache, must-revalidate');
48 header("Pragma: no-cache");
49 header("Expires: 0");
50 header("Content-type: text/csv");
51 header("Content-Disposition: attachment; filename=holiday.csv");
52 readfile($target_file);
53 exit;
55 die();
57 // end download section
59 // Handle uploads.
61 if (!empty($_POST['bn_upload'])) {
62 //Upload and save the csv
63 $saved = $holidays_controller->upload_csv($_FILES);
64 if($saved) {
65 $csv_file_data = $holidays_controller->get_file_csv_data();
69 if (!empty($_POST['import_holidays'])) {
70 //Import from the csv file to the calendar external table
71 $saved = $holidays_controller->import_holidays_from_csv();
73 if (!empty($_POST['sync'])) {
74 //Upload and save the csv
75 $saved = $holidays_controller->create_holiday_event();
81 <html>
82 <head>
83 <title><?php echo xlt('Holidays management'); ?></title>
84 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
86 </head>
88 <body class="body_top">
89 <?php
90 if ($saved){
91 echo "<p style='color:green'>" .
92 xlt('Successfully Completed');
93 "</p>\n";
94 }elseif(!empty($_POST['bn_upload']) &&
95 !empty($_POST['import_holidays']) &&
96 !empty($_POST['sync'])
98 echo "<p style='color:red'>" .
99 xlt('Operation Failed' );
100 "</p>\n";
103 <form method='post' action='import_holidays.php' enctype='multipart/form-data'
104 onsubmit='return top.restoreSession()'>
106 <p class='text'>
107 <table border='1' cellpadding='4'>
108 <tr bgcolor='#dddddd' class='dehead'>
109 <td align='center' colspan='2'>
110 <?php echo xlt('CSV'); ?>
111 </td>
112 </tr>
113 <tr>
114 <td class='detail' nowrap>
115 <?php echo htmlspecialchars(xl('CSV File')); ?>
116 <input type="hidden" name="MAX_FILE_SIZE" value="350000000" />
117 </td>
118 <td class='detail' nowrap>
119 <input type="file" name="form_file" size="40" />
120 </td>
121 </tr>
122 <tr>
123 <td class='detail' nowrap>
124 <?php echo xlt('File on server (modification date)'); ?>
125 </td>
126 <td class='detail' nowrap>
127 <?php
128 if(!empty($csv_file_data)){?>
130 <?php $path=explode("/",$holidays_controller->get_target_file());?>
131 <?php $filename=$path[count($path)-1];?>
132 <?php unset($path[count($path)-1]);?>
134 <a href="#" onclick='window.open("import_holidays.php?download_file=1")'><?php echo text($csv_file_data['date']);?></a>
135 <?php }else{
136 echo htmlspecialchars(xl('File not found'));
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>