Ejemplo n.º 1
0
function parseData($lines)
{
    array_shift($lines);
    $products = [];
    foreach ($lines as $line) {
        $columns = explode(';', $line);
        $product = mapProduct($columns, getMapping());
        $products[] = $product;
    }
    return $products;
}
Ejemplo n.º 2
0
function downloadZip($format = null){

	$app = \Slim\Slim::getInstance();
	$extension = array(
		'xml' => 'xml',
		'rdfxml' => 'xml',
		'jsonld' => 'json',
		'turtle' => 'ttl',
		'ntriples' => 'nt'
	);
	if(!array_key_exists($format, $extension)){
		$app->flash('error', '指定された出力形式が不正です。');
		throw new RuntimeException('指定された出力形式が不正です。');
	}
	$zip = new ZipArchive();
	$zipFileName = 'data.zip';
	$zipFilePath = $app->config( 'uploadPath' ) ;

	$check = $zip->open($zipFilePath.$zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
	if ($check !== true) {
		$app->flash('error', 'zipファイルの作成に失敗しました');
		throw new RuntimeException('zipファイルの作成に失敗しました');
	}

	if($format == 'xml'){
		$zip->addFromString('schema.xsd' , getSchema());
		$xml = new XMLConverter();
		$output = $xml->getXML();
	}else{
		$rdf = new RDFConverter();
		$rdf->parseGraph($format);
		$output = $rdf->output();
	}
	$zip->addFromString('convertedData.'  . $extension[$format] , $output);
	$zip->addFromString('header.xml' , dmdHeaderXML());
	$zip->addFromString('header.ttl' , dmdHeaderRDF());
	$zip->addFromString('mapping.json' , getMapping());

	$zip->close();

	$app->response->headers->set( 'Content-Type', 'application/zip; name="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Disposition', 'attachment; filename="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Length', filesize($zipFilePath.$zipFileName) );
	$app->response->write( file_get_contents($zipFilePath.$zipFileName));

	unlink($zipFilePath.$zipFileName);
}
Ejemplo n.º 3
0
function loadConfig()
{
    $file = fopen(find('config.file'), "r");
    //Attempt to open config file
    //If file opened correctly
    if ($file) {
        $commentFlag = false;
        //Flag for signalling reading of comments
        //Read each line of file
        while (($line = fgets($file)) !== false) {
            //Ignore Newlines
            if ($line !== "\r\n") {
                //If this line is not commented
                if (!beginningOfComment($line) && $commentFlag == false) {
                    $GLOBALS['config'][getMapping('key', $line)] = getMapping('value', $line);
                    //Add config setting to global array
                } else {
                    //If this line ends the comment
                    if (endOfComment($line)) {
                        $commentFlag = false;
                        //Reset comment flag
                    } else {
                        $commentFlag = true;
                        //So continue flag
                    }
                }
            }
        }
        fclose($file);
        //Close file opened for reading
    } else {
        echo $GLOBALS['error'][0];
        //So echo appropriate error message
    }
    //Assign base directory value
    $GLOBALS['config']['directory'] = $_SERVER['DOCUMENT_ROOT'] . '/' . $GLOBALS['config']['source'] . '/' . $GLOBALS['config']['subfolders'];
}
Ejemplo n.º 4
0
/** ask db to provide a universally unique id */

function getUUID( $concepts ) {
    $dbr = & wfGetDB( DB_SLAVE );
    
    $uuid_array = array();
 	$uuid = - 1;
    
    foreach ( $concepts as $dc => $dm_id ) {
		$collid = getCollectionIdForDC( $dc );
		$uuid_array[$dc] = getMapping( $dc, $collid, $dm_id );
		if ( ( $uuid == - 1 ) && ( $uuid_array[$dc] != - 1 ) ) {
			$uuid = $uuid_array[$dc];
		}
	}
	
	if ( $uuid == - 1 ) {
		$query = "SELECT uuid() AS id";
		$queryResult = $dbr->query( $query );
		$row = $dbr->fetchObject( $queryResult );
		$uuid = isset( $row->id ) ? $row->id : - 1;
	}
	
    foreach ( $concepts as $dc => $dm_id ) {
    	if ( $uuid_array[$dc] == - 1 ) {
    		$uuid_array[$dc] = $uuid;
    	}
    	else {
    		$uuid_array[$dc] = - 1;
    	}
    }
	
	return $uuid_array;
}
function import($store, $csv_file, $delete_old_items, $categories)
{
    $folder = getContactsFolder($store);
    // open the csv file and start reading
    $fh = fopen($csv_file, "r");
    if (!$fh) {
        trigger_error("Can't read CSV file \"" . $csv_file . "\".", E_USER_ERROR);
    }
    // Delete all existing items if requested.
    if ($delete_old_items) {
        mapi_folder_emptyfolder($folder, DEL_ASSOCIATED);
        printf("Old items deleted.\n");
    }
    $properties = getProperties();
    $properties = replaceStringPropertyTags($store, $properties);
    //composed properties which require more work
    $special_properties = getSpecialPropertyNames();
    $csv_mapping = getMapping();
    $i = 1;
    while (!feof($fh)) {
        $line = fgetcsv($fh, CSV_MAX_LENGTH, CSV_DELIMITER, CSV_ENCLOSURE);
        // print_r($line);
        if (!$line) {
            continue;
        }
        if ($i == 1 && defined('FIELD_NAMES') && FIELD_NAMES) {
            $i++;
            continue;
        }
        $propValues = array();
        //set "simple" properties
        foreach ($csv_mapping as $property => $cnt) {
            if (!in_array($property, $special_properties)) {
                setProperty($property, $line[$csv_mapping[$property]], $propValues, $properties);
            }
        }
        // set display name
        if (isset($csv_mapping["display_name"]) && isset($line[$csv_mapping["display_name"]])) {
            $name = to_windows1252($line[$csv_mapping["display_name"]]);
            $propValues[$properties["display_name"]] = $propValues[$properties["subject"]] = $propValues[$properties["fileas"]] = $name;
            $propValues[$properties["fileas_selection"]] = -1;
        } else {
            $propValues[$properties["display_name"]] = $propValues[$properties["subject"]] = $propValues[$properties["fileas"]] = "";
            if (isset($propValues[$properties["given_name"]])) {
                $propValues[$properties["display_name"]] .= $propValues[$properties["given_name"]];
                $propValues[$properties["subject"]] .= $propValues[$properties["given_name"]];
            }
            if (isset($propValues[$properties["surname"]])) {
                if (strlen($propValues[$properties["display_name"]]) > 0) {
                    $propValues[$properties["display_name"]] .= " " . $propValues[$properties["surname"]];
                    $propValues[$properties["subject"]] .= " " . $propValues[$properties["surname"]];
                } else {
                    $propValues[$properties["display_name"]] .= $propValues[$properties["surname"]];
                    $propValues[$properties["subject"]] .= $propValues[$properties["surname"]];
                }
            }
            if (isset($propValues[$properties["surname"]])) {
                $propValues[$properties["fileas"]] .= $propValues[$properties["surname"]];
            }
            if (isset($propValues[$properties["given_name"]])) {
                if (strlen($propValues[$properties["fileas"]]) > 0) {
                    $propValues[$properties["fileas"]] .= ", " . $propValues[$properties["given_name"]];
                } else {
                    $propValues[$properties["fileas"]] .= $propValues[$properties["given_name"]];
                }
            }
        }
        $nremails = array();
        $abprovidertype = 0;
        if (isset($csv_mapping["email_address_1"]) && isset($line[$csv_mapping["email_address_1"]])) {
            setEmailAddress($line[$csv_mapping["email_address_1"]], $propValues[$properties["display_name"]], 1, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (isset($csv_mapping["email_address_2"]) && isset($line[$csv_mapping["email_address_2"]])) {
            setEmailAddress($line[$csv_mapping["email_address_2"]], $propValues[$properties["display_name"]], 2, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (isset($csv_mapping["email_address_3"]) && isset($line[$csv_mapping["email_address_3"]])) {
            setEmailAddress($line[$csv_mapping["email_address_3"]], $propValues[$properties["display_name"]], 3, $propValues, $properties, $nremails, $abprovidertype);
        }
        if (!empty($nremails)) {
            $propValues[$properties["address_book_mv"]] = $nremails;
        }
        $propValues[$properties["address_book_long"]] = $abprovidertype;
        //set addresses
        if (isset($csv_mapping["home_address_street2"])) {
            mergeStreet("home", $line[$csv_mapping["home_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["home_address_street3"])) {
            mergeStreet("home", $line[$csv_mapping["home_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["home_address"]]) && isset($propValues[$properties["home_address_street"]]) && isset($propValues[$properties["home_address_postal_code"]]) && isset($propValues[$properties["home_address_city"]]) && isset($propValues[$properties["home_address_state"]]) && isset($propValues[$properties["home_address_country"]])) {
            buildAddressString("home", $propValues[$properties["home_address_street"]], $propValues[$properties["home_address_postal_code"]], $propValues[$properties["home_address_city"]], $propValues[$properties["home_address_state"]], $propValues[$properties["home_address_country"]], $propValues, $properties);
        }
        if (isset($csv_mapping["business_address_street2"])) {
            mergeStreet("business", $line[$csv_mapping["business_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["business_address_street3"])) {
            mergeStreet("business", $line[$csv_mapping["business_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["business_address"]]) && isset($propValues[$properties["business_address_street"]]) && isset($propValues[$properties["business_address_postal_code"]]) && isset($propValues[$properties["business_address_city"]]) && isset($propValues[$properties["business_address_state"]]) && isset($propValues[$properties["business_address_country"]])) {
            buildAddressString("business", $propValues[$properties["business_address_street"]], $propValues[$properties["business_address_postal_code"]], $propValues[$properties["business_address_city"]], $propValues[$properties["business_address_state"]], $propValues[$properties["business_address_country"]], $propValues, $properties);
        }
        if (isset($csv_mapping["other_address_street2"])) {
            mergeStreet("other", $line[$csv_mapping["other_address_street2"]], $propValues, $properties);
        }
        if (isset($csv_mapping["other_address_street3"])) {
            mergeStreet("other", $line[$csv_mapping["other_address_street3"]], $propValues, $properties);
        }
        if (!isset($propValues[$properties["other_address"]]) && isset($propValues[$properties["other_address_street"]]) && isset($propValues[$properties["other_address_postal_code"]]) && isset($propValues[$properties["other_address_city"]]) && isset($propValues[$properties["other_address_state"]]) && isset($propValues[$properties["other_address_country"]])) {
            buildAddressString("other", $propValues[$properties["other_address_street"]], $propValues[$properties["other_address_postal_code"]], $propValues[$properties["other_address_city"]], $propValues[$properties["other_address_state"]], $propValues[$properties["other_address_country"]], $propValues, $properties);
        }
        if (isset($propValues[$properties["home_address"]])) {
            $propValues[$properties["mailing_address"]] = 1;
            setMailingAdress($propValues[$properties["home_address_street"]], $propValues[$properties["home_address_postal_code"]], $propValues[$properties["home_address_city"]], $propValues[$properties["home_address_state"]], $propValues[$properties["home_address_country"]], $propValues[$properties["home_address"]], $propValues, $properties);
        } elseif (isset($propValues[$properties["business_address"]])) {
            $propValues[$properties["mailing_address"]] = 2;
            setMailingAdress($propValues[$properties["business_address_street"]], $propValues[$properties["business_address_postal_code"]], $propValues[$properties["business_address_city"]], $propValues[$properties["business_address_state"]], $propValues[$properties["business_address_country"]], $propValues[$properties["business_address"]], $propValues, $properties);
        } elseif (isset($propValues[$properties["other_address"]])) {
            $propValues[$properties["mailing_address"]] = 3;
            setMailingAdress($propValues[$properties["other_address_street"]], $propValues[$properties["other_address_postal_code"]], $propValues[$properties["other_address_city"]], $propValues[$properties["other_address_state"]], $propValues[$properties["other_address_country"]], $propValues[$properties["other_address"]], $propValues, $properties);
        }
        if (isset($categories) && !empty($categories)) {
            setProperty("categories", $categories, $propValues, $properties);
        }
        // if the display name is set, then it is a valid contact: save it to the folder
        if (isset($propValues[$properties["display_name"]])) {
            $propValues[$properties["message_class"]] = "IPM.Contact";
            $propValues[$properties["icon_index"]] = "512";
            $message = mapi_folder_createmessage($folder);
            mapi_setprops($message, $propValues);
            mapi_savechanges($message);
            printf("New contact added: \"%s\".\n", $propValues[$properties["display_name"]]);
        }
        $i++;
    }
}