-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib4php.php
196 lines (167 loc) · 5.11 KB
/
lib4php.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?
function echo2log($fn, $subj='', $text='')
{
$r=true;
if($text=='-') $t='\n\n\n';
elseif($text=='') $t=curtime("$subj");
else $t=curtime("$subj:\n$text");
echo $t;
file_put_contents($fn, $t, FILE_APPEND | LOCK_EX);
return $r;
}
function curtime($s)
{
if($s!='') return(date('Y-m-d H:i:s :: ').$s."\n");
else return(date('Y-m-d H:i:s')."\n");
}
function clearDir($dir='')
{
if(dir!='')
{
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file)
{
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
}
#return rmdir($dir);
}
function dir2arr($dir)
{
$r=array();
$cdir=scandir($dir);
foreach($cdir as $key=>$value)
{
if(!in_array($value,array(".","..")))
{
if(is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
}
else
{
$r[]=strtoupper($dir.DIRECTORY_SEPARATOR.$value);
}
}
}
return $r;
}
function utf2win($str)
{
if($str!='') return @iconv("UTF-8", "CP1251", $str);
else return '';
}
function win2utf($str)
{
if($str!='') return @iconv("CP1251", "UTF-8", $str);
else return '';
}
function dos2win($str)
{
if($str!='') return @iconv("866", "CP1251", $str);
else return '';
}
function win2dos($str)
{
if($str!='') return @iconv("CP1251", "866", $str);
else return '';
}
function utf2lat($s)
{
$s=strtr($s, "абвгдеёзийклмнопрстуфхыэ",
"abvgdeeziyklmnoprstufhie");
$s=strtr($s, "АБВГДЕЁЗИЙКЛМНОПРСТУФХЫЭ",
"ABVGDEEZIYKLMNOPRSTUFHIE");
$s=strtr($s,array(
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
"щ"=>"shch","ь"=>"", "ъ"=>"", "ю"=>"yu", "я"=>"ya",
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
"Щ"=>"SHCH","Ь"=>"", "Ъ"=>"", "Ю"=>"YU", "Я"=>"YA"
));
return $s;
}
function subj4form($dt, $form_id, $form_period='')
{
$r='';
$r=preg_replace('/^0409(\d\d\d)/i', "F$1", $form_id);
if($r!='')
{
if($form_period=='нерегулярная') $r.='D';
if($form_period=='декадная')
{
if($form_id=='0409664') $r='D664';
}
$r="IES you have mail - $r//$dt";
}
return($r);
}
function dir4form($dt, $form_id, $form_period='')
{
global $dir4arhform;
$r='';
$r=preg_replace('/^0409(\d\d\d)/i', "F$1", $form_id);
if($r==$form_id) $r='';//не поняли что за отчетность
if($r!='')
{
if($form_period=='нерегулярная') $r.='D';
if($form_period=='декадная')
{
if($form_id=='0409664') $r='D664';
}
$dt=str_replace('-','\\',$dt);
$r=utf2win("$dir4arhform\\$dt\\ies");//архив
}
return($r);
}
function email4form($form_id)
{
global $ini;
$r=$ini['mailto'];
if(preg_match('/^0409(\d\d\d)/i',$form_id,$m))
{
#echo "\$m[1]=$m[1]\n";
$e=$ini["f$m[1]"];
if($e!='') $r.=",$e";
#if($m[1]=='135') $r.=',[email protected]';
}
return($r);
}
function sendEmail($to, $subj, $text='')
{
global $ini;
$objEmail = new COM("CDO.Message") or die("Cannot init CDO.Message");
$objEmail->Configuration->Fields->Item("http://schemas.microsoft.com/cdo/configuration/sendusing")->Value = 2;
$objEmail->Configuration->Fields->Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")->Value = $ini['mailserver'];//
$objEmail->Configuration->Fields->Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")->Value = $ini['mailport'];
$objEmail->Configuration->Fields->Update();
$objEmail->From = $ini['mailfrom'];
$objEmail->To = $to;
$objEmail->Subject = $subj;
$objEmail->BodyPart->Charset = $ini['mailcharset'];
$objEmail->HTMLBody = $text;
return $objEmail->Send();
}
function evd_lz($str, $len=0, $ch='0')
{
$str=trim($str);
if(mb_strlen($str)>=$len) return $str;
else return (str_repeat($ch, $len-mb_strlen($str)).$str);
}
function Commas($number=0, $dig=2, $delim="`", $lz=0, $lz_ch=' ')
{
#floatval($number);
$number=str_replace(',','.',$number);
@$number*=1;
$number=sprintf("%.${dig}f",$number);
$number=strrev(preg_replace("#(\d{3})(?=\d)#","\\1${delim}", strrev($number)));
//после преобразования в binary забивает точку \x00
$number=str_replace("\x00","\x2E",$number);
$number=str_replace(',','.',$number);
if($lz>0) $number=evd_lz($number, $lz, $lz_ch);
return $number;
}
function xml100($s)
{
$r="$s";
return($r/100);
}
?>