Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default [Done v2.0] Incorrect Language Validation

    I recently installed a second language and when I logged into the admin interface it reported an error:
    MISSING LANGUAGE FILES OR DIRECTORIES

    My operating system is a windows 2003 server.
    The zen cart is 1.3.9d

    The error is referring to the missing language in the admin section, which does not exist. Further testing shows that it is not checking for the existence of the language in the includes/language folder at all.

    So what its doing is reporting an error on something that isn't and not even checking what it's supposed to be.

    The issue is two fold, you may multiple languages in your website but only one in the admin section to administer the site.

    If you add a language and it does not exist in the admin section you should not get an error. On the other hand, if you do have it in both your web site and the admin interface, it should be checked to be sure both the file and directory exist.

    The code at the top of admin/includes/header.php is where this disaster is all happening: This is the un-edited code exactly as it's being distributed.
    PHP Code:
     // Show Languages Dropdown for convenience only if main filename and directory exists
    if ((basename($PHP_SELF) != FILENAME_DEFINE_LANGUAGE '.php') and (basename($PHP_SELF) != FILENAME_PRODUCTS_OPTIONS_NAME '.php') and empty($action)) {
      
    $languages zen_get_languages();
      if (
    sizeof($languages) > 1) {
        
    $languages_array = array();
        
    $languages_selected $_GET['language'];
        
    $missing_languages='';
        for (
    $i 0$n sizeof($languages); $i $n$i++) {
          
    $test_directoryDIR_WS_LANGUAGES $languages[$i]['directory'];
          
    $test_fileDIR_WS_LANGUAGES $languages[$i]['directory'] . '.php';
          if ( 
    file_exists($test_file) and file_exists($test_directory) ) {
            
    $count++;
            
    $languages_array[] = array('id' => $languages[$i]['code'],
                                     
    'text' => $languages[$i]['name']);
    //        if ($languages[$i]['directory'] == $language) {
            
    if ($languages[$i]['directory'] == $_SESSION['language']) {
              
    $languages_selected $languages[$i]['code'];
            }
          } else {
            
    $missing_languages .= ' ' ucfirst($languages[$i]['directory']) . ' ' $languages[$i]['name'];
          }
        }

    // if languages in table do not match valid languages show error message
        
    if ($count != sizeof($languages)) {
          
    $messageStack->add('MISSING LANGUAGE FILES OR DIRECTORIES ...' $missing_languages,'caution');
        }
        
    $hide_languagesfalse;
      } else {
        
    $hide_languagestrue;
      } 
    // more than one language
    } else {
      
    $hide_languagestrue;
    // hide when other language dropdown is used 
    This is, to say the least, a bit of a mess since its not doing any thing useful or correctly.

    The correct way:
    Once the languages listed in the db have been retrieved we need to check to see if the directory and file exists in the includes/languages directory, as these must exist.

    While we're at it we can check to see it the same language is also being used in the admin section (but it doesn't have to be).

    In the case of the website languages both the directory and file must exist or an error should be reported/generated.

    If both parts do not exist in admin/includes/languages it should not be considered an error and ignored.
    However, if one part exists, either the directory or the file, then it can or should be considered an error.

    Here is how it can be done which addresses what I've been talking about.
    PHP Code:
    // Check to see if each language directory and file exists.
    // Create an Admin Languages Dropdown list of only those languages used by the admin interface.
    $hide_languagestrue// first, initialize $hide_languages to get rid of all the crap in the else conditions that were at the end of this if statement
    if ((basename($PHP_SELF) != FILENAME_DEFINE_LANGUAGE '.php') and (basename($PHP_SELF) != FILENAME_PRODUCTS_OPTIONS_NAME '.php') and empty($action)) {
      
    $languages_array = array();
      
    $languages zen_get_languages();
      if (
    sizeof($languages) > 1) {
        
    $languages_selected $_SESSION['language'];
        
    $missing_languages=$missing_admin_languages='';
        
    $count 0;
        for (
    $i 0$n sizeof($languages); $i $n$i++) {
          
    // Check for the catalog language directory and file
          
    $test_directoryDIR_FS_CATALOG_LANGUAGES $languages[$i]['directory'] ;
          
    $test_fileDIR_FS_CATALOG_LANGUAGES $languages[$i]['directory'] . '.php';
          
    $isFile file_exists($test_file);
          
    $isDir file_exists($test_directory);
          if ( !
    $isFile || !$isDir ) {
            if ( !
    $isFile && !$isDir ) { $missing_languages .= ' Missing directory: ' $test_directory ', and file: '$test_file;}
            else if ( !
    $isDir ) { $missing_languages .= ' Missing directory: ' $test_directory;}
            else { 
    $missing_languages .= ' Missing file: ' $test_file;}
          }
          
    // Check to see if this language is also being used by admin interface.
          
    $test_directoryDIR_WS_LANGUAGES $languages[$i]['directory'] ;
          
    $test_fileDIR_WS_LANGUAGES $languages[$i]['directory'] . '.php';
          
    $isFile file_exists($test_file);
          
    $isDir file_exists($test_directory);
          if ( 
    $isFile and $isDir ) {
            
    $count++;
            
    $languages_array[] = array('id' => $languages[$i]['code'], 'text' => $languages[$i]['name']);
            if (
    $languages[$i]['directory'] == $_SESSION['language']) {
              
    $languages_selected $languages[$i]['code'];
            }
          } else if ( !
    $isFile and !$isDir ) { // When both parts are missing it just means this language does not exist in the admin section 
            
    continue;
          } else {
            if ( !
    $isDir ) { $missing_admin_languages .= ' Missing directory: ' DIR_WS_ADMIN $test_directory;}
            else { 
    $missing_admin_languages .= ' Missing file: ' DIR_WS_ADMIN $test_file;}
          }
        }
        if ( 
    $missing_admin_languages !== '') {
          
    $messageStack->add('MISSING ADMIN LANGUAGE FILES OR DIRECTORIES ...' $missing_admin_languages,'caution');
        }
        if ( 
    $missing_languages !== '') { 
          
    $messageStack->add('MISSING CATALOG LANGUAGE FILES OR DIRECTORIES ...' $missing_languages,'caution');
        }
        if(
    $count 1$hide_languages false;
      } 

    In the admin interface, the select language option list will only be generated if there is more than 1 language in the admin section.
    And, it will only contain the languages in the admin/includes/langauges directory not all the languages listed in the database.


    Well there you have it, do what you like with it.
    Last edited by glenara; 29 Jul 2010 at 11:05 PM.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Incorrect Language Validation

    Quote Originally Posted by glenara View Post
    The issue is two fold, you may multiple languages in your website but only one in the admin section to administer the site.

    If you add a language and it does not exist in the admin section you should not get an error.
    One serious caveat: if you're corresponding with customers from your admin, all correspondence will happen in the selected language. So, if you're sending emails from your admin while in "English", then all your emails will go to the customer in English, even if the customer did their shopping in French or Spanish, or whatever. If you want the emails to be sent from the other language, you need to switch to that language first. But, if you haven't installed that language on your admin side, then ... well ... you won't be able to do that.
    It's your customers who suffer when you don't install the admin-side language pack.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2010
    Location
    Edmonton, Alberta, Canada
    Posts
    13
    Plugin Contributions
    0

    Default Re: Incorrect Language Validation

    Quote Originally Posted by DrByte View Post
    One serious caveat: if you're corresponding with customers from your admin, all correspondence will happen in the selected language. So, if you're sending emails from your admin while in "English", then all your emails will go to the customer in English, even if the customer did their shopping in French or Spanish, or whatever. If you want the emails to be sent from the other language, you need to switch to that language first. But, if you haven't installed that language on your admin side, then ... well ... you won't be able to do that.
    It's your customers who suffer when you don't install the admin-side language pack.
    Thanks for the feedback, but I'm not sure it's a caveat. Your point is well taken, however, if person chooses not to install the languages on the admin side then he won't get the annoying error persisting across the top of the page.

    On the other hand this code segment still checks to see if both parts exist, ie that they match in the both the site and the admin sections. It will only be ignored if the entire admin section is missing which would be the installers choice.

    In my initial effort to get rid of the message, I simply created an empty directory and added the file that contained the following:

    PHP Code:
    <?php

    exit("<div style='text-align:center; margin-top: 200px; color:red; font-weight: bold;'>There is no French admin section.<br>
          Use Back Button and select English.<br><br>
          "
    );

    ?>
    This does address the fact the admin language has not been installed and gets rid of the error message. This is one way to deal with missing admin sections.

    With that said and taking your caveat/warning into consideration, we could modify my code segment as follows:
    PHP Code:
    // Check to see if each language directory and file exists.
    // Create an Admin Languages Dropdown list of only those languages used by the admin interface.
    $hide_languagestrue// first, initialize $hide_languages to get rid of all the crap in the else conditions that were at the end of this if statement
    if ((basename($PHP_SELF) != FILENAME_DEFINE_LANGUAGE '.php') and (basename($PHP_SELF) != FILENAME_PRODUCTS_OPTIONS_NAME '.php') and empty($action)) {
      
    $languages_array = array();
      
    $languages zen_get_languages();
      if (
    sizeof($languages) > 1) {
        
    $languages_selected $_SESSION['language'];
        
    $missing_languages=$missing_admin_languages='';
        for (
    $i 0$n sizeof($languages); $i $n$i++) {
          
    // Check for the catalog language directory and file
          
    $test_directoryDIR_FS_CATALOG_LANGUAGES $languages[$i]['directory'] ;
          
    $test_fileDIR_FS_CATALOG_LANGUAGES $languages[$i]['directory'] . '.php';
          
    $isFile file_exists($test_file);
          
    $isDir file_exists($test_directory);
          if ( !
    $isFile || !$isDir ) {
            if ( !
    $isFile && !$isDir ) { $missing_languages .= ' Missing directory: ' $test_directory ', and file: '$test_file;}
            else if ( !
    $isDir ) { $missing_languages .= ' Missing directory: ' $test_directory;}
            else { 
    $missing_languages .= ' Missing file: ' $test_file;}
          }
          
    // Check to see if this language is also being used by admin interface.
          
    $test_directoryDIR_WS_LANGUAGES $languages[$i]['directory'] ;
          
    $test_fileDIR_WS_LANGUAGES $languages[$i]['directory'] . '.php';
          
    $isFile file_exists($test_file);
          
    $isDir file_exists($test_directory);
          if ( 
    $isFile and $isDir ) {
            
    $languages_array[] = array('id' => $languages[$i]['code'], 'text' => $languages[$i]['name']);
            if (
    $languages[$i]['directory'] == $_SESSION['language']) {
              
    $languages_selected $languages[$i]['code'];
            }
          } else if ( !
    $isFile and !$isDir ) { // When both parts are missing it just means this language does not exist in the admin section 
            
    $languages_array[] = array('id' => $languages[$i]['code'], 'text' => $languages[$i]['name'] . ' (not installed)');
          } else {
            if ( !
    $isDir ) { $missing_admin_languages .= ' Missing directory: ' DIR_WS_ADMIN $test_directory;}
            else { 
    $missing_admin_languages .= ' Missing file: ' DIR_WS_ADMIN $test_file;}
          }
        }
        if ( 
    $missing_admin_languages !== '') {
          
    $messageStack->add('MISSING ADMIN LANGUAGE FILES OR DIRECTORIES ...' $missing_admin_languages,'caution');
        }
        if ( 
    $missing_languages !== '') { 
          
    $messageStack->add('MISSING CATALOG LANGUAGE FILES OR DIRECTORIES ...' $missing_languages,'caution');
        }
        if(
    sizeof($languages) > 1$hide_languages false;
      }

    Now, the drop-down list is created but next to the missing language(s) it reads: French (not installed)

    This might be the best of both worlds. It keeps the user informed about the languages missing in the admin side without creating the MISSING LANGUAGE FILES OR DIRECTORIES ... error, but still generates the error if there is file/directory mismatch.

    In my clients case, he'll be responding in English regardless because he doesn't know any French.

    In his case he is offering all his products in French although he doesn't speak it.

    I suspect there are a lot of others that do the same thing, ie offer there products in languages they don't speak.

    Anyway, good point and I think we'll have to look at how we handle our auto responses. (possibly a partial admin section to deal with the language email responses)

    Thanks for the constructive criticism.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Incorrect Language Validation

    Your points are understood. Thanks for the suggestions.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Sep 2008
    Location
    Sweden
    Posts
    94
    Plugin Contributions
    4

    Default Re: Incorrect Language Validation

    This points is also important for orders.php page.

    It should be great if it is not made for the language the order is made in. As I wrote in another bug post.

    All important point in this post is that I tryed to say in that post.

    No part of the administration should be in need of a specific language. Im not thinking about the invoice function and packing list because it still has to be in the language the order was in but then this post point is important.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Incorrect Language Validation

    Quote Originally Posted by FrilansReklam View Post
    This points is also important for orders.php page.

    It should be great if it is not made for the language the order is made in. As I wrote in another bug post.

    All important point in this post is that I tryed to say in that post.

    No part of the administration should be in need of a specific language. Im not thinking about the invoice function and packing list because it still has to be in the language the order was in but then this post point is important.
    I don't dispute that it's undesirable that the admin can only email in the language currently in use by the administrator.
    But, to fix that is extremely difficult in Zen Cart v1.x.x.
    However, due to some slick architectural changes in v2.x, it's looking like we'll be able to make it send emails in the language used by the customer when the purchase was made.

    So ... while you may want to raise numerous bug reports about the fact that you don't like that it can only send from one language, it's not going to be fixed in Zen Cart v1.x.x. Stay tuned for v2.x in the near future, where it'll be more possible. Until then, duplicate bug reports about your wished feature will be ignored. Sorry.

    And please don't hijack someone else's discussion of a very different matter just to slide in your complaint another time.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v151 *[Done v1.6.0] Incorrect comparison in ot_cod_fee.php
    By lat9 in forum Bug Reports
    Replies: 1
    Last Post: 6 Apr 2013, 12:16 AM
  2. Replies: 13
    Last Post: 4 May 2010, 10:47 AM
  3. Replies: 2
    Last Post: 14 Nov 2009, 03:01 PM
  4. [Done v1.3.9] Validation error in Shipping Estimator
    By torvista in forum Bug Reports
    Replies: 1
    Last Post: 11 Nov 2009, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg