$ListField) { $ins.="&$ImpFieldID=$ListField"; $Do[$ListField]=$ImpFieldID; } mysql_query("UPDATE " . $TABLEPREFIX . "imports SET FieldLinks='".addslashes($ins)."' WHERE ImportID='".addslashes($ImportID)."'"); $import_result = mysql_query("SELECT * FROM " . $TABLEPREFIX . "imports WHERE ImportID='" . addslashes($ImportID)."'"); $IMPORT = mysql_fetch_assoc($import_result); if (!SAFE_MODE) { $IMPORT_DIR = $ROOTDIR.'temp/import_' . $ImportID; } else { $IMPORT_DIR = $ROOTDIR . 'temp/import'; } /* This splits up the file to be imported into 100 line chunks so we can do a popup window and have it refresh. This should ease people who are looking to import thousands of users at a time. */ if (!is_dir($IMPORT_DIR)) { if (!SAFE_MODE) { if (!mkdir($IMPORT_DIR, 0755)) { $OUTPUT .= MakeErrorBox("An error occurred", "Unable to create directory " . str_replace($ROOTDIR, '', $IMPORT_DIR)); } } else { $OUTPUT .= MakeErrorBox("An error occurred", "Please create the '" . $ROOTDIR . "temp/import' directory and CHMOD it to 777"); } } $num_files = 0; if (is_dir($IMPORT_DIR)) { $original_import_file = file($ROOTDIR.'temp/' . $ImportID); $size = sizeof($original_import_file); $num_files = 1; $start_pos = 0; $header = array(); if ($IMPORT['Headers'] == 1) { $header = array_slice($original_import_file, 0, 1); } while($start_pos < $size) { $file_contents = array_slice($original_import_file, $start_pos, $IMPORT_PER_FILE); $handle = fopen($IMPORT_DIR.'/import_file' . $num_files, 'w'); // dont include the header in the first file, it's already there. if ($start_pos > 0) fputs($handle, implode("", $header)); fputs($handle, implode("", $file_contents)); fclose($handle); $start_pos += $IMPORT_PER_FILE; $num_files++; } } $popup_link = "import?ImportID=$ImportID&Action=DoImport&StartTime=$SYSTEMTIME&TotalFiles=$num_files"; $add_to_url = array('ConfStatus', 'Status', 'AbFormat', 'OverrideDate'); foreach($add_to_url as $k) { $popup_link .= "&" . $k . "=" . $$k; } $link_fields = urlencode(serialize($_POST['LinkField'])); $popup_link .= "&LinkField=" . $link_fields; $link = MakeAdminLink($popup_link); $OUTPUT .= 'Click OK to start importing your users ...
'; $OUTPUT .= '
  • ".number_format($DuplicateAttempts, 0)." duplicate subscribers were detected and were rejected.
  • ".number_format($OverwrittenRecords, 0) . " subscriber details were updated.
  • ".number_format($BannedAttempts, 0) . " subscribers were not added because they are banned.
  • "; if (isset($_REQUEST['RemovedRecords'])) { $report .= "
  • " . number_format($RemovedRecords, 0) . " subscribers were removed successfully.
  • "; } $report .= ""; $OUTPUT .= MakeSuccessBox("Import Completed Successfully", $report, MakeAdminLink("members?View=ListSummary&ListID=$ListID&Status=ALL&Confirmed=ALL&Format=ALL&PerPage=20")); session_save_path($ROOTDIR.'temp'); session_name('SendStudio'); session_start(); foreach($_SESSION as $k => $v) { session_unregister($k); } session_destroy(); } if($Action=='UploadText' && $ImportID) { $owrite = (isset($_POST['overwrite'])) ? $_POST['overwrite'] : 0; mysql_query("UPDATE " . $TABLEPREFIX . "imports SET Headers='".addslashes($headers)."', FieldDelim='".addslashes($fielddelim)."', RecordDelim='".addslashes($recorddelim)."', OverWrite='".addslashes($owrite)."' WHERE ImportID='".addslashes($ImportID)."'"); $imp=mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "imports WHERE ImportID='".addslashes($ImportID)."'")); $imp = stripslashes_array($imp); $ListID=$imp['ListID']; $impfile = false; $continue = true; if (!empty($_FILES['TextFileName'])) { if (SAFE_MODE) { $IMPORT_DIR = $ROOTDIR . 'temp/import'; if (!is_dir($IMPORT_DIR)) { $OUTPUT .= MakeErrorBox("An error occurred", "Please create the '" . $ROOTDIR . "temp/import' folder and make it writable. CHMOD this folder to 777"); $continue = false; } } if ($continue) { $userfile = $_FILES['TextFileName']['tmp_name']; $filename = $_FILES['TextFileName']['name']; if(is_uploaded_file($userfile)) { if(!is_writable($ROOTDIR.'/temp')) { $OUTPUT .= MakeErrorBox("An error occurred", "The '" . $ROOTDIR . "temp' folder is not writable. Please CHMOD this folder to 757."); } else { clearstatcache(); $impfile = $ROOTDIR.'/temp/' . $ImportID; move_uploaded_file($userfile, $impfile); } } } } if (isset($_POST['ServerFile']) && $_POST['ServerFile'] != '0') { $serverfile = $ROOTDIR . 'temp/' . $_POST['ServerFile']; $impfile = $ROOTDIR.'temp/' . $ImportID; if (!rename($serverfile, $impfile)) { if (SAFE_MODE) { $OUTPUT .= MakeErrorBox("An error occurred", "Unable to rename the import file for importing. You will need to upload the file through the browser due to server restrictions."); } else { $OUTPUT .= MakeErrorBox("An error occurred", "Unable to rename the import file for importing. Possible permissions problem."); } } else { $continue = true; } } if ($continue) { if ($impfile && is_file($impfile)) { $impdat = ParseImportFile($ImportID, true); // Was the import OK? if($impdat == "") { $OUTPUT .= MakeErrorBox("Invalid Import File", "The file that you have imported is empty or contains invalid data."); } else { $headers = $impdat['Headers']; $alllistfields = 'None->---- None;E->Email Address;F->Newsletter Format;S->Subscriber Status;C->Subscriber Confirmed;'; $custom_fields = FetchCustomFields(); foreach($custom_fields as $pos => $f) { $f = stripslashes_array($f); $alllistfields .= $f['FieldID'].'->'.$f['FieldName'].';'; } //field linkings! foreach($headers as $ID=>$Field) { $FORM_ITEMS["Link '".$Field."' To"]="select|LinkField[$ID]:1:$alllistfields"; if($hasHeaders == 0) { $HELP_ITEMS["LinkField[$ID]"]["Title"] = "Field Preview:"; $HELP_ITEMS["LinkField[$ID]"]["Content"] = str_replace('\r', '', str_replace('\n', '', str_replace('\'', '\\\'', $impdat["Data"][1]["Field $ID"]))); } } $FORM_ITEMS["-1"]="submit|Next »:1-import?Action=ChooseDatasource&ListID=$ListID"; //make the form $FORM=new AdminForm; $FORM->title="ImportLinkings"; $FORM->items=$FORM_ITEMS; $FORM->action=MakeAdminLink("import?Action=VerifyLinkings&ImportID=$ImportID&ConfStatus=$ConfStatus&Status=$Status&AbFormat=$AbFormat"); $FORM->MakeForm("Link Import Fields"); $FORM->output = "Use the form below to define which import fields should map to which subscriber fields." . $FORM->output; $OUTPUT.=MakeBox("Import Subscribers (Step 4 of 5)",$FORM->output); $OUTPUT .= ' '; } } else { $OUTPUT .= MakeErrorBox("Invalid Import File", "The file you selected to import from doesn't exist"); } } } if ($Action == 'ChooseDatasource') { mysql_query("INSERT INTO " . $TABLEPREFIX . "imports SET ListID='".addslashes($ListID)."', TimeStamp='".addslashes($SYSTEMTIME)."'"); $ImportID=mysql_insert_id(); $FORM_ITEMS["-3"]="hidden|ListID:$ListID"; $FORM_ITEMS["-2"]="hidden|ImportID:$ImportID"; $FORM_ITEMS[$FORM_REQUIRED_ITEM . 'Import Type'] = 'select|ImportType:1:1->File;2->Database;3->Email Account:1'; $HELP_ITEMS['ImportType']['Title'] = 'Importing Records'; $HELP_ITEMS['ImportType']['Content'] = 'Where should we import our records from?

    File:
    Import from a file (such as a CSV), you can either upload it through the \\\'browse\\\' button, or FTP the file to your server and name it \\\'import\\\' and choose it from the server.

    Database
    You can import records from another database by choosing this option.

    Email Address
    Check an email address for any emails with the word \\\'subscribe\\\' or \\\'unsubscribe\\\' in the subject.
    Note: This will only import email addresses, it will not import custom subscriber fields.'; $FORM_ITEMS['-1']="submit|Next »:1-import"; $FORM=new AdminForm; $FORM->title="ChooseSource"; $FORM->items=$FORM_ITEMS; $FORM->action=MakeAdminLink("import?Action=Datasource"); $FORM->MakeForm("Import Type"); $FORM->output = "Choose which type of import you will be performing.
    " . $FORM->output; $OUTPUT.=MakeBox("Import Subscribers (Step 2 of 5)",$FORM->output); $OUTPUT .= ' '; } if($Action=='Datasource') { $FORM_ITEMS["-3"]="hidden|ListID:$ListID"; $FORM_ITEMS["-2"]="hidden|ImportID:$ImportID"; $list = mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "lists WHERE ListID = '".addslashes($ListID)."' ORDER BY ListName ASC")); $list = stripslashes_array($list); $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Status"]="select|Status:1:0->Inactive;1->Active:1"; $HELP_ITEMS['Status']['Title'] = "Status"; $HELP_ITEMS['Status']['Content'] = "When these subscribers are imported, should they be marked as active or inactive?"; $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Confirmed"] = "select|ConfStatus:1:1->All Confirmed;0->All Unconfirmed"; $HELP_ITEMS['ConfStatus']['Title'] = "Confirmation Status"; $HELP_ITEMS['ConfStatus']['Content'] = "If a subscriber was to join your list using a normal subscription form with \'Requires Confirmation\' enabled, then they would be marked as unconfirmed until they click on the confirmation link inside the email automatically sent to them."; if($list['Formats'] == 3) { $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Format"] = "select|AbFormat:1:text->Text;html->HTML:" . $list['Formats']; } else if($list['Formats'] == 1) { $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Format"] = "select|AbFormat:text:text->Text Only"; } else { $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Format"] = "select|AbFormat:html:html->HTML Only"; } $HELP_ITEMS['AbFormat']['Title'] = "Format"; $HELP_ITEMS['AbFormat']['Content'] = "Which newsletter format should these subscribers be \'flagged\' to receive? Text only or HTML? HTML subscribers can also receive text newsletters. This is overwritten if there is a format field in the uploaded file."; $FORM_ITEMS[$FORM_NOT_REQUIRED_ITEM . "Overwrite Existing Subscriber"]="checkbox|overwrite:1:Yes, overwrite existing subscriber :"; $HELP_ITEMS['overwrite']['Title'] = "Overwrite Existing Subscriber"; $HELP_ITEMS['overwrite']['Content'] = "If a subscriber already exists in the current mailing list with the same email address, should we overwrite their information based on the imported data, or keep the existing information?"; switch($_REQUEST['ImportType']) { case 1: // file. $FORM_ITEMS['-100'] = 'spacer|
      Import File Details
    '; $FORM_ITEMS[$FORM_NOT_REQUIRED_ITEM . "Contains Headers"]="checkbox|headers:1:Yes, contains headers :checked"; $HELP_ITEMS['headers']['Title'] = "Contains Headers"; $HELP_ITEMS['headers']['Content'] = "Does the first line of your import file contain headers? If so, each header should be separated with a field separator, such as: email, name, sex."; $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Field Separator"]="textfield|fielddelim:10:10:,"; $HELP_ITEMS['fielddelim']['Title'] = "Field Separator"; $HELP_ITEMS['fielddelim']['Content'] = "What is the character used in your import file that separates the contents of each new field in a record?"; $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Record Separator"]="textfield|recorddelim:10:10:NEWLINE"; $HELP_ITEMS['recorddelim']['Title'] = "Record Separator"; $HELP_ITEMS['recorddelim']['Content'] = "What is the character used in your import file that separates one record from the next?"; $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Import File"]="file|TextFileName"; $HELP_ITEMS['TextFileName']['Title'] = "Import File"; $HELP_ITEMS['TextFileName']['Content'] = "Choose a file to upload that contains the subscriber details that you want to import. This should be a plain text file."; $import_files = list_files($ROOTDIR.'temp/'); $filelist = '0->Select a file from the server;'; if (!empty($import_files)) { $found_import_files = false; foreach($import_files as $import_file) { if (!preg_match('/^import/', $import_file)) continue; $found_import_files = true; $filelist .= $import_file . '->' . $import_file . ';'; } $filelist = substr($filelist, 0, -1); } $extra_check = ''; if ($found_import_files) { $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Import Server File"]="select|ServerFile:1:" . $filelist; $HELP_ITEMS['ServerFile']['Title'] = "Import File"; $HELP_ITEMS['ServerFile']['Content'] = "Choose a file on the server that contains the subscriber details that you want to import. This should be a plain text file.
    The file should be named so the start is \'import\' - eg \'import_list.txt\'"; $extra_check = ' && (f.ServerFile.selectedIndex == -1 || f.ServerFile.selectedIndex == 0) '; } $FORM_ITEMS["-1"]="submit|Next »:1-import?Action=ChooseDatasource&ListID=$ListID"; //make the form $FORM=new AdminForm; $FORM->title="TextFileImport"; $FORM->items=$FORM_ITEMS; $FORM->action=MakeAdminLink("import?Action=UploadText"); $FORM->EXTRA='ENCTYPE="multipart/form-data"'; $FORM->MakeForm("Import Details"); $FORM->output = "Complete the form below and then click on the \"Next\" button to proceed. For a tutorial on how to import subscribers, click here.
    " . $FORM->output; $OUTPUT.=MakeBox("Import Subscribers (Step 3 of 5)",$FORM->output); $OUTPUT .= ' '; $OUTPUT .= ' '; break; case 2: // database import $query = "SELECT * FROM " . $TABLEPREFIX . "import_mappings WHERE AdminID='" . addslashes($CURRENTADMIN['AdminID'])."' AND ImportType='db'"; $map_result = mysql_query($query); $default_database_host = $default_database_user = $default_database_pass = $default_database_name = ''; $map_list = ''; $jscript = ' '; $list = mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "lists WHERE ListID = '".addslashes($ListID)."' ORDER BY ListName ASC")); $list = stripslashes_array($list); if($list['Formats'] == 3) { $format = ''; } else if($list['Formats'] == 1) { $format = ''; } else { $format = ''; } $form = '
      
     
      Import Details
    ' . $FORM_REQUIRED_ITEM . 'Status: '; $HELP_ITEMS['Status']['Title'] = 'Status'; $HELP_ITEMS['Status']['Content'] = 'When these subscribers are imported, should they be marked as active or inactive?'; $item = MakeHelp('Status'); $form .= $item; $form .= '
    ' . $FORM_REQUIRED_ITEM . 'Confirmed: '; $HELP_ITEMS['Confirmed']['Title'] = 'Confirmed'; $HELP_ITEMS['Confirmed']['Content'] = 'If a subscriber was to join your list using a normal subscription form with Requires Confirmation enabled, then they would be marked as unconfirmed until they click on the confirmation link inside the email automatically sent to them.'; $item = MakeHelp('Confirmed'); $form .= $item; $form .= '
    ' . $FORM_REQUIRED_ITEM . 'Format: '; $HELP_ITEMS['Format']['Title'] = 'Format'; $HELP_ITEMS['Format']['Content'] = 'Which newsletter format should these subscribers be flagged to receive?'; $item = MakeHelp('Format'); $form .= $item; $form .= '
    ' . $FORM_NOT_REQUIRED_ITEM . 'Overwrite Existing Subscriber? Yes, overwrite existing subscriber '; $HELP_ITEMS['Overwrite']['Title'] = 'Overwrite'; $HELP_ITEMS['Overwrite']['Content'] = 'If a subscriber already exists in the current mailing list with the same email address, should we overwrite their information based on the imported data, or keep the existing information?'; $item = MakeHelp('Overwrite'); $form .= $item; $form .= '

      Database Details
    ' . $FORM_NOT_REQUIRED_ITEM . 'Previously Saved Settings: '; $HELP_ITEMS['Saved']['Title'] = 'Previously Saved Settings'; $HELP_ITEMS['Saved']['Content'] = 'If youve previously saved your database details when importing (Step 4) you can reload them from here. If not, simply select the new option'; $item = MakeHelp('Saved'); $form .= $item; $form .= '
    ' . $FORM_REQUIRED_ITEM . 'MySQL Server: '; $HELP_ITEMS['host']['Title'] = 'MySQL Server'; $HELP_ITEMS['host']['Content'] = 'MySQL server I.P. address/hostname, such as localhost'; $item = MakeHelp('host'); $form .= $item; $form .= '
    ' . $FORM_REQUIRED_ITEM . 'MySQL Username: '; $HELP_ITEMS['user']['Title'] = 'MySQL Username'; $HELP_ITEMS['user']['Content'] = 'Username for a valid MySQL account'; $item = MakeHelp('user'); $form .= $item; $form .= '
    ' . $FORM_NOT_REQUIRED_ITEM . 'MySQL Password: '; $HELP_ITEMS['pass']['Title'] = 'MySQL Password'; $HELP_ITEMS['pass']['Content'] = 'Password for a valid MySQL account'; $item = MakeHelp('pass'); $form .= $item; $form .= '
    ' . $FORM_REQUIRED_ITEM . 'MySQL Database: '; $HELP_ITEMS['dbname']['Title'] = 'MySQL Username'; $HELP_ITEMS['dbname']['Content'] = 'Username for a valid MySQL account'; $item = MakeHelp('dbname'); $form .= $item; $form .= '
     
      
     
    '; $form .= $jscript; $intro_text = 'Complete the form below and then click on the "Next" button to proceed importing data from a database'; $OUTPUT.=MakeBox("Import Subscribers (Step 3 of 5)", $intro_text . $form); break; case 3: // email account $query = "SELECT * FROM " . $TABLEPREFIX . "import_mappings WHERE AdminID='" . addslashes($CURRENTADMIN['AdminID'])."' AND ImportType='email'"; $map_result = mysql_query($query); $default_email_host = $default_email_user = $default_email_pass = ''; $default_email_port = '110'; $map_list = ''; $jscript = ' '; $list = mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "lists WHERE ListID = '".addslashes($ListID)."' ORDER BY ListName ASC")); $list = stripslashes_array($list); if($list['Formats'] == 3) { $format = ''; } else if($list['Formats'] == 1) { $format = ''; } else { $format = ''; } $form = '
      

      Import Details
    ' . $FORM_NOT_REQUIRED_ITEM . 'Status:
    ' . $FORM_NOT_REQUIRED_ITEM . 'Confirmed:
    ' . $FORM_NOT_REQUIRED_ITEM . 'Format:

    Email Server Details
    ' . $FORM_NOT_REQUIRED_ITEM . 'Previously Saved Settings
    ' . $FORM_REQUIRED_ITEM . 'Email Hostname
    ' . $FORM_REQUIRED_ITEM . 'Email Username
    ' . $FORM_REQUIRED_ITEM . 'Email Password
    ' . $FORM_REQUIRED_ITEM . 'Email Port
    ' . $FORM_NOT_REQUIRED_ITEM . 'Save Import Details:Yes, save import details '; $HELP_ITEMS['ImportDetails']['Title'] = 'Overwrite'; $HELP_ITEMS['ImportDetails']['Content'] = 'Save your import settings, so next time you import data, you can load these settings (step 3) without needing to enter in all the required information'; $item = MakeHelp('ImportDetails'); $form .= $item; $form .= '
     
      
     
    '; $form .= $jscript; $intro_text = 'Complete the form below and then click on the "Next" button to proceed.

    '; $OUTPUT.=MakeBox("Import Subscribers (Step 3 of 5)", $intro_text . $form); break; } } if ($Action == 'CheckEmail') { $view = (isset($_GET['View'])) ? $_GET['View'] : ''; switch($view) { case 'CheckConnection': list($status, $result) = ConnectEmail($_POST['EmailHost'], $_POST['EmailUser'], $_POST['EmailPass'], $_POST['EmailPort']); if (!$status) { $OUTPUT .= MakeErrorBox("Unable to connect", "Unable to connect to email server: " . $result); } else { if (isset($_POST['SaveSettings']) && $_POST['SaveSettings'] == 1) { $email_mapping = array( 'hostname' => $_POST['EmailHost'], 'username' => $_POST['EmailUser'], 'password' => $_POST['EmailPass'], 'port' => $_POST['EmailPort'] ); if ($_POST['MapID'] <= 0) { $query = "INSERT INTO " . $TABLEPREFIX . "import_mappings(ListID, AdminID, ImportMap, ImportType) VALUES ('" . addslashes($_POST['ListID']) . "', '" . addslashes($CURRENTADMIN['AdminID']) . "', '" . addslashes(serialize($email_mapping)) . "', 'email')"; } else { $query = "UPDATE " . $TABLEPREFIX . "import_mappings SET ImportMap='" . addslashes(serialize($email_mapping)) . "' WHERE MapID='" . addslashes($_POST['MapID'])."'"; $MapID = $_POST['MapID']; } mysql_query($query); if ($_POST['MapID'] <= 0) $MapID = mysql_insert_id(); } imap_close($result); $popup_link = 'import?ImportID=' . $ImportID . '&Action=DoEmailImport&ListID=' . $ListID . '&EmailHost=' . $_POST['EmailHost'] . '&EmailUser=' . $_POST['EmailUser'] . '&EmailPass=' . $_POST['EmailPass'] . '&EmailPort=' . $_POST['EmailPort'] . '&Status=' . $_POST['Status'] . '&Confirmed=' . $_POST['Confirmed'] . '&Format=' . $_POST['Format']; $OUTPUT .= MakeSuccessBox("Connected to Email Server Successfully", "Connected to email server successfully. Click OK to start importing email addresses
    ", MakeAdminLink($popup_link), "", "", "import$ImportID~width=300,height=400,left=400,top=300"); } break; } } if ($Action == 'DatabaseMappings') { switch($_GET['View']) { case 'CheckConnection': list($status, $database_result) = MySQLConnect($_POST['DatabaseHost'], $_POST['DatabaseUser'], $_POST['DatabasePass'], $_POST['DatabaseName']); if (!$status) { $OUTPUT .= MakeErrorBox("Unable to connect", "Unable to connect to the MySQL server: " . $database_result); } if ($status) { $db_tables = FetchTables($_POST['DatabaseName']); mysql_close($database_result); // we need to re-establish the old database connection. we can't just use mysql_connect(host, user, pass, new_connection=1) since that came in at php 4.2 :( // so here we go! MySQLConnect($DBHOST, $DBUSER, $DBPASS, $DBNAME); $show_fields = true; $tablenames = array_keys($db_tables); if (empty($tablenames)) { $show_fields = false; $OUTPUT .= MakeErrorBox("Empty Database", "Sorry, that database is empty. Please try again."); } if ($show_fields) { $core_fields = array( 'Email' => 'Email', 'Format' => 'Newsletter Format', 'Confirmed' => 'Confirmation Status', 'Status' => 'Active/Inactive Status' ); $custom_fields = FetchCustomFields(); $db_map = array(); $OverWrite = (isset($_POST['OverWrite'])) ? 1 : 0; if ($_POST['MapID'] > 0) $db_map = LoadMap($_POST['MapID']); $table_list = ''; $Format = (isset($_POST['Format'])) ? $_POST['Format'] : 1; $Confirmed = (isset($_POST['Confirmed'])) ? $_POST['Confirmed'] : 0; $form = '
      
      '; foreach($core_fields as $name => $desc) { $selected = ''; $field_list = ''; if (isset($db_map['Map']['tablemapping'][$name])) { $default = current(array_keys($db_map['Map']['tablemapping'][$name])); $selected = '"' . $default . '"'; $id = 1; foreach($db_tables[$default] as $field) { $field_list .= ''; $id++; } } $tlist = str_replace('%%fieldname%%', $name, $table_list); if ($selected != '') $tlist = str_replace('value=' . $selected, 'SELECTED value=' . $selected, $tlist); $form .= ' '; } foreach($custom_fields as $pos => $fielddata) { $fieldid = $fielddata['FieldID']; $fieldname = $fielddata['FieldName']; $selected = ''; $field_list = ''; if (isset($db_map['Map']['tablemapping']['CustomFields'][$fieldid])) { $default = current(array_keys($db_map['Map']['tablemapping']['CustomFields'][$fieldid])); $selected = '"' . $default . '"'; $id = 1; foreach($db_tables[$default] as $field) { $field_list .= ''; $id++; } } else { $id = 1; foreach($db_tables[$tablename] as $field) { $field_list .= ''; $id++; } } $tlist = str_replace('%%fieldname%%', $fieldid, $table_list); if ($selected != '') $tlist = str_replace('value=' . $selected, 'SELECTED value=' . $selected, $tlist); $form .= ' '; } $form .= '
      Field Name   Database Table   Database Field
    ' . $name . ': ' . $tlist . '
    ' . $fieldname . ': ' . $tlist . '

      Save Settings
    Save Settings: Yes, save settings '; $HELP_ITEMS['ImportDetails']['Title'] = 'Save Settings'; $HELP_ITEMS['ImportDetails']['Content'] = 'Save your import settings, so next time you import data, you can load these settings (step 3) without needing to enter in all the required information'; $item = MakeHelp('ImportDetails'); $form .= $item; $form .= '
     
      
     
    '; $intro_text = 'Select which database fields you wish to insert into the subscriber fields.'; $OUTPUT.=MakeBox("Import Subscribers (Step 4 of 5)", $intro_text . $form); } // end if show_fields (ie the database isn't empty). } // end if ($status) break; case 'MapPaths': list($status, $database_result) = MySQLConnect($_POST['DatabaseHost'], $_POST['DatabaseUser'], $_POST['DatabasePass'], $_POST['DatabaseName']); $db_tables = FetchTables($_POST['DatabaseName']); mysql_close($database_result); // we need to re-establish the old database connection. we can't just use mysql_connect(host, user, pass, new_connection=1) since that came in at php 4.2 :( // so here we go! MySQLConnect($DBHOST, $DBUSER, $DBPASS, $DBNAME); $email_found = false; $database_mapping = array( 'hostname' => $_POST['DatabaseHost'], 'username' => $_POST['DatabaseUser'], 'password' => $_POST['DatabasePass'], 'database' => $_POST['DatabaseName'], 'tablemapping' => array() ); foreach($_POST as $key => $table) { if (!preg_match('%^map_%', $key) || preg_match('%_option$%', $key)) continue; $mapval = $key.'_option'; if (isset($_POST[$mapval]) && $_POST[$mapval] > 0) { $mapkey = preg_replace('%^map_%', '', $key); if ($mapkey == 'Email') $email_found = true; if (is_numeric($mapkey)) { $database_mapping['tablemapping']['CustomFields'][$mapkey] = array($_POST[$key] => $db_tables[$table][(int)($_POST[$mapval]-1)]); } else { $database_mapping['tablemapping'][$mapkey] = array($_POST[$key] => $db_tables[$table][(int)($_POST[$mapval]-1)]); } } } $errormsgs = array(); if (!$email_found) { $errormsgs[] = ' You need to at least map the Email Address field.'; $OUTPUT .= MakeErrorBox("Missing data", "Please try again." . implode('
    ', $errormsgs)); } else { if (isset($_POST['SaveSettings'])) { if ($_POST['MapID'] <= 0) { $query = "INSERT INTO " . $TABLEPREFIX . "import_mappings(ListID, AdminID, ImportMap, ImportType) VALUES ('" . addslashes($_POST['ListID']) . "', '" . addslashes($CURRENTADMIN['AdminID']) . "', '" . addslashes(serialize($database_mapping)) . "', 'db')"; } else { $query = "UPDATE " . $TABLEPREFIX . "import_mappings SET ImportMap='" . addslashes(serialize($database_mapping)) . "' WHERE MapID='" . addslashes($_POST['MapID'])."'"; } mysql_query($query); $MapID = ($_POST['MapID'] <= 0) ? mysql_insert_id() : $_POST['MapID']; } else { $MapID = $_POST['MapID']; } foreach(array('OverWrite', 'Confirmed') as $area) { $$area = (isset($_POST[$area])) ? $_POST[$area] : 0; } $Format = (isset($_POST['Format'])) ? $_POST['Format'] : 1; $popup_link = "import?Action=DoDatabaseImport&ImportID=$ImportID&MapID=$MapID&ListID=$ListID&OverWrite=$OverWrite&Status=$Status&Format=$Format&Confirmed=$Confirmed&ImportMap=" . urlencode(serialize($database_mapping)) . "&DatabaseHost=" . $_POST['DatabaseHost'] . "&DatabaseUser=" . $_POST['DatabaseUser'] . "&DatabasePass=" . $_POST['DatabasePass'] . "&DatabaseName=" . $_POST['DatabaseName']; $OUTPUT .= MakeSuccessBox("Connected to Database successfully", "Database mapped successfully. Click OK to start importing.", MakeAdminLink($popup_link), "", "", "import$ImportID~width=300,height=400,left=400,top=300"); } break; } } if ($Action == 'DoDatabaseImport') { $OUTPUT .= ''; $POPOUTPUT=1; include('includes/do_import_database.inc.php'); } if ($Action == 'DoEmailImport') { $OUTPUT .= ''; $POPOUTPUT=1; include('includes/do_import_email.inc.php'); } if(!$Action && !$ListID) { //select ListID form! $lists=mysql_query("SELECT * FROM " . $TABLEPREFIX . "lists ORDER BY ListName ASC"); while($l=mysql_fetch_assoc($lists)) { $l = stripslashes_array($l); if(AllowList($l['ListID'])) { if ($CURRENTADMIN['DisplaySummaries']) { $numSubs = (int)mysql_result(mysql_query("SELECT COUNT(*) from " . $TABLEPREFIX . "members where ListID=" . addslashes($l['ListID'])), 0, 0); if($numSubs == 1) $subs = "1 subscriber"; else $subs = number_format($numSubs, 0) . " subscribers"; $subs = " (" . $subs . ")"; } else { $subs = ""; } $alllists.=$l["ListID"]."->".str_replace(';', '$$SEMI$$', str_replace(':', '$$COLON$$', $l["ListName"]))."$subs;"; } } if ($alllists == '') { $OUTPUT = MakeBox("Import Subscribers",'No mailing lists have been created. Please click on the "Create Mailing List" button below to create one.



    '); } else { $FORM_ITEMS[$FORM_REQUIRED_ITEM . "Mailing List"]="select|ListID:5:$alllists"; $FORM_ITEMS["-1"]="submit|Next »:1-members"; $FORM=new AdminForm; $FORM->title="SelectList"; $FORM->items=$FORM_ITEMS; $FORM->action=MakeAdminLink("import?Action=ChooseDatasource"); $FORM->MakeForm("Import Details"); $FORM->output = "Before you can import subscribers, please choose a mailing list to work with." . $FORM->output; $OUTPUT.=MakeBox("Import Subscribers (Step 1 of 5)",$FORM->output); $OUTPUT .= ' '; } } ?>