-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizationassessment.php
267 lines (218 loc) · 7.87 KB
/
organizationassessment.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
class organizationassessment extends CI_Controller
{
public function add_organizationassessment()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('email', 'email', 'required|valid_email|callback_checkifemailexist');
$this->form_validation->set_rules('phone_no', 'Phone No', 'required');
$this->form_validation->set_rules('address1', 'Address', 'required');
$this->form_validation->set_rules('city', 'City', 'required');
$this->form_validation->set_rules('state', 'State', 'required');
$this->form_validation->set_rules('country', 'Country', 'required');
$this->form_validation->set_error_delimiters('<div style="color: red;">', '</div>');
if ($this->form_validation->run() == FALSE)
{
$data['content'] = 'organizationassessment_insert';
$this->load->view('layout/layoutassesment',$data);
}
else{
$verify_reg_code=uniqid();
$config['mailtype'] = 'html';
$this->load->library('email',$config);
$this->load->library('table');
$this->email->from('[email protected]', 'GPI');
$first_name=$this->input->post('first_name');
$last_name=$this->input->post('last_name');
$city = ucwords($this->input->post('city'));
$state = ucwords($this->input->post('state'));
$country = $this->input->post('country');
$zip_code=$this->input->post('zip_code');
$organization=$this->input->post('organization');
$email=$this->input->post('email');
$totalscore=$this->input->post('postscore');
$totalscore = sprintf("%02d", $totalscore);
$password=mt_rand(1000, 9999);
$getlevel=$this->gpi_model->getscore("organization_score",$totalscore);
/*foreach($getlevel as $getlevel)
{*/
$level_id= $getlevel->level_id;
//}
//$level_id=$level_id;
$getlevelname=$this->gpi_model->getrecordbyidrow("levels",'level_id',$level_id);
$level=$getlevelname->level_name;
/* if($totalscore>=0 && $totalscore<=17)
{
$level_id=1;
$level="1-2";
}
else if($totalscore>=18 && $totalscore<=35)
{
$level_id=2;
$level="3-4";
}
else if($totalscore>=36 && $totalscore<=45)
{
$level_id=3;
$level="5-6";
}
else
{
$level_id=4;
$level="7-8";
}
*/
$mem_id = $this->common_model->select_single_field('mem_id','tbl_membership',array('mem_default'=>1));
$data=array(
'first_name'=>$first_name,
'last_name'=>$last_name,
'mem_id'=>$mem_id,
'email'=>$email,
'phone_no'=>$this->input->post('phone_no'),
'address1'=>$this->input->post('address1'),
'city'=>$city,
'state'=>$state,
'country'=>$country,
'zip_code'=>$zip_code,
'organization'=>$organization,
'password'=>$password,
'score'=>$totalscore,
'level_id'=>$level_id,
'verify_reg_code'=>$verify_reg_code,
'flag'=>5,
);
$this->gpi_model->insert($data,'users');
//$this->email->to($this->input->post('email'));
$this->email->to($this->input->post('email'));
$qa="";
$i=0;
$answer=$this->input->post('answer_id');
$question=$this->input->post('question');
$start = '
<html>
<head>
<title>GPI</title>
</head>
<body>
<p align="center"><h1><b>Organization Assessment Check</b></h1></p><br/>
<table align="center"><h1><b>Score:'.$totalscore.'</b></h1><br/>
<h1><b>Level:'.$level.'</b></h1></table><br/>
<table>
<tr>
<td><b>First Name : </b></td>
<td>'.$first_name.'</td>
</tr>
<tr>
<td><b>Last Name : </b></td>
<td>'.$last_name.'</td>
</tr>
<tr>
<td><b>Email : </b></td>
<td>'.$email.'</td>
</tr>
<tr>
<td><b>Password : </b></td>
<td>'.$password.'</td>
</tr>
<tr>
<td><b>City : </b></td>
<td>'.$city.'</td>
</tr>
<tr>
<td><b>State : </b></td>
<td>'.province_list($country,$state,true).'</td>
</tr>
<tr>
<td><b>Country : </b></td>
<td>'.country_list($country).'</td>
</tr>
<tr>
<td><b>Zip Code : </b></td>
<td>'.$zip_code.'</td>
</tr>
<tr>
<td><b>Organization : </b></td>
<td>'.$organization.'</td>
</tr><br />';
$userid = $this->db->insert_id();
$mid="";
foreach($answer as $answer)
{
$question_name=$this->gpi_model->get_questions("organization_questions",$question[$i]);
$qa.= $question_name->questions_name.":".$answer."\n";
//$qa.= $question_name->questions_name."\n";
//$qa.= $answer."\n";
$mid.='<b>Que#'.$question_name->questions_id.':'.$question_name->questions_name.'</b><br />
Ans)'.$answer.'<br/><br/>';
$data2=array(
'user_id'=>$userid,
'questions' =>$question_name->questions_name,
'answers' =>$answer,
);
$this->gpi_model->insert($data2,'user_answer_organization');
$i++;
}
//print_r($data2);
// exit;
$last='</table><br /><br />'.$mid.'</body></html>';
$message=$start.$last;
//print_r($message);
//exit;
/* set CC to Admins */
$where = array('id'=>3); // Event 1 = Readiness Assessment Submitted
$email_template = $this->gpi_model->get_by_where('email_template',$where);
$content = '';
if($email_template){
$recipients = $email_template->admin_recipients !='' ? unserialize($email_template->admin_recipients) : array();
if($recipients){
$admin_recipients = $this->gpi_model->get_by_whereIn('users',array('user_id'=>$recipients));
$cc = array();
foreach ($admin_recipients as $key => $u) {
$cc[] = $u->email;
}
if($cc)
$this->email->cc($cc);
}
/* Replacement Pattern */
$make_patterns = array(
'name' => $first_name.' '.$last_name ,
'level' => $level,
'summary' => $message,
);
$content = $email_template->email_content;
foreach ($make_patterns as $key => $value) {
$content = str_replace('{{'.$key.'}}', $value, $content);
}
$this->email->subject($email_template->email_subject);
/* Replacement Pattern */
}else{
$this->email->subject('Score');
$this->email->cc("[email protected], [email protected]");
}
/* set CC to Admins */
$this->email->message($content);
if($_SERVER['HTTP_HOST'] == 'localhost'){
echo $content;
exit;
}else
$this->email->send();
/*$this->email->message($message);
$this->email->send();*/
//echo $this->email->print_debugger();
$this->session->set_flashdata('msg', "Email Successfully Sent. Your Current Level is : ".$level);
$this->session->set_flashdata('success', "Your Assessment is Successfully Submited.");
redirect(base_url()."organizationassessment/add_organizationassessment/organizationassessment.html");
}
}
function checkifemailexist($str) {
$checkemailexist=$this->gpi_model->emailexist("users", "email", $str);
if($checkemailexist) {
$this->form_validation->set_message('checkifemailexist', 'Email already exists Please try another one.');
return false;
} else {
return true;
}
}
}