<?php

/*
** Maintained by Moshe Weitzman (weitzman@tejasa.com)
*/

function delphi_link($type) {
    if ($type == "auth_help") {
    $links[] = "<a href=\"module.php?mod=delphi\">". t("Delphi Forums") ."</a>";
    }

  return $links ? $links : array();
}

function delphi_auth($username, $password, $server, $port = 80) {
   global $delphi;  
   $authURL = "http://$server/authservice/remoteAuthSvc.asmx/PwdCheck?userName=$username&pwd=$password";
   $fp = @fopen($authURL,"r"); 
    if($fp){ 
       $reply = fread($fp,9999);
       fclose($fp);
       // echo $reply."<br/>";        
       if(ereg("true", $reply)) {
         // watchdog("user", "Successful Delphi Authentication");
         return 1;
       }
       else { 
         // watchdog("error", "Failed Delphi Authentication: ". $reply);
         return 0; 
       }
    }   
    else { 
       // watchdog("error", "Could not connect to Delphi Authentication server: $server");
       return 0;
    }   
}

function delphi_form($edit = array()) {

  $form .= form_textfield("Site name", "name", $edit["name"], 50, 128, "The name of the website you want to monitor for updates.");
  $form .= form_textfield("Site URL", "link", $edit["link"], 50, 255, "The URL of the website you want to monitor for updates.");
  $form .= form_textfield("URL to monitor", "feed", $edit["feed"], 50, 255, "The URL of the page you want to monitor for updates.  Likely to be same as the site's URL but useful to monitor framed pages and more accurate when pointed to a XML/RSS/RDF feed.");

  $form .= form_submit("Submit");

  if ($edit["sid"]) {
    $form .= form_submit("Delete");
    $form .= form_hidden("sid", $edit["sid"]);
  }

  return form($form);
}

function delphi_page() {
  global $theme;
  $theme->header();
  $theme->box(t("Delphi Forums"), delphi_auth_help());
  $theme->footer();
}

function delphi_auth_help() {
$site = variable_get("site_name","this web site");
$html_output = <<<EOF
<p><a href="http://www.delphiforums.com">Delphi Forums</a> is the premier destination 
  for those looking to create or participate in online communities. You may already 
  have participated in one the <a href="http://forums.delphiforums.com/dir-app/search/forumbrowse.asp?webtag=mainconf&swebtag=delphicomz">100,000 
  active Delphi forums</a>. If so, you already have a <b>Delphi ID</b> and can login to <i>$site</i>
  using your Delphi Membername and password. Just add @remote.prospero.com to your membername
  and you'll be able to register or login to $site. An example of valid Delphi ID   is <b>mwlily@remote.delphi.com</b>.</p>
  <p>Millions of individuals participate in Forums on Delphi. They   come from all walks of life, represent every interest under the sun, and bring 
  incredible expertise and passion to the Delphi Forums online communities. The interaction 
  within Forums creates a vast and valuable resource of content for anyone seeking 
  information, advice, or friendship.</p>
EOF;
return $html_output;
}

?>