Index: /trunk/admin/help.php
===================================================================
--- /trunk/admin/help.php	(revision 878)
+++ /trunk/admin/help.php	(revision 879)
@@ -28,18 +28,10 @@
 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
 
-// language files
-$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language'];
-$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language'];
-
-if (file_exists($user_langdir.'/help.html'))
-{
-  $html_file = $user_langdir.'/help.html';
-}
-else
-{
-  $html_file = $conf_langdir.'/help.html';
-}
-
-$template->set_filenames(array('help_content' => $html_file));
+$template->set_filenames(
+  array(
+    'help_content' => get_language_filepath('help.html')
+    )
+  );
+  
 $template->assign_var_from_handle('ADMIN_CONTENT', 'help_content');
 ?>
Index: /trunk/doc/ChangeLog
===================================================================
--- /trunk/doc/ChangeLog	(revision 878)
+++ /trunk/doc/ChangeLog	(revision 879)
@@ -1,2 +1,8 @@
+2005-09-27 Pierrick LE GALL
+	
+	* bug 168 fixed: crash when language file does not
+	exists. Constant PHPWG_DEFAULT_LANGUAGE added. New function
+	get_language_filepath always used to find language files.
+
 2005-09-26 Pierrick LE GALL
 
Index: /trunk/include/common.inc.php
===================================================================
--- /trunk/include/common.inc.php	(revision 878)
+++ /trunk/include/common.inc.php	(revision 879)
@@ -167,30 +167,9 @@
 
 // language files
-$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language'];
-$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language'];
+include_once(get_language_filepath('common.lang.php'));
 
-if (file_exists($user_langdir.'/common.lang.php'))
-{
-  include_once($user_langdir.'/common.lang.php');
-}
-else
-{
-  include_once($conf_langdir.'/common.lang.php');
-}
-
-// The administration section requires 2 more language files
 if (defined('IN_ADMIN') and IN_ADMIN)
 {
-  foreach (array('admin') as $section)
-  {
-    if (file_exists($user_langdir.'/'.$section.'.lang.php'))
-    {
-      include_once($user_langdir.'/'.$section.'.lang.php');
-    }
-    else
-    {
-      include_once($conf_langdir.'/'.$section.'.lang.php');
-    }
-  }
+  include_once(get_language_filepath('admin.lang.php'));
 }
 
Index: /trunk/include/constants.php
===================================================================
--- /trunk/include/constants.php	(revision 878)
+++ /trunk/include/constants.php	(revision 879)
@@ -30,4 +30,5 @@
 define('PHPWG_URL', 'http://www.phpwebgallery.net');
 define('PHPWG_FORUM_URL', 'http://forum.phpwebgallery.net');
+define('PHPWG_DEFAULT_LANGUAGE', 'en_UK.iso-8859-1');
 
 // Error codes
Index: /trunk/include/functions_user.inc.php
===================================================================
--- /trunk/include/functions_user.inc.php	(revision 878)
+++ /trunk/include/functions_user.inc.php	(revision 879)
@@ -498,3 +498,37 @@
   return $groupname;
 }
+
+/**
+ * return the file path of the given language filename, depending on the
+ * availability of the file
+ *
+ * in descending order of preference: user language, default language,
+ * PhpWebGallery default language.
+ *
+ * @param string filename
+ * @return string filepath
+ */
+function get_language_filepath($filename)
+{
+  global $user, $conf;
+  
+  $directories =
+    array(
+      PHPWG_ROOT_PATH.'language/'.$user['language'],
+      PHPWG_ROOT_PATH.'language/'.$conf['default_language'],
+      PHPWG_ROOT_PATH.'language/'.PHPWG_DEFAULT_LANGUAGE
+      );
+
+  foreach ($directories as $directory)
+  {
+    $filepath = $directory.'/'.$filename;
+    
+    if (file_exists($filepath))
+    {
+      return $filepath;
+    }
+  }
+  
+  return false;
+}
 ?>
Index: /trunk/popuphelp.php
===================================================================
--- /trunk/popuphelp.php	(revision 878)
+++ /trunk/popuphelp.php	(revision 879)
@@ -33,21 +33,13 @@
 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
 
-// language files
-$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language'];
-$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language'];
-
-if (file_exists($user_langdir.'/help/'.$_GET['page'].'.html'))
-{
-  $html_file = $user_langdir.'/help/'.$_GET['page'].'.html';
-}
-else
-{
-  $html_file = $conf_langdir.'/help/'.$_GET['page'].'.html';
-}
-
 $page['body_id'] = 'thePopuphelpPage';
 $page['gallery_title'] = $title = l10n('PhpWebGallery Help');
 include(PHPWG_ROOT_PATH.'include/page_header.php');
-$template->set_filenames(array('help_content' => $html_file));
+
+$template->set_filenames(
+  array(
+    'help_content' => get_language_filepath('help/'.$_GET['page'].'.html')
+    )
+  );
 
 $template->set_filenames(array('popuphelp' => 'popuphelp.tpl'));
