/
onPinkieSubmit.php
128 lines (110 loc) · 4.05 KB
/
onPinkieSubmit.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
<?php
include_once 'includes/functions.php';
include_once 'includes/sessionFunctions.php';
include_once 'includes/pinkie.php';
include_once 'includes/logger.php';
secureSessionStart();
// TODO Needs to have serverside validation of variables. Especially the files.
$_pinkie = new Pinkie();
// All the stuff at the top.
$_pinkie->s_Title = $_POST['title'];
$_pinkie->s_Submitter = $_SESSION['Username'];
$_pinkie->s_OriginalSubmitter = $_SESSION['Username'];
$_pinkie->s_SubmittedFor = $_POST['submitTo'];
$_pinkie->s_Action = $_POST['action'];
$_pinkie->s_Priority = $_POST['priority'];
$_pinkie->s_ReferenceNumber = $_POST['referenceNumber'];
$_pinkie->s_Status = $_POST['status'];
if(isset( $_POST['includeTax']))
$_pinkie->b_isTaxable = TRUE;
else {
$_pinkie->b_isTaxable = FALSE;
}
//------------------------------------------------------------------------------
// Purchase Objects.
$_quantity = $_POST['quantity'];
$_stockNumber = $_POST['stockNumber'];
$_description = $_POST['description'];
$_unitPrice = $_POST['unitPrice'];
// add each of the objects to the pinkie.
foreach($_quantity as $key=>$q)
{
$_pinkie->addObject(intval($q), $_stockNumber[$key], $_description[$key], '', '', floatval($_unitPrice[$key]));
}
$_pinkie->d_ShippingFreight = floatval($_POST['shipping']);
$_pinkie->d_Total = floatval($_POST['total']);
$_pinkie->s_EquipmentType = $_POST['typeOfPurchase'];
if($_POST['typeOfPurchase'] == 'Other')
{
$_pinkie->s_EquipmentType = $_POST['typeOfPurchaseOther'];
}
//------------------------------------------------------------------------------
// Vendors and Justification.
$_pinkie->v_Vendor = $_POST['vendor'];
$_pinkie->s_Justification=$_POST['justification'];
$_pinkie->s_JustificationText=$_POST['justificationText'];
$_pinkie->s_EquipmentLocation = $_POST['equipmentLocation'];
$_pinkie->s_UCRPropertyTag = $_POST['ucrPropertyNumber'];
$_pinkie->s_classInstructed = $_POST['classInstructed'];
$_pinkie->s_Quote = $_POST['quote'];
// Funds
$_fund = $_POST['fund'];
$_amt = $_POST['amount'];
// Add them to the pinkie.
foreach ($_fund as $key => $f)
{
$_pinkie->addExpense(floatval($_amt[$key]), $f);
}
//------------------------------------------------------------------------------
// Please note that if the number of files excedes the max supported by the file
// system it will fail to create a folder.
//------------------------------------------------------------------------------
// Attachments.
for($i=0; $i<count($_FILES['attachment']['name']); $i++)
{
//Get the temp file path
$tmpFilePath = $_FILES['attachment']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
//-----------------------------
$now = time();
$num = date("w");
if ($num == 0)
{
$sub = 6;
}
else
{
$sub = ($num-1);
}
$WeekMon = mktime(0, 0, 0, date("m", $now) , date("d", $now)-$sub, date("Y", $now)); //monday week begin calculation
$todayh = getdate($WeekMon); //monday week begin reconvert
$d = $todayh['mday'];
$m = $todayh['mon'];
$y = $todayh['year'];
$newFilePath = PATH_PREFIX."$d-$m-$y/".$_SESSION['Username']."/". $_FILES['attachment']['name'][$i];
// Make the folder if it doesn't exist.
if (!is_dir(PATH_PREFIX."$d-$m-$y/".$_SESSION['Username']."/") && !mkdir(PATH_PREFIX."$d-$m-$y/".$_SESSION['Username']."/"))
{
onError("onSubmitPinkie failed", "Error creating folder: ".PATH_PREFIX."$d-$m-$y/".$_SESSION['Username']."/");
}
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath))
{
//Handle other code here
$_pinkie->addAttachment($newFilePath);
}
else
{
onError("onSubmitPinkie","Failed to submit pinkie because file upload failed. Path was: ".$newFilePath);
}
}
}
//------------------------------------------------------------------------------
// push it to the database.
//var_dump($_pinkie);
$_pinkie->toDatabase();
logGeneral($_pinkie->i_PinkieID, $_SESSION['Username'], "Pinkie was created by: ".getName());
header("Location: ./home.php");
?>