From 846bfc833cf63fe4d31e6e0e988cffc111b42a63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 7 Jan 2011 07:36:18 +0100 Subject: [PATCH] Administrations pages for country and language edition (Closes #1320). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- modules/admin.php | 102 ++++++++++++++++++++++++++++++++++--- templates/admin/geocoding.tpl | 14 +++++ templates/admin/geocoding_edit.tpl | 55 ++++++++++++++++++++ 3 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 templates/admin/geocoding_edit.tpl diff --git a/modules/admin.php b/modules/admin.php index f007313..ef780f4 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -1,6 +1,6 @@ 'iso_3166_1_a2', 'main_fields' => array('iso_3166_1_a3', 'iso_3166_1_num', 'countryEn'), 'other_fields' => array('worldRegion', 'country', 'capital', 'nationality', 'nationalityEn', - 'phonePrefix', 'phoneFormat', 'licensePlate', 'belongsTo', 'countryPlain') + 'phonePrefix', 'phoneFormat', 'licensePlate', 'belongsTo') ), 'language' => array( 'name' => 'langages', @@ -1246,16 +1256,94 @@ class AdminModule extends PLModule ) ); - //For ISO 639, the first three columns are the ISO 639 2B code, the ISO 639 2T code and the ISO 639-1 code. The third column may be - if (is_null($action) || !array_key_exists($action, $properties)) { + if (is_null($category) || !array_key_exists($category, $properties)) { pl_redirect('admin'); } - $data = $properties[$action]; + $data = $properties[$category]; + + if ($action == 'edit' || $action == 'add') { + $main_fields = array_merge(array($data['id']), $data['main_fields']); + $all_fields = array_merge($main_fields, $data['other_fields']); + + if (is_null($id)) { + if (Post::has('new_id')) { + $id = Post::v('new_id'); + } else { + pl_redirect('admin/geocoding/' . $category); + } + } + + $list = array(); + exec('isoquery --iso=' . $data['isocode'] . ' ' . $id, $list); + if (count($list) == 1) { + $array = explode("\t", $list[0]); + foreach ($main_fields as $i => $field) { + $iso[$field] = $array[$i]; + } + } else { + $iso = array(); + } + + if ($action == 'add') { + if (Post::has('new_id')) { + S::assert_xsrf_token(); + } + + if (count($iso)) { + $item = $iso; + } else { + $item = array($data['id'] => $id); + } + XDB::execute('INSERT INTO ' . $data['table'] . '(' . implode(', ', array_keys($item)) . ') + VALUES ' . XDB::formatArray($item)); + $page->trigSuccess($id . ' a bien été ajouté à la base.'); + } elseif ($action == 'edit') { + if (Post::has('edit')) { + S::assert_xsrf_token(); + + $item = array(); + $set = array(); + foreach ($all_fields as $field) { + $item[$field] = Post::t($field); + $set[] = $field . XDB::format(' = {?}', ($item[$field] ? $item[$field] : null)); + } + XDB::execute('UPDATE ' . $data['table'] . ' + SET ' . implode(', ', $set) . ' + WHERE ' . $data['id'] . ' = {?}', + $id); + call_user_func_array(array('self', 'update' . ucfirst($category)), array($item)); + $page->trigSuccess($id . ' a bien été mis à jour.'); + } elseif (Post::has('del')) { + S::assert_xsrf_token(); + + XDB::execute('DELETE FROM ' . $data['table'] . ' + WHERE ' . $data['id'] . ' = {?}', + $id); + $page->trigSuccessRedirect($id . ' a bien été supprimé.', 'admin/geocoding/' . $category); + } else { + $item = XDB::fetchOneAssoc('SELECT * + FROM ' . $data['table'] . ' + WHERE ' . $data['id'] . ' = {?}', + $id); + } + } + + $page->changeTpl('admin/geocoding_edit.tpl'); + $page->setTitle('Administration - ' . ucfirst($data['name'])); + $page->assign('category', $category); + $page->assign('name', $data['name']); + $page->assign('all_fields', $all_fields); + $page->assign('id', $id); + $page->assign('iso', $iso); + $page->assign('item', $item); + return; + } $page->changeTpl('admin/geocoding.tpl'); $page->setTitle('Administration - ' . ucfirst($data['name'])); + $page->assign('category', $category); $page->assign('name', $data['name']); $page->assign('id', $data['id']); $page->assign('main_fields', $data['main_fields']); @@ -1308,7 +1396,7 @@ class AdminModule extends PLModule } if ($error == true) { $erroneous[$id] = $item; - } elseif (call_user_func_array(array('self', 'is' . ucfirst($action) . 'Incomplete'), array(&$item))) { + } elseif (call_user_func_array(array('self', 'is' . ucfirst($category) . 'Incomplete'), array(&$item))) { $incomplete[$id] = $item; } else { $remaining[$id] = $item; diff --git a/templates/admin/geocoding.tpl b/templates/admin/geocoding.tpl index f3a5564..05c1db7 100644 --- a/templates/admin/geocoding.tpl +++ b/templates/admin/geocoding.tpl @@ -25,8 +25,10 @@ {foreach from=$lists item=list key=list_description} {if $list_description eq "manquant"} {assign var="fields" value=$main_fields} +{assign var="action" value="add"} {else} {assign var="fields" value=$all_fields} +{assign var="action" value="edit"} {/if}

{$list|@count} {$name} {$list_description}{if $list|@count > 1}s{/if}.

@@ -37,6 +39,7 @@ {foreach from=$fields item=field} {$field} {/foreach} + {$action} {foreach from=$list item=item key=key} @@ -46,6 +49,7 @@ {assign var="warning" value=$field|cat:'_warning'} {$item.$field} {/foreach} + {icon name="page_edit"} {/foreach} @@ -53,9 +57,19 @@ {foreach from=$fields item=field} {$field} {/foreach} + {$action} {/if} {/foreach} +
+ {xsrf_token_field} +

+ Ajouter un champ (n'indiquer que l'indentifiant principal) : + + +

+
+ {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/admin/geocoding_edit.tpl b/templates/admin/geocoding_edit.tpl new file mode 100644 index 0000000..0e49a8b --- /dev/null +++ b/templates/admin/geocoding_edit.tpl @@ -0,0 +1,55 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2010 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

{$name|ucfirst} : édition

+ +
+ {xsrf_token_field} + + {if $iso|@count eq 0} +

Cet élément ne figure pas dans la liste ISO.

+ {/if} + + + + + + + {foreach from=$all_fields item=field} + + + + + + {/foreach} +
ChampsÉlémentDonnées ISO
{$field} + + {if t($iso.$field)}{$iso.$field}{/if}
+ +

+     + +

+
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4