-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_triggers.php
99 lines (87 loc) · 3.06 KB
/
util_triggers.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
/*
- Created by Torin
- Helper functions to retrieve values in Triggers table
*/
require_once("db_config.php");
function func_getTriggerByID($id)
{
$condition = "trigger_id = '" . $id . "'";
return func_getSingleRowFromTable("triggers", $condition);
}
/*
* Returns all triggers can be generated by a given module, returns raw SQL result
*/
function func_getTriggersByModuleID($id)
{
$condition = "module_id = '" . $id . "' AND trigger_enabled = 1";
return func_getMultiRowFromTable("triggers", $condition);
}
/*
* Returns all triggers can be generated by a given module, returns raw SQL result
* This is more expensive than func_getTriggersByModuleID
*/
function func_getTriggersByModuleAlias($alias)
{
require_once("util_modules.php");
$the_module = func_getModuleByAlias($alias);
if ($the_module == null)
return null;
$module_id = $the_module['module_id'];
if ($module_id == null || $module_id <= 0 || $module_id == "")
return null;
return func_getTriggersByModuleID($module_id);
}
/*
* Returns all triggers that has the given name from all modules, returns raw SQL result
*/
function func_getTriggersByName($name)
{
$condition = "trigger_name = '" . $name . "'";
return func_getMultiRowFromTable("triggers", $condition);
}
function func_getTriggerModuleNameByID($id)
{
$condition = "trigger_id = '" . $id . "'";
$one_record = func_getSingleRowFromTable("triggers", $condition);
if ($one_record == null)
return null;
return intval($one_record['module_id']);
}
function func_getTriggerNameByID($id)
{
$condition = "trigger_id = '" . $id . "'";
$one_record = func_getSingleRowFromTable("triggers", $condition);
if ($one_record == null)
return null;
return $one_record['trigger_name'];
}
function func_getTriggerDescriptionByID($id)
{
$condition = "trigger_id = '" . $id . "'";
$one_record = func_getSingleRowFromTable("triggers", $condition);
if ($one_record == null)
return null;
return $one_record['trigger_description'];
}
//---------------------------------------------------------------------
// ADD
//---------------------------------------------------------------------
/*
* Add a new trigger/trigger
* $trigger_id: specific pre-defined trigger in the system (unique to a $module_id)
* $module_id: mandatory
* $trigger_name: a short name of this trigger to be displayed to user, eg. disconnect, connect, new post, change
* $trigger_description: optional description of this trigger, will be displayed to user as tips
*/
function func_addTrigger($trigger_id, $user_id, $filter_id, $filter_param, $action_id, $action_param, $trigger_description)
{
$table_name = "triggers";
$id_field_name = "trigger_id";
$input_names_array = array("module_id", "trigger_name", "trigger_description");
$input_values_array = array($module_id, $trigger_name, $trigger_description);
$datetime_field_name = 'last_updated';
$entry_ID = func_insertSingleRecordReturnID($table_name, $id_field_name, $input_names_array, $input_values_array, $datetime_field_name);
return $entry_ID;
}
?>