function process($argv) { mapidefs(); mapitags(); if (!isset($argv[1]) || !isset($argv[2]) || !isset($argv[3]) || !isset($argv[4])) { return INVALID_ARGS; } // Process parameters. $username = $argv[2]; $password = $argv[3]; $csv_file = $argv[4]; $store = openMsgStore($username, $password); if ($argv[1] == "import") { if (!isset($argv[5]) || $argv[5] != "add" && $argv[5] != "replace") { return INVALID_ARGS; } if (!file_exists($csv_file)) { print "File {$csv_file} not found.\n"; return 1; } $delete_old_items = $argv[5] == "replace"; $categories = isset($argv[6]) ? $argv[6] : ""; print "Importing {$csv_file}...\n"; import($store, $csv_file, $delete_old_items, $categories); } else { if ($argv[1] == "export") { if (isset($argv[5]) && $argv[5] != "overwrite") { return INVALID_ARGS; } $overwrite = isset($argv[5]) && $argv[5] == "overwrite"; if (!$overwrite && file_exists($csv_file)) { print "File {$csv_file} already existing, you can use the overwrite option.\n"; return 1; } print "Exporting to {$csv_file}...\n"; export($store, $csv_file); } else { return INVALID_ARGS; } } return 0; }
// when set to false only the line ends of the running system are used (so don't change this) define("CSV_CHARSET", "UTF-8"); // The charset of the CSV input files //set it to true if the first line of the csv file contains field names, it will be skipped then. define("FIELD_NAMES", true); //the format of date values: true if they are as unix timestamps, false otherwise define("DATES_AS_TIMESTAMPS", false); // mapping for the csv column number to contact field (first field is 0) $csv_mapping = array("given_name" => 0, "middle_name" => 1, "surname" => 2, "display_name_prefix" => 3, "webpage" => 6, "birthday" => 8, "wedding_anniversary" => 9, "notes" => 13, "email_address_1" => 14, "email_address_2" => 15, "email_address_3" => 16, "home_telephone_number" => 18, "home2_telephone_number" => 19, "cellular_telephone_number" => 20, "pager_telephone_number" => 21, "home_fax_number" => 22, "home_address" => 23, "home_address_street" => 24, "home_address_street2" => 25, "home_address_street3" => 26, "home_address_pobox" => 27, "home_address_city" => 28, "home_address_state" => 29, "home_address_postal_code" => 30, "home_address_country" => 31, "spouse_name" => 32, "manager_name" => 34, "assistant" => 35, "company_telephone_number" => 37, "office_telephone_number" => 38, "business2_telephone_number" => 39, "business_fax_number" => 40, "assistant_telephone_number" => 41, "company_name" => 42, "job_title" => 43, "department_name" => 44, "office_location" => 45, "profession" => 47, "business_address" => 49, "business_address_street" => 50, "business_address_street2" => 51, "business_address_street3" => 52, "business_address_pobox" => 53, "business_address_city" => 54, "business_address_state" => 55, "business_address_postal_code" => 56, "business_address_country" => 57, "other_telephone_number" => 58, "other_address" => 60, "other_address_street" => 61, "other_address_street2" => 62, "other_address_street3" => 63, "other_address_pobox" => 64, "other_address_city" => 65, "other_address_state" => 66, "other_address_postal_code" => 67, "other_address_country" => 68, "callback_telephone_number" => 69, "car_telephone_number" => 70, "isdn_number" => 71, "radio_telephone_number" => 72, "ttytdd_telephone_number" => 73, "telex_telephone_number" => 74, "sensitivity" => 84, "categories" => 87); ########################## ## end of configuration ## ########################## error_reporting(E_ALL); ini_set("display_errors", true); ini_set("html_errors", false); mapidefs(); mapitags(); $session = mapi_logon_zarafa($username, $password, SERVER); if (mapi_last_hresult() != 0) { trigger_error(sprintf("MAPI Error: 0x%x", mapi_last_hresult()), E_USER_ERROR); } $storesTable = mapi_getmsgstorestable($session); $stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER)); for ($i = 0; $i < count($stores); $i++) { if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) { $storeEntryid = $stores[$i][PR_ENTRYID]; break; } } if (!isset($storeEntryid)) { trigger_error("Default store not found", E_USER_ERROR);