-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.php
More file actions
371 lines (275 loc) · 15.6 KB
/
function.php
File metadata and controls
371 lines (275 loc) · 15.6 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/*
Name: Function
Purpose: System object shortcut/alias function library
Author: Broken Arrow (SKJoy2001@GMail.Com);
Created: May 30, 2018 05:30 PM
Modified: June 7, 2018 01:45 AM
*/
namespace sPHP{
function SetVariable($Name, $DefaultValue = null, $GET = true, $POST = true, $SESSION = false, $COOKIE = false){
global $Environment;
return $Environment->SetVariable($Name, $DefaultValue, $GET, $POST, $SESSION, $COOKIE);
}
function SetVar($Name, $DefaultValue = null, $GET = true, $POST = true, $SESSION = false, $COOKIE = false){
return SetVariable($Name, $DefaultValue, $GET, $POST, $SESSION, $COOKIE);
}
function Upload($Path, $Field = null, $SetPOST = null, $MustRename = null, $AllowedExtension = null, $ForbiddenExtension = null){
global $Environment;
return $Environment->Utility()->Upload($Path, $Field, $SetPOST, $MustRename, $AllowedExtension, $ForbiddenExtension);
}
function ValidFileName($Name, $ReplacementCharacter = "_"){
global $Environment;
return $Environment->Utility()->ValidFileName($Name, $ReplacementCharacter);
}
function ValidVariableName($Name, $ReplacementCharacter = "_"){
global $Environment;
return $Environment->Utility()->ValidVariableName($Name, $ReplacementCharacter);
}
function UniqueFileName($File){
global $Environment;
return $Environment->Utility()->UniqueFileName($File);
}
function GUID($Hyphen = false, $CurlyBrace = false){
global $Environment;
return $Environment->Utility()->GUID($Hyphen, $CurlyBrace);
}
function ListToArray($List, $Separator = null, $DiscardSpace = null, $IgnoreEmpty = null){
global $Environment;
return $Environment->Utility()->ListToArray($List, $Separator, $DiscardSpace, $IgnoreEmpty);
}
function NumberInWord($Number = false){
global $Environment;
return $Environment->Utility()->NumberInWord($Number);
}
function RandomString($Length = 8, $Number = true, $Lowercase = true, $Uppercase = true, $Symbol = true, $TagSafe = true){
global $Environment;
return $Environment->Utility()->RandomString($Length, $Number, $Lowercase, $Uppercase, $Symbol, $TagSafe);
}
function Redirect($URL, $Message = null){
global $Terminal;
return $Terminal->Redirect($URL, $Message);
}
function OpenGraphMetaTag($URL = null, $Title = null, $Descroption = null, $Image = null, $ImageTitle = null, $UpdateTime = null, $Type = null, $Locale = null){
$OpenGraphMetaTag = new OpenGraphMetaTag($URL, $Title, $Descroption, $Image, $ImageTitle, $UpdateTime, $Type, $Locale);
return $OpenGraphMetaTag->MetaHTML();
}
function DebugDump($Value, $Name = null, $Output = true, $CallerDepth = 1){
global $Environment;
// Control where to start the debug from, framework layer or application layer
//$CallerDepth = 0; // Framework layer
//$CallerDepth = 1; // Application layer
return $Environment->Utility()->Debug()->Dump($Value, $Name, $Output, $CallerDepth);
}
function Impersonate($CurrentUser, $Application, $Email, $Session){
$Database = $Application->Database();
$EntityName = "User";
$Error = [];
if($CurrentUser->UserGroupIdentifierHighest() == "ADMINISTRATOR"){
$UserRecord = $Database->Query("
SELECT U.UserID, U.UserEmail, U.UserPasswordHash, U.UserPicture, U.UserPictureThumbnail, U.UserURL,
@UserName := CONCAT(
U.UserNameFirst,
IF(U.UserNameMiddle > '', CONCAT(' ', U.UserNameMiddle), ''),
IF(U.UserNameLast > '', CONCAT(' ', U.UserNameLast), '')
) AS UserName,
IF(U.UserPhoneMobile IS NULL, IF(U.UserPhoneWork IS NULL, IF(U.UserPhoneHome IS NULL, IF(U.UserPhoneOther IS NULL, '', U.UserPhoneOther), U.UserPhoneHome), U.UserPhoneWork), U.UserPhoneMobile) AS UserPhone,
(
SELECT GROUP_CONCAT(UG.UserGroupIdentifier ORDER BY UG.UserGroupWeight DESC SEPARATOR '; ')
FROM sphp_userusergroup AS UUG
LEFT JOIN sphp_usergroup AS UG ON UG.UserGroupID = UUG.UserGroupID
WHERE UUG.UserID = U.UserID
AND UUG.UserUserGroupIsActive = 1
AND UG.UserGroupIsActive = 1
ORDER BY UG.UserGroupWeight DESC
) AS UserGroupIdentifier,
(
SELECT GROUP_CONCAT(UG.UserGroupWeight ORDER BY UG.UserGroupWeight DESC SEPARATOR '; ')
FROM sphp_userusergroup AS UUG
LEFT JOIN sphp_usergroup AS UG ON UG.UserGroupID = UUG.UserGroupID
WHERE UUG.UserID = U.UserID
AND UUG.UserUserGroupIsActive = 1
AND UG.UserGroupIsActive = 1
ORDER BY UG.UserGroupWeight DESC
) AS UserGroupWeight,
(
SELECT GROUP_CONCAT(UG.UserGroupName ORDER BY UG.UserGroupWeight DESC SEPARATOR '; ')
FROM sphp_userusergroup AS UUG
LEFT JOIN sphp_usergroup AS UG ON UG.UserGroupID = UUG.UserGroupID
WHERE UUG.UserID = U.UserID
AND UUG.UserUserGroupIsActive = 1
AND UG.UserGroupIsActive = 1
ORDER BY UG.UserGroupWeight DESC
) AS UserGroupName,
'' AS _Other
FROM sphp_user AS U
WHERE TRUE
AND (
U.UserEmail = '" . $Database->Escape($Email) . "'
OR U.UserSignInName = '" . $Database->Escape($Email) . "'
)
AND U.UserIsActive = 1
LIMIT 1
");
if(isset($UserRecord[0])){
$UserRecord = $UserRecord[0][0];
$UserGroupIdentifier = explode("; ", $UserRecord["{$EntityName}GroupIdentifier"]);
if($UserGroupIdentifier[0] == "ADMINISTRATOR"){
$Error[] = ["Code" => ERROR_CODE_INVALID, "Message" => "Administrator users cannot be impersonated", ];
}
else{
$Session->Impersonate(new User(
$UserRecord["{$EntityName}Email"],
$UserRecord["{$EntityName}PasswordHash"],
$UserRecord["{$EntityName}Name"],
$UserRecord["{$EntityName}Phone"],
null,
$UserRecord["{$EntityName}URL"],
$UserRecord["{$EntityName}Picture"],
$UserRecord["{$EntityName}PictureThumbnail"],
$UserRecord["{$EntityName}ID"],
$UserRecord["{$EntityName}GroupIdentifier"],
$UserRecord["{$EntityName}GroupWeight"],
max(explode("; ", $UserRecord["{$EntityName}GroupWeight"])),
$UserRecord["{$EntityName}GroupName"],
$UserGroupIdentifier[0]
));
}
}
else{
$Error[] = ["Code" => ERROR_CODE_NOT_FOUND, "Message" => "User not found to impersonate", ];
}
}
else{
$Error[] = ["Code" => ERROR_CODE_ADMINISTRATOR_ONLY, "Message" => "Only Administrators can impersonate other non Administrator users", ];
}
return count($Error) ? $Error : true;
}
function CreatePath($Path){
global $Environment;
return $Environment->Utility()->CreatePath($Path);
}
function SecondToTime($Second = 0){
global $Environment;
return $Environment->Utility()->SecondToTime($Second);
}
function VariableSize($Variable){
return \sPHP::$Utility->VariableSize($Variable);
}
function VarSize($Variable){ // Alias for VariableSize()
return VariableSize($Variable);
}
}
namespace sPHP\Content{
/*
Shortcut for Value (GET) property of Content object
*/function Get($Name = null, $DefaultValue = null, $Path = null, $Language = null, $FileName = null, $Debug = null){
$Content = new \sPHP\Content($Name, $DefaultValue, $Path, null, $Language, $FileName);
return $Content->Value(null, $Debug);
}
/*
Shortcut for Value (SET) property of Content object
*/function Set($Name = null, $Value = null, $Path = null, $Language = null, $FileName = null, $Debug = null){
$Content = new \sPHP\Content($Name, null, $Path, null, $Language, $FileName);
return $Content->Value($Value, $Debug);
}
/*
Shortcut for EditAnchor property of Content object
*/function EditAnchor($Name = null, $Path = null, $Language = null, $FileName = null, $Hide = false, $NewWindow = false){
$Content = new \sPHP\Content($Name, null, $Path, null, $Language, $FileName);
return $Content->EditAnchor($Hide, $NewWindow);
}
}
namespace sPHP\Comm{
function Mail($To = null, $Subject = null, $Message = null, $From = null, $BodyStyle = null, $LogPath = null, $Cc = null, $Bcc = null, $Attachement = null, $ReplyTo = null, $HTML = null, $Header = null, $Host = null, $Port = null, $User = null, $Password = null){
$Mail = new Mail($To, $Subject, $Message, $From, $BodyStyle, $LogPath, $Cc, $Bcc, $Attachement, $ReplyTo, $HTML, $Header, $Host, $Port, $User, $Password);
return $Mail->Send();
}
function cURL(?string $URI = null, ?array $GET = null, ?array $POST = null, ?array $FILE = null, ?array $HTTPHeader = null, ?string $CookiePath = null, $CookieFile = null, ?string $Method = null, ?bool $SSLVerifyPeer = null, ?bool $SSLVerifyHost = null, ?string $UserAgent = null, ?string $Referer = null, ?bool $FollowRedirection = null){
$cURL = new cURL();
return $cURL->Fetch($URI, $GET, $POST, $FILE, $HTTPHeader, $CookiePath, $CookieFile, $Method, $SSLVerifyPeer, $SSLVerifyHost, $UserAgent, $Referer, $FollowRedirection);
}
}
namespace sPHP\HTML{
function Meta($Name = null, $Content = null, $HTTPEquivalent = null, $Property = null, $CharacterSet = null){
$Meta = new Meta($Name, $Content, $HTTPEquivalent, $Property, $CharacterSet);
return $Meta->HTML();
}
}
namespace sPHP\HTML\UI{
function Progressbar($Maximum = null, $Value = null, $URL = null, $Target = null, $CSSSelector = null, $Tooltip = null, $Width = null, $Prefix = null, $Suffix = null, $EventHandlerJavaScript = null, $ID = null){
$Object = new Progressbar($Maximum, $Value, $URL, $Target, $CSSSelector, $Tooltip, $Width, $Prefix, $Suffix, $EventHandlerJavaScript, $ID);
return $Object->HTML();
}
function ChartJS($Recordset = null, $Dataset = null, $Label = null, $XAxes = null, $YAxes = null, $ID = null, $Type = null, $Title = null, $TitleFontColor = null, $TitleFontSize = null, $TitleFontStyle = null, $LegendFontColor = null, $LegendFontSize = null, $LegendFontStyle = null, $AspectRatio = null, $MaintainAspectRatio = null, $Responsive = null){
$Object = new ChartJS($Recordset, $Dataset, $Label, $XAxes, $YAxes, $ID, $Type, $Title, $TitleFontColor, $TitleFontSize, $TitleFontStyle, $LegendFontColor, $LegendFontSize, $LegendFontStyle, $AspectRatio, $MaintainAspectRatio, $Responsive);
return $Object->HTML();
}
function Datagrid($Data = null, $URL = null, $RecordCount = null, $Field = null, $Title = null, $RowPerPage = null, $DataIDColumn = null, $Action = null, $BaseURL = null, $IconBaseURL = null, $Footer = null, $PreHTML = null, $BatchAction = null, $ExpandURL = null, $Serial = null, $Selectable = null, $ID = null, $CSSSelector = null, $SerialCaption = null, $PaginatorPageCaption = null, $PaginatorRecordsCaption = null, $RowCSSSelector = null){
$Object = new Datagrid($Data, $URL, $RecordCount, $Field, $Title, $RowPerPage, $DataIDColumn, $Action, $BaseURL, $IconBaseURL, $Footer, $PreHTML, $BatchAction, $ExpandURL, $Serial, $Selectable, $ID, $CSSSelector, $SerialCaption, $PaginatorPageCaption, $PaginatorRecordsCaption, $RowCSSSelector);
return $Object->HTML();
}
function MessageBox($Content, $Title = null, $CSSSelector = null){
$Object = new MessageBox($Content, $Title, $CSSSelector);
return $Object->HTML();
}
function Button($Caption = null, $Type = null, $Name = null, $Value = null, $EventHandlerJavaScript = null, $Width = null, $CSSSelector = null, $ID = null, $Tooltip = null, $Icon = null){
$Object = new Button($Caption, $Type, $Name, $Value, $EventHandlerJavaScript, $Width, $CSSSelector, $ID, $Tooltip, $Icon);
return $Object->HTML();
}
function Input($Name = null, $Width = null, $DefaultValue = null, $Required = null, $Type = null, $CSSSelector = null, $Placeholder = null, $EventHandlerJavaScript = null, $ID = null, $Step = null, $Minimum = null, $Maximum = null, $ReadOnly = null, $Autocomplete = null){
$Object = new Input($Name, $Width, $DefaultValue, $Required, $Type, $CSSSelector, $Placeholder, $EventHandlerJavaScript, $ID, $Step, $Minimum, $Maximum, $ReadOnly, $Autocomplete);
return $Object->HTML();
}
function Textarea($Name = null, $Width = null, $Height = null, $DefaultValue = null, $Required = null, $CSSSelector = null, $Placeholder = null, $EventHandlerJavaScript = null, $ID = null){
$Object = new Textarea($Name, $Width, $Height, $DefaultValue, $Required, $CSSSelector, $Placeholder, $EventHandlerJavaScript, $ID);
return $Object->HTML();
}
function Select($Name = null, $Option = null, $PrependOption = null, $CaptionField = null, $AppendOption = null, $ValueField = null, $DefaultValue = null, $CSSSelector = null, $EventHandlerJavaScript = null, $ID = null){
$Object = new Select($Name, $Option, $PrependOption, $CaptionField, $AppendOption, $ValueField, $DefaultValue, $CSSSelector, $EventHandlerJavaScript, $ID);
return $Object->HTML();
}
function Radio($Value = null, $Caption = null, $Name = null, $CSSSelector = null, $EventHandlerJavaScript = null, $ID = null){
$Object = new Radio($Value, $Caption, $Name, $CSSSelector, $EventHandlerJavaScript, $ID);
return $Object->HTML();
}
function RadioGroup($Name = null, $Option = null, $DefaultValue = null, $CSSSelector = null){
$Object = new RadioGroup($Name, $Option, $DefaultValue, $CSSSelector);
return $Object->HTML();
}
function Checkbox($Value = null, $Caption = null, $Name = null, $CSSSelector = null, $EventHandlerJavaScript = null, $ID = null){
$Object = new Checkbox($Value, $Caption, $Name, $CSSSelector, $EventHandlerJavaScript, $ID);
return $Object->HTML();
}
function CheckboxGroup($Name = null, $Option = null, $PrependOption = null, $CaptionField = null, $AppendOption = null, $ValueField = null, $CSSSelector = null, $EventHandlerJavaScript = null, $Array = null, $ID = null){
$Object = new CheckboxGroup($Name, $Option, $PrependOption, $CaptionField, $AppendOption, $ValueField, $CSSSelector, $EventHandlerJavaScript, $Array, $ID);
return $Object->HTML();
}
function Field($Content = null, $Caption = null, $NewLine = null, $Separate = null, $CaptionWidth = null, $ContentWidth = null, $CSSSelector = null, $Header = null, $Footer = null, $Prefix = null, $Suffix = null, $ContentName = null, $ContentPath = null, $ContentAnchor = null, $ContentLanguage = null, $ID = null){
$Object = new Field($Content, $Caption, $NewLine, $Separate, $CaptionWidth, $ContentWidth, $CSSSelector, $Header, $Footer, $Prefix, $Suffix, $ContentName, $ContentPath, $ContentAnchor, $ContentLanguage, $ID);
return $Object->HTML();
}
function Form(?string $Action = null, $Content = null, $SubmitCaption = null, $SignatureModifier = null, $Title = null, $Header = null, $Footer = null, $Status = null, $ID = null, $Reset = null, $ButtonContent = null, $EventHandlerJavaScript = null, $InputValidation = null, $CSSSelector = null){
$Object = new Form($Action, $Content, $SubmitCaption, $SignatureModifier, $Title, $Header, $Footer, $Status, $ID, $Reset, $ButtonContent, $EventHandlerJavaScript, $InputValidation, $CSSSelector);
return $Object->HTML();
}
function DropdownMenu($Item = null, $CSSSelector = null){
$Object = new DropdownMenu($Item, $CSSSelector);
return $Object->HTML();
}
function Toast($Content = null, $CSSSelector = null, $LifeTime = null, $Container = null, $HTML = null){
$Object = new Toast($Content, $CSSSelector, $LifeTime, $Container, $HTML);
return $Object->HTML();
}
function Accordion($Name = null, $Pad = null, $IconBaseURL = null, $CSSSelector = null, $SinglePad = null){
$Object = new Accordion($Name, $Pad, $IconBaseURL, $CSSSelector, $SinglePad);
return $Object->HTML();
}
}
namespace sPHP\Graphic{
function Resample($PictureFile, $MaximumWidth = null, $MaximumHeight = null, $SavePath = null, $Percent = null, $Width = null, $Height = null, $Type = null){
$Object = new \sPHP\Graphic();
return $Object->Resample($PictureFile, $MaximumWidth, $MaximumHeight, $SavePath, $Percent, $Width, $Height, $Type);
}
}
?>