Hi,

I am using a video script called Clipbucket and I am trying to build a function to send email to category subscribers instead of only user subscribers. So when a new video is uploaded in a category I subscribe to I get an e-mail. The user subscribe e-mail functionality works perfect.

In the file that handeles video convertion checks I call the mail functions as below:

function sendCategorySubscriptionEmail($vidDetails,$updateStatus=true)
{

global $cbemail,$db;
$v = $vidDetails;
if(!$v['videoid'])
{
e(lang("invalid_videoid"));
return false;
}

if(!$v['userid'])
{



e(lang("invalid_userid"));
return false;
}

//Lets get the list of subscribers
$subscribers = $this->get_user_cat_sub($v['userid'],false);

//Now lets get details of our uploader bhai saab
$uploader = $this->get_user_details($v['userid']);
//Loading subscription email template
$tpl = $cbemail->get_template('video_categoey_subscription_email');

$total_subscribers = count($subscribers);
if($subscribers)
foreach($subscribers as $subscriber)
{
$var = $this->custom_subscription_email_vars;

$more_var = array
('{username}' => $subscriber['username'],
'{uploader}' => 'Subscribe Category',
'{video_title}' => $v['title'],
'{video_description}' => $v['description'],
'{video_link}' => cblink(['name'=>'category','data'=>$v,'type'=>'videos']),
'{video_thumb}' => get_thumb ($v),
'{cat_thumb}' => $this->get_cat_thumb_1($v, 'video'),
);
if(!is_array($var))
$var = array();
$var = array_merge($more_var,$var);
$subj = $cbemail->replace($tpl['email_template_subject'],$var);
$msg = nl2br($cbemail->replace($tpl['email_template'],$var));

//Now Finally Sending Email
cbmail(array('to'=>$subscriber['email'],'from'=>WELCOME_EMAIL,'subject'=>$subj,'content'=>$msg));

}

if($total_subscribers)
{
//Updating video subscription email status to sent
if($updateStatus)
$db->update(tbl('video'),array('subscription_email'),array('sent')," videoid='".$v['videoid']."'");
$s = "";
if($total_subscribers>1)
$s = "s";
e(sprintf(lang('subs_email_sent_to_users'),$total_subscribers,$s),"m");
return true;
}

e(lang("no_user_subscribed_to_uploader"));

return true;
}

get_user_cat_sub

function get_user_cat_sub($id,$limit=NULL)
{
global $db;

$result = $db->select(tbl("users,".$this->dbtbl['subtbl']),"*"," ".tbl("cat_subscribe.category_id")." = '$id' AND ".tbl("cat_subscribe.user_id")."=".tbl("users.userid"),$limit);

if($db->num_rows>0)
return $result;
else
return false;
}


get_user_details

function get_user_details_with_profile($uid=NULL)
{
global $db;
if(!$uid)
$uid = userid();
$result = $db->select(tbl($this->dbtbl['users'].",".$this->dbtbl['user_profile']),"*",tbl($this->dbtbl['users']).".userid ='$uid' AND ".tbl($this->dbtbl['users']).".userid = ".tbl($this->dbtbl['user_profile']).".userid");
return $result[0];
}


get_template

Work in user subscription so no problem here!


I am new to PHP and is trying to understand with my limited knowledge. Anyone who would like to have a go on this to help me solve it?