From: Stéphane Jacob Date: Wed, 5 Jan 2011 15:13:36 +0000 (+0100) Subject: Displays and compares our country and language lists with iso lists. X-Git-Tag: xorg/1.1.0~227 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a7fada4fdb44ce796ac206f4ff870513ebd5421b;p=platal.git Displays and compares our country and language lists with iso lists. Signed-off-by: Stéphane Jacob --- diff --git a/modules/admin.php b/modules/admin.php index 26c0475..f007313 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -47,6 +47,7 @@ class AdminModule extends PLModule 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), + 'admin/geocoding' => $this->make_hook('geocoding', AUTH_MDP, 'admin'), 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'), 'admin/account/watch' => $this->make_hook('account_watch', AUTH_MDP, 'admin'), 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'), @@ -1190,6 +1191,140 @@ class AdminModule extends PLModule $table_editor->apply($page, $action, $id); } + private static function isCountryIncomplete(array &$item) + { + $warning = false; + foreach (array('worldRegion', 'country', 'capital', 'phonePrefix', 'licensePlate', 'countryPlain') as $field) { + if ($item[$field] == '') { + $item[$field . '_warning'] = true; + $warning = true; + } + } + if (is_null($item['belongsTo'])) { + foreach (array('nationality', 'nationalityEn') as $field) { + if ($item[$field] == '') { + $item[$field . '_warning'] = true; + $warning = true; + } + } + } + return $warning; + } + + private static function isLanguageIncomplete(array &$item) + { + if ($item['language'] == '') { + $item['language_warning'] = true; + return true; + } + return false; + } + + function handler_geocoding(&$page, $action = null) + { + // Warning, this handler requires the following packages: + // * pkg-isocodes + // * isoquery + + static $properties = array( + 'country' => array( + 'name' => 'pays', + 'isocode' => '3166', + 'table' => 'geoloc_countries', + 'id' => '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') + ), + 'language' => array( + 'name' => 'langages', + 'isocode' => '639', + 'table' => 'profile_langskill_enum', + 'id' => 'iso_639_2b', + 'main_fields' => array('iso_639_2t', 'iso_639_1', 'language_en'), + 'other_fields' => array('language') + + ) + ); + //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)) { + pl_redirect('admin'); + } + + $data = $properties[$action]; + + $page->changeTpl('admin/geocoding.tpl'); + $page->setTitle('Administration - ' . ucfirst($data['name'])); + $page->assign('name', $data['name']); + $page->assign('id', $data['id']); + $page->assign('main_fields', $data['main_fields']); + $page->assign('all_fields', array_merge($data['main_fields'], $data['other_fields'])); + + // First build the list provided by the iso codes. + $list = array(); + exec('isoquery --iso=' . $data['isocode'], $list); + + foreach ($list as $key => $item) { + $array = explode("\t", $item); + unset($list[$key]); + $list[$array[0]] = array(); + foreach ($data['main_fields'] as $i => $field) { + $list[$array[0]][$field] = $array[$i + 1]; + } + } + ksort($list); + + // Retrieve all data from the database. + $db_list = XDB::rawFetchAllAssoc('SELECT * + FROM ' . $data['table'] . ' + ORDER BY ' . $data['id'], + $data['id']); + + // Sort both iso and database data into 5 categories: + // $missing: data from the iso list not in the database, + // $non_existing: data from the database not in the iso list, + // $erroneous: data that differ on main fields, + // $incomplete: data with empty fields in the data base, + // $remaining: remaining correct and complete data from the database. + + $missing = $non_existing = $erroneous = $incomplete = $remaining = array(); + foreach (array_keys($list) as $id) { + if (!array_key_exists($id, $db_list)) { + $missing[$id] = $list[$id]; + } + } + + foreach ($db_list as $id => $item) { + if (!array_key_exists($id, $list)) { + $non_existing[$id] = $item; + } else { + $error = false; + foreach ($data['main_fields'] as $field) { + if ($item[$field] != $list[$id][$field]) { + $item[$field . '_error'] = true; + $error = true; + } + } + if ($error == true) { + $erroneous[$id] = $item; + } elseif (call_user_func_array(array('self', 'is' . ucfirst($action) . 'Incomplete'), array(&$item))) { + $incomplete[$id] = $item; + } else { + $remaining[$id] = $item; + } + } + } + + $page->assign('lists', array( + 'manquant' => $missing, + 'disparu' => $non_existing, + 'erroné' => $erroneous, + 'incomplet' => $incomplete, + 'restant' => $remaining + )); + } + function handler_accounts(PlPage $page) { $page->changeTpl('admin/accounts.tpl'); diff --git a/templates/admin/geocoding.tpl b/templates/admin/geocoding.tpl new file mode 100644 index 0000000..f3a5564 --- /dev/null +++ b/templates/admin/geocoding.tpl @@ -0,0 +1,61 @@ +{**************************************************************************} +{* *} +{* 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}

+ +{foreach from=$lists item=list key=list_description} +{if $list_description eq "manquant"} +{assign var="fields" value=$main_fields} +{else} +{assign var="fields" value=$all_fields} +{/if} + +

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

+{if $list|@count} + + + + {foreach from=$fields item=field} + + {/foreach} + +{foreach from=$list item=item key=key} + + + {foreach from=$fields item=field} + {assign var="error" value=$field|cat:'_error'} + {assign var="warning" value=$field|cat:'_warning'} + {$item.$field} + {/foreach} + +{/foreach} + + + {foreach from=$fields item=field} + + {/foreach} + +
{$id}{$field}
{$key}
{$id}{$field}
+{/if} +{/foreach} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index af6d8b1..17cd7eb 100644 --- a/templates/admin/index.tpl +++ b/templates/admin/index.tpl @@ -114,6 +114,14 @@ {icon name=user_gray} Champs + Pays / Langues + + Pays +   |   + Langues + + + Formation Formations