1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
plimus.php
См. документацию.
1<?
2if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
3
4$STAT_RIGHT = $APPLICATION->GetGroupRight("statistic");
5if($STAT_RIGHT=="D") $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
6
7/***************************************************************************
8Convertation of the standard Plimus CSV file to the
9CSV file format of the Statistics module.
10***************************************************************************/
11
12/*
13 Input parameters:
14 INPUT_CSV_FILE - path to the source file
15 OUTPUT_CSV_FILE - path to the target file
16*/
17
18$SEPARATOR = ";"; // CSV separator
19$CURRENCY = "USD"; // Currency
20
21function CleanUpCsv(&$item)
22{
23 $item = trim($item, "\"");
24}
25
26function PrepareQuotes(&$item)
27{
28 $item = "\"".str_replace("\"","\"\"", $item)."\"";
29}
30
32 "Jan" => "01",
33 "Feb" => "02",
34 "Mar" => "03",
35 "Apr" => "04",
36 "May" => "05",
37 "Jun" => "06",
38 "Jul" => "07",
39 "Aug" => "08",
40 "Sep" => "09",
41 "Oct" => "10",
42 "Nov" => "11",
43 "Dec" => "12",
44 );
45
46if ($fp_in = fopen($INPUT_CSV_FILE,"rb"))
47{
48 $upload_dir = $_SERVER["DOCUMENT_ROOT"]."/".COption::GetOptionString("main","upload_dir","/upload/"). "/statistic";
49 if (mb_substr($OUTPUT_CSV_FILE, 0, mb_strlen($upload_dir)) == $upload_dir && $fp_out = fopen($OUTPUT_CSV_FILE,"wb"))
50 {
51 $i = 0; // counter of the read valuable lines
52 $j = 0; // counter of the written to the resulting file lines
53 $lang_date_format = FORMAT_DATETIME; // date format for the current language
54 $event1 = "plimus";
55 $event2 = "buy";
56 $EVENT_ID = CStatEventType::ConditionSet($event1, $event2, $arEventType)." (".$event1." / ".$event2.")";
57 $SITE_ID = GetEventSiteID(); // short site identifier (ID)
58 while (!feof($fp_in))
59 {
60 $arrCSV = fgetcsv($fp_in, 4096, $SEPARATOR);
61
62 if (is_array($arrCSV) && count($arrCSV)>1)
63 {
64 array_walk($arrCSV, "CleanUpCsv");
65 reset($arrCSV);
66 $i++;
67
68 // if it is the first line then
69 if ($arrCSV[0]=="Reference No")
70 {
71 // get an array with the field numbers
72 $arrS = array_flip($arrCSV);
73 }
74 elseif ($arrCSV[0]!="Reference No" && is_array($arrS) && count($arrS)>0) // else form the CSV line in module format and write it to the resulting file
75 {
76 $arrRes = array();
77
78 // ID of an event type;
79 $arrRes[] = $EVENT_ID;
80
81 // event3
82 $arrRes[] = $arrCSV[$arrS["Reference No"]]." / ".$arrCSV[$arrS["Product ID"]];
83
84 // date
85 $ar = explode(" ", $arrCSV[$arrS["Date"]]); // 11-Jul-2005 07:54:48
86 $arDate = explode("-", $ar[0]); // 11-Jul-2005
87 $arTime = explode(":", $ar[1]); // 07:54:48
88 $date_time = $arDate[0].".".$arMonth[$arDate[1]].".".$arDate[2]." ".$ar[1]; // 11.07.2005 07:54:48
89
90 // extended trim
91 $date_time = preg_replace("#^[^0-9]#", "", $date_time);
92 $date_time = preg_replace("#[^0-9]$#", "", $date_time);
93
94 $date = $DB->FormatDate($date_time, "DD.MM.YYYY HH:MI:SS", $lang_date_format);
95 $arrRes[] = $date;
96
97 // additional parameter
98 $ADDITIONAL_PARAMETER = $arrCSV[$arrS["Custom1"]];
99 $arrRes[] = $ADDITIONAL_PARAMETER;
100
101 // money sum
102 $arrRes[] = str_replace(",", "", $arrCSV[$arrS["Total"]]);
103
104 // currency
105 //$arrRes[] = $arrCSV[$arrS["currency"]];
106 $arrRes[] = $CURRENCY;
107
108 // if short site identifier exists in Additional parameter then
109 if (mb_strpos($ADDITIONAL_PARAMETER, $SITE_ID) !== false)
110 {
111 // write the line to the resulting file
112 $j++;
113 array_walk($arrRes, "PrepareQuotes");
114 $str = implode(",",$arrRes);
115 if ($j>1) $str = "\n".$str;
116 fputs($fp_out, $str);
117 }
118 }
119 }
120 }
121 @fclose($fp_out);
122 }
123 @fclose($fp_in);
124}
125
126/*
127
128Column headers:
129
130Reference No;Date;Company Name;First Name;Last Name;Email;Product ID;Product Name;Contract ID;Contract Name;Quantity;Unit Price;Additional Charges;Coupon Amount;Total;License Key;Commission;Discount Rate %;Discount Transaction Fee;Payment Frequency;Address 1;Address 2;City;State;Country;Zip Code;Work Phone;Work Extension;Mobile Phone;Fax;Home Phone;Custom1;Custom2;Custom3;Custom4;Custom5;Referrer;Original Ref#;IP Address;Affiliate Commission;Armadillo Hardware Id;Account Id
131
132*/
133?>
global $APPLICATION
Определения include.php:80
static ConditionSet($event1, $event2, &$arEventType)
Определения stateventtype.php:106
$str
Определения commerceml2.php:63
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
const FORMAT_DATETIME
Определения include.php:64
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$SEPARATOR
Определения plimus.php:18
PrepareQuotes(&$item)
Определения plimus.php:26
$STAT_RIGHT
Определения plimus.php:4
$arMonth
Определения plimus.php:31
CleanUpCsv(&$item)
Определения plimus.php:21
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
die
Определения quickway.php:367
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$CURRENCY
Определения result.php:6
GetEventSiteID()
Определения stat_tools.php:544
$SITE_ID
Определения yandex_run.php:607