-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinventory.php
99 lines (68 loc) · 2.73 KB
/
inventory.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
<?php
$filename = "inventory.html";
$start = 1;
$max = 40;
$file = file_get_contents($filename);
$wrapper_start = <<<END
<!-- BEGIN new inventory page -->
<div class="sheet-inventory-pagePAGENUMBER">
<div class="sheet-row sheet-sub-header">
<div class="sheet-col-1-15 sheet-center sheet-small-label">Row #</div>
<div class="sheet-col-1-15 sheet-center sheet-small-label">Carried?</div>
<div class="sheet-col-1-15 sheet-center sheet-small-label">Qty</div>
<div class="sheet-col-4-15 sheet-center sheet-small-label">Name</div>
<div class="sheet-col-2-15 sheet-center sheet-small-label">Weight</div>
<div class="sheet-col-6-15 sheet-center sheet-small-label">Descripton</div>
</div>
END;
$wrapper_end = <<<END
</div>
<!-- END inventory page -->
END;
$inventory_rows = <<<'END'
<!-- BEGIN inventory row -->
<div class="sheet-inventory-rowCURRENTROW">
<div class="sheet-row sheet-grey-row">
<div class="sheet-col-1-15 sheet-vert-middle sheet-inventory-row-number">CURRENTROW</div>
<div class="sheet-col-1-15 sheet-vert-middle sheet-checkbox-row"><input type="checkbox" name="attr_inventorycarriedCURRENTROW" value="@{inventoryweightCURRENTROW}" checked="checked" /></div>
<div class="sheet-col-1-15"><input type="number" name="attr_inventoryqtyCURRENTROW" value="1" min="0" step="1"></div>
<div class="sheet-col-4-15"><input type="text" name="attr_inventorynameCURRENTROW"></div>
<div class="sheet-col-2-15"><input type="number" name="attr_inventoryweightCURRENTROW" value="0" step="0.01"></div>
<div class="sheet-col-6-15"><input type="text" name="attr_inventorydescriptionCURRENTROW"></div>
</div>
</div>
<!-- END inventory row -->
END;
$full_output = "";
for ($i=$start; $i<=$max; $i++)
{
$return_text = "";
if (($i%10==1 && $i<$max) || ($i%10==1 && $i==$max) )
{
//Add start of page wrapper
$return_text .= $wrapper_start;
}
$return_text .= $inventory_rows;
if (is_int($i/10) || $i==$max)
{
//Add end of page wrapper
$return_text .= $wrapper_end;
}
// Replace placeholders with correct values
$return_text = str_replace("CURRENTROW", $i, $return_text);
$return_text = str_replace("PAGENUMBER", ceil($i/10), $return_text);
$full_output .= $return_text;
}
//Now stitch together weight calc hidden field
$weight_calc = "";
for ($i=$start; $i<=$max; $i++)
{
$weight_calc .= "@{inventorycarried$i} + (((@{inventoryqty$i} - 1) * @{inventorycarried$i}) * @{weight_unit_setting})";
if ($i < $max) $weight_calc .= " + ";
}
$html_weight_calc = "<input type=\"hidden\" name=\"attr_inventory_weight_calc\" value=\"(" . $weight_calc . ")\" />";
$full_output .= $html_weight_calc;
//echo $full_output;
$file = $full_output;
file_put_contents($filename, $file);
?>