Skip to Content Skip to Menu

uddeIM and message per user limit with CB Subs

  • Digigreg
  • Digigreg
  • OFFLINE
  • Posts: 38
  • Thanks: 8
  • Karma: 0
4 years 6 months ago #318301 by Digigreg
Replied by Digigreg on topic uddeIM and message per user limit with CB Subs
Rob I have found some code in a text note. Is that I have used to patch the file. Of course is raw and not enough, you must configure CB for this purpose.
But it may helps you, somehow.

Good luck ;)
Gregorio

Code:
// digigreg // includes.php // row 2017 // get user id $dg_id = $config->userid; // get database $database = uddeIMgetDatabase(); // get user subscription type $sql="SELECT `cb_subscriptiontype FROM `#__comprofiler` WHERE `user_id` = ".$dg_id; $database->setQuery($sql); $dg_subscription = $database->loadResult(); // get the total number of messages sent from the user from last midnight $sql="SELECT count(*) FROM `#__uddeim` WHERE #__uddeim.fromid = ".$dg_id." AND #__uddeim.timestamp >= CURDATE()"; $database->setQuery($sql); $sent_messages_in_last_day = $database->loadResult(); // deny sentence $block_sentence = JText::_("DG_MESSAGES_LIMIT_REACHED"); if ((($dg_subscription == 'FREE') && ($sent_messages_in_last_day >= 10)) || (($dg_subscription == 'SILVER') && ($sent_messages_in_last_day >= 50))) { echo $block_sentence; } else { echo "<div class='uddeim-sendbutton'>"; echo "<input type='submit' name='reply' class='button' value='"._UDDEIM_SUBMIT."' /> "; echo "</div>"; }
The following user(s) said Thank You: RobJob

Please Log in or Create an account to join the conversation.

  • RobJob
  • RobJob
  • OFFLINE
  • Posts: 5
  • Thanks: 1
  • Karma: 0
4 years 6 months ago #318303 by RobJob
Gregorio,

Questo è impressionante! Grazie mille!

That is going to save me a few hours, you're very kind.

Saluti

Please Log in or Create an account to join the conversation.

  • Digigreg
  • Digigreg
  • OFFLINE
  • Posts: 38
  • Thanks: 8
  • Karma: 0
4 years 6 months ago #318304 by Digigreg
Replied by Digigreg on topic uddeIM and message per user limit with CB Subs
Hopefully it's the half way done.

Buon lavoro,
saluti ;)
Gregorio
The following user(s) said Thank You: RobJob

Please Log in or Create an account to join the conversation.

  • RobJob
  • RobJob
  • OFFLINE
  • Posts: 5
  • Thanks: 1
  • Karma: 0
4 years 6 months ago #318306 by RobJob
Got it working with a few changes to the script, I've had to put in a check to remove from the count where messages are copied to the sender and format the unix date time in the datum column

$sql="SELECT count(*) FROM `#__uddeim`
WHERE #__uddeim.fromid = ".$dg_id."
AND DATE_FORMAT(FROM_UNIXTIME(#__uddeim.datum), \"%Y-%m-%d\") >= CURDATE()
AND #__uddeim.fromid != #__uddeim.toid";

I owe you a beer!
The following user(s) said Thank You: Digigreg

Please Log in or Create an account to join the conversation.

  • Digigreg
  • Digigreg
  • OFFLINE
  • Posts: 38
  • Thanks: 8
  • Karma: 0
4 years 6 months ago #318308 by Digigreg
Replied by Digigreg on topic uddeIM and message per user limit with CB Subs
Happy that it works. For you and for who will need in the future.
I have used uddeIM bridged to an iOS and Android app as well. And my client needed to limit number of messages sent by free accounts, so users can subscribe to the premium account. Of course if uddeIM get an update, that file will be overwrite, so the patch should be applied again.
Well done Rob, sound's good.

If you wonder to visit Tuscany... Write me a word, beer is welcome every time :D

Please Log in or Create an account to join the conversation.

  • RobJob
  • RobJob
  • OFFLINE
  • Posts: 5
  • Thanks: 1
  • Karma: 0
4 years 6 months ago #318311 by RobJob
Will do for sure..

Thought I'd share this in case anyone else was wanting something similar..

This is my finished code which is working.. I've the set the limits in the script rather than a DB look up which I know is not good but for now it is working.

// ================================== SEND BUTTON ==============================

// get user id
$dg_id = $config->userid;

// get database
$database = uddeIMgetDatabase();

// get user subscription type
$sql="SELECT #__osmembership_subscribers.plan_id FROM `#__osmembership_subscribers` WHERE `user_id` = ".$dg_id;
$database->setQuery($sql);
$dg_subscription = $database->loadResult();

//SET allowance

if($dg_subscription == 2); {
$msgallowance = 10; {
if($dg_subscription == 3);{
$msgallowance = 30;
{
if($dg_subscription == 4) {
$msgallowance = 500;
}
}
}
}
}

// get the total number of messages sent from the user from last midnight
$sql="SELECT count(*) FROM `#__uddeim` WHERE #__uddeim.fromid = ".$dg_id." AND DATE_FORMAT(FROM_UNIXTIME(#__uddeim.datum), \"%Y-%m-%d\") >= CURDATE() AND #__uddeim.fromid != #__uddeim.toid";
$database->setQuery($sql);
$sent_messages_in_last_day = $database->loadResult();

// Check messages sent against allowance and show send button if not exceeded

if($sent_messages_in_last_day < $msgallowance) {
echo "<input type='submit' name='reply' class='button' value='" . _UDDEIM_SUBMIT . "' /> ";}
// Hide send button and return error if allowance reached.
else
{
echo "You have exceeded your message limit for the day";
}

// Show real time count of messages sent and remaining allowance for user

echo "<br></br>You have sent ", $sent_messages_in_last_day , " messages today, you have ", $msgallowance - $sent_messages_in_last_day, " messages remaining";
echo "</div>";
echo "</form>\n";
echo "</div>\n"; // end of uddeim-writeform
}

Please Log in or Create an account to join the conversation.

Moderators: beatnantslabbikrileon
Powered by Kunena Forum