Skip to content

Commit

Permalink
Adapt load_config hook to fallback to english if no valid language is
Browse files Browse the repository at this point in the history
present
Move CI system language files back to their correct location
(form_validation_lang)
Add upload_lang.php and email_lang.php to system files (default english
version for the time being)
Add account_number check when importing customer data from excel
Avoid unnecessary calls to check_item_number when importing items from
excel
  • Loading branch information
jekkos committed Feb 17, 2015
1 parent c7c4ac1 commit 40eef74
Show file tree
Hide file tree
Showing 27 changed files with 410 additions and 96 deletions.
15 changes: 11 additions & 4 deletions application/controllers/customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,18 @@ function do_excel_import()
);

$customer_data=array(
'account_number'=>$data[12]=='' ? null:$data[12],
'taxable'=>$data[13]=='' ? 0:1,
'taxable'=>$data[13]=='' ? 0:1
);

if(!$this->Customer->save($person_data,$customer_data))
$account_number = $data[12];
$invalidated = false;
if ($account_number != "")
{
$customer_data['account_number'] = $account_number;
$invalidated = $this->Customer->account_number_exists($account_number);
}

if($invalidated || !$this->Customer->save($person_data,$customer_data))
{
$failCodes[] = $i;
}
Expand All @@ -185,7 +192,7 @@ function do_excel_import()
}

