");
}
}
return true;
}
/**
* @name bpo_deactivateallinarray
*
* This function will send email if there were problems deactivating any of the accounts.
* @param [array] $bpoarray
*/
function bpo_deactivateallinarray($bpoqry){
d(bpo_deactivateallinarray, $bpoqry);
if (is_array($bpoqry) && !empty($bpoqry)){
foreach ($bpoqry as $bpokey=>$bpoval){
d(bpoval,$bpoval);
$bpousername = $bpoval[loginbpousername];
$bpo_result = bpo_de_activate($bpousername,0);
if ($bpo_result === TRUE || $bpo_result ='true')
$bpo_deactivate[$bpoval[loginid]] = $bpoval[loginid];
else{
$bpo_error[$bpoval[loginid]][error] = $bpo_result;
$bpo_error[$bpoval[loginid]][bpousername] = $bpousername;
$bpo_deactivate[$bpoval[loginid]] = $bpoval[loginid];
}
}
if (is_array($bpo_deactivate) && !empty($bpo_deactivate)){
db_exec("update tbllogin set loginbpodisableddate = now() where loginid in (".implode(",",$bpo_deactivate).")");
ob_start();
echo "
BPO API HAS DISABLED FOLLOWING ACCOUNTS:
|
";
echo " BPO Disable function in ".$_SERVER[SCRIPT_NAME]." has disabled following accounts.
Reason for disabling: BPO Addon has expired.";
foreach ($bpoqry as $bpokey=>$bpovalue){
foreach ($bpo_deactivate as $bpoekey => $bpookval){
if ($bpookval[bpousername] == $bpovalue[loginbpousername]){
//echo "
Loginid: ".$bpoeval[loginid];
echo "
RIO username: ".$bpovalue[loginusername];
echo "
BPO username: ".$bpovalue[loginbpousername];
echo "
";
}
}
}
d(bpoqry,$bpoqry);
d(bpoerr,$bpo_deactivate);
$body = ob_get_clean();
$subject = "BPO Deactivation/Activation Report";
}
if (is_array($bpo_error) && !empty($bpo_error)){
ob_start();
echo "
BPO DISABLE HAS FAILED TO DISABLE FOLLOWING ACCOUNTS:
|
";
echo " BPO Disable function in ".$_SERVER[SCRIPT_NAME]." has failed to disable following accounts.
Reason for disabling: BPO Addon has expired.";
foreach ($bpoqry as $bpokey=>$bpovalue){
foreach ($bpo_error as $bpoekey => $bpoeval){
if ($bpoeval[bpousername] == $bpovalue[loginbpousername]){
//echo "
Loginid: ".$bpoeval[loginid];
echo "
RIO username: ".$bpovalue[loginusername];
echo "
BPO username: ".$bpovalue[loginbpousername];
echo "
BPO API Error: ".$bpoeval[error];
echo "
";
}
}
}
d(bpoqry,$bpoqry);
d(bpoerr,$bpo_error);
$body = ob_get_clean();
//$subject = "BPO CANCELATION ERRORS";
mail ("helpdesk-support@matraex.com",$subject." ".$_SERVER[SCRIPT_NAME],$body,"From: ");
}
}
return true;
}
function runbpo ($companyid=0,$bpoarr=array()){
if(is_bpoinactive())
return false;
// BPO Deactivation
if(is_developer())
{
if(!isset($_GET[debug]))
$_GET[debug]=1;
if($_GET[debug])
d("_GET[debug] is '$_GET[debug]', to turn off debug set \$_GET[debug]=0");
else
d("_GET[debug] is '$_GET[debug]', to turn on debug set \$_GET[debug]=1");
}
$bposql = "select loginid,loginusername,loginpassword,loginbpousername,loginbpopassword from tbllogin where companyid in (
select companyid from tbladdon
join tblcompanyaddon using (addonid)
join tblcompany using(companyid)
left join tbladdonsubpackage using(addonsubpackageid)
where 0=0
and (coalesce(companyaddonpaidthru, companypaidthru) < now() - interval '1 days')
and addonisolatedbilling = 1
and companydemo = 0
and addonshortname = 'bpo'
and loginbpodisableddate is null
and loginbpousername is not null
and coalesce(companyaddonlastbillingattemptdate ,'01/01/2001')::date <> now()::date";
if ($companyid)
$bposql .=" and companyid = ".db_number($companyid);
$bposql .=" order by companyaddonpaidthru)";
d(bposql,htmlpre($bposql));
$bpoqry = db_query($bposql);
if ($bpoqry)
bpo_deactivateallinarray($bpoqry);
// Now we make sure that all than need to be active are actually active
$bposql = "select loginid,loginusername,loginpassword,loginbpousername,loginbpopassword from tbllogin where companyid in (
select companyid from tbladdon
join tblcompanyaddon using (addonid)
join tblcompany using(companyid)
join tbladdonsubpackage using(addonsubpackageid)
where 0=0
and (companyaddonpaidthru > now())
and addonisolatedbilling = 1
and companydemo = 0
and addonshortname = 'bpo'
and loginbpodisableddate is not null
and loginbpousername is not null
and coalesce(companyaddonlastbillingattemptdate ,'01/01/2001')::date <> now()::date";
if ($companyid)
$bposql .=" and companyid = ".db_number($companyid);
$bposql.=" order by companyaddonpaidthru)
and logininactive is null";
d(bposql,htmlpre($bposql));
$bpoqry = db_query($bposql);
if ($bpoqry)
bpo_activateallinarray($bpoqry,$bpoarr);
return true;
}
function is_bpoinactive()
{
return true;
}