set_events not working after upgrading phpgrid

Questionsset_events not working after upgrading phpgrid
santosh asked 8 years ago

set_events not working after upgrading phpgrid. the fields modifier and modified are not updating now. Can you please help

<?php

// include db config
include_once("../config.php");
if (!$user->checkMembership("1,2,4,6,8,11"))redirect_to("/accessDenied.php");

// include and create object
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");

$g = new jqgrid();

// set few params
$grid["caption"] = "Front Sheet 3G";
$grid["shrinkToFit"] = false;
$grid["autowidth"] = true; // expand grid to screen width
//$grid["width"] = "1200";
$grid["multiselect"] = true;
$grid["ignoreCase"] = true; // do case insensitive sorting
$grid["altRows"] = true;
$grid["altclass"] = "myAltRowClass";
$grid["sortname"] = 'id';
$grid["sortorder"] = "desc";
$grid["toolbar"] = "bottom";

// export XLS file
// export to excel parameters
$grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "sheetname"=>"test");
$grid["reloadedit"] = true;
$g->set_options($grid);

$e["on_after_insert"] = array("add_modifier", null, true);
$e["on_after_update"] = array("update_modifier", null, true);

$g->set_events($e);

function update_modifier($data)
{
require("../init.php");

mysqli_query($con,"UPDATE mytable SET Modified= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s') WHERE id = {$data["id"]}");
mysqli_query($con,"UPDATE mytable SET Modifier= ' " . $user->name . " ' WHERE id = {$data["id"]}");

}

//This is not used as we want users to only submit data using the form
function add_modifier($data)
{
require("../init.php");
mysqli_query($con,"UPDATE mytable SET Submitted= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s') WHERE id = {$data["id"]}");
mysqli_query($con,"UPDATE mytable SET Submitter= ' " . $user->name . " ' WHERE id = {$data["id"]}");
mysqli_query($con,"UPDATE mytable SET Status= 'New' WHERE id = {$data["id"]}");
}

// you can provide custom SQL query to display data
$g->select_command = "select * from mytable";

// this db table will be used for add,edit,delete
$g->table = "mytable";

//Data for export// Create view with above sql
$_SESSION['selection']= "mytable";

$cols = array();

// you can customize your own columns …
$col = array();
$col["name"] = "id";
$col["dbname"] = "frontSheet4g.id";
$col["title"] = "id";
$col["width"] = "50";
if (editGrid != 'NO'){
$col["editable"] = false;
}
$cols[] = $col;

$col = array();
$col["name"] = "Modifier";
$col["dbname"] = "frontSheet4g.Modifier";
$col["title"] = "Modified By";
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["name"] = "Modified";
$col["dbname"] = "frontSheet4g.Modified";
$col["title"] = "Modified On";
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["name"] = "Submitter";
$col["dbname"] = "frontSheet4g.Submitter";
$col["title"] = "Submitted By";
$col["editable"] = false;
$cols[] = $col;

$col = array();
$col["name"] = "Submitted";
$col["dbname"] = "frontSheet4g.Submitted";
$col["title"] = "Submitted On";
$col["editable"] = false;
$cols[] = $col;

// pass the cooked columns to grid
$g->set_columns($cols);

// generate grid output, with unique grid name as 'list1'
$out = $g->render("list1");
?>

<?php include("../header.php");?>
<div id="wrap" class="top-space">
<div class="screen-95 tablet-90 phone-100 push-center">
<div class="wojo form">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="/grid/lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="/grid/lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="/grid/lib/js/jquery.min.js" type="text/javascript"></script>
<script src="/grid/lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="/grid/lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="/grid/lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>

<div style="margin:10px">

<?php echo $out?>
<br>

<button onclick='downloadRecord()' class="btn waves-effect waves-light">Download Scripts<i class="material-icons right">file_download</i></button>
    
<a href="/grid/export.php">
<button class="btn waves-effect waves-light">Download Table<i class="material-icons right">file_download</i></button>

</div>
</body>
</html>
</div>
</div>
</div>
<?php include("../footer.php");?>

2 Answers
Abu Ghufran answered 8 years ago

Apparently it looks like $con is not defined inside callback function.

You can put phpgrid_error("test"); inside function to see if it is executing.

santosh answered 8 years ago

spot on. Thanks for the answer
$con was not required within function as I was using mysql (now using mysqli)

Your Answer

8 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?