-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasicFunctions.php
151 lines (144 loc) · 4.04 KB
/
BasicFunctions.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
<?php
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
$var = stripslashes($var);
//global $con; // Allow function access to global $db variable
return real_escape_string($var);
}
function funcFillArray($strResult,$strType='MYSQLI_ASSOC')//MYSQLI_BOTH,MYSQLI_ASSOC,MYSQLI_NUM
{
$aryReturn = array();
switch ($strType) {
case "MYSQLI_BOTH":
while ($aryReturn[] = mysqli_fetch_array($strResult, MYSQLI_BOTH)) {
}
break;
case "MYSQLI_ASSOC":
while ($aryReturn[] = mysqli_fetch_array($strResult, MYSQLI_ASSOC)) {
}
break;
case "MYSQLI_NUM":
while ($aryReturn[] = mysqli_fetch_array($strResult, MYSQLI_NUM)) {
}
break;
}
array_pop($aryReturn);
return $aryReturn;
}
function funcConvertMultiDimArray($aryMulti,$col){
for($i=0;$i<count($aryMulti);++$i){
$aryTemp[]=$aryMulti[$i][$col];
}
return $aryTemp;
}
function flatten_array($mArray) {
$sArray = array();
foreach ($mArray as $row) {
if ( !(is_array($row)) ) {
if($sArray[] = $row){
}
} else {
$sArray = array_merge($sArray,flatten_array($row));
}
}
return $sArray;
}
function funcSelectFromRecordSet($rvsRecordSet,$strSelection=null){
$aryTemp = funcConvertMultiDimArray(funcFillArray($rvsRecordSet,'MYSQLI_BOTH'),0);
return SelectFromArray($aryTemp,$aryTemp,$strSelection);
}
function SelectFromConcant($strOptions,$strTextOptions,$strSplitter,$strSelection = null)
{
$aryOptions=explode($strSplitter,$strOptions);
$aryText=explode($strSplitter,$strTextOptions);
return SelectFromArray($aryOptions,$aryText,$strSelection);
}
function SelectFromArray($aryOptions,$aryText,$strSelection = null)
{
$strHtmlSelect="";
for($i=0;$i<count($aryOptions);++$i)
{
if(!$aryOptions[$i]){
//Null
}
else{
if($aryOptions[$i]==$strSelection)
{
$strHtmlSelect .= "<option value='".$aryOptions[$i]."' selected>".$aryText[$i];
}
else
{
$strHtmlSelect .= "<option value='".$aryOptions[$i]."'>".$aryText[$i];
}
$strHtmlSelect .= "</option>";
}
}
return $strHtmlSelect;
}
function DropDownFromConcant($strConcat)
{
$aryList=explode(";",$strConcat);
return DropDownFromArray($aryList);
}
function DropDownFromArray($aryList)
{
$strHtmlDropDown="<div class='dropdown'><span class='help-block' data-toggle='dropdown' onclick=$(this).dropdown()>";
$strHtmlDropDown .=$aryList[0]." <button type='button' class='btn btn-xs dropdown-toggle btn-default' data-toggle='dropdown'><span class='caret'></span></button></span>";
$strHtmlDropDown .= "<ul class='dropdown-menu' role = 'menu'>";
for($i=0;$i<count($aryList);$i++)
{
$strHtmlDropDown .= "<li role='presentation'><a role='menuitem' tabindex='-1' href='#'>".$aryList[$i]."</a></li>";
}
$strHtmlDropDown .= "</ul>";
$strHtmlDropDown .="</div>";
return $strHtmlDropDown;
}
function tableFromRecordSet($rvsRecordSet,$tblID)
{
$aryData=funcFillArray($rvsRecordSet,'MYSQLI_ASSOC');
$finfo = mysqli_fetch_fields($rvsRecordSet);
$aryFields=array();
foreach ($finfo as $val) {
array_push($aryFields, $val->name);
}
return tableFromArray($aryData,$aryFields,$tblID);
}
function tableFromArray($aryData,$aryFields,$tblID)
{
//Initialize the table and header row
if($tblID=='')
{
$tblID='tblGenerated'.rand();
}
$strTable = "<div class='table-responsive'><table id='$tblID' class='table table-condensed table-striped table-hover'><thead><tr>";
for($i=0;$i<count($aryFields);$i++)
{
$strTable .="<th>".addSpaceAndCapitolize($aryFields[$i],'false')."</th>";
}
$strTable .="</tr></thead><tbody>";
//Add in the data fields
for($x=0;$x<count($aryData);$x++)
{
$strTable .="<tr id='tblRow$x'>";
for($y=0;$y<count($aryFields);$y++)
{
$strTable .="<td><div class='tablediv'>".$aryData[$x][$aryFields[$y]]."</div></td>";
}
$strTable .="</tr>";
}
$strTable .="</tbody></table></div>";
return $strTable;
}
function addSpaceAndCapitolize($strIncoming,$blnCap)
{
$strReturn='';
$aryReturn = split(",",substr(preg_replace("/([A-Z])/",',\\1',$strIncoming),1));
for($i=0;$i<count($aryReturn);$i++)
{
$strReturn = $strReturn.$aryReturn[$i]." ";
}
return $strReturn;
}
?>