Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?if($_POST['name'] != ''){
- require_once('city_config.php');
- if(!$cityAr['CODE'])
- exit('В city_config.php не установлен код горда');
- //Make "Random" Num PromoCode and save to $dbfile
- $dbfile = $_SERVER['DOCUMENT_ROOT'].'/'.$cityAr['CODE'].'/promo/lastnum.db';
- $LastNum = file_get_contents($dbfile);
- $LastNum = $LastNum +1;
- file_put_contents($dbfile, $LastNum );
- $PromoCode = rand(100, 999).$LastNum.'-RH';
- // decode checkboxes jsonArray to Line
- function checkboxes($post){
- $Result = false;
- if($post){
- $post = json_decode($post);
- foreach($post as $arItem){
- $Result .= $arItem->value.', ';
- }
- }
- $Result = substr($Result, 0, -2);
- return $Result;
- }
- //Convert Array to Windows-1251 for makeing CSV
- function ConvertRow($list) {
- foreach ($list as $key=> $value)
- {
- $Result[$key] = iconv("utf-8", "windows-1251",$value);
- }
- return $Result;
- }
- //Main Inputs STR
- $Code['PROMOCODE'] = $PromoCode;
- $Code['NAME'] = $_POST['name'];
- $Code['AGE'] = $_POST['age'];
- $Code['EMAIL'] = $_POST['email'];
- $Code['COUNT_KIDS'] =$_POST['custKids'];
- $Code['AGE_KIDS'] = checkboxes($_POST['kidsage']);
- $Code['ADV'] = checkboxes($_POST['advertising']);
- $HeadingLine = array('Промокод', 'Имя', 'Возраст', 'Email', 'Количество детей', 'Возраст детей', 'Источник');
- //Make Conerted STR
- $codeCP1251 = ConvertRow($Code);
- $Heading1251 = ConvertRow($HeadingLine);
- //ADD to CSV for Analytics
- $AnalyticFile = 'CodeList.csv';
- //Check exist File and make Header if not
- $makeHeading = false;
- if (!file_exists($AnalyticFile ))
- $makeHeading = true;
- $fp = fopen($AnalyticFile, 'a', ';' );
- if($makeHeading)
- fputcsv($fp, $Heading1251,';','"');
- fputcsv($fp, $codeCP1251,';','"');
- fclose($fp);
- // Make PromoCodes File
- $Code['COMMENT'] = "Номер промокода:".$Code['PROMOCODE'].' // Детей: '.$Code['COUNT_KIDS'].' // Возраст детей: '.$Code['AGE_KIDS'] .' // Как вы о нас узнали: '.$Code['ADV'];
- $CodeFileName = 'codes/'.$PromoCode.'.txt';
- $CodeFile = file_get_contents($CodeFileName);
- file_put_contents($CodeFileName, json_encode($Code));
- //Set Cookie PromoCode and echo
- setcookie("PromoCode", $PromoCode, time() + 86400*8, "/".$cityAr['CODE']."/");
- echo $PromoCode;
- }
- else{
- echo 'Заполните форму';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement