Advertisement
Guest User

admin_listloader_third_gen.php.patch

a guest
Sep 28th, 2011
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 179.02 KB | None | 0 0
  1. --- /usr/src/vicidial-trunk/www/vicidial/admin_listloader_third_gen.php 2011-09-21 20:14:09.000000000 -0500
  2. +++ ./admin_listloader_third_gen.php    2011-09-21 20:27:46.000000000 -0500
  3. @@ -1,2331 +1,2341 @@
  4. -<?php
  5. -# admin_listloader_third_gen.php - version 2.4
  6. -#  (based upon - new_listloader_superL.php script)
  7. -#
  8. -# Copyright (C) 2011  Matt Florell,Joe Johnson <vicidial@gmail.com>    LICENSE: AGPLv2
  9. -#
  10. -# ViciDial web-based lead loader from formatted file
  11. -#
  12. -# CHANGES
  13. -# 50602-1640 - First version created by Joe Johnson
  14. -# 51128-1108 - Removed PHP global vars requirement
  15. -# 60113-1603 - Fixed a few bugs in Excel import
  16. -# 60421-1624 - check GET/POST vars lines with isset to not trigger PHP NOTICES
  17. -# 60616-1240 - added listID override
  18. -# 60616-1604 - added gmt lookup for each lead
  19. -# 60619-1651 - Added variable filtering to eliminate SQL injection attack threat
  20. -# 60822-1121 - fixed for nonwritable directories
  21. -# 60906-1100 - added filter of non-digits in alt_phone field
  22. -# 61110-1222 - added new USA-Canada DST scheme and Brazil DST scheme
  23. -# 61128-1149 - added postal code GMT lookup and duplicate check options
  24. -# 70417-1059 - Fixed default phone_code bug
  25. -# 70510-1518 - Added campaign and system duplicate check and phonecode override
  26. -# 80428-0417 - UTF8 changes
  27. -# 80514-1030 - removed filesize limit and raised number of errors to be displayed
  28. -# 80713-0023 - added last_local_call_time field default of 2008-01-01
  29. -# 81011-2009 - a few bug fixes
  30. -# 90309-1831 - Added admin_log logging
  31. -# 90310-2128 - Added admin header
  32. -# 90508-0644 - Changed to PHP long tags
  33. -# 90522-0506 - Security fix
  34. -# 90721-1339 - Added rank and owner as vicidial_list fields
  35. -# 91112-0616 - Added title/alt-phone duplicate checking
  36. -# 100118-0543 - Added new Australian and New Zealand DST schemes (FSO-FSA and LSS-FSA)
  37. -# 100621-1026 - Added admin_web_directory variable
  38. -# 100630-1609 - Added a check for invalid ListIds and filtered out ' " ; ` \ from the field <mikec>
  39. -# 100705-1507 - Added custom fields to field chooser, only when liast_id_override is used and only with TXT and CSV file formats
  40. -# 100706-1250 - Forked script to create new script that will only load TXT(tab-
  41. -#              delimited files) and use a perl script to convert others to TXT
  42. -# 100707-1040 - Converted List Id Override and Phone Code Override to drop downs <mikec>
  43. -# 100707-1156 - Made it so you cannot submit with no lead file selected. Also fixed Start Over Link <mikec>
  44. -# 100712-1416 - Added entry_list_id field to vicidial_list to preserve link to custom fields if any
  45. -# 100728-0900 - Filtered uploaded filenames for unsupported characters
  46. -# 110424-0926 - Added option for time zone code in the owner field
  47. -# 110705-1947 - Added USACAN check for prefix and areacode
  48. -#
  49. -
  50. -$version = '2.4-41';
  51. -$build = '110705-1947';
  52. -
  53. -
  54. -require("dbconnect.php");
  55. -
  56. -
  57. -$US='_';
  58. -
  59. -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
  60. -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
  61. -$PHP_SELF=$_SERVER['PHP_SELF'];
  62. -$leadfile=$_FILES["leadfile"];
  63. -   $LF_orig = $_FILES['leadfile']['name'];
  64. -   $LF_path = $_FILES['leadfile']['tmp_name'];
  65. -if (isset($_GET["submit_file"]))           {$submit_file=$_GET["submit_file"];}
  66. -   elseif (isset($_POST["submit_file"]))   {$submit_file=$_POST["submit_file"];}
  67. -if (isset($_GET["submit"]))                {$submit=$_GET["submit"];}
  68. -   elseif (isset($_POST["submit"]))    {$submit=$_POST["submit"];}
  69. -if (isset($_GET["SUBMIT"]))                {$SUBMIT=$_GET["SUBMIT"];}
  70. -   elseif (isset($_POST["SUBMIT"]))    {$SUBMIT=$_POST["SUBMIT"];}
  71. -if (isset($_GET["leadfile_name"]))         {$leadfile_name=$_GET["leadfile_name"];}
  72. -   elseif (isset($_POST["leadfile_name"])) {$leadfile_name=$_POST["leadfile_name"];}
  73. -if (isset($_FILES["leadfile"]))                {$leadfile_name=$_FILES["leadfile"]['name'];}
  74. -if (isset($_GET["file_layout"]))               {$file_layout=$_GET["file_layout"];}
  75. -   elseif (isset($_POST["file_layout"]))       {$file_layout=$_POST["file_layout"];}
  76. -if (isset($_GET["OK_to_process"]))             {$OK_to_process=$_GET["OK_to_process"];}
  77. -   elseif (isset($_POST["OK_to_process"]))     {$OK_to_process=$_POST["OK_to_process"];}
  78. -if (isset($_GET["vendor_lead_code_field"]))                {$vendor_lead_code_field=$_GET["vendor_lead_code_field"];}
  79. -   elseif (isset($_POST["vendor_lead_code_field"]))    {$vendor_lead_code_field=$_POST["vendor_lead_code_field"];}
  80. -if (isset($_GET["source_id_field"]))           {$source_id_field=$_GET["source_id_field"];}
  81. -   elseif (isset($_POST["source_id_field"]))   {$source_id_field=$_POST["source_id_field"];}
  82. -if (isset($_GET["list_id_field"]))             {$list_id_field=$_GET["list_id_field"];}
  83. -   elseif (isset($_POST["list_id_field"]))     {$list_id_field=$_POST["list_id_field"];}
  84. -if (isset($_GET["phone_code_field"]))          {$phone_code_field=$_GET["phone_code_field"];}
  85. -   elseif (isset($_POST["phone_code_field"]))  {$phone_code_field=$_POST["phone_code_field"];}
  86. -if (isset($_GET["phone_number_field"]))                {$phone_number_field=$_GET["phone_number_field"];}
  87. -   elseif (isset($_POST["phone_number_field"]))    {$phone_number_field=$_POST["phone_number_field"];}
  88. -if (isset($_GET["title_field"]))               {$title_field=$_GET["title_field"];}
  89. -   elseif (isset($_POST["title_field"]))       {$title_field=$_POST["title_field"];}
  90. -if (isset($_GET["first_name_field"]))          {$first_name_field=$_GET["first_name_field"];}
  91. -   elseif (isset($_POST["first_name_field"]))  {$first_name_field=$_POST["first_name_field"];}
  92. -if (isset($_GET["middle_initial_field"]))          {$middle_initial_field=$_GET["middle_initial_field"];}
  93. -   elseif (isset($_POST["middle_initial_field"]))  {$middle_initial_field=$_POST["middle_initial_field"];}
  94. -if (isset($_GET["last_name_field"]))           {$last_name_field=$_GET["last_name_field"];}
  95. -   elseif (isset($_POST["last_name_field"]))   {$last_name_field=$_POST["last_name_field"];}
  96. -if (isset($_GET["address1_field"]))                {$address1_field=$_GET["address1_field"];}
  97. -   elseif (isset($_POST["address1_field"]))    {$address1_field=$_POST["address1_field"];}
  98. -if (isset($_GET["address2_field"]))                {$address2_field=$_GET["address2_field"];}
  99. -   elseif (isset($_POST["address2_field"]))    {$address2_field=$_POST["address2_field"];}
  100. -if (isset($_GET["address3_field"]))                {$address3_field=$_GET["address3_field"];}
  101. -   elseif (isset($_POST["address3_field"]))    {$address3_field=$_POST["address3_field"];}
  102. -if (isset($_GET["city_field"]))                    {$city_field=$_GET["city_field"];}
  103. -   elseif (isset($_POST["city_field"]))        {$city_field=$_POST["city_field"];}
  104. -if (isset($_GET["state_field"]))               {$state_field=$_GET["state_field"];}
  105. -   elseif (isset($_POST["state_field"]))       {$state_field=$_POST["state_field"];}
  106. -if (isset($_GET["province_field"]))                {$province_field=$_GET["province_field"];}
  107. -   elseif (isset($_POST["province_field"]))        {$province_field=$_POST["province_field"];}
  108. -if (isset($_GET["postal_code_field"]))             {$postal_code_field=$_GET["postal_code_field"];}
  109. -   elseif (isset($_POST["postal_code_field"]))     {$postal_code_field=$_POST["postal_code_field"];}
  110. -if (isset($_GET["country_code_field"]))                {$country_code_field=$_GET["country_code_field"];}
  111. -   elseif (isset($_POST["country_code_field"]))    {$country_code_field=$_POST["country_code_field"];}
  112. -if (isset($_GET["gender_field"]))              {$gender_field=$_GET["gender_field"];}
  113. -   elseif (isset($_POST["gender_field"]))      {$gender_field=$_POST["gender_field"];}
  114. -if (isset($_GET["date_of_birth_field"]))           {$date_of_birth_field=$_GET["date_of_birth_field"];}
  115. -   elseif (isset($_POST["date_of_birth_field"]))   {$date_of_birth_field=$_POST["date_of_birth_field"];}
  116. -if (isset($_GET["alt_phone_field"]))           {$alt_phone_field=$_GET["alt_phone_field"];}
  117. -   elseif (isset($_POST["alt_phone_field"]))   {$alt_phone_field=$_POST["alt_phone_field"];}
  118. -if (isset($_GET["email_field"]))               {$email_field=$_GET["email_field"];}
  119. -   elseif (isset($_POST["email_field"]))       {$email_field=$_POST["email_field"];}
  120. -if (isset($_GET["security_phrase_field"]))         {$security_phrase_field=$_GET["security_phrase_field"];}
  121. -   elseif (isset($_POST["security_phrase_field"])) {$security_phrase_field=$_POST["security_phrase_field"];}
  122. -if (isset($_GET["comments_field"]))                {$comments_field=$_GET["comments_field"];}
  123. -   elseif (isset($_POST["comments_field"]))    {$comments_field=$_POST["comments_field"];}
  124. -if (isset($_GET["rank_field"]))                    {$rank_field=$_GET["rank_field"];}
  125. -   elseif (isset($_POST["rank_field"]))        {$rank_field=$_POST["rank_field"];}
  126. -if (isset($_GET["owner_field"]))               {$owner_field=$_GET["owner_field"];}
  127. -   elseif (isset($_POST["owner_field"]))       {$owner_field=$_POST["owner_field"];}
  128. -if (isset($_GET["list_id_override"]))          {$list_id_override=$_GET["list_id_override"];}
  129. -   elseif (isset($_POST["list_id_override"]))  {$list_id_override=$_POST["list_id_override"];}
  130. -   $list_id_override = (preg_replace("/\D/","",$list_id_override));
  131. -if (isset($_GET["lead_file"]))                 {$lead_file=$_GET["lead_file"];}
  132. -   elseif (isset($_POST["lead_file"]))         {$lead_file=$_POST["lead_file"];}
  133. -if (isset($_GET["dupcheck"]))              {$dupcheck=$_GET["dupcheck"];}
  134. -   elseif (isset($_POST["dupcheck"]))      {$dupcheck=$_POST["dupcheck"];}
  135. -if (isset($_GET["postalgmt"]))             {$postalgmt=$_GET["postalgmt"];}
  136. -   elseif (isset($_POST["postalgmt"]))     {$postalgmt=$_POST["postalgmt"];}
  137. -if (isset($_GET["phone_code_override"]))           {$phone_code_override=$_GET["phone_code_override"];}
  138. -   elseif (isset($_POST["phone_code_override"]))   {$phone_code_override=$_POST["phone_code_override"];}
  139. -   $phone_code_override = (preg_replace("/\D/","",$phone_code_override));
  140. -if (isset($_GET["DB"]))                    {$DB=$_GET["DB"];}
  141. -   elseif (isset($_POST["DB"]))        {$DB=$_POST["DB"];}
  142. -if (isset($_GET["usacan_check"]))          {$usacan_check=$_GET["usacan_check"];}
  143. -   elseif (isset($_POST["usacan_check"]))  {$usacan_check=$_POST["usacan_check"];}
  144. -
  145. -
  146. -# if the didnt select an over ride wipe out in_file
  147. -if ( $list_id_override == "in_file" ) { $list_id_override = ""; }
  148. -if ( $phone_code_override == "in_file" ) { $phone_code_override = ""; }
  149. -
  150. -# $country_field=$_GET["country_field"];                   if (!$country_field) {$country_field=$_POST["country_field"];}
  151. -
  152. -### REGEX to prevent weird characters from ending up in the fields
  153. -$field_regx = "['\"`\\;]";
  154. -
  155. -$vicidial_list_fields = '|lead_id|vendor_lead_code|source_id|list_id|gmt_offset_now|called_since_last_reset|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|called_count|last_local_call_time|rank|owner|entry_list_id|';
  156. -
  157. -#############################################
  158. -##### START SYSTEM_SETTINGS LOOKUP #####
  159. -$stmt = "SELECT use_non_latin,admin_web_directory,custom_fields_enabled FROM system_settings;";
  160. -$rslt=mysql_query($stmt, $link);
  161. -if ($DB) {echo "$stmt\n";}
  162. -$qm_conf_ct = mysql_num_rows($rslt);
  163. -if ($qm_conf_ct > 0)
  164. -   {
  165. -   $row=mysql_fetch_row($rslt);
  166. -   $non_latin =                $row[0];
  167. -   $admin_web_directory =      $row[1];
  168. -   $custom_fields_enabled =    $row[2];
  169. -   }
  170. -##### END SETTINGS LOOKUP #####
  171. -###########################################
  172. -
  173. -if ($non_latin < 1)
  174. -   {
  175. -   $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER);
  176. -   $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW);
  177. -   $list_id_override = ereg_replace("[^0-9]","",$list_id_override);
  178. -   }
  179. -else
  180. -   {
  181. -   $PHP_AUTH_PW = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_PW);
  182. -   $PHP_AUTH_USER = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_USER);
  183. -   }
  184. -
  185. -$STARTtime = date("U");
  186. -$TODAY = date("Y-m-d");
  187. -$NOW_TIME = date("Y-m-d H:i:s");
  188. -$FILE_datetime = $STARTtime;
  189. -
  190. -$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7;";
  191. -if ($DB) {echo "|$stmt|\n";}
  192. -if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
  193. -$rslt=mysql_query($stmt, $link);
  194. -$row=mysql_fetch_row($rslt);
  195. -$auth=$row[0];
  196. -
  197. -if ($WeBRooTWritablE > 0) {$fp = fopen ("./project_auth_entries.txt", "a");}
  198. -$date = date("r");
  199. -$ip = getenv("REMOTE_ADDR");
  200. -$browser = getenv("HTTP_USER_AGENT");
  201. -
  202. -if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth))
  203. -   {
  204. -    Header("WWW-Authenticate: Basic realm=\"VICIDIAL-LEAD-LOADER\"");
  205. -    Header("HTTP/1.0 401 Unauthorized");
  206. -    echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n";
  207. -    exit;
  208. -   }
  209. -else
  210. -   {
  211. -   header ("Content-type: text/html; charset=utf-8");
  212. -   header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
  213. -   header ("Pragma: no-cache");                          // HTTP/1.0
  214. -
  215. -   if($auth>0)
  216. -       {
  217. -       $office_no=strtoupper($PHP_AUTH_USER);
  218. -       $password=strtoupper($PHP_AUTH_PW);
  219. -           $stmt="SELECT load_leads from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'";
  220. -           $rslt=mysql_query($stmt, $link);
  221. -           $row=mysql_fetch_row($rslt);
  222. -           $LOGload_leads              =$row[0];
  223. -
  224. -       if ($LOGload_leads < 1)
  225. -           {
  226. -           echo "You do not have permissions to load leads\n";
  227. -           exit;
  228. -           }
  229. -       if ($WeBRooTWritablE > 0)
  230. -           {
  231. -           fwrite ($fp, "LIST_LOAD|GOOD|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|$LOGfullname|\n");
  232. -           fclose($fp);
  233. -           }
  234. -       }
  235. -   else
  236. -       {
  237. -       if ($WeBRooTWritablE > 0)
  238. -           {
  239. -           fwrite ($fp, "LIST_LOAD|FAIL|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|\n");
  240. -           fclose($fp);
  241. -           }
  242. -       }
  243. -   }
  244. -
  245. -
  246. -$script_name = getenv("SCRIPT_NAME");
  247. -$server_name = getenv("SERVER_NAME");
  248. -$server_port = getenv("SERVER_PORT");
  249. -if (eregi("443",$server_port)) {$HTTPprotocol = 'https://';}
  250. -   else {$HTTPprotocol = 'http://';}
  251. -$admDIR = "$HTTPprotocol$server_name$script_name";
  252. -$admDIR = eregi_replace('admin_listloader_third_gen.php','',$admDIR);
  253. -$admSCR = 'admin.php';
  254. -$NWB = " &nbsp; <a href=\"javascript:openNewWindow('$admDIR$admSCR?ADD=99999";
  255. -$NWE = "')\"><IMG SRC=\"help.gif\" WIDTH=20 HEIGHT=20 BORDER=0 ALT=\"HELP\" ALIGN=TOP></A>";
  256. -
  257. -$secX = date("U");
  258. -$hour = date("H");
  259. -$min = date("i");
  260. -$sec = date("s");
  261. -$mon = date("m");
  262. -$mday = date("d");
  263. -$year = date("Y");
  264. -$isdst = date("I");
  265. -$Shour = date("H");
  266. -$Smin = date("i");
  267. -$Ssec = date("s");
  268. -$Smon = date("m");
  269. -$Smday = date("d");
  270. -$Syear = date("Y");
  271. -$pulldate0 = "$year-$mon-$mday $hour:$min:$sec";
  272. -$inSD = $pulldate0;
  273. -$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
  274. -
  275. -### Grab Server GMT value from the database
  276. -$stmt="SELECT local_gmt FROM servers where server_ip = '$server_ip';";
  277. -$rslt=mysql_query($stmt, $link);
  278. -$gmt_recs = mysql_num_rows($rslt);
  279. -if ($gmt_recs > 0)
  280. -   {
  281. -   $row=mysql_fetch_row($rslt);
  282. -   $DBSERVER_GMT       =       "$row[0]";
  283. -   if (strlen($DBSERVER_GMT)>0)    {$SERVER_GMT = $DBSERVER_GMT;}
  284. -   if ($isdst) {$SERVER_GMT++;}
  285. -   }
  286. -else
  287. -   {
  288. -   $SERVER_GMT = date("O");
  289. -   $SERVER_GMT = eregi_replace("\+","",$SERVER_GMT);
  290. -   $SERVER_GMT = ($SERVER_GMT + 0);
  291. -   $SERVER_GMT = ($SERVER_GMT / 100);
  292. -   }
  293. -
  294. -$LOCAL_GMT_OFF = $SERVER_GMT;
  295. -$LOCAL_GMT_OFF_STD = $SERVER_GMT;
  296. -
  297. -#if ($DB) {print "SEED TIME  $secX      :   $year-$mon-$mday $hour:$min:$sec  LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";}
  298. -
  299. -
  300. -echo "<html>\n";
  301. -echo "<head>\n";
  302. -echo "<!-- VERSION: $version     BUILD: $build -->\n";
  303. -echo "<!-- SEED TIME  $secX:   $year-$mon-$mday $hour:$min:$sec  LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF  DST: $isdst -->\n";
  304. -
  305. -function macfontfix($fontsize)
  306. -   {
  307. -   $browser = getenv("HTTP_USER_AGENT");
  308. -   $pctype = explode("(", $browser);
  309. -   if (ereg("Mac",$pctype[1]))
  310. -       {
  311. -       /* Browser is a Mac.  If not Netscape 6, raise fonts */
  312. -       $blownbrowser = explode('/', $browser);
  313. -       $ver = explode(' ', $blownbrowser[1]);
  314. -       $ver = $ver[0];
  315. -       if ($ver >= 5.0) return $fontsize; else return ($fontsize+2);
  316. -       }
  317. -   else return $fontsize;  /* Browser is not a Mac - don't touch fonts */
  318. -   }
  319. -
  320. -echo "<style type=\"text/css\">\n
  321. -<!--\n
  322. -.title {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(18)."pt}\n
  323. -.standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt}\n
  324. -.small_standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(8)."pt}\n
  325. -.tiny_standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(6)."pt}\n
  326. -.standard_bold {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold}\n
  327. -.standard_header {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(14)."pt; font-weight: bold}\n
  328. -.standard_bold_highlight {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold; color: white; BACKGROUND-COLOR: black}\n
  329. -.standard_bold_blue_highlight {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; BACKGROUND-COLOR: blue}\n
  330. -A.employee_standard {  font-family: garamond, sans-serif; font-size: ".macfontfix(10)."pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none}\n
  331. -.employee_standard {  font-family: garamond, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold}\n
  332. -.employee_title {  font-family: Garamond, sans-serif; font-size: ".macfontfix(14)."pt; font-weight: bold}\n
  333. -\\\\-->\n
  334. -</style>\n";
  335. -
  336. -?>
  337. -
  338. -
  339. -<script language="JavaScript1.2">
  340. -function openNewWindow(url)
  341. -   {
  342. -   window.open (url,"",'width=700,height=300,scrollbars=yes,menubar=yes,address=yes');
  343. -   }
  344. -function ShowProgress(good, bad, total, dup, inv, post)
  345. -   {
  346. -   parent.lead_count.document.open();
  347. -   parent.lead_count.document.write('<html><body><table border=0 width=200 cellpadding=10 cellspacing=0 align=center valign=top><tr bgcolor="#000000"><th colspan=2><font face="arial, helvetica" size=3 color=white>Current file status:</font></th></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Good:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+good+'</B></font></td></tr><tr bgcolor="#990000"><td align=right><font face="arial, helvetica" size=2 color=white><B>Bad:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+bad+'</B></font></td></tr><tr bgcolor="#000099"><td align=right><font face="arial, helvetica" size=2 color=white><B>Total:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+total+'</B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B> &nbsp; </B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B> &nbsp; </B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Duplicate:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+dup+'</B></font></td></tr></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Invalid:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+inv+'</B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Postal Match:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+post+'</B></font></td></tr></table><body></html>');
  348. -   parent.lead_count.document.close();
  349. -   }
  350. -function ParseFileName()
  351. -   {
  352. -   if (!document.forms[0].OK_to_process)
  353. -       {  
  354. -       var endstr=document.forms[0].leadfile.value.lastIndexOf('\\');
  355. -       if (endstr>-1)
  356. -           {
  357. -           endstr++;
  358. -           var filename=document.forms[0].leadfile.value.substring(endstr);
  359. -           document.forms[0].leadfile_name.value=filename;
  360. -           }
  361. -       }
  362. -   }
  363. -
  364. -</script>
  365. -<title>ADMINISTRATION: Lead Loader</title>
  366. -</head>
  367. -<BODY BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>
  368. -
  369. -<?php
  370. -$short_header=1;
  371. -
  372. -require("admin_header.php");
  373. -
  374. -echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
  375. -
  376. -if ( (!$OK_to_process) or ( ($leadfile) and ($file_layout!="standard") ) )
  377. -   {
  378. -   ?>
  379. -   <form action=<?php echo $PHP_SELF ?> method=post onSubmit="ParseFileName()" enctype="multipart/form-data">
  380. -   <input type=hidden name='leadfile_name' value="<?php echo $leadfile_name ?>">
  381. -   <input type=hidden name='DB' value="<?php echo $DB ?>">
  382. -   <?php
  383. -   if ($file_layout!="custom")
  384. -       {
  385. -       ?>
  386. -       <table align=center width="700" border=0 cellpadding=5 cellspacing=0 bgcolor=#D9E6FE>
  387. -         <tr>
  388. -           <td align=right width="35%"><B><font face="arial, helvetica" size=2>Load leads from this file:</font></B></td>
  389. -           <td align=left width="65%"><input type=file name="leadfile" value="<?php echo $leadfile ?>"> <?php echo "$NWB#vicidial_list_loader$NWE"; ?></td>
  390. -         </tr>
  391. -         <tr>
  392. -           <td align=right width="25%"><font face="arial, helvetica" size=2>List ID Override: </font></td>
  393. -           <td align=left width="75%"><font face="arial, helvetica" size=1>
  394. -           <select name='list_id_override'>
  395. -           <option value='in_file' selected='yes'>Load from Lead File</option>
  396. -           <?php
  397. -           $stmt="SELECT list_id, list_name from vicidial_lists order by list_id;";
  398. -           $rslt=mysql_query($stmt, $link);
  399. -           $num_rows = mysql_num_rows($rslt);
  400. -
  401. -           $count=0;
  402. -           while ( $num_rows > $count )
  403. -               {
  404. -               $row = mysql_fetch_row($rslt);
  405. -               echo "<option value=\'$row[0]\'>$row[0] - $row[1]</option>\n";
  406. -               $count++;
  407. -               }
  408. -           ?>
  409. -           </select>
  410. -           </font></td>
  411. -         </tr>
  412. -         <tr>
  413. -           <td align=right width="25%"><font face="arial, helvetica" size=2>Phone Code Override: </font></td>
  414. -           <td align=left width="75%"><font face="arial, helvetica" size=1>
  415. -           <select name='phone_code_override'>
  416. -                        <option value='in_file' selected='yes'>Load from Lead File</option>
  417. -           <?php
  418. -           $stmt="select distinct country_code, country from vicidial_phone_codes;";
  419. -           $rslt=mysql_query($stmt, $link);
  420. -           $num_rows = mysql_num_rows($rslt);
  421. -          
  422. -           $count=0;
  423. -                   while ( $num_rows > $count )
  424. -               {
  425. -               $row = mysql_fetch_row($rslt);
  426. -               echo "<option value=\'$row[0]\'>$row[0] - $row[1]</option>\n";
  427. -               $count++;
  428. -               }
  429. -           ?>
  430. -           </select>
  431. -           </font></td>
  432. -         </tr>
  433. -         <tr>
  434. -           <td align=right><B><font face="arial, helvetica" size=2>File layout to use:</font></B></td>
  435. -           <td align=left><font face="arial, helvetica" size=2><input type=radio name="file_layout" value="standard" checked>Standard Format&nbsp;&nbsp;&nbsp;&nbsp;<input type=radio name="file_layout" value="custom">Custom layout</td>
  436. -         </tr>
  437. -         <tr>
  438. -           <td align=right width="25%"><font face="arial, helvetica" size=2>Lead Duplicate Check: </font></td>
  439. -           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=dupcheck>
  440. -           <option selected value="NONE">NO DUPLICATE CHECK</option>
  441. -           <option value="DUPLIST">CHECK FOR DUPLICATES BY PHONE IN LIST ID</option>
  442. -           <option value="DUPCAMP">CHECK FOR DUPLICATES BY PHONE IN ALL CAMPAIGN LISTS</option>
  443. -           <option value="DUPSYS">CHECK FOR DUPLICATES BY PHONE IN ENTIRE SYSTEM</option>
  444. -           <option value="DUPTITLEALTPHONELIST">CHECK FOR DUPLICATES BY TITLE/ALT-PHONE IN LIST ID</option>
  445. -           <option value="DUPTITLEALTPHONESYS">CHECK FOR DUPLICATES BY TITLE/ALT-PHONE IN ENTIRE SYSTEM</option>
  446. -           </select></td>
  447. -         </tr>
  448. -         <tr>
  449. -           <td align=right width="25%"><font face="arial, helvetica" size=2>USA-Canada Check: </font></td>
  450. -           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=usacan_check>
  451. -           <option selected value="NONE">NO USACAN VALID CHECK</option>
  452. -           <option value="PREFIX">CHECK FOR VALID PREFIX</option>
  453. -           <option value="AREACODE">CHECK FOR VALID AREACODE</option>
  454. -           <option value="PREFIX_AREACODE">CHECK FOR VALID PREFIX and AREACODE</option>
  455. -           </select></td>
  456. -         </tr>
  457. -         <tr>
  458. -           <td align=right width="25%"><font face="arial, helvetica" size=2>Lead Time Zone Lookup: </font></td>
  459. -           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=postalgmt><option selected value="AREA">COUNTRY CODE AND AREA CODE ONLY</option><option value="POSTAL">POSTAL CODE FIRST</option><option value="TZCODE">OWNER TIME ZONE CODE FIRST</option></select></td>
  460. -         </tr>
  461. -       <tr>
  462. -           <td align=center colspan=2><input type=submit value="SUBMIT" name='submit_file'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button onClick="javascript:document.location='admin_listloader_third_gen.php'" value="START OVER" name='reload_page'></td>
  463. -         </tr>
  464. -         <tr><td align=left><font size=1> &nbsp; &nbsp; &nbsp; &nbsp; <a href="admin.php?ADD=100" target="_parent">BACK TO ADMIN</a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="./new_listloader_superL.php">Old Lead Loader</a> &nbsp; &nbsp; </font></td><td align=right><font size=1>LIST LOADER 3rd Gen- &nbsp; &nbsp; VERSION: <?php echo $version ?> &nbsp; &nbsp; BUILD: <?php echo $build ?> &nbsp; &nbsp; </td></tr>
  465. -       </table>
  466. -       <?php
  467. -
  468. -       }
  469. -   }
  470. -else
  471. -   {
  472. -   ?>
  473. -   <table align=center width="700" border=0 cellpadding=5 cellspacing=0 bgcolor=#D9E6FE>
  474. -   <tr>
  475. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead file:</font></B></td>
  476. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $leadfile_name ?></font></td>
  477. -   </tr>
  478. -   <tr>
  479. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>List ID Override:</font></B></td>
  480. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $list_id_override ?></font></td>
  481. -   </tr>
  482. -   <tr>
  483. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Phone Code Override:</font></B></td>
  484. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $phone_code_override ?></font></td>
  485. -   </tr>
  486. -   <tr>
  487. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>USA-Canada Check:</font></B></td>
  488. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $usacan_check ?></font></td>
  489. -   </tr>
  490. -   <tr>
  491. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead Duplicate Check:</font></B></td>
  492. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $dupcheck ?></font></td>
  493. -   </tr>
  494. -   <tr>
  495. -   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead Time Zone Lookup:</font></B></td>
  496. -   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $postalgmt ?></font></td>
  497. -   </tr>
  498. -
  499. -   <tr>
  500. -   <td align=center colspan=2><B><font face="arial, helvetica" size=2>
  501. -   <form action=<?php echo $PHP_SELF ?> method=post onSubmit="ParseFileName()" enctype="multipart/form-data">
  502. -   <input type=hidden name='leadfile_name' value="<?php echo $leadfile_name ?>">
  503. -   <input type=hidden name='DB' value="<?php echo $DB ?>">
  504. -   <a href="admin_listloader_third_gen.php">Load Another Lead File</a> &nbsp; &nbsp; &nbsp; &nbsp;</font></B> <font size=1>VERSION: <?php echo $version ?> &nbsp; &nbsp; BUILD: <?php echo $build ?>
  505. -   </font></td>
  506. -   </tr></table>
  507. -   <BR><BR><BR><BR>
  508. -   <?php
  509. -   }
  510. -
  511. -
  512. -
  513. -##### BEGIN custom fields submission #####
  514. -if ($OK_to_process)
  515. -   {
  516. -   print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true;document.forms[0].list_id_override.disabled=true;document.forms[0].phone_code_override.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script>";
  517. -   flush();
  518. -   $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  519. -
  520. -   $file=fopen("$lead_file", "r");
  521. -   if ($WeBRooTWritablE > 0)
  522. -       {
  523. -       $stmt_file=fopen("listloader_stmts.txt", "w");
  524. -       }
  525. -   $buffer=fgets($file, 4096);
  526. -   $tab_count=substr_count($buffer, "\t");
  527. -   $pipe_count=substr_count($buffer, "|");
  528. -
  529. -   if ($tab_count>$pipe_count) {$delimiter="\t";  $delim_name="tab";} else {$delimiter="|";  $delim_name="pipe";}
  530. -   $field_check=explode($delimiter, $buffer);
  531. -
  532. -   if (count($field_check)>=2)
  533. -       {
  534. -       flush();
  535. -       $file=fopen("$lead_file", "r");
  536. -       print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing file...\n";
  537. -
  538. -       if (strlen($list_id_override)>0)
  539. -           {
  540. -           print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  541. -           }
  542. -
  543. -       if (strlen($phone_code_override)>0)
  544. -           {
  545. -           print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>";
  546. -           }
  547. -
  548. -       if ($custom_fields_enabled > 0)
  549. -           {
  550. -           $tablecount_to_print=0;
  551. -           $fieldscount_to_print=0;
  552. -           $fields_to_print=0;
  553. -
  554. -           $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";";
  555. -           if ($DB>0) {echo "$stmt\n";}
  556. -           $rslt=mysql_query($stmt, $link);
  557. -           $tablecount_to_print = mysql_num_rows($rslt);
  558. -
  559. -           if ($tablecount_to_print > 0)
  560. -               {
  561. -               $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';";
  562. -               if ($DB>0) {echo "$stmt\n";}
  563. -               $rslt=mysql_query($stmt, $link);
  564. -               $fieldscount_to_print = mysql_num_rows($rslt);
  565. -
  566. -               if ($fieldscount_to_print > 0)
  567. -                   {
  568. -                   $stmt="SELECT field_label,field_type from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;";
  569. -                   if ($DB>0) {echo "$stmt\n";}
  570. -                   $rslt=mysql_query($stmt, $link);
  571. -                   $fields_to_print = mysql_num_rows($rslt);
  572. -                   $fields_list='';
  573. -                   $o=0;
  574. -                   while ($fields_to_print > $o)
  575. -                       {
  576. -                       $rowx=mysql_fetch_row($rslt);
  577. -                       $A_field_label[$o] =    $rowx[0];
  578. -                       $A_field_type[$o] =     $rowx[1];
  579. -                       $A_field_value[$o] =    '';
  580. -                       $o++;
  581. -                       }
  582. -                   }
  583. -               }
  584. -           }
  585. -
  586. -       while (!feof($file))
  587. -           {
  588. -           $record++;
  589. -           $buffer=rtrim(fgets($file, 4096));
  590. -           $buffer=stripslashes($buffer);
  591. -
  592. -           if (strlen($buffer)>0)
  593. -               {
  594. -               $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  595. -
  596. -               $pulldate=date("Y-m-d H:i:s");
  597. -               $entry_date =           "$pulldate";
  598. -               $modify_date =          "";
  599. -               $status =               "NEW";
  600. -               $user ="";
  601. -               $vendor_lead_code =     $row[$vendor_lead_code_field];
  602. -               $source_code =          $row[$source_id_field];
  603. -               $source_id=$source_code;
  604. -               $list_id =              $row[$list_id_field];
  605. -               $gmt_offset =           '0';
  606. -               $called_since_last_reset='N';
  607. -               $phone_code =           eregi_replace("[^0-9]", "", $row[$phone_code_field]);
  608. -               $phone_number =         eregi_replace("[^0-9]", "", $row[$phone_number_field]);
  609. -               $title =                $row[$title_field];
  610. -               $first_name =           $row[$first_name_field];
  611. -               $middle_initial =       $row[$middle_initial_field];
  612. -               $last_name =            $row[$last_name_field];
  613. -               $address1 =             $row[$address1_field];
  614. -               $address2 =             $row[$address2_field];
  615. -               $address3 =             $row[$address3_field];
  616. -               $city =$row[$city_field];
  617. -               $state =                $row[$state_field];
  618. -               $province =             $row[$province_field];
  619. -               $postal_code =          $row[$postal_code_field];
  620. -               $country_code =         $row[$country_code_field];
  621. -               $gender =               $row[$gender_field];
  622. -               $date_of_birth =        $row[$date_of_birth_field];
  623. -               $alt_phone =            eregi_replace("[^0-9]", "", $row[$alt_phone_field]);
  624. -               $email =                $row[$email_field];
  625. -               $security_phrase =      $row[$security_phrase_field];
  626. -               $comments =             trim($row[$comments_field]);
  627. -               $rank =                 $row[$rank_field];
  628. -               $owner =                $row[$owner_field];
  629. -              
  630. -               # replace ' " ` \ ; with nothing
  631. -               $vendor_lead_code =     eregi_replace($field_regx, "", $vendor_lead_code);
  632. -               $source_code =          eregi_replace($field_regx, "", $source_code);
  633. -               $source_id =            eregi_replace($field_regx, "", $source_id);
  634. -               $list_id =              eregi_replace($field_regx, "", $list_id);
  635. -               $phone_code =           eregi_replace($field_regx, "", $phone_code);
  636. -               $phone_number =         eregi_replace($field_regx, "", $phone_number);
  637. -               $title =                eregi_replace($field_regx, "", $title);
  638. -               $first_name =           eregi_replace($field_regx, "", $first_name);
  639. -               $middle_initial =       eregi_replace($field_regx, "", $middle_initial);
  640. -               $last_name =            eregi_replace($field_regx, "", $last_name);
  641. -               $address1 =             eregi_replace($field_regx, "", $address1);
  642. -               $address2 =             eregi_replace($field_regx, "", $address2);
  643. -               $address3 =             eregi_replace($field_regx, "", $address3);
  644. -               $city =                 eregi_replace($field_regx, "", $city);
  645. -               $state =                eregi_replace($field_regx, "", $state);
  646. -               $province =             eregi_replace($field_regx, "", $province);
  647. -               $postal_code =          eregi_replace($field_regx, "", $postal_code);
  648. -               $country_code =         eregi_replace($field_regx, "", $country_code);
  649. -               $gender =               eregi_replace($field_regx, "", $gender);
  650. -               $date_of_birth =        eregi_replace($field_regx, "", $date_of_birth);
  651. -               $alt_phone =            eregi_replace($field_regx, "", $alt_phone);
  652. -               $email =                eregi_replace($field_regx, "", $email);
  653. -               $security_phrase =      eregi_replace($field_regx, "", $security_phrase);
  654. -               $comments =             eregi_replace($field_regx, "", $comments);
  655. -               $rank =                 eregi_replace($field_regx, "", $rank);
  656. -               $owner =                eregi_replace($field_regx, "", $owner);
  657. -              
  658. -               $USarea =           substr($phone_number, 0, 3);
  659. -
  660. -               if (strlen($list_id_override)>0)
  661. -                   {
  662. -               #   print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  663. -                   $list_id = $list_id_override;
  664. -                   }
  665. -               if (strlen($phone_code_override)>0)
  666. -                   {
  667. -                   $phone_code = $phone_code_override;
  668. -                   }
  669. -
  670. -               ##### BEGIN custom fields columns list ###
  671. -               $custom_SQL='';
  672. -               if ($custom_fields_enabled > 0)
  673. -                   {
  674. -                   if ($tablecount_to_print > 0)
  675. -                       {
  676. -                       if ($fieldscount_to_print > 0)
  677. -                           {
  678. -                           $o=0;
  679. -                           while ($fields_to_print > $o)
  680. -                               {
  681. -                               $A_field_value[$o] =    '';
  682. -                               $field_name_id = $A_field_label[$o] . "_field";
  683. -
  684. -                           #   if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";}
  685. -
  686. -                               if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') )
  687. -                                   {
  688. -                                   if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields))
  689. -                                       {
  690. -                                       if (isset($_GET["$field_name_id"]))             {$form_field_value=$_GET["$field_name_id"];}
  691. -                                           elseif (isset($_POST["$field_name_id"]))    {$form_field_value=$_POST["$field_name_id"];}
  692. -
  693. -                                       if ($form_field_value >= 0)
  694. -                                           {
  695. -                                           $A_field_value[$o] =    $row[$form_field_value];
  696. -                                           # replace ' " ` \ ; with nothing
  697. -                                           $A_field_value[$o] =    eregi_replace($field_regx, "", $A_field_value[$o]);
  698. -
  699. -                                           $custom_SQL .= "$A_field_label[$o]='$A_field_value[$o]',";
  700. -                                           }
  701. -                                       }
  702. -                                   }
  703. -                               $o++;
  704. -                               }
  705. -                           }
  706. -                       }
  707. -                   }
  708. -               ##### END custom fields columns list ###
  709. -
  710. -               $custom_SQL = preg_replace("/,$/","",$custom_SQL);
  711. -
  712. -
  713. -               ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign #####
  714. -               if (eregi("DUPCAMP",$dupcheck))
  715. -                   {
  716. -                   $dup_lead=0;
  717. -                   $dup_lists='';
  718. -                   $stmt="select campaign_id from vicidial_lists where list_id='$list_id';";
  719. -                   $rslt=mysql_query($stmt, $link);
  720. -                   $ci_recs = mysql_num_rows($rslt);
  721. -                   if ($ci_recs > 0)
  722. -                       {
  723. -                       $row=mysql_fetch_row($rslt);
  724. -                       $dup_camp =         $row[0];
  725. -
  726. -                       $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';";
  727. -                       $rslt=mysql_query($stmt, $link);
  728. -                       $li_recs = mysql_num_rows($rslt);
  729. -                       if ($li_recs > 0)
  730. -                           {
  731. -                           $L=0;
  732. -                           while ($li_recs > $L)
  733. -                               {
  734. -                               $row=mysql_fetch_row($rslt);
  735. -                               $dup_lists .=   "'$row[0]',";
  736. -                               $L++;
  737. -                               }
  738. -                           $dup_lists = eregi_replace(",$",'',$dup_lists);
  739. -
  740. -                           $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;";
  741. -                           $rslt=mysql_query($stmt, $link);
  742. -                           $pc_recs = mysql_num_rows($rslt);
  743. -                           if ($pc_recs > 0)
  744. -                               {
  745. -                               $dup_lead=1;
  746. -                               $row=mysql_fetch_row($rslt);
  747. -                               $dup_lead_list =    $row[0];
  748. -                               }
  749. -                           if ($dup_lead < 1)
  750. -                               {
  751. -                               if (eregi("$phone_number$US$list_id",$phone_list))
  752. -                                   {$dup_lead++; $dup++;}
  753. -                               }
  754. -                           }
  755. -                       }
  756. -                   }
  757. -
  758. -               ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  759. -               if (eregi("DUPSYS",$dupcheck))
  760. -                   {
  761. -                   $dup_lead=0;
  762. -                   $stmt="select list_id from vicidial_list where phone_number='$phone_number';";
  763. -                   $rslt=mysql_query($stmt, $link);
  764. -                   $pc_recs = mysql_num_rows($rslt);
  765. -                   if ($pc_recs > 0)
  766. -                       {
  767. -                       $dup_lead=1;
  768. -                       $row=mysql_fetch_row($rslt);
  769. -                       $dup_lead_list =    $row[0];
  770. -                       }
  771. -                   if ($dup_lead < 1)
  772. -                       {
  773. -                       if (eregi("$phone_number$US$list_id",$phone_list))
  774. -                           {$dup_lead++; $dup++;}
  775. -                       }
  776. -                   }
  777. -
  778. -               ##### Check for duplicate phone numbers in vicidial_list table for one list_id #####
  779. -               if (eregi("DUPLIST",$dupcheck))
  780. -                   {
  781. -                   $dup_lead=0;
  782. -                   $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';";
  783. -                   $rslt=mysql_query($stmt, $link);
  784. -                   $pc_recs = mysql_num_rows($rslt);
  785. -                   if ($pc_recs > 0)
  786. -                       {
  787. -                       $row=mysql_fetch_row($rslt);
  788. -                       $dup_lead =         $row[0];
  789. -                       $dup_lead_list =    $list_id;
  790. -                       }
  791. -                   if ($dup_lead < 1)
  792. -                       {
  793. -                       if (eregi("$phone_number$US$list_id",$phone_list))
  794. -                           {$dup_lead++; $dup++;}
  795. -                       }
  796. -                   }
  797. -
  798. -               ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id #####
  799. -               if (eregi("DUPTITLEALTPHONELIST",$dupcheck))
  800. -                   {
  801. -                   $dup_lead=0;
  802. -                   $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';";
  803. -                   $rslt=mysql_query($stmt, $link);
  804. -                   $pc_recs = mysql_num_rows($rslt);
  805. -                   if ($pc_recs > 0)
  806. -                       {
  807. -                       $row=mysql_fetch_row($rslt);
  808. -                       $dup_lead =         $row[0];
  809. -                       $dup_lead_list =    $list_id;
  810. -                       }
  811. -                   if ($dup_lead < 1)
  812. -                       {
  813. -                       if (eregi("$alt_phone$title$US$list_id",$phone_list))
  814. -                           {$dup_lead++; $dup++;}
  815. -                       }
  816. -                   }
  817. -
  818. -               ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  819. -               if (eregi("DUPTITLEALTPHONESYS",$dupcheck))
  820. -                   {
  821. -                   $dup_lead=0;
  822. -                   $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';";
  823. -                   $rslt=mysql_query($stmt, $link);
  824. -                   $pc_recs = mysql_num_rows($rslt);
  825. -                   if ($pc_recs > 0)
  826. -                       {
  827. -                       $dup_lead=1;
  828. -                       $row=mysql_fetch_row($rslt);
  829. -                       $dup_lead_list =    $row[0];
  830. -                       }
  831. -                   if ($dup_lead < 1)
  832. -                       {
  833. -                       if (eregi("$alt_phone$title$US$list_id",$phone_list))
  834. -                           {$dup_lead++; $dup++;}
  835. -                       }
  836. -                   }
  837. -
  838. -               $valid_number=1;
  839. -               if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) )
  840. -                   {
  841. -                   $valid_number=0;
  842. -                   $invalid_reason = "INVALID PHONE NUMBER LENGTH";
  843. -                   }
  844. -               if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) )
  845. -                   {
  846. -                   $USprefix =     substr($phone_number, 3, 1);
  847. -                   if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";}
  848. -                   if ($USprefix < 2)
  849. -                       {
  850. -                       $valid_number=0;
  851. -                       $invalid_reason = "INVALID PHONE NUMBER PREFIX";
  852. -                       }
  853. -                   }
  854. -               if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) )
  855. -                   {
  856. -                   $phone_areacode = substr($phone_number, 0, 3);
  857. -                   $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';";
  858. -                   if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";}
  859. -                   $rslt=mysql_query($stmt, $link);
  860. -                   $row=mysql_fetch_row($rslt);
  861. -                   $valid_number=$row[0];
  862. -                   if ($valid_number < 1)
  863. -                       {
  864. -                       $invalid_reason = "INVALID PHONE NUMBER AREACODE";
  865. -                       }
  866. -                   }
  867. -
  868. -               if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 ))
  869. -                   {
  870. -                   if (strlen($phone_code)<1) {$phone_code = '1';}
  871. -
  872. -                   if (eregi("TITLEALTPHONE",$dupcheck))
  873. -                       {$phone_list .= "$alt_phone$title$US$list_id|";}
  874. -                   else
  875. -                       {$phone_list .= "$phone_number$US$list_id|";}
  876. -
  877. -                   $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
  878. -
  879. -                   if (strlen($custom_SQL)>3)
  880. -                       {
  881. -                       $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','$list_id');";
  882. -                       $rslt=mysql_query($stmtZ, $link);
  883. -                       $affected_rows = mysql_affected_rows($link);
  884. -                       $lead_id = mysql_insert_id($link);
  885. -                       if ($DB > 0) {echo "<!-- $affected_rows|$lead_id|$stmtZ -->";}
  886. -                       if ($WeBRooTWritablE > 0)
  887. -                           {fwrite($stmt_file, $stmtZ."\r\n");}
  888. -                       $multistmt='';
  889. -
  890. -                       $custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;";
  891. -                       $rslt=mysql_query($custom_SQL_query, $link);
  892. -                       $affected_rows = mysql_affected_rows($link);
  893. -                       if ($DB > 0) {echo "<!-- $affected_rows|$custom_SQL_query -->";}
  894. -                       }
  895. -                   else
  896. -                       {
  897. -                       if ($multi_insert_counter > 8)
  898. -                           {
  899. -                           ### insert good record into vicidial_list table ###
  900. -                           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');";
  901. -                           $rslt=mysql_query($stmtZ, $link);
  902. -                           if ($WeBRooTWritablE > 0)
  903. -                               {fwrite($stmt_file, $stmtZ."\r\n");}
  904. -                           $multistmt='';
  905. -                           $multi_insert_counter=0;
  906. -                           }
  907. -                       else
  908. -                           {
  909. -                           $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),";
  910. -                           $multi_insert_counter++;
  911. -                           }
  912. -                       }
  913. -                   $good++;
  914. -                   }
  915. -               else
  916. -                   {
  917. -                   if ($bad < 1000000)
  918. -                       {
  919. -                       if ( $list_id < 100 )
  920. -                           {
  921. -                           print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID</font><b>\n";
  922. -                           }
  923. -                       else
  924. -                           {
  925. -                           if ($valid_number < 1)
  926. -                               {
  927. -                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number</font><b>\n";
  928. -                               }
  929. -                           else
  930. -                               {
  931. -                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead  $dup_lead_list</font><b>\n";
  932. -                               }
  933. -                           }
  934. -                       }
  935. -                   $bad++;
  936. -                   }
  937. -               $total++;
  938. -               if ($total%100==0)
  939. -                   {
  940. -                   print "<script language='JavaScript1.2'>ShowProgress($good, $bad, $total, $dup, $inv, $post)</script>";
  941. -                   usleep(1000);
  942. -                   flush();
  943. -                   }
  944. -               }
  945. -           }
  946. -       if ($multi_insert_counter!=0)
  947. -           {
  948. -           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";";
  949. -           mysql_query($stmtZ, $link);
  950. -           if ($WeBRooTWritablE > 0)
  951. -               {fwrite($stmt_file, $stmtZ."\r\n");}
  952. -           }
  953. -
  954. -       ### LOG INSERTION Admin Log Table ###
  955. -       $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST CUSTOM', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';";
  956. -       if ($DB) {echo "|$stmt|\n";}
  957. -       $rslt=mysql_query($stmt, $link);
  958. -
  959. -       print "<BR><BR>Done</B> GOOD: $good &nbsp; &nbsp; &nbsp; BAD: $bad &nbsp; &nbsp; &nbsp; TOTAL: $total</font></center>";
  960. -       }
  961. -   else
  962. -       {
  963. -       print "<center><font face='arial, helvetica' size=3 color='#990000'><B>ERROR: The file does not have the required number of fields to process it.</B></font></center>";
  964. -       }
  965. -   }
  966. -##### END custom fields submission #####
  967. -
  968. -
  969. -
  970. -if (($leadfile) && ($LF_path))
  971. -   {
  972. -   $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  973. -
  974. -   ### LOG INSERTION Admin Log Table ###
  975. -   $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST', event_sql='', event_notes='File Name: $leadfile_name';";
  976. -   if ($DB) {echo "|$stmt|\n";}
  977. -   $rslt=mysql_query($stmt, $link);
  978. -
  979. -
  980. -
  981. -   ##### BEGIN process standard file layout #####
  982. -   if ($file_layout=="standard")
  983. -       {
  984. -       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script>";
  985. -       flush();
  986. -
  987. -
  988. -       $delim_set=0;
  989. -       # csv xls xlsx ods sxc conversion
  990. -       if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name))
  991. -           {
  992. -           $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name);
  993. -           copy($LF_path, "/tmp/$leadfile_name");
  994. -           $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name);
  995. -           $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename";
  996. -           passthru("$convert_command");
  997. -           $lead_file = "/tmp/$new_filename";
  998. -           if ($DB > 0) {echo "|$convert_command|";}
  999. -
  1000. -           if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";}
  1001. -           if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";}
  1002. -           if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";}
  1003. -           if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";}
  1004. -           if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";}
  1005. -           $delim_set=1;
  1006. -           }
  1007. -       else
  1008. -           {
  1009. -           copy($LF_path, "/tmp/vicidial_temp_file.txt");
  1010. -           $lead_file = "/tmp/vicidial_temp_file.txt";
  1011. -           }
  1012. -       $file=fopen("$lead_file", "r");
  1013. -       if ($WeBRooTWritablE > 0)
  1014. -           {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");}
  1015. -
  1016. -       $buffer=fgets($file, 4096);
  1017. -       $tab_count=substr_count($buffer, "\t");
  1018. -       $pipe_count=substr_count($buffer, "|");
  1019. -
  1020. -       if ($delim_set < 1)
  1021. -           {
  1022. -           if ($tab_count>$pipe_count)
  1023. -               {$delim_name="tab-delimited";}
  1024. -           else
  1025. -               {$delim_name="pipe-delimited";}
  1026. -           }
  1027. -       if ($tab_count>$pipe_count)
  1028. -           {$delimiter="\t";}
  1029. -       else
  1030. -           {$delimiter="|";}
  1031. -
  1032. -       $field_check=explode($delimiter, $buffer);
  1033. -
  1034. -       if (count($field_check)>=2)
  1035. -           {
  1036. -           flush();
  1037. -           $file=fopen("$lead_file", "r");
  1038. -           $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  1039. -           print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing $delim_name file... ($tab_count|$pipe_count)\n";
  1040. -           if (strlen($list_id_override)>0)
  1041. -               {
  1042. -               print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  1043. -               }
  1044. -           if (strlen($phone_code_override)>0)
  1045. -               {
  1046. -               print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>\n";
  1047. -               }
  1048. -           while (!feof($file))
  1049. -               {
  1050. -               $record++;
  1051. -               $buffer=rtrim(fgets($file, 4096));
  1052. -               $buffer=stripslashes($buffer);
  1053. -
  1054. -               if (strlen($buffer)>0)
  1055. -                   {
  1056. -                   $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  1057. -
  1058. -                   $pulldate=date("Y-m-d H:i:s");
  1059. -                   $entry_date =           "$pulldate";
  1060. -                   $modify_date =          "";
  1061. -                   $status =               "NEW";
  1062. -                   $user ="";
  1063. -                   $vendor_lead_code =     $row[0];
  1064. -                   $source_code =          $row[1];
  1065. -                   $source_id=$source_code;
  1066. -                   $list_id =              $row[2];
  1067. -                   $gmt_offset =           '0';
  1068. -                   $called_since_last_reset='N';
  1069. -                   $phone_code =           eregi_replace("[^0-9]", "", $row[3]);
  1070. -                   $phone_number =         eregi_replace("[^0-9]", "", $row[4]);
  1071. -                   $title =                $row[5];
  1072. -                   $first_name =           $row[6];
  1073. -                   $middle_initial =       $row[7];
  1074. -                   $last_name =            $row[8];
  1075. -                   $address1 =             $row[9];
  1076. -                   $address2 =             $row[10];
  1077. -                   $address3 =             $row[11];
  1078. -                   $city =$row[12];
  1079. -                   $state =                $row[13];
  1080. -                   $province =             $row[14];
  1081. -                   $postal_code =          $row[15];
  1082. -                   $country_code =         $row[16];
  1083. -                   $gender =               $row[17];
  1084. -                   $date_of_birth =        $row[18];
  1085. -                   $alt_phone =            eregi_replace("[^0-9]", "", $row[19]);
  1086. -                   $email =                $row[20];
  1087. -                   $security_phrase =      $row[21];
  1088. -                   $comments =             trim($row[22]);
  1089. -                   $rank =                 $row[23];
  1090. -                   $owner =                $row[24];
  1091. -                      
  1092. -                   # replace ' " ` \ ; with nothing
  1093. -                   $vendor_lead_code =     eregi_replace($field_regx, "", $vendor_lead_code);
  1094. -                   $source_code =          eregi_replace($field_regx, "", $source_code);
  1095. -                   $source_id =            eregi_replace($field_regx, "", $source_id);
  1096. -                   $list_id =              eregi_replace($field_regx, "", $list_id);
  1097. -                   $phone_code =           eregi_replace($field_regx, "", $phone_code);
  1098. -                   $phone_number =         eregi_replace($field_regx, "", $phone_number);
  1099. -                   $title =                eregi_replace($field_regx, "", $title);
  1100. -                   $first_name =           eregi_replace($field_regx, "", $first_name);
  1101. -                   $middle_initial =       eregi_replace($field_regx, "", $middle_initial);
  1102. -                   $last_name =            eregi_replace($field_regx, "", $last_name);
  1103. -                   $address1 =             eregi_replace($field_regx, "", $address1);
  1104. -                   $address2 =             eregi_replace($field_regx, "", $address2);
  1105. -                   $address3 =             eregi_replace($field_regx, "", $address3);
  1106. -                   $city =                 eregi_replace($field_regx, "", $city);
  1107. -                   $state =                eregi_replace($field_regx, "", $state);
  1108. -                   $province =             eregi_replace($field_regx, "", $province);
  1109. -                   $postal_code =          eregi_replace($field_regx, "", $postal_code);
  1110. -                   $country_code =         eregi_replace($field_regx, "", $country_code);
  1111. -                   $gender =               eregi_replace($field_regx, "", $gender);
  1112. -                   $date_of_birth =        eregi_replace($field_regx, "", $date_of_birth);
  1113. -                   $alt_phone =            eregi_replace($field_regx, "", $alt_phone);
  1114. -                   $email =                eregi_replace($field_regx, "", $email);
  1115. -                   $security_phrase =      eregi_replace($field_regx, "", $security_phrase);
  1116. -                   $comments =             eregi_replace($field_regx, "", $comments);
  1117. -                   $rank =                 eregi_replace($field_regx, "", $rank);
  1118. -                   $owner =                eregi_replace($field_regx, "", $owner);
  1119. -                  
  1120. -                   $USarea =           substr($phone_number, 0, 3);
  1121. -
  1122. -                   if (strlen($list_id_override)>0)
  1123. -                       {
  1124. -                       $list_id = $list_id_override;
  1125. -                       }
  1126. -                   if (strlen($phone_code_override)>0)
  1127. -                       {
  1128. -                       $phone_code = $phone_code_override;
  1129. -                       }
  1130. -
  1131. -                   ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign #####
  1132. -                   if (eregi("DUPCAMP",$dupcheck))
  1133. -                       {
  1134. -                           $dup_lead=0;
  1135. -                           $dup_lists='';
  1136. -                       $stmt="select campaign_id from vicidial_lists where list_id='$list_id';";
  1137. -                       $rslt=mysql_query($stmt, $link);
  1138. -                       $ci_recs = mysql_num_rows($rslt);
  1139. -                       if ($ci_recs > 0)
  1140. -                           {
  1141. -                           $row=mysql_fetch_row($rslt);
  1142. -                           $dup_camp =         $row[0];
  1143. -
  1144. -                           $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';";
  1145. -                           $rslt=mysql_query($stmt, $link);
  1146. -                           $li_recs = mysql_num_rows($rslt);
  1147. -                           if ($li_recs > 0)
  1148. -                               {
  1149. -                               $L=0;
  1150. -                               while ($li_recs > $L)
  1151. -                                   {
  1152. -                                   $row=mysql_fetch_row($rslt);
  1153. -                                   $dup_lists .=   "'$row[0]',";
  1154. -                                   $L++;
  1155. -                                   }
  1156. -                               $dup_lists = eregi_replace(",$",'',$dup_lists);
  1157. -
  1158. -                               $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;";
  1159. -                               $rslt=mysql_query($stmt, $link);
  1160. -                               $pc_recs = mysql_num_rows($rslt);
  1161. -                               if ($pc_recs > 0)
  1162. -                                   {
  1163. -                                   $dup_lead=1;
  1164. -                                   $row=mysql_fetch_row($rslt);
  1165. -                                   $dup_lead_list =    $row[0];
  1166. -                                   }
  1167. -                               if ($dup_lead < 1)
  1168. -                                   {
  1169. -                                   if (eregi("$phone_number$US$list_id",$phone_list))
  1170. -                                       {$dup_lead++; $dup++;}
  1171. -                                   }
  1172. -                               }
  1173. -                           }
  1174. -                       }
  1175. -
  1176. -                   ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  1177. -                   if (eregi("DUPSYS",$dupcheck))
  1178. -                       {
  1179. -                       $dup_lead=0;
  1180. -                       $stmt="select list_id from vicidial_list where phone_number='$phone_number';";
  1181. -                       $rslt=mysql_query($stmt, $link);
  1182. -                       $pc_recs = mysql_num_rows($rslt);
  1183. -                       if ($pc_recs > 0)
  1184. -                           {
  1185. -                           $dup_lead=1;
  1186. -                           $row=mysql_fetch_row($rslt);
  1187. -                           $dup_lead_list =    $row[0];
  1188. -                           }
  1189. -                       if ($dup_lead < 1)
  1190. -                           {
  1191. -                           if (eregi("$phone_number$US$list_id",$phone_list))
  1192. -                               {$dup_lead++; $dup++;}
  1193. -                           }
  1194. -                       }
  1195. -
  1196. -                   ##### Check for duplicate phone numbers in vicidial_list table for one list_id #####
  1197. -                   if (eregi("DUPLIST",$dupcheck))
  1198. -                       {
  1199. -                       $dup_lead=0;
  1200. -                       $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';";
  1201. -                       $rslt=mysql_query($stmt, $link);
  1202. -                       $pc_recs = mysql_num_rows($rslt);
  1203. -                       if ($pc_recs > 0)
  1204. -                           {
  1205. -                           $row=mysql_fetch_row($rslt);
  1206. -                           $dup_lead =         $row[0];
  1207. -                           }
  1208. -                       if ($dup_lead < 1)
  1209. -                           {
  1210. -                           if (eregi("$phone_number$US$list_id",$phone_list))
  1211. -                               {$dup_lead++; $dup++;}
  1212. -                           }
  1213. -                       }
  1214. -
  1215. -                   ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id #####
  1216. -                   if (eregi("DUPTITLEALTPHONELIST",$dupcheck))
  1217. -                       {
  1218. -                       $dup_lead=0;
  1219. -                       $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';";
  1220. -                       $rslt=mysql_query($stmt, $link);
  1221. -                       $pc_recs = mysql_num_rows($rslt);
  1222. -                       if ($pc_recs > 0)
  1223. -                           {
  1224. -                           $row=mysql_fetch_row($rslt);
  1225. -                           $dup_lead =         $row[0];
  1226. -                           $dup_lead_list =    $list_id;
  1227. -                           }
  1228. -                       if ($dup_lead < 1)
  1229. -                           {
  1230. -                           if (eregi("$alt_phone$title$US$list_id",$phone_list))
  1231. -                               {$dup_lead++; $dup++;}
  1232. -                           }
  1233. -                       }
  1234. -
  1235. -                   ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  1236. -                   if (eregi("DUPTITLEALTPHONESYS",$dupcheck))
  1237. -                       {
  1238. -                       $dup_lead=0;
  1239. -                       $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';";
  1240. -                       $rslt=mysql_query($stmt, $link);
  1241. -                       $pc_recs = mysql_num_rows($rslt);
  1242. -                       if ($pc_recs > 0)
  1243. -                           {
  1244. -                           $dup_lead=1;
  1245. -                           $row=mysql_fetch_row($rslt);
  1246. -                           $dup_lead_list =    $row[0];
  1247. -                           }
  1248. -                       if ($dup_lead < 1)
  1249. -                           {
  1250. -                           if (eregi("$alt_phone$title$US$list_id",$phone_list))
  1251. -                               {$dup_lead++; $dup++;}
  1252. -                           }
  1253. -                       }
  1254. -
  1255. -                   $valid_number=1;
  1256. -                   if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) )
  1257. -                       {
  1258. -                       $valid_number=0;
  1259. -                       $invalid_reason = "INVALID PHONE NUMBER LENGTH";
  1260. -                       }
  1261. -                   if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) )
  1262. -                       {
  1263. -                       $USprefix =     substr($phone_number, 3, 1);
  1264. -                       if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";}
  1265. -                       if ($USprefix < 2)
  1266. -                           {
  1267. -                           $valid_number=0;
  1268. -                           $invalid_reason = "INVALID PHONE NUMBER PREFIX";
  1269. -                           }
  1270. -                       }
  1271. -                   if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) )
  1272. -                       {
  1273. -                       $phone_areacode = substr($phone_number, 0, 3);
  1274. -                       $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';";
  1275. -                       if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";}
  1276. -                       $rslt=mysql_query($stmt, $link);
  1277. -                       $row=mysql_fetch_row($rslt);
  1278. -                       $valid_number=$row[0];
  1279. -                       if ($valid_number < 1)
  1280. -                           {
  1281. -                           $invalid_reason = "INVALID PHONE NUMBER AREACODE";
  1282. -                           }
  1283. -                       }
  1284. -
  1285. -                   if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 ))
  1286. -                       {
  1287. -                       if (strlen($phone_code)<1) {$phone_code = '1';}
  1288. -
  1289. -                       if (eregi("TITLEALTPHONE",$dupcheck))
  1290. -                           {$phone_list .= "$alt_phone$title$US$list_id|";}
  1291. -                       else
  1292. -                           {$phone_list .= "$phone_number$US$list_id|";}
  1293. -
  1294. -                       $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
  1295. -
  1296. -                       if ($multi_insert_counter > 8)
  1297. -                           {
  1298. -                           ### insert good deal into pending_transactions table ###
  1299. -                           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');";
  1300. -                           $rslt=mysql_query($stmtZ, $link);
  1301. -                           if ($WeBRooTWritablE > 0)
  1302. -                               {fwrite($stmt_file, $stmtZ."\r\n");}
  1303. -                           $multistmt='';
  1304. -                           $multi_insert_counter=0;
  1305. -                           }
  1306. -                       else
  1307. -                           {
  1308. -                           $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),";
  1309. -                           $multi_insert_counter++;
  1310. -                           }
  1311. -                       $good++;
  1312. -                       }
  1313. -                   else
  1314. -                       {
  1315. -                       if ($bad < 1000000)
  1316. -                           {
  1317. -                           if ( $list_id < 100 )
  1318. -                               {
  1319. -                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID</font><b>\n";
  1320. -                               }
  1321. -                           else
  1322. -                               {
  1323. -                               if ($valid_number < 1)
  1324. -                                   {
  1325. -                                   print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number</font><b>\n";
  1326. -                                   }
  1327. -                               else
  1328. -                                   {
  1329. -                                   print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead  $dup_lead_list</font><b>\n";
  1330. -                                   }
  1331. -                               }
  1332. -                           }
  1333. -                       $bad++;
  1334. -                       }
  1335. -                   $total++;
  1336. -                   if ($total%100==0)
  1337. -                       {
  1338. -                       print "<script language='JavaScript1.2'>ShowProgress($good, $bad, $total, $dup, $inv, $post)</script>";
  1339. -                       usleep(1000);
  1340. -                       flush();
  1341. -                       }
  1342. -                   }
  1343. -               }
  1344. -           if ($multi_insert_counter!=0)
  1345. -               {
  1346. -               $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";";
  1347. -               mysql_query($stmtZ, $link);
  1348. -               if ($WeBRooTWritablE > 0)
  1349. -                   {fwrite($stmt_file, $stmtZ."\r\n");}
  1350. -               }
  1351. -           ### LOG INSERTION Admin Log Table ###
  1352. -           $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST STANDARD', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';";
  1353. -           if ($DB) {echo "|$stmt|\n";}
  1354. -           $rslt=mysql_query($stmt, $link);
  1355. -
  1356. -           print "<BR><BR>Done</B> GOOD: $good &nbsp; &nbsp; &nbsp; BAD: $bad &nbsp; &nbsp; &nbsp; TOTAL: $total</font></center>";
  1357. -           }
  1358. -       else
  1359. -           {
  1360. -           print "<center><font face='arial, helvetica' size=3 color='#990000'><B>ERROR: The file does not have the required number of fields to process it.</B></font></center>";
  1361. -           }
  1362. -       }
  1363. -   ##### END process standard file layout #####
  1364. -
  1365. -      
  1366. -   ##### BEGIN field chooser #####
  1367. -   else
  1368. -       {
  1369. -       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script><HR>";
  1370. -       flush();
  1371. -       print "<table border=0 cellpadding=3 cellspacing=0 width=700 align=center>\r\n";
  1372. -       print "  <tr bgcolor='#330099'>\r\n";
  1373. -       print "    <th align=right><font class='standard' color='white'>VICIDIAL Column</font></th>\r\n";
  1374. -       print "    <th><font class='standard' color='white'>File data</font></th>\r\n";
  1375. -       print "  </tr>\r\n";
  1376. -
  1377. -       $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner from vicidial_list limit 1";
  1378. -
  1379. -       ##### BEGIN custom fields columns list ###
  1380. -       if ($custom_fields_enabled > 0)
  1381. -           {
  1382. -           $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";";
  1383. -           if ($DB>0) {echo "$stmt\n";}
  1384. -           $rslt=mysql_query($stmt, $link);
  1385. -           $tablecount_to_print = mysql_num_rows($rslt);
  1386. -           if ($tablecount_to_print > 0)
  1387. -               {
  1388. -               $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';";
  1389. -               if ($DB>0) {echo "$stmt\n";}
  1390. -               $rslt=mysql_query($stmt, $link);
  1391. -               $fieldscount_to_print = mysql_num_rows($rslt);
  1392. -               if ($fieldscount_to_print > 0)
  1393. -                   {
  1394. -                   $rowx=mysql_fetch_row($rslt);
  1395. -                   $custom_records_count = $rowx[0];
  1396. -
  1397. -                   $custom_SQL='';
  1398. -                   $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;";
  1399. -                   if ($DB>0) {echo "$stmt\n";}
  1400. -                   $rslt=mysql_query($stmt, $link);
  1401. -                   $fields_to_print = mysql_num_rows($rslt);
  1402. -                   $fields_list='';
  1403. -                   $o=0;
  1404. -                   while ($fields_to_print > $o)
  1405. -                       {
  1406. -                       $rowx=mysql_fetch_row($rslt);
  1407. -                       $A_field_label[$o] =    $rowx[1];
  1408. -                       $A_field_type[$o] =     $rowx[6];
  1409. -
  1410. -                       if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";}
  1411. -
  1412. -                       if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') )
  1413. -                           {
  1414. -                           if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields))
  1415. -                               {
  1416. -                               $custom_SQL .= ",$A_field_label[$o]";
  1417. -                               }
  1418. -                           }
  1419. -                       $o++;
  1420. -                       }
  1421. -
  1422. -                   $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner $custom_SQL from vicidial_list, custom_$list_id_override limit 1";
  1423. -
  1424. -                   }
  1425. -               }
  1426. -           }
  1427. -       ##### END custom fields columns list ###
  1428. -
  1429. -
  1430. -       $rslt=mysql_query("$fields_stmt", $link);
  1431. -
  1432. -       # csv xls xlsx ods sxc conversion
  1433. -       $delim_set=0;
  1434. -       if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name))
  1435. -           {
  1436. -           $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name);
  1437. -           copy($LF_path, "/tmp/$leadfile_name");
  1438. -           $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name);
  1439. -           $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename";
  1440. -           passthru("$convert_command");
  1441. -           $lead_file = "/tmp/$new_filename";
  1442. -           if ($DB > 0) {echo "|$convert_command|";}
  1443. -
  1444. -           if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";}
  1445. -           if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";}
  1446. -           if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";}
  1447. -           if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";}
  1448. -           if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";}
  1449. -           $delim_set=1;
  1450. -           }
  1451. -       else
  1452. -           {
  1453. -           copy($LF_path, "/tmp/vicidial_temp_file.txt");
  1454. -           $lead_file = "/tmp/vicidial_temp_file.txt";
  1455. -           }
  1456. -       $file=fopen("$lead_file", "r");
  1457. -       if ($WeBRooTWritablE > 0)
  1458. -           {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");}
  1459. -
  1460. -       $buffer=fgets($file, 4096);
  1461. -       $tab_count=substr_count($buffer, "\t");
  1462. -       $pipe_count=substr_count($buffer, "|");
  1463. -
  1464. -       if ($delim_set < 1)
  1465. -           {
  1466. -           if ($tab_count>$pipe_count)
  1467. -               {$delim_name="tab-delimited";}
  1468. -           else
  1469. -               {$delim_name="pipe-delimited";}
  1470. -           }
  1471. -       if ($tab_count>$pipe_count)
  1472. -           {$delimiter="\t";}
  1473. -       else
  1474. -           {$delimiter="|";}
  1475. -
  1476. -       $field_check=explode($delimiter, $buffer);
  1477. -       flush();
  1478. -       $file=fopen("$lead_file", "r");
  1479. -       print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing $delim_name file...\n";
  1480. -
  1481. -       if (strlen($list_id_override)>0)
  1482. -           {
  1483. -           print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  1484. -           }
  1485. -       if (strlen($phone_code_override)>0)
  1486. -           {
  1487. -           print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>";
  1488. -           }
  1489. -       $buffer=rtrim(fgets($file, 4096));
  1490. -       $buffer=stripslashes($buffer);
  1491. -       $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  1492. -      
  1493. -       for ($i=0; $i<mysql_num_fields($rslt); $i++)
  1494. -           {
  1495. -           if ( (mysql_field_name($rslt, $i)=="list_id" and $list_id_override!="") or (mysql_field_name($rslt, $i)=="phone_code" and $phone_code_override!="") )
  1496. -               {
  1497. -               print "<!-- skipping " . mysql_field_name($rslt, $i) . " -->\n";
  1498. -               }
  1499. -           else
  1500. -               {
  1501. -               print "  <tr bgcolor=#D9E6FE>\r\n";
  1502. -               print "    <td align=right><font class=standard>".strtoupper(eregi_replace("_", " ", mysql_field_name($rslt, $i))).": </font></td>\r\n";
  1503. -               print "    <td align=center><select name='".mysql_field_name($rslt, $i)."_field'>\r\n";
  1504. -               print "     <option value='-1'>(none)</option>\r\n";
  1505. -
  1506. -               for ($j=0; $j<count($row); $j++)
  1507. -                   {
  1508. -                   eregi_replace("\"", "", $row[$j]);
  1509. -                   print "     <option value='$j'>\"$row[$j]\"</option>\r\n";
  1510. -                   }
  1511. -
  1512. -               print "    </select></td>\r\n";
  1513. -               print "  </tr>\r\n";
  1514. -               }
  1515. -           }
  1516. -       print "  <tr bgcolor='#330099'>\r\n";
  1517. -       print "  <input type=hidden name=dupcheck value=\"$dupcheck\">\r\n";
  1518. -       print "  <input type=hidden name=usacan_check value=\"$usacan_check\">\r\n";
  1519. -       print "  <input type=hidden name=postalgmt value=\"$postalgmt\">\r\n";
  1520. -       print "  <input type=hidden name=lead_file value=\"$lead_file\">\r\n";
  1521. -       print "  <input type=hidden name=list_id_override value=\"$list_id_override\">\r\n";
  1522. -       print "  <input type=hidden name=phone_code_override value=\"$phone_code_override\">\r\n";
  1523. -       print "    <th colspan=2><input type=submit name='OK_to_process' value='OK TO PROCESS'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button onClick=\"javascript:document.location='admin_listloader_third_gen.php'\" value=\"START OVER\" name='reload_page'></th>\r\n";
  1524. -       print "  </tr>\r\n";
  1525. -       print "</table>\r\n";
  1526. -
  1527. -       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=false; document.forms[0].submit_file.disabled=false; document.forms[0].reload_page.disabled=false;</script>";
  1528. -       }
  1529. -   ##### END field chooser #####
  1530. -
  1531. -   }
  1532. -
  1533. -?>
  1534. -</form>
  1535. -</body>
  1536. -</html>
  1537. -
  1538. -
  1539. -
  1540. -
  1541. -
  1542. -<?php
  1543. -
  1544. -exit;
  1545. -
  1546. -
  1547. -
  1548. -function lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner)
  1549. -   {
  1550. -   global $link;
  1551. -
  1552. -   $postalgmt_found=0;
  1553. -   if ( (eregi("POSTAL",$postalgmt)) && (strlen($postal_code)>4) )
  1554. -       {
  1555. -       if (preg_match('/^1$/', $phone_code))
  1556. -           {
  1557. -           $stmt="select postal_code,state,GMT_offset,DST,DST_range,country,country_code from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";";
  1558. -           $rslt=mysql_query($stmt, $link);
  1559. -           $pc_recs = mysql_num_rows($rslt);
  1560. -           if ($pc_recs > 0)
  1561. -               {
  1562. -               $row=mysql_fetch_row($rslt);
  1563. -               $gmt_offset =   $row[2];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1564. -               $dst =          $row[3];
  1565. -               $dst_range =    $row[4];
  1566. -               $PC_processed++;
  1567. -               $postalgmt_found++;
  1568. -               $post++;
  1569. -               }
  1570. -           }
  1571. -       }
  1572. -   if ( ($postalgmt=="TZCODE") && (strlen($owner)>1) )
  1573. -       {
  1574. -       $dst_range='';
  1575. -       $dst='N';
  1576. -       $gmt_offset=0;
  1577. -
  1578. -       $stmt="select GMT_offset from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' limit 1;";
  1579. -       $rslt=mysql_query($stmt, $link);
  1580. -       $pc_recs = mysql_num_rows($rslt);
  1581. -       if ($pc_recs > 0)
  1582. -           {
  1583. -           $row=mysql_fetch_row($rslt);
  1584. -           $gmt_offset =   $row[0];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1585. -           $PC_processed++;
  1586. -           $postalgmt_found++;
  1587. -           $post++;
  1588. -           }
  1589. -
  1590. -       $stmt = "select distinct DST_range from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' order by DST_range desc limit 1;";
  1591. -       $rslt=mysql_query($stmt, $link);
  1592. -       $pc_recs = mysql_num_rows($rslt);
  1593. -       if ($pc_recs > 0)
  1594. -           {
  1595. -           $row=mysql_fetch_row($rslt);
  1596. -           $dst_range =    $row[0];
  1597. -           if (strlen($dst_range)>2) {$dst = 'Y';}
  1598. -           }
  1599. -       }
  1600. -
  1601. -   if ($postalgmt_found < 1)
  1602. -       {
  1603. -       $PC_processed=0;
  1604. -       ### UNITED STATES ###
  1605. -       if ($phone_code =='1')
  1606. -           {
  1607. -           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';";
  1608. -           $rslt=mysql_query($stmt, $link);
  1609. -           $pc_recs = mysql_num_rows($rslt);
  1610. -           if ($pc_recs > 0)
  1611. -               {
  1612. -               $row=mysql_fetch_row($rslt);
  1613. -               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1614. -               $dst =          $row[5];
  1615. -               $dst_range =    $row[6];
  1616. -               $PC_processed++;
  1617. -               }
  1618. -           }
  1619. -       ### MEXICO ###
  1620. -       if ($phone_code =='52')
  1621. -           {
  1622. -           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';";
  1623. -           $rslt=mysql_query($stmt, $link);
  1624. -           $pc_recs = mysql_num_rows($rslt);
  1625. -           if ($pc_recs > 0)
  1626. -               {
  1627. -               $row=mysql_fetch_row($rslt);
  1628. -               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1629. -               $dst =          $row[5];
  1630. -               $dst_range =    $row[6];
  1631. -               $PC_processed++;
  1632. -               }
  1633. -           }
  1634. -       ### AUSTRALIA ###
  1635. -       if ($phone_code =='61')
  1636. -           {
  1637. -           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and state='$state';";
  1638. -           $rslt=mysql_query($stmt, $link);
  1639. -           $pc_recs = mysql_num_rows($rslt);
  1640. -           if ($pc_recs > 0)
  1641. -               {
  1642. -               $row=mysql_fetch_row($rslt);
  1643. -               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1644. -               $dst =          $row[5];
  1645. -               $dst_range =    $row[6];
  1646. -               $PC_processed++;
  1647. -               }
  1648. -           }
  1649. -       ### ALL OTHER COUNTRY CODES ###
  1650. -       if (!$PC_processed)
  1651. -           {
  1652. -           $PC_processed++;
  1653. -           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code';";
  1654. -           $rslt=mysql_query($stmt, $link);
  1655. -           $pc_recs = mysql_num_rows($rslt);
  1656. -           if ($pc_recs > 0)
  1657. -               {
  1658. -               $row=mysql_fetch_row($rslt);
  1659. -               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  1660. -               $dst =          $row[5];
  1661. -               $dst_range =    $row[6];
  1662. -               $PC_processed++;
  1663. -               }
  1664. -           }
  1665. -       }
  1666. -
  1667. -   ### Find out if DST to raise the gmt offset ###
  1668. -   $AC_GMT_diff = ($gmt_offset - $LOCAL_GMT_OFF_STD);
  1669. -   $AC_localtime = mktime(($Shour + $AC_GMT_diff), $Smin, $Ssec, $Smon, $Smday, $Syear);
  1670. -       $hour = date("H",$AC_localtime);
  1671. -       $min = date("i",$AC_localtime);
  1672. -       $sec = date("s",$AC_localtime);
  1673. -       $mon = date("m",$AC_localtime);
  1674. -       $mday = date("d",$AC_localtime);
  1675. -       $wday = date("w",$AC_localtime);
  1676. -       $year = date("Y",$AC_localtime);
  1677. -   $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
  1678. -
  1679. -   $AC_processed=0;
  1680. -   if ( (!$AC_processed) and ($dst_range == 'SSM-FSN') )
  1681. -       {
  1682. -       if ($DBX) {print "     Second Sunday March to First Sunday November\n";}
  1683. -       #**********************************************************************
  1684. -       # SSM-FSN
  1685. -       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  1686. -       #       Standard time is in effect.
  1687. -       #     Based on Second Sunday March to First Sunday November at 2 am.
  1688. -       #     INPUTS:
  1689. -       #       mm              INTEGER       Month.
  1690. -       #       dd              INTEGER       Day of the month.
  1691. -       #       ns              INTEGER       Seconds into the day.
  1692. -       #       dow             INTEGER       Day of week (0=Sunday, to 6=Saturday)
  1693. -       #     OPTIONAL INPUT:
  1694. -       #       timezone        INTEGER       hour difference UTC - local standard time
  1695. -       #                                      (DEFAULT is blank)
  1696. -       #                                     make calculations based on UTC time,
  1697. -       #                                     which means shift at 10:00 UTC in April
  1698. -       #                                     and 9:00 UTC in October
  1699. -       #     OUTPUT:
  1700. -       #                       INTEGER       1 = DST, 0 = not DST
  1701. -       #
  1702. -       # S  M  T  W  T  F  S
  1703. -       # 1  2  3  4  5  6  7
  1704. -       # 8  9 10 11 12 13 14
  1705. -       #15 16 17 18 19 20 21
  1706. -       #22 23 24 25 26 27 28
  1707. -       #29 30 31
  1708. -       #
  1709. -       # S  M  T  W  T  F  S
  1710. -       #    1  2  3  4  5  6
  1711. -       # 7  8  9 10 11 12 13
  1712. -       #14 15 16 17 18 19 20
  1713. -       #21 22 23 24 25 26 27
  1714. -       #28 29 30 31
  1715. -       #
  1716. -       #**********************************************************************
  1717. -
  1718. -           $USACAN_DST=0;
  1719. -           $mm = $mon;
  1720. -           $dd = $mday;
  1721. -           $ns = $dsec;
  1722. -           $dow= $wday;
  1723. -
  1724. -           if ($mm < 3 || $mm > 11) {
  1725. -           $USACAN_DST=0;  
  1726. -           } elseif ($mm >= 4 and $mm <= 10) {
  1727. -           $USACAN_DST=1;  
  1728. -           } elseif ($mm == 3) {
  1729. -           if ($dd > 13) {
  1730. -               $USACAN_DST=1;  
  1731. -           } elseif ($dd >= ($dow+8)) {
  1732. -               if ($timezone) {
  1733. -               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  1734. -                   $USACAN_DST=0;  
  1735. -               } else {
  1736. -                   $USACAN_DST=1;  
  1737. -               }
  1738. -               } else {
  1739. -               if ($dow == 0 and $ns < 7200) {
  1740. -                   $USACAN_DST=0;  
  1741. -               } else {
  1742. -                   $USACAN_DST=1;  
  1743. -               }
  1744. -               }
  1745. -           } else {
  1746. -               $USACAN_DST=0;  
  1747. -           }
  1748. -           } elseif ($mm == 11) {
  1749. -           if ($dd > 7) {
  1750. -               $USACAN_DST=0;  
  1751. -           } elseif ($dd < ($dow+1)) {
  1752. -               $USACAN_DST=1;  
  1753. -           } elseif ($dow == 0) {
  1754. -               if ($timezone) { # UTC calculations
  1755. -               if ($ns < (7200+($timezone-1)*3600)) {
  1756. -                   $USACAN_DST=1;  
  1757. -               } else {
  1758. -                   $USACAN_DST=0;  
  1759. -               }
  1760. -               } else { # local time calculations
  1761. -               if ($ns < 7200) {
  1762. -                   $USACAN_DST=1;  
  1763. -               } else {
  1764. -                   $USACAN_DST=0;  
  1765. -               }
  1766. -               }
  1767. -           } else {
  1768. -               $USACAN_DST=0;  
  1769. -           }
  1770. -           } # end of month checks
  1771. -       if ($DBX) {print "     DST: $USACAN_DST\n";}
  1772. -       if ($USACAN_DST) {$gmt_offset++;}
  1773. -       $AC_processed++;
  1774. -       }
  1775. -
  1776. -   if ( (!$AC_processed) and ($dst_range == 'FSA-LSO') )
  1777. -       {
  1778. -       if ($DBX) {print "     First Sunday April to Last Sunday October\n";}
  1779. -       #**********************************************************************
  1780. -       # FSA-LSO
  1781. -       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  1782. -       #       Standard time is in effect.
  1783. -       #     Based on first Sunday in April and last Sunday in October at 2 am.
  1784. -       #**********************************************************************
  1785. -          
  1786. -           $USA_DST=0;
  1787. -           $mm = $mon;
  1788. -           $dd = $mday;
  1789. -           $ns = $dsec;
  1790. -           $dow= $wday;
  1791. -
  1792. -           if ($mm < 4 || $mm > 10) {
  1793. -           $USA_DST=0;
  1794. -           } elseif ($mm >= 5 and $mm <= 9) {
  1795. -           $USA_DST=1;
  1796. -           } elseif ($mm == 4) {
  1797. -           if ($dd > 7) {
  1798. -               $USA_DST=1;
  1799. -           } elseif ($dd >= ($dow+1)) {
  1800. -               if ($timezone) {
  1801. -               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  1802. -                   $USA_DST=0;
  1803. -               } else {
  1804. -                   $USA_DST=1;
  1805. -               }
  1806. -               } else {
  1807. -               if ($dow == 0 and $ns < 7200) {
  1808. -                   $USA_DST=0;
  1809. -               } else {
  1810. -                   $USA_DST=1;
  1811. -               }
  1812. -               }
  1813. -           } else {
  1814. -               $USA_DST=0;
  1815. -           }
  1816. -           } elseif ($mm == 10) {
  1817. -           if ($dd < 25) {
  1818. -               $USA_DST=1;
  1819. -           } elseif ($dd < ($dow+25)) {
  1820. -               $USA_DST=1;
  1821. -           } elseif ($dow == 0) {
  1822. -               if ($timezone) { # UTC calculations
  1823. -               if ($ns < (7200+($timezone-1)*3600)) {
  1824. -                   $USA_DST=1;
  1825. -               } else {
  1826. -                   $USA_DST=0;
  1827. -               }
  1828. -               } else { # local time calculations
  1829. -               if ($ns < 7200) {
  1830. -                   $USA_DST=1;
  1831. -               } else {
  1832. -                   $USA_DST=0;
  1833. -               }
  1834. -               }
  1835. -           } else {
  1836. -               $USA_DST=0;
  1837. -           }
  1838. -           } # end of month checks
  1839. -
  1840. -       if ($DBX) {print "     DST: $USA_DST\n";}
  1841. -       if ($USA_DST) {$gmt_offset++;}
  1842. -       $AC_processed++;
  1843. -       }
  1844. -
  1845. -   if ( (!$AC_processed) and ($dst_range == 'LSM-LSO') )
  1846. -       {
  1847. -       if ($DBX) {print "     Last Sunday March to Last Sunday October\n";}
  1848. -       #**********************************************************************
  1849. -       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  1850. -       #       Standard time is in effect.
  1851. -       #     Based on last Sunday in March and last Sunday in October at 1 am.
  1852. -       #**********************************************************************
  1853. -          
  1854. -           $GBR_DST=0;
  1855. -           $mm = $mon;
  1856. -           $dd = $mday;
  1857. -           $ns = $dsec;
  1858. -           $dow= $wday;
  1859. -
  1860. -           if ($mm < 3 || $mm > 10) {
  1861. -           $GBR_DST=0;
  1862. -           } elseif ($mm >= 4 and $mm <= 9) {
  1863. -           $GBR_DST=1;
  1864. -           } elseif ($mm == 3) {
  1865. -           if ($dd < 25) {
  1866. -               $GBR_DST=0;
  1867. -           } elseif ($dd < ($dow+25)) {
  1868. -               $GBR_DST=0;
  1869. -           } elseif ($dow == 0) {
  1870. -               if ($timezone) { # UTC calculations
  1871. -               if ($ns < (3600+($timezone-1)*3600)) {
  1872. -                   $GBR_DST=0;
  1873. -               } else {
  1874. -                   $GBR_DST=1;
  1875. -               }
  1876. -               } else { # local time calculations
  1877. -               if ($ns < 3600) {
  1878. -                   $GBR_DST=0;
  1879. -               } else {
  1880. -                   $GBR_DST=1;
  1881. -               }
  1882. -               }
  1883. -           } else {
  1884. -               $GBR_DST=1;
  1885. -           }
  1886. -           } elseif ($mm == 10) {
  1887. -           if ($dd < 25) {
  1888. -               $GBR_DST=1;
  1889. -           } elseif ($dd < ($dow+25)) {
  1890. -               $GBR_DST=1;
  1891. -           } elseif ($dow == 0) {
  1892. -               if ($timezone) { # UTC calculations
  1893. -               if ($ns < (3600+($timezone-1)*3600)) {
  1894. -                   $GBR_DST=1;
  1895. -               } else {
  1896. -                   $GBR_DST=0;
  1897. -               }
  1898. -               } else { # local time calculations
  1899. -               if ($ns < 3600) {
  1900. -                   $GBR_DST=1;
  1901. -               } else {
  1902. -                   $GBR_DST=0;
  1903. -               }
  1904. -               }
  1905. -           } else {
  1906. -               $GBR_DST=0;
  1907. -           }
  1908. -           } # end of month checks
  1909. -           if ($DBX) {print "     DST: $GBR_DST\n";}
  1910. -       if ($GBR_DST) {$gmt_offset++;}
  1911. -       $AC_processed++;
  1912. -       }
  1913. -   if ( (!$AC_processed) and ($dst_range == 'LSO-LSM') )
  1914. -       {
  1915. -       if ($DBX) {print "     Last Sunday October to Last Sunday March\n";}
  1916. -       #**********************************************************************
  1917. -       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  1918. -       #       Standard time is in effect.
  1919. -       #     Based on last Sunday in October and last Sunday in March at 1 am.
  1920. -       #**********************************************************************
  1921. -          
  1922. -           $AUS_DST=0;
  1923. -           $mm = $mon;
  1924. -           $dd = $mday;
  1925. -           $ns = $dsec;
  1926. -           $dow= $wday;
  1927. -
  1928. -           if ($mm < 3 || $mm > 10) {
  1929. -           $AUS_DST=1;
  1930. -           } elseif ($mm >= 4 and $mm <= 9) {
  1931. -           $AUS_DST=0;
  1932. -           } elseif ($mm == 3) {
  1933. -           if ($dd < 25) {
  1934. -               $AUS_DST=1;
  1935. -           } elseif ($dd < ($dow+25)) {
  1936. -               $AUS_DST=1;
  1937. -           } elseif ($dow == 0) {
  1938. -               if ($timezone) { # UTC calculations
  1939. -               if ($ns < (3600+($timezone-1)*3600)) {
  1940. -                   $AUS_DST=1;
  1941. -               } else {
  1942. -                   $AUS_DST=0;
  1943. -               }
  1944. -               } else { # local time calculations
  1945. -               if ($ns < 3600) {
  1946. -                   $AUS_DST=1;
  1947. -               } else {
  1948. -                   $AUS_DST=0;
  1949. -               }
  1950. -               }
  1951. -           } else {
  1952. -               $AUS_DST=0;
  1953. -           }
  1954. -           } elseif ($mm == 10) {
  1955. -           if ($dd < 25) {
  1956. -               $AUS_DST=0;
  1957. -           } elseif ($dd < ($dow+25)) {
  1958. -               $AUS_DST=0;
  1959. -           } elseif ($dow == 0) {
  1960. -               if ($timezone) { # UTC calculations
  1961. -               if ($ns < (3600+($timezone-1)*3600)) {
  1962. -                   $AUS_DST=0;
  1963. -               } else {
  1964. -                   $AUS_DST=1;
  1965. -               }
  1966. -               } else { # local time calculations
  1967. -               if ($ns < 3600) {
  1968. -                   $AUS_DST=0;
  1969. -               } else {
  1970. -                   $AUS_DST=1;
  1971. -               }
  1972. -               }
  1973. -           } else {
  1974. -               $AUS_DST=1;
  1975. -           }
  1976. -           } # end of month checks                    
  1977. -       if ($DBX) {print "     DST: $AUS_DST\n";}
  1978. -       if ($AUS_DST) {$gmt_offset++;}
  1979. -       $AC_processed++;
  1980. -       }
  1981. -
  1982. -   if ( (!$AC_processed) and ($dst_range == 'FSO-LSM') )
  1983. -       {
  1984. -       if ($DBX) {print "     First Sunday October to Last Sunday March\n";}
  1985. -       #**********************************************************************
  1986. -       #   TASMANIA ONLY
  1987. -       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  1988. -       #       Standard time is in effect.
  1989. -       #     Based on first Sunday in October and last Sunday in March at 1 am.
  1990. -       #**********************************************************************
  1991. -          
  1992. -           $AUST_DST=0;
  1993. -           $mm = $mon;
  1994. -           $dd = $mday;
  1995. -           $ns = $dsec;
  1996. -           $dow= $wday;
  1997. -
  1998. -           if ($mm < 3 || $mm > 10) {
  1999. -           $AUST_DST=1;
  2000. -           } elseif ($mm >= 4 and $mm <= 9) {
  2001. -           $AUST_DST=0;
  2002. -           } elseif ($mm == 3) {
  2003. -           if ($dd < 25) {
  2004. -               $AUST_DST=1;
  2005. -           } elseif ($dd < ($dow+25)) {
  2006. -               $AUST_DST=1;
  2007. -           } elseif ($dow == 0) {
  2008. -               if ($timezone) { # UTC calculations
  2009. -               if ($ns < (3600+($timezone-1)*3600)) {
  2010. -                   $AUST_DST=1;
  2011. -               } else {
  2012. -                   $AUST_DST=0;
  2013. -               }
  2014. -               } else { # local time calculations
  2015. -               if ($ns < 3600) {
  2016. -                   $AUST_DST=1;
  2017. -               } else {
  2018. -                   $AUST_DST=0;
  2019. -               }
  2020. -               }
  2021. -           } else {
  2022. -               $AUST_DST=0;
  2023. -           }
  2024. -           } elseif ($mm == 10) {
  2025. -           if ($dd > 7) {
  2026. -               $AUST_DST=1;
  2027. -           } elseif ($dd >= ($dow+1)) {
  2028. -               if ($timezone) {
  2029. -               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  2030. -                   $AUST_DST=0;
  2031. -               } else {
  2032. -                   $AUST_DST=1;
  2033. -               }
  2034. -               } else {
  2035. -               if ($dow == 0 and $ns < 3600) {
  2036. -                   $AUST_DST=0;
  2037. -               } else {
  2038. -                   $AUST_DST=1;
  2039. -               }
  2040. -               }
  2041. -           } else {
  2042. -               $AUST_DST=0;
  2043. -           }
  2044. -           } # end of month checks                    
  2045. -       if ($DBX) {print "     DST: $AUST_DST\n";}
  2046. -       if ($AUST_DST) {$gmt_offset++;}
  2047. -       $AC_processed++;
  2048. -       }
  2049. -
  2050. -   if ( (!$AC_processed) and ($dst_range == 'FSO-FSA') )
  2051. -       {
  2052. -       if ($DBX) {print "     Sunday in October to First Sunday in April\n";}
  2053. -       #**********************************************************************
  2054. -       # FSO-FSA
  2055. -       #   2008+ AUSTRALIA ONLY (country code 61)
  2056. -       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  2057. -       #       Standard time is in effect.
  2058. -       #     Based on first Sunday in October and first Sunday in April at 1 am.
  2059. -       #**********************************************************************
  2060. -      
  2061. -       $AUSE_DST=0;
  2062. -       $mm = $mon;
  2063. -       $dd = $mday;
  2064. -       $ns = $dsec;
  2065. -       $dow= $wday;
  2066. -
  2067. -       if ($mm < 4 or $mm > 10) {
  2068. -       $AUSE_DST=1;  
  2069. -       } elseif ($mm >= 5 and $mm <= 9) {
  2070. -       $AUSE_DST=0;  
  2071. -       } elseif ($mm == 4) {
  2072. -       if ($dd > 7) {
  2073. -           $AUSE_DST=0;  
  2074. -       } elseif ($dd >= ($dow+1)) {
  2075. -           if ($timezone) {
  2076. -           if ($dow == 0 and $ns < (3600+$timezone*3600)) {
  2077. -               $AUSE_DST=1;  
  2078. -           } else {
  2079. -               $AUSE_DST=0;  
  2080. -           }
  2081. -           } else {
  2082. -           if ($dow == 0 and $ns < 7200) {
  2083. -               $AUSE_DST=1;  
  2084. -           } else {
  2085. -               $AUSE_DST=0;  
  2086. -           }
  2087. -           }
  2088. -       } else {
  2089. -           $AUSE_DST=1;  
  2090. -       }
  2091. -       } elseif ($mm == 10) {
  2092. -       if ($dd >= 8) {
  2093. -           $AUSE_DST=1;  
  2094. -       } elseif ($dd >= ($dow+1)) {
  2095. -           if ($timezone) {
  2096. -           if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  2097. -               $AUSE_DST=0;  
  2098. -           } else {
  2099. -               $AUSE_DST=1;  
  2100. -           }
  2101. -           } else {
  2102. -           if ($dow == 0 and $ns < 3600) {
  2103. -               $AUSE_DST=0;  
  2104. -           } else {
  2105. -               $AUSE_DST=1;  
  2106. -           }
  2107. -           }
  2108. -       } else {
  2109. -           $AUSE_DST=0;  
  2110. -       }
  2111. -       } # end of month checks
  2112. -       if ($DBX) {print "     DST: $AUSE_DST\n";}
  2113. -       if ($AUSE_DST) {$gmt_offset++;}
  2114. -       $AC_processed++;
  2115. -       }
  2116. -
  2117. -   if ( (!$AC_processed) and ($dst_range == 'FSO-TSM') )
  2118. -       {
  2119. -       if ($DBX) {print "     First Sunday October to Third Sunday March\n";}
  2120. -       #**********************************************************************
  2121. -       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  2122. -       #       Standard time is in effect.
  2123. -       #     Based on first Sunday in October and third Sunday in March at 1 am.
  2124. -       #**********************************************************************
  2125. -          
  2126. -           $NZL_DST=0;
  2127. -           $mm = $mon;
  2128. -           $dd = $mday;
  2129. -           $ns = $dsec;
  2130. -           $dow= $wday;
  2131. -
  2132. -           if ($mm < 3 || $mm > 10) {
  2133. -           $NZL_DST=1;
  2134. -           } elseif ($mm >= 4 and $mm <= 9) {
  2135. -           $NZL_DST=0;
  2136. -           } elseif ($mm == 3) {
  2137. -           if ($dd < 14) {
  2138. -               $NZL_DST=1;
  2139. -           } elseif ($dd < ($dow+14)) {
  2140. -               $NZL_DST=1;
  2141. -           } elseif ($dow == 0) {
  2142. -               if ($timezone) { # UTC calculations
  2143. -               if ($ns < (3600+($timezone-1)*3600)) {
  2144. -                   $NZL_DST=1;
  2145. -               } else {
  2146. -                   $NZL_DST=0;
  2147. -               }
  2148. -               } else { # local time calculations
  2149. -               if ($ns < 3600) {
  2150. -                   $NZL_DST=1;
  2151. -               } else {
  2152. -                   $NZL_DST=0;
  2153. -               }
  2154. -               }
  2155. -           } else {
  2156. -               $NZL_DST=0;
  2157. -           }
  2158. -           } elseif ($mm == 10) {
  2159. -           if ($dd > 7) {
  2160. -               $NZL_DST=1;
  2161. -           } elseif ($dd >= ($dow+1)) {
  2162. -               if ($timezone) {
  2163. -               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  2164. -                   $NZL_DST=0;
  2165. -               } else {
  2166. -                   $NZL_DST=1;
  2167. -               }
  2168. -               } else {
  2169. -               if ($dow == 0 and $ns < 3600) {
  2170. -                   $NZL_DST=0;
  2171. -               } else {
  2172. -                   $NZL_DST=1;
  2173. -               }
  2174. -               }
  2175. -           } else {
  2176. -               $NZL_DST=0;
  2177. -           }
  2178. -           } # end of month checks                    
  2179. -       if ($DBX) {print "     DST: $NZL_DST\n";}
  2180. -       if ($NZL_DST) {$gmt_offset++;}
  2181. -       $AC_processed++;
  2182. -       }
  2183. -
  2184. -   if ( (!$AC_processed) and ($dst_range == 'LSS-FSA') )
  2185. -       {
  2186. -       if ($DBX) {print "     Last Sunday in September to First Sunday in April\n";}
  2187. -       #**********************************************************************
  2188. -       # LSS-FSA
  2189. -       #   2007+ NEW ZEALAND (country code 64)
  2190. -       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  2191. -       #       Standard time is in effect.
  2192. -       #     Based on last Sunday in September and first Sunday in April at 1 am.
  2193. -       #**********************************************************************
  2194. -      
  2195. -       $NZLN_DST=0;
  2196. -       $mm = $mon;
  2197. -       $dd = $mday;
  2198. -       $ns = $dsec;
  2199. -       $dow= $wday;
  2200. -
  2201. -       if ($mm < 4 || $mm > 9) {
  2202. -       $NZLN_DST=1;  
  2203. -       } elseif ($mm >= 5 && $mm <= 9) {
  2204. -       $NZLN_DST=0;  
  2205. -       } elseif ($mm == 4) {
  2206. -       if ($dd > 7) {
  2207. -           $NZLN_DST=0;  
  2208. -       } elseif ($dd >= ($dow+1)) {
  2209. -           if ($timezone) {
  2210. -           if ($dow == 0 && $ns < (3600+$timezone*3600)) {
  2211. -               $NZLN_DST=1;  
  2212. -           } else {
  2213. -               $NZLN_DST=0;  
  2214. -           }
  2215. -           } else {
  2216. -           if ($dow == 0 && $ns < 7200) {
  2217. -               $NZLN_DST=1;  
  2218. -           } else {
  2219. -               $NZLN_DST=0;  
  2220. -           }
  2221. -           }
  2222. -       } else {
  2223. -           $NZLN_DST=1;  
  2224. -       }
  2225. -       } elseif ($mm == 9) {
  2226. -       if ($dd < 25) {
  2227. -           $NZLN_DST=0;  
  2228. -       } elseif ($dd < ($dow+25)) {
  2229. -           $NZLN_DST=0;  
  2230. -       } elseif ($dow == 0) {
  2231. -           if ($timezone) { # UTC calculations
  2232. -           if ($ns < (3600+($timezone-1)*3600)) {
  2233. -               $NZLN_DST=0;  
  2234. -           } else {
  2235. -               $NZLN_DST=1;  
  2236. -           }
  2237. -           } else { # local time calculations
  2238. -           if ($ns < 3600) {
  2239. -               $NZLN_DST=0;  
  2240. -           } else {
  2241. -               $NZLN_DST=1;  
  2242. -           }
  2243. -           }
  2244. -       } else {
  2245. -           $NZLN_DST=1;  
  2246. -       }
  2247. -       } # end of month checks
  2248. -       if ($DBX) {print "     DST: $NZLN_DST\n";}
  2249. -       if ($NZLN_DST) {$gmt_offset++;}
  2250. -       $AC_processed++;
  2251. -       }
  2252. -
  2253. -   if ( (!$AC_processed) and ($dst_range == 'TSO-LSF') )
  2254. -       {
  2255. -       if ($DBX) {print "     Third Sunday October to Last Sunday February\n";}
  2256. -       #**********************************************************************
  2257. -       # TSO-LSF
  2258. -       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  2259. -       #       Standard time is in effect. Brazil
  2260. -       #     Based on Third Sunday October to Last Sunday February at 1 am.
  2261. -       #**********************************************************************
  2262. -          
  2263. -           $BZL_DST=0;
  2264. -           $mm = $mon;
  2265. -           $dd = $mday;
  2266. -           $ns = $dsec;
  2267. -           $dow= $wday;
  2268. -
  2269. -           if ($mm < 2 || $mm > 10) {
  2270. -           $BZL_DST=1;  
  2271. -           } elseif ($mm >= 3 and $mm <= 9) {
  2272. -           $BZL_DST=0;  
  2273. -           } elseif ($mm == 2) {
  2274. -           if ($dd < 22) {
  2275. -               $BZL_DST=1;  
  2276. -           } elseif ($dd < ($dow+22)) {
  2277. -               $BZL_DST=1;  
  2278. -           } elseif ($dow == 0) {
  2279. -               if ($timezone) { # UTC calculations
  2280. -               if ($ns < (3600+($timezone-1)*3600)) {
  2281. -                   $BZL_DST=1;  
  2282. -               } else {
  2283. -                   $BZL_DST=0;  
  2284. -               }
  2285. -               } else { # local time calculations
  2286. -               if ($ns < 3600) {
  2287. -                   $BZL_DST=1;  
  2288. -               } else {
  2289. -                   $BZL_DST=0;  
  2290. -               }
  2291. -               }
  2292. -           } else {
  2293. -               $BZL_DST=0;  
  2294. -           }
  2295. -           } elseif ($mm == 10) {
  2296. -           if ($dd < 22) {
  2297. -               $BZL_DST=0;  
  2298. -           } elseif ($dd < ($dow+22)) {
  2299. -               $BZL_DST=0;  
  2300. -           } elseif ($dow == 0) {
  2301. -               if ($timezone) { # UTC calculations
  2302. -               if ($ns < (3600+($timezone-1)*3600)) {
  2303. -                   $BZL_DST=0;  
  2304. -               } else {
  2305. -                   $BZL_DST=1;  
  2306. -               }
  2307. -               } else { # local time calculations
  2308. -               if ($ns < 3600) {
  2309. -                   $BZL_DST=0;  
  2310. -               } else {
  2311. -                   $BZL_DST=1;  
  2312. -               }
  2313. -               }
  2314. -           } else {
  2315. -               $BZL_DST=1;  
  2316. -           }
  2317. -           } # end of month checks
  2318. -       if ($DBX) {print "     DST: $BZL_DST\n";}
  2319. -       if ($BZL_DST) {$gmt_offset++;}
  2320. -       $AC_processed++;
  2321. -       }
  2322. -
  2323. -   if (!$AC_processed)
  2324. -       {
  2325. -       if ($DBX) {print "     No DST Method Found\n";}
  2326. -       if ($DBX) {print "     DST: 0\n";}
  2327. -       $AC_processed++;
  2328. -       }
  2329. -
  2330. -   return $gmt_offset;
  2331. -   }
  2332. -
  2333. -?>
  2334. -</TD></TR></TABLE>
  2335. +<?php
  2336. +# admin_listloader_third_gen.php - version 2.4
  2337. +#  (based upon - new_listloader_superL.php script)
  2338. +#
  2339. +# Copyright (C) 2011  Matt Florell,Joe Johnson <vicidial@gmail.com>    LICENSE: AGPLv2
  2340. +#
  2341. +# ViciDial web-based lead loader from formatted file
  2342. +#
  2343. +# CHANGES
  2344. +# 50602-1640 - First version created by Joe Johnson
  2345. +# 51128-1108 - Removed PHP global vars requirement
  2346. +# 60113-1603 - Fixed a few bugs in Excel import
  2347. +# 60421-1624 - check GET/POST vars lines with isset to not trigger PHP NOTICES
  2348. +# 60616-1240 - added listID override
  2349. +# 60616-1604 - added gmt lookup for each lead
  2350. +# 60619-1651 - Added variable filtering to eliminate SQL injection attack threat
  2351. +# 60822-1121 - fixed for nonwritable directories
  2352. +# 60906-1100 - added filter of non-digits in alt_phone field
  2353. +# 61110-1222 - added new USA-Canada DST scheme and Brazil DST scheme
  2354. +# 61128-1149 - added postal code GMT lookup and duplicate check options
  2355. +# 70417-1059 - Fixed default phone_code bug
  2356. +# 70510-1518 - Added campaign and system duplicate check and phonecode override
  2357. +# 80428-0417 - UTF8 changes
  2358. +# 80514-1030 - removed filesize limit and raised number of errors to be displayed
  2359. +# 80713-0023 - added last_local_call_time field default of 2008-01-01
  2360. +# 81011-2009 - a few bug fixes
  2361. +# 90309-1831 - Added admin_log logging
  2362. +# 90310-2128 - Added admin header
  2363. +# 90508-0644 - Changed to PHP long tags
  2364. +# 90522-0506 - Security fix
  2365. +# 90721-1339 - Added rank and owner as vicidial_list fields
  2366. +# 91112-0616 - Added title/alt-phone duplicate checking
  2367. +# 100118-0543 - Added new Australian and New Zealand DST schemes (FSO-FSA and LSS-FSA)
  2368. +# 100621-1026 - Added admin_web_directory variable
  2369. +# 100630-1609 - Added a check for invalid ListIds and filtered out ' " ; ` \ from the field <mikec>
  2370. +# 100705-1507 - Added custom fields to field chooser, only when liast_id_override is used and only with TXT and CSV file formats
  2371. +# 100706-1250 - Forked script to create new script that will only load TXT(tab-
  2372. +#              delimited files) and use a perl script to convert others to TXT
  2373. +# 100707-1040 - Converted List Id Override and Phone Code Override to drop downs <mikec>
  2374. +# 100707-1156 - Made it so you cannot submit with no lead file selected. Also fixed Start Over Link <mikec>
  2375. +# 100712-1416 - Added entry_list_id field to vicidial_list to preserve link to custom fields if any
  2376. +# 100728-0900 - Filtered uploaded filenames for unsupported characters
  2377. +# 110424-0926 - Added option for time zone code in the owner field
  2378. +# 110705-1947 - Added USACAN check for prefix and areacode
  2379. +#
  2380. +
  2381. +$version = '2.4-41';
  2382. +$build = '110705-1947';
  2383. +
  2384. +
  2385. +require("dbconnect.php");
  2386. +
  2387. +
  2388. +$US='_';
  2389. +
  2390. +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
  2391. +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
  2392. +$PHP_SELF=$_SERVER['PHP_SELF'];
  2393. +$leadfile=$_FILES["leadfile"];
  2394. +   $LF_orig = $_FILES['leadfile']['name'];
  2395. +   $LF_path = $_FILES['leadfile']['tmp_name'];
  2396. +if (isset($_GET["submit_file"]))           {$submit_file=$_GET["submit_file"];}
  2397. +   elseif (isset($_POST["submit_file"]))   {$submit_file=$_POST["submit_file"];}
  2398. +if (isset($_GET["submit"]))                {$submit=$_GET["submit"];}
  2399. +   elseif (isset($_POST["submit"]))    {$submit=$_POST["submit"];}
  2400. +if (isset($_GET["SUBMIT"]))                {$SUBMIT=$_GET["SUBMIT"];}
  2401. +   elseif (isset($_POST["SUBMIT"]))    {$SUBMIT=$_POST["SUBMIT"];}
  2402. +if (isset($_GET["leadfile_name"]))         {$leadfile_name=$_GET["leadfile_name"];}
  2403. +   elseif (isset($_POST["leadfile_name"])) {$leadfile_name=$_POST["leadfile_name"];}
  2404. +if (isset($_FILES["leadfile"]))                {$leadfile_name=$_FILES["leadfile"]['name'];}
  2405. +if (isset($_GET["file_layout"]))               {$file_layout=$_GET["file_layout"];}
  2406. +   elseif (isset($_POST["file_layout"]))       {$file_layout=$_POST["file_layout"];}
  2407. +if (isset($_GET["OK_to_process"]))             {$OK_to_process=$_GET["OK_to_process"];}
  2408. +   elseif (isset($_POST["OK_to_process"]))     {$OK_to_process=$_POST["OK_to_process"];}
  2409. +if (isset($_GET["vendor_lead_code_field"]))                {$vendor_lead_code_field=$_GET["vendor_lead_code_field"];}
  2410. +   elseif (isset($_POST["vendor_lead_code_field"]))    {$vendor_lead_code_field=$_POST["vendor_lead_code_field"];}
  2411. +if (isset($_GET["source_id_field"]))           {$source_id_field=$_GET["source_id_field"];}
  2412. +   elseif (isset($_POST["source_id_field"]))   {$source_id_field=$_POST["source_id_field"];}
  2413. +if (isset($_GET["list_id_field"]))             {$list_id_field=$_GET["list_id_field"];}
  2414. +   elseif (isset($_POST["list_id_field"]))     {$list_id_field=$_POST["list_id_field"];}
  2415. +if (isset($_GET["phone_code_field"]))          {$phone_code_field=$_GET["phone_code_field"];}
  2416. +   elseif (isset($_POST["phone_code_field"]))  {$phone_code_field=$_POST["phone_code_field"];}
  2417. +if (isset($_GET["phone_number_field"]))                {$phone_number_field=$_GET["phone_number_field"];}
  2418. +   elseif (isset($_POST["phone_number_field"]))    {$phone_number_field=$_POST["phone_number_field"];}
  2419. +if (isset($_GET["title_field"]))               {$title_field=$_GET["title_field"];}
  2420. +   elseif (isset($_POST["title_field"]))       {$title_field=$_POST["title_field"];}
  2421. +if (isset($_GET["first_name_field"]))          {$first_name_field=$_GET["first_name_field"];}
  2422. +   elseif (isset($_POST["first_name_field"]))  {$first_name_field=$_POST["first_name_field"];}
  2423. +if (isset($_GET["middle_initial_field"]))          {$middle_initial_field=$_GET["middle_initial_field"];}
  2424. +   elseif (isset($_POST["middle_initial_field"]))  {$middle_initial_field=$_POST["middle_initial_field"];}
  2425. +if (isset($_GET["last_name_field"]))           {$last_name_field=$_GET["last_name_field"];}
  2426. +   elseif (isset($_POST["last_name_field"]))   {$last_name_field=$_POST["last_name_field"];}
  2427. +if (isset($_GET["address1_field"]))                {$address1_field=$_GET["address1_field"];}
  2428. +   elseif (isset($_POST["address1_field"]))    {$address1_field=$_POST["address1_field"];}
  2429. +if (isset($_GET["address2_field"]))                {$address2_field=$_GET["address2_field"];}
  2430. +   elseif (isset($_POST["address2_field"]))    {$address2_field=$_POST["address2_field"];}
  2431. +if (isset($_GET["address3_field"]))                {$address3_field=$_GET["address3_field"];}
  2432. +   elseif (isset($_POST["address3_field"]))    {$address3_field=$_POST["address3_field"];}
  2433. +if (isset($_GET["city_field"]))                    {$city_field=$_GET["city_field"];}
  2434. +   elseif (isset($_POST["city_field"]))        {$city_field=$_POST["city_field"];}
  2435. +if (isset($_GET["state_field"]))               {$state_field=$_GET["state_field"];}
  2436. +   elseif (isset($_POST["state_field"]))       {$state_field=$_POST["state_field"];}
  2437. +if (isset($_GET["province_field"]))                {$province_field=$_GET["province_field"];}
  2438. +   elseif (isset($_POST["province_field"]))        {$province_field=$_POST["province_field"];}
  2439. +if (isset($_GET["postal_code_field"]))             {$postal_code_field=$_GET["postal_code_field"];}
  2440. +   elseif (isset($_POST["postal_code_field"]))     {$postal_code_field=$_POST["postal_code_field"];}
  2441. +if (isset($_GET["country_code_field"]))                {$country_code_field=$_GET["country_code_field"];}
  2442. +   elseif (isset($_POST["country_code_field"]))    {$country_code_field=$_POST["country_code_field"];}
  2443. +if (isset($_GET["gender_field"]))              {$gender_field=$_GET["gender_field"];}
  2444. +   elseif (isset($_POST["gender_field"]))      {$gender_field=$_POST["gender_field"];}
  2445. +if (isset($_GET["date_of_birth_field"]))           {$date_of_birth_field=$_GET["date_of_birth_field"];}
  2446. +   elseif (isset($_POST["date_of_birth_field"]))   {$date_of_birth_field=$_POST["date_of_birth_field"];}
  2447. +if (isset($_GET["alt_phone_field"]))           {$alt_phone_field=$_GET["alt_phone_field"];}
  2448. +   elseif (isset($_POST["alt_phone_field"]))   {$alt_phone_field=$_POST["alt_phone_field"];}
  2449. +if (isset($_GET["email_field"]))               {$email_field=$_GET["email_field"];}
  2450. +   elseif (isset($_POST["email_field"]))       {$email_field=$_POST["email_field"];}
  2451. +if (isset($_GET["security_phrase_field"]))         {$security_phrase_field=$_GET["security_phrase_field"];}
  2452. +   elseif (isset($_POST["security_phrase_field"])) {$security_phrase_field=$_POST["security_phrase_field"];}
  2453. +if (isset($_GET["comments_field"]))                {$comments_field=$_GET["comments_field"];}
  2454. +   elseif (isset($_POST["comments_field"]))    {$comments_field=$_POST["comments_field"];}
  2455. +if (isset($_GET["rank_field"]))                    {$rank_field=$_GET["rank_field"];}
  2456. +   elseif (isset($_POST["rank_field"]))        {$rank_field=$_POST["rank_field"];}
  2457. +if (isset($_GET["owner_field"]))               {$owner_field=$_GET["owner_field"];}
  2458. +   elseif (isset($_POST["owner_field"]))       {$owner_field=$_POST["owner_field"];}
  2459. +if (isset($_GET["list_id_override"]))          {$list_id_override=$_GET["list_id_override"];}
  2460. +   elseif (isset($_POST["list_id_override"]))  {$list_id_override=$_POST["list_id_override"];}
  2461. +   $list_id_override = (preg_replace("/\D/","",$list_id_override));
  2462. +if (isset($_GET["lead_file"]))                 {$lead_file=$_GET["lead_file"];}
  2463. +   elseif (isset($_POST["lead_file"]))         {$lead_file=$_POST["lead_file"];}
  2464. +if (isset($_GET["dupcheck"]))              {$dupcheck=$_GET["dupcheck"];}
  2465. +   elseif (isset($_POST["dupcheck"]))      {$dupcheck=$_POST["dupcheck"];}
  2466. +if (isset($_GET["postalgmt"]))             {$postalgmt=$_GET["postalgmt"];}
  2467. +   elseif (isset($_POST["postalgmt"]))     {$postalgmt=$_POST["postalgmt"];}
  2468. +if (isset($_GET["phone_code_override"]))           {$phone_code_override=$_GET["phone_code_override"];}
  2469. +   elseif (isset($_POST["phone_code_override"]))   {$phone_code_override=$_POST["phone_code_override"];}
  2470. +   $phone_code_override = (preg_replace("/\D/","",$phone_code_override));
  2471. +if (isset($_GET["DB"]))                    {$DB=$_GET["DB"];}
  2472. +   elseif (isset($_POST["DB"]))        {$DB=$_POST["DB"];}
  2473. +if (isset($_GET["usacan_check"]))          {$usacan_check=$_GET["usacan_check"];}
  2474. +   elseif (isset($_POST["usacan_check"]))  {$usacan_check=$_POST["usacan_check"];}
  2475. +
  2476. +
  2477. +# if the didnt select an over ride wipe out in_file
  2478. +if ( $list_id_override == "in_file" ) { $list_id_override = ""; }
  2479. +if ( $phone_code_override == "in_file" ) { $phone_code_override = ""; }
  2480. +
  2481. +# $country_field=$_GET["country_field"];                   if (!$country_field) {$country_field=$_POST["country_field"];}
  2482. +
  2483. +### REGEX to prevent weird characters from ending up in the fields
  2484. +$field_regx = "['\"`\\;]";
  2485. +
  2486. +$vicidial_list_fields = '|lead_id|vendor_lead_code|source_id|list_id|gmt_offset_now|called_since_last_reset|phone_code|phone_number|title|first_name|middle_initial|last_name|address1|address2|address3|city|state|province|postal_code|country_code|gender|date_of_birth|alt_phone|email|security_phrase|comments|called_count|last_local_call_time|rank|owner|entry_list_id|';
  2487. +
  2488. +#############################################
  2489. +##### START SYSTEM_SETTINGS LOOKUP #####
  2490. +$stmt = "SELECT use_non_latin,admin_web_directory,custom_fields_enabled FROM system_settings;";
  2491. +$rslt=mysql_query($stmt, $link);
  2492. +if ($DB) {echo "$stmt\n";}
  2493. +$qm_conf_ct = mysql_num_rows($rslt);
  2494. +if ($qm_conf_ct > 0)
  2495. +   {
  2496. +   $row=mysql_fetch_row($rslt);
  2497. +   $non_latin =                $row[0];
  2498. +   $admin_web_directory =      $row[1];
  2499. +   $custom_fields_enabled =    $row[2];
  2500. +   }
  2501. +##### END SETTINGS LOOKUP #####
  2502. +###########################################
  2503. +
  2504. +if ($non_latin < 1)
  2505. +   {
  2506. +   $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER);
  2507. +   $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW);
  2508. +   $list_id_override = ereg_replace("[^0-9]","",$list_id_override);
  2509. +   }
  2510. +else
  2511. +   {
  2512. +   $PHP_AUTH_PW = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_PW);
  2513. +   $PHP_AUTH_USER = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_USER);
  2514. +   }
  2515. +
  2516. +$STARTtime = date("U");
  2517. +$TODAY = date("Y-m-d");
  2518. +$NOW_TIME = date("Y-m-d H:i:s");
  2519. +$FILE_datetime = $STARTtime;
  2520. +
  2521. +$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7;";
  2522. +if ($DB) {echo "|$stmt|\n";}
  2523. +if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
  2524. +$rslt=mysql_query($stmt, $link);
  2525. +$row=mysql_fetch_row($rslt);
  2526. +$auth=$row[0];
  2527. +
  2528. +if ($WeBRooTWritablE > 0) {$fp = fopen ("./project_auth_entries.txt", "a");}
  2529. +$date = date("r");
  2530. +$ip = getenv("REMOTE_ADDR");
  2531. +$browser = getenv("HTTP_USER_AGENT");
  2532. +
  2533. +if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth))
  2534. +   {
  2535. +    Header("WWW-Authenticate: Basic realm=\"VICIDIAL-LEAD-LOADER\"");
  2536. +    Header("HTTP/1.0 401 Unauthorized");
  2537. +    echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n";
  2538. +    exit;
  2539. +   }
  2540. +else
  2541. +   {
  2542. +   header ("Content-type: text/html; charset=utf-8");
  2543. +   header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
  2544. +   header ("Pragma: no-cache");                          // HTTP/1.0
  2545. +
  2546. +   if($auth>0)
  2547. +       {
  2548. +       $office_no=strtoupper($PHP_AUTH_USER);
  2549. +       $password=strtoupper($PHP_AUTH_PW);
  2550. +           $stmt="SELECT load_leads from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'";
  2551. +           $rslt=mysql_query($stmt, $link);
  2552. +           $row=mysql_fetch_row($rslt);
  2553. +           $LOGload_leads              =$row[0];
  2554. +
  2555. +       if ($LOGload_leads < 1)
  2556. +           {
  2557. +           echo "You do not have permissions to load leads\n";
  2558. +           exit;
  2559. +           }
  2560. +       if ($WeBRooTWritablE > 0)
  2561. +           {
  2562. +           fwrite ($fp, "LIST_LOAD|GOOD|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|$LOGfullname|\n");
  2563. +           fclose($fp);
  2564. +           }
  2565. +       }
  2566. +   else
  2567. +       {
  2568. +       if ($WeBRooTWritablE > 0)
  2569. +           {
  2570. +           fwrite ($fp, "LIST_LOAD|FAIL|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|\n");
  2571. +           fclose($fp);
  2572. +           }
  2573. +       }
  2574. +   }
  2575. +
  2576. +
  2577. +$script_name = getenv("SCRIPT_NAME");
  2578. +$server_name = getenv("SERVER_NAME");
  2579. +$server_port = getenv("SERVER_PORT");
  2580. +if (eregi("443",$server_port)) {$HTTPprotocol = 'https://';}
  2581. +   else {$HTTPprotocol = 'http://';}
  2582. +$admDIR = "$HTTPprotocol$server_name$script_name";
  2583. +$admDIR = eregi_replace('admin_listloader_third_gen.php','',$admDIR);
  2584. +$admSCR = 'admin.php';
  2585. +$NWB = " &nbsp; <a href=\"javascript:openNewWindow('$admDIR$admSCR?ADD=99999";
  2586. +$NWE = "')\"><IMG SRC=\"help.gif\" WIDTH=20 HEIGHT=20 BORDER=0 ALT=\"HELP\" ALIGN=TOP></A>";
  2587. +
  2588. +$secX = date("U");
  2589. +$hour = date("H");
  2590. +$min = date("i");
  2591. +$sec = date("s");
  2592. +$mon = date("m");
  2593. +$mday = date("d");
  2594. +$year = date("Y");
  2595. +$isdst = date("I");
  2596. +$Shour = date("H");
  2597. +$Smin = date("i");
  2598. +$Ssec = date("s");
  2599. +$Smon = date("m");
  2600. +$Smday = date("d");
  2601. +$Syear = date("Y");
  2602. +$pulldate0 = "$year-$mon-$mday $hour:$min:$sec";
  2603. +$inSD = $pulldate0;
  2604. +$dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
  2605. +
  2606. +### Grab Server GMT value from the database
  2607. +$stmt="SELECT local_gmt FROM servers where server_ip = '$server_ip';";
  2608. +$rslt=mysql_query($stmt, $link);
  2609. +$gmt_recs = mysql_num_rows($rslt);
  2610. +if ($gmt_recs > 0)
  2611. +   {
  2612. +   $row=mysql_fetch_row($rslt);
  2613. +   $DBSERVER_GMT       =       "$row[0]";
  2614. +   if (strlen($DBSERVER_GMT)>0)    {$SERVER_GMT = $DBSERVER_GMT;}
  2615. +   if ($isdst) {$SERVER_GMT++;}
  2616. +   }
  2617. +else
  2618. +   {
  2619. +   $SERVER_GMT = date("O");
  2620. +   $SERVER_GMT = eregi_replace("\+","",$SERVER_GMT);
  2621. +   $SERVER_GMT = ($SERVER_GMT + 0);
  2622. +   $SERVER_GMT = ($SERVER_GMT / 100);
  2623. +   }
  2624. +
  2625. +$LOCAL_GMT_OFF = $SERVER_GMT;
  2626. +$LOCAL_GMT_OFF_STD = $SERVER_GMT;
  2627. +
  2628. +#if ($DB) {print "SEED TIME  $secX      :   $year-$mon-$mday $hour:$min:$sec  LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";}
  2629. +
  2630. +
  2631. +echo "<html>\n";
  2632. +echo "<head>\n";
  2633. +echo "<!-- VERSION: $version     BUILD: $build -->\n";
  2634. +echo "<!-- SEED TIME  $secX:   $year-$mon-$mday $hour:$min:$sec  LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF  DST: $isdst -->\n";
  2635. +
  2636. +function macfontfix($fontsize)
  2637. +   {
  2638. +   $browser = getenv("HTTP_USER_AGENT");
  2639. +   $pctype = explode("(", $browser);
  2640. +   if (ereg("Mac",$pctype[1]))
  2641. +       {
  2642. +       /* Browser is a Mac.  If not Netscape 6, raise fonts */
  2643. +       $blownbrowser = explode('/', $browser);
  2644. +       $ver = explode(' ', $blownbrowser[1]);
  2645. +       $ver = $ver[0];
  2646. +       if ($ver >= 5.0) return $fontsize; else return ($fontsize+2);
  2647. +       }
  2648. +   else return $fontsize;  /* Browser is not a Mac - don't touch fonts */
  2649. +   }
  2650. +
  2651. +echo "<style type=\"text/css\">\n
  2652. +<!--\n
  2653. +.title {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(18)."pt}\n
  2654. +.standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt}\n
  2655. +.small_standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(8)."pt}\n
  2656. +.tiny_standard {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(6)."pt}\n
  2657. +.standard_bold {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold}\n
  2658. +.standard_header {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(14)."pt; font-weight: bold}\n
  2659. +.standard_bold_highlight {  font-family: Arial, Helvetica, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold; color: white; BACKGROUND-COLOR: black}\n
  2660. +.standard_bold_blue_highlight {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; BACKGROUND-COLOR: blue}\n
  2661. +A.employee_standard {  font-family: garamond, sans-serif; font-size: ".macfontfix(10)."pt; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none}\n
  2662. +.employee_standard {  font-family: garamond, sans-serif; font-size: ".macfontfix(10)."pt; font-weight: bold}\n
  2663. +.employee_title {  font-family: Garamond, sans-serif; font-size: ".macfontfix(14)."pt; font-weight: bold}\n
  2664. +\\\\-->\n
  2665. +</style>\n";
  2666. +
  2667. +?>
  2668. +
  2669. +
  2670. +<script language="JavaScript1.2">
  2671. +function openNewWindow(url)
  2672. +   {
  2673. +   window.open (url,"",'width=700,height=300,scrollbars=yes,menubar=yes,address=yes');
  2674. +   }
  2675. +function ShowProgress(good, bad, total, dup, inv, post)
  2676. +   {
  2677. +   parent.lead_count.document.open();
  2678. +   parent.lead_count.document.write('<html><body><table border=0 width=200 cellpadding=10 cellspacing=0 align=center valign=top><tr bgcolor="#000000"><th colspan=2><font face="arial, helvetica" size=3 color=white>Current file status:</font></th></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Good:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+good+'</B></font></td></tr><tr bgcolor="#990000"><td align=right><font face="arial, helvetica" size=2 color=white><B>Bad:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+bad+'</B></font></td></tr><tr bgcolor="#000099"><td align=right><font face="arial, helvetica" size=2 color=white><B>Total:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+total+'</B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B> &nbsp; </B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B> &nbsp; </B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Duplicate:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+dup+'</B></font></td></tr></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Invalid:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+inv+'</B></font></td></tr><tr bgcolor="#009900"><td align=right><font face="arial, helvetica" size=2 color=white><B>Postal Match:</B></font></td><td align=left><font face="arial, helvetica" size=2 color=white><B>'+post+'</B></font></td></tr></table><body></html>');
  2679. +   parent.lead_count.document.close();
  2680. +   }
  2681. +function ParseFileName()
  2682. +   {
  2683. +   if (!document.forms[0].OK_to_process)
  2684. +       {  
  2685. +       var endstr=document.forms[0].leadfile.value.lastIndexOf('\\');
  2686. +       if (endstr>-1)
  2687. +           {
  2688. +           endstr++;
  2689. +           var filename=document.forms[0].leadfile.value.substring(endstr);
  2690. +           document.forms[0].leadfile_name.value=filename;
  2691. +           }
  2692. +       }
  2693. +   }
  2694. +
  2695. +</script>
  2696. +<title>ADMINISTRATION: Lead Loader</title>
  2697. +</head>
  2698. +<BODY BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>
  2699. +
  2700. +<?php
  2701. +$short_header=1;
  2702. +
  2703. +require("admin_header.php");
  2704. +
  2705. +echo "<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
  2706. +
  2707. +if ( (!$OK_to_process) or ( ($leadfile) and ($file_layout!="standard") ) )
  2708. +   {
  2709. +   ?>
  2710. +   <form action=<?php echo $PHP_SELF ?> method=post onSubmit="ParseFileName()" enctype="multipart/form-data">
  2711. +   <input type=hidden name='leadfile_name' value="<?php echo $leadfile_name ?>">
  2712. +   <input type=hidden name='DB' value="<?php echo $DB ?>">
  2713. +   <?php
  2714. +   if ($file_layout!="custom")
  2715. +       {
  2716. +       ?>
  2717. +       <table align=center width="700" border=0 cellpadding=5 cellspacing=0 bgcolor=#D9E6FE>
  2718. +         <tr>
  2719. +           <td align=right width="35%"><B><font face="arial, helvetica" size=2>Load leads from this file:</font></B></td>
  2720. +           <td align=left width="65%"><input type=file name="leadfile" value="<?php echo $leadfile ?>"> <?php echo "$NWB#vicidial_list_loader$NWE"; ?></td>
  2721. +         </tr>
  2722. +         <tr>
  2723. +           <td align=right width="25%"><font face="arial, helvetica" size=2>List ID Override: </font></td>
  2724. +           <td align=left width="75%"><font face="arial, helvetica" size=1>
  2725. +           <select name='list_id_override'>
  2726. +           <option value='in_file' selected='yes'>Load from Lead File</option>
  2727. +           <?php
  2728. +           $stmt="SELECT list_id, list_name from vicidial_lists order by list_id;";
  2729. +           $rslt=mysql_query($stmt, $link);
  2730. +           $num_rows = mysql_num_rows($rslt);
  2731. +
  2732. +           $count=0;
  2733. +           while ( $num_rows > $count )
  2734. +               {
  2735. +               $row = mysql_fetch_row($rslt);
  2736. +               echo "<option value=\'$row[0]\'>$row[0] - $row[1]</option>\n";
  2737. +               $count++;
  2738. +               }
  2739. +           ?>
  2740. +           </select>
  2741. +           </font></td>
  2742. +         </tr>
  2743. +         <tr>
  2744. +           <td align=right width="25%"><font face="arial, helvetica" size=2>Phone Code Override: </font></td>
  2745. +           <td align=left width="75%"><font face="arial, helvetica" size=1>
  2746. +           <select name='phone_code_override'>
  2747. +                        <option value='in_file' selected='yes'>Load from Lead File</option>
  2748. +           <?php
  2749. +           $stmt="select distinct country_code, country from vicidial_phone_codes;";
  2750. +           $rslt=mysql_query($stmt, $link);
  2751. +           $num_rows = mysql_num_rows($rslt);
  2752. +          
  2753. +           $count=0;
  2754. +                   while ( $num_rows > $count )
  2755. +               {
  2756. +               $row = mysql_fetch_row($rslt);
  2757. +               echo "<option value=\'$row[0]\'>$row[0] - $row[1]</option>\n";
  2758. +               $count++;
  2759. +               }
  2760. +           ?>
  2761. +           </select>
  2762. +           </font></td>
  2763. +         </tr>
  2764. +         <tr>
  2765. +           <td align=right><B><font face="arial, helvetica" size=2>File layout to use:</font></B></td>
  2766. +           <td align=left><font face="arial, helvetica" size=2><input type=radio name="file_layout" value="standard" checked>Standard Format&nbsp;&nbsp;&nbsp;&nbsp;<input type=radio name="file_layout" value="custom">Custom layout</td>
  2767. +         </tr>
  2768. +         <tr>
  2769. +           <td align=right width="25%"><font face="arial, helvetica" size=2>Lead Duplicate Check: </font></td>
  2770. +           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=dupcheck>
  2771. +           <option selected value="NONE">NO DUPLICATE CHECK</option>
  2772. +           <option value="DUPLIST">CHECK FOR DUPLICATES BY PHONE IN LIST ID</option>
  2773. +           <option value="DUPCAMP">CHECK FOR DUPLICATES BY PHONE IN ALL CAMPAIGN LISTS</option>
  2774. +           <option value="DUPSYS">CHECK FOR DUPLICATES BY PHONE IN ENTIRE SYSTEM</option>
  2775. +           <option value="DUPTITLEALTPHONELIST">CHECK FOR DUPLICATES BY TITLE/ALT-PHONE IN LIST ID</option>
  2776. +           <option value="DUPTITLEALTPHONESYS">CHECK FOR DUPLICATES BY TITLE/ALT-PHONE IN ENTIRE SYSTEM</option>
  2777. +           </select></td>
  2778. +         </tr>
  2779. +         <tr>
  2780. +           <td align=right width="25%"><font face="arial, helvetica" size=2>USA-Canada Check: </font></td>
  2781. +           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=usacan_check>
  2782. +           <option selected value="NONE">NO USACAN VALID CHECK</option>
  2783. +           <option value="PREFIX">CHECK FOR VALID PREFIX</option>
  2784. +           <option value="AREACODE">CHECK FOR VALID AREACODE</option>
  2785. +           <option value="PREFIX_AREACODE">CHECK FOR VALID PREFIX and AREACODE</option>
  2786. +           </select></td>
  2787. +         </tr>
  2788. +         <tr>
  2789. +           <td align=right width="25%"><font face="arial, helvetica" size=2>Lead Time Zone Lookup: </font></td>
  2790. +           <td align=left width="75%"><font face="arial, helvetica" size=1><select size=1 name=postalgmt><option selected value="AREA">COUNTRY CODE AND AREA CODE ONLY</option><option value="POSTAL">POSTAL CODE FIRST</option><option value="TZCODE">OWNER TIME ZONE CODE FIRST</option></select></td>
  2791. +         </tr>
  2792. +       <tr>
  2793. +           <td align=center colspan=2><input type=submit value="SUBMIT" name='submit_file'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button onClick="javascript:document.location='admin_listloader_third_gen.php'" value="START OVER" name='reload_page'></td>
  2794. +         </tr>
  2795. +         <tr><td align=left><font size=1> &nbsp; &nbsp; &nbsp; &nbsp; <a href="admin.php?ADD=100" target="_parent">BACK TO ADMIN</a> &nbsp; &nbsp; &nbsp; &nbsp; <a href="./new_listloader_superL.php">Old Lead Loader</a> &nbsp; &nbsp; </font></td><td align=right><font size=1>LIST LOADER 3rd Gen- &nbsp; &nbsp; VERSION: <?php echo $version ?> &nbsp; &nbsp; BUILD: <?php echo $build ?> &nbsp; &nbsp; </td></tr>
  2796. +       </table>
  2797. +       <?php
  2798. +
  2799. +       }
  2800. +   }
  2801. +else
  2802. +   {
  2803. +   ?>
  2804. +   <table align=center width="700" border=0 cellpadding=5 cellspacing=0 bgcolor=#D9E6FE>
  2805. +   <tr>
  2806. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead file:</font></B></td>
  2807. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $leadfile_name ?></font></td>
  2808. +   </tr>
  2809. +   <tr>
  2810. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>List ID Override:</font></B></td>
  2811. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $list_id_override ?></font></td>
  2812. +   </tr>
  2813. +   <tr>
  2814. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Phone Code Override:</font></B></td>
  2815. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $phone_code_override ?></font></td>
  2816. +   </tr>
  2817. +   <tr>
  2818. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>USA-Canada Check:</font></B></td>
  2819. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $usacan_check ?></font></td>
  2820. +   </tr>
  2821. +   <tr>
  2822. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead Duplicate Check:</font></B></td>
  2823. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $dupcheck ?></font></td>
  2824. +   </tr>
  2825. +   <tr>
  2826. +   <td align=right width="35%"><B><font face="arial, helvetica" size=2>Lead Time Zone Lookup:</font></B></td>
  2827. +   <td align=left width="75%"><font face="arial, helvetica" size=2><?php echo $postalgmt ?></font></td>
  2828. +   </tr>
  2829. +
  2830. +   <tr>
  2831. +   <td align=center colspan=2><B><font face="arial, helvetica" size=2>
  2832. +   <form action=<?php echo $PHP_SELF ?> method=post onSubmit="ParseFileName()" enctype="multipart/form-data">
  2833. +   <input type=hidden name='leadfile_name' value="<?php echo $leadfile_name ?>">
  2834. +   <input type=hidden name='DB' value="<?php echo $DB ?>">
  2835. +   <a href="admin_listloader_third_gen.php">Load Another Lead File</a> &nbsp; &nbsp; &nbsp; &nbsp;</font></B> <font size=1>VERSION: <?php echo $version ?> &nbsp; &nbsp; BUILD: <?php echo $build ?>
  2836. +   </font></td>
  2837. +   </tr></table>
  2838. +   <BR><BR><BR><BR>
  2839. +   <?php
  2840. +   }
  2841. +
  2842. +
  2843. +
  2844. +##### BEGIN custom fields submission #####
  2845. +if ($OK_to_process)
  2846. +   {
  2847. +   print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true;document.forms[0].list_id_override.disabled=true;document.forms[0].phone_code_override.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script>";
  2848. +   flush();
  2849. +   $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  2850. +
  2851. +   $file=fopen("$lead_file", "r");
  2852. +   if ($WeBRooTWritablE > 0)
  2853. +       {
  2854. +       $stmt_file=fopen("listloader_stmts.txt", "w");
  2855. +       }
  2856. +   $buffer=fgets($file, 4096);
  2857. +   $tab_count=substr_count($buffer, "\t");
  2858. +   $pipe_count=substr_count($buffer, "|");
  2859. +
  2860. +   if ($tab_count>$pipe_count) {$delimiter="\t";  $delim_name="tab";} else {$delimiter="|";  $delim_name="pipe";}
  2861. +   $field_check=explode($delimiter, $buffer);
  2862. +
  2863. +   if (count($field_check)>=2)
  2864. +       {
  2865. +       flush();
  2866. +       $file=fopen("$lead_file", "r");
  2867. +       print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing file...\n";
  2868. +
  2869. +       if (strlen($list_id_override)>0)
  2870. +           {
  2871. +           print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  2872. +           }
  2873. +
  2874. +       if (strlen($phone_code_override)>0)
  2875. +           {
  2876. +           print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>";
  2877. +           }
  2878. +
  2879. +       if ($custom_fields_enabled > 0)
  2880. +           {
  2881. +           $tablecount_to_print=0;
  2882. +           $fieldscount_to_print=0;
  2883. +           $fields_to_print=0;
  2884. +
  2885. +           $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";";
  2886. +           if ($DB>0) {echo "$stmt\n";}
  2887. +           $rslt=mysql_query($stmt, $link);
  2888. +           $tablecount_to_print = mysql_num_rows($rslt);
  2889. +
  2890. +           if ($tablecount_to_print > 0)
  2891. +               {
  2892. +               $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';";
  2893. +               if ($DB>0) {echo "$stmt\n";}
  2894. +               $rslt=mysql_query($stmt, $link);
  2895. +               $fieldscount_to_print = mysql_num_rows($rslt);
  2896. +
  2897. +               if ($fieldscount_to_print > 0)
  2898. +                   {
  2899. +                   $stmt="SELECT field_label,field_type from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;";
  2900. +                   if ($DB>0) {echo "$stmt\n";}
  2901. +                   $rslt=mysql_query($stmt, $link);
  2902. +                   $fields_to_print = mysql_num_rows($rslt);
  2903. +                   $fields_list='';
  2904. +                   $o=0;
  2905. +                   while ($fields_to_print > $o)
  2906. +                       {
  2907. +                       $rowx=mysql_fetch_row($rslt);
  2908. +                       $A_field_label[$o] =    $rowx[0];
  2909. +                       $A_field_type[$o] =     $rowx[1];
  2910. +                       $A_field_value[$o] =    '';
  2911. +                       $o++;
  2912. +                       }
  2913. +                   }
  2914. +               }
  2915. +           }
  2916. +
  2917. +       while (!feof($file))
  2918. +           {
  2919. +           $record++;
  2920. +           $buffer=rtrim(fgets($file, 4096));
  2921. +           $buffer=stripslashes($buffer);
  2922. +
  2923. +           if (strlen($buffer)>0)
  2924. +               {
  2925. +               $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  2926. +
  2927. +               $pulldate=date("Y-m-d H:i:s");
  2928. +               $entry_date =           "$pulldate";
  2929. +               $modify_date =          "";
  2930. +               $status =               "NEW";
  2931. +               $user ="";
  2932. +               $vendor_lead_code =     $row[$vendor_lead_code_field];
  2933. +               $source_code =          $row[$source_id_field];
  2934. +               $source_id=$source_code;
  2935. +               $list_id =              $row[$list_id_field];
  2936. +               $gmt_offset =           '0';
  2937. +               $called_since_last_reset='N';
  2938. +               $phone_code =           eregi_replace("[^0-9]", "", $row[$phone_code_field]);
  2939. +               $phone_number =         eregi_replace("[^0-9]", "", $row[$phone_number_field]);
  2940. +               $title =                $row[$title_field];
  2941. +               $first_name =           $row[$first_name_field];
  2942. +               $middle_initial =       $row[$middle_initial_field];
  2943. +               $last_name =            $row[$last_name_field];
  2944. +               $address1 =             $row[$address1_field];
  2945. +               $address2 =             $row[$address2_field];
  2946. +               $address3 =             $row[$address3_field];
  2947. +               $city =$row[$city_field];
  2948. +               $state =                $row[$state_field];
  2949. +               $province =             $row[$province_field];
  2950. +               $postal_code =          $row[$postal_code_field];
  2951. +               $country_code =         $row[$country_code_field];
  2952. +               $gender =               $row[$gender_field];
  2953. +               $date_of_birth =        $row[$date_of_birth_field];
  2954. +               $alt_phone =            eregi_replace("[^0-9]", "", $row[$alt_phone_field]);
  2955. +               $email =                $row[$email_field];
  2956. +               $security_phrase =      $row[$security_phrase_field];
  2957. +               $comments =             trim($row[$comments_field]);
  2958. +               $rank =                 $row[$rank_field];
  2959. +               $owner =                $row[$owner_field];
  2960. +              
  2961. +               # replace ' " ` \ ; with nothing
  2962. +               $vendor_lead_code =     eregi_replace($field_regx, "", $vendor_lead_code);
  2963. +               $source_code =          eregi_replace($field_regx, "", $source_code);
  2964. +               $source_id =            eregi_replace($field_regx, "", $source_id);
  2965. +               $list_id =              eregi_replace($field_regx, "", $list_id);
  2966. +               $phone_code =           eregi_replace($field_regx, "", $phone_code);
  2967. +               $phone_number =         eregi_replace($field_regx, "", $phone_number);
  2968. +               $title =                eregi_replace($field_regx, "", $title);
  2969. +               $first_name =           eregi_replace($field_regx, "", $first_name);
  2970. +               $middle_initial =       eregi_replace($field_regx, "", $middle_initial);
  2971. +               $last_name =            eregi_replace($field_regx, "", $last_name);
  2972. +               $address1 =             eregi_replace($field_regx, "", $address1);
  2973. +               $address2 =             eregi_replace($field_regx, "", $address2);
  2974. +               $address3 =             eregi_replace($field_regx, "", $address3);
  2975. +               $city =                 eregi_replace($field_regx, "", $city);
  2976. +               $state =                eregi_replace($field_regx, "", $state);
  2977. +               $province =             eregi_replace($field_regx, "", $province);
  2978. +               $postal_code =          eregi_replace($field_regx, "", $postal_code);
  2979. +               $country_code =         eregi_replace($field_regx, "", $country_code);
  2980. +               $gender =               eregi_replace($field_regx, "", $gender);
  2981. +               $date_of_birth =        eregi_replace($field_regx, "", $date_of_birth);
  2982. +               $alt_phone =            eregi_replace($field_regx, "", $alt_phone);
  2983. +               $email =                eregi_replace($field_regx, "", $email);
  2984. +               $security_phrase =      eregi_replace($field_regx, "", $security_phrase);
  2985. +               $comments =             eregi_replace($field_regx, "", $comments);
  2986. +               $rank =                 eregi_replace($field_regx, "", $rank);
  2987. +               $owner =                eregi_replace($field_regx, "", $owner);
  2988. +              
  2989. +               $USarea =           substr($phone_number, 0, 3);
  2990. +
  2991. +               if (strlen($list_id_override)>0)
  2992. +                   {
  2993. +               #   print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  2994. +                   $list_id = $list_id_override;
  2995. +                   }
  2996. +               if (strlen($phone_code_override)>0)
  2997. +                   {
  2998. +                   $phone_code = $phone_code_override;
  2999. +                   }
  3000. +
  3001. +               ##### BEGIN custom fields columns list ###
  3002. +               $custom_SQL='';
  3003. +               if ($custom_fields_enabled > 0)
  3004. +                   {
  3005. +                   if ($tablecount_to_print > 0)
  3006. +                       {
  3007. +                       if ($fieldscount_to_print > 0)
  3008. +                           {
  3009. +                           $o=0;
  3010. +                           while ($fields_to_print > $o)
  3011. +                               {
  3012. +                               $A_field_value[$o] =    '';
  3013. +                               $field_name_id = $A_field_label[$o] . "_field";
  3014. +
  3015. +                           #   if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";}
  3016. +
  3017. +                               if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') )
  3018. +                                   {
  3019. +                                   if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields))
  3020. +                                       {
  3021. +                                       if (isset($_GET["$field_name_id"]))             {$form_field_value=$_GET["$field_name_id"];}
  3022. +                                           elseif (isset($_POST["$field_name_id"]))    {$form_field_value=$_POST["$field_name_id"];}
  3023. +
  3024. +                                       if ($form_field_value >= 0)
  3025. +                                           {
  3026. +                                           $A_field_value[$o] =    $row[$form_field_value];
  3027. +                                           # replace ' " ` \ ; with nothing
  3028. +                                           $A_field_value[$o] =    eregi_replace($field_regx, "", $A_field_value[$o]);
  3029. +
  3030. +                                           $custom_SQL .= "$A_field_label[$o]='$A_field_value[$o]',";
  3031. +                                           }
  3032. +                                       }
  3033. +                                   }
  3034. +                               $o++;
  3035. +                               }
  3036. +                           }
  3037. +                       }
  3038. +                   }
  3039. +               ##### END custom fields columns list ###
  3040. +
  3041. +               $custom_SQL = preg_replace("/,$/","",$custom_SQL);
  3042. +
  3043. +
  3044. +               ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign #####
  3045. +               if (eregi("DUPCAMP",$dupcheck))
  3046. +                   {
  3047. +                   $dup_lead=0;
  3048. +                   $dup_lists='';
  3049. +                   $stmt="select campaign_id from vicidial_lists where list_id='$list_id';";
  3050. +                   $rslt=mysql_query($stmt, $link);
  3051. +                   $ci_recs = mysql_num_rows($rslt);
  3052. +                   if ($ci_recs > 0)
  3053. +                       {
  3054. +                       $row=mysql_fetch_row($rslt);
  3055. +                       $dup_camp =         $row[0];
  3056. +
  3057. +                       $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';";
  3058. +                       $rslt=mysql_query($stmt, $link);
  3059. +                       $li_recs = mysql_num_rows($rslt);
  3060. +                       if ($li_recs > 0)
  3061. +                           {
  3062. +                           $L=0;
  3063. +                           while ($li_recs > $L)
  3064. +                               {
  3065. +                               $row=mysql_fetch_row($rslt);
  3066. +                               $dup_lists .=   "'$row[0]',";
  3067. +                               $L++;
  3068. +                               }
  3069. +                           $dup_lists = eregi_replace(",$",'',$dup_lists);
  3070. +
  3071. +                           $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;";
  3072. +                           $rslt=mysql_query($stmt, $link);
  3073. +                           $pc_recs = mysql_num_rows($rslt);
  3074. +                           if ($pc_recs > 0)
  3075. +                               {
  3076. +                               $dup_lead=1;
  3077. +                               $row=mysql_fetch_row($rslt);
  3078. +                               $dup_lead_list =    $row[0];
  3079. +                               }
  3080. +                           if ($dup_lead < 1)
  3081. +                               {
  3082. +                               if (eregi("$phone_number$US$list_id",$phone_list))
  3083. +                                   {$dup_lead++; $dup++;}
  3084. +                               }
  3085. +                           }
  3086. +                       }
  3087. +                   }
  3088. +
  3089. +               ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  3090. +               if (eregi("DUPSYS",$dupcheck))
  3091. +                   {
  3092. +                   $dup_lead=0;
  3093. +                   $stmt="select list_id from vicidial_list where phone_number='$phone_number';";
  3094. +                   $rslt=mysql_query($stmt, $link);
  3095. +                   $pc_recs = mysql_num_rows($rslt);
  3096. +                   if ($pc_recs > 0)
  3097. +                       {
  3098. +                       $dup_lead=1;
  3099. +                       $row=mysql_fetch_row($rslt);
  3100. +                       $dup_lead_list =    $row[0];
  3101. +                       }
  3102. +                   if ($dup_lead < 1)
  3103. +                       {
  3104. +                       if (eregi("$phone_number$US$list_id",$phone_list))
  3105. +                           {$dup_lead++; $dup++;}
  3106. +                       }
  3107. +                   }
  3108. +
  3109. +               ##### Check for duplicate phone numbers in vicidial_list table for one list_id #####
  3110. +               if (eregi("DUPLIST",$dupcheck))
  3111. +                   {
  3112. +                   $dup_lead=0;
  3113. +                   $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';";
  3114. +                   $rslt=mysql_query($stmt, $link);
  3115. +                   $pc_recs = mysql_num_rows($rslt);
  3116. +                   if ($pc_recs > 0)
  3117. +                       {
  3118. +                       $row=mysql_fetch_row($rslt);
  3119. +                       $dup_lead =         $row[0];
  3120. +                       $dup_lead_list =    $list_id;
  3121. +                       }
  3122. +                   if ($dup_lead < 1)
  3123. +                       {
  3124. +                       if (eregi("$phone_number$US$list_id",$phone_list))
  3125. +                           {$dup_lead++; $dup++;}
  3126. +                       }
  3127. +                   }
  3128. +
  3129. +               ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id #####
  3130. +               if (eregi("DUPTITLEALTPHONELIST",$dupcheck))
  3131. +                   {
  3132. +                   $dup_lead=0;
  3133. +                   $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';";
  3134. +                   $rslt=mysql_query($stmt, $link);
  3135. +                   $pc_recs = mysql_num_rows($rslt);
  3136. +                   if ($pc_recs > 0)
  3137. +                       {
  3138. +                       $row=mysql_fetch_row($rslt);
  3139. +                       $dup_lead =         $row[0];
  3140. +                       $dup_lead_list =    $list_id;
  3141. +                       }
  3142. +                   if ($dup_lead < 1)
  3143. +                       {
  3144. +                       if (eregi("$alt_phone$title$US$list_id",$phone_list))
  3145. +                           {$dup_lead++; $dup++;}
  3146. +                       }
  3147. +                   }
  3148. +
  3149. +               ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  3150. +               if (eregi("DUPTITLEALTPHONESYS",$dupcheck))
  3151. +                   {
  3152. +                   $dup_lead=0;
  3153. +                   $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';";
  3154. +                   $rslt=mysql_query($stmt, $link);
  3155. +                   $pc_recs = mysql_num_rows($rslt);
  3156. +                   if ($pc_recs > 0)
  3157. +                       {
  3158. +                       $dup_lead=1;
  3159. +                       $row=mysql_fetch_row($rslt);
  3160. +                       $dup_lead_list =    $row[0];
  3161. +                       }
  3162. +                   if ($dup_lead < 1)
  3163. +                       {
  3164. +                       if (eregi("$alt_phone$title$US$list_id",$phone_list))
  3165. +                           {$dup_lead++; $dup++;}
  3166. +                       }
  3167. +                   }
  3168. +
  3169. +               $valid_number=1;
  3170. +               if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) )
  3171. +                   {
  3172. +                   $valid_number=0;
  3173. +                   $invalid_reason = "INVALID PHONE NUMBER LENGTH";
  3174. +                   }
  3175. +               if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) )
  3176. +                   {
  3177. +                   $USprefix =     substr($phone_number, 3, 1);
  3178. +                   if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";}
  3179. +                   if ($USprefix < 2)
  3180. +                       {
  3181. +                       $valid_number=0;
  3182. +                       $invalid_reason = "INVALID PHONE NUMBER PREFIX";
  3183. +                       }
  3184. +                   }
  3185. +               if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) )
  3186. +                   {
  3187. +                   $phone_areacode = substr($phone_number, 0, 3);
  3188. +                   $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';";
  3189. +                   if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";}
  3190. +                   $rslt=mysql_query($stmt, $link);
  3191. +                   $row=mysql_fetch_row($rslt);
  3192. +                   $valid_number=$row[0];
  3193. +                   if ($valid_number < 1)
  3194. +                       {
  3195. +                       $invalid_reason = "INVALID PHONE NUMBER AREACODE";
  3196. +                       }
  3197. +                   }
  3198. +
  3199. +               if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 ))
  3200. +                   {
  3201. +                   if (strlen($phone_code)<1) {$phone_code = '1';}
  3202. +
  3203. +                   if (eregi("TITLEALTPHONE",$dupcheck))
  3204. +                       {$phone_list .= "$alt_phone$title$US$list_id|";}
  3205. +                   else
  3206. +                       {$phone_list .= "$phone_number$US$list_id|";}
  3207. +
  3208. +                   $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
  3209. +
  3210. +                   if (strlen($custom_SQL)>3)
  3211. +                       {
  3212. +                       $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','$list_id');";
  3213. +                       $rslt=mysql_query($stmtZ, $link);
  3214. +                       $affected_rows = mysql_affected_rows($link);
  3215. +                       $lead_id = mysql_insert_id($link);
  3216. +                       if ($DB > 0) {echo "<!-- $affected_rows|$lead_id|$stmtZ -->";}
  3217. +                       if ($WeBRooTWritablE > 0)
  3218. +                           {fwrite($stmt_file, $stmtZ."\r\n");}
  3219. +                       $multistmt='';
  3220. +
  3221. +                       $custom_SQL_query = "INSERT INTO custom_$list_id_override SET lead_id='$lead_id',$custom_SQL;";
  3222. +                       $rslt=mysql_query($custom_SQL_query, $link);
  3223. +                       $affected_rows = mysql_affected_rows($link);
  3224. +                       if ($DB > 0) {echo "<!-- $affected_rows|$custom_SQL_query -->";}
  3225. +                       }
  3226. +                   else
  3227. +                       {
  3228. +                       if ($multi_insert_counter > 8)
  3229. +                           {
  3230. +                           ### insert good record into vicidial_list table ###
  3231. +                           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');";
  3232. +                           $rslt=mysql_query($stmtZ, $link);
  3233. +                           if ($WeBRooTWritablE > 0)
  3234. +                               {fwrite($stmt_file, $stmtZ."\r\n");}
  3235. +                           $multistmt='';
  3236. +                           $multi_insert_counter=0;
  3237. +                           }
  3238. +                       else
  3239. +                           {
  3240. +                           $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),";
  3241. +                           $multi_insert_counter++;
  3242. +                           }
  3243. +                       }
  3244. +                   $good++;
  3245. +                   }
  3246. +               else
  3247. +                   {
  3248. +                   if ($bad < 1000000)
  3249. +                       {
  3250. +                       if ( $list_id < 100 )
  3251. +                           {
  3252. +                           print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID</font><b>\n";
  3253. +                           }
  3254. +                       else
  3255. +                           {
  3256. +                           if ($valid_number < 1)
  3257. +                               {
  3258. +                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number</font><b>\n";
  3259. +                               }
  3260. +                           else
  3261. +                               {
  3262. +                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead  $dup_lead_list</font><b>\n";
  3263. +                               }
  3264. +                           }
  3265. +                       }
  3266. +                   $bad++;
  3267. +                   }
  3268. +               $total++;
  3269. +               if ($total%100==0)
  3270. +                   {
  3271. +                   print "<script language='JavaScript1.2'>ShowProgress($good, $bad, $total, $dup, $inv, $post)</script>";
  3272. +                   usleep(1000);
  3273. +                   flush();
  3274. +                   }
  3275. +               }
  3276. +           }
  3277. +       if ($multi_insert_counter!=0)
  3278. +           {
  3279. +           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";";
  3280. +           mysql_query($stmtZ, $link);
  3281. +           if ($WeBRooTWritablE > 0)
  3282. +               {fwrite($stmt_file, $stmtZ."\r\n");}
  3283. +           }
  3284. +
  3285. +       ### LOG INSERTION Admin Log Table ###
  3286. +       $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST CUSTOM', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';";
  3287. +       if ($DB) {echo "|$stmt|\n";}
  3288. +       $rslt=mysql_query($stmt, $link);
  3289. +
  3290. +       print "<BR><BR>Done</B> GOOD: $good &nbsp; &nbsp; &nbsp; BAD: $bad &nbsp; &nbsp; &nbsp; TOTAL: $total</font></center>";
  3291. +       }
  3292. +   else
  3293. +       {
  3294. +       print "<center><font face='arial, helvetica' size=3 color='#990000'><B>ERROR: The file does not have the required number of fields to process it.</B></font></center>";
  3295. +       }
  3296. +   }
  3297. +##### END custom fields submission #####
  3298. +
  3299. +
  3300. +
  3301. +if (($leadfile) && ($LF_path))
  3302. +   {
  3303. +   $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  3304. +
  3305. +   ### LOG INSERTION Admin Log Table ###
  3306. +   $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST', event_sql='', event_notes='File Name: $leadfile_name';";
  3307. +   if ($DB) {echo "|$stmt|\n";}
  3308. +   $rslt=mysql_query($stmt, $link);
  3309. +
  3310. +
  3311. +
  3312. +   ##### BEGIN process standard file layout #####
  3313. +   if ($file_layout=="standard")
  3314. +       {
  3315. +       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script>";
  3316. +       flush();
  3317. +
  3318. +
  3319. +       $delim_set=0;
  3320. +       # csv xls xlsx ods sxc conversion
  3321. +       if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name))
  3322. +           {
  3323. +           $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name);
  3324. +           copy($LF_path, "/tmp/$leadfile_name");
  3325. +           $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name);
  3326. +           $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename";
  3327. +           passthru("$convert_command");
  3328. +           $lead_file = "/tmp/$new_filename";
  3329. +           if ($DB > 0) {echo "|$convert_command|";}
  3330. +
  3331. +           if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";}
  3332. +           if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";}
  3333. +           if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";}
  3334. +           if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";}
  3335. +           if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";}
  3336. +           $delim_set=1;
  3337. +           }
  3338. +       else
  3339. +           {
  3340. +           copy($LF_path, "/tmp/vicidial_temp_file.txt");
  3341. +           $lead_file = "/tmp/vicidial_temp_file.txt";
  3342. +           }
  3343. +       $file=fopen("$lead_file", "r");
  3344. +       if ($WeBRooTWritablE > 0)
  3345. +           {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");}
  3346. +
  3347. +       $buffer=fgets($file, 4096);
  3348. +       $tab_count=substr_count($buffer, "\t");
  3349. +       $pipe_count=substr_count($buffer, "|");
  3350. +
  3351. +       if ($delim_set < 1)
  3352. +           {
  3353. +           if ($tab_count>$pipe_count)
  3354. +               {$delim_name="tab-delimited";}
  3355. +           else
  3356. +               {$delim_name="pipe-delimited";}
  3357. +           }
  3358. +       if ($tab_count>$pipe_count)
  3359. +           {$delimiter="\t";}
  3360. +       else
  3361. +           {$delimiter="|";}
  3362. +
  3363. +       $field_check=explode($delimiter, $buffer);
  3364. +
  3365. +       if (count($field_check)>=2)
  3366. +           {
  3367. +           flush();
  3368. +           $file=fopen("$lead_file", "r");
  3369. +           $total=0; $good=0; $bad=0; $dup=0; $post=0; $phone_list='';
  3370. +           print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing $delim_name file... ($tab_count|$pipe_count)\n";
  3371. +           if (strlen($list_id_override)>0)
  3372. +               {
  3373. +               print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  3374. +               }
  3375. +           if (strlen($phone_code_override)>0)
  3376. +               {
  3377. +               print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>\n";
  3378. +               }
  3379. +           while (!feof($file))
  3380. +               {
  3381. +               $record++;
  3382. +               $buffer=rtrim(fgets($file, 4096));
  3383. +               $buffer=stripslashes($buffer);
  3384. +
  3385. +               if (strlen($buffer)>0)
  3386. +                   {
  3387. +                   $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  3388. +
  3389. +                   $pulldate=date("Y-m-d H:i:s");
  3390. +                   $entry_date =           "$pulldate";
  3391. +                   $modify_date =          "";
  3392. +                   $status =               "NEW";
  3393. +                   $user ="";
  3394. +                   $vendor_lead_code =     $row[0];
  3395. +                   $source_code =          $row[1];
  3396. +                   $source_id=$source_code;
  3397. +                   $list_id =              $row[2];
  3398. +                   $gmt_offset =           '0';
  3399. +                   $called_since_last_reset='N';
  3400. +                   $phone_code =           eregi_replace("[^0-9]", "", $row[3]);
  3401. +                   $phone_number =         eregi_replace("[^0-9]", "", $row[4]);
  3402. +                   $title =                $row[5];
  3403. +                   $first_name =           $row[6];
  3404. +                   $middle_initial =       $row[7];
  3405. +                   $last_name =            $row[8];
  3406. +                   $address1 =             $row[9];
  3407. +                   $address2 =             $row[10];
  3408. +                   $address3 =             $row[11];
  3409. +                   $city =$row[12];
  3410. +                   $state =                $row[13];
  3411. +                   $province =             $row[14];
  3412. +                   $postal_code =          $row[15];
  3413. +                   $country_code =         $row[16];
  3414. +                   $gender =               $row[17];
  3415. +                   $date_of_birth =        $row[18];
  3416. +                   $alt_phone =            eregi_replace("[^0-9]", "", $row[19]);
  3417. +                   $email =                $row[20];
  3418. +                   $security_phrase =      $row[21];
  3419. +                   $comments =             trim($row[22]);
  3420. +                   $rank =                 $row[23];
  3421. +                   $owner =                $row[24];
  3422. +                      
  3423. +                   # replace ' " ` \ ; with nothing
  3424. +                   $vendor_lead_code =     eregi_replace($field_regx, "", $vendor_lead_code);
  3425. +                   $source_code =          eregi_replace($field_regx, "", $source_code);
  3426. +                   $source_id =            eregi_replace($field_regx, "", $source_id);
  3427. +                   $list_id =              eregi_replace($field_regx, "", $list_id);
  3428. +                   $phone_code =           eregi_replace($field_regx, "", $phone_code);
  3429. +                   $phone_number =         eregi_replace($field_regx, "", $phone_number);
  3430. +                   $title =                eregi_replace($field_regx, "", $title);
  3431. +                   $first_name =           eregi_replace($field_regx, "", $first_name);
  3432. +                   $middle_initial =       eregi_replace($field_regx, "", $middle_initial);
  3433. +                   $last_name =            eregi_replace($field_regx, "", $last_name);
  3434. +                   $address1 =             eregi_replace($field_regx, "", $address1);
  3435. +                   $address2 =             eregi_replace($field_regx, "", $address2);
  3436. +                   $address3 =             eregi_replace($field_regx, "", $address3);
  3437. +                   $city =                 eregi_replace($field_regx, "", $city);
  3438. +                   $state =                eregi_replace($field_regx, "", $state);
  3439. +                   $province =             eregi_replace($field_regx, "", $province);
  3440. +                   $postal_code =          eregi_replace($field_regx, "", $postal_code);
  3441. +                   $country_code =         eregi_replace($field_regx, "", $country_code);
  3442. +                   $gender =               eregi_replace($field_regx, "", $gender);
  3443. +                   $date_of_birth =        eregi_replace($field_regx, "", $date_of_birth);
  3444. +                   $alt_phone =            eregi_replace($field_regx, "", $alt_phone);
  3445. +                   $email =                eregi_replace($field_regx, "", $email);
  3446. +                   $security_phrase =      eregi_replace($field_regx, "", $security_phrase);
  3447. +                   $comments =             eregi_replace($field_regx, "", $comments);
  3448. +                   $rank =                 eregi_replace($field_regx, "", $rank);
  3449. +                   $owner =                eregi_replace($field_regx, "", $owner);
  3450. +                  
  3451. +                   $USarea =           substr($phone_number, 0, 3);
  3452. +
  3453. +                   if (strlen($list_id_override)>0)
  3454. +                       {
  3455. +                       $list_id = $list_id_override;
  3456. +                       }
  3457. +                   if (strlen($phone_code_override)>0)
  3458. +                       {
  3459. +                       $phone_code = $phone_code_override;
  3460. +                       }
  3461. +
  3462. +                   ##### Check for duplicate phone numbers in vicidial_list table for all lists in a campaign #####
  3463. +                   if (eregi("DUPCAMP",$dupcheck))
  3464. +                       {
  3465. +                           $dup_lead=0;
  3466. +                           $dup_lists='';
  3467. +                       $stmt="select campaign_id from vicidial_lists where list_id='$list_id';";
  3468. +                       $rslt=mysql_query($stmt, $link);
  3469. +                       $ci_recs = mysql_num_rows($rslt);
  3470. +                       if ($ci_recs > 0)
  3471. +                           {
  3472. +                           $row=mysql_fetch_row($rslt);
  3473. +                           $dup_camp =         $row[0];
  3474. +
  3475. +                           $stmt="select list_id from vicidial_lists where campaign_id='$dup_camp';";
  3476. +                           $rslt=mysql_query($stmt, $link);
  3477. +                           $li_recs = mysql_num_rows($rslt);
  3478. +                           if ($li_recs > 0)
  3479. +                               {
  3480. +                               $L=0;
  3481. +                               while ($li_recs > $L)
  3482. +                                   {
  3483. +                                   $row=mysql_fetch_row($rslt);
  3484. +                                   $dup_lists .=   "'$row[0]',";
  3485. +                                   $L++;
  3486. +                                   }
  3487. +                               $dup_lists = eregi_replace(",$",'',$dup_lists);
  3488. +
  3489. +                               $stmt="select list_id from vicidial_list where phone_number='$phone_number' and list_id IN($dup_lists) limit 1;";
  3490. +                               $rslt=mysql_query($stmt, $link);
  3491. +                               $pc_recs = mysql_num_rows($rslt);
  3492. +                               if ($pc_recs > 0)
  3493. +                                   {
  3494. +                                   $dup_lead=1;
  3495. +                                   $row=mysql_fetch_row($rslt);
  3496. +                                   $dup_lead_list =    $row[0];
  3497. +                                   }
  3498. +                               if ($dup_lead < 1)
  3499. +                                   {
  3500. +                                   if (eregi("$phone_number$US$list_id",$phone_list))
  3501. +                                       {$dup_lead++; $dup++;}
  3502. +                                   }
  3503. +                               }
  3504. +                           }
  3505. +                       }
  3506. +
  3507. +                   ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  3508. +                   if (eregi("DUPSYS",$dupcheck))
  3509. +                       {
  3510. +                       $dup_lead=0;
  3511. +                       $stmt="select list_id from vicidial_list where phone_number='$phone_number';";
  3512. +                       $rslt=mysql_query($stmt, $link);
  3513. +                       $pc_recs = mysql_num_rows($rslt);
  3514. +                       if ($pc_recs > 0)
  3515. +                           {
  3516. +                           $dup_lead=1;
  3517. +                           $row=mysql_fetch_row($rslt);
  3518. +                           $dup_lead_list =    $row[0];
  3519. +                           }
  3520. +                       if ($dup_lead < 1)
  3521. +                           {
  3522. +                           if (eregi("$phone_number$US$list_id",$phone_list))
  3523. +                               {$dup_lead++; $dup++;}
  3524. +                           }
  3525. +                       }
  3526. +
  3527. +                   ##### Check for duplicate phone numbers in vicidial_list table for one list_id #####
  3528. +                   if (eregi("DUPLIST",$dupcheck))
  3529. +                       {
  3530. +                       $dup_lead=0;
  3531. +                       $stmt="select count(*) from vicidial_list where phone_number='$phone_number' and list_id='$list_id';";
  3532. +                       $rslt=mysql_query($stmt, $link);
  3533. +                       $pc_recs = mysql_num_rows($rslt);
  3534. +                       if ($pc_recs > 0)
  3535. +                           {
  3536. +                           $row=mysql_fetch_row($rslt);
  3537. +                           $dup_lead =         $row[0];
  3538. +                           }
  3539. +                       if ($dup_lead < 1)
  3540. +                           {
  3541. +                           if (eregi("$phone_number$US$list_id",$phone_list))
  3542. +                               {$dup_lead++; $dup++;}
  3543. +                           }
  3544. +                       }
  3545. +
  3546. +                   ##### Check for duplicate title and alt-phone in vicidial_list table for one list_id #####
  3547. +                   if (eregi("DUPTITLEALTPHONELIST",$dupcheck))
  3548. +                       {
  3549. +                       $dup_lead=0;
  3550. +                       $stmt="select count(*) from vicidial_list where title='$title' and alt_phone='$alt_phone' and list_id='$list_id';";
  3551. +                       $rslt=mysql_query($stmt, $link);
  3552. +                       $pc_recs = mysql_num_rows($rslt);
  3553. +                       if ($pc_recs > 0)
  3554. +                           {
  3555. +                           $row=mysql_fetch_row($rslt);
  3556. +                           $dup_lead =         $row[0];
  3557. +                           $dup_lead_list =    $list_id;
  3558. +                           }
  3559. +                       if ($dup_lead < 1)
  3560. +                           {
  3561. +                           if (eregi("$alt_phone$title$US$list_id",$phone_list))
  3562. +                               {$dup_lead++; $dup++;}
  3563. +                           }
  3564. +                       }
  3565. +
  3566. +                   ##### Check for duplicate phone numbers in vicidial_list table entire database #####
  3567. +                   if (eregi("DUPTITLEALTPHONESYS",$dupcheck))
  3568. +                       {
  3569. +                       $dup_lead=0;
  3570. +                       $stmt="select list_id from vicidial_list where title='$title' and alt_phone='$alt_phone';";
  3571. +                       $rslt=mysql_query($stmt, $link);
  3572. +                       $pc_recs = mysql_num_rows($rslt);
  3573. +                       if ($pc_recs > 0)
  3574. +                           {
  3575. +                           $dup_lead=1;
  3576. +                           $row=mysql_fetch_row($rslt);
  3577. +                           $dup_lead_list =    $row[0];
  3578. +                           }
  3579. +                       if ($dup_lead < 1)
  3580. +                           {
  3581. +                           if (eregi("$alt_phone$title$US$list_id",$phone_list))
  3582. +                               {$dup_lead++; $dup++;}
  3583. +                           }
  3584. +                       }
  3585. +
  3586. +                   $valid_number=1;
  3587. +                   if ( (strlen($phone_number)<6) || (strlen($phone_number)>16) )
  3588. +                       {
  3589. +                       $valid_number=0;
  3590. +                       $invalid_reason = "INVALID PHONE NUMBER LENGTH";
  3591. +                       }
  3592. +                   if ( (preg_match("/PREFIX/",$usacan_check)) and ($valid_number > 0) )
  3593. +                       {
  3594. +                       $USprefix =     substr($phone_number, 3, 1);
  3595. +                       if ($DB>0) {echo "DEBUG: usacan prefix check - $USprefix|$phone_number\n";}
  3596. +                       if ($USprefix < 2)
  3597. +                           {
  3598. +                           $valid_number=0;
  3599. +                           $invalid_reason = "INVALID PHONE NUMBER PREFIX";
  3600. +                           }
  3601. +                       }
  3602. +                   if ( (preg_match("/AREACODE/",$usacan_check)) and ($valid_number > 0) )
  3603. +                       {
  3604. +                       $phone_areacode = substr($phone_number, 0, 3);
  3605. +                       $stmt = "select count(*) from vicidial_phone_codes where areacode='$phone_areacode' and country_code='1';";
  3606. +                       if ($DB>0) {echo "DEBUG: usacan areacode query - $stmt\n";}
  3607. +                       $rslt=mysql_query($stmt, $link);
  3608. +                       $row=mysql_fetch_row($rslt);
  3609. +                       $valid_number=$row[0];
  3610. +                       if ($valid_number < 1)
  3611. +                           {
  3612. +                           $invalid_reason = "INVALID PHONE NUMBER AREACODE";
  3613. +                           }
  3614. +                       }
  3615. +
  3616. +                   if ( ($valid_number>0) and ($dup_lead<1) and ($list_id >= 100 ))
  3617. +                       {
  3618. +                       if (strlen($phone_code)<1) {$phone_code = '1';}
  3619. +
  3620. +                       if (eregi("TITLEALTPHONE",$dupcheck))
  3621. +                           {$phone_list .= "$alt_phone$title$US$list_id|";}
  3622. +                       else
  3623. +                           {$phone_list .= "$phone_number$US$list_id|";}
  3624. +
  3625. +                       $gmt_offset = lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner);
  3626. +
  3627. +                       if ($multi_insert_counter > 8)
  3628. +                           {
  3629. +                           ### insert good deal into pending_transactions table ###
  3630. +                           $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values$multistmt('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0');";
  3631. +                           $rslt=mysql_query($stmtZ, $link);
  3632. +                           if ($WeBRooTWritablE > 0)
  3633. +                               {fwrite($stmt_file, $stmtZ."\r\n");}
  3634. +                           $multistmt='';
  3635. +                           $multi_insert_counter=0;
  3636. +                           }
  3637. +                       else
  3638. +                           {
  3639. +                           $multistmt .= "('','$entry_date','$modify_date','$status','$user','$vendor_lead_code','$source_id','$list_id','$gmt_offset','$called_since_last_reset','$phone_code','$phone_number','$title','$first_name','$middle_initial','$last_name','$address1','$address2','$address3','$city','$state','$province','$postal_code','$country_code','$gender','$date_of_birth','$alt_phone','$email','$security_phrase','$comments',0,'2008-01-01 00:00:00','$rank','$owner','0'),";
  3640. +                           $multi_insert_counter++;
  3641. +                           }
  3642. +                       $good++;
  3643. +                       }
  3644. +                   else
  3645. +                       {
  3646. +                       if ($bad < 1000000)
  3647. +                           {
  3648. +                           if ( $list_id < 100 )
  3649. +                               {
  3650. +                               print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INVALID LIST ID</font><b>\n";
  3651. +                               }
  3652. +                           else
  3653. +                               {
  3654. +                               if ($valid_number < 1)
  3655. +                                   {
  3656. +                                   print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| INV: $phone_number</font><b>\n";
  3657. +                                   }
  3658. +                               else
  3659. +                                   {
  3660. +                                   print "<BR></b><font size=1 color=red>record $total BAD- PHONE: $phone_number ROW: |$row[0]| DUP: $dup_lead  $dup_lead_list</font><b>\n";
  3661. +                                   }
  3662. +                               }
  3663. +                           }
  3664. +                       $bad++;
  3665. +                       }
  3666. +                   $total++;
  3667. +                   if ($total%100==0)
  3668. +                       {
  3669. +                       print "<script language='JavaScript1.2'>ShowProgress($good, $bad, $total, $dup, $inv, $post)</script>";
  3670. +                       usleep(1000);
  3671. +                       flush();
  3672. +                       }
  3673. +                   }
  3674. +               }
  3675. +           if ($multi_insert_counter!=0)
  3676. +               {
  3677. +               $stmtZ = "INSERT INTO vicidial_list (lead_id,entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,gmt_offset_now,called_since_last_reset,phone_code,phone_number,title,first_name,middle_initial,last_name,address1,address2,address3,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email,security_phrase,comments,called_count,last_local_call_time,rank,owner,entry_list_id) values".substr($multistmt, 0, -1).";";
  3678. +               mysql_query($stmtZ, $link);
  3679. +               if ($WeBRooTWritablE > 0)
  3680. +                   {fwrite($stmt_file, $stmtZ."\r\n");}
  3681. +               }
  3682. +           ### LOG INSERTION Admin Log Table ###
  3683. +           $stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='LISTS', event_type='LOAD', record_id='$list_id_override', event_code='ADMIN LOAD LIST STANDARD', event_sql='', event_notes='File Name: $leadfile_name, GOOD: $good, BAD: $bad, TOTAL: $total';";
  3684. +           if ($DB) {echo "|$stmt|\n";}
  3685. +           $rslt=mysql_query($stmt, $link);
  3686. +
  3687. +           print "<BR><BR>Done</B> GOOD: $good &nbsp; &nbsp; &nbsp; BAD: $bad &nbsp; &nbsp; &nbsp; TOTAL: $total</font></center>";
  3688. +           }
  3689. +       else
  3690. +           {
  3691. +           print "<center><font face='arial, helvetica' size=3 color='#990000'><B>ERROR: The file does not have the required number of fields to process it.</B></font></center>";
  3692. +           }
  3693. +       }
  3694. +   ##### END process standard file layout #####
  3695. +
  3696. +      
  3697. +   ##### BEGIN field chooser #####
  3698. +   else
  3699. +       {
  3700. +       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=true; document.forms[0].submit_file.disabled=true; document.forms[0].reload_page.disabled=true;</script><HR>";
  3701. +       flush();
  3702. +       print "<table border=0 cellpadding=3 cellspacing=0 width=700 align=center>\r\n";
  3703. +       print "  <tr bgcolor='#330099'>\r\n";
  3704. +       print "    <th align=right><font class='standard' color='white'>VICIDIAL Column</font></th>\r\n";
  3705. +       print "    <th><font class='standard' color='white'>File data</font></th>\r\n";
  3706. +       print "  </tr>\r\n";
  3707. +
  3708. +       $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner from vicidial_list limit 1";
  3709. +
  3710. +       ##### BEGIN custom fields columns list ###
  3711. +       if ($custom_fields_enabled > 0)
  3712. +           {
  3713. +           $stmt="SHOW TABLES LIKE \"custom_$list_id_override\";";
  3714. +           if ($DB>0) {echo "$stmt\n";}
  3715. +           $rslt=mysql_query($stmt, $link);
  3716. +           $tablecount_to_print = mysql_num_rows($rslt);
  3717. +           if ($tablecount_to_print > 0)
  3718. +               {
  3719. +               $stmt="SELECT count(*) from vicidial_lists_fields where list_id='$list_id_override';";
  3720. +               if ($DB>0) {echo "$stmt\n";}
  3721. +               $rslt=mysql_query($stmt, $link);
  3722. +               $fieldscount_to_print = mysql_num_rows($rslt);
  3723. +               if ($fieldscount_to_print > 0)
  3724. +                   {
  3725. +                   $rowx=mysql_fetch_row($rslt);
  3726. +                   $custom_records_count = $rowx[0];
  3727. +
  3728. +                   $custom_SQL='';
  3729. +                   $stmt="SELECT field_id,field_label,field_name,field_description,field_rank,field_help,field_type,field_options,field_size,field_max,field_default,field_cost,field_required,multi_position,name_position,field_order from vicidial_lists_fields where list_id='$list_id_override' order by field_rank,field_order,field_label;";
  3730. +                   if ($DB>0) {echo "$stmt\n";}
  3731. +                   $rslt=mysql_query($stmt, $link);
  3732. +                   $fields_to_print = mysql_num_rows($rslt);
  3733. +                   $fields_list='';
  3734. +                   $o=0;
  3735. +                   while ($fields_to_print > $o)
  3736. +                       {
  3737. +                       $rowx=mysql_fetch_row($rslt);
  3738. +                       $A_field_label[$o] =    $rowx[1];
  3739. +                       $A_field_type[$o] =     $rowx[6];
  3740. +
  3741. +                       if ($DB>0) {echo "$A_field_label[$o]|$A_field_type[$o]\n";}
  3742. +
  3743. +                       if ( ($A_field_type[$o]!='DISPLAY') and ($A_field_type[$o]!='SCRIPT') )
  3744. +                           {
  3745. +                           if (!preg_match("/\|$A_field_label[$o]\|/",$vicidial_list_fields))
  3746. +                               {
  3747. +                               $custom_SQL .= ",$A_field_label[$o]";
  3748. +                               }
  3749. +                           }
  3750. +                       $o++;
  3751. +                       }
  3752. +
  3753. +                   $fields_stmt = "SELECT vendor_lead_code, source_id, list_id, phone_code, phone_number, title, first_name, middle_initial, last_name, address1, address2, address3, city, state, province, postal_code, country_code, gender, date_of_birth, alt_phone, email, security_phrase, comments, rank, owner $custom_SQL from vicidial_list, custom_$list_id_override limit 1";
  3754. +
  3755. +                   }
  3756. +               }
  3757. +           }
  3758. +       ##### END custom fields columns list ###
  3759. +
  3760. +
  3761. +       $rslt=mysql_query("$fields_stmt", $link);
  3762. +
  3763. +       # csv xls xlsx ods sxc conversion
  3764. +       $delim_set=0;
  3765. +       if (preg_match("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", $leadfile_name))
  3766. +           {
  3767. +           $leadfile_name = ereg_replace("[^-\.\_0-9a-zA-Z]","_",$leadfile_name);
  3768. +           copy($LF_path, "/tmp/$leadfile_name");
  3769. +           $new_filename = preg_replace("/\.csv$|\.xls$|\.xlsx$|\.ods$|\.sxc$/i", '.txt', $leadfile_name);
  3770. +           $convert_command = "$WeBServeRRooT/$admin_web_directory/sheet2tab.pl /tmp/$leadfile_name /tmp/$new_filename";
  3771. +           passthru("$convert_command");
  3772. +           $lead_file = "/tmp/$new_filename";
  3773. +           if ($DB > 0) {echo "|$convert_command|";}
  3774. +
  3775. +           if (preg_match("/\.csv$/i", $leadfile_name)) {$delim_name="CSV: Comma Separated Values";}
  3776. +           if (preg_match("/\.xls$/i", $leadfile_name)) {$delim_name="XLS: MS Excel 2000-XP";}
  3777. +           if (preg_match("/\.xlsx$/i", $leadfile_name)) {$delim_name="XLSX: MS Excel 2007+";}
  3778. +           if (preg_match("/\.ods$/i", $leadfile_name)) {$delim_name="ODS: OpenOffice.org OpenDocument Spreadsheet";}
  3779. +           if (preg_match("/\.sxc$/i", $leadfile_name)) {$delim_name="SXC: OpenOffice.org First Spreadsheet";}
  3780. +           $delim_set=1;
  3781. +           }
  3782. +       else
  3783. +           {
  3784. +           copy($LF_path, "/tmp/vicidial_temp_file.txt");
  3785. +           $lead_file = "/tmp/vicidial_temp_file.txt";
  3786. +           }
  3787. +       $file=fopen("$lead_file", "r");
  3788. +       if ($WeBRooTWritablE > 0)
  3789. +           {$stmt_file=fopen("$WeBServeRRooT/$admin_web_directory/listloader_stmts.txt", "w");}
  3790. +
  3791. +       $buffer=fgets($file, 4096);
  3792. +       $tab_count=substr_count($buffer, "\t");
  3793. +       $pipe_count=substr_count($buffer, "|");
  3794. +
  3795. +       if ($delim_set < 1)
  3796. +           {
  3797. +           if ($tab_count>$pipe_count)
  3798. +               {$delim_name="tab-delimited";}
  3799. +           else
  3800. +               {$delim_name="pipe-delimited";}
  3801. +           }
  3802. +       if ($tab_count>$pipe_count)
  3803. +           {$delimiter="\t";}
  3804. +       else
  3805. +           {$delimiter="|";}
  3806. +
  3807. +       $field_check=explode($delimiter, $buffer);
  3808. +       flush();
  3809. +       $file=fopen("$lead_file", "r");
  3810. +       print "<center><font face='arial, helvetica' size=3 color='#009900'><B>Processing $delim_name file...\n";
  3811. +
  3812. +       if (strlen($list_id_override)>0)
  3813. +           {
  3814. +           print "<BR><BR>LIST ID OVERRIDE FOR THIS FILE: $list_id_override<BR><BR>";
  3815. +           }
  3816. +       if (strlen($phone_code_override)>0)
  3817. +           {
  3818. +           print "<BR><BR>PHONE CODE OVERRIDE FOR THIS FILE: $phone_code_override<BR><BR>";
  3819. +           }
  3820. +       $buffer=rtrim(fgets($file, 4096));
  3821. +       $buffer=stripslashes($buffer);
  3822. +       $row=explode($delimiter, eregi_replace("[\'\"]", "", $buffer));
  3823. +      
  3824. +       // Custom labels for loader fields
  3825. +       $custom_labels_query = "SELECT * FROM system_settings LIMIT 1";
  3826. +       $custom_labels_result= mysql_query("$custom_labels_query", $link);
  3827. +       $custom_labels_row = mysql_fetch_assoc($custom_labels_result);
  3828. +       for ($i=0; $i<mysql_num_fields($rslt); $i++)
  3829. +           {
  3830. +           if ( (mysql_field_name($rslt, $i)=="list_id" and $list_id_override!="") or (mysql_field_name($rslt, $i)=="phone_code" and $phone_code_override!="") )
  3831. +               {
  3832. +               print "<!-- skipping " . mysql_field_name($rslt, $i) . " -->\n";
  3833. +               }
  3834. +           else
  3835. +               {
  3836. +               if (($custom_labels_row['label_'.mysql_field_name($rslt,$i)] <> '' ) && ($custom_labels_row['label_'.mysql_field_name($rslt,$i)] <> "--HIDE--"))
  3837. +                   $custom_labels_field_name = $custom_labels_row['label_'. mysql_field_name($rslt,$i)];
  3838. +               else
  3839. +                   $custom_labels_field_name = eregi_replace("_", " ", mysql_field_name($rslt, $i));
  3840. +
  3841. +               print "  <tr bgcolor=#D9E6FE>\r\n";
  3842. +               print "    <td align=right><font class=standard>".strtoupper($custom_labels_field_name).": </font></td>\r\n";
  3843. +               print "    <td align=center><select name='".mysql_field_name($rslt, $i)."_field'>\r\n";
  3844. +               print "     <option value='-1'>(none)</option>\r\n";
  3845. +
  3846. +               for ($j=0; $j<count($row); $j++)
  3847. +                   {
  3848. +                   eregi_replace("\"", "", $row[$j]);
  3849. +                   print "     <option value='$j'>\"$row[$j]\"</option>\r\n";
  3850. +                   }
  3851. +
  3852. +               print "    </select></td>\r\n";
  3853. +               print "  </tr>\r\n";
  3854. +               }
  3855. +           }
  3856. +       print "  <tr bgcolor='#330099'>\r\n";
  3857. +       print "  <input type=hidden name=dupcheck value=\"$dupcheck\">\r\n";
  3858. +       print "  <input type=hidden name=usacan_check value=\"$usacan_check\">\r\n";
  3859. +       print "  <input type=hidden name=postalgmt value=\"$postalgmt\">\r\n";
  3860. +       print "  <input type=hidden name=lead_file value=\"$lead_file\">\r\n";
  3861. +       print "  <input type=hidden name=list_id_override value=\"$list_id_override\">\r\n";
  3862. +       print "  <input type=hidden name=phone_code_override value=\"$phone_code_override\">\r\n";
  3863. +       print "    <th colspan=2><input type=submit name='OK_to_process' value='OK TO PROCESS'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button onClick=\"javascript:document.location='admin_listloader_third_gen.php'\" value=\"START OVER\" name='reload_page'></th>\r\n";
  3864. +       print "  </tr>\r\n";
  3865. +       print "</table>\r\n";
  3866. +
  3867. +       print "<script language='JavaScript1.2'>document.forms[0].leadfile.disabled=false; document.forms[0].submit_file.disabled=false; document.forms[0].reload_page.disabled=false;</script>";
  3868. +       }
  3869. +   ##### END field chooser #####
  3870. +
  3871. +   }
  3872. +
  3873. +?>
  3874. +</form>
  3875. +</body>
  3876. +</html>
  3877. +
  3878. +
  3879. +
  3880. +
  3881. +
  3882. +<?php
  3883. +
  3884. +exit;
  3885. +
  3886. +
  3887. +
  3888. +function lookup_gmt($phone_code,$USarea,$state,$LOCAL_GMT_OFF_STD,$Shour,$Smin,$Ssec,$Smon,$Smday,$Syear,$postalgmt,$postal_code,$owner)
  3889. +   {
  3890. +   global $link;
  3891. +
  3892. +   $postalgmt_found=0;
  3893. +   if ( (eregi("POSTAL",$postalgmt)) && (strlen($postal_code)>4) )
  3894. +       {
  3895. +       if (preg_match('/^1$/', $phone_code))
  3896. +           {
  3897. +           $stmt="select postal_code,state,GMT_offset,DST,DST_range,country,country_code from vicidial_postal_codes where country_code='$phone_code' and postal_code LIKE \"$postal_code%\";";
  3898. +           $rslt=mysql_query($stmt, $link);
  3899. +           $pc_recs = mysql_num_rows($rslt);
  3900. +           if ($pc_recs > 0)
  3901. +               {
  3902. +               $row=mysql_fetch_row($rslt);
  3903. +               $gmt_offset =   $row[2];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  3904. +               $dst =          $row[3];
  3905. +               $dst_range =    $row[4];
  3906. +               $PC_processed++;
  3907. +               $postalgmt_found++;
  3908. +               $post++;
  3909. +               }
  3910. +           }
  3911. +       }
  3912. +   if ( ($postalgmt=="TZCODE") && (strlen($owner)>1) )
  3913. +       {
  3914. +       $dst_range='';
  3915. +       $dst='N';
  3916. +       $gmt_offset=0;
  3917. +
  3918. +       $stmt="select GMT_offset from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' limit 1;";
  3919. +       $rslt=mysql_query($stmt, $link);
  3920. +       $pc_recs = mysql_num_rows($rslt);
  3921. +       if ($pc_recs > 0)
  3922. +           {
  3923. +           $row=mysql_fetch_row($rslt);
  3924. +           $gmt_offset =   $row[0];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  3925. +           $PC_processed++;
  3926. +           $postalgmt_found++;
  3927. +           $post++;
  3928. +           }
  3929. +
  3930. +       $stmt = "select distinct DST_range from vicidial_phone_codes where tz_code='$owner' and country_code='$phone_code' order by DST_range desc limit 1;";
  3931. +       $rslt=mysql_query($stmt, $link);
  3932. +       $pc_recs = mysql_num_rows($rslt);
  3933. +       if ($pc_recs > 0)
  3934. +           {
  3935. +           $row=mysql_fetch_row($rslt);
  3936. +           $dst_range =    $row[0];
  3937. +           if (strlen($dst_range)>2) {$dst = 'Y';}
  3938. +           }
  3939. +       }
  3940. +
  3941. +   if ($postalgmt_found < 1)
  3942. +       {
  3943. +       $PC_processed=0;
  3944. +       ### UNITED STATES ###
  3945. +       if ($phone_code =='1')
  3946. +           {
  3947. +           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';";
  3948. +           $rslt=mysql_query($stmt, $link);
  3949. +           $pc_recs = mysql_num_rows($rslt);
  3950. +           if ($pc_recs > 0)
  3951. +               {
  3952. +               $row=mysql_fetch_row($rslt);
  3953. +               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  3954. +               $dst =          $row[5];
  3955. +               $dst_range =    $row[6];
  3956. +               $PC_processed++;
  3957. +               }
  3958. +           }
  3959. +       ### MEXICO ###
  3960. +       if ($phone_code =='52')
  3961. +           {
  3962. +           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and areacode='$USarea';";
  3963. +           $rslt=mysql_query($stmt, $link);
  3964. +           $pc_recs = mysql_num_rows($rslt);
  3965. +           if ($pc_recs > 0)
  3966. +               {
  3967. +               $row=mysql_fetch_row($rslt);
  3968. +               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  3969. +               $dst =          $row[5];
  3970. +               $dst_range =    $row[6];
  3971. +               $PC_processed++;
  3972. +               }
  3973. +           }
  3974. +       ### AUSTRALIA ###
  3975. +       if ($phone_code =='61')
  3976. +           {
  3977. +           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code' and state='$state';";
  3978. +           $rslt=mysql_query($stmt, $link);
  3979. +           $pc_recs = mysql_num_rows($rslt);
  3980. +           if ($pc_recs > 0)
  3981. +               {
  3982. +               $row=mysql_fetch_row($rslt);
  3983. +               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  3984. +               $dst =          $row[5];
  3985. +               $dst_range =    $row[6];
  3986. +               $PC_processed++;
  3987. +               }
  3988. +           }
  3989. +       ### ALL OTHER COUNTRY CODES ###
  3990. +       if (!$PC_processed)
  3991. +           {
  3992. +           $PC_processed++;
  3993. +           $stmt="select country_code,country,areacode,state,GMT_offset,DST,DST_range,geographic_description from vicidial_phone_codes where country_code='$phone_code';";
  3994. +           $rslt=mysql_query($stmt, $link);
  3995. +           $pc_recs = mysql_num_rows($rslt);
  3996. +           if ($pc_recs > 0)
  3997. +               {
  3998. +               $row=mysql_fetch_row($rslt);
  3999. +               $gmt_offset =   $row[4];     $gmt_offset = eregi_replace("\+","",$gmt_offset);
  4000. +               $dst =          $row[5];
  4001. +               $dst_range =    $row[6];
  4002. +               $PC_processed++;
  4003. +               }
  4004. +           }
  4005. +       }
  4006. +
  4007. +   ### Find out if DST to raise the gmt offset ###
  4008. +   $AC_GMT_diff = ($gmt_offset - $LOCAL_GMT_OFF_STD);
  4009. +   $AC_localtime = mktime(($Shour + $AC_GMT_diff), $Smin, $Ssec, $Smon, $Smday, $Syear);
  4010. +       $hour = date("H",$AC_localtime);
  4011. +       $min = date("i",$AC_localtime);
  4012. +       $sec = date("s",$AC_localtime);
  4013. +       $mon = date("m",$AC_localtime);
  4014. +       $mday = date("d",$AC_localtime);
  4015. +       $wday = date("w",$AC_localtime);
  4016. +       $year = date("Y",$AC_localtime);
  4017. +   $dsec = ( ( ($hour * 3600) + ($min * 60) ) + $sec );
  4018. +
  4019. +   $AC_processed=0;
  4020. +   if ( (!$AC_processed) and ($dst_range == 'SSM-FSN') )
  4021. +       {
  4022. +       if ($DBX) {print "     Second Sunday March to First Sunday November\n";}
  4023. +       #**********************************************************************
  4024. +       # SSM-FSN
  4025. +       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  4026. +       #       Standard time is in effect.
  4027. +       #     Based on Second Sunday March to First Sunday November at 2 am.
  4028. +       #     INPUTS:
  4029. +       #       mm              INTEGER       Month.
  4030. +       #       dd              INTEGER       Day of the month.
  4031. +       #       ns              INTEGER       Seconds into the day.
  4032. +       #       dow             INTEGER       Day of week (0=Sunday, to 6=Saturday)
  4033. +       #     OPTIONAL INPUT:
  4034. +       #       timezone        INTEGER       hour difference UTC - local standard time
  4035. +       #                                      (DEFAULT is blank)
  4036. +       #                                     make calculations based on UTC time,
  4037. +       #                                     which means shift at 10:00 UTC in April
  4038. +       #                                     and 9:00 UTC in October
  4039. +       #     OUTPUT:
  4040. +       #                       INTEGER       1 = DST, 0 = not DST
  4041. +       #
  4042. +       # S  M  T  W  T  F  S
  4043. +       # 1  2  3  4  5  6  7
  4044. +       # 8  9 10 11 12 13 14
  4045. +       #15 16 17 18 19 20 21
  4046. +       #22 23 24 25 26 27 28
  4047. +       #29 30 31
  4048. +       #
  4049. +       # S  M  T  W  T  F  S
  4050. +       #    1  2  3  4  5  6
  4051. +       # 7  8  9 10 11 12 13
  4052. +       #14 15 16 17 18 19 20
  4053. +       #21 22 23 24 25 26 27
  4054. +       #28 29 30 31
  4055. +       #
  4056. +       #**********************************************************************
  4057. +
  4058. +           $USACAN_DST=0;
  4059. +           $mm = $mon;
  4060. +           $dd = $mday;
  4061. +           $ns = $dsec;
  4062. +           $dow= $wday;
  4063. +
  4064. +           if ($mm < 3 || $mm > 11) {
  4065. +           $USACAN_DST=0;  
  4066. +           } elseif ($mm >= 4 and $mm <= 10) {
  4067. +           $USACAN_DST=1;  
  4068. +           } elseif ($mm == 3) {
  4069. +           if ($dd > 13) {
  4070. +               $USACAN_DST=1;  
  4071. +           } elseif ($dd >= ($dow+8)) {
  4072. +               if ($timezone) {
  4073. +               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  4074. +                   $USACAN_DST=0;  
  4075. +               } else {
  4076. +                   $USACAN_DST=1;  
  4077. +               }
  4078. +               } else {
  4079. +               if ($dow == 0 and $ns < 7200) {
  4080. +                   $USACAN_DST=0;  
  4081. +               } else {
  4082. +                   $USACAN_DST=1;  
  4083. +               }
  4084. +               }
  4085. +           } else {
  4086. +               $USACAN_DST=0;  
  4087. +           }
  4088. +           } elseif ($mm == 11) {
  4089. +           if ($dd > 7) {
  4090. +               $USACAN_DST=0;  
  4091. +           } elseif ($dd < ($dow+1)) {
  4092. +               $USACAN_DST=1;  
  4093. +           } elseif ($dow == 0) {
  4094. +               if ($timezone) { # UTC calculations
  4095. +               if ($ns < (7200+($timezone-1)*3600)) {
  4096. +                   $USACAN_DST=1;  
  4097. +               } else {
  4098. +                   $USACAN_DST=0;  
  4099. +               }
  4100. +               } else { # local time calculations
  4101. +               if ($ns < 7200) {
  4102. +                   $USACAN_DST=1;  
  4103. +               } else {
  4104. +                   $USACAN_DST=0;  
  4105. +               }
  4106. +               }
  4107. +           } else {
  4108. +               $USACAN_DST=0;  
  4109. +           }
  4110. +           } # end of month checks
  4111. +       if ($DBX) {print "     DST: $USACAN_DST\n";}
  4112. +       if ($USACAN_DST) {$gmt_offset++;}
  4113. +       $AC_processed++;
  4114. +       }
  4115. +
  4116. +   if ( (!$AC_processed) and ($dst_range == 'FSA-LSO') )
  4117. +       {
  4118. +       if ($DBX) {print "     First Sunday April to Last Sunday October\n";}
  4119. +       #**********************************************************************
  4120. +       # FSA-LSO
  4121. +       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  4122. +       #       Standard time is in effect.
  4123. +       #     Based on first Sunday in April and last Sunday in October at 2 am.
  4124. +       #**********************************************************************
  4125. +          
  4126. +           $USA_DST=0;
  4127. +           $mm = $mon;
  4128. +           $dd = $mday;
  4129. +           $ns = $dsec;
  4130. +           $dow= $wday;
  4131. +
  4132. +           if ($mm < 4 || $mm > 10) {
  4133. +           $USA_DST=0;
  4134. +           } elseif ($mm >= 5 and $mm <= 9) {
  4135. +           $USA_DST=1;
  4136. +           } elseif ($mm == 4) {
  4137. +           if ($dd > 7) {
  4138. +               $USA_DST=1;
  4139. +           } elseif ($dd >= ($dow+1)) {
  4140. +               if ($timezone) {
  4141. +               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  4142. +                   $USA_DST=0;
  4143. +               } else {
  4144. +                   $USA_DST=1;
  4145. +               }
  4146. +               } else {
  4147. +               if ($dow == 0 and $ns < 7200) {
  4148. +                   $USA_DST=0;
  4149. +               } else {
  4150. +                   $USA_DST=1;
  4151. +               }
  4152. +               }
  4153. +           } else {
  4154. +               $USA_DST=0;
  4155. +           }
  4156. +           } elseif ($mm == 10) {
  4157. +           if ($dd < 25) {
  4158. +               $USA_DST=1;
  4159. +           } elseif ($dd < ($dow+25)) {
  4160. +               $USA_DST=1;
  4161. +           } elseif ($dow == 0) {
  4162. +               if ($timezone) { # UTC calculations
  4163. +               if ($ns < (7200+($timezone-1)*3600)) {
  4164. +                   $USA_DST=1;
  4165. +               } else {
  4166. +                   $USA_DST=0;
  4167. +               }
  4168. +               } else { # local time calculations
  4169. +               if ($ns < 7200) {
  4170. +                   $USA_DST=1;
  4171. +               } else {
  4172. +                   $USA_DST=0;
  4173. +               }
  4174. +               }
  4175. +           } else {
  4176. +               $USA_DST=0;
  4177. +           }
  4178. +           } # end of month checks
  4179. +
  4180. +       if ($DBX) {print "     DST: $USA_DST\n";}
  4181. +       if ($USA_DST) {$gmt_offset++;}
  4182. +       $AC_processed++;
  4183. +       }
  4184. +
  4185. +   if ( (!$AC_processed) and ($dst_range == 'LSM-LSO') )
  4186. +       {
  4187. +       if ($DBX) {print "     Last Sunday March to Last Sunday October\n";}
  4188. +       #**********************************************************************
  4189. +       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  4190. +       #       Standard time is in effect.
  4191. +       #     Based on last Sunday in March and last Sunday in October at 1 am.
  4192. +       #**********************************************************************
  4193. +          
  4194. +           $GBR_DST=0;
  4195. +           $mm = $mon;
  4196. +           $dd = $mday;
  4197. +           $ns = $dsec;
  4198. +           $dow= $wday;
  4199. +
  4200. +           if ($mm < 3 || $mm > 10) {
  4201. +           $GBR_DST=0;
  4202. +           } elseif ($mm >= 4 and $mm <= 9) {
  4203. +           $GBR_DST=1;
  4204. +           } elseif ($mm == 3) {
  4205. +           if ($dd < 25) {
  4206. +               $GBR_DST=0;
  4207. +           } elseif ($dd < ($dow+25)) {
  4208. +               $GBR_DST=0;
  4209. +           } elseif ($dow == 0) {
  4210. +               if ($timezone) { # UTC calculations
  4211. +               if ($ns < (3600+($timezone-1)*3600)) {
  4212. +                   $GBR_DST=0;
  4213. +               } else {
  4214. +                   $GBR_DST=1;
  4215. +               }
  4216. +               } else { # local time calculations
  4217. +               if ($ns < 3600) {
  4218. +                   $GBR_DST=0;
  4219. +               } else {
  4220. +                   $GBR_DST=1;
  4221. +               }
  4222. +               }
  4223. +           } else {
  4224. +               $GBR_DST=1;
  4225. +           }
  4226. +           } elseif ($mm == 10) {
  4227. +           if ($dd < 25) {
  4228. +               $GBR_DST=1;
  4229. +           } elseif ($dd < ($dow+25)) {
  4230. +               $GBR_DST=1;
  4231. +           } elseif ($dow == 0) {
  4232. +               if ($timezone) { # UTC calculations
  4233. +               if ($ns < (3600+($timezone-1)*3600)) {
  4234. +                   $GBR_DST=1;
  4235. +               } else {
  4236. +                   $GBR_DST=0;
  4237. +               }
  4238. +               } else { # local time calculations
  4239. +               if ($ns < 3600) {
  4240. +                   $GBR_DST=1;
  4241. +               } else {
  4242. +                   $GBR_DST=0;
  4243. +               }
  4244. +               }
  4245. +           } else {
  4246. +               $GBR_DST=0;
  4247. +           }
  4248. +           } # end of month checks
  4249. +           if ($DBX) {print "     DST: $GBR_DST\n";}
  4250. +       if ($GBR_DST) {$gmt_offset++;}
  4251. +       $AC_processed++;
  4252. +       }
  4253. +   if ( (!$AC_processed) and ($dst_range == 'LSO-LSM') )
  4254. +       {
  4255. +       if ($DBX) {print "     Last Sunday October to Last Sunday March\n";}
  4256. +       #**********************************************************************
  4257. +       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  4258. +       #       Standard time is in effect.
  4259. +       #     Based on last Sunday in October and last Sunday in March at 1 am.
  4260. +       #**********************************************************************
  4261. +          
  4262. +           $AUS_DST=0;
  4263. +           $mm = $mon;
  4264. +           $dd = $mday;
  4265. +           $ns = $dsec;
  4266. +           $dow= $wday;
  4267. +
  4268. +           if ($mm < 3 || $mm > 10) {
  4269. +           $AUS_DST=1;
  4270. +           } elseif ($mm >= 4 and $mm <= 9) {
  4271. +           $AUS_DST=0;
  4272. +           } elseif ($mm == 3) {
  4273. +           if ($dd < 25) {
  4274. +               $AUS_DST=1;
  4275. +           } elseif ($dd < ($dow+25)) {
  4276. +               $AUS_DST=1;
  4277. +           } elseif ($dow == 0) {
  4278. +               if ($timezone) { # UTC calculations
  4279. +               if ($ns < (3600+($timezone-1)*3600)) {
  4280. +                   $AUS_DST=1;
  4281. +               } else {
  4282. +                   $AUS_DST=0;
  4283. +               }
  4284. +               } else { # local time calculations
  4285. +               if ($ns < 3600) {
  4286. +                   $AUS_DST=1;
  4287. +               } else {
  4288. +                   $AUS_DST=0;
  4289. +               }
  4290. +               }
  4291. +           } else {
  4292. +               $AUS_DST=0;
  4293. +           }
  4294. +           } elseif ($mm == 10) {
  4295. +           if ($dd < 25) {
  4296. +               $AUS_DST=0;
  4297. +           } elseif ($dd < ($dow+25)) {
  4298. +               $AUS_DST=0;
  4299. +           } elseif ($dow == 0) {
  4300. +               if ($timezone) { # UTC calculations
  4301. +               if ($ns < (3600+($timezone-1)*3600)) {
  4302. +                   $AUS_DST=0;
  4303. +               } else {
  4304. +                   $AUS_DST=1;
  4305. +               }
  4306. +               } else { # local time calculations
  4307. +               if ($ns < 3600) {
  4308. +                   $AUS_DST=0;
  4309. +               } else {
  4310. +                   $AUS_DST=1;
  4311. +               }
  4312. +               }
  4313. +           } else {
  4314. +               $AUS_DST=1;
  4315. +           }
  4316. +           } # end of month checks                    
  4317. +       if ($DBX) {print "     DST: $AUS_DST\n";}
  4318. +       if ($AUS_DST) {$gmt_offset++;}
  4319. +       $AC_processed++;
  4320. +       }
  4321. +
  4322. +   if ( (!$AC_processed) and ($dst_range == 'FSO-LSM') )
  4323. +       {
  4324. +       if ($DBX) {print "     First Sunday October to Last Sunday March\n";}
  4325. +       #**********************************************************************
  4326. +       #   TASMANIA ONLY
  4327. +       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  4328. +       #       Standard time is in effect.
  4329. +       #     Based on first Sunday in October and last Sunday in March at 1 am.
  4330. +       #**********************************************************************
  4331. +          
  4332. +           $AUST_DST=0;
  4333. +           $mm = $mon;
  4334. +           $dd = $mday;
  4335. +           $ns = $dsec;
  4336. +           $dow= $wday;
  4337. +
  4338. +           if ($mm < 3 || $mm > 10) {
  4339. +           $AUST_DST=1;
  4340. +           } elseif ($mm >= 4 and $mm <= 9) {
  4341. +           $AUST_DST=0;
  4342. +           } elseif ($mm == 3) {
  4343. +           if ($dd < 25) {
  4344. +               $AUST_DST=1;
  4345. +           } elseif ($dd < ($dow+25)) {
  4346. +               $AUST_DST=1;
  4347. +           } elseif ($dow == 0) {
  4348. +               if ($timezone) { # UTC calculations
  4349. +               if ($ns < (3600+($timezone-1)*3600)) {
  4350. +                   $AUST_DST=1;
  4351. +               } else {
  4352. +                   $AUST_DST=0;
  4353. +               }
  4354. +               } else { # local time calculations
  4355. +               if ($ns < 3600) {
  4356. +                   $AUST_DST=1;
  4357. +               } else {
  4358. +                   $AUST_DST=0;
  4359. +               }
  4360. +               }
  4361. +           } else {
  4362. +               $AUST_DST=0;
  4363. +           }
  4364. +           } elseif ($mm == 10) {
  4365. +           if ($dd > 7) {
  4366. +               $AUST_DST=1;
  4367. +           } elseif ($dd >= ($dow+1)) {
  4368. +               if ($timezone) {
  4369. +               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  4370. +                   $AUST_DST=0;
  4371. +               } else {
  4372. +                   $AUST_DST=1;
  4373. +               }
  4374. +               } else {
  4375. +               if ($dow == 0 and $ns < 3600) {
  4376. +                   $AUST_DST=0;
  4377. +               } else {
  4378. +                   $AUST_DST=1;
  4379. +               }
  4380. +               }
  4381. +           } else {
  4382. +               $AUST_DST=0;
  4383. +           }
  4384. +           } # end of month checks                    
  4385. +       if ($DBX) {print "     DST: $AUST_DST\n";}
  4386. +       if ($AUST_DST) {$gmt_offset++;}
  4387. +       $AC_processed++;
  4388. +       }
  4389. +
  4390. +   if ( (!$AC_processed) and ($dst_range == 'FSO-FSA') )
  4391. +       {
  4392. +       if ($DBX) {print "     Sunday in October to First Sunday in April\n";}
  4393. +       #**********************************************************************
  4394. +       # FSO-FSA
  4395. +       #   2008+ AUSTRALIA ONLY (country code 61)
  4396. +       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  4397. +       #       Standard time is in effect.
  4398. +       #     Based on first Sunday in October and first Sunday in April at 1 am.
  4399. +       #**********************************************************************
  4400. +      
  4401. +       $AUSE_DST=0;
  4402. +       $mm = $mon;
  4403. +       $dd = $mday;
  4404. +       $ns = $dsec;
  4405. +       $dow= $wday;
  4406. +
  4407. +       if ($mm < 4 or $mm > 10) {
  4408. +       $AUSE_DST=1;  
  4409. +       } elseif ($mm >= 5 and $mm <= 9) {
  4410. +       $AUSE_DST=0;  
  4411. +       } elseif ($mm == 4) {
  4412. +       if ($dd > 7) {
  4413. +           $AUSE_DST=0;  
  4414. +       } elseif ($dd >= ($dow+1)) {
  4415. +           if ($timezone) {
  4416. +           if ($dow == 0 and $ns < (3600+$timezone*3600)) {
  4417. +               $AUSE_DST=1;  
  4418. +           } else {
  4419. +               $AUSE_DST=0;  
  4420. +           }
  4421. +           } else {
  4422. +           if ($dow == 0 and $ns < 7200) {
  4423. +               $AUSE_DST=1;  
  4424. +           } else {
  4425. +               $AUSE_DST=0;  
  4426. +           }
  4427. +           }
  4428. +       } else {
  4429. +           $AUSE_DST=1;  
  4430. +       }
  4431. +       } elseif ($mm == 10) {
  4432. +       if ($dd >= 8) {
  4433. +           $AUSE_DST=1;  
  4434. +       } elseif ($dd >= ($dow+1)) {
  4435. +           if ($timezone) {
  4436. +           if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  4437. +               $AUSE_DST=0;  
  4438. +           } else {
  4439. +               $AUSE_DST=1;  
  4440. +           }
  4441. +           } else {
  4442. +           if ($dow == 0 and $ns < 3600) {
  4443. +               $AUSE_DST=0;  
  4444. +           } else {
  4445. +               $AUSE_DST=1;  
  4446. +           }
  4447. +           }
  4448. +       } else {
  4449. +           $AUSE_DST=0;  
  4450. +       }
  4451. +       } # end of month checks
  4452. +       if ($DBX) {print "     DST: $AUSE_DST\n";}
  4453. +       if ($AUSE_DST) {$gmt_offset++;}
  4454. +       $AC_processed++;
  4455. +       }
  4456. +
  4457. +   if ( (!$AC_processed) and ($dst_range == 'FSO-TSM') )
  4458. +       {
  4459. +       if ($DBX) {print "     First Sunday October to Third Sunday March\n";}
  4460. +       #**********************************************************************
  4461. +       #     This is s 1 if Daylight Savings Time is in effect and 0 if
  4462. +       #       Standard time is in effect.
  4463. +       #     Based on first Sunday in October and third Sunday in March at 1 am.
  4464. +       #**********************************************************************
  4465. +          
  4466. +           $NZL_DST=0;
  4467. +           $mm = $mon;
  4468. +           $dd = $mday;
  4469. +           $ns = $dsec;
  4470. +           $dow= $wday;
  4471. +
  4472. +           if ($mm < 3 || $mm > 10) {
  4473. +           $NZL_DST=1;
  4474. +           } elseif ($mm >= 4 and $mm <= 9) {
  4475. +           $NZL_DST=0;
  4476. +           } elseif ($mm == 3) {
  4477. +           if ($dd < 14) {
  4478. +               $NZL_DST=1;
  4479. +           } elseif ($dd < ($dow+14)) {
  4480. +               $NZL_DST=1;
  4481. +           } elseif ($dow == 0) {
  4482. +               if ($timezone) { # UTC calculations
  4483. +               if ($ns < (3600+($timezone-1)*3600)) {
  4484. +                   $NZL_DST=1;
  4485. +               } else {
  4486. +                   $NZL_DST=0;
  4487. +               }
  4488. +               } else { # local time calculations
  4489. +               if ($ns < 3600) {
  4490. +                   $NZL_DST=1;
  4491. +               } else {
  4492. +                   $NZL_DST=0;
  4493. +               }
  4494. +               }
  4495. +           } else {
  4496. +               $NZL_DST=0;
  4497. +           }
  4498. +           } elseif ($mm == 10) {
  4499. +           if ($dd > 7) {
  4500. +               $NZL_DST=1;
  4501. +           } elseif ($dd >= ($dow+1)) {
  4502. +               if ($timezone) {
  4503. +               if ($dow == 0 and $ns < (7200+$timezone*3600)) {
  4504. +                   $NZL_DST=0;
  4505. +               } else {
  4506. +                   $NZL_DST=1;
  4507. +               }
  4508. +               } else {
  4509. +               if ($dow == 0 and $ns < 3600) {
  4510. +                   $NZL_DST=0;
  4511. +               } else {
  4512. +                   $NZL_DST=1;
  4513. +               }
  4514. +               }
  4515. +           } else {
  4516. +               $NZL_DST=0;
  4517. +           }
  4518. +           } # end of month checks                    
  4519. +       if ($DBX) {print "     DST: $NZL_DST\n";}
  4520. +       if ($NZL_DST) {$gmt_offset++;}
  4521. +       $AC_processed++;
  4522. +       }
  4523. +
  4524. +   if ( (!$AC_processed) and ($dst_range == 'LSS-FSA') )
  4525. +       {
  4526. +       if ($DBX) {print "     Last Sunday in September to First Sunday in April\n";}
  4527. +       #**********************************************************************
  4528. +       # LSS-FSA
  4529. +       #   2007+ NEW ZEALAND (country code 64)
  4530. +       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  4531. +       #       Standard time is in effect.
  4532. +       #     Based on last Sunday in September and first Sunday in April at 1 am.
  4533. +       #**********************************************************************
  4534. +      
  4535. +       $NZLN_DST=0;
  4536. +       $mm = $mon;
  4537. +       $dd = $mday;
  4538. +       $ns = $dsec;
  4539. +       $dow= $wday;
  4540. +
  4541. +       if ($mm < 4 || $mm > 9) {
  4542. +       $NZLN_DST=1;  
  4543. +       } elseif ($mm >= 5 && $mm <= 9) {
  4544. +       $NZLN_DST=0;  
  4545. +       } elseif ($mm == 4) {
  4546. +       if ($dd > 7) {
  4547. +           $NZLN_DST=0;  
  4548. +       } elseif ($dd >= ($dow+1)) {
  4549. +           if ($timezone) {
  4550. +           if ($dow == 0 && $ns < (3600+$timezone*3600)) {
  4551. +               $NZLN_DST=1;  
  4552. +           } else {
  4553. +               $NZLN_DST=0;  
  4554. +           }
  4555. +           } else {
  4556. +           if ($dow == 0 && $ns < 7200) {
  4557. +               $NZLN_DST=1;  
  4558. +           } else {
  4559. +               $NZLN_DST=0;  
  4560. +           }
  4561. +           }
  4562. +       } else {
  4563. +           $NZLN_DST=1;  
  4564. +       }
  4565. +       } elseif ($mm == 9) {
  4566. +       if ($dd < 25) {
  4567. +           $NZLN_DST=0;  
  4568. +       } elseif ($dd < ($dow+25)) {
  4569. +           $NZLN_DST=0;  
  4570. +       } elseif ($dow == 0) {
  4571. +           if ($timezone) { # UTC calculations
  4572. +           if ($ns < (3600+($timezone-1)*3600)) {
  4573. +               $NZLN_DST=0;  
  4574. +           } else {
  4575. +               $NZLN_DST=1;  
  4576. +           }
  4577. +           } else { # local time calculations
  4578. +           if ($ns < 3600) {
  4579. +               $NZLN_DST=0;  
  4580. +           } else {
  4581. +               $NZLN_DST=1;  
  4582. +           }
  4583. +           }
  4584. +       } else {
  4585. +           $NZLN_DST=1;  
  4586. +       }
  4587. +       } # end of month checks
  4588. +       if ($DBX) {print "     DST: $NZLN_DST\n";}
  4589. +       if ($NZLN_DST) {$gmt_offset++;}
  4590. +       $AC_processed++;
  4591. +       }
  4592. +
  4593. +   if ( (!$AC_processed) and ($dst_range == 'TSO-LSF') )
  4594. +       {
  4595. +       if ($DBX) {print "     Third Sunday October to Last Sunday February\n";}
  4596. +       #**********************************************************************
  4597. +       # TSO-LSF
  4598. +       #     This is returns 1 if Daylight Savings Time is in effect and 0 if
  4599. +       #       Standard time is in effect. Brazil
  4600. +       #     Based on Third Sunday October to Last Sunday February at 1 am.
  4601. +       #**********************************************************************
  4602. +          
  4603. +           $BZL_DST=0;
  4604. +           $mm = $mon;
  4605. +           $dd = $mday;
  4606. +           $ns = $dsec;
  4607. +           $dow= $wday;
  4608. +
  4609. +           if ($mm < 2 || $mm > 10) {
  4610. +           $BZL_DST=1;  
  4611. +           } elseif ($mm >= 3 and $mm <= 9) {
  4612. +           $BZL_DST=0;  
  4613. +           } elseif ($mm == 2) {
  4614. +           if ($dd < 22) {
  4615. +               $BZL_DST=1;  
  4616. +           } elseif ($dd < ($dow+22)) {
  4617. +               $BZL_DST=1;  
  4618. +           } elseif ($dow == 0) {
  4619. +               if ($timezone) { # UTC calculations
  4620. +               if ($ns < (3600+($timezone-1)*3600)) {
  4621. +                   $BZL_DST=1;  
  4622. +               } else {
  4623. +                   $BZL_DST=0;  
  4624. +               }
  4625. +               } else { # local time calculations
  4626. +               if ($ns < 3600) {
  4627. +                   $BZL_DST=1;  
  4628. +               } else {
  4629. +                   $BZL_DST=0;  
  4630. +               }
  4631. +               }
  4632. +           } else {
  4633. +               $BZL_DST=0;  
  4634. +           }
  4635. +           } elseif ($mm == 10) {
  4636. +           if ($dd < 22) {
  4637. +               $BZL_DST=0;  
  4638. +           } elseif ($dd < ($dow+22)) {
  4639. +               $BZL_DST=0;  
  4640. +           } elseif ($dow == 0) {
  4641. +               if ($timezone) { # UTC calculations
  4642. +               if ($ns < (3600+($timezone-1)*3600)) {
  4643. +                   $BZL_DST=0;  
  4644. +               } else {
  4645. +                   $BZL_DST=1;  
  4646. +               }
  4647. +               } else { # local time calculations
  4648. +               if ($ns < 3600) {
  4649. +                   $BZL_DST=0;  
  4650. +               } else {
  4651. +                   $BZL_DST=1;  
  4652. +               }
  4653. +               }
  4654. +           } else {
  4655. +               $BZL_DST=1;  
  4656. +           }
  4657. +           } # end of month checks
  4658. +       if ($DBX) {print "     DST: $BZL_DST\n";}
  4659. +       if ($BZL_DST) {$gmt_offset++;}
  4660. +       $AC_processed++;
  4661. +       }
  4662. +
  4663. +   if (!$AC_processed)
  4664. +       {
  4665. +       if ($DBX) {print "     No DST Method Found\n";}
  4666. +       if ($DBX) {print "     DST: 0\n";}
  4667. +       $AC_processed++;
  4668. +       }
  4669. +
  4670. +   return $gmt_offset;
  4671. +   }
  4672. +
  4673. +?>
  4674. +</TD></TR></TABLE>
  4675. +
  4676.  
  4677.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement