\$("#mne_dialog").ready(function(){ // Some magic to set the proper width of the grid inside a Modal window var modalWidth = \$("#mne_dialog").width(); var modalHeight = \$("#mne_dialog").height() - 52; \$('#mnegrid').jqGrid('setGridWidth',modalWidth); \$('#mnegrid').jqGrid('setGridHeight',modalHeight); \$('#mnegrid').fluidGrid({base:'#mne_dialog', offset:-25}); }); //--------------------------------------------------------------- // END: Mnemonic Select Dialog //--------------------------------------------------------------- }); \$(window).resize(function() { \$('#mnegrid').fluidGrid({base:'#ui-dialog-title-mne_dialog', offset:-25}); }); CUSTOM; $grid->setJSCode($custom); $oper = jqGridUtils::GetParam("oper"); if ($oper == "pdf") { $grid->setPdfOptions(array("header" => true, "margin_top" => 25, "page_orientation" => "P", "header_logo" => "../../../../../images/Logo_450x123_24bit_color.jpg", "header_logo_width" => 45, "header_title" => " Mnemonics Report")); } // Enjoy $summaryrows = array("Seen" => array("Seen" => "SUM")); $grid->renderGrid('#mnegrid', '#mnepager', true, $summaryrows, null, true, true); $conn = null;
/** * Convert the query to record set and set the summary data if available * @param array $params parameters to the qurery * @param array $summary summary option * @param boolean excel * @return recordset object */ protected function _rs($params = null, $summary = null, $excel = false) { if ($this->ExportCommand && strlen($this->ExportCommand) > 0) { $sqlId = $this->ExportCommand; } else { $sqlId = $this->_setSQL(); } if (!$sqlId) { return false; } $sidx = $this->GridParams['sort']; $sidx = jqGridUtils::GetParam($sidx, ''); // get index row - i.e. user click to sort $sord = $this->GridParams['order']; $sord = jqGridUtils::GetParam($sord, ''); // get the direction $search = $this->GridParams['search']; $search = jqGridUtils::GetParam($search, 'false'); // get the direction $sord = preg_replace("/[^a-zA-Z0-9]/", "", $sord); $sidx = preg_replace("/[^a-zA-Z0-9. _,]/", "", $sidx); if ($search == 'true') { if ($this->dbtype == 'mongodb') { $params = jqGridDB::_mongoSearch($params, $this->GridParams, $this->encoding, $this->datearray, $this->mongointegers); } else { $sGrid = $this->_buildSearch($params); if ($this->dbtype == 'array') { $whr = ""; if ($sGrid[0]) { if (preg_match("/WHERE/i", $sqlId)) { // to be refined $whr = " AND " . $sGrid[0]; } else { $whr = " WHERE " . $sGrid[0]; } } $sqlId .= $whr; } else { $whr = $sGrid[0] ? " WHERE " . $sGrid[0] : ""; $sqlId = "SELECT * FROM (" . $sqlId . ") gridsearch" . $whr; } $params = $sGrid[1]; } } if ($this->dbtype !== 'mongodb') { if ($sidx) { $sqlId .= " ORDER BY " . $sidx . " " . $sord; } } if (!$excel && is_array($summary)) { if ($this->dbtype == 'mongodb') { $qryData = jqGridDB::_mongocount($sqlId, $params, $summary); } else { $qryData = $this->_getcount($sqlId, $params, $summary); } unset($qryData->COUNT, $qryData->count); foreach ($qryData as $k => $v) { if ($v == null) { $v = 0; } $this->tmpvar[$k] = $v; } } if ($this->userdata) { if (!$this->tmpvar) { $this->tmpvar = array(); } $this->tmpvar = jqGridUtils::array_extend($this->tmpvar, $this->userdata); } if ($this->debug) { $this->logQuery($sqlId, $params); $this->debugout(); } $ret = $this->execute($sqlId, $params, $sql, true, $this->gSQLMaxRows, 0, $sidx, $sord); return $sql; }
<?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 $rowid = jqGridUtils::GetParam('EmployeeID', 0); // Create the jqGrid instance $grid = new jqGridRender($conn); // Write the SQL Query $grid->SelectCommand = "SELECT OrderID, RequiredDate, ShipName, ShipCity, Freight, EmployeeID FROM orders WHERE EmployeeID= ?"; // set the ouput format to json $grid->dataType = 'json'; // Let the grid create the model $grid->setPrimaryKeyId('OrderID'); $grid->setColModel(null, array((int) $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)); // on beforeshow form when add we get the customer id and set it for posting $beforeshow = <<<BEFORE function(formid)
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // Create the jqGrid instance $grid = new jqGridRender($conn); // this table is 1252 encoded, so we need to tell the grid // Set the table data source $grid->setTable('products'); // set the ouput format to xml since json have problems $grid->dataType = 'json'; // Let the grid create the model $grid->setColModel(); // Set the url from where we obtain the data $grid->setUrl('grid.php'); // Set some grid options //get the height passed as parameter $height = jqGridUtils::GetParam('gridheigh', '200'); $grid->setGridOptions(array("rowNum" => 10, "rowList" => array(10, 20, 30), "sortname" => "ProductID", "height" => $height, "shrinkToFit" => false, "hoverrows" => true)); $grid->setColProperty("ProductID", array("width" => 80)); // We can hide some columns $grid->setColProperty("SupplierID", array("hidden" => true)); $grid->setColProperty("CategoryID", array("hidden" => true)); $grid->setColProperty("UnitsOnOrder", array("hidden" => true)); $grid->setColProperty("ReorderLevel", array("hidden" => true)); $grid->setColProperty("Discontinued", array("hidden" => true)); // Enable toolbar searching $grid->toolbarfilter = true; $grid->setFilterOptions(array("stringResult" => true)); // Enjoy $grid->renderGrid('#grid', '#pager', true, null, null, true, true); $conn = null;
<?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 $rowid = jqGridUtils::GetParam("id"); if (!$rowid) { die("Missed parameters"); } // Create the base jqGrid instance $grid = new jqGrid($conn); // Write the SQL Query $grid->SubgridCommand = "SELECT OrderID, RequiredDate, ShipName, ShipCity, Freight FROM orders WHERE CustomerID=? ORDER BY OrderID desc"; // set the ouput format to json $grid->dataType = 'json'; // Use the build in function for the simple subgrid $grid->querySubGrid(array(&$rowid)); $conn = null;
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ include_once '../php/jqUtils.php'; $myFile = jqGridUtils::GetParam('fname'); $r = ""; if (file_exists($myFile)) { if (is_writable($myFile)) { $r = save_server($myFile); } else { $r = "File is not Writtable"; } } else { $r = save_server($myFile); } echo $r; function getRealPOST() { $pairs = explode("&", file_get_contents("php://input")); $vars = array(); foreach ($pairs as $pair) { $nv = explode("=", $pair); $name = urldecode($nv[0]); $value = urldecode($nv[1]); $vars[$name] = $value; } return $vars; }
public function renderGrid($tblelement = '', $pager = '', $script = true, array $summary = null, array $params = null, $createtbl = false, $createpg = false, $echo = true) { $oper = $this->GridParams["oper"]; $goper = jqGridUtils::GetParam($oper, 'nooper'); if ($goper == $this->GridParams["excel"]) { if (!$this->export) { return false; } $this->exportToExcel($summary, $params, $this->colModel); } else { if (in_array($goper, array_values($this->GridParams))) { $this->editGrid($summary, $params, $goper); } else { if (!isset($this->gridOptions["datatype"])) { $this->gridOptions["datatype"] = $this->dataType; } $this->gridOptions['colModel'] = $this->colModel; if (isset($this->gridOptions['postData'])) { $this->gridOptions['postData'] = jqGridUtils::array_extend($this->gridOptions['postData'], array($oper => $this->GridParams["query"])); } else { $this->setGridOptions(array("postData" => array($oper => $this->GridParams["query"]))); } if (isset($this->primaryKey)) { $this->GridParams["id"] = $this->primaryKey; } $this->setGridOptions(array("prmNames" => $this->GridParams)); $s = ''; if ($createtbl) { $tmptbl = $tblelement; if (strpos($tblelement, "#") === false) { $tblelement = "#" . $tblelement; } else { $tmptbl = substr($tblelement, 1); } $s .= "<table id='" . $tmptbl . "'></table>"; } if ($createpg) { $tmppg = $pager; if (strpos($pager, "#") === false) { $pager = "#" . $pager; } else { $tmppg = substr($pager, 1); } $s .= "<div id='" . $tmppg . "'></div>"; } if (strlen($pager) > 0) { $this->setGridOptions(array("pager" => $pager)); } $this->editOptions['mtype'] = $this->mtype; $this->addOptions['mtype'] = $this->mtype; $this->delOptions['mtype'] = $this->mtype; if ($script) { $s .= "<script type='text/javascript'>"; $s .= "jQuery(document).ready(function() {"; } $s .= "jQuery('" . $tblelement . "').jqGrid(" . jqGridUtils::encode($this->gridOptions) . ");"; if ($this->navigator && strlen($pager) > 0) { $s .= "jQuery('" . $tblelement . "').jqGrid('navGrid','" . $pager . "'," . jqGridUtils::encode($this->navOptions); $s .= "," . jqGridUtils::encode($this->editOptions); $s .= "," . jqGridUtils::encode($this->addOptions); $s .= "," . jqGridUtils::encode($this->delOptions); $s .= "," . jqGridUtils::encode($this->searchOptions); $s .= "," . jqGridUtils::encode($this->viewOptions) . ");"; if ($this->navOptions["excel"] == true) { $eurl = $this->getGridOption('url'); $exexcel = <<<EXCELE onClickButton : function(e) { try { jQuery("{$tblelement}").jqGrid('excelExport',{url:'{$eurl}'}); } catch (e) { window.location= '{$eurl}?oper=excel'; } } EXCELE; $s .= "jQuery('" . $tblelement . "').jqGrid('navButtonAdd','" . $pager . "',{caption:'',title:'Export to Excel'," . $exexcel . "});"; } } if ($this->toolbarfilter) { $s .= "jQuery('" . $tblelement . "').jqGrid('filterToolbar'," . jqGridUtils::encode($this->filterOptions) . ");\n"; } $gM = count($this->gridMethods); if ($gM > 0) { for ($i = 0; $i < $gM; $i++) { $s .= $this->gridMethods[$i] . "\n"; } } if (strlen($this->customCode) > 0) { $s .= jqGridUtils::encode($this->customCode); } if ($script) { $s .= " });</script>"; } if ($echo) { echo $s; } return $echo ? "" : $s; } } }
/** * * Constructor * @param resource $db the database connection passed to the constructor. * In case of array set to 'local' */ function __construct($db = null) { if (class_exists('jqGridDB')) { $interface = jqGridDB::getInterface(); } else { $interface = 'local'; } $this->conn = $db; if ($interface == 'pdo') { $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbtype = $this->conn->getAttribute(PDO::ATTR_DRIVER_NAME); } else { $this->dbtype = $interface; } $this->term = jqGridUtils::GetParam('term', -1); if ($this->term !== -1) { $this->runAll = false; } $this->element = jqGridUtils::GetParam('acelem', ''); }
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ include_once 'connections.php'; include_once '../php/jqUtils.php'; $connstr = jqGridUtils::GetParam('conn'); $dbtype = jqGridUtils::GetParam('dbtype'); $action = jqGridUtils::GetParam('action'); $sqlstr = jqGridUtils::GetParam('sqlstring'); //var_dump($sqlstr); if ($action == 'test') { if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') { echo pdo_test_connection($connstr, $dbtype); } } // var_dump($action); if ($action == 'genform') { if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') { include '../php/jqGridPdo.php'; ini_set("display_errors", 1); $info = parse_connection_string($connstr); try { $conn = new PDO($dbtype . ':host=' . $info->host . ';dbname=' . $info->database, $info->user_id, $info->password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sqlstr = jqGridDB::limit($sqlstr, $dbtype, 1, 0); //var_dump($sqlstr); $stmt = jqGridDB::prepare($conn, $sqlstr, null); $ret = jqGridDB::execute($stmt);
public static function _mongoSearch($mongoquery, $GridParams = array(), $encoding = 'utf-8', $datearray = array(), $mongointegers = array()) { $s = ''; $v = array(); $sopt = array('eq' => '===', 'ne' => '!==', 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '>=', 'bw' => "", 'bn' => "", 'in' => '==', 'ni' => '!=', 'ew' => '', 'en' => '', 'cn' => '', 'nc' => ''); $filters = jqGridUtils::GetParam($GridParams["filter"], ""); $rules = ""; // multiple filter if ($filters) { if (function_exists('json_decode') && strtolower(trim($encoding)) == "utf-8") { $jsona = json_decode($filters, true); } else { $jsona = jqGridUtils::decode($filters); } if (is_array($jsona)) { $gopr = strtolower(trim($jsona['groupOp'])); $rules = $jsona['rules']; } // single filter } else { if (jqGridUtils::GetParam($GridParams['searchField'], '')) { $gopr = 'or'; $rules[0]['field'] = jqGridUtils::GetParam($GridParams['searchField'], ''); $rules[0]['op'] = jqGridUtils::GetParam($GridParams['searchOper'], ''); $rules[0]['data'] = jqGridUtils::GetParam($GridParams['searchString'], ''); } } if ($gopr == 'or') { $gopr = ' || '; } else { $gopr = ' && '; } $i = 0; if (!is_array($mongoquery)) { $mongoquery = array(); } foreach ($rules as $key => $val) { $field = $val['field']; $op = $val['op']; $v = $val['data']; if (strlen($v) != 0 && $op) { $string = true; if (in_array($field, $datearray)) { $av = explode(",", jqGridUtils::parseDate('d/m/Y H:i:s', $v, 'Y,m,d,H,i,s')); $av[1] = (int) $av[1] - 1; $v = "new Date(" . implode(",", $av) . ")"; $string = false; } if (in_array($field, $mongointegers)) { $string = false; } $i++; if ($i > 1) { $s .= $gopr; } switch ($op) { case 'bw': $s .= "this." . $field . ".match(/^{$v}.*\$/i)"; break; case 'bn': $s .= "!this." . $field . ".match(/^{$v}.*\$/i)"; break; case 'ew': $s .= "this." . $field . ".match(/^.*{$v}\$/i)"; break; case 'en': $s .= "!this." . $field . ".match(/^.*{$v}\$/i)"; break; case 'cn': $s .= "this." . $field . ".match(/^.*{$v}.*\$/i)"; break; case 'nc': $s .= "!this." . $field . ".match(/^.*{$v}.*\$/i)"; break; default: if ($string) { $v = "'" . $v . "'"; } $s .= " this." . $field . " " . $sopt[$op] . $v; break; } } } if (isset($mongoquery) && is_array($mongoquery)) { $mongoquery = jqGridUtils::array_extend($mongoquery, array('$where' => "function(){ return " . $s . ";}")); } else { $mongoquery = array('$where' => "function(){ return " . $s . ";}"); } return $mongoquery; }
include_once 'jqformconfig.php'; include_once $CODE_PATH . 'jqUtils.php'; include_once $CODE_PATH . 'jqForm.php'; // Create instance $newForm = new jqForm('newForm', array('method' => 'post', 'id' => 'newForm')); // Demo Mode creating connection include_once $CODE_PATH . 'jqGridPdo.php'; $conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD); $newForm->setConnection($conn); // Set url $newForm->setUrl($SERVER_HOST . $SELF_PATH . 'sqlcheckdata.php'); // Set Form header $formhead = 'Edit Ship Details'; $newForm->setFormHeader($formhead, 'ui-icon-pencil'); // Set parameters $Order = jqGridUtils::GetParam('Order', '10254'); $Order = is_numeric($Order) ? (int) $Order : 0; $jqformparams = array($Order); // Set SQL Command, table, keys $newForm->SelectCommand = 'SELECT OrderID, ShipName, ShipAddress, ShipCity, ShipPostalCode, ShipCountry, Freight FROM orders WHERE OrderID = ?'; $newForm->table = 'orders'; $newForm->setPrimaryKeys('OrderID'); $newForm->serialKey = true; // Set Form layout $newForm->setColumnLayout('twocolumn'); $newForm->setTableStyles('width:580px;', '', ''); // Add elements $newForm->addElement('OrderID', 'hidden', array('label' => 'OrderID', 'id' => 'newForm_OrderID')); $newForm->addElement('ShipName', 'text', array('label' => 'ShipName', 'maxlength' => '40', 'style' => 'width:98%;', 'id' => 'newForm_ShipName')); $newForm->addElement('ShipAddress', 'text', array('label' => 'ShipAddress', 'maxlength' => '60', 'style' => 'width:98%;', 'id' => 'newForm_ShipAddress')); $newForm->addElement('ShipCity', 'text', array('label' => 'ShipCity', 'maxlength' => '15', 'size' => '20', 'id' => 'newForm_ShipCity'));
$grid = new jqGridRender($conn); // Write the SQL Query $grid->SelectCommand = 'SELECT CustomerID, CompanyName, Phone, PostalCode, City FROM customers'; // Set the table to where you update the data $grid->table = 'customers'; // Set output format to json $grid->dataType = 'json'; $grid->setPrimaryKeyId('CustomerID'); // Let the grid create the model $grid->setColModel(); // Set the url from where we obtain the data $grid->setUrl('grid.php'); // Set some grid options $grid->setGridOptions(array("rowNum" => 10, "rowList" => array(10, 20, 30), "sortname" => "CustomerID")); $grid->setColProperty('CustomerID', array("editoptions" => array("readonly" => true))); // For demonstration purposes only we will update the Customer name adding at end of // the field U after the data is updated from the user // We can set ulimited commands after edit occur. // The same apply for del and add operation $cid = jqGridUtils::GetParam('CustomerID'); // This command is executed immediatley after edit occur. $grid->setAfterCrudAction('edit', "UPDATE customers SET CompanyName = CONCAT(CompanyName,' -U') WHERE CustomerID=?", array($cid)); // Enable navigator $grid->navigator = true; // Enable only editing $grid->setNavOptions('navigator', array("excel" => false, "add" => false, "edit" => true, "del" => false, "view" => true, "search" => false)); // Close the dialog after editing $grid->setNavOptions('edit', array("closeAfterEdit" => true, "editCaption" => "Update Customer", "bSubmit" => "Update")); // Enjoy $grid->renderGrid('#grid', '#pager', true, null, null, true, true); $conn = null;