Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <style>
- body {background-color: #3E3D3D;}
- form {
- border: 3px solid #f1f1f1;
- }
- .maincontainer {width: 550px;margin: 0 auto; padding: 20px; background-color: whitesmoke;}
- input[type=text], input[type=password] {
- width: 100%;
- padding: 12px 20px;
- margin: 8px 0;
- display: inline-block;
- border: 1px solid #ccc;
- box-sizing: border-box;
- }
- .button {
- background-color: #4CAF50;
- color: white;
- padding: 14px 20px;
- margin: 8px 0;
- border: none;
- cursor: pointer;
- width: 80%;
- }
- .button:hover {
- opacity: 0.8;
- }
- .cancelbtn {
- width: auto;
- padding: 10px 18px;
- background-color: #f44336;
- }
- .imgcontainer {
- text-align: center;
- margin: 24px 0 12px 0;
- }
- img.avatar {
- width: 40%;
- border-radius: 50%;
- }
- .container {
- padding: 16px;
- width: 500px;
- text-align: center;
- }
- span.psw {
- float: right;
- padding-top: 16px;
- }
- /* Change styles for span and cancel button on extra small screens */
- @media screen and (max-width: 300px) {
- span.psw {
- display: block;
- float: none;
- }
- .cancelbtn {
- width: 100%;
- }
- }
- </style>
- <body>
- <div class="maincontainer">
- <form method="post" action="">
- <div class="imgcontainer">
- <img src="https://www.paragonvision.com/wp-content/uploads/2016/12/paragon-logo.png" width="150px" alt="paragon logo" >
- </div>
- <div class="container">
- <?php
- //Developed by Robert Moses 08/3/2017 v.Beta 0.112.1624b
- //This app takes a JSONP datasource provided by client to parse and format a Importable CSV for a maps plugin in Wordpress. Developed for AmbientSkies.com
- //Lets get our Datasource where our list starts
- $post='';
- date_default_timezone_set('UTC');
- $date = date("Y-m-d-H:i:s");
- $doctorlist ='DoctorMapImport.csv';
- //Lets connect to the Database and get ready to put all our records in
- $host="*";
- $user="*";
- $password="*";
- $dbname="*";
- //mysql info
- $conn = new mysqli($host, $user, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error ."</br>");
- }
- //If $step is not set we are on the first step
- if ($_POST['step'] == '1') {
- // Do something.
- $datasource = 'http://drsearch.paragonvision.com/beta/jsonp-drsearch.asp';
- //Dont forget to change our time
- //What should we name it? Lets take our Date and time and add docTmpfile.csv
- //Lets Get our Data
- $getdata = file_get_contents($datasource);
- //Now lets decode our jsonP request and make it into a php array
- function jsonp_decode($jsonp, $assoc = false) { // PHP 5.3 adds depth as third parameter to json_decode
- if($jsonp[0] !== '[' && $jsonp[0] !== '{') { // we have JSONP
- $jsonp = substr($jsonp, strpos($jsonp, '('));
- }//we have to now decode our jsonP for sorting and cleaning
- return json_decode(trim($jsonp,'();'), $assoc);
- }
- //Decoding our JSON and Putting it in $data
- $data = jsonp_decode($getdata, true);
- // loop over the rows, key, subarray, then subsubarray so we can remove all commas and line breaks per record.
- foreach($data as $key => $subarray) {
- foreach($subarray as $subkey => $subsubarray) {
- //Our Counter
- $rec = $rec +1;
- //Incase we need a null value
- $blank = NULL;
- //Lets combin our address to format for map import
- $fulladdress = $data[$key][$subkey]['address'].$data[$key][$subkey]['address2'].' '.$data[$key][$subkey]['city'] .' '. $data[$key][$subkey]['state'].' '. $data[$key][$subkey]['country'].' '.$data[$key][$subkey]['postal'];
- //Lets take away any breaks in our address some data had hidden breaks.
- $removebreak = str_replace (array("\r\n", "\n", "\r"), ' ', $fulladdress);
- //Again lets remove any hidden commas in our full address
- $finaladdress = str_replace( ',', '', $removebreak );
- $finaladdress = mysqli_real_escape_string($conn, $finaladdress);
- //Lets Make our Title by combining buissness name, First name, And Last Name
- //' '.$data[$key][$subkey]['fName'].' '.$data[$key][$subkey]['lName'];
- //We need to make individual arrrays to put it line by line in a csv. So we cant have any ',' anywhere in our results. We will later add the correct comma in the correct place from our array. We will now make variables out of each to ensure we are creating the correct string and removing all commas for each string. Possible redundancy?
- $docid = str_replace( ',', '',$data[$key][$subkey]['id']);
- $docid = mysqli_real_escape_string($conn, $docid);
- $name = str_replace( ',', '',$data[$key][$subkey]['businessName']);
- $name = mysqli_real_escape_string($conn, $name);
- $fname = str_replace( ',', '',$data[$key][$subkey]['fName']);
- $fname = mysqli_real_escape_string($conn, $fname);
- $lname = str_replace( ',', '',$data[$key][$subkey]['lName']);
- $lname = mysqli_real_escape_string($conn, $lname);
- $web = str_replace( ',', '',$data[$key][$subkey]['Website']);
- $web = mysqli_real_escape_string($conn, $web);
- $shownweb = str_replace( ',', '',$data[$key][$subkey]['shownWebsite']);
- $shownweb = mysqli_real_escape_string($conn, $shownweb);
- $address = str_replace( ',', '',$data[$key][$subkey]['address']);
- $address = mysqli_real_escape_string($conn, $address);
- $address2 = str_replace( ',', '',$data[$key][$subkey]['address2']);
- $address2 = mysqli_real_escape_string($conn, $address2);
- $city = str_replace( ',', '',$data[$key][$subkey]['city']);
- $city = mysqli_real_escape_string($conn, $city);
- $state = str_replace( ',', '',$data[$key][$subkey]['state']);
- $state = mysqli_real_escape_string($conn, $state);
- $postal = str_replace( ',', '',$data[$key][$subkey]['postal']);
- $postal = mysqli_real_escape_string($conn, $postal);
- $country = str_replace( ',', '',$data[$key][$subkey]['country']);
- $country = mysqli_real_escape_string($conn, $country);
- $phone = str_replace( ',', '',$data[$key][$subkey]['phone']);
- $phone = mysqli_real_escape_string($conn, $phone);
- $fax = str_replace( ',', '',$data[$key][$subkey]['fax']);
- $fax = mysqli_real_escape_string($conn, $fax);
- $lastUpdate = str_replace( ',', '',$data[$key][$subkey]['lastUpdate']);
- $lastUpdate = mysqli_real_escape_string($conn, $lastUpdate);
- $created = str_replace( ',', '',$data[$key][$subkey]['created']);
- $created = mysqli_real_escape_string($conn, $created);
- $logo = str_replace( ',', '',$data[$key][$subkey]['logo']);
- $logo = mysqli_real_escape_string($conn, $logo);
- $email = str_replace( ',', '',$data[$key][$subkey]['email']);
- $email = mysqli_real_escape_string($conn, $email);
- $phone = str_replace( ',', '',$data[$key][$subkey]['phone']);
- $phone = mysqli_real_escape_string($conn, $phone);
- $fax = str_replace( ',', '',$data[$key][$subkey]['fax']);
- $fax = mysqli_real_escape_string($conn, $fax);
- $lat = str_replace( ',', '',$data[$key][$subkey]['Latitude']);
- $lat = mysqli_real_escape_string($conn, $lat);
- $long = str_replace( ',', '',$data[$key][$subkey]['Longitude']);
- $long = mysqli_real_escape_string($conn, $long);
- $webnotes = str_replace( ',', '',$data[$key][$subkey]['WebNotes']);
- $webnotes = mysqli_real_escape_string($conn, $webnotes);
- $prompres = str_replace( ',', '',$data[$key][$subkey]['Promo']);
- //Lets check if the Promo is 1 or 0 and create a string for it.
- if ($prompres == 1){$promo = 'Free Screening';} else { $promo = 'Practitioners';};
- //Lets check if our Clinic name is set
- $fullname = $data[$key][$subkey]['fName']." ".$data[$key][$subkey]['lName'];
- $fullname = mysqli_real_escape_string($conn, $fullname);
- $infobox = '<h6>Practice Details</h6></br><strong>Phone:</strong> '.$phone.'</br><strong>Fax:</strong> '.$fax.'</br><strong>Address:</strong> '.$finaladdress.'</br><strong>Website:</strong> '.$web.'</br><h6>Practitioner(s)</h6></br> '.$fullname.'</br>';
- $infobox = mysqli_real_escape_string($conn, $infobox);
- if (empty($name)){$titleinfo = $fullname;} else {$titleinfo = $name; };
- $titleinfo = mysqli_real_escape_string($conn, $titleinfo);
- //Lets add our new record to the database
- $sql = "INSERT INTO doc_list (docid,businessName,fName,lName,Website,shownWebsite,FullAddress,address,address2, city,state,postal,country,phone,fax,lastUpdate,created,logo,email,lat,lng,promo,WebNotes,Approve,InfoBoxHtml,Fulltitle,parent)
- VALUES ('$docid','$titleinfo','$fname','$lname','$web','$shownweb','$finaladdress','$address','$address2','$city','$state','$postal','$country','$phone','$fax','$lastUpdate','$created','$logo','$email','$lat','$long','$promo','$webnotes','1','$infobox','$titleinfo','0')";
- if ($conn->query($sql) === TRUE) {
- //WE ADDED OUR RESULTS
- } else {
- echo "Error:" . $sql . "<br>" . $conn->error."</br>";
- }
- }
- } echo '<center><strong>First Step Complete - Added '.$rec.' Records to database</strong></br> <p>Click the Button to Conitune to step 2 and proccess the Matching Doctors and clinics.</br> This process can take up to 10 minutes to complete.</br><input type="hidden" name="step" value="2"> <input type="submit" class="button" value="Step 2 of 3"></p></center>';
- }
- elseif ($_POST['step'] == '2'){
- //We have our records in the database Now we are going to grab all of them again. Seperate and sort each record and match with other records in the database and create a new table with all our Practices in it.
- $sql = "SELECT * FROM doc_list";
- //$sql= "SELECT * FROM doc_list GROUP BY lat, lng";
- $rec = 0;
- $docrec = 0;
- $skipped = 0;
- $result = $conn->query($sql);
- while ($row = mysqli_fetch_assoc($result))
- {
- $reclat = $row['lat'];
- $reclng = $row['lng'];
- $rowid = $row['docid'];
- $sqlmatch = "UPDATE doc_list SET parent ='1' WHERE docid='$rowid'";
- $conn->query($sqlmatch);
- if (empty($row['lat'])){$skipped = $skipped + 1; }
- elseif ($row['lat'] == '-500'){ $skipped = $skipped + 1;}
- else {
- $docsql = "SELECT * FROM doc_list WHERE lat='".$reclat."' AND lng='".$reclng."'";
- $docresult = $conn->query($docsql);
- $rec = $rec + 1;
- while ($docrow = mysqli_fetch_assoc($docresult)){
- $itemid = $docrow['docid'];
- $match = $docrow['parent'];
- //We have our record and added it. Lets append to what we have. Then delete this record from the database
- if ($match == '1'){}
- else { $docrec = $docrec + 1;
- $newdoc ='';
- $newdoc = $docrow['fName']." ".$docrow['lName']."</br>";
- $sqlup = "UPDATE doc_list SET InfoBoxHtml = concat(InfoBoxHtml,'$newdoc') WHERE docid='$rowid'";
- $conn->query($sqlup);
- //Delete this record so we dont go in a loop
- $delsql ="DELETE FROM doc_list WHERE docid='".$itemid."'";
- $conn->query($delsql);
- } }
- //We have our matches now lets combine them
- }
- //Now lets insertthe new Record into the database
- //Lets loop now through each result and find matches then insert a new clinic name in the database.
- }
- echo '<center><strong>Second Step Complete - Adding Doctors to their Clinics</strong></br><strong>'.$skipped.'</strong> Non Matching Records</br><strong>'.$docrec.'</strong> Records Combined </br> Click the Button to Continue to step 3 To Download Your Csv <input type="hidden" name="step" value="3"> <input class="button" type="submit" value="Step 3 of 3">';
- }
- elseif ($_POST['step'] == '3'){
- //Great now lets export the new formated database into a csv and download
- // lets output headers so that the file is downloaded rather than displayed
- //header('Content-Type: text/csv; charset=utf-8');
- //header('Content-Disposition: attachment; filename=DoctorMapImport.csv');
- //lets create a file pointer connected to the output stream
- $output = fopen($doctorlist, 'w');
- //This is what our array looks like from the json --
- //doctors":[{"id":10002,"businessName":"School Of Optometry","fName":"Edward","lName":"Bennett, O.D.","Website":null,"shownWebsite":null,"address":"One University Blvd\r\n331 Marillac Hall","address2":null,"city":"St. Louis","state":"MO","postal":"63121","country":null,"phone":"314-516-6258","fax":"314-516-5507","LastUpdate":"7/7/2017","created":"6/27/2002","Logo":null,"email":"ebennett@umsl.edu","Latitude":38.716864,"Longitude":-90.306338,"Promo":false,"WebNotes":null,"SCert":10002,"AssocCert":10002,"Internal":false}
- // now we output the column headings
- fputcsv($output, array('id','businessName','fName','lName','Website','shownWebsite','FullAddress','address','address2', 'city','state','postal','country','phone','fax','lastUpdate','created','logo','email','lat', 'lng','promo','WebNotes','Approve','InfoBoxHtml','Fulltitle'));
- $finalsql = "SELECT * FROM doc_list";
- $finalresult = $conn->query($finalsql);
- while ($finalrow = mysqli_fetch_assoc($finalresult))
- {
- $docid = $finalrow['id'];
- $fulladdress = $finalrow['FullAddress'];
- $name = $finalrow['businessName'];
- $fname = $finalrow['fName'];
- $lname = $finalrow['lName'];
- $web = $finalrow['Website'];
- $shownweb = $finalrow['shownWebsite'];
- $address = $finalrow['address'];
- $address2 = $finalrow['address2'];
- $city = $finalrow['city'];
- $state = $finalrow['state'];
- $postal = $finalrow['postal'];
- $country = $finalrow['country'];
- $phone = $finalrow['phone'];
- $fax = $finalrow['fax'];
- $lastUpdate = $finalrow['lastUpdate'];
- $created = $finalrow['created'];
- $logo = $finalrow['logo'];
- $email = $finalrow['email'];
- $phone = $finalrow['phone'];
- $fax = $finalrow['fax'];
- $webnotes = $finalrow['WebNotes'];
- $prompres =$finalrow['Promo'];
- $infobox = $finalrow['InfoBoxHtml'];
- $docid = $finalrow['id'];
- $name = $finalrow['businessName'];
- $fname = $finalrow['fName'];
- $lname = $finalrow['lName'];
- $web = $finalrow['Website'];
- $shownweb = $finalrow['shownWebsite'];
- $address = $finalrow['address'];
- $address2 = $finalrow['address2'];
- $city = $finalrow['city'];
- $state = $finalrow['state'];
- $postal = $finalrow['postal'];
- $country = $finalrow['country'];
- $phone = $finalrow['phone'];
- $fax = $finalrow['fax'];
- $lastUpdate = $finalrow['lastUpdate'];
- $created = $finalrow['created'];
- $logo = $finalrow['logo'];
- $email = $finalrow['email'];
- $phone = $finalrow['phone'];
- $fax = $finalrow['fax'];
- $lat = $finalrow['lat'];
- $long = $finalrow['lng'];
- $webnotes = $finalrow['WebNotes'];
- $prompres = $finalrow['promo'];
- $titleinfo = $finalrow['Fulltitle'];
- //Now lets make our results and create and arry to put it in our CSV.
- $result = array($docid,$name,$fname,$lname,$web,$shownweb,$fulladdress,$address,$address2,$city,$state,$postal,$country,$phone,$fax,$lastUpdate,$created,$logo,$email,$lat,$long,$prompres,$webnotes,'1',$infobox,$titleinfo);
- fputcsv($output,$result);
- }
- fclose($output);
- echo '<center><strong>Export Complete!<strong></br>All Steps Complete Download your CSV Here </br><h2><a href="/'.$doctorlist.'" target="_blank">Doctors List</a></h2></strong></center>';
- }
- //Show Landing Page If nothing is posted
- else {
- $finalsql = "DELETE FROM doc_list";
- $finalresult = $conn->query($finalsql);
- echo '<center><strong>Welcome to the Paragon Doctor Export System</strong></br><p>Click the Button to Grab the Doctors from Paragons Server and Add them into our Databse.</br> Step 1 Can take up to a 5 minutes to complete </br><input type="hidden" name="step" value="1"> <input type="submit" class="button" value="Lets Begin!"></p></center>';
- }
- $conn->close();
- ?></div>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement