Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Undefined variable: language


ArtcoInc

Recommended Posts

I have a very small file called /catalog/conditions_modal.php. The contents are:
 

<?php
require('includes/languages' . $language . '/conditions.php');
echo TEXT_INFORMATION:
?>

This is called by a Modal to pop up my Terms and Conditions information. My problem is: I am getting a "Undefined variable: language" error.

If I change the file to:

<?php
require('includes/languages/english/conditions.php');
echo TEXT_INFORMATION:
?>

everything works fine. So, how or where do I define the $language variable?

I looked into /admin/define_language.php. I see that in order for a file to be displayed here, there needs to be a 'language' file associated with the mother file. So, I created a file /catalog/includes/language/english/conditions_modal.php. With this file in place, I can now see that conditions_modal.php is listed as a file in admin/define_language.php. Yet, my problem still exists.

So again, what do I have to do to define $language in this file?

TIA

Malcolm

PS: If you are wondering what I'm doing, or why, it's this: I wrote the Modal to pop-up the T&C info as a content_footer module. Everything worked fine, but it loaded the entire T&C 'information' into the footer of every page in the shop. To reduce the page size, I am now using a process to Load Dynamic Content into the modal. This way, the content of the Modal (in this case, the T&C 'information') is only loaded dynamically when the modal is triggered. This trigger calls the above mentioned file, which then echos the T&C information. Like I said, this all works ... except for the $language variable problem.

Link to comment
Share on other sites

@Jack_mcs Thank you.

I added the global statement to the conditions_modal.php file (as listed above). That removed the Undefined Variable error, but the variable $language is blank.

I tried adding the global statement to the content_footer module, but it had no effect.

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

/catalog/conditions_modal.php

(includes test code)

<?php
  global $language;
  require('includes/languages' . $language . '/conditions.php');
//  require('includes/languages/english/conditions.php');
  echo "The variable language is:  " . $language;
  echo TEXT_INFORMATION;
?>

 

/catalog/includes/modules/content/footer/templates/conditions_modal.php

<?php
global $language;
?>

<script>
$('.ModalConditions').on('click',function(){
    $('.modal-body').load('conditions_modal.php?id=2',function(){
        $('#ModalConditions').modal({show:true});
    });
});
</script>

<div class="modal fade" id="ModalConditions" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> X </button>
        <h3 class="modal-title-site text-center" >
          <?php echo MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_HEADING_TITLE; ?>
        </h3>
      </div> <!-- /.modal-header -->

      <div class="modal-body">

      </div> <!-- /.modal-body -->

      <div class="modal-footer">
      </div> <!--  /.modal-footer -->

    </div> <!-- /.modal-content --> 
  </div> <!-- /.modal-dialog --> 
</div> <!-- /.Modal Conditions -->


 

/catalog/includes/modules/content/footer/cm_footer_conditions_modal.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  class cm_footer_conditions_modal {
    var $code;
    var $group;
    var $title;
    var $description;
    var $enabled = false;

    function cm_footer_conditions_modal() {
      $this->code = get_class($this);
      $this->group = basename(dirname(__FILE__));

      $this->title = MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_TITLE;
      $this->description = MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_DESCRIPTION;

      if ( defined('MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_STATUS') ) {
        $this->enabled = (MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_STATUS == 'True');
      }
    }

    function execute() {
      global $oscTemplate, $language;
      
      ob_start();
      include('/includes/modules/content/' . $this->group . '/templates/conditions_modal.php');
      $template = ob_get_clean();

      $oscTemplate->addContent($template, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_STATUS');
    }

    function install() {
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Conditions Modal', 'MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_STATUS', 'True', 'Do you want to enable the Conditions Modal content module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
    }

    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_CONTENT_FOOTER_CONDITIONS_MODAL_STATUS');
    }
  }


 

Link to comment
Share on other sites

$language is defined in application_top.php, so you have to include it before using $language.

Global $language is not required if you use it in the main page file, remove it everywhere.

and yes, @JcMagpie is right, you missed one slash, it must be:

require('includes/languages/' . $language . '/conditions.php');

 

Link to comment
Share on other sites

@raiwa

Thank you!

1) I removed the define from everything except the content_footer module

2) I added a require('includes/application_top.php'): to the trigger file:

<?php
  require('includes/application_top.php');
  require('includes/languages/' . $language . '/conditions.php');
  echo TEXT_INFORMATION;
?>

Now it is working! :smile: Thank you again!

Malcolm

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...