Advertisement
Guest User

Ambient Skies Example

a guest
Jan 22nd, 2019
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <style>
  4.     body {background-color: #3E3D3D;}
  5. form {
  6.     border: 3px solid #f1f1f1;
  7. }
  8.     .maincontainer {width: 550px;margin: 0 auto; padding: 20px; background-color: whitesmoke;}
  9.  
  10. input[type=text], input[type=password] {
  11.     width: 100%;
  12.     padding: 12px 20px;
  13.     margin: 8px 0;
  14.     display: inline-block;
  15.     border: 1px solid #ccc;
  16.     box-sizing: border-box;
  17. }
  18.  
  19. .button {
  20.     background-color: #4CAF50;
  21.     color: white;
  22.     padding: 14px 20px;
  23.     margin: 8px 0;
  24.     border: none;
  25.     cursor: pointer;
  26.     width: 80%;
  27. }
  28.  
  29. .button:hover {
  30.     opacity: 0.8;
  31. }
  32.  
  33. .cancelbtn {
  34.     width: auto;
  35.     padding: 10px 18px;
  36.     background-color: #f44336;
  37. }
  38.  
  39. .imgcontainer {
  40.     text-align: center;
  41.     margin: 24px 0 12px 0;
  42. }
  43.  
  44. img.avatar {
  45.     width: 40%;
  46.     border-radius: 50%;
  47. }
  48.  
  49. .container {
  50.     padding: 16px;
  51.     width: 500px;
  52.     text-align: center;
  53. }
  54.  
  55. span.psw {
  56.     float: right;
  57.     padding-top: 16px;
  58. }
  59.  
  60. /* Change styles for span and cancel button on extra small screens */
  61. @media screen and (max-width: 300px) {
  62.     span.psw {
  63.        display: block;
  64.        float: none;
  65.     }
  66.     .cancelbtn {
  67.        width: 100%;
  68.     }
  69. }
  70. </style>
  71. <body>
  72.  
  73. <div class="maincontainer">
  74.  
  75. <form method="post" action="">
  76.   <div class="imgcontainer">
  77.     <img src="https://www.paragonvision.com/wp-content/uploads/2016/12/paragon-logo.png" width="150px" alt="paragon logo" >
  78.   </div>
  79.  
  80.   <div class="container">
  81.    
  82.  
  83. <?php
  84.     //Developed by Robert Moses 08/3/2017 v.Beta 0.112.1624b
  85. //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
  86. //Lets get our Datasource where our list starts
  87. $post='';
  88. date_default_timezone_set('UTC');
  89. $date = date("Y-m-d-H:i:s");
  90. $doctorlist ='DoctorMapImport.csv';
  91. //Lets connect to the Database and get ready to put all our records in     
  92. $host="*";
  93. $user="*";
  94. $password="*";
  95. $dbname="*";
  96.   //mysql info
  97. $conn = new mysqli($host, $user, $password, $dbname);
  98. // Check connection
  99. if ($conn->connect_error) {
  100. die("Connection failed: " . $conn->connect_error ."</br>");
  101. }
  102. //If $step is not set we are on the first step
  103. if ($_POST['step'] == '1') {
  104.   // Do something.
  105.  
  106.  
  107. $datasource = 'http://drsearch.paragonvision.com/beta/jsonp-drsearch.asp';
  108. //Dont forget to change our time
  109.  
  110.  
  111. //What should we name it? Lets take our Date and time and add docTmpfile.csv
  112.  
  113. //Lets Get our Data
  114. $getdata = file_get_contents($datasource);
  115. //Now lets decode our jsonP request and make it into a php array
  116. function jsonp_decode($jsonp, $assoc = false) { // PHP 5.3 adds depth as third parameter to json_decode
  117.     if($jsonp[0] !== '[' && $jsonp[0] !== '{') { // we have JSONP
  118.        $jsonp = substr($jsonp, strpos($jsonp, '('));
  119.     }//we have to now decode our jsonP for sorting and cleaning
  120.     return json_decode(trim($jsonp,'();'), $assoc);
  121. }
  122. //Decoding our JSON and Putting it in $data
  123. $data = jsonp_decode($getdata, true);      
  124.  
  125.  
  126. // loop over the rows, key, subarray, then subsubarray so we can remove all commas and line breaks per record.
  127. foreach($data as $key => $subarray) {
  128.    foreach($subarray as $subkey => $subsubarray) {     
  129. //Our Counter
  130. $rec = $rec +1;
  131. //Incase we need a null value
  132. $blank = NULL;  
  133. //Lets combin our address to format for map import
  134.     $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'];
  135.     //Lets take away any breaks in our address some data had hidden breaks.
  136.     $removebreak = str_replace (array("\r\n", "\n", "\r"), ' ', $fulladdress);
  137.     //Again lets remove any hidden commas in our full address
  138.     $finaladdress = str_replace( ',', '', $removebreak );
  139.        $finaladdress = mysqli_real_escape_string($conn, $finaladdress);
  140.     //Lets Make our Title by combining buissness name, First name, And Last Name  
  141.         //' '.$data[$key][$subkey]['fName'].' '.$data[$key][$subkey]['lName'];
  142.     //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?
  143.         $docid = str_replace( ',', '',$data[$key][$subkey]['id']);
  144.        $docid = mysqli_real_escape_string($conn, $docid);
  145.         $name = str_replace( ',', '',$data[$key][$subkey]['businessName']);
  146.        $name = mysqli_real_escape_string($conn, $name);
  147.         $fname = str_replace( ',', '',$data[$key][$subkey]['fName']);
  148.        $fname = mysqli_real_escape_string($conn, $fname);
  149.         $lname = str_replace( ',', '',$data[$key][$subkey]['lName']);
  150.        $lname = mysqli_real_escape_string($conn, $lname);
  151.         $web = str_replace( ',', '',$data[$key][$subkey]['Website']);
  152.        $web = mysqli_real_escape_string($conn, $web);
  153.         $shownweb = str_replace( ',', '',$data[$key][$subkey]['shownWebsite']);
  154.        $shownweb = mysqli_real_escape_string($conn, $shownweb);
  155.         $address = str_replace( ',', '',$data[$key][$subkey]['address']);
  156.        $address = mysqli_real_escape_string($conn, $address);
  157.         $address2 = str_replace( ',', '',$data[$key][$subkey]['address2']);
  158.        $address2 = mysqli_real_escape_string($conn, $address2);
  159.         $city = str_replace( ',', '',$data[$key][$subkey]['city']);
  160.        $city = mysqli_real_escape_string($conn, $city);
  161.         $state = str_replace( ',', '',$data[$key][$subkey]['state']);
  162.        $state = mysqli_real_escape_string($conn, $state);
  163.         $postal = str_replace( ',', '',$data[$key][$subkey]['postal']);
  164.        $postal = mysqli_real_escape_string($conn, $postal);
  165.         $country = str_replace( ',', '',$data[$key][$subkey]['country']);
  166.        $country = mysqli_real_escape_string($conn, $country);
  167.         $phone = str_replace( ',', '',$data[$key][$subkey]['phone']);
  168.        $phone = mysqli_real_escape_string($conn, $phone);
  169.         $fax = str_replace( ',', '',$data[$key][$subkey]['fax']);
  170.        $fax = mysqli_real_escape_string($conn, $fax);
  171.         $lastUpdate = str_replace( ',', '',$data[$key][$subkey]['lastUpdate']);
  172.        $lastUpdate = mysqli_real_escape_string($conn, $lastUpdate);
  173.         $created = str_replace( ',', '',$data[$key][$subkey]['created']);
  174.        $created = mysqli_real_escape_string($conn, $created);
  175.         $logo = str_replace( ',', '',$data[$key][$subkey]['logo']);
  176.        $logo = mysqli_real_escape_string($conn, $logo);
  177.         $email = str_replace( ',', '',$data[$key][$subkey]['email']);
  178.        $email = mysqli_real_escape_string($conn, $email);
  179.         $phone = str_replace( ',', '',$data[$key][$subkey]['phone']);
  180.        $phone = mysqli_real_escape_string($conn, $phone);
  181.         $fax = str_replace( ',', '',$data[$key][$subkey]['fax']);
  182.        $fax = mysqli_real_escape_string($conn, $fax);
  183.         $lat = str_replace( ',', '',$data[$key][$subkey]['Latitude']);
  184.        $lat = mysqli_real_escape_string($conn, $lat);
  185.         $long = str_replace( ',', '',$data[$key][$subkey]['Longitude']);
  186.        $long = mysqli_real_escape_string($conn, $long);
  187.         $webnotes = str_replace( ',', '',$data[$key][$subkey]['WebNotes']);
  188.        $webnotes = mysqli_real_escape_string($conn, $webnotes);
  189.         $prompres = str_replace( ',', '',$data[$key][$subkey]['Promo']);
  190.        
  191.         //Lets check if the Promo is 1 or 0 and create a string for it.
  192.         if ($prompres == 1){$promo = 'Free Screening';} else { $promo = 'Practitioners';};
  193.        //Lets check if our Clinic name is set
  194.        $fullname = $data[$key][$subkey]['fName']." ".$data[$key][$subkey]['lName'];
  195.        $fullname = mysqli_real_escape_string($conn, $fullname);
  196.         $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>';
  197.        $infobox = mysqli_real_escape_string($conn, $infobox);
  198.         if (empty($name)){$titleinfo = $fullname;} else {$titleinfo = $name; };
  199.        $titleinfo = mysqli_real_escape_string($conn, $titleinfo);      
  200.        //Lets add our new record to the database
  201.        $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)
  202. 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')";
  203.        
  204.            
  205. if ($conn->query($sql) === TRUE) {
  206. //WE ADDED OUR RESULTS
  207. } else {
  208. echo "Error:" . $sql . "<br>" . $conn->error."</br>";
  209. }      
  210.             }
  211.     } 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>';   
  212. }
  213.  
  214. elseif ($_POST['step'] == '2'){
  215.        //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.
  216.        $sql = "SELECT * FROM doc_list";
  217.     //$sql= "SELECT *  FROM doc_list GROUP BY lat, lng";
  218. $rec = 0;
  219. $docrec = 0;
  220.     $skipped = 0;
  221.        $result = $conn->query($sql);
  222.        while ($row = mysqli_fetch_assoc($result))
  223.    {
  224.         $reclat = $row['lat'];
  225.         $reclng = $row['lng'];
  226.         $rowid = $row['docid'];
  227.        $sqlmatch = "UPDATE doc_list SET parent ='1' WHERE docid='$rowid'";
  228.        $conn->query($sqlmatch);
  229.        if (empty($row['lat'])){$skipped = $skipped + 1; }
  230.        elseif ($row['lat'] == '-500'){ $skipped = $skipped + 1;}
  231.            else {
  232.        $docsql = "SELECT * FROM doc_list WHERE lat='".$reclat."' AND lng='".$reclng."'";
  233.        $docresult = $conn->query($docsql);     
  234.       $rec = $rec + 1;
  235.                
  236.          
  237.         while ($docrow = mysqli_fetch_assoc($docresult)){            
  238.            
  239.             $itemid = $docrow['docid'];
  240.             $match = $docrow['parent'];
  241.            
  242.             //We have our record and added it. Lets append to what we have. Then delete this record from the database
  243.             if ($match == '1'){}
  244.             else { $docrec = $docrec + 1;
  245.                  
  246.             $newdoc ='';           
  247.             $newdoc = $docrow['fName']." ".$docrow['lName']."</br>";           
  248.             $sqlup = "UPDATE doc_list SET InfoBoxHtml = concat(InfoBoxHtml,'$newdoc') WHERE docid='$rowid'";
  249.             $conn->query($sqlup);
  250.                
  251.             //Delete this record so we dont go in a loop
  252.             $delsql ="DELETE FROM doc_list WHERE docid='".$itemid."'";
  253.             $conn->query($delsql);
  254.        
  255.    }    }      
  256.    
  257.         //We have our matches now lets combine them
  258.         }
  259.        //Now lets insertthe new Record into the database
  260.       //Lets loop now through each result and find matches then insert a new clinic name in the database.
  261.    }
  262.     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">';
  263. }
  264. elseif ($_POST['step'] == '3'){
  265.  
  266.       //Great now lets export the new formated database into a csv and download
  267.        // lets output headers so that the file is downloaded rather than displayed
  268. //header('Content-Type: text/csv; charset=utf-8');
  269. //header('Content-Disposition: attachment; filename=DoctorMapImport.csv');
  270.        //lets create a file pointer connected to the output stream
  271. $output = fopen($doctorlist, 'w');
  272. //This is what our array looks like from the json --
  273. //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}
  274. // now we output the column headings
  275. 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'));       
  276.        $finalsql = "SELECT * FROM doc_list";
  277.        $finalresult = $conn->query($finalsql);
  278.        while ($finalrow = mysqli_fetch_assoc($finalresult))
  279.    {    
  280.         $docid = $finalrow['id'];
  281.        $fulladdress = $finalrow['FullAddress'];
  282.         $name = $finalrow['businessName'];     
  283.         $fname = $finalrow['fName'];     
  284.         $lname = $finalrow['lName'];       
  285.         $web = $finalrow['Website'];
  286.         $shownweb = $finalrow['shownWebsite'];   
  287.         $address =  $finalrow['address'];    
  288.         $address2 = $finalrow['address2'];   
  289.         $city = $finalrow['city'];   
  290.         $state = $finalrow['state'];
  291.         $postal = $finalrow['postal'];   
  292.         $country = $finalrow['country'];
  293.         $phone = $finalrow['phone'];   
  294.         $fax = $finalrow['fax'];   
  295.         $lastUpdate = $finalrow['lastUpdate'];
  296.         $created = $finalrow['created'];   
  297.         $logo = $finalrow['logo']; 
  298.         $email = $finalrow['email'];     
  299.         $phone = $finalrow['phone'];
  300.         $fax = $finalrow['fax'];     
  301.         $webnotes = $finalrow['WebNotes'];
  302.         $prompres =$finalrow['Promo'];
  303.         $infobox = $finalrow['InfoBoxHtml'];   
  304.         $docid = $finalrow['id'];    
  305.         $name = $finalrow['businessName'];   
  306.         $fname = $finalrow['fName'];     
  307.         $lname = $finalrow['lName'];   
  308.         $web = $finalrow['Website'];     
  309.         $shownweb = $finalrow['shownWebsite'];   
  310.         $address = $finalrow['address'];     
  311.         $address2 = $finalrow['address2'];     
  312.         $city = $finalrow['city'];   
  313.         $state = $finalrow['state'];       
  314.         $postal = $finalrow['postal'];   
  315.         $country = $finalrow['country'];
  316.         $phone = $finalrow['phone'];
  317.         $fax = $finalrow['fax'];       
  318.         $lastUpdate = $finalrow['lastUpdate'];   
  319.         $created = $finalrow['created'];     
  320.         $logo = $finalrow['logo'];   
  321.         $email = $finalrow['email'];     
  322.         $phone = $finalrow['phone'];     
  323.         $fax = $finalrow['fax'];
  324.         $lat = $finalrow['lat'];
  325.         $long = $finalrow['lng'];    
  326.         $webnotes = $finalrow['WebNotes'];   
  327.         $prompres = $finalrow['promo'];
  328.         $titleinfo = $finalrow['Fulltitle'];  
  329.        //Now lets make our results and create and arry to put it in our CSV.
  330.     $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);     
  331.     fputcsv($output,$result);      
  332.    }
  333.     fclose($output);
  334.      
  335.     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>'; 
  336. }      
  337.     //Show Landing Page If nothing is posted
  338.     else {
  339.         $finalsql = "DELETE FROM doc_list";
  340.        $finalresult = $conn->query($finalsql);
  341.         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>';
  342.        
  343.     }
  344.        $conn->close();
  345.        
  346.     ?></div>
  347.  
  348.  
  349. </form>
  350.     </div>
  351. </body>
  352. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement