1+ <?php
2+
3+ function isValidDate ($ date )
4+ {
5+ return $ date == '0000-00-00 00:00:00 ' || $ date == NULL ? FALSE : TRUE ;
6+ }
7+
8+ function calculateCostPerDay ( $ price )
9+ {
10+ $ cost_per_day = $ price / 30 ;
11+ return number_format ( (float ) $ cost_per_day ,2 ,'. ' ,'' );
12+
13+ }
14+
15+ function pr ($ array )
16+ {
17+ echo "<pre> " ;
18+ print_r ($ array );
19+ echo "</pre> " ;
20+ exit ;
21+ }
22+
23+ function makeExpiry ($ units , $ unit , $ format = 'Y-m-d H:i:s ' )
24+ {
25+ $ val = Carbon \Carbon::now ();
26+ $ add = "add " .$ unit ;
27+ $ val ->$ add ( $ units );
28+ return $ val ->format ($ format );
29+ }
30+
31+ function mikrotikRateLimit ($ object , $ prefix = NULL )
32+ {
33+ $ v = (array ) $ object ;
34+
35+ return "{$ v [$ prefix .'max_up ' ]}{$ v [$ prefix .'max_up_unit ' ][0 ]}/ " .
36+ "{$ v [$ prefix .'max_down ' ]}{$ v [$ prefix .'max_down_unit ' ][0 ]} " .
37+ "{$ v [$ prefix .'max_up ' ]}{$ v [$ prefix .'max_up_unit ' ][0 ]}/ " .
38+ "{$ v [$ prefix .'max_down ' ]}{$ v [$ prefix .'max_down_unit ' ][0 ]} " .
39+ "{$ v [$ prefix .'max_up ' ]}{$ v [$ prefix .'max_up_unit ' ][0 ]}/ " .
40+ "{$ v [$ prefix .'max_down ' ]}{$ v [$ prefix .'max_down_unit ' ][0 ]} " .
41+ "1/1 1 " .
42+ "{$ v [$ prefix .'min_up ' ]}{$ v [$ prefix .'min_up_unit ' ][0 ]}/ " .
43+ "{$ v [$ prefix .'min_down ' ]}{$ v [$ prefix .'min_down_unit ' ][0 ]}" ;
44+ }
45+
46+ function formatTime ($ seconds )
47+ {
48+ $ mins = intval ($ seconds /60 );
49+ $ seconds = $ seconds %60 ;
50+ $ Hrs = intval ($ mins /60 );
51+ $ mins = $ mins %60 ;
52+ $ result = NULL ;
53+
54+ if ( $ Hrs != 0 ) {
55+ $ result .= " $ Hrs Hrs " ;
56+ }
57+ if ( $ mins != 0 ) {
58+ $ result .= " $ mins Mins " ;
59+ }
60+ if ( $ seconds != 0 ) {
61+ $ result .= " $ seconds Secs " ;
62+ }
63+ return $ result ;
64+ }
65+
66+ function formatBytes ($ bytes , $ precision = 2 ) {
67+ $ units = array ('B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' );
68+
69+ $ bytes = max ($ bytes , 0 );
70+ $ pow = floor (($ bytes ? log ($ bytes ) : 0 ) / log (1024 ));
71+ $ pow = min ($ pow , count ($ units ) - 1 );
72+
73+ // Uncomment one of the following alternatives
74+ $ bytes /= pow (1024 , $ pow );
75+ // $bytes /= (1 << (10 * $pow));
76+
77+ return round ($ bytes , $ precision ) . ' ' . $ units [$ pow ];
78+ }
79+
80+ function reject ($ string )
81+ {
82+ echo "Reply-Message := \"$ string \"" ;
83+ exit (1 );
84+ }
85+
86+ function parseAttributes ($ z )
87+ {
88+ $ output = preg_replace ("/\s+[=]\s+/ " ,'= ' , $ z );
89+ $ output = preg_replace ("/\s+/ " ,' ' ,$ output );
90+ $ output = explode (' ' ,$ output );
91+ $ result = [];
92+ foreach ($ output as $ pair ) {
93+ if (strpos ($ pair ,'= ' ) ){
94+ list ($ k ,$ v ) = explode ('= ' ,$ pair );
95+ $ result [$ k ] = trim ($ v ,'" ' );
96+ }
97+ }
98+ return $ result ;
99+ }
0 commit comments