$varValue) { if (strpos($varName, 'address') !== FALSE) $addresses[] = urldecode($varValue); } displayPageHeader($color, "None"); // These shouldn't be set at all at this point. $ADDRS['csvdata'] = array(); $ADDRS['csvorder'] = array(); foreach ($addresses as $addr) { list($address, $nick) = explode('---', $addr); if (empty($nick)) $nick = substr($address, 0, strpos($address, $emailAddressDelimiter)); if (preg_match('/(\w+), (\w+)/', $nick, $matches)) $temp = array($nick, $matches[2], $matches[1], $address, ''); else if (preg_match('/(\w+)[_ ](\w+)/', $nick, $matches)) $temp = array($nick, $matches[1], $matches[2], $address, ''); else $temp = array($nick, $nick, '', $address, ''); $ADDRS['csvdata'][$key] = $temp; $key++; } unset($ADDRS['csvorder']); echo '
'; // user's data table // Here I will create the headers that I want. echo ' '; // //'; // The Omit column for($x = 0; $x < $csvmax; $x++) { // The Drop down boxes to select what each column is echo ' '; } echo ' '; do { if (count($ADDRS['csvdata'][$row]) >= 5) { // This if ensures the minimum number of columns $cols = count($ADDRS['csvdata'][$row]); // so importing can function for all 5 fields } else { $cols = 5; } $colspan = $cols + 1; if ($row % 2) { // Set up the alternating colored rows echo ' '; } else { echo ' '; } //echo ' '; } else { // if empty, put space in cell keeping colors correct. echo ' '; } } echo ' '; $row++; } while ($row < count($ADDRS['csvdata'])); echo '
' . _("Add To Address Book:") . '

' . _("Omit") . ''; create_Select($csvmax,$x); echo '
//'; // Print the omit checkbox, to be checked before write for($c = 0; $c < $cols; $c++) { // For each column in the current row if ($ADDRS['csvdata'][$row][$c] != "") { // if not empty, put data in cell. echo '

'; if(strlen($errorstring)) { echo _("The following rows have errors") . ':

' . $errorstring; } } else { /** ** $abook ---->Setup the addressbook functions for Pallo's Addressbook. **/ $abook = addressbook_init(true, true); // We only need to do this here because we will only access the address book in this section // rebuild submit data // foreach ($_POST as $varName => $varValue) { preg_match('/^data(\d)_(\d)$/', $varName, $matches); if (count($matches)) { $ADDRS['csvdata'][$matches[1]][$matches[2]] = $varValue; } } do { if (count($ADDRS['csvdata'][$row]) >= 5) { // This if ensures the minimum number of columns $cols = count($ADDRS['csvdata'][$row]); // so importing can function for all 5 fields } else { $cols = 5; } $reorg = array('', '', '', '', ''); for ($c=0; $c < $cols; $c++) { // Reorganize the data to fit the header cells that the user chose // concatenate fields based on user input into text boxes. $column = "COL$c"; if($_POST[$column] != 5) { if ($_POST[$column] == 4) { $reorg[4] .= $ADDRS['csvdata'][$row][$c] . ";"; } else { $reorg[$_POST[$column]] = $ADDRS['csvdata'][$row][$c]; $reorg[$c] = trim($reorg[$c],"\r\n \""); } } } $reorg[4] = trim($reorg[4],";"); $ADDRS['csvdata'][$row] = $reorg; unset($reorg); // So that we don't get any weird information from a previous rows // If finished, do the import. This uses Pallo's excellent class and object stuff $selrow = 'sel' . $row; if (!isset($_POST[$selrow])) { if (eregi('[ \\:\\|\\#\\"\\!]', $ADDRS['csvdata'][$row][0])) { $ADDRS['csvdata'][$row][0] = ''; } //Here we should create the right data to input if (count($ADDRS['csvdata'][$row]) < 5) { array_pad($ADDRS['csvdata'][$row],5,''); } $addaddr['nickname'] = $ADDRS['csvdata'][$row][0]; $addaddr['firstname'] = $ADDRS['csvdata'][$row][1]; $addaddr['lastname'] = $ADDRS['csvdata'][$row][2]; $addaddr['email'] = $ADDRS['csvdata'][$row][3]; $addaddr['label'] = $ADDRS['csvdata'][$row][4]; if (false == $abook->add($addaddr,$abook->localbackend)) { $errorstring .= $abook->error . "
\n"; $error++; } unset($addaddr); // Also so we don't get any weird information from previous rows } $row++; } while($row < count($ADDRS['csvdata'])); unset($ADDRS['csvdata']); // Now that we've uploaded this information, we dont' need this variable anymore, aka cleanup // Print out that we've completed this operation if ($error) { // Since we will print something to the page at this point displayPageHeader($color, "None"); echo '
' . _("There were errors uploading the data, as listed below. Entries not listed here were uploaded.") . '
' . $errorstring . '
'; } else { header('Location: ../../src/addressbook.php'); exit; // Since we will print something to the page at this point displayPageHeader($color, "None"); echo '

' . _("Upload Completed!") . '

' . _("Click on the link below to verify your work.") . ''; } echo '

' . _("Addresses") . '
'; } // Send the field numbers entered in the text boxes by the user back to this script for more processing // email is handled differently, not being an array function create_Select($csvmax,$column) { // $column is the one that should be selected out of the bunch echo "\n"; } bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain('squirrelmail'); ?>