Guest User

Untitled

a guest
Apr 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. <?php
  2. function curl($url, $post=''){
  3. $con=mysqli_connect("localhost","maruerti_vehicleprice","vehicleprice123","maruerti_vehicleprice");
  4. // Check connection
  5. if(mysqli_connect_errno())
  6. {
  7. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  8. }
  9. else{
  10. //echo "connected";
  11. }
  12.  
  13. $_SESSION['price']='';
  14. $_SESSION['insurance']='';
  15. $_SESSION['rto']='';
  16.  
  17. //cURL options
  18. $options = array(
  19. CURLOPT_RETURNTRANSFER => true,
  20. CURLOPT_HEADER => false,
  21. CURLOPT_FOLLOWLOCATION => true,
  22. CURLOPT_ENCODING => "",
  23. CURLOPT_AUTOREFERER => true,
  24.  
  25. CURLOPT_SSL_VERIFYHOST => 0,
  26. CURLOPT_SSL_VERIFYPEER => 0,
  27. CURLOPT_USERAGENT => "",
  28. CURLOPT_COOKIESESSION => false,
  29. );
  30.  
  31. //Go go go!
  32. $ch=curl_init($url);
  33. curl_setopt_array( $ch, $options );
  34. $output['content'] = curl_exec( $ch );
  35. /* $output['err'] = curl_errno( $ch );
  36. $output['errmsg'] = curl_error( $ch );
  37. $output['header'] = curl_getinfo( $ch );*/
  38. $doc = new DOMDocument;
  39. @$doc->loadHTML($output['content']);
  40. $doc->preserveWhiteSpace = false;
  41.  
  42. $xpath = new DOMXpath($doc);
  43.  
  44.  
  45.  
  46.  
  47.  
  48. $city=array();
  49.  
  50. if($_REQUEST['index']<0 OR !isset($_REQUEST['index'])){
  51. $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city='',sr_price='',rto_price='',ins_price='' WHERE varient_id=".$_REQUEST['varient_id'];
  52.  
  53. if(mysqli_query($con,$sql)){
  54. echo "<h4 style='color:green'>Record Removed successfully</h4>";
  55. }
  56. else{
  57. echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
  58. echo "</div>";
  59. }
  60.  
  61.  
  62.  
  63. $brand_id=0;
  64. $brand=str_replace('-',' ',trim($_REQUEST['brand']));
  65. $sql2_apr="SELECT id,brand_name FROM vehicle_brands WHERE brand_name='".$brand."'";
  66. if($result=mysqli_query($con,$sql2_apr))
  67. {
  68. echo $total_city=mysqli_num_rows($result);
  69. while($row=mysqli_fetch_row($result))
  70. {
  71. $brand_id=$row[0];
  72. //array_push($city,$data);
  73. //var_dump($row);
  74. }
  75. }
  76.  
  77. $sql2_apr="SELECT city_id,city_name FROM cities WHERE FIND_IN_SET ($brand_id,active_dealers)";
  78. if($result=mysqli_query($con,$sql2_apr))
  79. {
  80. echo $total_city=mysqli_num_rows($result);
  81. while($row=mysqli_fetch_row($result))
  82. {
  83. $data=$row[1];
  84. array_push($city,$data);
  85. //var_dump($row);
  86. }
  87. }
  88. //var_dump($city);
  89. $_SESSION['city_name']=$city;
  90. echo "City session started..........................";
  91. //var_dump($_SESSION['city_name']);
  92. //exit();
  93. }
  94. else
  95.  
  96. $varient=$_REQUEST['varient'];
  97.  
  98. echo $varient=str_replace(' ','-',$varient);
  99.  
  100. $nodeList = $xpath->query("//tbody[@class='".$varient."']");
  101.  
  102. foreach($nodeList as $val=> $node){
  103.  
  104. $prices=$node->nodeValue;
  105. var_dump($prices);
  106. $data=explode('₹',$prices);
  107. //var_dump($data);
  108. echo "<br> Ex_showroom_price =>";
  109. $price=explode('.',$data[1]);
  110. $Ex_showroom_price=trim(str_replace('RTO','',str_replace('*','',str_replace(',','',$price[0]))));
  111. echo $Ex_showroom_price=preg_replace("/[^0-9]/","",$Ex_showroom_price);
  112. echo "<br> rto_price =>";
  113. $rto_price=explode('.',$data[2]);
  114. $rto_price=trim(str_replace('Insurance','',str_replace(',','',$rto_price[0])));
  115. echo $rto_price=preg_replace("/[^0-9]/","",$rto_price);
  116. echo "<br> Insurance_price=>";
  117. $Insurance_price=explode('.',$data[3]);
  118. $Insurance_price=trim(str_replace('Others','',str_replace(',','',str_replace('-','',$Insurance_price[0]))));
  119. echo $Insurance_price=preg_replace("/[^0-9]/","",$Insurance_price);
  120. echo "<br> other_price=>";
  121. $other_price=explode('.',$data[4]);
  122.  
  123. echo $other_price=preg_replace("/[^0-9]/","",$other_price[0]);
  124. echo "<br>";
  125. $index=$_REQUEST['index']+1;
  126. echo $city=$_SESSION['city_name'][$index];
  127. //exit();
  128. $city=strtolower(str_replace('-',' ',str_replace('(','-',str_replace(')','',$city))));
  129. $new_cityname=$city;
  130. $value=str_replace('-',' ',$city);
  131. $sql="SELECT * FROM cities WHERE city_name='".$new_cityname."'";
  132. $id ='';
  133. $city_price ='';
  134. $value=str_replace('-',' ',$value);
  135. if(strlen($new_cityname)>2){
  136. $sql2 ="INSERT INTO cities (city_name)
  137. VALUES ('$new_cityname')";
  138. if ($con->query($sql2) === TRUE) {
  139. echo "<br><h1 style='color:green'>New City created successfully!!!</h1>";
  140. } else{
  141. //echo "<br><h1 style='color:red'>City name already in table</h1>";
  142. }
  143. }
  144. if($result=mysqli_query($con,$sql))
  145. {
  146. // Fetch one and one row
  147. $row=mysqli_fetch_row($result);
  148. echo $new_cityname.'';
  149. echo $id=$row[0];
  150. $city_price=trim($Ex_showroom_price);
  151. $insurance=trim($Insurance_price);
  152. $rto=trim($rto_price);
  153. $variant=$_REQUEST['varient_id'];
  154. if ($city_price!=null){
  155. $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city=CONCAT_WS(',', city, '$id'),sr_price=CONCAT_WS(',', sr_price, '$city_price'),rto_price=CONCAT_WS(',', rto_price, '$rto'),ins_price=CONCAT_WS(',', ins_price, '$insurance') WHERE varient_id=".$variant;
  156. if(mysqli_query($con,$sql)){
  157. echo "<h4 style='color:green'>Record updated successfully</h4>";
  158. }else{
  159. echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
  160. echo "</div>";
  161. }
  162. }
  163. }
  164. $sql="SELECT city,sr_price,rto_price,ins_price FROM vehicals_type_brand_model_varient_vehicle WHERE varient_id=".$variant;
  165. if ($result=mysqli_query($con,$sql))
  166. {
  167. while ($row=mysqli_fetch_row($result))
  168. {
  169. $new_city=explode(',',$row[0]);
  170. $new_price=explode(',',$row[1]);
  171. $new_ins=explode(',',$row[2]);
  172. $new_rto=explode(',',$row[3]);
  173. if ($new_price[0]==null){
  174. $new_city=$new_city[1];
  175. $new_price=$new_price[1];
  176. $new_ins=$new_ins[1];
  177. $new_rto=$new_rto[1];
  178. $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city='{$new_city}',sr_price='{$new_price}',rto_price='{$new_rto}',ins_price='{$new_ins}' WHERE varient_id=".$variant;
  179. if(mysqli_query($con,$sql)){
  180. echo "<h4 style='color:green'>Record updated successfully</h4>";
  181. }
  182. else{
  183. echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
  184. echo "</div>";
  185. }
  186. echo $new_price[1];
  187. echo $new_ins[1];
  188. echo $new_rto[1];
  189. }
  190.  
  191. }
  192. }
  193. echo '<h4>'.$variant.'</h4>';
  194. //var_dump($prices);
  195. echo "<hr>";
  196. }
  197.  
  198. return $output;
  199. }
  200. ?>
Add Comment
Please, Sign In to add comment