#4 pentabarf room import

This commit is contained in:
Philip Häusler 2011-07-11 20:40:27 +02:00
parent 3d15b591e3
commit f59f0eae9c
6 changed files with 91 additions and 4 deletions

View File

@ -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
);
}
?>

View File

@ -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)

View File

@ -107,6 +107,10 @@ table {
border-collapse: collapse;
}
fieldset table {
margin: 4px;
}
th {
background: #f0f0f0;
}

View File

@ -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>

View File

@ -0,0 +1,3 @@
<p class="success">
It's done!
</p>

View File

@ -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.