gpc('p');
if($bAdd) {
if(!$strUrl || !$strTitle || !$strCid || !$strEmail)
{
$strWarning = "Please fill all required fields (marked by star)";
}
if($strUrl)
{
if(!preg_match("%^http://%is", $strUrl))
$strUrl = "http://".$strUrl;
$arrUrl = parse_url($strUrl);
$arrUrl['host'] = str_replace("www.", "", $arrUrl['host']);
$strQuery = "select *, p.nId as nId, if(p.bIsOurSite, 'yes', 'no') as strIsOurSite, c.strName as strName from partners p, categories c where p.strCid=c.nId And p.strUrl like '%".addslashes($arrUrl['host'])."%'";
$hRes = $oSql->query($strQuery);
if($bParnerExists = $hRes->numRows()) {
list($nExistingPartnerId, $bIsExistingPartnerOurs, $strExistingPartnerName) = $hRes->fetchRow();
}
}
if($strUrl && !$arrSids)
{
$strWarning = "Please apply to some of our sites to exchange links.";
}
if($strUrl && $arrSids)
{
$strQuery = "SELECT strValue FROM settings WHERE nId=5"; /*4- Id of a setting, that shows if we need to look for our links on partner page before adding him */
$hRes = $oSql->query($strQuery);
$bLookForLinks = $hRes->fetchHash();
$bLookForLinks = $bLookForLinks['strValue'];
if ($bLookForLinks)
{
$strQuery = "select strUrl FROM sites ORDER BY nId";
$hRes = $oSql->query($strQuery);
$k=1;
while($arrSite = $hRes->fetchRow())
{
$arrSites[$k] = $arrSite[0];
$k++;
}
}
reset($arrSids);
while(list($nSid, $val) = each($arrSids))
{
if(!$arrRecipUrls[$nSid] || $arrRecipUrls[$nSid] == "http://")
{
$strWarning = "Please specify URLs where you placed links to our sites which you have selected. URLs must start with http://";
break;
}
if ($bLookForLinks)
{
$strLookResult = lookForLink($arrSites[$nSid],$arrRecipUrls[$nSid]);
if ($strLookResult)
{
$strWarning = "We cannot add your site, since:
$strLookResult Page: $arrRecipUrls[$nSid]
Link: $arrSites[$nSid]";
break;
}
}
}
}
if(!$strWarning) //check if host names of all link pages and Url host was the same
{
$arrAllUrls = array('url' => $strUrl);
reset($arrSids);
while(list($nSid, $val) = each($arrSids))//makes array of main url and all link pages
{
$arrAllUrls = array_merge(array($nSid => $arrRecipUrls[$nSid]), $arrAllUrls);
}
if (!checkHostCorrespondence ( $arrAllUrls ) )//checks for host names corresponding
{
$strWarning = "The host of your Url and Link page should be the same";
}
}
if(!$strWarning)
{
$oVarset->quote();
if($bParnerExists) {
$nPid = $nExistingPartnerId;
$oSql->query("update partners set ".$oVarset->joinSqlUpdate()." where nId = $nExistingPartnerId");
$hRes = $oSql->query("select r.nId as nRelationId, s.nId as nSiteId from sites s, relations r where
r.nSid = s.nId and r.nPid = $nPid and r.nValidation !=2");
while(list($nRelationId, $nSiteId) = $hRes->fetchRow()) {
if($arrSids[$nSiteId] == "on") {
$strRecipUrl = $oSql->quote($arrRecipUrls[$nSiteId]);
$oSql->query("update relations set
strRecipUrl = $strRecipUrl,
nValidation = 1
where nId = $nRelationId");
}
}
$strReport = "Your site information and link exchange preferences were updated.
We would review your application and add your link to our site(s)";
$strMessage = "Old link partner applied new links.\n";
$strMessage .= "URL = $strUrl\n\n";
$strMessage .= "Click here to view this partners options in the \"partners who have only \"applied\" relations\" section of the linker.";
@mail("edvard@fda-phentermine.com", "Old Link Partner - $strEmail", $strMessage , "From: \"Linker\"\nContent-type: text/html");
} else {
$oSql->query("insert into partners ".$oVarset->joinSqlInsert());
$nPid = $oSql->insertId();
$oSql->query("update partners set strDateAdded = NOW() where nId = $nPid");
$hRes = $oSql->query("select * from sites");
while($hashRow = $hRes->fetchHash()) {
$oSql->query("insert into relations (nSid, nPid, strRecipUrl, nValidation) values (".$hashRow['nId'].", $nPid, '".($arrSids[$hashRow['nId']] == "on" ? addslashes($arrRecipUrls[$hashRow['nId']]) : "")."', ".($arrSids[$hashRow['nId']] == "on" ? "1" : "0").") ");
}
$strReport = "Your site have been applied for link partnership. We would review your application and add your link to our site(s)";
$strMessage = "New link partner applied.\n";
$strMessage .= "URL = $strUrl\n\n";
$strMessage .= "Click here to view this partners options in the \"partners who have only \"applied\" relations\" section of the linker.";
#@mail(setting(3), "New Link Partner Application", $strMessage , "From: \"Linker\"\nContent-type: text/html\nX-Mailer: PHP/" . phpversion());
#@mail(setting(3), "New Link Partner - $strEmail", $strMessage , "From: \"Linker\"\nContent-type: text/html\nX-Mailer: PHP/" . phpversion());
@mail("edvard@fda-phentermine.com", "New Link Partner - $strEmail", $strMessage , "From: \"Linker\"\nContent-type: text/html\nX-Mailer: PHP/" . phpversion());
}
}
}
$oPage->load("html/application.html");
$strCatOptions = getOptionsByQuery("select nId, strName from categories order by strName", $strCid);
$oPage->add('partner', array('strCid' => $strCatOptions, 'strUrl' => htmlspecialchars(unslash($strUrl)), 'strTitle' => htmlspecialchars(unslash($strTitle)), 'strDescription' => htmlspecialchars(unslash($strDescription)), 'strEmail' => htmlspecialchars(unslash($strEmail)), 'strName' => htmlspecialchars(unslash($strName)), 'strExtraInfo' => htmlspecialchars(unslash($strExtraInfo))));
$hRes = $oSql->query("select * from sites");
while($hashRow = $hRes->fetchHash()) {
list($hashRow['strTitle'], $hashRow['strDescription']) = getAltInfo($hashRow['nId']);
$hashRow['is_checked'] = $arrSids[$hashRow[nId]] == 'on' ? "checked" : '';
$hashRow['strRecipUrl'] = $arrRecipUrls[$hashRow[nId]] ? htmlspecialchars(unslash($arrRecipUrls[$hashRow[nId]])) : "http://";
$oPage->add('site', $hashRow);
$oPage->add('js', $hashRow);
}
if(!$strWarning)
$oPage->kill('warning');
else
$oPage->add('warning', array('strWarning' => $strWarning));
if(!$strReport)
$oPage->kill('report');
else
$oPage->add('report', array('strReport' => $strReport));
print $oPage->render();
// this function cyclically picks up title and description for partner's site from partner_alternative_site_info
function getAltInfo($nSiteId) {
$oSql =& getGlobalObject('SqlConnection');
$hRes = $oSql->query("select count(*) from alternative_site_info where nSiteId = $nSiteId");
list($nAltInfo) = $hRes->fetchRow();
if(rand()/getrandmax() > 1 / ($nAltInfo + 1)) {
$hRes = $oSql->query("select strTitle, strDescription from alternative_site_info where nSiteId = $nSiteId order by rand() limit 1");
} else {
$hRes = $oSql->query("select strTitle, strDescription from sites where nId = $nSiteId");
}
return $hRes->fetchRow();
}
?>