예제 #1
0
 /**
  * Perform the all CRUD operations depending on the oper param send from the grid
  * and the table element
  * If the primaryKey is not set we try to obtain it using jqGridDB::getPrimaryKey
  * If the primary key is not set or can not be obtained the operation is aborted.
  * Also the method call the queryGrid to perform the grid ouput
  * @param array $summary - set which columns should be sumarized in order to be displayed to the grid
  * By default this parameter uses SQL SUM function: array("colmodelname"=>"sqlname");
  * It can be set to use the other one this way
  * array("colmodelname"=>array("sqlname"=>"AVG"));
  * By default the first field correspond to the name of colModel the second to
  * the database name
  * @param array $params additional parameters that can be passed to the query
  * @param string $oper if set the requested oper operation is performed without to check
  * the parameter sended from the grid.
  */
 public function editGrid(array $summary = null, array $params = null, $oper = false, $echo = true)
 {
     if (!$oper) {
         $oper = $this->oper ? $this->oper : "grid";
     }
     switch ($oper) {
         case $this->GridParams["editoper"]:
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             if ($this->update($data)) {
                 if ($this->successmsg) {
                     echo $this->successmsg;
                 }
             }
             break;
         case $this->GridParams["addoper"]:
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             if ($this->insert($data)) {
                 if ($this->getLastInsert) {
                     // inline edit here
                     echo $this->getPrimaryKeyId() . "#" . $this->lastId;
                 } else {
                     if ($this->successmsg) {
                         echo $this->successmsg;
                     }
                 }
             }
             break;
         case $this->GridParams["deloper"]:
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             if ($this->delete($data)) {
                 if ($this->successmsg) {
                     echo $this->successmsg;
                 }
             }
             break;
         default:
             return $this->queryGrid($summary, $params, $echo);
     }
 }
예제 #2
0
 public function editGrid(array $summary = null, array $params = null, $oper = false)
 {
     if (!$oper) {
         $oper = $this->GridParams["oper"];
         $oper = jqGridUtils::GetParam($oper, "grid");
     }
     switch ($oper) {
         case $this->GridParams["editoper"]:
             if (strlen($this->table) > 0 && !$this->primaryKey) {
                 $this->primaryKey = jqGridDB::getPrimaryKey($this->table, $this->pdo, $this->dbtype);
                 if (!$this->primaryKey) {
                     die("could not determine primary key");
                 }
             }
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             $this->update($data);
             break;
         case $this->GridParams["addoper"]:
             if (strlen($this->table) > 0 && !$this->primaryKey) {
                 $this->primaryKey = jqGridDB::getPrimaryKey($this->table, $this->pdo, $this->dbtype);
                 if (!$this->primaryKey) {
                     die("could not determine primary key");
                 }
             }
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             $this->insert($data);
             break;
         case $this->GridParams["deloper"]:
             if (strlen($this->table) > 0 && !$this->primaryKey) {
                 $this->primaryKey = jqGridDB::getPrimaryKey($this->table, $this->pdo, $this->dbtype);
                 if (!$this->primaryKey) {
                     die("could not determine primary key");
                 }
             }
             $data = strtolower($this->mtype) == "post" ? jqGridUtils::Strip($_POST) : jqGridUtils::Strip($_GET);
             $this->delete($data);
             break;
         default:
             $this->queryGrid($summary, $params);
     }
 }
예제 #3
0
<?php

require_once '../../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH . "php/jqGrid.php";
// include the driver class
require_once ABSPATH . "php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Get the needed parameters passed from the main grid
$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
if (!$subtable && !$rowid) {
    die("Missed parameters");
}
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = "SELECT OrderID, ProductID, Quantity, UnitPrice FROM order_details WHERE OrderID=?";
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel(null, array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('subsubgrid.php');
// Set some grid options
$grid->setGridOptions(array("width" => 480, "rowNum" => 10, "sortname" => "OrderID", "height" => 'auto', "postData" => array("subgrid" => $subtable, "rowid" => $rowid)));
// Change some property of the field(s)
$grid->navigator = true;
예제 #4
0
<?php

require_once '../../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH . "php/jqGrid.php";
// include the driver class
require_once ABSPATH . "php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Get the needed parameters passed from the main grid
if (isset($_REQUEST["CustomerID"])) {
    $rowid = jqGridUtils::Strip($_REQUEST["CustomerID"]);
} else {
    $rowid = "";
}
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = "SELECT OrderID, RequiredDate, ShipName, ShipCity, Freight FROM orders WHERE CustomerID= ?";
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel(null, array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('detail.php');
// Set some grid options
$grid->setGridOptions(array("rowNum" => 10, "footerrow" => true, "userDataOnFooter" => true, "sortname" => "OrderID", "height" => 110));
// Change some property of the field(s)
$grid->setColProperty("RequiredDate", array("formatter" => "date", "formatoptions" => array("srcformat" => "Y-m-d H:i:s", "newformat" => "m/d/Y"), "search" => false));