KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to render a based on input parameter using session variable #1484

Open Sowmya opened this topic on on Jun 12, 2020 - 7 comments

Sowmya commented on Jun 12, 2020

Dear KoolReport team,

I have an issue. I have 2 login users 1) Admin and 2) Employee Generate report based on user session id I got the report successfully. But here my issue is, Whenever Admin logged in, he will pass the Employee name, Which Employee Report , he wants to see, this report I can't render. I written the query based on SESSION variable. But it is not executed. Why?

Can you tell me, where I done mistake...

index.php

include APPPATH."reports/WeeklyReport_Ex.php"
$report = new WeeklyReport_EX(array("Empid" => $Empid)); // It shows the ERROR: Undefined variable Empid
$report = new WeeklyReport_EX(array("Empid" =>isset($this->params['Empid'])?Empid:NULL));
WeeklyReport_Ex.php

function setup()
{
 if($_SESSION['Roleid] != 1)
{
    $querystr = " ........."
    ->this->src('default')
    ->this->query($querystr);
    ->pipe(new Pivot(
    ==========
    =========
    ))
->pipe($this->dataStore('EmployeeWeeklyReport))
}
else
{
    if (isset($this->params['Employee']))
    {
         $querystr = " ........."
    ->this->src('default')
    ->this->query($querystr);
    ->pipe(new Pivot(
    ==========
    =========
    ))
->pipe($this->dataStore('EmployeeFilterReport))
    }
   else
    {
         $querystr = " ........."
    ->this->src('default')
    ->this->query($querystr);
    ->pipe(new Pivot(
    ==========
    =========
    ))
    ->pipe($this->dataStore('AdminWeeklyReport))
    }
}
}

WeeklyReport_Ex.view.php

<form method= "post">
<?php
 IF($_SESSION['Roleid'] == 1)
{
?>
<div class = "row">
    <h6> Employee Name </h6>
    <?php
      select2 :: create(array(
        "name"  => "Employee",
        "dataStore" => $this->dataStore("EmployeeFilter"),
        "dataBind" => array("text" => "EmpName" , "value" => "Empid")
        
));
    ?>
</div>
<button type="submit" name= "submitBtn" onclick = "btnClick();">Submit</button>
</form>

<div class = "row">
    <?php
        if($_SESSION['Roleid] != 1)
        {
            PivotTable :: create(array(
                "dataStore" => $this->dataStore('EmployeeWeeklyReport')
            ));
        }
        else
        {
            if(isset($this->params["Empid"]) && $_SESSION['empid'] != $_POST['empid'])
            {
                 PivotTable :: create(array(
                "dataStore" => $this->dataStore(EmployeeFilterReport')     /// This is not giving OUTPUT
            ));
            }
            else
            {
                 PivotTable :: create(array(
                "dataStore" => $this->dataStore('AdminWeeklyReport')
            ));
            }
        }
    ?>
</div>

$(document).ready(function()
{
    function btnClick()
    {
        var Empid = $(this).val();
        $.ajax({
            type : 'POST',
            url  : '<?php echo site_url();?>/WeeklyReport/index',
            data : {Empid : Empid},
            success : function(response){
                    console.log(response);
               },
            error : function()
            {
                alert(error);
            }
        });
    }

});

Thanks in Advance. I already reached my dead line. Please reply me as early as possible. I am waiting for your reply.

Sowmya commented on Jun 12, 2020

Hi Koolreport team, I need your solution as early as possible. Please ...

KoolReport commented on Jun 15, 2020

It seems to me you have undefined $Empid, could you please check

Sowmya commented on Jun 15, 2020

Hi tanks for your reply, Actually I changed my URL code. Now I think I done some thing, But not completely.

$(document).ready(function(){
 $('#Employeeselecet').change(function(){
    var EmpId = $('#Employeeselecet').val();
     window.location.replace("<?php echo base_url();?>index.php/WeeklyReport/index");
});
});

Now how can I pass the Selected EmpId value through this URL. Thanks in Advance, Waiting for your reply.

Sowmya commented on Jun 15, 2020

Hi KoolReport team, Please provide some solution for my issue, How can I pass this selected EmpId variable to controller

KoolReport commented on Jun 15, 2020

May be what you need is

$(document).ready(function(){
 $('#Employeeselecet').change(function(){
    var EmpId = $('#Employeeselecet').val();
     window.location.replace("<?php echo base_url();?>index.php/WeeklyReport/index?Empid="+Empid);
});
});

Then at server-side you can get the empid with GET

$Empid = $_GET["Empid"];
Sowmya commented on Jun 15, 2020

I already given like this only,

$report = new WeeklyReport_Ex(array("EmpId"=> $_GET["EmpId"]));

But it gives the error as undefined EmpId

KoolReport commented on Jun 16, 2020

It could be issue with case sensitive in the Empid. please make sure it use the same name everywhere. In my example giving to you, I use "Empid", and in your code you posted back to me, you use "EmpId". It could be issue.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None