· 9 years ago · Nov 19, 2016, 09:20 AM
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2class Api_New extends CI_Controller {
3
4 function Api_New()
5 {
6 parent::__construct();
7 $this->load->model('commonmodel');
8 $this->load->model('api_model');
9 $this->load->library('email');
10 $this->load->helper('email');
11
12 $this->form_validation->set_message('valid_email', 'please insert a valid email address');
13 $this->form_validation->set_message('matches', 'please check you have entered the correct password');
14 $this->form_validation->set_message('is_unique', 'it seems you have already registered with us. Can you please login');
15 $this->data['giftcard_url'] = $this->config->item('site_url').'uploads/giftcard/original/';
16 $this->data['country_url'] = $this->config->item('site_url').'uploads/country/original/';
17 $this->data['social_url'] = $this->config->item('site_url').'uploads/social/original/';
18
19 }
20
21 function index()
22 {
23 echo "Not authorized";
24 }
25
26 /* Start Function for register user */
27 function register(){
28
29 if($_POST){
30
31 //// Start Check fields validation
32 if($this->input->post('type') == 'email'){$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');}
33 $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
34 $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
35 $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]');
36 $this->form_validation->set_rules('cnfpassword', 'Confirm Password', 'trim|required|matches[password]');
37 $this->form_validation->set_rules('gcm_id', 'Gcm id', 'trim|required');
38 $this->form_validation->set_rules('device_id', 'Device id', 'trim|required');
39 $this->form_validation->set_rules('type', 'Type', 'trim|required');
40 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
41 //// End Check fields validation
42
43 if($this->form_validation->run()) {
44 $insertdata = array();
45 if($this->input->post('type') != 'email'){$insertdata['is_active'] = 'Y';}
46 $insertdata['type'] = $this->input->post('type');
47 $insertdata['first_name'] = $this->input->post('first_name');
48 $insertdata['last_name'] = $this->input->post('last_name');
49 $insertdata['password'] = md5($this->input->post('password'));
50 $insertdata['email'] = $this->input->post('email');
51 $insertdata['encrypt'] = base64_encode($_POST['password']);
52 $insertdata['gcm_id'] = $this->input->post('gcm_id');
53 $insertdata['device_id'] = $this->input->post('device_id');
54 $insertdata['registration_date'] = date('Y-m-d H:i:s');
55 $insertdata['wallet_id'] = str_replace('0','5',md5(uniqid()));
56 $insertdata['invation_code'] = substr(md5(uniqid()) ,5, 5);
57 $insertdata['activation_code'] = md5(date("Y-m-d H:i:s").$_POST['email']);
58 $insertdata['last_login_date'] = date("Y-m-d H:i:s");
59
60 if($this->input->post('type') == 'email'){
61
62 //// insert user register data
63 $id = $this->api_model->insertData("users", $insertdata);
64 }
65 else{
66
67 $checkDataa = array();
68 $tableNamea ="users AS usr";
69 $fieldNamea = array('usr.* , usr.id AS user_id , usr.is_active');
70 $checkDataa['usr.email'] = $this->input->post('email');
71 $rowDataa = $this->api_model->selectData($tableNamea, $fieldNamea, $checkDataa);
72
73 if($rowDataa->num_rows() > 0){
74 $userDataa = $rowDataa->result_array();
75 if($userDataa[0]['is_active'] == 'Y'){$id = $userDataa[0]['user_id'];}
76 else{echo json_encode(array("RESULT" => "NO", "Message" => "Admin Blocked this account"));exit;}
77 }
78 else{$id = $this->api_model->insertData("users", $insertdata);}
79
80 }
81 if($id){
82
83 $checkData['usr.Id'] = $id;
84 $tableName = "users AS usr";
85 $fieldName = array('usr.* , usr.id AS user_id');
86
87 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
88 $userData = $rowData->result_array();
89 $userData[0]['password'] = base64_decode($userData[0]['encrypt']);
90
91 //Add other things to register
92
93 //Menu Text Details
94 $checkData2 = "(menu.id='1')";
95 $tableCon2 ="menu_pages AS menu";
96 $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
97 $groupBy2 = "menu.id";
98 $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
99 $menuData = $rowData2->row_array();
100
101
102 /* Earn points details */
103 $checkData3['ern.id'] = 1;
104 $tableName3 ="earn_points AS ern";
105 $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
106 $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
107 $earnData = $rowData3->row_array();
108
109
110 //version Details
111 $checkData4 = "(ver.id='1')";
112 $tableCon4 ="app_version AS ver";
113 $fields4 = array("ver.version AS app_version");
114 $groupBy4 = "ver.id";
115 $rowData4 = $this->api_model->selectData($tableCon4, $fields4, $checkData4,NULL,NULL,0,10,FALSE,$groupBy4);
116 $versionData = $rowData4->row_array();
117 $resultArray = array_merge($userData[0],$menuData , $earnData , $versionData);
118
119 ///send activation account
120 if($this->input->post('type') == 'email'){ $this->sendmail($insertdata);
121
122 echo json_encode(array("RESULT" => "YES", "Message" => "Thanks, Please Check Your Email to Activate Your Account.", "Data" => $resultArray));} else{ echo json_encode(array("RESULT" => "YES", "Message" => "Login Successfully", "Data" => $resultArray)); exit; }
123
124 }else{
125 echo json_encode(array("RESULT" => "NO", "Message" => "Registration not completed. Please contact with application administrator"));
126 }
127 exit();
128 }else{
129 $this->load->view('api/noresult'); //load noresult and error view
130 exit();
131 }
132
133 }else{
134
135 //$this->load->view('api/register'); // load default testing view
136 }
137 }
138 /* End Function for register user */
139
140 /* Start Function for register user */
141 function update_profile(){
142
143 if($_POST){
144
145
146 $updatedata = array();
147 $where['id'] = $this->input->post('user_id');
148 if($this->input->post('paypal_account')!='') {$updatedata['paypal_account'] = $this->input->post('paypal_account');}
149 if($this->input->post('first_name')!='') {$updatedata['first_name'] = $this->input->post('first_name');}
150 if($this->input->post('last_name')!='') {$updatedata['last_name'] = $this->input->post('last_name');}
151 if($this->input->post('password')!='') {$updatedata['password'] = $this->input->post('password');$updatedata['encrypt'] = base64_encode($_POST['password']);}
152
153 //// insert user register data
154 $id = $this->api_model->updateData("users", $updatedata , $where);
155
156 if($id){
157
158 $checkData['usr.Id'] = $this->input->post('user_id');
159 $tableName = "users AS usr";
160 $fieldName = array('usr.* , usr.id AS user_id');
161
162 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
163 $userData = $rowData->result_array();
164 $userData[0]['password'] = base64_decode($userData[0]['encrypt']);
165
166 //Add other things to register
167
168 //Menu Text Details
169 $checkData2 = "(menu.id='1')";
170 $tableCon2 ="menu_pages AS menu";
171 $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
172 $groupBy2 = "menu.id";
173 $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
174 $menuData = $rowData2->row_array();
175
176
177 /* Earn points details */
178
179
180 $checkData3['ern.id'] = 1;
181 $tableName3 ="earn_points AS ern";
182 $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
183 $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
184 $earnData = $rowData3->row_array();
185 $resultArray = array_merge($userData[0],$menuData , $earnData);
186
187
188
189 echo json_encode(array("RESULT" => "YES", "Message" => "success", "Data" => $resultArray));
190
191 }else{
192 echo json_encode(array("RESULT" => "NO", "Message" => "Please try again"));
193 }
194
195
196 }else{
197
198 //$this->load->view('api/update_profile'); // load default testing view
199 }
200 }
201 /* End Function for register user */
202
203
204 /* Start Function for login authentication */
205 function login_authentication(){
206 if($_POST){
207 //// Start Check fields validation
208
209 $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
210 $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]');
211 $this->form_validation->set_rules('gcm_id', 'Gcm id', 'trim|required');
212 $this->form_validation->set_rules('device_id', 'Device id', 'trim|required');
213 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
214 //// End Check fields validation
215
216 if($this->form_validation->run()) {
217 $checkData = array();
218
219 $checkData['usr.password'] = md5($this->input->post('password'));
220 $checkData['usr.email'] = $this->input->post('email');
221 $checkData['usr.is_active'] = 'Y';
222 $insertData['device_id'] = $this->input->post('device_id');
223 $insertData['gcm_id'] = $this->input->post('gcm_id');
224
225 $insertData['last_login_date'] = date("Y-m-d H:i:s");
226
227 $tableName ="users AS usr";
228 $fieldName = array('usr.* , usr.id AS user_id');
229
230 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
231
232 if($rowData->num_rows() > 0){
233 $userData = $rowData->result_array();
234
235 $whereData['id'] = $userData[0]['user_id'];
236 $this->api_model->updateData("users",$insertData , $whereData );
237
238 //Add other things to login
239
240 //Menu Text Details
241 $checkData2 = "(menu.id='1')";
242 $tableCon2 ="menu_pages AS menu";
243 $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
244 $groupBy2 = "menu.id";
245 $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
246 $menuData = $rowData2->row_array();
247
248
249
250
251 /* Earn points details */
252 $checkData3['ern.id'] = 1;
253 $tableName3 ="earn_points AS ern";
254 $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
255 $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
256 $earnData = $rowData3->row_array();
257
258 //version Details
259 $checkData4 = "(ver.id='1')";
260 $tableCon4 ="app_version AS ver";
261 $fields4 = array("ver.version AS app_version");
262 $groupBy4 = "ver.id";
263 $rowData4 = $this->api_model->selectData($tableCon4, $fields4, $checkData4,NULL,NULL,0,10,FALSE,$groupBy4);
264 $versionData = $rowData4->row_array();
265
266
267 $resultArray = array_merge($userData[0],$menuData , $earnData ,$versionData);
268 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $resultArray));
269 }else{ echo json_encode(array("RESULT" => "NO", "Message" => "Inavalid Email and Password")); }
270
271
272 }
273
274 else{
275 $this->load->view('api/noresult'); //load noresult and error view
276 exit();
277 }
278 }else{
279 //$this->load->view('api/checklogin'); // load default testing view
280 }
281 }
282 /* End Function for login authentication */
283
284
285 /* Start Function for forgot password */
286 function forgot_pass(){
287 if($_POST){
288 //// Start Check fields validation
289
290 $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
291 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
292 //// End Check fields validation
293
294 if($this->form_validation->run()) {
295 $checkData = array();
296
297 $checkData['usr.email'] = $this->input->post('email');
298 $checkData['usr.is_active'] = 'Y';
299
300 $tableName ="users AS usr";
301 $fieldName = array('usr.* , usr.id AS user_id');
302
303 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
304
305 if($rowData->num_rows() > 0){
306 $userData = $rowData->result_array();
307
308 $password = uniqid();
309
310 $insertData['password'] = md5($password);
311 $insertData['encrypt'] = base64_encode($password);
312
313 $this->sendmailForgotPassword($userData[0],$password);
314
315 $whereData['id'] = $userData[0]['user_id'];
316
317 $this->api_model->updateData("users",$insertData , $whereData );
318
319 echo json_encode(array("RESULT" => "YES", "Message" => "Your updated password sent on your email address,Please check", "Data" => $userData[0]));
320 }else{
321 echo json_encode(array("RESULT" => "NO", "Message" => "Inavalid Email Address")); }
322 }
323
324 else{
325 $this->load->view('api/noresult'); //load noresult and error view
326 exit();
327 }
328 }else{
329 //$this->load->view('api/checklogin'); // load default testing view
330 }
331 }
332 /* End Function for forgot password */
333
334 /* Start Function for country list */
335
336 function country_list(){
337
338 $checkData = "(cty.is_active='Y')";
339
340 $tableCon ="country AS cty";
341
342
343$fields = array("cty.id AS country_id , cty.name AS country_name, cty.price_sign AS country_price_sign , CONCAT('".$this->data['country_url']."',cty.logo) AS country_logo , cty.is_active AS country_status ");
344
345 $groupBy = "cty.id";
346 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
347 if($rowData->num_rows() > 0){
348 $query_tables_result = array();
349 $query_tables_result = $rowData->result_array();
350
351 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
352 }else{
353 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
354 }
355 }
356
357 /* End Function for country list */
358
359
360 /* Start Function for redeem complete list */
361
362 function redeem_complete_list(){
363 if($_POST){
364
365 $checkData = "(red.user_id = '".$_POST['user_id']."')";
366
367 $tableCon ="redeem_offers AS red LEFT JOIN offers AS off ON red.offer_id = off.id LEFT JOIN gifts_card AS gift ON gift.id = off.giftcard_id LEFT JOIN country ON country.id =gift.country_id";
368
369
370 $fields = array("red.* , off.*,gift.title AS giftcard_title , red.is_active AS redeem_status ,country.price_sign AS country_price_sign, country.name AS country_name");
371
372 $groupBy = "red.id";
373 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
374 if($rowData->num_rows() > 0){
375 $query_tables_result = array();
376 $query_tables_result = $rowData->result_array();
377
378 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
379 }else{
380 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
381 }
382 }
383 //$this->load->view('api/redeem_complete_list');// load default testing view
384 }
385
386 /* End Function for for redeem complete list */
387
388
389 /* Start Function for redeem complete list */
390
391 function credits_complete_list(){
392 if($_POST){
393
394 $checkData = "(red.user_wallet = '".$_POST['user_id']."') AND (red.sdk_name!='admin')";
395
396 $tableCon ="offers_credits AS red LEFT JOIN users AS usr ON red.user_wallet = usr.wallet_id";
397
398
399 $fields = array("red.* , usr.first_name , usr.last_name , usr.email");
400
401 $groupBy = "red.id";
402 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
403 if($rowData->num_rows() > 0){
404 $query_tables_result = array();
405 $query_tables_result = $rowData->result_array();
406
407 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
408 }else{
409 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
410 }
411 }
412 // $this->load->view('api/redeem_complete_list');// load default testing view
413 }
414
415 /* End Function for for redeem complete list */
416
417
418 /* Start Function for invite friend list */
419
420 function invite_friend_list(){
421 if($_POST){
422
423 $checkData = "(usr.parent_id = '".$_POST['user_id']."')";
424
425 $tableCon ="users AS usr";
426
427
428 $fields = array("usr.*");
429
430 $groupBy = "usr.id";
431 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
432 if($rowData->num_rows() > 0){
433 $query_tables_result = array();
434 $query_tables_result = $rowData->result_array();
435
436 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
437 }else{
438 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
439 }
440 }
441 //$this->load->view('api/redeem_complete_list');// load default testing view
442 }
443
444 /* End Function for invite friend list */
445
446 /* Start Function for social list */
447 function social_list(){
448
449 $checkData = "(social.is_active='Y')";
450
451 $tableCon ="social_networks AS social";
452
453
454$fields = array("social.id AS social_id , social.title AS social_title, social.link AS social_link , CONCAT('".$this->data['social_url']."',social.logo) AS social_logo , social.is_active AS social_status ");
455
456 $groupBy = "social.id";
457 $orderby = "social.weight";
458 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,$orderby,0,10,FALSE,$groupBy);
459 if($rowData->num_rows() > 0){
460 $query_tables_result = array();
461 $query_tables_result = $rowData->result_array();
462
463 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
464 }else{
465 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
466 }
467 }
468 /* End Function for country list */
469
470
471 /* Start Function for country Details */
472
473 function country_details(){
474 if($_POST){
475
476 //// Start Check fields validation
477 $this->form_validation->set_rules('country_id', 'Country Id', 'required');
478 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
479 //// End Check fields validation
480
481 if($this->form_validation->run()) {
482
483 /* Post values */
484 $country_id = $this->input->post('country_id');
485
486 $checkData = "(gift.country_id= '".$country_id."') AND (gift.is_active='Y')";
487
488 $tableCon ="gifts_card gift LEFT JOIN offers ON (offers.giftcard_id = gift.id AND offers.is_active='Y')";
489
490
491$fields = array("gift.country_id AS country_id , gift.description AS giftcard_description, gift.id AS giftcard_id , gift.title AS giftcard_title , CONCAT('".$this->data['giftcard_url']."',gift.logo) AS giftcard_logo ,CONCAT('[' , GROUP_CONCAT(DISTINCT '{\"offer_id\":\"' , offers.id, '\",\"offers_redeem_amount\":\"' , offers.title , '\",\"offer_price\":\"' , offers.price , '\"}') , ']') AS offers_details");
492
493 $groupBy = "gift.id";
494 $orderBy = 'gift.weight';
495 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,$orderBy,0,10,FALSE,$groupBy);
496 if($rowData->num_rows() > 0){
497 $query_tables_result = array();
498 $query_tables_result = $rowData->result_array();
499
500 $count =sizeof($query_tables_result);
501 for($a= 0; $a<$count; $a++){
502 /* Start Convert json to Array */
503 $query_tables_result[$a]['offers_details'] = json_decode($query_tables_result[$a]['offers_details']);
504
505 if($query_tables_result[$a]['offers_details'] == null || $query_tables_result[$a]['offers_details'] == '') {$query_tables_result[$a]['offers_details'] = array();}
506 /* End Convert json to Array */
507
508 }
509
510
511 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
512 }else{
513 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!"));exit();
514 }
515 }else{
516 $this->load->view('api/noresult'); //load noresult and error view
517 exit();
518 }}
519
520 else{
521
522 //$this->load->view('api/country_details');// load default testing view
523 }
524 }
525
526 /* End Function for country Details */
527
528
529 /* Start Function for Checkin */
530
531 function checkin(){
532 if($_POST){
533
534 //// Start Check fields validation
535 $this->form_validation->set_rules('user_id', 'User id', 'required');
536 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
537 //// End Check fields validation
538
539 if($this->form_validation->run()) {
540 $checkData = array();
541 /* Post values */
542 $checkData['usr.id'] = $this->input->post('user_id');
543 $tableName ="users AS usr";
544 $fieldName = array('usr.rewards_checkin AS rewards_checkin , usr.points AS points');
545 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
546
547
548 if($rowData->num_rows() > 0){
549 $userData = $rowData->row_array();
550 $rewards_checkin = $userData['rewards_checkin'];
551 $datetime = date('Y-m-d H:i:s');
552 /* Earn points details */
553 $checkData2['ern.id'] = 1;
554 $tableName2 ="earn_points AS ern";
555 $fieldName2 = array('ern.*');
556 $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
557 $earnData = $rowData2->row_array();
558
559 if($rewards_checkin == '0000-00-00 00:00:00'){
560 $insertData['points'] = $userData['points'] + $earnData['daily_reward_points'];
561 $insertData['rewards_checkin'] = date('Y-m-d H:i:s');
562 }
563 else{
564
565 $day1 = strtotime($rewards_checkin);
566 $day2 = strtotime($datetime);
567 $diffHours = round(($day2 - $day1) / 3600);
568 if($diffHours >= 24 ){ $insertData['points'] = $userData['points'] + $earnData['daily_reward_points']; $insertData['rewards_checkin'] = date('Y-m-d H:i:s');}
569 else{ echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Check-In!"));exit(); }
570 }
571
572
573 $whereData['id'] = $this->input->post('user_id');
574 $this->api_model->updateData("users",$insertData , $whereData );
575 $points['user_points'] = $insertData['points'];
576 $points['rewards_checkin'] = $insertData['rewards_checkin'];
577 echo json_encode(array("RESULT" => "YES", "Message" => "Check-In Successful", "Data" => $points));
578 }
579
580 else{
581 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to checkin!"));exit();
582 }
583 }else{
584 $this->load->view('api/noresult'); //load noresult and error view
585 exit();
586 }}
587
588 else{
589
590 //$this->load->view('api/checkin');// load default testing view
591 }
592 }
593
594 /* End Function for Checkin */
595
596
597 /* Start Function For menu_content*/
598 function menu_content(){
599
600 $checkData = "(menu.id='1')";
601
602 $tableCon ="menu_pages AS menu";
603 $fields = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
604
605 $groupBy = "menu.id";
606 $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,10,FALSE,$groupBy);
607 if($rowData->num_rows() > 0){
608
609 $query_tables_result = $rowData->row_array();
610
611 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $query_tables_result));exit();
612 }else{
613 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
614 }
615
616 }
617
618 /* End Function For menu_content*/
619
620 /* Start Function For invitaion_code */
621
622 function invitaion_code(){
623 if($_POST){
624
625 //// Start Check fields validation
626 $this->form_validation->set_rules('user_id', 'User id', 'required');
627 $this->form_validation->set_rules('invite_wallet_id', 'Invite wallet id', 'required');
628
629 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
630 //// End Check fields validation
631
632 if($this->form_validation->run()) {
633 $checkData = array();
634 /* Post values */
635 $checkData['usr.id'] = $this->input->post('user_id');
636 $tableName ="users AS usr";
637 $fieldName = array('usr.*');
638 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
639
640 $checkData2['usr.wallet_id'] = $this->input->post('invite_wallet_id');
641 $tableName2 ="users AS usr";
642 $fieldName2 = array('usr.*');
643 $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
644
645
646
647 if($rowData->num_rows() > 0 && $rowData2->num_rows() > 0){
648 $userData = $rowData->row_array();
649 $fuserData = $rowData2->row_array();
650 if($userData['is_usecode'] == 'N'){
651
652
653 /// Get Reward points details
654 $checkEarnData['earn.id'] = '1';
655 $tableEarnName ="earn_points AS earn";
656 $fieldEarnName = array('earn.*');
657 $rowEarnData = $this->api_model->selectData($tableEarnName, $fieldEarnName, $checkEarnData);
658 $earnData = $rowEarnData->row_array();
659
660 //update user points who use invation code
661 $udateUserData = $this->db->query("UPDATE users set points = points + '".$earnData['invite_user_reward']."' , parent_id = '".$fuserData['id']."' , is_usecode = 'Y' WHERE id ='".$this->input->post('user_id')."'");
662
663 //update user friends points who send invation code
664 $udateFriendData = $this->db->query("UPDATE users set points = points + '".$earnData['invite_friend_reward']."' WHERE wallet_id ='".$this->input->post('invite_wallet_id')."'");
665
666
667 $checkData = array();
668 /* Post values */
669 $checkData['usr.id'] = $this->input->post('user_id');
670 $tableName ="users AS usr";
671 $fieldName = array('usr.rewards_checkin AS rewards_checkin , usr.points AS user_points');
672 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
673 $userData = $rowData->row_array();
674
675
676 echo json_encode(array("RESULT" => "YES", "Message" => "Successfully Use Invitaion code ", "Data" => $userData));
677 }
678 else{
679 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Use Invitaion code!"));exit();
680 }
681
682 }
683
684 else{
685 echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Use Invitaion code!"));exit();
686 }
687 }else{
688 $this->load->view('api/noresult'); //load noresult and error view
689 exit();
690 }}
691
692 else{
693
694 //$this->load->view('api/invitaion_code');// load default testing view
695 }
696 }
697
698
699 /* End Function For invitaion_code */
700
701
702
703 /* Start Function For credit apk */
704
705 function super_rewards(){
706
707 if($_REQUEST){
708
709
710 $SECRET_KEY = "36f0b3b4cd28302a41ecb52a7f08dc3d"; // secret for my app
711 $transaction_id = $_REQUEST['id'];
712 $walletId = $_REQUEST['uid'];
713 $offer_id = $_REQUEST['oid']; // completed offer or payment method
714 $points = $_REQUEST['new'];
715 $hash_signature = $_REQUEST['sig'];
716
717 $hash = md5($transaction_id.':'.$points.':'.$walletId.':'.$SECRET_KEY);
718 if ($hash != $hash_signature) {
719 // signature doesn't match, respond with a failure
720 /*$to = "mca.abhinav.saxena@gmail.com";
721 $subject = "Testing Email ";
722 $msg = "Info Mail User Failure";
723 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
724 $headers .= "MIME-Version: 1.0" . "\r\n";
725 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
726 mail($to,$subject,$msg,$headers);*/
727 echo "0\n";
728 exit;
729 }
730
731 //update user friends points who send invation code
732 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
733 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Super Rewards' , user_wallet = '".$walletId."' , created = now()");
734 //GET user Details
735 $checkData['usr.wallet_id'] = $walletId;
736 $tableName ="users AS usr";
737 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
738 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
739 $userData = $rowData->row_array();
740 $registatoin_ids = $userData['registatoin_ids'];
741 $earn = $userData['points'];
742 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
743 $message = array("message" => 'Congrats!!! You got '.$points.' credits from super rewards.' , 'type' => 'confirm' , 'userpoints' =>$earn);
744
745 $this->send_notification($registatoin_ids, $message); // sending push notification
746
747 // all good!
748 //log("User $user_id purchased $new_currency coins using $offer_id (txn: $transaction_id)\n");
749 $to = "mca.abhinav.saxena@gmail.com";
750 $subject = "Testing Email ";
751 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
752 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
753 $headers .= "MIME-Version: 1.0" . "/r/n";
754 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
755 //mail($to,$subject,$msg,$headers);
756
757 echo "1";
758
759 }
760
761
762 }
763
764 function adscend_media(){
765
766 if($_REQUEST){
767
768 $transaction_id = $_REQUEST['offerid'];
769 $walletId = $_REQUEST['sub1'];
770 $points = $_REQUEST['rate']; // completed offer or payment method
771
772 //update user friends points who send invation code
773 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
774 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'AdscendMedia' , user_wallet = '".$walletId."' , created = now()");
775 //GET user Details
776 $checkData['usr.wallet_id'] = $walletId;
777 $tableName ="users AS usr";
778 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
779 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
780 $userData = $rowData->row_array();
781 $registatoin_ids = $userData['registatoin_ids'];
782 $earn = $userData['points'];
783 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
784 $message = array("message" => 'Congrats!!! You got '.$points.' credits from adscend media.' , 'type' => 'confirm' , 'userpoints' =>$earn);
785
786 $this->send_notification($registatoin_ids, $message); // sending push notification
787
788 $to = "mca.abhinav.saxena@gmail.com";
789 $subject = "Testing Email ";
790 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
791 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
792 $headers .= "MIME-Version: 1.0" . "\r\n";
793 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
794 //mail($to,$subject,$msg,$headers);
795
796 echo "1";
797
798
799 }
800
801
802 }
803
804 function adxmi(){
805
806 if($_GET){
807
808 $transaction_id = $_REQUEST['order'];
809 $walletId = $_REQUEST['user'];
810 $points = $_REQUEST['points']; // completed offer or payment method
811
812 //update user friends points who send invation code
813 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
814 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'ADXMI' , user_wallet = '".$walletId."' , created = now()");
815 //GET user Details
816 $checkData['usr.wallet_id'] = $walletId;
817 $tableName ="users AS usr";
818 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
819 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
820 $userData = $rowData->row_array();
821 $registatoin_ids = $userData['registatoin_ids'];
822 $earn = $userData['points'];
823 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
824 $message = array("message" => 'Congratulations! You got '.$points.' credits from ADXMI.' , 'type' => 'confirm' , 'userpoints' =>$earn);
825
826 $this->send_notification($registatoin_ids, $message); // sending push notification
827
828 $to = "mca.abhinav.saxena@gmail.com";
829 $subject = "Testing Email ";
830 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
831 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
832 $headers .= "MIME-Version: 1.0" . "\r\n";
833 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
834 //mail($to,$subject,$msg,$headers);
835
836 echo "1";
837
838
839 }
840
841
842 }
843
844 function cpa_lead(){
845
846 if($_REQUEST){
847
848 /*
849 * Postback Example Script. This script is meant to only be a rough outline of
850 * how a postback should operate, and not necessarily used out of the box.
851 *
852 * Copyright 2015. CPAlead, LLC. All Rights Reserved
853 */
854
855 // Define your password, set to blank "" for no password. (optional).
856 $your_postback_password = "";
857
858 // Setup postback variables. For a complete list of variables visit https://cpalead.com/documentation/postback/index.php
859 $password = $_REQUEST['password'];
860 $walletId = $_REQUEST['subid'];
861 $campaign_name = $_REQUEST['campaign_name'];
862 $payout = $_REQUEST['payout'];
863 $points = $_REQUEST['virtual_currency'];
864
865
866 // If (optional) password is set, deny access.
867 if (!empty($your_postback_password) && isset($password) && !empty($password) && ($your_postback_password != $password))
868 {
869 // exit;
870 }
871
872 //update user friends points who send invation code
873 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
874 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'CPALead' , user_wallet = '".$walletId."' , created = now()");
875 //GET user Details
876 $checkData['usr.wallet_id'] = $walletId;
877 $tableName ="users AS usr";
878 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
879 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
880 $userData = $rowData->row_array();
881 $registatoin_ids = $userData['registatoin_ids'];
882
883 $earn = $userData['points'];
884 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
885 $message = array("message" => 'Congrats!!! You got '.$points.' credits from cpa lead.' , 'type' => 'confirm' , 'userpoints' =>$earn);
886 $this->send_notification($registatoin_ids, $message); // sending push notification
887
888
889 $to = "mca.abhinav.saxena@gmail.com";
890 $subject = "Testing Email ";
891 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
892 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
893 $headers .= "MIME-Version: 1.0" . "/r/n";
894 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
895 //mail($to,$subject,$msg,$headers);
896
897 echo "success";
898
899
900 }
901
902
903 }
904
905 function personaly(){
906
907 if($_REQUEST){
908
909 $secret_key = '1819ba4924947870f0666e3bd15c466c';
910 $app_hash = '84bd29a809d93f7d2f4e0e1a01a6517b';
911 // Get params
912 $walletId = $_REQUEST['user_id'];
913 $points = $_REQUEST['amount'];
914 $offer_id = $_REQUEST['offer_id'];
915 $app_id = $_REQUEST['app_id'];
916 $signature = $_REQUEST['signature'];
917 $offer_name = $_REQUEST['offer_name'];
918 // Create validation signature
919 $validation_signature = md5($walletId . ':' . $app_hash . ':' . $secret_key); // the app_hash can be found in your app settings
920 if ($signature != $validation_signature) {
921 // Signatures not equal - send error code
922 echo 0;
923 //die();
924 }
925
926 //update user friends points who send invation code
927 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
928 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Persona.ly' , user_wallet = '".$walletId."' , created = now()");
929 //GET user Details
930 $checkData['usr.wallet_id'] = $walletId;
931 $tableName ="users AS usr";
932 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
933 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
934 $userData = $rowData->row_array();
935 $registatoin_ids = $userData['registatoin_ids'];
936 // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
937
938 $earn = $userData['points'];
939 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
940 $message = array("message" => 'Congrats!!! You got '.$points.' credits from personaly.' , 'type' => 'confirm' , 'userpoints' =>$earn);
941
942 $this->send_notification($registatoin_ids, $message); // sending push notification
943
944
945 // Validation was successful. Credit user process.
946 $to = "mca.abhinav.saxena@gmail.com";
947 $subject = "Testing Email ";
948 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
949 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
950 $headers .= "MIME-Version: 1.0" . "\r\n";
951 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
952 //mail($to,$subject,$msg,$headers);
953
954 echo 1;
955 die();
956
957
958 }
959
960
961 }
962
963 function super_sonic(){
964
965 if($_GET){
966
967 // get the variables
968 $userId = $_GET['appUserId'];
969 $eventId = $_GET['eventId'];
970 $rewards = $_GET['rewards'];
971 $signature = $_GET['signature'];
972 $timestamp = $_GET['timestamp'];
973 $privateKey = '9d4a37';
974 // validate the call using the signature
975 if (md5($timestamp.$eventId.$userId.$rewards.$privateKey) != $signature)
976 {
977 echo "Signature doesnÕt match parameters";
978 return;
979 }
980 //update user friends points who send invation code
981 $udatepoints = $this->db->query("UPDATE users set points = points + '".$rewards."' WHERE wallet_id ='".$userId."'");
982 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$rewards."' , sdk_name = 'Super Sonic' , user_wallet = '".$userId."' , created = now()");
983 //GET user Details
984 $checkData['usr.wallet_id'] = $userId;
985 $tableName ="users AS usr";
986 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
987 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
988 $userData = $rowData->row_array();
989 $registatoin_ids = $userData['registatoin_ids'];
990 $earn = $userData['points'];
991 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
992 $message = array("message" => 'Congrats!!! You got '.$rewards.' credits from super sonic.' , 'type' => 'confirm' , 'userpoints' =>$earn);
993
994 //$message = array("message" => 'Congrats!!! You got '.$rewards.' points.');
995
996
997
998
999 $to = "mca.abhinav.saxena@gmail.com";
1000 $subject = "Testing Email ";
1001 $msg = "Info Mail User Id".$userId."===Event Id".$eventId."====REwards".$message."";
1002 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
1003 $headers .= "MIME-Version: 1.0" . "\r\n";
1004 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
1005 //mail($to,$subject,$msg,$headers);
1006 $this->send_notification($registatoin_ids, $message); // sending push notification
1007 // check that we haven't processed the same event before
1008 /*if (!alreadyProcessed($eventId)){
1009 // grant the rewards
1010 // doProcessEvent($eventId, $userId, $rewards);
1011
1012
1013 }*/
1014 // return ok
1015 echo $eventId.":OK";
1016
1017
1018 }
1019
1020
1021 }
1022
1023
1024 function trial_rewards(){
1025
1026 if($_REQUEST){
1027
1028 // TrialPay provides this signature for the message
1029 // Note: The actual HTTP header is "TrialPay-HMAC-MD5",
1030 // but PHP renames all HTTP headers so we end up with:
1031 $message_signature = $_SERVER['HTTP_TRIALPAY_HMAC_MD5'];
1032
1033 // Recalculate the signature locally
1034 $key = '9f93738c9f';
1035
1036 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1037 // the following is for POST notification
1038 if (empty($HTTP_RAW_POST_DATA)) {
1039 $recalculated_message_signature = hash_hmac('md5', file_get_contents('php://input'), $key);
1040 } else {
1041 $recalculated_message_signature = hash_hmac('md5', $HTTP_RAW_POST_DATA, $key);
1042 }
1043
1044 } else {
1045 // the following is for GET notification
1046 $recalculated_message_signature = hash_hmac('md5', $_SERVER['QUERY_STRING'], $key);
1047
1048
1049 }
1050
1051 if ($message_signature == $recalculated_message_signature) {
1052 // the message is authentic
1053 $walletId = $_REQUEST['sid'];
1054 $points = $_REQUEST['reward_amount'];// Revenue In dollor
1055
1056 //update user friends points who send invation code
1057 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
1058 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Trial Pay' , user_wallet = '".$walletId."' , created = now()");
1059 //GET user Details
1060 $checkData['usr.wallet_id'] = $walletId;
1061 $tableName ="users AS usr";
1062
1063 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
1064 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
1065 $userData = $rowData->row_array();
1066 $registatoin_ids = $userData['registatoin_ids'];
1067 $message = array("message" => 'Congrats!!! You got '.$points.' points.');
1068 $earn = $userData['points'];
1069 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
1070 $message = array("message" => 'Congrats!!! You got '.$points.' credits from Trialpay.' , 'type' => 'confirm' , 'userpoints' =>$earn);
1071
1072 $this->send_notification($registatoin_ids, $message); // sending push notification
1073
1074
1075 $to = "mca.abhinav.saxena@gmail.com";
1076 $subject = "Testing Email ";
1077 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
1078 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
1079 $headers .= "MIME-Version: 1.0" . "\r\n";
1080 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
1081 // mail($to,$subject,$msg,$headers);
1082http_response_code(200);
1083echo "1";
1084
1085
1086 } else {
1087 // the message is not authentic
1088http_response_code(400);
1089echo "Duplicate Transaction";
1090 }
1091
1092
1093 }
1094
1095
1096 }
1097
1098 function test(){
1099
1100$url = 'http://sensiblewallet.com/sensible_wallet/admin/index.php/api_new/test1';
1101
1102//print_r(get_headers($url));
1103
1104//print_r(get_headers($url, 1));
1105
1106$homepage = file_get_contents($url);
1107//echo $homepage;
1108$message_signature = $_SERVER['HTTP_TRIALPAY_HMAC_MD5'];
1109echo $message_signature;}
1110
1111 function test1(){
1112 http_response_code(200);
1113 echo "2";
1114 //http_response_code(400);
1115 }
1116
1117 function adgate_media(){
1118
1119 // Validation was successful. Credit user process.
1120 $to = "mca.abhinav.saxena@gmail.com";
1121 $subject = "Testing Email ";
1122 $msg = "Info Mail adgatemedia";
1123 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
1124 $headers .= "MIME-Version: 1.0" . "/r/n";
1125 $headers .= "Content-type:text/html;charset=UTF-8" . "/r/n";
1126 //mail($to,$subject,$msg,$headers);
1127 echo 1;
1128 //die;
1129
1130 if($_REQUEST){
1131
1132
1133 // Get params
1134 $walletId = $_REQUEST['aff_sub'];
1135 $points = $_REQUEST['points'];
1136
1137
1138 //update user friends points who send invation code
1139 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
1140 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'AdgateMedia' , user_wallet = '".$walletId."' , created = now()");
1141 //GET user Details
1142 $checkData['usr.wallet_id'] = $walletId;
1143 $tableName ="users AS usr";
1144 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
1145 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
1146 $userData = $rowData->row_array();
1147 $registatoin_ids = $userData['registatoin_ids'];
1148 // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
1149
1150 $earn = $userData['points'];
1151 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
1152 $message = array("message" => 'Congrats!!! You got '.$points.' credits from adgate media.' , 'type' => 'confirm' , 'userpoints' =>$earn);
1153
1154 $this->send_notification($registatoin_ids, $message); // sending push notification
1155
1156
1157 // Validation was successful. Credit user process.
1158 $to = "mca.abhinav.saxena@gmail.com";
1159 $subject = "Testing Email ";
1160 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
1161 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
1162 $headers .= "MIME-Version: 1.0" . "\r\n";
1163 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
1164 //mail($to,$subject,$msg,$headers);
1165
1166 echo 1;
1167 die();
1168 }
1169
1170
1171 }
1172
1173 function tapjoy(){
1174
1175
1176 if($_REQUEST){
1177
1178
1179 // Get params
1180 $walletId = $_REQUEST['snuid'];
1181 $points = $_REQUEST['currency'];
1182
1183
1184 //update user friends points who send invation code
1185 $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
1186 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'TapJoy' , user_wallet = '".$walletId."' , created = now()");
1187 //GET user Details
1188 $checkData['usr.wallet_id'] = $walletId;
1189 $tableName ="users AS usr";
1190 $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
1191 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
1192 $userData = $rowData->row_array();
1193 $registatoin_ids = $userData['registatoin_ids'];
1194 // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
1195
1196 $earn = $userData['points'];
1197 //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
1198 $message = array("message" => 'Congrats!!! You got '.$points.' credits from Tapjoy.' , 'type' => 'confirm' , 'userpoints' =>$earn);
1199
1200 $this->send_notification($registatoin_ids, $message); // sending push notification
1201
1202
1203 // Validation was successful. Credit user process.
1204 $to = "mca.abhinav.saxena@gmail.com";
1205 $subject = "Testing Email ";
1206 $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
1207 $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
1208 $headers .= "MIME-Version: 1.0" . "\r\n";
1209 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
1210 //mail($to,$subject,$msg,$headers);
1211
1212 echo 1;
1213 die();
1214 }
1215
1216
1217 }
1218
1219 /* End Function For credit apk */
1220
1221
1222
1223 /* Start Function For redeem */
1224 function redeem(){
1225
1226 if($_POST){
1227
1228 //// Start Check fields validation
1229 $this->form_validation->set_rules('user_id', 'User Id', 'trim|required');
1230 $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
1231 $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
1232 $this->form_validation->set_rules('offer_id', 'Offer id', 'trim|required');
1233 $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
1234 $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
1235 //// End Check fields validation
1236
1237 if($this->form_validation->run()) {
1238 $insertdata = array();
1239 $insertdata['user_id'] = $this->input->post('user_id');
1240 $insertdata['first_name'] = $this->input->post('first_name');
1241 $insertdata['last_name'] = $this->input->post('last_name');
1242 $insertdata['offer_id'] = $this->input->post('offer_id');
1243 $insertdata['email'] = $this->input->post('email');
1244 $insertdata['created'] = date('Y-m-d H:i:s');
1245
1246
1247 ///check points of user
1248
1249 $offerQuery2 = $this->db->query("SELECT price AS offer_price FROM offers WHERE id = '".$this->input->post('offer_id')."'");
1250 $offerData2 = $offerQuery2->row_array();
1251 $offer_price2 = $offerData2['offer_price'];
1252
1253 $checkpoints = $this->db->query("SELECT points AS offer_points FROM users WHERE id ='".$this->input->post('user_id')."'");
1254 $checkpointsData = $checkpoints->row_array();
1255 $chkpoints = $checkpointsData['offer_points'];
1256
1257
1258 if($offer_price2 > $chkpoints){echo json_encode(array("RESULT" => "NO", "Message" => "Try Again")); exit;}
1259
1260
1261 //// insert user register data
1262 $id = $this->api_model->insertData("redeem_offers", $insertdata);
1263
1264 if($id){
1265
1266 $offerQuery = $this->db->query("SELECT price AS offer_price FROM offers WHERE id = '".$this->input->post('offer_id')."'");
1267 $offerData = $offerQuery->row_array();
1268 $offer_price = $offerData['offer_price'];
1269 $udatepoints = $this->db->query("UPDATE users set points = points - '".$offer_price."' WHERE id ='".$this->input->post('user_id')."'");
1270
1271
1272 //updated points
1273 $userQuery = $this->db->query("SELECT points FROM users WHERE id = '".$this->input->post('user_id')."'");
1274 $userData = $userQuery ->row_array();
1275 $points_user = $userData['points'];
1276
1277
1278 $points['user_points'] = $points_user;
1279 $points['charged_offer_points'] = $offer_price;
1280
1281 $query = $this->db->query("SELECT t1.*,t3.title , t3.price AS offer_price ,t4.title AS gift_title , t5.name AS country_name , t5.price_sign FROM redeem_offers t1 LEFT JOIN users t2 ON t1.user_id = t2.id LEFT JOIN offers t3 ON t1.offer_id = t3.id LEFT JOIN gifts_card t4 ON t3.giftcard_id = t4.id LEFT JOIN country t5 ON t4.country_id = t5.id WHERE t1.id = '".$id."' ");
1282
1283 $redeemData = $query->row_array();
1284
1285 $this->sendredeemmail($redeemData);
1286 echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $points));
1287
1288 }else{
1289 echo json_encode(array("RESULT" => "NO", "Message" => "Try Again"));
1290 }
1291 exit();
1292 }else{
1293 $this->load->view('api/noresult'); //load noresult and error view
1294 exit();
1295 }
1296
1297 }else{
1298
1299 //$this->load->view('api/redeem'); // load default testing view
1300 }
1301 }
1302
1303 /* End Function For redeem */
1304
1305
1306 /**
1307 * This function is to send varification mail
1308 */
1309
1310 function sendmail($userData)
1311 {
1312
1313 // send mail
1314 $to = $userData['email'];
1315 $to_name = $userData['first_name'].' '.$userData['last_name'];
1316
1317 $from = 'support@sensiblewallet.com';
1318 $from_name = 'Sensible Wallet Support Team';
1319
1320 $subject = "Regarding Activation on Sensible Wallet App";
1321 $message = "Hello,<br><br>
1322
1323 Welcome to Sensible Wallet! <br><br>
1324
1325 You are almost Ready to Start Recharging Your Wallet!<br><br>
1326
1327 You, or someone using your email address, has completed registration at Wallet.<br><br>
1328
1329 You can complete registration by clicking the following link:<br><br>";
1330
1331 $message .='<a href="'."http://".$_SERVER['HTTP_HOST'].base_url().'users/activation/'.$userData['activation_code'].'">Click here</a><br><br><br><br>Best Regards,<br/>
1332Sensible Wallet Support Team';
1333
1334 $this->email->clear();
1335 $this->email->from($from, $from_name);
1336 $this->email->to($to,$to_name);
1337
1338$this->email->reply_to('no@noreply.com','noreplay');
1339 $this->email->subject($subject);
1340 $this->email->message($message);
1341 $this->email->set_mailtype('html');
1342 $this->email->send();
1343
1344 return true;
1345
1346 }
1347
1348 function updatePoints(){
1349 if($_POST){
1350 $this->form_validation->set_rules('wallet_id', 'Wallet id', 'required');
1351 $this->form_validation->set_rules('points', 'Points', 'required');
1352 $this->form_validation->set_error_delimiters('', '');
1353
1354 if($this->form_validation->run()) {
1355 $checkData = array();
1356 $checkData['wallet_id'] = $this->input->post('wallet_id');
1357 $tableName ="users AS usr";
1358
1359 $fieldName = array('usr.*');
1360 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
1361
1362 if($rowData->num_rows() > 0){
1363 $data = $rowData->row_array();
1364 $insertData['points'] = $this->input->post('points') + $data['points'] ;
1365 $whereData['wallet_id'] = $this->input->post('wallet_id');
1366
1367 $this->api_model->updateData("users",$insertData , $whereData );
1368
1369 //GET user Details
1370 $checkData2['usr.wallet_id'] = $this->input->post('wallet_id');
1371 $tableName2 ="users AS usr";
1372 $fieldName2 = array('usr.gcm_id AS registatoin_ids' ,'usr.points');
1373 $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
1374 $userData2 = $rowData2->row_array();
1375 $registatoin_ids = $userData2['registatoin_ids'];
1376 $earn = $userData2['points'];
1377 $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$this->input->post('points')."' , sdk_name = '".$this->input->post('sdkName')."', user_wallet = '".$this->input->post('wallet_id')."' , created = now()");
1378 $message = array("message" => 'Congrats!!! You got '.$this->input->post('points').' credits from '.$this->input->post('sdkName').'.' , 'type' => 'points' , 'userpoints' =>$earn);
1379 $this->send_notification($registatoin_ids, $message); // sending push notification
1380
1381 $points['user_points'] = $insertData['points'];
1382
1383 echo json_encode(array("RESULT" => "YES", "Message" => "Credits updated successfully!", "Data" => $points));
1384
1385 }else{
1386 echo json_encode(array("RESULT" => "NO", "Message" => "Oops! Invalid wallet id"));exit();
1387 }
1388 }else{
1389 $this->load->view('api/noresult'); //load noresult and error view
1390 exit();
1391 }
1392 }else{
1393 //$this->load->view('api/updatePoints');// load default testing view
1394 }
1395 }
1396
1397 /* End Function for updatePoints */
1398
1399
1400
1401 function sendmailForgotPassword($userData,$password)
1402 {
1403
1404 // send mail
1405 $to = $userData['email'];
1406 $to_name = $userData['first_name'].' '.$userData['last_name'];
1407
1408 $from = 'support@sensiblewallet.com';
1409 $from_name = 'Wallet Support Team';
1410
1411 $subject = "Forgot Password on Wallet App";
1412
1413 $message = "Your password is ".$password ."<br/>";
1414
1415 $message .='Best Regards,<br/>
1416Wallet Support Team';
1417
1418 $this->email->clear();
1419 $this->email->from($from, $from_name);
1420 $this->email->to($to,$to_name);
1421
1422$this->email->reply_to('no@noreply.com','noreplay');
1423 $this->email->subject($subject);
1424 $this->email->message($message);
1425 $this->email->set_mailtype('html');
1426 $this->email->send();
1427
1428 return true;
1429
1430 }
1431
1432
1433
1434 /**
1435 * Sending Push Notification
1436 */
1437 function send_notification($registatoin_ids, $message) {
1438
1439
1440
1441 // Set POST variables
1442 $url = 'https://android.googleapis.com/gcm/send';
1443
1444 $fields = array(
1445 'registration_ids' => array($registatoin_ids),
1446 'data' => $message,
1447 );
1448
1449 $headers = array(
1450 'Authorization: key=' .$this->config->item('GOOGLE_API_KEY'),
1451 'Content-Type: application/json'
1452 );
1453 // Open connection
1454 $ch = curl_init();
1455
1456 // Set the url, number of POST vars, POST data
1457 curl_setopt($ch, CURLOPT_URL, $url);
1458
1459 curl_setopt($ch, CURLOPT_POST, true);
1460 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
1461 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1462
1463 // Disabling SSL Certificate support temporarly
1464 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1465
1466 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
1467
1468 // Execute post
1469 $result = curl_exec($ch);
1470 if ($result === FALSE) {
1471 die('Curl failed: ' . curl_error($ch));
1472 }
1473
1474 // Close connection
1475 curl_close($ch);
1476 // echo $result;
1477 }
1478
1479
1480
1481
1482
1483 /**
1484 * Sending Push Notification
1485 */
1486 function test_notification($walletId) {
1487
1488 //GET user Details
1489 $checkData['usr.wallet_id'] = $walletId;
1490 $tableName ="users AS usr";
1491 $fieldName = array('usr.gcm_id AS registatoin_ids');
1492 $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
1493 $userData = $rowData->row_array();
1494
1495 // $registatoin_ids = array($gcm_regid);
1496
1497 // json message
1498 $arr_message = array('testing notification');
1499 //$message = array("message" => json_encode($arr_message));
1500$message = array("message" => 'Congrats!!! You got 5 points.' , 'type' => 'confirm' , 'userpoints' =>'5');
1501
1502 $registatoin_ids = $userData['registatoin_ids'];
1503
1504
1505 // Set POST variables
1506 $url = 'https://android.googleapis.com/gcm/send';
1507
1508 $fields = array(
1509 'registration_ids' =>array($registatoin_ids),
1510 'data' =>$message,
1511 );
1512
1513 $headers = array(
1514 'Authorization: key=' .$this->config->item('GOOGLE_API_KEY'),
1515 'Content-Type: application/json'
1516 );
1517 // Open connection
1518 $ch = curl_init();
1519
1520 // Set the url, number of POST vars, POST data
1521 curl_setopt($ch, CURLOPT_URL, $url);
1522
1523 curl_setopt($ch, CURLOPT_POST, true);
1524 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
1525 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1526
1527 // Disabling SSL Certificate support temporarly
1528 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1529
1530 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
1531
1532 // Execute post
1533 $result = curl_exec($ch);
1534 if ($result === FALSE) {
1535 die('Curl failed: ' . curl_error($ch));
1536 }
1537
1538 // Close connection
1539 curl_close($ch);
1540 echo $result;
1541 }
1542
1543
1544 /**
1545 * This function is to send reddem mail
1546 */
1547
1548 function sendredeemmail($data)
1549 {
1550
1551
1552 // send mail
1553 $to = 'rewards@sensiblewallet.com';
1554 $to_name = 'sensiblewallet';
1555
1556 $from = $data['email'];
1557 $from_name = $data['first_name'].' '.$data['last_name'];
1558
1559 $subject = "User is Requesting Award";
1560 $message = "Hi,<br><br>
1561
1562 Country : ".$data['country_name']." <br><br>
1563 GiftCard : ".$data['gift_title']." <br><br>
1564 UserName : ".$data['first_name'].' '.$data['last_name']." <br><br>
1565 Email : ".$data['email']." <br><br>
1566 Offer Redeem Amount : ".$data['price_sign'].' '.$data['title']." <br><br>";
1567
1568 $message .='<br><br>Best Regards,<br/>
1569'.$from_name.'';
1570
1571 $this->email->clear();
1572 $this->email->from($from, $from_name);
1573 $this->email->to($to,$to_name);
1574$this->email->reply_to('no@noreply.com','noreplay');
1575 $this->email->subject($subject);
1576 $this->email->message($message);
1577 $this->email->set_mailtype('html');
1578 $this->email->send();
1579
1580 return true;
1581
1582 }
1583
1584 function arrayresult($value){
1585 echo "<pre>";
1586 print_r($value);die;
1587
1588 }
1589
1590
1591}
1592?>