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 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 display($tmpl = null)
 {
     $this->items = JMMCommon::showDatabaseLists();
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->addToolbar();
     parent::display($tmpl);
 }
Beispiel #4
0
 function getTables()
 {
     $rows = JMMCommon::getTablesFromDB();
     $tables = array();
     for ($i = 0; $i < count($rows); $i++) {
         $tables[] = JHTML::_('select.option', $rows[$i], $rows[$i]);
     }
     return $tables;
 }
 function getDatabases()
 {
     $rows = JMMCommon::getDataBaseLists();
     $databases = array();
     for ($i = 0; $i < count($rows); $i++) {
         $databases[] = JHTML::_('select.option', $rows[$i], $rows[$i]);
     }
     return $databases;
 }
 function display($tmpl = null)
 {
     $document = JFactory::getDocument();
     $document->addScript(JURI::root() . 'media' . DS . 'com_jmm' . DS . 'js' . DS . 'jquery-1.7.2.min.js');
     $document->addScript(JURI::root() . 'media' . DS . 'com_jmm' . DS . 'js' . DS . 'export.js');
     $action = JRequest::getString('action', '');
     $limit = JRequest::getInt('limit', 15);
     $limitstart = JRequest::getInt('limitstart', 0);
     $pagination = '&limit=' . $limit . '&limitstart=' . $limitstart;
     $filter_order = JRequest::getString('filter_order', null);
     $filter_order_Dir = JRequest::getString('filter_order_Dir', null);
     if (isset($filter_order) && isset($filter_order_Dir)) {
         $pagination .= '&filter_order=' . $filter_order . '&filter_order_Dir=' . $filter_order_Dir;
     }
     $tbl = JRequest::getString('tbl');
     $filter_browsetable = JRequest::getVar('filter_browsetable', '');
     if (isset($_REQUEST['dbname'])) {
         $dbname = JRequest::getVar('dbname');
         $urlString = '&dbname=' . $dbname;
     } else {
         $urlString = '';
     }
     if ($filter_browsetable != '') {
         JFactory::getApplication()->redirect('index.php?option=com_jmm&view=tables&action=browse&tbl=' . $filter_browsetable . $urlString . $pagination, 'Table Data of ' . $filter_browsetable);
     }
     $filter_tablestructure = JRequest::getVar('filter_tablestructure');
     if ($filter_tablestructure != '') {
         JFactory::getApplication()->redirect('index.php?option=com_jmm&view=tables&action=structure&tbl=' . $filter_tablestructure . $urlString, 'Table Structure of ' . $filter_tablestructure);
     }
     $filter_chnagedatabase = JRequest::getVar('filter_chnagedatabase', '');
     if ($filter_chnagedatabase != '') {
         JFactory::getApplication()->redirect('index.php?option=com_jmm&view=tables&dbname=' . $filter_chnagedatabase, 'Database Switched to  ' . $filter_chnagedatabase);
     }
     switch ($action) {
         case 'structure':
             $this->items = JMMCommon::showTableStructure($tbl);
             JFactory::getApplication()->enqueueMessage('Table Structure of ' . $tbl, 'message');
             break;
         case 'browse':
             $this->items = $this->get('Items');
             JFactory::getApplication()->enqueueMessage('Table Data of ' . $tbl, 'message');
             break;
         default:
             $this->items = JMMCommon::showTableLists();
             JFactory::getApplication()->enqueueMessage('Table Lists', 'message');
             break;
     }
     $this->tables = $this->get('Tables');
     $this->databases = $this->get('Databases');
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->addToolbar();
     parent::display($tmpl);
 }
 public function getInput()
 {
     $table = JRequest::getVar('tbl');
     $dbname = JRequest::getVar('dbname');
     $tableFields = JMMCommon::showTableStructure($table);
     for ($i = 0; $i < count($tableFields); $i++) {
         $field = $tableFields[$i];
         $tmp = explode('(', $field['Type']);
         $name = $field['Field'];
         $type = $tmp[0];
         $length = (int) str_replace(')', '', $tmp[1]);
         $length += 1;
         $id = 'jform_' . $name;
         $label_name = ucwords($name) . ' (' . $type . ')';
         $label_id = 'jform_' . $name . '-lbl';
         $this->drawForm("jform[{$name}]", $type, $id, $label_name, $label_id, $length);
     }
     return $this->formData;
 }
Beispiel #8
0
 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');
     }
 }
Beispiel #9
0
 public function __construct(&$db)
 {
     $tbl = JRequest::getVar('tbl');
     $db = JMMCommon::getDBInstance();
     parent::__construct($tbl, null, $db);
 }
Beispiel #10
0
 function getSiteTables()
 {
     $rows = JMMCommon::listSiteTables();
     $queries = array();
     for ($i = 0; $i < count($rows); $i++) {
         $queries[] = JHTML::_('select.option', $rows[$i]->query, $rows[$i]->title);
     }
     return $queries;
 }
 /**
  * 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;
 }
Beispiel #12
0
 /**
  * [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;
 }