getProfilesMatch( $aProf1, $aProf2 ); //write to cache $sQuery = "INSERT INTO `ProfilesMatch` ( `PID1`, `PID2`, `Percent` ) VALUES ( $iPID1, $iPID2, $iMatch )"; db_res( $sQuery ); return $iMatch; } function clearProfileMatchCache( $iProfileID ) { $iProfileID = (int)$iProfileID; if( !$iProfileID ) return false; $sQuery = "DELETE FROM `ProfilesMatch` WHERE `PID1` = $iProfileID OR `PID2` = $iProfileID"; db_res( $sQuery ); } function cupid_email_cron() { $iMinCupLevel = (int)getParam('match_percent'); $sLastCupidCheckDate = getParam('cupid_last_cron'); if (!strlen($sLastCupidCheckDate)) return; $sLastCupidCheckDateParam = "(`DateReg`>='{$sLastCupidCheckDate}' OR `DateLastEdit`>='{$sLastCupidCheckDate}') AND"; $sSelectedSQL = "SELECT DISTINCT `Profiles`.`ID` FROM `Profiles` WHERE {$sLastCupidCheckDateParam} `Status`='Active'"; $vSelCupProf = db_res($sSelectedSQL); $aSelCupids = array(); while ($aSelCup = mysql_fetch_array($vSelCupProf)) { $aSelCupids[] = $aSelCup['ID']; } $sAllProfSQL = "SELECT DISTINCT `Profiles`.* FROM `Profiles` WHERE `Status`='Active' AND (`Couple`='0' OR `Couple`>`ID`)"; $vAllProf = db_res($sAllProfSQL); while ($aAnyProf = mysql_fetch_array($vAllProf)) { foreach ( $aSelCupids as $iSelCupID ) { $iCurMatch = getProfilesMatch( $aAnyProf['ID'], $iSelCupID ); if ( $iCurMatch >= $iMinCupLevel ) // If the profile matches less then predefined percent then go to next iteration (i.e. next profile) send_cupid_email($aAnyProf, $iSelCupID, $iCurMatch); } } $sUpdateCronValSQL = "UPDATE `GlParams` SET `VALUE`=NOW() WHERE `Name`='cupid_last_cron' LIMIT 1"; db_res($sUpdateCronValSQL); } function send_cupid_email( $aAnyProf, $iSelCupID) { global $site; $message = getParam( "t_CupidMail" ); $subject = getParam('t_CupidMail_subject'); $subject = addslashes($subject); $recipient = $aAnyProf['Email']; $headers = "From: {$site['title']} <{$site['email_notify']}>"; $headers2 = "-f{$site['email_notify']}"; $message = str_replace( "", $site['title'], $message ); $message = str_replace( "", $site['url'], $message ); $message = str_replace( "", $aAnyProf['NickName'], $message ); $message = str_replace( "", $aAnyProf['ID'], $message ); $message = str_replace( "", getProfileLink($iSelCupID), $message ); $message = addslashes($message); if ('Text' == $aAnyProf['EmailFlag']) { $message = html2txt($message); } if ('HTML' == $aAnyProf['EmailFlag']) { $headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8\r\n" . $headers; } $sql = "INSERT INTO `NotifyQueue` SET `Email` = {$aAnyProf['ID']}, Msg = 0, `From` = 'ProfilesMsgText', Creation = NOW(), MsgText = '$message', MsgSubj = '$subject'"; $res = db_res($sql); return true; }