".loginid(); $qry = db_first($sql); if($qry) { $bpousername_isavailable_check[$un] = false; // return false; } //do a lookup against their server to see if TMF thinks it is available $result = bpo_api('checkusername',array(username=>$un)); if(trim($result) != "available") { d(bpo_api,$result); $bpousername_isavailable_check[$un] = false; return false; } $bpousername_isavailable_check[$un] = true; return true; } function get_bpoapidata($username,$companyid=0){ if (!$companyid) $companyid=compnayid(); $sql = "select companyaddonpaidthru,companyaddonserialized from tblcompanyaddon where addonid=5 and companyid=". db_number($companyid); $result = db_query($sql); } /** * @name bpo_updateuser * @param [string|array] $username * @param [array] $extra * @uses functions_core.php */ function bpo_updateuser($username,$extra=array()){ if (!is_array($username) && !$username){ if (is_developer()) ddie("BPO: No username!"); return false; } if (!is_array($username)){ if (!$extra){ $extra = get_bpoapidata($username); } $username[$username]=$extra; } return false; //default error state } /** * @name bpo_api * @param unknown $request * @param unknown $dataarr * @return boolean * @uses functions_general.php */ function bpo_api($request,$dataarr) { if(is_bpoinactive()) return false; $ch = curl_init(); $addurl=""; if (is_array($dataarr) && !empty($dataarr)) foreach($dataarr as $fld=>$val){ if ($fld == 'companyaddonpaidthru') $addurl .= "&$fld=" . urlencode(dttime_format($val)); else $addurl.="&$fld=".urlencode($val); } $url = "https://www.trackmyforeclosures.com/rio_api.php?request=$request$addurl"; if($_GET[debug]) { d('bpo_api.NOTRUN.DEBUG',"$_SERVER[REMOTE_ADDR]|$url"); return false; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Set timeout to 10 sec //curl_setopt($ch, CURLOPT_USERPWD, "matraex:zipdisk"); //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //curl_setopt($ch, CURLINFO_HEADER_OUT, true); // DEBUG d("bpo_api url: ".$url); $tmp = curl_exec($ch); // $headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT ); //DEBUG INFO curl_close ($ch); //d(headers,$headerSent); //d(url,$url); dlog(bpo_api,"$_SERVER[REMOTE_ADDR]|$url|$tmp"); if (strstr($tmp,"on line")) { $devmsg = "
TMF Server has reported an error in script on their side.
Our Client needs to be notified that we are experiencing problems with TMF, so TMF can fix it.
When contacting client please include request info and response. See MTX19564 for sample."; $devmsg .="
additional info:
Time: " . date("m/d/Y H:i:s",time()) . "
Request: " . $url; $devmsg .="
TMF Response:
--------------------------------------------------
" . htmlentities($tmp) . "
----------------------------------------------------"; developer_error ("BPOAPI TMF ERROR: see MTX19564 for more info.",$devmsg); } return trim($tmp); } /** * @name bpo_chunameandpasswd * @param [string] $username * @param [string] $password * @return [mixed] true if ok err msg if err */ function bpo_chunameandpasswd ($username,$password){ //if (end(explode("_",$username)) !='bpo') // return false; // username must end with _bpo if (!$password) return false; // we need password $request ='changepassword&username='.$username.'&password='.$password; $result = bpo_api($request,""); if ($result === TRUE) return true; else return $result; } /** * @name bpo_de_activate * @param [string] $username * @param [integer] $activate if is not set it will DEactivate account * @return [mixed] true id ok err msg if err */ function bpo_de_activate($username,$activate=0,$bpoarr=array()){ if (!$username) developer_error("NO BPO Username"); //if (end(explode("_",$username))!='bpo') // return false; if ($activate ==1) $request = 'turnon_user&username='.$username; else $request = 'shutoff_user&username='.$username; $result = bpo_api($request,(is_array($bpoarr)? $bpoarr : '' )); if ($result === TRUE) return true; else return $result; } /** * @name bpo_activate_company * @param [integer] $companyid * @param [integer] $deactivate * @todo Implement deactivate function */ function bpo_activate_company($companyid,$deactivate=0){ if(!db_number($companyid)) return; $bposql = "select loginid,loginusername,loginpassword,loginbpousername,loginbpopassword from tbllogin where companyid = ".db_number($companyid); if (!$deactivate) $bposql .=" and logininactive is null"; $bpoqry = db_query($bposql); if (is_array($bpoqry) && !empty($bpoqry)){ if (!$deactivate) bpo_activateallinarray($bpoqry); else bpo_deactivateallinarray($bpoqry); } return true; } /** * @name bpo_activateallinarray * * This function will send email if there were problems activating any of the accounts. * @param [array] $bpoarray */ function bpo_activateallinarray($bpoqry,$bpoarr=array()){ d(bpo_activateallinarray, $bpoqry); if (is_array($bpoqry) && !empty($bpoqry)){ foreach ($bpoqry as $bpokey=>$bpoval){ $bpousername = $bpoval[loginbpousername]; $bpo_result = bpo_de_activate($bpousername,1,$bpoarr); if ($bpo_result === TRUE || $bpo_result ='true') $bpo_activate [$bpoval[loginid]] = $bpoval[loginid]; else{ $bpo_error[$bpoval[loginid]][error] = $bpo_result; $bpo_error[$bpoval[loginid]][bpousername] = $bpousername; $bpo_error[$bpoval[loginid]][loginusername] = $bpoval[loginusername]; } } if (is_array($bpo_activate) && !empty($bpo_activate)){ db_exec("update tbllogin set loginbpodisableddate = null where loginid in (".implode(",",$bpo_activate).")"); } if (is_array($bpo_error) && $bpo_error){ ob_start(); echo "


BPO AUTOMATION HAS FAILED TO ACTIVATE FOLLOWING ACCOUNTS:
"; foreach ($bpo_error as $bpoekey => $bpoeval){ echo "
Loginid: ".$bpoekey; echo "
Loginusername: ".$bpoeval[loginusername]; echo "
BPO username: ".$bpoeval[bpousername]; echo "
BPO API Error: ".$bpoeval[error]; echo "

"; } d(bpoqry,$bpoqry); d(bpoerr,$bpo_error); $body = ob_get_clean(); $subject = "BPO Activaton ERRORS"; mail ("helpdesk-support@matraex.com",$subject." ".$_SERVER[SCRIPT_NAME],$body,"From: "); } } 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; }