<?php
defined('_JEXEC') or die( 'Restricted access' );
class smcModelCore extends JModel {
function loadList() {
$version = new JVersion();
$db = JFactory :: getDBO();
$row = new stdclass;
$row->type = 'Joomla 1.6';
$row->version = $version->DEV_LEVEL;
$row->path = JPATH_SITE.DS;
$row->php = phpversion();
$row->mysql = $db->getVersion();
return $row;
}
function getDatabaseDump() {
set_time_limit(0);
ini_set('memory_limit', '512M');
$db = JFactory :: getDBO();
$prefix = $db->getPrefix();
$tables = $db->getTableList();
$excludes = explode(',', JRequest :: getString('excludes'));
if ($excludes) foreach ($excludes as $i=>$exclude) $excludes[$i] = $prefix.trim($exclude);
$query = '';
$i = 0;
foreach ($tables as $table) {
$db->setQuery('SHOW CREATE TABLE `'.$table.'`');
if ($obj = $db->loadAssoc()) {
$query .= 'DROP TABLE IF EXISTS `'.$table."`;\n";
$query .= $obj['Create Table'].";\n\n";
$i++;
}
/* do not dump data of excluded tables */
if (in_array($table, $excludes)) continue;
$db->setQuery('SHOW COLUMNS FROM `'.$table.'`');
if ($cols = $db->loadAssocList()) {
foreach ($cols as $i=>$col) $cols[$i]['is_numeric'] = preg_match("/^(\w*int|year)/", $col['Type'])?true:false;
$db->setQuery('SELECT * FROM `'.$table.'`');
if ($dbh = $db->query()) {
while ($row = mysql_fetch_assoc($dbh)) {
$query .= 'INSERT INTO `'.$table.'` VALUES (';
foreach ($cols as $i=>$col) {
if ($i) $query .= ',';
if ($col['is_numeric']) $query .= $row[$col['Field']];
else $query .= $db->quote($row[$col['Field']]);
}
$query .= ");\n";
}
}
}
$query .= "\n";
}
return $query;
}
}
?>