Cheetah
ChWsbCommunicator.php
Go to the documentation of this file.
1 <?php
2 
8  require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbPageView.php');
9  require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbAlerts.php' );
10  require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbEmailTemplates.php' );
11 
13  {
14  // contain count of all requests ;
16 
17  // contain some necessary data ;
18  var $aCommunicatorSettings = array();
19 
33  {
34  $aCommunicatorSettings['member_id'] = (int) $aCommunicatorSettings['member_id'];
35  $aCommunicatorSettings['page'] = (int) $aCommunicatorSettings['page'];
36  $aCommunicatorSettings['per_page'] = (int) $aCommunicatorSettings['per_page'];
37  $aCommunicatorSettings['alert_page'] = (int) $aCommunicatorSettings['alert_page'];
38 
39  $aCommunicatorSettings['communicator_mode'] = process_db_input($aCommunicatorSettings['communicator_mode'], CH_TAGS_STRIP);
40  $aCommunicatorSettings['person_switcher'] = process_db_input($aCommunicatorSettings['person_switcher'], CH_TAGS_STRIP);
42 
43  // call the parent constructor ;
44  parent::__construct('communicator_page');
45  $this -> aCommunicatorSettings = &$aCommunicatorSettings;
46 
47  // init some pagination parameters ;
48  if ( $this -> aCommunicatorSettings['per_page'] < 1 )
49  $this -> aCommunicatorSettings['per_page'] = 10 ;
50 
51  if ($this -> aCommunicatorSettings['per_page'] > 100 )
52  $this -> aCommunicatorSettings['per_page'] = 100;
53 
54  if($aCommunicatorSettings['member_id'] != 0)
55  $GLOBALS['oTopMenu']->setCurrentProfileID($aCommunicatorSettings['member_id']);
56  }
57 
72  function getRequests( $sTableName, &$aRequestTypes, $sAdditionalParam = null, $sAdditionalField = null )
73  {
75  $sAdditionalParam = process_db_input($sAdditionalParam);
76  $sAdditionalField = process_db_input($sAdditionalField);
77 
78  // ** init some needed variables ;
79  $aRequests = array();
80 
81  // init all sort criterias ;
82  $aSortCriterias = array
83  (
84  // sort all requests by 'date' ;
85  'date' => "`{$sTableName}`.`When` ASC",
86 
87  // sort all requests by 'author' ;
88  'author' => '`Profiles`.`NickName` ASC',
89 
90  // sort all requests by 'date' DESC;
91  'date_desc' => "`{$sTableName}`.`When` DESC",
92 
93  // sort all requests by 'author' DESC ;
94  'author_desc' => '`Profiles`.`NickName` DESC',
95  );
96 
97  // define the sort parameter ;
98  $sSortParameter = ( array_key_exists($this -> aCommunicatorSettings['sorting'], $aSortCriterias) )
99  ? $aSortCriterias[$this -> aCommunicatorSettings['sorting']]
100  : $aSortCriterias['date_desc'];
101 
102  // define the person mode ;
103  switch( $this -> aCommunicatorSettings['person_switcher'] ) {
104  case 'from' :
105  $sFieldName = '`ID`';
106  break;
107  case 'to' :
108  $sFieldName = '`Profile`';
109  break;
110  default :
111  $sFieldName = '`ID`';
112  }
113 
114  // count of all requests ;
115  $this -> iTotalRequestsCount = db_value
116  ("
117  SELECT
118  COUNT(*)
119  FROM
120  `{$sTableName}`
121  WHERE
122  `{$sTableName}`.{$sFieldName} = {$this -> aCommunicatorSettings['member_id']}
123  {$sAdditionalParam}
124  ");
125 
126  if ( $this -> iTotalRequestsCount ) {
127  // lang keys ;
128  $sRequestFrom = $GLOBALS['MySQL'] -> escape($aRequestTypes['from']);
129  $sRequestTo = $GLOBALS['MySQL'] -> escape($aRequestTypes['to']);
130 
131  // define number of maximum rows for per page ;
132  if( $this -> aCommunicatorSettings['page'] < 1 )
133  $this -> aCommunicatorSettings['page'] = 1;
134 
135  $sLimitFrom = ( $this -> aCommunicatorSettings['page'] - 1 ) * $this -> aCommunicatorSettings['per_page'];
136  $sSqlLimit = "LIMIT {$sLimitFrom}, {$this -> aCommunicatorSettings['per_page']}";
137 
138  // define the additional table's field ;
139  $sExtFieldName = ( $sAdditionalField ) ? ", `{$sTableName}`.`{$sAdditionalField}`" : null ;
140 
141  $sQuery =
142  "
143  SELECT
144  IF(`{$sTableName}`.`ID` = {$this -> aCommunicatorSettings['member_id']},
145  `{$sTableName}`.`Profile`, `{$sTableName}`.`ID`) AS `iMemberID`,
146 
147  IF(`{$sTableName}`.`ID` = {$this -> aCommunicatorSettings['member_id']}, $sRequestFrom, $sRequestTo)
148  AS `sType`,
149 
150  DATE_FORMAT(`{$sTableName}`.`When`, '" . getLocaleFormat(CH_WSB_LOCALE_DATE, CH_WSB_LOCALE_DB) . "') AS `sDate`
151  {$sExtFieldName}
152  FROM
153  `{$sTableName}`
154  LEFT JOIN
155  `Profiles`
156  ON
157  `Profiles`.`ID` = IF(`{$sTableName}`.`ID` = {$this -> aCommunicatorSettings['member_id']},
158  `{$sTableName}`.`Profile`, `{$sTableName}`.`ID`)
159  WHERE
160  `{$sTableName}`.{$sFieldName} = {$this -> aCommunicatorSettings['member_id']}
161  {$sAdditionalParam}
162  ORDER BY
163  {$sSortParameter}
164  {$sSqlLimit}
165  ";
166 
167  $rResult = db_res($sQuery);
168  while( true == ($aRow = $rResult->fetch()) ) {
169  $sExtType = ( !empty($aRequestTypes['specific_key']) and $sAdditionalField )
170  ? ' ' . _t( $aRequestTypes['specific_key'], $aRow[$sAdditionalField] )
171  : null ;
172 
173  $aRequests[] = array
174  (
175  'member_id' => $aRow['iMemberID'],
176  'date' => $aRow['sDate'],
177  'type' => $aRow['sType'] . $sExtType,
178  );
179  }
180  }
181 
182  return $aRequests;
183  }
184 
193  function execFunction( $sCallback, $sTableName, &$aMembersList, $aParameters = array() )
194  {
196 
197  $aCallback = array($this, $sCallback);
198  if ( is_callable($aCallback) and is_array($aMembersList) and !empty($aMembersList) ) {
199  foreach( $aMembersList AS $iMemberID ) {
200  if ( is_numeric($iMemberID) ) {
201  $aExtendedParameters = array_merge( array($sTableName), array( $iMemberID), $aParameters );
202  call_user_func_array($aCallback, $aExtendedParameters );
203  }
204  }
205  }
206  }
207 
216  function _deleteRequest( $sTableName, $iMemberID, $iFromOwner = 0, $iExtraDelete = 0 )
217  {
219  $iMemberID = (int) $iMemberID;
220  $iFromOwner = (int) $iFromOwner;
221  $iExtraDelete = (int) $iExtraDelete;
222 
223  // define the table's field ;
224  if ( !$iFromOwner ) {
225  $iID = $iMemberID;
226  $iProfile = $this -> aCommunicatorSettings['member_id'];
227  } else {
228  $iID = $this -> aCommunicatorSettings['member_id'];
229  $iProfile = $iMemberID;
230  }
231 
232  if ( $iExtraDelete ) {
233  $sQuery =
234  "
235  DELETE FROM
236  `{$sTableName}`
237  WHERE
238  (
239  `ID` = {$iMemberID}
240  AND
241  `Profile` = {$this -> aCommunicatorSettings['member_id']}
242  )
243  OR
244  (
245  `ID` = {$this -> aCommunicatorSettings['member_id']}
246  AND
247  `Profile` = {$iMemberID}
248  )
249  ";
250 
251  $res = db_res($sQuery);
252  } else {
253  $sQuery = "DELETE FROM `{$sTableName}` WHERE `ID` = {$iID} AND `Profile` = {$iProfile}";
254  $res = db_res($sQuery);
255  }
256 
257  $iRet = db_affected_rows($res);
258 
259  switch ($sTableName) {
260  case 'sys_friend_list':
261  $oZ = new ChWsbAlerts('friend', 'delete', $iID, $iProfile);
262  $oZ -> alert();
263  break;
264  case 'sys_fave_list':
265  $oZ = new ChWsbAlerts('fave', 'delete', $iID, $iProfile);
266  $oZ -> alert();
267  break;
268  case 'sys_block_list':
269  $oZ = new ChWsbAlerts('block', 'delete', $iID, $iProfile);
270  $oZ -> alert();
271  break;
272  }
273 
274  return $iRet;
275  }
276 
285  {
287  $iMemberID = (int) $iMemberID;
288 
289  $sQuery =
290  "
291  SELECT
292  `ID`
293  FROM
294  `{$sTableName}`
295  WHERE
296  `ID` = {$this -> aCommunicatorSettings['member_id']}
297  AND
298  `Profile` = {$iMemberID}
299  ";
300 
301  $res = null;
302  // if pair non-existent ;
303  if ( !db_value($sQuery) ) {
304  $sQuery =
305  "
306  INSERT INTO
307  `{$sTableName}`
308  SET
309  `ID` = {$this -> aCommunicatorSettings['member_id']},
310  `Profile` = {$iMemberID}
311  ";
312 
313  $res = db_res($sQuery);
314  }
315 
316  return db_affected_rows($res);
317  }
318 
326  {
328 
329  $iMemberID = (int)$iMemberID;
330  $iAccepted = (int)db_value("SELECT `Check` FROM `{$sTableName}` WHERE `ID`={$iMemberID} AND `Profile`={$this -> aCommunicatorSettings['member_id']} LIMIT 1");
331  if($iAccepted == 1)
332  return;
333 
334  db_res("UPDATE `{$sTableName}` SET `Check`=1 WHERE `ID`={$iMemberID} AND `Profile`={$this -> aCommunicatorSettings['member_id']}");
335 
336  //--- Friend -> Accept for Alerts Engine --//
337  $oZ = new ChWsbAlerts('friend', 'accept', $iMemberID, $this -> aCommunicatorSettings['member_id']);
338  $oZ -> alert();
339  //--- Friend -> Accept for Alerts Engine --//
340 
341  //--- Send email notification ---//
342  $oEmailTemplate = new ChWsbEmailTemplates();
343  $aTemplate = $oEmailTemplate->getTemplate('t_FriendRequestAccepted', $iMemberID);
344 
345  $aRecipient = getProfileInfo($iMemberID);
346  sendMail($aRecipient['Email'], $aTemplate['Subject'], $aTemplate['Body'], '', array(
347  'Recipient' => getNickName($aRecipient['ID']),
348  'SenderLink' => getProfileLink($this -> aCommunicatorSettings['member_id']),
349  'Sender' => getNickName($this -> aCommunicatorSettings['member_id']),
350  ));
351  //--- Send email notification ---//
352  }
353 
354  function _getJsObject()
355  {
356  return 'oCommunicatorPage' . str_replace(' ', '', ucwords(str_replace('_', ' ', $this->aCommunicatorSettings['communicator_mode'])));
357  }
358  }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
CH_WSB_LOCALE_DATE
const CH_WSB_LOCALE_DATE
Definition: utils.inc.php:16
$aMembersList
$aMembersList
Definition: communicator.php:22
$sLimitFrom
$sLimitFrom
Definition: post_mod_crss.php:49
ChWsbPageView
Definition: ChWsbPageView.php:99
ChWsbCommunicator
Definition: ChWsbCommunicator.php:13
ChWsbCommunicator\_getJsObject
_getJsObject()
Definition: ChWsbCommunicator.php:354
ChWsbEmailTemplates
Definition: ChWsbEmailTemplates.php:11
sendMail
sendMail( $sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID=0, $aPlus=array(), $sEmailFlag='html', $isDisableAlert=false, $bForceSend=false)
Definition: utils.inc.php:461
php
$oZ
$oZ
Definition: db.php:20
ChWsbCommunicator\_deleteRequest
_deleteRequest( $sTableName, $iMemberID, $iFromOwner=0, $iExtraDelete=0)
Definition: ChWsbCommunicator.php:216
ChWsbCommunicator\$aCommunicatorSettings
$aCommunicatorSettings
Definition: ChWsbCommunicator.php:18
null
Attr AllowedClasses this is null
Definition: Attr.AllowedClasses.txt:6
ChWsbPageView\$iMemberID
$iMemberID
Definition: ChWsbPageView.php:104
ChWsbCommunicator\__construct
__construct($aCommunicatorSettings)
Definition: ChWsbCommunicator.php:32
CH_SLASHES_NO_ACTION
const CH_SLASHES_NO_ACTION
Definition: utils.inc.php:30
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChWsbCommunicator\$iTotalRequestsCount
$iTotalRequestsCount
Definition: ChWsbCommunicator.php:15
and
and
Definition: license.txt:18
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
CH_TAGS_NO_ACTION
const CH_TAGS_NO_ACTION
Definition: utils.inc.php:21
ChWsbPageView\$sTableName
$sTableName
Definition: ChWsbPageView.php:109
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
db_affected_rows
db_affected_rows($oStmt=null)
Definition: db.inc.php:56
ChWsbCommunicator\execFunction
execFunction( $sCallback, $sTableName, &$aMembersList, $aParameters=array())
Definition: ChWsbCommunicator.php:193
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChWsbCommunicator\getRequests
getRequests( $sTableName, &$aRequestTypes, $sAdditionalParam=null, $sAdditionalField=null)
Definition: ChWsbCommunicator.php:72
CH_WSB_LOCALE_DB
const CH_WSB_LOCALE_DB
Definition: utils.inc.php:19
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
default
Attr AllowedFrameTargets _parent and _top Values should be as validation will be done in a case sensitive manner despite W3C s recommendation XHTML Strict does not permit the target attribute so this directive will have no effect in that doctype XHTML does not enable the Target module by default
Definition: Attr.AllowedFrameTargets.txt:10
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
getLocaleFormat
getLocaleFormat($iCode=CH_WSB_LOCALE_DATE_SHORT, $iType=CH_WSB_LOCALE_PHP)
Definition: utils.inc.php:89
ChWsbCommunicator\_acceptFriendInvite
_acceptFriendInvite($sTableName, $iMemberID)
Definition: ChWsbCommunicator.php:325
ChWsbCommunicator\_addRequest
_addRequest( $sTableName, $iMemberID)
Definition: ChWsbCommunicator.php:284
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$aParameters
$aParameters
Definition: index.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10