Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?if($_POST['name'] != ''){
  2.  
  3. require_once('city_config.php');
  4.  
  5. if(!$cityAr['CODE'])
  6. exit('В city_config.php не установлен код горда');
  7.  
  8.  
  9. //Make "Random" Num PromoCode and save to $dbfile
  10. $dbfile = $_SERVER['DOCUMENT_ROOT'].'/'.$cityAr['CODE'].'/promo/lastnum.db';
  11. $LastNum = file_get_contents($dbfile);
  12. $LastNum = $LastNum +1;
  13. file_put_contents($dbfile, $LastNum );
  14. $PromoCode = rand(100, 999).$LastNum.'-RH';
  15.  
  16. // decode checkboxes jsonArray to Line
  17. function checkboxes($post){
  18. $Result = false;
  19. if($post){
  20. $post = json_decode($post);
  21.  
  22. foreach($post as $arItem){
  23. $Result .= $arItem->value.', ';
  24. }
  25. }
  26.  
  27. $Result = substr($Result, 0, -2);
  28. return $Result;
  29. }
  30.  
  31.  
  32. //Convert Array to Windows-1251 for makeing CSV
  33. function ConvertRow($list) {
  34. foreach ($list as $key=> $value)
  35. {
  36. $Result[$key] = iconv("utf-8", "windows-1251",$value);
  37. }
  38. return $Result;
  39. }
  40.  
  41.  
  42. //Main Inputs STR
  43. $Code['PROMOCODE'] = $PromoCode;
  44. $Code['NAME'] = $_POST['name'];
  45. $Code['AGE'] = $_POST['age'];
  46. $Code['EMAIL'] = $_POST['email'];
  47. $Code['COUNT_KIDS'] =$_POST['custKids'];
  48. $Code['AGE_KIDS'] = checkboxes($_POST['kidsage']);
  49. $Code['ADV'] = checkboxes($_POST['advertising']);
  50. $HeadingLine = array('Промокод', 'Имя', 'Возраст', 'Email', 'Количество детей', 'Возраст детей', 'Источник');
  51.  
  52.  
  53. //Make Conerted STR
  54. $codeCP1251 = ConvertRow($Code);
  55. $Heading1251 = ConvertRow($HeadingLine);
  56.  
  57. //ADD to CSV for Analytics
  58. $AnalyticFile = 'CodeList.csv';
  59.  
  60. //Check exist File and make Header if not
  61. $makeHeading = false;
  62. if (!file_exists($AnalyticFile ))
  63. $makeHeading = true;
  64.  
  65. $fp = fopen($AnalyticFile, 'a', ';' );
  66. if($makeHeading)
  67. fputcsv($fp, $Heading1251,';','"');
  68. fputcsv($fp, $codeCP1251,';','"');
  69. fclose($fp);
  70.  
  71. // Make PromoCodes File
  72. $Code['COMMENT'] = "Номер промокода:".$Code['PROMOCODE'].' // Детей: '.$Code['COUNT_KIDS'].' // Возраст детей: '.$Code['AGE_KIDS'] .' // Как вы о нас узнали: '.$Code['ADV'];
  73. $CodeFileName = 'codes/'.$PromoCode.'.txt';
  74. $CodeFile = file_get_contents($CodeFileName);
  75. file_put_contents($CodeFileName, json_encode($Code));
  76.  
  77. //Set Cookie PromoCode and echo
  78. setcookie("PromoCode", $PromoCode, time() + 86400*8, "/".$cityAr['CODE']."/");
  79. echo $PromoCode;
  80. }
  81. else{
  82. echo 'Заполните форму';
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement