Current Path :
/
home
/
zrcdevco
/
www
/
zrc-email-program
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/zrcdevco/www/zrc-email-program/mailChimpTest0115.php
<?php set_time_limit(100); error_reporting(E_ALL); date_default_timezone_set('America/New_York'); //include('zrc_pdf_email.php'); //include('zrc_ftp_files.php'); if (!(isset($_GET['startDate']) && isset($_GET['endDate']))) { ?> <form> Select a Start Date prior to the End Date. </br> Enter a start date: <input type="date" name="startDate"></br> Enter a end date: <input type="date" name="endDate"></br> SendFaxes:</br> <!--<input type="radio" name="sendFaxes" value="true" checked>Send Faxes --> </br> <input type="radio" name="sendFaxes" value="false">Test Mode - Do not Send Faxes </br> <input type='submit' name='Submit' value='submit'> </form> <?php } else { $startDate = $_GET['startDate']; $endDate = $_GET['endDate']; echo 'Start Date: '.$_GET['startDate'].'</br>'; echo 'End Date'.$_GET['endDate'].'</br>'; // Download Files from Reed FTP server //download_reed_files($startDate, $endDate); // Function to download the FTP files from the Reed Server function download_reed_files_xml($startDate, $endDate) { $newEnd = date("Y-m-d h:i:s"); $newStart = date("Y-m-d h:i:s",strtotime('-14 days')); echo 'New Start'.$newStart .'<br />'; echo 'New End'.$newEnd .'<br />'; // Connect to FTP // $conn_id = ftp_connect('ftp.reeddatalink.com'); $conn_id = ftp_connect('ftp.cmdintegration.com'); // login with username and password $login_result = ftp_login($conn_id, 'zrcworldwide', 'ZrCW0rlD!'); echo "Login Results: $login_result\n"; $processDate = $newStart; while ($processDate <= $newEnd) { echo 'Process Date: '.$processDate.'</br>'; echo "<br />Start\n"; echo date("l jS \of F Y h:i:s A") . "<br>"; // Reed Insight files contain a date stamp so new code will be required to // add the date stamp. // Use ftp to retrieve the files from the Reed Server // define some variables $file_date = str_replace('-','',$processDate); $zipfile_name = "1.3_DL_ZRCWorldwide_XML_" . $file_date . ".zip"; $local_file = $zipfile_name; $server_file = '/zrcworldwide_insight/'.$zipfile_name; // try to download $server_file and save to $local_file if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { echo "Successfully written to $local_file\n"; } else { echo "There was a problem writing to $local_file\n"; } echo date("l jS \of F Y h:i:s A") . "<br>"; // increment process date $date = new DateTime($processDate); $date->add(new DateInterval('P1D')); $processDate = $date->format('Y-m-d'); echo date("l jS \of F Y h:i:s A") . "<br>"; } } $newEnd = date("Y-m-d h:i:s"); $newStart = date("Y-m-d h:i:s",strtotime('-14 days')); download_reed_files_xml($newStart, $newEnd); $firstPass = TRUE; while ($processDate <= $newEnd) { echo 'Process Date: '.$processDate.'</br>'; echo "<br />Start\n"; echo date("l jS \of F Y h:i:s A") . "<br>"; // Unzip the results from Reed Connect // Code taken from the website http://www.timlinden.com/blog/website-development/unzip-files-with-php/ // Reed Insight files contain a date stamp so new code will be required to // add the date stamp. // Use ftp to retrieve the files from the Reed Server // define some variables $file_date = str_replace('-','',$processDate); $zipfile_name = "1.3_DL_ZRCWorldwide_XML_" . $file_date . ".zip"; $file = "1.3_DL_ZRCWorldwide_XML_" . $file_date . ".xml"; echo date("l jS \of F Y h:i:s A") . "<br>"; $zip = zip_open( $zipfile_name ); $filesToProcess = array($file); if (is_resource($zip)) { while ($zip_entry = zip_read($zip)) { $fp = fopen(zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { if (in_array(zip_entry_name($zip_entry), $filesToProcess) ) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); // echo "<br />".zip_entry_name($zip_entry); zip_entry_close($zip_entry); fclose($fp); } } } zip_close($zip); } echo "<br />files unzipped"; echo date("l jS \of F Y h:i:s A") . "<br>"; //Pull the Do Not Fax list $exclude_numbers[] = ''; // Process each file foreach ($filesToProcess as $file_name) { if (file_exists($file_name)) { $xml = simplexml_load_file($file_name); $a=array("0"=>"Roles:"); $prim=array("0"=>"Primary contacts:"); $cemail=array("0"=>"Company emails:"); $fcn1=array("0"=>"FCN initial run:"); $fcn=array("0"=>"First contact name:"); foreach($xml->Project as $project1){ $projectname = (string) $project1->attributes()->Title; echo "<br />Projectname: <br />"; echo $projectname; foreach($project1->Companies->children() as $company){ $participantRoles = (string) $company->ClassificationTypes->ClassificationType['Type']; echo "<br />Participant Roles: <br />"; echo $participantRoles; array_push($a,"$participantRoles"); $primary = (string) $company->ParticipantRoles->ParticipantRole['ContactName']; echo "<br />Primary: <br />"; echo $primary; $companyName = (string) $company['Name']; $companyEmail = (string) $company->Email; echo "<br />Company Name: <br />"; echo $companyName; $first_contact = (string) $project1->Companies->Company->Contacts->Contact[0]; $first_contactName = (string) $first_contact['Name']; $first_contactEmail = (string) $first_contact->Email; array_push($fcn1,"$first_contactEmail"); echo "<br />Initial run at FCN: <br />"; print_r($fcn1); if (preg_match("/(Architect|Structural|Contractor|Steel)/i",$participantRoles)) { echo "<br />In Architect Engineer Loop<br />"; foreach( $company->Contacts as $contacts ){ foreach( $contacts as $contact ){ echo "<br />Primary Contact<br />"; echo $primary; echo "<br />Contact to Update<br />"; echo $contact['Name']."<br />"; print_r($contact['Name']); if ($primary == $contact['Name']) { array_push($prim,"$primary"); echo "<br />Found Primary Contact<br />"; if( !empty( $contact->Email )){ echo "<br />Contact to Update<br />"; echo $contact['Name']; $email = (Array)$contact->Email; $email = $email['0']; $name = explode( ' ', $contact['Name']); $first = array_shift($name); $last = array_pop($name); $name_middle = trim(implode(' ', $name)); echo '<br />First: ' . $first . ', '; echo 'Last: ' . $last . ', '; echo 'Middle: ' . $name_middle . '.'; echo "<br />Projectname: <br />"; echo $projectname; //$first = $name['0']; //$last = $name['1']; $architects[] = array( 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => $first, 'LNAME' => $last, 'PNAME' => $projectname, 'COMPANY' => $companyName, 'ROLE' => $participantRoles), ); } } if (empty ($primary)) { echo "<br />No Primary Contact<br />"; $primary = "No primary"; $name = $companyName; if( !empty($companyEmail)){ $email = $companyEmail; array_push($cemail,"$companyEmail"); $name = explode( ' ', $companyName); $first = array_shift($companyName); $last = array_pop($companyName); $name_middle = trim(implode(' ', $companyName)); echo '<br />First: ' . $first . ', '; echo 'Last: ' . $last . ', '; echo 'Middle: ' . $name_middle . '.'; //$first = $name['0']; //$last = $name['1']; $architects[] = array( 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => $first, 'LNAME' => $last, 'PNAME' => $projectname, 'COMPANY' => $companyName, 'ROLE' => $participantRoles), ); } if(empty($companyEmail)){ $companyEmail = "No cEmail"; $email = $first_contactEmail; array_push($fcn,"$first_contactName"); $name = explode( ' ', $first_contactName); $first = array_shift($first_contactName); $last = array_pop($first_contactName); $name_middle = trim(implode(' ', $first_contactName)); echo '<br />First: ' . $first . ', '; echo 'Last: ' . $last . ', '; echo 'Middle: ' . $name_middle . '.'; //$first = $name['0']; //$last = $name['1']; $architects[] = array( 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => $first, 'LNAME' => $last, 'PNAME' => $projectname, 'COMPANY' => $companyName, 'ROLE' => $participantRoles), ); } } } } } } } $a = array_unique($a); print_r($a); echo "<br /><br />"; print_r($prim); echo count($prim); echo "<br /><br />"; print_r($cemail); echo count($cemail); echo "<br /><br />"; print_r($fcn); echo count($fcn); } else { exit('Failed to open test.xml.'. $file_name); } $file = fopen($file_name,"r"); $table_name = substr($file_name,0,strpos($file_name,'.csv')); // Read in the header line $line = fgets($file); // Remove all double quotes (") from the header line $line = str_replace('"','',$line); //print_r($line); $column_names = explode(',',$line); while (!feof($file)) { $data_line = fgets($file); //print_r( $data_line); // Enter in blank strings to insert in the DB $data_line = str_replace(', ,',', "",',$data_line); $data_line = str_replace(', ,',',"",',$data_line); // Check for comma as the last character in the string. If so add an empty string. // last comma is 4 characters from the end due to cr, lf and space characters. if (strrpos($data_line,',',0) == (strlen($data_line)-4)) $data_line .= '""'; } fclose($file); echo "<br />$file_name loaded"; echo date("l jS \of F Y h:i:s A") . "<br>"; } echo "<br />all data loaded"; echo date("l jS \of F Y h:i:s A") . "<br>"; echo date("l jS \of F Y h:i:s A") . "<br>"; $firstPass = False; // increment process date $date = new DateTime($processDate); $date->add(new DateInterval('P1D')); $processDate = $date->format('Y-m-d'); echo date("l jS \of F Y h:i:s A") . "<br>"; } fclose($outFileArchitect); echo "<br />Faxes Sent - Total $totalFaxesArchitect<br />"; // export results to a file for download echo "<br />data ready for download<br />"; echo "<a href='reed_merge_data_architects.csv'>Right Click and Save As for Reed Merge File</a>"; fclose($outFileBidder); echo "<br />Faxes Sent - Total $totalFaxesBidder<br />"; // export results to a file for download echo "<br />data ready for download<br />"; echo "<a href='reed_merge_data.csv'>Right Click and Save As for Reed Merge File</a>"; //output faxes sent to database for reporting /*$sql = "INSERT INTO FaxHistory (processdate, architectfaxes, bidderfaxes) VALUES ('".$processDate."','".$totalFaxesArchitect."','".$totalFaxesBidder."')"; if (mysql_query($sql, $conn)) { echo "History updated"; } else { echo "Error: " . $sql . "<br>" . mysql_error($conn); }*/ // close the FTP connection echo date("l jS \of F Y h:i:s A") . "<br>"; } // End While ?>