public function export_csv()
 {
     if ($_REQUEST['submit_export']) {
         if ($_REQUEST['export'] == 'Excel') {
             global $wpdb;
             require 'export.inc.php';
             $table = $wpdb->prefix . "EPR_user";
             // this is the tablename that you want to export to csv from mysql.
             exportMysqlToCsv($table);
         }
     }
 }
Exemple #2
0
<?php

include_once "config.php";
include_once "utils.php";
include_once "RunSelector.php";
$host = 'localhost';
// MYSQL database host adress
$db = 'cnipol';
// MYSQL database name
$user = '******';
// Mysql Datbase user
$pass = '******';
// Mysql Datbase password
// Connect to the database
$link = mysql_connect($host, $user, $pass);
//print_r($_GET);
$runSelector = new RunSelector();
mysql_select_db($db);
$table = "run_info";
// this is the tablename that you want to export to csv from mysql.
exportMysqlToCsv($table, $runSelector->sqlWhere);
        $total_rows = $obj_setting->numberOfRows('contact', 'type = 101');
        //number of rows in pages table
    } else {
        $total_rows = $obj_setting->numberOfRows('contact', "type = 101 and `name` like '%" . addslashes($_REQUEST['searchtext']) . "%' OR `email` like '%" . addslashes($_REQUEST['searchtext']) . "%'");
        //number of rows in pages table for perticular search criteria
    }
}
if (!isset($_REQUEST['searchcombo'])) {
    if ($searchword == "" && $type != "") {
        $all_pages = $obj_setting->customQuery("SELECT * FROM contact where type = 101 order by {$field} {$orderby} limit {$eu}, {$limit} ");
    } else {
        if ($searchword != "" && $type != "") {
            $all_pages = $obj_setting->customQuery("SELECT * FROM contact where type = 101 and name like '%" . addslashes($searchword) . "%' or  `email` like '%" . addslashes($searchword) . "%' order by {$field} {$orderby} limit {$eu}, {$limit} ");
        } else {
            $all_pages = $obj_setting->customQuery("SELECT * FROM contact where type = 101 order by {$field} {$orderby} limit {$eu}, {$limit} ");
        }
    }
} else {
    if ($_REQUEST['searchtext'] == 'Search') {
        $all_pages = $obj_setting->customQuery("SELECT * FROM contact where type = 101 and order by {$field} {$orderby} limit {$eu}, {$limit} ");
    } else {
        $all_pages = $obj_setting->customQuery("SELECT * FROM contact where type = 101 and `name` like '%" . addslashes($_REQUEST['searchtext']) . "%' OR `desc` like '%" . addslashes($_REQUEST['searchtext']) . "%' order by {$field} {$orderby} limit {$eu}, {$limit} ");
        //number of rows in pages table for perticular search criteria
    }
}
if (isset($_REQUEST['exportMYSQLData'])) {
    $mysqlFilename = "index_page_inquiry_" . date("dMY") . ".csv";
    $CSVraw = $obj_setting->customQuery("SELECT name,email,phone FROM contact where FIND_IN_SET(type,101) order by {$field} {$orderby} ");
    exportMysqlToCsv($CSVraw, $mysqlFilename);
}
unset($obj_setting);
Exemple #4
0
<?
include("includes/config_db.php");
$table= $_REQUEST['tb_name']; // this is the tablename that you want to export to csv from mysql.
exportMysqlToCsv($table);
function exportMysqlToCsv($table,$filename = 'export.csv')
{
	$csv_terminated = "  ";
	$csv_separator = " , ";
	$csv_enclosed = '  ';
	$csv_escaped = "\n";
	$sql_query = 'SELECT * FROM '.$_REQUEST['tb_name'].' ';
	// Gets the data from the database
	$result = mysql_query($sql_query);
	$fields_cnt = mysql_num_fields($result);
	 $schema_insert = ''; 
	for ($i = 0; $i < $fields_cnt; $i++)
	{
		$l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
			stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
		$schema_insert .= $l;
		$schema_insert .= $csv_separator;
	} // end for
	$out = trim(substr($schema_insert, 0, -1));
	$out .= $csv_terminated;
	// Format the data
	while ($row = mysql_fetch_array($result))
	{
		$schema_insert = '';
		for ($j = 0; $j < $fields_cnt; $j++)
		{
			if ($row[$j] == '0' || $row[$j] != '')
<?php

session_start();
exportMysqlToCsv('Export_Projects_without_licences.csv');
// export csv
function exportMysqlToCsv($filename = 'export_csv_Expier.csv')
{
    include "configFile.php";
    // call export function
    if (isset($_GET['lName'])) {
        $lNameG = $_GET['lName'];
    }
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Create connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT projects_219.pName,\n\t\t\t\t\t\tprojects_219.pID,\n\t\t\t\t\t\tprojects_219.StartDate,\n\t\t\t\t\t\tprojects_219.EndDate,\n\t\t\t\t\t\tprojects_219.Client,\n\t\t\t\t\t\tprojects_219.Country,\n\t\t\t\t\t\tprojects_219.Comments,\n\t\t\t\t\t\tprojects_219.Status,\n\t\t\t\t\t\tlicenses_proj_219.lcID, \n\t\t\t\t\t\tlicenses_proj_219.lcAmount, \n\t\t\t\t\t\tlicenses_proj_219.pID, \n\t\t\t\t\t\tlicenses_proj_219.pAmount \n\t\t\t\t\t\tFROM projects_219\n\t\t\t\t\t\tjoin licenses_proj_219 ON projects_219.pID = licenses_proj_219.pID \n\t\t\t\t\t\tWHERE licenses_proj_219.lcID = 0 AND licenses_proj_219.pAmount = 0 ";
    // Gets the data from the database
    $result = $conn->query($sql);
    $f = fopen('php://temp', 'wt');
    $first = true;
    while ($row = $result->fetch_assoc()) {
        if ($first) {
            fputcsv($f, array_keys($row));
            $first = false;
        }
        fputcsv($f, $row);
    }
    // end while
    $conn->close();
        $finalstart = $_POST["start_date"] . ' 00:00:00';
        $finalend = $_POST["end_date"] . ' 00:00:00';
        $nquery .= " AND (t1.add_date BETWEEN '{$finalstart}' AND '{$finalend}') ";
    }
    if ($_SESSION['adminType'] == 'sub-admin') {
        $nquery .= " and t1.subadmin= " . $_SESSION['aid'];
    }
    $queryrws = "SELECT t1.firstname, t1.middlename, t1.lastname, t1.email, t1.mobile, t1.city, t1.state, t1.source, t1.sourcebank, t1.type, t4.full_name as owner, t1.contact_method, DATE_FORMAT(t1.add_date, '%d %M %Y %I:%i:%S') as \n   Register_Date, IFNULL(t2.total_account,0) as total_account FROM tbl_userdetails AS t1 LEFT JOIN (SELECT userid, COUNT(*) AS total_account FROM tbl_accounts GROUP BY userid ) AS t2 ON t1.id = t2.userid left join tbl_admin as t4 on t1.owner=t4.id WHERE t1.id > 0 " . $nquery . ' ORDER BY t1.add_date';
    $result_add = mysql_query_with_throw($queryrws);
    while ($row = mysql_fetch_assoc($result_add)) {
        $firstname = addslashes($row["firstname"]);
        $middlename = addslashes($row["middlename"]);
        $lastname = addslashes($row["lastname"]);
        $email = $row["email"];
        $mobile = $row["mobile"];
        $city = $row["city"];
        $state = $row["state"];
        $Register_Date = $row["Register_Date"];
        $total_account = $row["total_account"];
        $source = addslashes($array_source[$row["source"]]);
        $type = addslashes($array_custype[$row["type"]]);
        $owner = $row["owner"];
        $contact_method = addslashes($array_conmethod[$row["contact_method"]]);
        $sourcebank = togetfieldvalue($row["sourcebank"], 'tbl_banks', 'bank');
        $insert_query = mysql_query_with_throw("INSERT INTO `tbl_userexport_main` (`Firstname`, `Middlename`, `Lastname`, `Email`, `Mobile`, `City`, `State`, `Register_Date`, `Source`, `Source_Bank`, `Type`, `Owner`, `Contact_Method` , `total_account`) VALUES ('{$firstname}', '{$middlename}', '{$lastname}', '{$email}', '{$mobile}', '{$city}', '{$state}', '{$Register_Date}', '{$source}', '{$sourcebank}', '{$type}', '{$owner}', '{$contact_method}', '{$total_account}')");
    }
    $export_query = "SELECT * FROM `tbl_userexport_main`";
    $rand2 = mt_rand(1000, 9999);
    $filenamenew = 'CMD-User-List-' . $rand2 . "-" . date('d-m-Y') . ".csv";
    exportMysqlToCsv($export_query, $filenamenew);
}
<?php

session_start();
exportMysqlToCsv('Export_License.csv');
// export csv
function exportMysqlToCsv($filename = 'export_csv.csv')
{
    include "configFile.php";
    // call export function
    if (isset($_GET['lName'])) {
        $lNameG = $_GET['lName'];
    }
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Create connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT licenses_contract_219.lName, \n\t\t\t\tlicenses_contract_219.lcID,\n\t\t\t\tlicenses_contract_219.cID,\t\t\t\t\n\t\t\t\tlicenses_contract_219.Amount, \n\t\t\t\tlicenses_contract_219.startDate, \n\t\t\t\tlicenses_contract_219.endDate, \n\t\t\t\tlicenses_contract_219.File, \n\t\t\t\tlicenses_contract_219.Comments \n\t\t\t\tFROM licenses_contract_219 \n\t\t\t\tWHERE lName = '{$lNameG}'";
    // Gets the data from the database
    $result = $conn->query($sql);
    $f = fopen('php://temp', 'wt');
    $first = true;
    while ($row = $result->fetch_assoc()) {
        if ($first) {
            fputcsv($f, array_keys($row));
            $first = false;
        }
        fputcsv($f, $row);
    }
    // end while
    $conn->close();
        $email = $row["email"];
        $mobile = $row["mobile"];
        $city = $row["city"];
        $state = $row["state"];
        $pincode = $row["pincode"];
        $insertquery = mysql_query_with_throw("INSERT INTO `tbl_accounts_export` (`id`, `account_name`, `balance`, `bank`, `bankid`, `account_type`, `account_number`, `date_opened`, `date_closed`, `dateofbirth`, `pancard`, `principal`, `interest`, `other_charges`, `last_payment_date`, `last_payment_done`, `otherbank`, `dues_id`, `caption`, `notes`, `alert`, `status`, `userid`, `cibil_status`, `payin`, `add_date`, `firstname`, `middlename`, `lastname`, `email`, `mobile`, `city`, `state`, `pincode`) VALUES ({$id}, '{$account}', '{$balance}', '{$bank}', '{$bankid}', '{$product_type}', '{$account_no}', '{$date_opened}', '{$date_closed}', '{$dateofbirth}', '{$pancard}', '{$principal}', '{$interest}', '{$other_charges}', '{$last_payment_date}', '{$last_payment_done}', '{$otherbank}', '{$unikdueid}', '{$caption}', '{$notes}', '{$alert}', '{$status}', '{$userid}', '{$cibil_status}', '{$payin}', '{$add_date}', '{$firstname}', '{$middlename}', '{$lastname}', '{$email}', '{$mobile}', '{$city}', '{$state}', '{$pincode}')");
    }
    if ($rwsapproval == 0) {
        $queryrws = 'SELECT id, account_name, bank, account_type, account_number, dateofbirth, pancard, otherbank, dues_id, caption, notes, status, payin, add_date FROM tbl_accounts_export WHERE bankid = ' . $_SESSION['bid'] . ' ORDER BY add_date DESC';
    } else {
        $queryrws = 'SELECT id, account_name, bank, account_type, account_number, dateofbirth, pancard, date_opened, date_closed, principal, interest, other_charges, balance, last_payment_date, last_payment_done, cibil_status, otherbank, dues_id, caption, notes, status, payin, add_date FROM tbl_accounts_export  WHERE bankid = ' . $_SESSION['bid'] . ' ORDER BY add_date DESC';
    }
    $rand2 = mt_rand(1000, 9999);
    $filenamenew = str_replace(' ', '-', togetfieldvalue($_SESSION['bid'], 'tbl_banks', 'bank')) . '-User-Account-Data-' . $rand2 . "-" . date('d-m-Y') . ".csv";
    echo mysql_num_rows(mysql_query_with_throw($queryrws));
    exportMysqlToCsv($queryrws, $filenamenew);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ADMIN CONSOLE // <?php 
echo $sitename;
?>
 Website</title>
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="resources/css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />
<link href="<?php 
echo $baseurl;
<?php

session_start();
exportMysqlToCsv('Export_Project.csv');
// export csv
function exportMysqlToCsv($filename = 'Project_csv.csv')
{
    include "configFile.php";
    // call export function
    if (isset($_GET['pName'])) {
        $pNameP = $_GET['pName'];
    }
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Create connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT projects_219.pName,\n\t\t\t\tprojects_219.pID,\n\t\t\t\tlicenses_proj_219.lcID, \n\t\t\t\tlicenses_proj_219.lcAmount, \n\t\t\t\tlicenses_proj_219.pID, \n\t\t\t\tlicenses_proj_219.pAmount, \n\t\t\t\tlicenses_contract_219.lcID, \n\t\t\t\tlicenses_contract_219.lName, \n\t\t\t\tlicenses_contract_219.cID, \n\t\t\t\tlicenses_contract_219.Amount, \n\t\t\t\tlicenses_contract_219.startDate, \n\t\t\t\tlicenses_contract_219.endDate, \n\t\t\t\tlicenses_contract_219.File, \n\t\t\t\tlicenses_contract_219.Comments \n\t\t\t\tFROM projects_219\n\t\t\t\tjoin licenses_proj_219 ON projects_219.pID = licenses_proj_219.pID \n\t\t\t\tjoin licenses_contract_219 ON licenses_proj_219.lcID = licenses_contract_219.lcID \n\t\t\t\tWHERE pName = '{$pNameP}'";
    // Gets the data from the database
    $result = $conn->query($sql);
    $f = fopen('php://temp', 'wt');
    $first = true;
    while ($row = $result->fetch_assoc()) {
        if ($first) {
            fputcsv($f, array_keys($row));
            $first = false;
        }
        fputcsv($f, $row);
    }
    // end while
    $conn->close();
Exemple #10
0
        //**Pendiente busqueda inventarios
        $xmov = CleanText($_GET["xmov"]);
        $invent = CleanText($_GET["xtitulo"]);
        $almacen = CleanText($_GET["alma"]);
        $xLocal = getNombreComercialLocal($idlocal);
        $almacen = $almacen ? $almacen : $xLocal;
        $xinvent = $xinvent ? $xinvent : 'none';
        $selcvs = "       DATE_FORMAT(FechaMovimiento, '%e/%m/%y %H:%i') as FechaMovimiento, " . "       ges_usuarios.Identificacion as Usuario, " . "       ges_locales.NombreComercial as Almacen, " . "       CONCAT(ges_productos.CodigoBarras,' ',ges_productos_idioma.Descripcion,' '," . "       ges_marcas.Marca,' ', " . "       ges_modelos.Color,' ', " . "       ges_detalles.Talla,' ', " . "       ges_laboratorios.NombreComercial) as Producto, " . "       ges_contenedores.Contenedor, " . "       ges_productos.UnidadMedida, " . "       ges_productos.UnidadesPorContenedor as UnidxCont, " . "       KardexOperacion, " . "       ges_kardex.TipoMovimiento, " . "       (SELECT ges_kardexajusteoperacion.AjusteOperacion from ges_kardexajusteoperacion where ges_kardexajusteoperacion.IdKardexAjusteOperacion = ges_kardex.IdKardexAjusteOperacion AND ges_kardex.IdKardexAjusteOperacion > 0) as 'AjusteOperacion', " . "       CantidadMovimiento, " . "       ROUND(CostoUnitarioMovimiento,2) as CostoUnitarioMovimiento, " . "       ROUND(CostoTotalMovimiento,2) as CostoTotalMovimiento, " . "       SaldoCantidad, " . "       IF ( ges_kardex.Observaciones like '', ' ',ges_kardex.Observaciones) " . "       as Observaciones ";
        $sql = obtenerKardexMovimientosInventario($idlocal, $desde, $hasta, $xfamilia, $xmarca, $xope, $xmov, $xnombre, $xcodigo, $xinvent, $esInvent, false, $selcvs, false, false, false);
        $xinvent = str_replace("- ", "", $invent);
        $xinvent = str_replace(" ", "_", $xinvent);
        $xalmacen = str_replace(" ", "_", $almacen);
        $name = "gPOS_" . $xalmacen . "_" . $xinvent;
        $NombreArchivo = $name . ".csv";
        $xtitulo = '"' . $almacen . ' ' . $invent . '"';
        exportMysqlToCsv($sql, $NombreArchivo, $xtitulo);
        break;
}
function ProcesarSQL($cod, $Desde, $Hasta, $IdLocal, $IdFamilia, $IdSubsidia, $STSubsid, $IdProveedor, $IdUsuario, $Referencia, $CodigoBarra, $NumeroSerie, $Lote, $Partida, $TipoVenta, $esTPVOP, $LocalActual, $DNICliente, $TipoComprobante, $SerieComprobante, $EstadoComprobante, $EstadoPago, $Modalidad, $EstadoPromo, $TipoPromo, $TipoOperacion, $TipoOpCjaGral, $PeriodoVenta, $NombreCliente, $TipoCliente, $IdMarca, $CondicionVenta, $EstadoOS, $Prioridad, $Facturacion, $EstadoSuscripcion, $TipoSuscripcion, $TipoPagoSuscripcion, $Prolongacion, $IdCLiente, $Codigo, $EstadoPagoVenta, $Cobranza, $CodigoComprobante)
{
    $Moneda = getSesionDato("Moneda");
    if (function_exists("getSesionDato")) {
        $IdLang = getSesionDato("IdLenguajeDefecto");
    }
    if (!$IdLang) {
        $IdLang = 1;
    }
    if ($PeriodoVenta == 'DAY') {
        $g_periodo = "{$PeriodoVenta}(FechaComprobante)";
    }
    if ($PeriodoVenta == 'WEEK') {
include "includes/application_top.php";
?>
<html>
<head>
<title>Import products</title>	
<link rel="stylesheet" href="nusoap/soap.css">
<script type="text/javascript" src="nusoap/soap.js"></script>
</head>

<body>
	<?php 
include DIR_WS_INCLUDES . 'header.php';
?>

<?php 
ini_set("display_errors", 1);
ini_set("memory_limit", "64M");
include "nusoap/lib/nusoap.php";
include "nusoap/functions.php";
$table = "visualproducts_selected";
exportMysqlToCsv($table, "csvdir/products.csv");
header("Location: ez_populate2.php?csvfile=products.csv");
?>

<div style="font-size: 12px;margin-top: 3px;">
<br>
<span style="background-color: #6296FC;color:#ffffff;margin-left: 5px;padding: 5px;font-size : 13px;"> Import was completed succesfully </span>
</div>
</body>
</html>
Exemple #12
0
if (true === isset($_GET['export']) && false === empty($_GET['export'])) {
    $host = Config::$dbHost;
    $user = Config::$dbUser;
    $pass = Config::$dbPass;
    $db = Config::$dbDatabase;
    $table = Config::$dbTable;
    $from_date = $_GET['from_date'];
    $sql_query = "select * from {$table} where add_ts >= '{$from_date}'";
    Logger::debug("Connecting to DB {$db} table {$table} user {$user} host {$host}");
    Logger::debug("SQL query: {$sql_query}");
    $link = mysql_connect($host, $user, $pass);
    mysql_select_db($db);
    $db = SingletonFactory::getInstance()->getSingleton(DB_MANAGER_CLASS_NAME);
    $dateString = date("Y-m-d-Hi");
    $filename = "pa_ipn_export_{$dateString}_from_{$from_date}.csv";
    $csvData = exportMysqlToCsv($table, $sql_query);
    if (true === empty($csvData)) {
        echo "An error occurred, your data is either empty or there's something wrong with the system. Please try again or e-mail dafydd@cantab.net";
    } else {
        //Logger::debug("CSV data: " . print_r($csvData, true));
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Length: " . strlen($csvData));
        header("Content-type: text/csv");
        //header("Content-type: application/csv");
        header("Content-Disposition: attachment; filename={$filename}");
        echo $csvData;
    }
} else {
    ?>

<html>