2

So I have my function (using ajax):

function show_statsMonth($element,$id,$annee)
{
    $objResponse = new xajaxResponse();
    $tpl = new PHPTAL();
    $tpl->setTemplate('templates/lightboxes/statsDays.tpl.xhtml');

    $data = array();

    /*Enregistrement du nombre d'acces par mois dans un tableau*/
    $objDatabase = QApplication::$Database[1];
}

After i create my two dates

$dateL = explode('-', date("Y-m-d",mktime(0,0,0,2,1)) );
    $dayL = new QDateTime();
    $dayL->setDate(intval($dateL[0]), intval($dateL[1]), intval($dateL[2]));
    $dateF = explode('-', date("Y-m-d",mktime(0,0,0,1,1)) );
    $dayF = new QDateTime();
    $dayF->setDate(intval($dateF[0]), intval($dateF[1]), intval($dateF[2]));

     if($annee ==NULL){
        $annee='2015';
     }
     else{
        $dayL->setDate(intval($annee), intval($dateL[1]), intval($dateL[2]));
        $dayF->setDate(intval($annee), intval($dateF[1]), intval($dateF[2]));
    }

And at the end i call my template where i have my Jquery Datepicker like this :

$objResponse->call("activateDatePickerMonth2",$element,$id,'new');

And my datepicker is like this :

function activateDatePickerMonth2(element,id,action) {

            $("#watchby li a").removeClass("active");
            $("#as_a_month").addClass("active");
            $('.date-picker').datepicker( "destroy" );
            $('.date-picker').datepicker( {
                changeYear: true,
                showButtonPanel: false,
                dateFormat: 'yy-mm',
              onChangeMonthYear: function(year, month, inst) {
                    dpY=year;
                    dpM=month;

                    xajax_show_statsMonth(element,id,dpY);

                     }

            });$

I don't know why but my datepicker is stuck on the same year, I can't change the year I select, it's stuck on '2015'

My question is why, and how i can create a new template with the year i give on the datepicker, to display the new stats.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
sleakerz
  • 169
  • 19

1 Answers1

0

My guess is that this piece of code is causing the problem:

// I do not see $annee being used before this, so it might be always NULL here
if($annee == NULL){
    $annee='2015';
    // I also do not see $annee being used again after this. If we set it to '2015' where is it used again?
}else{
    $dayL->setDate(intval($annee), intval($dateL[1]), intval($dateL[2]));
    $dayF->setDate(intval($annee), intval($dateF[1]), intval($dateF[2]));
    // Why are you setting the dates again here, if you just set them above?
}

Could you please clarify this code?

Praxis Ashelin
  • 5,137
  • 2
  • 20
  • 46
  • What i do here, is like i call my function with the parameter $annee , i say if it's null, $annee take 2015, because when i call my datepicker, the year default is 2015 – sleakerz Apr 28 '15 at 12:15
  • When i click on a button to show stats, i click on it everytime – sleakerz Apr 29 '15 at 06:59
  • Well I think the `$annee` is always being reset to `'2015'` here and that is causing the problem. – Praxis Ashelin Apr 29 '15 at 07:15
  • I created another function, so i have one to show the stats, and another to refresh, and now, it's seems to work :) Thanks ! – sleakerz Apr 29 '15 at 08:06