$success = true;
if(count($failCodes) > 1)
if(count($failCodes) > 0)
{
$msg = "Most customers imported. But some were not, here is list of their CODE (" .count($failCodes) ."): ".implode(", ", $failCodes);
$success = false;
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,12 @@ function do_excel_import()
'custom10' => $data[23] /** GARRISON ADDED 5/6/2013 **/
);
$item_number = $data[0];
$invalidated = false;
if ($item_number != "")
{
$item_data['item_number'] = $item_number;
$invalidated = $this->Item->item_number_exists($item_number);
}
$invalidated = $this->Item->item_number_exists($item_number);
}
else
{
Expand Down
90 changes: 90 additions & 0 deletions application/core/MY_Lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_Lang extends CI_Lang
{

function MY_Lang()
{
parent::__construct();
}

function switch_to( $idiom )
{
$CI =& get_instance();
if( is_string( $idiom ) )
{
$CI->config->set_item( 'language', $idiom );
$loaded = $this->is_loaded;
$this->is_loaded = array();

foreach($loaded as $file)
{
$this->load( str_replace( '_lang.php', '', $file ) );
}
}
}

/**
* Fetch a single line of text from the language array. Takes variable number
* of arguments and supports wildcards in the form of '%1', '%2', etc.
* Overloaded function.
*
* @access public
* @return mixed false if not found or the language string
*/
function line($line = '')
{
//get the arguments passed to the function
$args = func_get_args();

//count the number of arguments
$c = count($args);

//if one or more arguments, perform the necessary processing
if ($c)
{
//first argument should be the actual language line key
//so remove it from the array (pop from front)
$line = array_shift($args);

//check to make sure the key is valid and load the line
if ($line == '')
{
$line = FALSE;
}
else
{
if (isset($this->language[$line]))
{
$line = $this->language[$line];
//if the line exists and more function arguments remain
//perform wildcard replacements
if ($args)
{
$i = 1;
foreach ($args as $arg)
{
$line = preg_replace('/\%'.$i.'/', $arg, $line);
$i++;
}
}
}
else
{
// just return label name (with TBD)
$line = $line . ' (TBD)';
log_message('error', 'Could not find the language line "'.$line.'"');
}
}
}
else
{
//if no arguments given, no language line available
$line = false;
}

return $line;
}
}

?>
12 changes: 9 additions & 3 deletions application/hooks/load_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ function load_config()
if ( $CI->config->item( 'language' ) )
{
$CI->config->set_item( 'language', $CI->config->item( 'language' ) );

$map = directory_map('./application/language/' . $CI->config->item( 'language' ));
// fallback to english if language folder does not exist
$language = $CI->config->item( 'language' );
if (!file_exists('./application/language/' . $language))
{
$language = 'en';
}

$map = directory_map('./application/language/' . $language);
foreach($map as $file)
{
if ( substr(strrchr($file,'.'),1) == "php")
{
$CI->lang->load( str_replace( '_lang.php', '', $file ) );
$CI->lang->load( str_replace( '_lang.php', '', $file ), $language);
}
}

}

//Set timezone from config database
Expand Down
18 changes: 0 additions & 18 deletions application/language/fr/form_validation_lang.php

This file was deleted.

18 changes: 0 additions & 18 deletions application/language/nl-BE/form_validation_lang.php

This file was deleted.

18 changes: 0 additions & 18 deletions application/language/th/form_validation_lang.php

This file was deleted.

26 changes: 0 additions & 26 deletions application/libraries/MY_Language.php

This file was deleted.

24 changes: 24 additions & 0 deletions system/language/es/email_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$lang['email_must_be_array'] = "The email validation method must be passed an array.";
$lang['email_invalid_address'] = "Invalid email address: %s";
$lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s";
$lang['email_attachment_unreadable'] = "Unable to open this attachment: %s";
$lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc";
$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.";
$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.";
$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.";
$lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s";
$lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings.";
$lang['email_no_hostname'] = "You did not specify a SMTP hostname.";
$lang['email_smtp_error'] = "The following SMTP error was encountered: %s";
$lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password.";
$lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s";
$lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s";
$lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s";
$lang['email_smtp_data_failure'] = "Unable to send data: %s";
$lang['email_exit_status'] = "Exit status code: %s";


/* End of file email_lang.php */
/* Location: ./system/language/english/email_lang.php */
File renamed without changes.
22 changes: 22 additions & 0 deletions system/language/es/upload_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$lang['upload_userfile_not_set'] = "Unable to find a post variable called userfile.";
$lang['upload_file_exceeds_limit'] = "The uploaded file exceeds the maximum allowed size in your PHP configuration file.";
$lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form.";
$lang['upload_file_partial'] = "The file was only partially uploaded.";
$lang['upload_no_temp_directory'] = "The temporary folder is missing.";
$lang['upload_unable_to_write_file'] = "The file could not be written to disk.";
$lang['upload_stopped_by_extension'] = "The file upload was stopped by extension.";
$lang['upload_no_file_selected'] = "You did not select a file to upload.";
$lang['upload_invalid_filetype'] = "The filetype you are attempting to upload is not allowed.";
$lang['upload_invalid_filesize'] = "The file you are attempting to upload is larger than the permitted size.";
$lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceeds the maximum height or width.";
$lang['upload_destination_error'] = "A problem was encountered while attempting to move the uploaded file to the final destination.";
$lang['upload_no_filepath'] = "The upload path does not appear to be valid.";
$lang['upload_no_file_types'] = "You have not specified any allowed file types.";
$lang['upload_bad_filename'] = "The file name you submitted already exists on the server.";
$lang['upload_not_writable'] = "The upload destination folder does not appear to be writable.";


/* End of file upload_lang.php */
/* Location: ./system/language/english/upload_lang.php */
24 changes: 24 additions & 0 deletions system/language/id/email_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$lang['email_must_be_array'] = "The email validation method must be passed an array.";
$lang['email_invalid_address'] = "Invalid email address: %s";
$lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s";
$lang['email_attachment_unreadable'] = "Unable to open this attachment: %s";
$lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc";
$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.";
$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.";
$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.";
$lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s";
$lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings.";
$lang['email_no_hostname'] = "You did not specify a SMTP hostname.";
$lang['email_smtp_error'] = "The following SMTP error was encountered: %s";
$lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password.";
$lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s";
$lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s";
$lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s";
$lang['email_smtp_data_failure'] = "Unable to send data: %s";
$lang['email_exit_status'] = "Exit status code: %s";


/* End of file email_lang.php */
/* Location: ./system/language/english/email_lang.php */
File renamed without changes.
22 changes: 22 additions & 0 deletions system/language/id/upload_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$lang['upload_userfile_not_set'] = "Unable to find a post variable called userfile.";
$lang['upload_file_exceeds_limit'] = "The uploaded file exceeds the maximum allowed size in your PHP configuration file.";
$lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form.";
$lang['upload_file_partial'] = "The file was only partially uploaded.";
$lang['upload_no_temp_directory'] = "The temporary folder is missing.";
$lang['upload_unable_to_write_file'] = "The file could not be written to disk.";
$lang['upload_stopped_by_extension'] = "The file upload was stopped by extension.";
$lang['upload_no_file_selected'] = "You did not select a file to upload.";
$lang['upload_invalid_filetype'] = "The filetype you are attempting to upload is not allowed.";
$lang['upload_invalid_filesize'] = "The file you are attempting to upload is larger than the permitted size.";
$lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceeds the maximum height or width.";
$lang['upload_destination_error'] = "A problem was encountered while attempting to move the uploaded file to the final destination.";
$lang['upload_no_filepath'] = "The upload path does not appear to be valid.";
$lang['upload_no_file_types'] = "You have not specified any allowed file types.";
$lang['upload_bad_filename'] = "The file name you submitted already exists on the server.";
$lang['upload_not_writable'] = "The upload destination folder does not appear to be writable.";


/* End of file upload_lang.php */
/* Location: ./system/language/english/upload_lang.php */
30 changes: 22 additions & 8 deletions system/language/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<?php

<p>Directory access is forbidden.</p>
$lang['email_must_be_array'] = "The email validation method must be passed an array.";
$lang['email_invalid_address'] = "Invalid email address: %s";
$lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s";
$lang['email_attachment_unreadable'] = "Unable to open this attachment: %s";
$lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc";
$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.";
$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.";
$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.";
$lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s";
$lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings.";
$lang['email_no_hostname'] = "You did not specify a SMTP hostname.";
$lang['email_smtp_error'] = "The following SMTP error was encountered: %s";
$lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password.";
$lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s";
$lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s";
$lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s";
$lang['email_smtp_data_failure'] = "Unable to send data: %s";
$lang['email_exit_status'] = "Exit status code: %s";

</body>
</html>

/* End of file email_lang.php */
/* Location: ./system/language/english/email_lang.php */

0 comments on commit 40eef74

Please sign in to comment.