'.$GLOBALS['I18N']->get('import is not available').'

'; return; } print ''; ignore_user_abort(); set_time_limit(500); ob_end_flush(); ?>

get('temp_dir_not_writeable')." (".$GLOBALS["tmpdir"].")"); } if(isset($_REQUEST['import'])) { $test_import = (isset($_POST["import_test"]) && $_POST["import_test"] == "yes"); /* if (!is_array($_POST["lists"]) && !$test_import) { Fatal_Error($GLOBALS['I18N']->get('select_list')); return; } */ if(empty($_FILES["import_file"])) { Fatal_Error($GLOBALS['I18N']->get('none_specified')); return; } if(!$_FILES["import_file"]) { Fatal_Error($GLOBALS['I18N']->get('too_large_inexistant')); return; } if (filesize($_FILES["import_file"]['tmp_name']) > 1000000) { Fatal_Error($GLOBALS['I18N']->get('too_big')); return; } if( !preg_match("/^[0-9A-Za-z_\.\-\/\s \(\)]+$/", $_FILES["import_file"]["name"]) ) { Fatal_Error($GLOBALS['I18N']->get('wrong_characters').$_FILES["import_file"]["name"]); return; } if (!$_POST["notify"] && !$test_import) { Fatal_Error($GLOBALS['I18N']->get('signup_or_notify')); return; } $notify = $_POST["notify"]; if ($_FILES["import_file"] && filesize($_FILES["import_file"]['tmp_name']) > 10) { $newfile = $GLOBALS['tmpdir'].'/'. $_FILES['import_file']['name'].time(); move_uploaded_file($_FILES['import_file']['tmp_name'], $newfile); if( !($fp = fopen ($newfile, "r"))) { Fatal_Error($GLOBALS['I18N']->get('unreadable')." (".$newfile.")"); return; } $email_list = fread($fp, filesize ($newfile)); fclose($fp); } elseif ($_FILES["import_file"]) { Fatal_Error($GLOBALS['I18N']->get('empty_file')); return; } // Clean up email file $email_list = trim($email_list); $email_list = str_replace("\r","\n",$email_list); $email_list = str_replace("\n\r","\n",$email_list); $email_list = str_replace("\n\n","\n",$email_list); if (isset($_REQUEST['import_record_delimiter'])) { $import_record_delimiter = $_REQUEST['import_record_delimiter']; } else { $import_record_delimiter = "\n"; } // Change delimiter for new line. if(isset($import_record_delimiter) && $import_record_delimiter != "" && $import_record_delimiter != "\n") { $email_list = str_replace($import_record_delimiter,"\n",$email_list); }; if (!isset($import_field_delimiter) || $import_field_delimiter == "" || $import_field_delimiter == "TAB") $import_field_delimiter = "\t"; // Check file for illegal characters $illegal_cha = array(",", ";", ":", "#","\t"); for($i=0; $iget('invalid_delimiter')." $import_field_delimiter, $import_record_delimiter");return; } }; // Split file/emails into array $email_list = explode("\n",$email_list); // Parse the lines into records $hasinfo = 0; foreach ($email_list as $line) { $uservalues = explode($import_field_delimiter,$line); $email = trim(array_shift($uservalues)); $info = join(" ",$uservalues); $hasinfo = $hasinfo || $info != ""; $user_list[$email] = array ( "info" => $info ); } if (sizeof($email_list) > 300 && !$test_import) { # this is a possibly a time consuming process, so lets show a progress bar print ''; flush(); # increase the memory to make sure we are not running out ini_set("memory_limit","16M"); } // View test output of emails if($test_import) { print $GLOBALS['I18N']->get('test_output').':
'.$GLOBALS['I18N']->get('one_email_per_line').'
'.$GLOBALS['I18N']->get('output_ok').' '.$GLOBALS['I18N']->get('back').''.$GLOBALS['I18N']->get('resubmit').'

'; $i = 1; while (list($email,$data) = each ($user_list)) { $email = trim($email); if(strlen($email) > 4) { print "$email
"; $html = ""; foreach (array("info") as $item) if ($user_list[$email][$item]) $html .= "$item -> ".$user_list[$email][$item]."
"; if ($html) print "

$html
"; }; if($i == 50) {break;}; $i++; }; // Do import } else { $count_email_add = 0; $count_email_exist = 0; $count_list_add = 0; if (isset($_REQUEST['lists']) && is_array($_REQUEST['lists'])) { $lists = $_REQUEST['lists']; } else { $lists = array(); } $num_lists = sizeof($lists); $todo = sizeof($user_list); $done = 0; if ($hasinfo) { # we need to add an info attribute if it does not exist $req = Sql_Query("select id from ".$tables["attribute"]." where name = \"info\""); if (!Sql_Affected_Rows()) { # it did not exist Sql_Query(sprintf('insert into %s (name,type,listorder,default_value,required,tablename) values("info","textline",0,"",0,"info")', $tables["attribute"])); } } # which attributes were chosen, apply to all users $res = Sql_Query("select * from ".$tables["attribute"]); $attributes = array(); while ($row = Sql_Fetch_Array($res)) { $fieldname = "attribute" .$row["id"]; $attributes[$row["id"]] = $_POST[$fieldname]; } while (list($email,$data) = each ($user_list)) { ## a lot of spreadsheet include those annoying quotes $email = str_replace('"', '', $email); $done++; if ($done % 50 ==0) { print "$done/$todo
"; flush(); } if(strlen($email) > 4) { $email = addslashes($email); // Annoying hack => Much too time consuming. Solution => Set email in users to UNIQUE() $result = Sql_query("SELECT id,uniqid FROM ".$tables["user"]." WHERE email = '$email'"); if (Sql_affected_rows()) { // Email exist, remember some values to add them to the lists $user = Sql_fetch_array($result); $userid = $user["id"]; $uniqid = $user["uniqid"]; $history_entry = $GLOBALS['I18N']->get('import_user'); $old_data = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',$tables["user"],$userid)); $old_data = array_merge($old_data,getUserAttributeValues('',$userid)); # and membership of lists $req = Sql_Query("select * from {$tables["listuser"]} where userid = $userid"); while ($row = Sql_Fetch_Array($req)) { $old_listmembership[$row["listid"]] = listName($row["listid"]); } $count_email_exist++; } else { // Email does not exist // Create unique number mt_srand((double)microtime()*1000000); $randval = mt_rand(); include_once dirname(__FILE__)."/commonlib/lib/userlib.php"; $uniqid = getUniqid(); $query = sprintf('INSERT INTO %s (email,entered,confirmed,uniqid,htmlemail) values("%s",now(),%d,"%s","%s")', $tables["user"],$email,$notify != "yes",$uniqid,isset($_POST['htmlemail']) ? '1':'0'); $result = Sql_query($query); $userid = Sql_insert_id(); $count_email_add++; $some = 1; $history_entry = $GLOBALS['I18N']->get('import_new_user'); # add the attributes for this user reset($attributes); while (list($attr,$value) = each($attributes)) Sql_query(sprintf('replace into %s (attributeid,userid,value) values("%s","%s","%s")', $tables["user_attribute"],$attr,$userid,addslashes($value))); } #add this user to the lists identified reset($lists); $addition = 0; $listoflists = ""; while (list($key,$listid) = each($lists)) { $query = "replace INTO ".$tables["listuser"]." (userid,listid,entered) values($userid,$listid,now())"; $result = Sql_query($query); # if the affected rows is 2, the user was already subscribed $addition = $addition || Sql_Affected_Rows() == 1; if (!empty($_POST['listname'][$key])) { $listoflists .= " * ".$_POST['listname'][$key]."\n"; } } if ($addition) { $additional_emails++; } $subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid)); if (!TEST && $notify == "yes" && $addition) sendMail($email, getConfig("subscribesubject"), $subscribemessage,system_messageheaders(),$envelope); # history stuff $current_data = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',$tables["user"],$userid)); $current_data = array_merge($current_data,getUserAttributeValues('',$userid)); foreach ($current_data as $key => $val) { if (!is_numeric($key)) if ($old_data[$key] != $val && $key != "modified") { $history_entry .= "$key = $val\nchanged from $old_data[$key]\n"; } } if (!$history_entry) { $history_entry = "\n".$GLOBALS['I18N']->get('no_data_changed'); } # check lists $req = Sql_Query("select * from {$tables["listuser"]} where userid = $userid"); while ($row = Sql_Fetch_Array($req)) { $listmembership[$row["listid"]] = listName($row["listid"]); } $history_entry .= "\n".$GLOBALS['I18N']->get('lists_subscriptions')."\n"; foreach ($old_listmembership as $key => $val) { $history_entry .= $GLOBALS['I18N']->get('was_subscribed')." $val\n"; } foreach ($listmembership as $key => $val) { $history_entry .= $GLOBALS['I18N']->get('is_subscribed')." $val\n"; } if (!sizeof($listmembership)) { $history_entry .= $GLOBALS['I18N']->get('not_subscribed')."\n"; } addUserHistory($email,$GLOBALS['I18N']->get('import_by').adminName(),$history_entry); }; // end if }; // end while print ''; # lets be gramatically correct :-) $displists = ($num_lists == 1) ? $GLOBALS['I18N']->get('list'): $GLOBALS['I18N']->get('lists'); $dispemail = ($count_email_add == 1) ? $GLOBALS['I18N']->get('new_email_was'): $GLOBALS['I18N']->get('new_emails_were'); $dispemail2 = ($additional_emails == 1) ? $GLOBALS['I18N']->get('email_was'): $GLOBALS['I18N']->get('emails_were'); if ($count_email_exist) { print "
$count_email_exist ".$GLOBALS['I18N']->get('some_emails_exist'); } if(!$some && !$additional_emails) { print "
".$GLOBALS['I18N']->get('all_emails_exist'); } else { print "$count_email_add $dispemail ".$GLOBALS['I18N']->get('import_successful')." $num_lists $displists.
$additional_emails $dispemail2 ".$GLOBALS['I18N']->get('subscribed')." $displists"; } }; // end else print '

'.PageLink2("import",$GLOBALS['I18N']->get('import_more_emails')).'

'; } else { ?>
get('info_emails_file'); ?>
get('emails_file'); ?>
get('field_delimiter'); ?> get('tab_default'); ?>
get('record_delimiter'); ?> get('line_break_default'); ?>
get('info_test_output'); ?>
get('test_output'); ?>
get('info_notification_email'); ?>
get('notification_email'); ?>get('confirmed_immediately'); ?>