-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRA.gs
More file actions
101 lines (82 loc) · 3.42 KB
/
Copy pathRA.gs
File metadata and controls
101 lines (82 loc) · 3.42 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
function onOpen() {
SpreadsheetApp.getUi().createMenu('RemoteAccess')
.addItem('Authorize', 'createSpreadsheetEditTrigger')
.addItem('Logout Anywhere', 'logoutAnywhere')
.addItem('Open #remote-access channel', 'openRemoteAccessChannel')
.addItem('About', 'About')
.addToUi()
}
function createSpreadsheetEditTrigger() {
checkTriggers();
ScriptApp.newTrigger('runOnEdit')
.forSpreadsheet(SpreadsheetApp.getActive())
.onEdit()
.create();
var user = Session.getActiveUser().getEmail();
SpreadsheetApp.getUi().alert('Hi, ' + user + '. The script has been authorized.');
}
function runOnEdit(e) {
// if (e.source.getActiveSheet().getName() !== 'ras'
// //|| e.range.columnStart !== 6 || !e.value
// ) return;
// e.range.offset(0, 1, 1, 2).setValues([
// [Session.getActiveUser().getEmail().split("@")[0], new Date()]
// ])
}
function checkTriggers() {
var allTriggers = ScriptApp.getProjectTriggers();
if (allTriggers.length > 0) {
for (var i = 0; i < allTriggers.length; i++) {
ScriptApp.deleteTrigger(allTriggers[i]);
}
}
}
/*CyberHacktivist.com*/
function onEdit(event)
{
var timezone = "GMT+3";
var timestamp_format = "dd.MM.yyyy HH:mm:ss"; // Timestamp Format.
var updateColName = "IsBusy";
var updateColName2 = "PreviousUser";
var updateColNameCurrentUser = "CurrentUser";
var timeStampColName = "Timestamp";
var sheet = event.source.getSheetByName('RA'); //Name of the sheet where you want to run this script.
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
var updateCol2 = headers[0].indexOf(updateColName2); updateCol2 = updateCol2+1;
var updateColNameCurrentUser = headers[0].indexOf(updateColNameCurrentUser); updateColNameCurrentUser = updateColNameCurrentUser+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol)// && indexOf(updateColName) >= 1)// && editColumn == updateCol)
{
// only timestamp if 'Last Updated' header exists, but not in the header row itself!
// Browser.msgBox(event.value);
// Browser.msgBox(event.oldValue);
// Place current user to the "previousUser" column (if exist)
if (sheet.getRange(index, updateColNameCurrentUser).getValue() != "")
{
var cell = sheet.getRange(index, updateCol2);
cell.setValue(sheet.getRange(index, updateColNameCurrentUser).getValue());
}
if (event.value == "TRUE")
{
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
var email = Session.getActiveUser().getEmail();
cell.setValue(date);
//cell.setValue(date).setComment(email);
var email = Session.getActiveUser().getEmail();
sheet.getRange(event.source.getActiveRange().getRowIndex(), event.source.getActiveRange().getColumnIndex()+1).setValue(email);
}
else
{
var cell = sheet.getRange(index, dateCol + 1);
cell.setValue("");
sheet.getRange(event.source.getActiveRange().getRowIndex(), event.source.getActiveRange().getColumnIndex()+1).setValue("");
}
}
}
function logoutAnywhere() {
}