-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblackbox.php
More file actions
138 lines (109 loc) · 3.48 KB
/
blackbox.php
File metadata and controls
138 lines (109 loc) · 3.48 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
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
129
130
131
132
133
134
135
136
137
138
<?php
include 'civi_constants.php';
$postData = array(
"json" => "1",
"api_key" => API_KEY,
"key" => KEY,
);
function http_call($params){
$ch = curl_init(RESTURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POST,count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
if(! $reply = curl_exec($ch))
{
var_dump(curl_error($ch));
}
curl_close($ch);
return json_decode($reply, TRUE);
}
function civicrm_call($entity, $action, $params){
global $postData;
$addData = array(
"entity" => $entity,
"action" => $action
);
$allParams = array_merge($postData, $addData, $params);
return http_call($allParams);
}
function new_contact($params){
$contact = civicrm_call("Contact", "create", $params["Contact"]);
$id = $contact["values"]["contact_id"];
$primaryParams = array(
"contact_id" => $id,
"isPrimary" => "1"
);
$emailParams = array_merge($params["Email"], $primaryParams);
civicrm_call("Email", "create", $emailParams);
$phoneParams = array_merge($params["Phone"], $primaryParams);
civicrm_call("Phone", "create", $phoneParams);
$relParams = array(
"relationship_type_id" => 10, // Student Currently Attending
"contact_id_a" => $id,
"contact_id_b" => $params["School"]["contact_id_b"]
);
civicrm_call("Relationship", "create", $schoolParams);
$date = "some special format date";
$surveyParams = array(
"source_contact_id" => 1,
"target_contact_id" => $id,
"activity_type_id" => 32, // petition
"activity_date_time" => $date,
"subject" => 'Mission Hub Survey 2012',
"status_id" => 2, // completed
"campaign_id" => 2 // September 2012 launch
);
}
function sortByOrg($a, $b) {
return strcmp($a['organization_name'], $b['organization_name']);
}
function get_schools(){
global $postData;
$return = NULL;
$schoolData = array(
"entity" => "Contact",
"action" => "get",
"rowCount" => "1000",
"contact_sub_type" => "School",
"return" => "organization_name"
);
$allParams = array_merge($postData, $schoolData);
$reply = http_call($allParams);
if(key_exists('values', $reply))
{
$return = $reply["values"];
usort($return, "sortByOrg");
}
return $return;
}
function new_high_school_contact($params){
$contact = civicrm_call("Contact", "create", $params["Contact"]);
$id = $contact["id"];
$primaryParams = array(
"contact_id" => $id,
"isPrimary" => "1"
);
$emailParams = array_merge($params["Email"], $primaryParams);
civicrm_call("Email", "create", $emailParams);
$phoneParams = array_merge($params["Phone"], $primaryParams);
civicrm_call("Phone", "create", $phoneParams);
$schoolParams = array(
"relationship_type_id" => 10, // student currently attending
"contact_id_a" => $id,
"contact_id_b" => $params["School"]["contact_id_b"]
);
civicrm_call("Relationship", "create", $schoolParams);
$activityParams = array(
"source_contact_id" => 1,
"target_contact_id" => $id,
"activity_type_id" => 32, // Transition Form
"subject" => 'Transition 2013',
"status_id" => 4,
"priority_id" => 1,
"campaign_id" => 10,
"source_record_id" => 23,
);
civicrm_call("Activity", "create", $activityParams);
}
?>