function createTableStructure() { $result = array(); $mainframe = JFactory::getApplication(); $this->posts = $_POST; $totalfields = count($_POST['field_name']); $query = 'CREATE TABLE IF NOT EXISTS `' . $this->getTableName() . '` ('; $query .= "\n"; for ($i = 0; $i < $totalfields; $i++) { $query .= '`' . $this->getFieldName($i) . '`' . $this->getFieldType($i) . $this->getFieldLength($i) . $this->getNull($i) . $this->getAutoIncrements($i) . $this->getFieldComments($i) . ','; //$query.="\n"; } $query = rtrim($query, ','); $query .= $this->getTableKeys(); $query .= ')' . ' ENGINE=' . $this->getTableType() . ' DEFAULT CHARSET=latin1' . $this->getTableComment() . $this->getAutoIncrementCounter(); $db = JMMCommon::getDBInstance(); $db->setQuery($query); if ($db->query()) { $result['status'] = true; $result['msg'] = 'Table ' . $this->getTableName() . ' Created sucessfully'; } else { $result['status'] = false; $result['msg'] = $db->getErrorMsg(); } echo json_encode($result); $mainframe->close(); }
public function getListQuery() { $tbl = JRequest::getString('tbl', '#__users'); $query = parent::getListQuery(); $query->select('*'); $query->from($tbl); $search = $this->getState('filter.search'); //$db = $this -> getDbo(); $this->_db = JMMCommon::getDBInstance(); /* if (!empty($search)) { $search = '%' . $db -> getEscaped($search, true) . '%'; $fileds = JMMCommon::getCloumnsFromTable($tbl); $searchflString = implode(" LIKE '$search' OR ", $fileds); $field_searches = "($searchflString)"; $query -> where($field_searches); } */ $filter_order = JRequest::getString('filter_order', null); $filter_order_Dir = JRequest::getString('filter_order_Dir', null); if (!empty($filter_order) && !empty($filter_order_Dir)) { $query->order($filter_order . ' ' . $filter_order_Dir); } return $query; }
public function getItems() { $arr = array(); $arr['Result'] = "FALSE"; $arr['TotalRecordCount'] = 0; $arr['Records'] = array(); $siteTableId = JRequest::getInt('site_table_id', 0); $model = $this->getModel('Table'); $siteTableDetails = $model->getSiteTableDetails($siteTableId); $jtStartIndex = JRequest::getInt('jtStartIndex', 0); $jtPageSize = JRequest::getInt('jtPageSize', 25); $jtSorting = JRequest::getString('jtSorting', null); if (isset($siteTableDetails)) { $dbname = $siteTableDetails->dbname; $db = JMMCommon::getDBInstance(null, null, null, null, $dbname, null); $query = $siteTableDetails->query; $db->setQuery($query); $db->query(); $total = $db->getNumRows(); if (!empty($jtSorting)) { $query .= " ORDER BY {$jtSorting}"; } $query .= " LIMIT {$jtStartIndex},{$jtPageSize}"; $db->setQuery($query); $items = $db->loadAssocList(); $arr['Result'] = "OK"; $arr['TotalRecordCount'] = $total; $arr['Records'] = $items; } echo json_encode($arr); JFactory::getApplication()->close(); }
function getItems() { $db = JMMCommon::getDBInstance(); $query = JRequest::getVar('query', ''); if (isset($query) && $query != '') { $db->setQuery($query); if (!$db->query()) { JFactory::getApplication()->enqueueMessage($db->getErrorMsg(), 'error'); return false; } else { $rows = $db->loadAssocList(); $total = count($rows); JFactory::getApplication()->enqueueMessage('SQL Statement "' . $query . '" Executed Sucessfully,' . $total . ' rows found'); return $rows; } } else { return false; } }
function save() { $jform = JRequest::getVar('jform', null, null, 'validation type', JREQUEST_ALLOWRAW); $dbname = JRequest::getVar('dbname', JFactory::getApplication()->getCfg('db')); $tbl = JRequest::getVar('tbl'); $db = JMMCommon::getDBInstance(); $query = 'INSERT INTO `' . $tbl . '`'; $fields = ''; $values = ''; foreach ($jform as $key => $value) { $fields .= '`' . $key . '`,'; $values .= $db->quote($value) . ','; } $fields = rtrim($fields, ','); $values = rtrim($values, ','); $query .= '(' . $fields . ') VALUES(' . $values . ')'; $db->setQuery($query); $redirectUrl = 'index.php?option=com_jmm&view=insert&tbl=' . $tbl . '&dbname=' . $dbname; if ($db->query()) { JFactory::getApplication()->redirect($redirectUrl, "Record Inserted Sucessfully"); } else { JFactory::getApplication()->redirect($redirectUrl, $db->getErrorMsg(), 'error'); } }
public function __construct(&$db) { $tbl = JRequest::getVar('tbl'); $db = JMMCommon::getDBInstance(); parent::__construct($tbl, null, $db); }
/** * Display Data From Table */ function showDataFromTable($table, $db = null) { if (!isset($db)) { $db = JMMCommon::getDBInstance(); } $query = "SELECT * FROM {$table}"; $db->setQuery($query); $rows = $db->loadAssocList(); for ($i = 0; $i < count($rows); $i++) { $row =& $rows[$i]; foreach ($row as $key => &$val) { //$row['Browse']='<a href="index.php?option=com_jmm&view=tables&action=structure&&tbl='.$val.'">Edit</a>'; //$row['Structure']='<a href="index.php?option=com_jmm&view=tables&action=browse&tbl='.$val.'">Delete</a>'; } } return $rows; }
/** * [getItems description] * @return [type] [description] */ function getItems() { $params = JFactory::getApplication()->getParams(); $siteTableId = (int) $params->get('site_table_id'); if (!isset($siteTableId)) { $siteTableId = JRequest::getInt('site_table_id'); } $table_pagination = (int) $params->get('table_pagination'); if (!isset($table_pagination)) { $table_pagination = JRequest::getInt('table_pagination', 0); } $no_record_per_page = (int) $params->get('no_record_per_page'); if (!isset($no_record_per_page)) { $no_record_per_page = JRequest::getInt('no_record_per_page', 10); } $this->setState('limit', $no_record_per_page); $siteTableDetails = $this->getSiteTableDetails($siteTableId); $dbname = $siteTableDetails->dbname; $query = $siteTableDetails->query; $db = JMMCommon::getDBInstance(null, null, null, null, $dbname, null); if ($table_pagination) { $query .= ' LIMIT ' . $this->getState('limitstart') . ',' . $this->getState('limit'); } $db->setQuery($query); $items = $db->loadAssocList(); return $items; }