notification.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /****************************
  3. * File : notification.php
  4. * Author : Cygnusa
  5. * @2018
  6. ****************************/
  7. //SECURITY
  8. if ( ! defined('APPLICATION_PATH')) exit('No direct script access allowed');
  9. //FUNCTION LISTS
  10. //1 - TOPIC AND CONTENT
  11. //2 - ASSESSMENT
  12. //3 - SURVEY
  13. //4 - BULLETIN
  14. //5 - GENERAL
  15. //6 - REWARD POINT
  16. //7 - WALLET
  17. class notification
  18. {
  19. function __construct($parent)
  20. {
  21. //GET PAGE MESSAGE
  22. $this->page_data=globalfunc::getMessage($parent,$parent->lang,'notification');
  23. if(count($parent->params)==0)
  24. {
  25. $this->notificationFunc($parent);
  26. }else
  27. {
  28. $qry_params=explode ("?",$parent->params[0]);
  29. $parameter_val=strtolower($qry_params[0]);
  30. if(strtolower($parent->device_type)=='app')
  31. {
  32. switch($parameter_val){
  33. case "read_notification":
  34. case "remove_notification":
  35. //case "group":
  36. $this->$parameter_val($parent );
  37. break;
  38. default:
  39. //$this->notificationFunc($parent);
  40. break;
  41. }
  42. }else if(strtolower($parent->device_type)=='web')
  43. {
  44. switch($parameter_val){
  45. case "read_notification":
  46. case "remove_notification":
  47. $this->$parameter_val($parent );
  48. break;
  49. default:
  50. //$this->notificationFunc($parent);
  51. break;
  52. }
  53. }
  54. }
  55. $parent->response(array('response'=>'failed', 'message' => 'PAGE NOT FOUND'), 404);
  56. }
  57. /* /////////////////////////////// NOTIFICATION FUNCTION //////////////////////////////////////////////// */
  58. private function notificationFunc($parent){
  59. globalfunc::checkMethodType($parent,array('GET'));
  60. globalfunc::checkParamCount($parent,0);
  61. $user_details=globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  62. //PAGINATION SETTINGS
  63. if($parent->device_type!='web')
  64. {
  65. $limit_str=globalfunc::setPageLimit($parent,$parent->funcparams[0]);
  66. $limit_cond=($limit_str)?" LIMIT ".$limit_str:'';
  67. }else
  68. {
  69. $limit_cond='';
  70. }
  71. $notification_str="SELECT n.`id`, n.`notificationtitle`, n.`notificationtext`, n.`notificationdata`, n.`notificationtype`,nu.status,nu.read_date,nu.created_on FROM ".TABLE_NOTIFICATION." as n JOIN ".TABLE_NOTIFICATION_USER." as nu ON n.id=nu.notificationid WHERE n.status='1' AND nu.userid='".$parent->current_user_id."' AND nu.status!='2' ORDER BY nu.created_on DESC ".$limit_cond;
  72. $notification_arr=$parent->getQueryValue($notification_str);
  73. if(count($notification_arr)>0)
  74. {
  75. foreach($notification_arr as $nkey=>$res_noti)
  76. {
  77. $notification_arr[$nkey]->notificationdata=($res_noti->notificationdata!='')?json_decode($res_noti->notificationdata):null;
  78. }
  79. }
  80. //TOTAL COUNT
  81. $get_user_noti_count=$parent->selectQuery(TABLE_NOTIFICATION." as n JOIN ".TABLE_NOTIFICATION_USER." as nu ON n.id=nu.notificationid","COUNT(n.`id`)as n_count"," nu.userid='".$parent->current_user_id."' AND nu.status!='2'","");
  82. $total=($get_user_noti_count['nr'])?$get_user_noti_count['result'][0]->n_count:0;
  83. $last_page=($total && $parent->device_type!='web')?ceil($total/$parent->current_limit)-1:0;
  84. //NOT READ COUNT
  85. $get_user_noti_count=$parent->selectQuery(TABLE_NOTIFICATION." as n JOIN ".TABLE_NOTIFICATION_USER." as nu ON n.id=nu.notificationid","COUNT(n.`id`)as n_count"," nu.userid='".$parent->current_user_id."' AND nu.status='0'","");
  86. $not_read_count=($get_user_noti_count['nr'])?$get_user_noti_count['result'][0]->n_count:0;
  87. //LOG
  88. $logstr='NOTIFICATION LIST';
  89. globalfunc::insertUserLog($parent,$logstr);
  90. $parent->response(array('response'=>'success', 'data'=>$notification_arr,'total'=>$total,'last_page'=>$last_page,'current_page'=>$parent->current_page,'message'=>$this->page_data['success1'],'not_read_count'=>$not_read_count),200);
  91. }
  92. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  93. /* /////////////////////////////// READ NOTIFICATION //////////////////////////////////////////////// */
  94. private function read_notification($parent){
  95. globalfunc::checkMethodType($parent,array('GET','POST'));
  96. if($parent->get_request_method()=='POST')
  97. {
  98. globalfunc::checkParamCount($parent,1);
  99. globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  100. $REQUEST_KEYS=array('notificationid'=>'string');
  101. globalfunc::mandatoryKey($parent,$REQUEST_KEYS);
  102. $notificationid=escape_str($parent->_request['notificationid']);
  103. $notificationid_arr=@explode(',',$notificationid);
  104. $notificationid=(count($notificationid_arr)>0)? @implode(',',$notificationid_arr):"''";
  105. }else if($parent->get_request_method()=='GET')
  106. {
  107. globalfunc::checkParamCount($parent,2);
  108. globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  109. $notificationid = escape_str($parent->params[1]);
  110. }
  111. //FOR MULIPLE
  112. $checkcond=(strpos($notificationid,',') !== false)?" AND n.`id` IN (".$notificationid.") ":" AND n.`id`='".$notificationid."'";
  113. $cond=(strpos($notificationid,',') !== false)?" AND notificationid IN (".$notificationid.") ":" AND notificationid='".$notificationid."'";
  114. $notification_str="SELECT n.`id`, n.`notificationtitle`, n.`notificationtext`, n.`notificationdata`, n.`notificationtype`, nu.status,nu.read_date FROM ".TABLE_NOTIFICATION." as n JOIN ".TABLE_NOTIFICATION_USER." as nu ON n.id=nu.notificationid WHERE nu.userid='".$parent->current_user_id."' AND nu.status!='2' ".$checkcond." ORDER BY n.`id` ASC ".$limit_cond;
  115. $notification_arr=$parent->getQueryValue($notification_str);
  116. //if(!count($notification_arr)>0) $parent->response(array('response'=>'failed','message'=>$this->page_data["error1"]),406);
  117. //STATUS CHANGE
  118. $parent->executeQuery(" UPDATE ".TABLE_NOTIFICATION_USER." SET status='1' WHERE userid='".$parent->current_user_id."' ".$cond);
  119. //LOG
  120. $logstr='READ NOTIFICATION';
  121. globalfunc::insertUserLog($parent,$logstr);
  122. $parent->response(array('response'=>'success','message'=>$this->page_data['success1']),200);
  123. }
  124. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  125. /* /////////////////////////////// REMOVE NOTIFICATION //////////////////////////////////////////////// */
  126. private function remove_notification($parent){
  127. globalfunc::checkMethodType($parent,array('GET','POST'));
  128. if($parent->get_request_method()=='POST')
  129. {
  130. globalfunc::checkParamCount($parent,1);
  131. globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  132. $REQUEST_KEYS=array('notificationid'=>'string');
  133. globalfunc::mandatoryKey($parent,$REQUEST_KEYS);
  134. $notificationid=escape_str($parent->_request['notificationid']);
  135. $notificationid_arr=@explode(',',$notificationid);
  136. $notificationid=(count($notificationid_arr)>0)? @implode(',',$notificationid_arr):"''";
  137. }else if($parent->get_request_method()=='GET')
  138. {
  139. globalfunc::checkParamCount($parent,2);
  140. globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  141. $notificationid = escape_str($parent->params[1]);
  142. }
  143. //FOR MULIPLE
  144. $checkcond=(strpos($notificationid,',') !== false)?" AND n.`id` IN (".$notificationid.") ":" AND n.`id`='".$notificationid."'";
  145. $cond=(strpos($notificationid,',') !== false)?" AND notificationid IN (".$notificationid.") ":" AND notificationid='".$notificationid."'";
  146. $notification_str="SELECT n.`id`, n.`notificationtitle`, n.`notificationtext`, n.`notificationdata`, n.`notificationtype`, nu.status,nu.read_date FROM ".TABLE_NOTIFICATION." as n JOIN ".TABLE_NOTIFICATION_USER." as nu ON n.id=nu.notificationid WHERE nu.userid='".$parent->current_user_id."' AND nu.status!='2' ".$checkcond." ORDER BY n.`id` ASC ".$limit_cond;
  147. $notification_arr=$parent->getQueryValue($notification_str);
  148. //if(!count($notification_arr)>0) $parent->response(array('response'=>'failed','message'=>$this->page_data["error1"]),406);
  149. //STATUS CHANGE
  150. $parent->executeQuery(" UPDATE ".TABLE_NOTIFICATION_USER." SET status='2' WHERE userid='".$parent->current_user_id."' ".$cond);
  151. //LOG
  152. $logstr='REMOVE NOTIFICATION';
  153. globalfunc::insertUserLog($parent,$logstr);
  154. $parent->response(array('response'=>'success','message'=>$this->page_data['success1']),200);
  155. }
  156. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  157. }
  158. ?>