-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_new_leads.php
93 lines (72 loc) · 3.4 KB
/
action_new_leads.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
<?php
/**
* Created by N0B0DY.
* User: me@suvo.me
* Date: 9/15/14
* Time: 1:41 AM
*/
require('core.php');
$session->loginRequired('user', false);
$Form = new Form();
$Email = new Email();
if (!isset($_POST['submit'])) {
redirect('view.php');
} else {
if (!isset($_POST['first_name']) || empty($_POST['first_name'])) {
$Form->setError('error', 'Please write your first name.');
}
if (!isset($_POST['last_name']) || empty($_POST['last_name'])) {
$Form->setError('error', 'Please write your last name.');
}
if (!isset($_POST['lead_result']) || empty($_POST['lead_result'])) {
$Form->setError('error', 'Please select a lead result.');
}
if($_POST['lead_result'] == 'Y'){
if( !isset( $_POST['call_time'] ) || empty($_POST['call_time']) ) {
$Form->setError('leadsError','Please select call time and enter a phone number');
}
if( !isset( $_POST['phone_no'] ) || empty($_POST['phone_no']) ) {
$Form->setError('leadsError','Please select call time and enter a phone number');
}
}
if ($Form->num_errors > 0) {
$Form->return_msg_to('view.php');
} else {
$first_name = cleanData($_POST['first_name']);
$last_name = cleanData($_POST['last_name']);
$lead_result = cleanData($_POST['lead_result']);
$call_time = cleanData($_POST['call_time']);
$phone_no = cleanData($_POST['phone_no']);
$notes = cleanData($_POST['notes']);
$leadAdd = insertQuery(TBL_LEADS, array(
'user_id' => $_SESSION['user_id'],
'first_name' => $first_name,
'last_name' => $last_name,
'lead_result' => $lead_result,
'call_time' => $call_time,
'phone_no' => $phone_no,
'notes' => $notes,
'create_date' => 'NOW()'
));
if (!$leadAdd) {
$Form->setError('error', 'Database error! Please try again.');
$Form->return_msg_to('view.php');
} else {
if ($lead_result == 'Y') {
$leadData = mysql_fetch_object(mysql_query("SELECT agency.agency_name, leads.first_name, leads.last_name, leads.phone_no, leads.call_time, leads.notes FROM leads LEFT JOIN user ON user.id = leads.user_id LEFT JOIN agency ON agency.id = user.agency_id WHERE leads.id = $leadAdd"));
$Email->setEmailSubject('A new lead has been submitted.');
$Email->setMessage("A new lead has been submitted for agency <b>$leadData->agency_name</b> by <b style='color: #9B0202' >$_SESSION->first_name $_SESSION->last_name</b> with following info:<br/><br/>"
. "<b style='color: #9B0202'>Lead :</b> <span style='color: #9B0202' > $leadData->first_name $leadData->last_name </span> <br/>"
. "<b>Phone :</b> $leadData->phone_no <br/>"
. "<b>Time to Call:</b> $leadData->call_time <br/>"
. "<b>Note :</b> $leadData->notes. ");
$sentMailQuery = mysql_query("SELECT email FROM user WHERE type='admin' AND receive_email ='Y'");
while ($sentMail = mysql_fetch_assoc($sentMailQuery)) {
$Email->setEmailTo($sentMail['email']);
$Email->sendMail();
}
}
redirect('view.php?leads=success');
}
}
}