summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-07-11 21:58:06 +0200
committerPhilip Häusler <msquare@notrademark.de>2011-07-11 21:58:06 +0200
commitf058a07a5ea31221d7f3cb415cb75d1e7e857a38 (patch)
tree91d76a34c2f0ad59ab433dba3e181f2761a85571
parentf59f0eae9c44a7464eded0a0d4352c0689df6d11 (diff)
#4 pentabarf shift import
-rw-r--r--includes/pages/admin_import.php78
-rw-r--r--includes/sys_template.php3
-rw-r--r--templates/admin_import_check.html26
3 files changed, 100 insertions, 7 deletions
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 14271a85..5b5474ca 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -26,11 +26,15 @@ function admin_import() {
case "check" :
list ($rooms_new, $rooms_deleted) = prepare_rooms();
+ list ($events_new, $events_updated, $events_deleted) = prepare_events();
$html .= template_render('../templates/admin_import_check.html', array (
'link' => page_link_to('admin_import'),
- 'rooms_new' => count($rooms_new) == 0 ? "<td>None</td>" : table_body($rooms_new),
- 'rooms_deleted' => count($rooms_deleted) == 0 ? "<td>None</td>" : table_body($rooms_deleted)
+ 'rooms_new' => count($rooms_new) == 0 ? "<tr><td>None</td></tr>" : table_body($rooms_new),
+ 'rooms_deleted' => count($rooms_deleted) == 0 ? "<tr><td>None</td></tr>" : table_body($rooms_deleted),
+ 'events_new' => count($events_new) == 0 ? "<tr><td>None</td><td></td><td></td><td></td></tr>" : table_body(shifts_printable($events_new)),
+ 'events_updated' => count($events_updated) == 0 ? "<tr><td>None</td><td></td><td></td><td></td></tr>" : table_body($events_updated),
+ 'events_deleted' => count($events_deleted) == 0 ? "<tr><td>None</td><td></td><td></td><td></td></tr>" : table_body($events_deleted)
));
break;
@@ -41,6 +45,10 @@ function admin_import() {
foreach ($rooms_deleted as $room)
sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
+ list ($events_new, $events_updated, $events_deleted) = prepare_events();
+ foreach ($events_new as $event)
+ sql_query("INSERT INTO `Shifts` SET `start`=" . sql_escape($event['start']) . ", `end`=" . sql_escape($event['end']) . ", `RID`=" . sql_escape($event['RID']) . ", `PSID`=" . sql_escape($event['PSID']) . ", `URL`='" . sql_escape($event['URL']) . "'");
+
$html .= template_render('../templates/admin_import_import.html', array ());
break;
}
@@ -299,13 +307,17 @@ function CreateRoomArrays() {
}
function prepare_rooms() {
- $data = new SimpleXMLElement(file_get_contents('../import/27C3_sample.xcs'));
+ global $rooms_import;
+ $data = read_xml();
// Load rooms from db for compare with input
$rooms = sql_select("SELECT * FROM `Room` WHERE `FromPentabarf`='Y'");
$rooms_db = array ();
- foreach ($rooms as $room)
+ $rooms_import = array ();
+ foreach ($rooms as $room) {
$rooms_db[] = $room['Name'];
+ $rooms_import[$room['Name']] = $room['RID'];
+ }
$events = $data->vcalendar->vevent;
$rooms_pb = array ();
@@ -321,5 +333,63 @@ function prepare_rooms() {
$rooms_deleted
);
}
+
+function prepare_events() {
+ global $rooms_import;
+ $data = read_xml();
+
+ $rooms = sql_select("SELECT * FROM `Room`");
+ $rooms_db = array ();
+ foreach ($rooms as $room)
+ $rooms_db[$room['Name']] = $room['RID'];
+
+ $events = $data->vcalendar->vevent;
+ $shifts_pb = array ();
+ foreach ($events as $event) {
+ $event_pb = $event->children("http://pentabarf.org");
+ $shifts_pb[] = array (
+ 'start' => DateTime :: createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp(),
+ 'end' => DateTime :: createFromFormat("Ymd\THis", $event->dtend)->getTimestamp(),
+ 'RID' => $rooms_import[trim($event->location)],
+ 'URL' => trim($event->url),
+ 'PSID' => trim($event_pb-> {
+ 'event-id' })
+ );
+ }
+
+ return array (
+ $shifts_pb,
+ array (),
+ array ()
+ );
+}
+
+function read_xml() {
+ global $xml_import;
+ if (!isset ($xml_import))
+ $xml_import = new SimpleXMLElement(file_get_contents('../import/27C3_sample.xcs'));
+ return $xml_import;
+}
+
+function shifts_printable($shifts) {
+ global $rooms_import;
+ $rooms = array_flip($rooms_import);
+
+ usort($shifts, 'shift_sort');
+
+ $shifts_printable = array ();
+ foreach ($shifts as $shift)
+ $shifts_printable[] = array (
+ 'day' => date("l, Y-m-d", $shift['start']),
+ 'start' => date("H:i", $shift['start']),
+ 'end' => date("H:i", $shift['end']),
+ 'room' => $rooms[$shift['RID']]
+ );
+ return $shifts_printable;
+}
+
+function shift_sort($a, $b) {
+ return ($a['start'] < $b['start']) ? -1 : 1;
+}
?>
diff --git a/includes/sys_template.php b/includes/sys_template.php
index c3e874ae..f409dada 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -20,7 +20,8 @@ function table_body($array) {
foreach ($array as $line) {
$html .= "<tr>";
if (is_array($line)) {
-
+ foreach ($line as $td)
+ $html .= "<td>" . $td . "</td>";
} else {
$html .= "<td>" . $line . "</td>";
}
diff --git a/templates/admin_import_check.html b/templates/admin_import_check.html
index 864339fc..a74f1693 100644
--- a/templates/admin_import_check.html
+++ b/templates/admin_import_check.html
@@ -10,7 +10,7 @@
</tr>
</thead>
<tbody>
- %rooms_new%
+ %rooms_new%
</tbody>
</table>
<h3>Rooms to delete</h3>
@@ -23,7 +23,29 @@
</tr>
</thead>
<tbody>
- %rooms_deleted%
+ %rooms_deleted%
+ </tbody>
+ </table>
+ <h3>Shifts to create</h3>
+ <table>
+ <thead>
+ <tr>
+ <th>
+ Day
+ </th>
+ <th>
+ Start
+ </th>
+ <th>
+ End
+ </th>
+ <th>
+ Room
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ %events_new%
</tbody>
</table>
<input type="submit" name="submit" value="Submit" />