• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

calendar/includes/inc.parse.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                                                                                       |
00005         |       Dateplaner Modul                                                                                                                  |                                                                                                     
00006         +-----------------------------------------------------------------------------+
00007         | Copyright (c) 2004 ILIAS open source & University of Applied Sciences Bremen|
00008         |                                                                             |
00009         | This program is free software; you can redistribute it and/or               |
00010         | modify it under the terms of the GNU General Public License                 |
00011         | as published by the Free Software Foundation; either version 2              |
00012         | of the License, or (at your option) any later version.                      |
00013         |                                                                             |
00014         | This program is distributed in the hope that it will be useful,             |
00015         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017         | GNU General Public License for more details.                                |
00018         |                                                                             |
00019         | You should have received a copy of the GNU General Public License           |
00020         | along with this program; if not, write to the Free Software                 |
00021         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022         +-----------------------------------------------------------------------------+
00023 */
00024 
00046 function getCSV($file){
00047         $handle = fopen ($file,"r"); 
00048         while ($data = fgetcsv ($handle, 1000, ",")) { // Daten werden aus der Datei
00049                 
00050                 if (is_array($data))
00051                 {
00052                         foreach($data as $k => $v)
00053                         {
00054                                 $data[$k] = strip_tags($data[$k]);
00055                         }
00056                 }
00057 
00058             $array[] = $data;                           // in ein Array $data gelesen
00059         }
00060         fclose ($handle);
00061         return $array;
00062 }
00063 
00071 function showArray($array){
00072         global $DP_language;
00073         $format = $DP_language[date_format];
00074         $parsedata.= "<b>$DP_language[insertImportDates]</b> <br><hr>";
00075         foreach($array as $date){
00076                 $parsedata.= "<table><tr><td><b>$DP_language[timeslice]</b></td><td>".date($format, $date[begin])." - ".date($format, $date[end])."</td></tr>";
00077                 $parsedata.= "<tr><td valign='top'><b>$DP_language[shorttext]:</b></td><td>".$date[short]."</td></tr>";
00078                 $parsedata.= "<tr><td valign='top'><b>$DP_language[Text]:</b></td><td>".$date[text]."</td></tr></table>";
00079                 
00080                 $parsedata.= "<hr>";
00081         }
00082         return $parsedata;
00083 }
00084 
00085 
00093 function convertToDateFormat($a){
00094         global $DP_UId;
00095         for($i=1; $i<count($a); $i++){
00096                 $j = $i-1;
00097                 if($a[$i][5]=="Aus"){//ganztagestermin?
00098                         $dates[$j][begin]       = makeTimestamp($a[$i][1], $a[$i][2]);
00099                         $dates[$j][end]         = makeTimestamp($a[$i][3], $a[$i][4]);
00100                         $dates[$j][user_ID]     = $DP_UId;
00101                         $dates[$j][short]       = $a[$i][0];
00102                         if($a[$i][16]!="") {$dates[$j][short].= " (".$a[$i][16].")";}//Ort?
00103                         $dates[$j][text]        = $a[$i][14];
00104                 }else{
00105                         $dates[$j][begin]       = makeTimestamp($a[$i][1], "00:00:00");
00106                         $dates[$j][end]         = makeTimestamp($a[$i][3], "23:59:59");
00107                         $dates[$j][user_ID]     = $DP_UId;
00108                         $dates[$j][short]       = $a[$i][0];
00109                         if($a[$i][16]!="") {$dates[$j][short].= " (".$a[$i][16].")";}//Ort?
00110                         $dates[$j][text]        = $a[$i][14];
00111                 }
00112                 
00113         }
00114         return $dates;          
00115 }
00116 
00124 function makeTimestamp($day, $time){
00125         $d = explode(".", $day );
00126         $t = explode(":", $time);
00127         $timestamp = mktime($t[0],$t[1],$t[2],$d[1],$d[0],$d[2]);
00128         return  $timestamp;
00129 }
00130 
00139 function parse($db, $_FILES){
00140         global $DP_language;
00141         $file = $_FILES['Datei'];
00142         if($file[tmp_name]){            
00143                 $array = getCSV($file[tmp_name]);
00144                 $dates = convertToDateFormat($array);
00145                 for($j=0; $j<count($dates);$j++){
00146                         $return = $db->addDate (        $dates[$j][begin],
00147                                                                                 $dates[$j][end], 
00148                                                                                 0, 
00149                                                                                 $dates[$j][user_ID], 
00150                                                                                 mktime(),
00151                                                                                 0, 
00152                                                                                 0, 
00153                                                                                 $dates[$j][short], 
00154                                                                                 $dates[$j][text], 
00155                                                                                 0, 
00156                                                                                 $dates[$j][user_ID]);
00157                 }
00158                 return showArray($dates);
00159         }
00160         else{
00161                 return $DP_language[ERROR_FILE_CSV_MSG];
00162         }
00163 
00164 }
00165 ?>

Generated on Fri Dec 13 2013 17:56:47 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1