summaryrefslogtreecommitdiff
path: root/includes/pages
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2011-07-11 20:40:27 +0200
committerPhilip Häusler <msquare@notrademark.de>2011-07-11 20:40:27 +0200
commitf59f0eae9c44a7464eded0a0d4352c0689df6d11 (patch)
tree0c26b56928a6ca3da1184f0798c833a5782836b9 /includes/pages
parent3d15b591e3f4196846fff005cc800feb383073c7 (diff)
#4 pentabarf room import
Diffstat (limited to 'includes/pages')
-rw-r--r--includes/pages/admin_import.php41
1 files changed, 38 insertions, 3 deletions
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 781dc15a..14271a85 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -21,16 +21,27 @@ function admin_import() {
$html .= template_render('../templates/admin_import_input.html', array (
'link' => page_link_to('admin_import')
));
-
- $data = new SimpleXMLElement(file_get_contents('../import/27C3_sample.xcs'));
- print_r($data->vcalendar);
break;
}
case "check" :
+ list ($rooms_new, $rooms_deleted) = prepare_rooms();
+
+ $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)
+ ));
break;
case "import" :
+ list ($rooms_new, $rooms_deleted) = prepare_rooms();
+ foreach ($rooms_new as $room)
+ sql_query("INSERT INTO `Room` SET `Name`='" . sql_escape($room) . "', `FromPentabarf`='Y', `Show`='Y'");
+ foreach ($rooms_deleted as $room)
+ sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1");
+
+ $html .= template_render('../templates/admin_import_import.html', array ());
break;
}
@@ -286,5 +297,29 @@ function CreateRoomArrays() {
$RoomName[mysql_result($Erg, $i, "Name")] = mysql_result($Erg, $i, "RID");
}
}
+
+function prepare_rooms() {
+ $data = new SimpleXMLElement(file_get_contents('../import/27C3_sample.xcs'));
+
+ // 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_db[] = $room['Name'];
+
+ $events = $data->vcalendar->vevent;
+ $rooms_pb = array ();
+ foreach ($events as $event)
+ $rooms_pb[] = $event->location;
+ $rooms_pb = array_unique($rooms_pb);
+
+ $rooms_new = array_diff($rooms_pb, $rooms_db);
+ $rooms_deleted = array_diff($rooms_db, $rooms_pb);
+
+ return array (
+ $rooms_new,
+ $rooms_deleted
+ );
+}
?>