PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/user/auth/customer/icmp.php

https://bitbucket.org/nav_subhamkumar/crm
PHP | 204 lines | 128 code | 57 blank | 19 comment | 11 complexity | ddc060a95154160f49754bb5899a3eee MD5 | raw file
Possible License(s): Unlicense, GPL-2.0, GPL-3.0
  1. <?php
  2. session_start();
  3. error_reporting(E_PARSE | E_ERROR);
  4. $id=$_SESSION['id'];
  5. if(!$_SESSION['id'])
  6. {
  7. echo '<script>location.replace("../../../../index.php");</script>';
  8. }
  9. require_once "../../conn/conn.php";
  10. ?>
  11. <?php
  12. if(isset($_POST['submit']))
  13. {
  14. $rep=$_SESSION['n'];
  15. $rmail=$id;
  16. $company=$_POST['company'];
  17. $sector=$_POST['sector'];
  18. $subsector=$_POST['subsector'];
  19. $url=$_POST['url'];
  20. $address=$_POST['address'];
  21. $location=$_POST['location'];
  22. $sublocation=$_POST['sublocation'];
  23. $city=$_POST['city'];
  24. $pin=$_POST['pin'];
  25. $state=$_POST['state'];
  26. $country=$_POST['country'];
  27. $stdcode=$_POST['stdcode'];
  28. $landlineno=$_POST['landlineno'];
  29. $faxno=$_POST['faxno'];
  30. $noofemployees=$_POST['noofemployees'];
  31. $companytype=$_POST['companytype'];
  32. $companytype=$_POST['companytype'];
  33. $gstno=$_POST['gstno'];
  34. $datafrom=$_POST['datafrom'];
  35. // Generate Guid - unique id
  36. function NewGuid() {
  37. $s = strtoupper(md5(uniqid(rand(),true)));
  38. date_default_timezone_set('Asia/Kolkata');
  39. $timestamp = date('dmYHis', time());
  40. $guidText =
  41. substr($timestamp,0,18) . '-' .
  42. substr($s,18,4) . '-' .
  43. substr($s,22,4). '-' .
  44. substr($s,26,4). '-' .
  45. substr($s,30);
  46. return $guidText;
  47. }
  48. // End Generate Guid
  49. $custuniqueid = NewGuid();
  50. /*check columns available start*/
  51. $result=mysqli_query($dbc,"show columns from customers");
  52. $k=0;
  53. $c=0;
  54. while($row = mysqli_fetch_array($result)){
  55. $str=$row['Field'];
  56. $newstr = filter_var($str, FILTER_SANITIZE_STRING);
  57. if($newstr="ContactName")
  58. {
  59. $int_id = filter_var($str, FILTER_SANITIZE_NUMBER_INT);
  60. if($int_id > $k)
  61. {
  62. global $c;
  63. $c=$int_id;
  64. $k=$int_id;
  65. }
  66. }
  67. }
  68. /*check columns available end*/
  69. for ($i = 0; $i < 50; $i++)
  70. {
  71. /*if (isset($_POST['partdesc'][$i], $_POST['qty'][$i],$_POST['unitprice'][$i])) { // Make sure both are filled in*/
  72. // Do stuff with this row of the form
  73. $name=$_POST['name'][$i];
  74. $designation=$_POST['designation'][$i];
  75. $level=$_POST['level'][$i];
  76. $department=$_POST['department'][$i];
  77. $email=$_POST['email'][$i];
  78. $mobile=$_POST['mobile'][$i];
  79. if(!empty($name))
  80. {
  81. if($i=='0')
  82. {
  83. $ad=mysqli_query($dbc,"insert into `customers` (`Representive`,`RMail`,`UniqueId`,`Company`,`Sector`,`SubSector`,`ContactName1`,`ContactDesignation1`,`ContactLevel1`,`ContactDept1`,`ContactMobile1`,`ContactMail1`,`Url`,`Address`,`Location`,`SubLocation`,`City`,`Pin`,`State`,`StdCode`,`LandlineNo`,`FaxNo`,`NoOfEmployees`,`CompanyType`,`GSTNo`) values ('$rep','$rmail','$custuniqueid','$company','$sector','$subsector','$name','$designation','$level','$department','$mobile','$email','$url','$address','$location','$sublocation','$city','$pin','$state','$stdcode','$landlineno','$faxno','$noofemployees','$companytype','$gstno')");
  84. }
  85. elseif($i>=1)
  86. {
  87. if($i==$c)
  88. {
  89. $namenew="ContactName".($c+1);
  90. $designationnew="ContactDesignation".($c+1);
  91. $levelnew="ContactLevel".($c+1);
  92. $departmentnew="ContactDept".($c+1);
  93. $emailnew="ContactMail".($c+1);
  94. $mobilenew="ContactMobile".($c+1);
  95. mysqli_query($dbc,"ALTER TABLE `customers` ADD `$namenew` TEXT NULL, ADD `$designationnew` TEXT NULL,ADD `$levelnew` TEXT NULL,ADD `$departmentnew` TEXT NULL,ADD `$emailnew` TEXT NULL,ADD `$mobilenew` TEXT NULL");
  96. $c=$c+1;
  97. }
  98. $ii=$i+1;
  99. $namecolumn="ContactName".$ii;
  100. $designationcolumn="ContactDesignation".$ii;
  101. $levelcolumn="ContactLevel".$ii;
  102. $departmentcolumn="ContactDept".$ii;
  103. $emailcolumn="ContactMail".$ii;
  104. $mobilecolumn="ContactMobile".$ii;
  105. $ad=mysqli_query($dbc,"update `customers` set `$namecolumn`='$name',`$designationcolumn`='$designation',`$levelcolumn`='$level',`$departmentcolumn`='$department',`$emailcolumn`='$email',`$mobilecolumn`='$mobile' where `RMail`='$rmail' and `UniqueId`='$custuniqueid' ");
  106. }
  107. else
  108. {
  109. echo '<script>alert("Sorry!! Maximum Description Reached");location.replace("../../opr/addcust.php");</script>';
  110. }
  111. }
  112. else
  113. {
  114. break;
  115. }
  116. }
  117. if($ad>0)
  118. {
  119. if($datafrom == 'quotgen')
  120. {
  121. echo '<script>alert("Data Inserted Successfully");window.history.back();</script>';
  122. }
  123. else
  124. {
  125. echo '<script>alert("Data Inserted Successfully");location.replace("../../opr/addcust.php");</script>';
  126. }
  127. }
  128. else
  129. {
  130. echo '<script>alert("Data not Inserted");location.replace("../../opr/addcust.php");</script>';
  131. }
  132. /* while($r=mysqli_fetch_row($ad))
  133. {
  134. if($r>0)
  135. {
  136. $_SESSION['id']=$id;
  137. echo '<script>location.replace("dashboard.php");</script>';
  138. }
  139. }
  140. */
  141. }
  142. echo '<script>location.replace("../../opr/addcust.php");</script>';
  143. ?>