summaryrefslogtreecommitdiff
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
parent3d15b591e3f4196846fff005cc800feb383073c7 (diff)
#4 pentabarf room import
-rw-r--r--includes/pages/admin_import.php41
-rw-r--r--includes/sys_template.php14
-rw-r--r--public/css/base.css4
-rw-r--r--templates/admin_import_check.html31
-rw-r--r--templates/admin_import_import.html3
-rw-r--r--templates/admin_import_input.html2
6 files changed, 91 insertions, 4 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
+ );
+}
?>
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 .= "<tr>";
+ if (is_array($line)) {
+
+ } else {
+ $html .= "<td>" . $line . "</td>";
+ }
+ $html .= "</tr>";
+ }
+ 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 @@
+<form action="%link%&step=import" method="post">
+ <fieldset>
+ <h3>Rooms to create</h3>
+ <table>
+ <thead>
+ <tr>
+ <th>
+ Name
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ %rooms_new%
+ </tbody>
+ </table>
+ <h3>Rooms to delete</h3>
+ <table>
+ <thead>
+ <tr>
+ <th>
+ Name
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ %rooms_deleted%
+ </tbody>
+ </table>
+ <input type="submit" name="submit" value="Submit" />
+ </fieldset>
+</form> \ 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 @@
+<p class="success">
+ It's done!
+</p>
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 @@
-<form action="%link%" method="post">
+<form action="%link%&step=check" method="post">
<fieldset>
<p>
While developing we use a fixed file input. Just hit submit.