コード例 #1
0
ファイル: import.php プロジェクト: thaian2009/php
$file_name = 'data/' . $_GET['db'] . '-' . date("D-m-y_h-i-s") . ".sql";
if (isset($_POST['url']) && $_POST['url'] !== 'http://') {
    $_sql = file_get_contents($_POST['url']);
    // we assume that the file is sql
    $fp = fopen($file_name, "w");
    fwrite_stream($fp, $_sql);
    fclose($fp);
} elseif (isset($_GET['file'])) {
    $_sql = file_get_contents($_GET['file']);
} else {
    move_uploaded_file($_FILES['file']['tmp_name'], $file_name);
    $_sql = file_get_contents($file_name);
}
if ($_POST['sv'] == '1' || $_GET['sv'] == '1') {
    $fp = fopen($file_name, "w");
    fwrite_stream($fp, $_sql);
}
// sending query
if ($_POST['th'] == '1' || $_GET['th'] == '1') {
    //$_sql = htmlspecialchars($_sql,ENT_QUOTES);
    $result = $db->multi_query($_sql);
    if (!$result) {
        $_err[] = $db->error;
    } else {
        $_sql_nr = 0;
        while ($db->next_result()) {
            $_sql_nr++;
        }
        if ($db->error) {
            $_err[] = $db->error;
        }
コード例 #2
0
	function createStoreCreditFile($email, $historyId) {
		global $core_read, $core_write;
		$sql = "SELECT customer_entity.entity_id AS customer_id, customer_entity.email, history_id, balance_delta,balance_amount, additional_info, enterprise_customerbalance_history.updated_at FROM enterprise_customerbalance, enterprise_customerbalance_history, customer_entity 
					WHERE enterprise_customerbalance.balance_id = enterprise_customerbalance_history.balance_id 
					AND customer_entity.entity_id = enterprise_customerbalance.customer_id
					AND customer_entity.is_active = 1
					AND action IN (2, 1, 4, 5)
					AND customer_entity.email = '$email'
					AND history_id = '$historyId'
					LIMIT 1";

			$credit_updateds = $core_read->fetchAll($sql);
			$doc  = new DOMDocument('1.0', 'utf-8');
			$doc->formatOutput = true;

			$StoreCreditsNode = $doc->createElement( "StoreCredits" );
			$doc->appendChild( $StoreCreditsNode );
			Mage::log("Found " . count($credit_updateds) . " record(s) to update.", null, $logfile);
			$foundData = FALSE;
			$creditDataCount = 0;
			
			foreach($credit_updateds as $credit) {
				Mage::log("Exporting record for customer email " . $credit['email'] . " to xml object", null, $logfile);
				
				$customer_sql = "SELECT * FROM customer_entity_varchar WHERE entity_id = '".$credit['customer_id']."' AND attribute_id IN (4, 5, 6, 7) ";
				$customer_names = $core_read->fetchAll($customer_sql);
				$customerNameArr = array();
				$customerFullName = array();
				$customerNameArr = array('full_name' => '', 'first_name' => '', 'last_name' => '');
				foreach($customer_names as $names) {
					if (trim($names['value']) != "") {
						$customerFullName[] = $names['value'];
					}
					if ($names['attribute_id'] == 5) {
						$customerNameArr['first_name'] = $names['value'];
					} else if ($names['attribute_id'] == 7) {
						$customerNameArr['last_name'] = $names['value'];
					}
				}
				$customerNameArr['full_name'] = implode(" ", $customerFullName);
				
				$creditDataCount ++;
				$StoreCreditNode = $doc->createElement( "StoreCredit" );
				$StoreCreditsNode->appendChild( $StoreCreditNode );

				$additional_info = $credit['additional_info'];
				$order_number = "";
				if (strpos(strtolower($additional_info), "order #") !== FALSE) {
					$additional_info = trim(substr($additional_info, strpos(strtolower($additional_info), "order #") + 7, -1));
					if (strpos($additional_info, ",") !== FALSE) {
						$order_number = substr($additional_info, 0, strpos($additional_info, ","));
					} else if (strpos($additional_info, ".") !== FALSE) {
						$order_number = substr($additional_info, 0, strpos($additional_info, "."));
					} else {
						$order_number = $additional_info;
					}
				}
				
				$dataNode = $doc->createElement( 'RecordId' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($credit['history_id']);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'OrderNumber' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($order_number);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'Email' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($credit['email']);
				$dataNode->appendChild( $value );
				
			/*	$dataNode = $doc->createElement( 'CustomerFullName' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($customerNameArr['full_name']);
				$dataNode->appendChild( $value );
			*/	

				$dataNode = $doc->createElement( 'Amount' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($credit['balance_amount']);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'StoreCreditCreated' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($credit['updated_at']);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'AdditionalData' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($credit['additional_info']);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'CustomerFirstName' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($customerNameArr['first_name']);
				$dataNode->appendChild( $value );

				$dataNode = $doc->createElement( 'CustomerLastName' );
				$StoreCreditNode->appendChild( $dataNode );
				$value = $doc->createCDATASection($customerNameArr['last_name']);
				$dataNode->appendChild( $value );

				$foundData = TRUE;
				$array_record_to_flag[] = array('history_id' => $credit['history_id'], 'email' => $credit['email']);
				Mage::log("Exported record for customer email " . $credit['email'] . " to xml object", null, $logfile);
			}

			$storeCreditFeed = $doc->saveXML();

			if ($foundData) {
				$filepath = "/home/cloudpanel/mnt/lecomotf/outbound/storeCredit/scf-" . date('YmdHis') . ".xml";
				Mage::log("Creating XML to " . $filepath, null, $logfile);
				try {
					$fp = fopen($filepath, 'w');
					$written = fwrite_stream($fp, $storeCreditFeed);
					fclose($fp);

					if ($written < strlen($storeCreditFeed)) {
						Mage::log("Error in writing file " . $filepath, null, $logfile);
						unlink($filepath);
					}
				else
				{
					Mage::log("Success, " . $creditDataCount . " records found. Feed XML: " . $filepath, null, $logfile);
					foreach($array_record_to_flag as $record) {
						Mage::log("Flaging record for customer email: ".$record['email']." and history_id #".$record['history_id'], null, $logfile);
						$sql = "UPDATE enterprise_customerbalance_history SET is_exported=1, exported_on=NOW() WHERE history_id='" . $record['history_id'] . "';";
						$core_write->query($sql);
					}
				}
				} catch (Exception $e) {
					$errmsg = $e->getMessage();
					Mage::log("Failed :: " . $errmsg, null, $logfile);
				}
				return $email;
			} 
			else {
				Mage::log("Success, No record found.", null, $logfile);
			}
			
			$time_elapsed = microtime(true) - $script_start;
			Mage::log("[" . date('Y-m-d H:i:s') . "] script ended. Time taken: " . (round($time_elapsed / 60)) . " minut(s) \n\n\n\n\n", null, $logfile);
	}
コード例 #3
0
<?php

/**
* Rest client services.
* @author KikApp PHP Generator
* @version 1.0 
*/
define('_BLOB_PATH', "http://www.devxtend.com/nicolas/DynamicComboBoxExample/services/");
define('_FOLDER', "PublicStorage/");
$fileName = getName() . "." . getExtension(getHeader("Content-Type"));
fwrite_stream(_FOLDER . $fileName, file_get_contents('php://input'));
echo json_encode(getResponse($fileName));
function getResponse($fileName)
{
    header('Content-Type: application/json; charset=utf-8');
    header('HTTP/ 201 ');
    header('GeneXus-Object-Id:  gxupload:' . _FOLDER . $fileName);
    $data = array('object_id' => _FOLDER . $fileName);
    return $data;
}
function getHeader($header)
{
    foreach (getallheaders() as $name => $value) {
        if ($name == $header) {
            return $value;
        }
    }
}
function fwrite_stream($path, $string)
{
    $fp = fopen($path, 'w');
コード例 #4
0
ファイル: export.php プロジェクト: thaian2009/php
            // Dump table data, default: false
            $dump->doDump(true, ++$i);
            $_final_data .= $dump->filestream . "\n\n";
        }
    }
    if ($_POST['output'] == '0') {
        // write the sql file
        $file_name = 'data/' . $_GET['db'] . '-' . date("D-m-y_h-i-s") . ".sql";
        $fp = fopen($file_name, "w");
        fwrite_stream($fp, $_final_data);
        fclose($fp);
    }
    if ($_POST['output'] == '1') {
        $_SESSION['file_sql'] = 'data/' . $_GET['db'] . '-' . date("D-m-y_h-i-s") . ".sql";
        $fp = fopen($_SESSION['file_sql'], "w");
        fwrite_stream($fp, $_final_data);
        $ziper = new zipfile();
        $ziper->addFiles($_SESSION['file_sql']);
        $ziper->output($_SESSION['file_sql'] . '.zip');
        unlink($_SESSION['file_sql']);
        fclose($fp);
    }
} else {
    if (isset($_GET['db'])) {
        if ($db_name) {
            $lt = $db->query("SHOW TABLE STATUS;");
            while ($lst = $lt->fetch_array()) {
                $list[] = $lst[0];
            }
        }
    } else {