-
Notifications
You must be signed in to change notification settings - Fork 30
/
csp2chart.php
80 lines (62 loc) · 2.19 KB
/
csp2chart.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
<?php
include_once("csp_helper.php");
$u = "drpico@gmail.com";
$p = "pi314159265";
$ss = new Google_Spreadsheet($u,$p);
$ss->useSpreadsheet("Collaboration Tracking");
$ss->useWorksheet("Sheet1");
$ss2 = new Google_Spreadsheet($u,$p);
$ss2->useSpreadsheet("NRNB Subproject Stages");
$ss2->useWorksheet("Sheet1");
$rowset = 'projectstage!=""'; # only rows with stage info
$rows = $ss->getRows($rowset);
if ($rows){
foreach ($rows as $row){
$stage = $row['projectstage'];
$stage2 = array();
## skip if no digits
$stage = str_replace(",","",$stage);
$len = strlen($stage);
if ($len < 1)
continue;
## else extract digits and prepare cell writes
elseif ($len == 1){
array_push($stage2, $stage . "1");
} elseif ($len > 1) {
array_push($stage2, substr($stage,0,1) . "2");
for ($i=1; $i<$len-1; $i++) {
array_push($stage2, substr($stage,$i,1) . "1");
array_push($stage2, substr($stage,$i,1) . "2");
}
array_push($stage2, substr($stage,$len-1,1) . "1");
}
#print_r($stage2);
## get or add row to Stages and write cells
$subid = "CSP-".$row['subprojectstatus'];
$nrnb = $row['nrnbcontact'];
$title = $row['projecttitle'];
$uprow = array
(
'projecttitle' => $title,
'nrnbcontact' => $nrnb,
'subprojectstatus' => $subid
);
foreach ($stage2 as $st){
$col = "st".$st;
$uprow[$col] = $st;
}
## UPDATE GOOGLE DOC
$rowcheck = $ss2->getRows("subprojectstatus=\"$subid\"");
if ($rowcheck) {
if ($ss2->updateRow($uprow, "subprojectstatus=\"$subid\""))
echo "Data successfully updated for subproject ID: $subid\n";
else
echo "Error, unable to update data for subproject ID: $subid\n";
} else {
if ($ss2->addRow($uprow))
echo "Data successfully added for subproject ID: $subid\n";
else
echo "Error, unable to add data for subproject ID: $subid\n";
}
}
}