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>;.
19 * @author sharonco <sharonco@matrix.co.il>
20 * @link http://www.open-emr.org
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');
46 header('HTTP/1.1 200 OK');
47 header('Cache-Control: no-cache, must-revalidate');
48 header("Pragma: no-cache");
50 header("Content-type: text/csv");
51 header("Content-Disposition: attachment; filename=holiday.csv");
52 readfile($target_file);
57 // end download section
61 if (!empty($_POST['bn_upload'])) {
62 //Upload and save the csv
63 $saved = $holidays_controller->upload_csv($_FILES);
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();
83 <title
><?php
echo xlt('Holidays management'); ?
></title
>
84 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
88 <body
class="body_top">
91 echo "<p style='color:green'>" .
92 xlt('Successfully Completed');
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' );
103 <form method
='post' action
='import_holidays.php' enctype
='multipart/form-data'
104 onsubmit
='return top.restoreSession()'>
107 <table border
='1' cellpadding
='4'>
108 <tr bgcolor
='#dddddd' class='dehead'>
109 <td align
='center' colspan
='2'>
110 <?php
echo xlt('CSV'); ?
>
114 <td
class='detail' nowrap
>
115 <?php
echo htmlspecialchars(xl('CSV File')); ?
>
116 <input type
="hidden" name
="MAX_FILE_SIZE" value
="350000000" />
118 <td
class='detail' nowrap
>
119 <input type
="file" name
="form_file" size
="40" />
123 <td
class='detail' nowrap
>
124 <?php
echo xlt('File on server (modification date)'); ?
>
126 <td
class='detail' nowrap
>
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
>
136 echo htmlspecialchars(xl('File not found'));
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
') ?>' />
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
>
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')?
>
166 <form method
='post' action
='import_holidays.php' onsubmit
='return top.restoreSession()'>
167 <input type
='submit' name
='sync' value
='<?php echo xla('Synchronize
') ?>' /></br
>
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')?
>