Welcome Guest, Not a member yet? Register   Sign In
A PHP Error was encountered Severity: Notice Message: Undefined index
#1

[eluser]adamsmith2059[/eluser]
Hi all,

I have a little issue that I could do with some words of advice on.

Quote:Severity: Notice

Message: Undefined variable: data

Filename: controllers/irc.php

Line Number: 75

Is the error I am getting.

The line it is referring to is:

Code:
$data['country'] = $this->ircmodel->getLeafName($this->_countryId);

And the full code is:

Code:
<?php
class Irc extends CI_Controller
{

    public $_countryId;
    public $_menuId;
    public $fileId;
function __construct()
{
  parent::__construct();
  //mb_internal_encoding("ISO-8859-1");
  //mb_http_output("ISO-8859-1");
  
  $this->freakauth_light->check();

  $this->load->helper('irc', 'Irc');
  $this->load->helper('form');
  
  $this->load->library('report_status');
  //$this->report_status->init();
  
  $this->_container = $this->config->item('FAL_template_dir').'template/container'; // Load View Container

  //$this->fileContent;
  $this->_charLimit = 500; //the limit text per edit block.
  $this->_formAction = base_url().'index.php/tickets/add/editorial.html';
  $this->_fileLocation = 'http://www.mysite.com/';
$this->_js = "[removed]config->item('FAL_js')."/jquery.blockUI.js' type='text/javascript'>[removed]";
  $this->_js .= "[removed]config->item('FAL_js')."/irc.js' type='text/javascript'>[removed]";
}

function index($id = null)
{
  $this->load->library('country_assignment');
  $this->country_assignment->init();
  
  $data['assignedCountries'] = $this->country_assignment->getAssignedCountries(getUserProperty('id'));
  $this->load->model('ircmodel', 'ircmodel');
if($id){
  $data['cmenu'] = loadEditorialCountryMenu($id);
   $data['leftpage'] = $this->config->item('FAL_template_dir').'irc/countrymenu';
}
  $data['page'] = $this->config->item('FAL_template_dir').'irc/test';
  $data['js'] .= "[removed]config->item('FAL_js')."/jquery.boxy.js' type='text/javascript'>[removed]";

  $data['js'] .= "[removed]config->item('FAL_js')."/irc.js' type='text/javascript'>[removed]";
   $data['js'] .= "[removed]config->item('FAL_js')."/ticketsubmit.js'type='text/javascript'>[removed]";  $this->load->vars($data);
  $this->load->view($this->_container);
  
}



/**/

function report($countryId, $menuId, $fileId)
{
  $this->_countryId = $countryId;
  $this->_menuId = $menuId;
  $this->_fileId = $fileId;
  
  $this->load->model('ircmodel', 'ircmodel');
  $filename = $this->_fileLocation.$this->ircmodel->getLeafName($this->_countryId).'/'.$fileId;
  
  ob_start();
  readfile($filename);
  $contents = ob_get_contents();
  //if(!defined($contents)){$contents = "Error: File Not Found";
  ob_end_clean();
  
  $cleancontent = htmlentities(utf8_encode($contents), ENT_QUOTES);

  $data['reports'] = $this->_buildForms($cleancontent, $data);
  $data['user'] = getUserProperty('id');
  $data['country'] = $this->ircmodel->getLeafName($this->_countryId);
  $data['section'] =  $this->ircmodel->getTreeName($this->_menuId);
  $data['topic'] = $this->ircmodel->reverseTopicName($this->_countryId, $this->_menuId, $this->_fileId);
  
  
  $data['cmenu'] = loadEditorialCountryMenu($countryId, $this->_menuId);
  $data['leftpage'] = $this->config->item('FAL_template_dir').'irc/countrymenu';
  
  $data['page'] = $this->config->item('FAL_template_dir').'irc/report';

  $data['js'] .= "[removed]config->item('FAL_js')."/jquery.boxy.js' type='text/javascript'>[removed]";

  $data['js'] .= "[removed]config->item('FAL_js')."/irc.js' type='text/javascript'>[removed]";
   $data['js'] .= "[removed]config->item('FAL_js')."/ticketsubmit.js'type='text/javascript'>[removed]";

  $this->load->vars($data);
  $this->load->view($this->_container);

}

Any help would be greatly appreciated. Smile
#2

[eluser]TheFuzzy0ne[/eluser]
I can't see why the problem would be there, but it's difficult to tell, since Ellis Lab's XSS cleaning has gone to town on your Javascript. Please could you post it as an attachment?
#3

[eluser]adamsmith2059[/eluser]
Thank you Please see attached.below as I can not upload it.

this is for irc.js

Code:
jQuery(document).ready(function(){

    Boxy.DEFAULTS.title = 'Submit corrections ';

// Country report menu
jQuery(".menuitem ul").hide();
jQuery(".selected ul").show();
   jQuery(".submenu h4").click(function(){
    jQuery(".submenu ul").slideUp("fast");
    jQuery(".submenu ul").eq(jQuery(".submenu h4").index(this)).slideDown("fast");
   });
    // load styles, hide elements    
    jQuery(".editBox").css("border", "2px solid white");
    jQuery(".showForm").hide();
jQuery(".editForm").hide();

// Mouse scroll-over the content
    jQuery(".editBox").mouseover(function(){
     jQuery(".editBox").eq(jQuery(".editBox").index(this)).css("color", "black").css("border", "2px solid #0068CF");
     jQuery(".editBox").eq(jQuery(".editBox").index(this)).css("color", "black").css("cursor", "pointer");
     jQuery(".editBox button").eq(jQuery(".editBox").index(this)).show();
    }).mouseout(function(){
     jQuery(".editBox").eq(jQuery(".editBox").index(this)).css("color", "#4c4c4c").css("border", "2px solid white");
     jQuery(".editBox").eq(jQuery(".editBox").index(this)).css("color", "black").css("cursor", "auto");
     jQuery(".editBox button").eq(jQuery(".editBox").index(this)).hide();
    });
  
   // Onclick of the "edit" button
   jQuery(".editBox").click(function(){
       var fbox = ".f"+jQuery(".editBox").eq(jQuery(".editBox").index(this)).attr("name");
         new Boxy(jQuery(fbox)).resize(700,450);

         return false;
});
  
  
  
    jQuery('.cancel').click(function() {
      jQuery.unblockUI();
    return false;
    });

   jQuery('#reload').click(function() {
                jQuery.location.reload();
            });

jQuery('.status-checkbox').change(function(){
  
  var countryId =  jQuery('#countryId').val();
  var page =  jQuery('.status-checkbox').eq(jQuery('.status-checkbox').index(this)).attr('name');
  var status = jQuery('.status-checkbox').eq(jQuery('.status-checkbox').index(this)).attr('checked');
  
  statusupdate(countryId, page,status );
  });
  
  
  
  
// select-option menu
  jQuery("#countryMenu").change(function(){
  var selected = jQuery("#countryMenu").val();
  [removed] = "http://mysite" + selected;    
});  

  
  
});




function statusupdate(countryId,page, status){
  new Ajax.Updater('statusupdate',
      'http://mysite',
      { method:'post',
       postBody:'countryId=' + countryId +'&page;='+ page +'&status;='+ status      
      });
}
#4

[eluser]adamsmith2059[/eluser]
XSS cleaning is set to false in the config
#5

[eluser]TheFuzzy0ne[/eluser]
I think you misunderstood. I'm asking you to post your controller code as an attachment, or somewhere online where I can copy and paste it into my IDE to see if I can reproduce the problem.

If I copy and paste what's in your first post, it's broken. The forum has gone all medieval on your code. It's replaced things with [removed].

Please put your controller code somewhere else. [url="http://pastebin.com/"]Pastebin[/url] might be a good option.
#6

[eluser]adamsmith2059[/eluser]
Oh, sorry Smile

Having one of those days.

http://pastebin.com/iZ0sN8y5
#7

[eluser]TheFuzzy0ne[/eluser]
Bah! it was wishful thinking on my part to think that I could have made that work by commenting out a few lines of code. It seems to have more dependencies than I anticipated. I've made a few suggestions for that method, but I doubt it'll fix the problem.

Code:
// Set defaults, to save errors if the method is called with missing parameters.
function report($countryId='0', $menuId='0', $fileId='0')
{
    $this->_countryId = $countryId;
    $this->_menuId = $menuId;
    $this->_fileId = $fileId;

    $this->load->model('ircmodel', 'ircmodel');
    $filename = $this->_fileLocation.$this->ircmodel->getLeafName($this->_countryId).'/'.$fileId;
    
    // What if the file doesn't exist?
    if ( ! file_exists($filename))
    {
        // Show an error or something?
    }

    //ob_start();
    //readfile($filename);
    //$contents = ob_get_contents();
    
    // Incorrect usage. Use defined() to check for constants that have been defined with define().
    //if(!defined($contents)){$contents = "Error: File Not Found";
    //ob_end_clean();
    
    // Much easier.
    $contents = file_get_contents($filename);

    $cleancontent = htmlentities(utf8_encode($contents), ENT_QUOTES);
    $data['reports'] = $this->_buildForms($cleancontent, $data);
    $data['user']    = getUserProperty('id');
    $data['country'] = $this->ircmodel->getLeafName($this->_countryId);
    $data['section'] =  $this->ircmodel->getTreeName($this->_menuId);
    $data['topic'] = $this->ircmodel->reverseTopicName($this->_countryId, $this->_menuId, $this->_fileId);

    $data['cmenu'] = loadEditorialCountryMenu($countryId, $this->_menuId);
    $data['leftpage'] = $this->config->item('FAL_template_dir').'irc/countrymenu';

    $data['page'] = $this->config->item('FAL_template_dir').'irc/report';

    $data['js'] .= "[removed]config->item('FAL_js')."/jquery.boxy.js' type='text/javascript'>[removed]";
    $data['js'] .= "[removed]config->item('FAL_js')."/irc.js' type='text/javascript'>[removed]";
    $data['js'] .= "[removed]config->item('FAL_js')."/ticketsubmit.js'type='text/javascript'>[removed]";

    //$this->load->vars($data);
    //$this->load->view($this->_container);
    
    // Saves you typing a whole line of code. WOW! :D
    $this->load->view($this->_container, $data);
}

Also, make sure you have error reporting set to E_ALL when you're developing. In your index.php file, put this at the top:

Code:
ini_set('display_errors', '1');
error_reporting(E_ALL);

That might show you a bit more information (warning as well as errors).
#8

[eluser]adamsmith2059[/eluser]
Thank you for that - it is very useful and kind of you.

I have managed to eradicate an error regarding $data by defining it in "function report". But I am now getting these errors.

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined index: value

Filename: controllers/irc.php

Line Number: 192

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined index: js

Filename: controllers/irc.php

Line Number: 47

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined index: js

Filename: controllers/irc.php

Line Number: 87

I have included the entire code in pastebin: http://pastebin.com/mNDC8Whr

It is centring on:

Quote:$data['js'] .= "[removed]config->item('FAL_js')."/jquery.boxy.js' type='text/javascript'>[removed]";
#9

[eluser]TheFuzzy0ne[/eluser]
Looking at your code on Pastebin, both lines 87 and 192 are empty, so it's difficult to see where the problem is...

All three errors are being caused because you are trying to concatenate an undefined index.

Code:
$data['foo'] .= 'This will cause a problem, since $data['foo'] is unset and uninitialised.';

but

Code:
$data['foo']  = '';
$data['foo'] .= 'This won't be a problem, because the index has already been defined as an empty string.';

However, you should be able to fix these types of errors yourself now, since you know what they mean.
#10

[eluser]adamsmith2059[/eluser]
That fixed it! Thank you - Now I need to do more debugging and will probably be back here again! Thank you Smile




Theme © iAndrew 2016 - Forum software by © MyBB