From f59f0eae9c44a7464eded0a0d4352c0689df6d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20H=C3=A4usler?= Date: Mon, 11 Jul 2011 20:40:27 +0200 Subject: [PATCH] #4 pentabarf room import --- includes/pages/admin_import.php | 41 +++++++++++++++++++++++++++--- includes/sys_template.php | 14 ++++++++++ public/css/base.css | 4 +++ templates/admin_import_check.html | 31 ++++++++++++++++++++++ templates/admin_import_import.html | 3 +++ templates/admin_import_input.html | 2 +- 6 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 templates/admin_import_check.html create mode 100644 templates/admin_import_import.html 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 ? "None" : table_body($rooms_new), + 'rooms_deleted' => count($rooms_deleted) == 0 ? "None" : 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 + ); +} ?> diff --git a/includes/sys_template.php b/includes/sys_template.php index 7524b0cb..c3e874ae 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -15,6 +15,20 @@ function template_render($file, $data) { } } +function table_body($array) { + $html = ""; + foreach ($array as $line) { + $html .= ""; + if (is_array($line)) { + + } else { + $html .= "" . $line . ""; + } + $html .= ""; + } + return $html; +} + function html_options($name, $options, $selected = "") { $html = ""; foreach ($options as $value => $label) diff --git a/public/css/base.css b/public/css/base.css index 236eba81..59660b58 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -107,6 +107,10 @@ table { border-collapse: collapse; } +fieldset table { + margin: 4px; +} + th { background: #f0f0f0; } diff --git a/templates/admin_import_check.html b/templates/admin_import_check.html new file mode 100644 index 00000000..864339fc --- /dev/null +++ b/templates/admin_import_check.html @@ -0,0 +1,31 @@ +
+
+

Rooms to create

+ + + + + + + + %rooms_new% + +
+ Name +
+

Rooms to delete

+ + + + + + + + %rooms_deleted% + +
+ Name +
+ +
+
\ No newline at end of file diff --git a/templates/admin_import_import.html b/templates/admin_import_import.html new file mode 100644 index 00000000..4f2905be --- /dev/null +++ b/templates/admin_import_import.html @@ -0,0 +1,3 @@ +

+ It's done! +

diff --git a/templates/admin_import_input.html b/templates/admin_import_input.html index 19e756fe..89454f8c 100644 --- a/templates/admin_import_input.html +++ b/templates/admin_import_input.html @@ -1,4 +1,4 @@ -
+

While developing we use a fixed file input. Just hit submit.