/**
 * entry function, gathers information
 */
function enter($frm)
{
    $trhconf = getTrhConfig();
    if ($trhconf["MANAGEUSER"] <= 0) {
        r2sListSet("trh_comminit");
        header("Location: configuration.php");
        exit;
    }
    if (isset($_REQUEST["suppid"])) {
        $sc_desc = "Supplier";
        $sc_fld = "suppid";
    } else {
        $sc_desc = "Customer";
        $sc_fld = "custid";
    }
    $frm->setkey("confirm");
    $frm->settitle("Initialize Transheks Communications");
    $frm->add_heading("{$sc_desc} Information");
    $frm->add_hidden($sc_fld, $_REQUEST[$sc_fld], "int");
    $frm->add_text("{$sc_desc} Transheks Email Address", "email", "", "email", "1:255");
    $OUT = $frm->getfrm_input();
    return $OUT;
}
/**
 * sends a trh message.
 *
 * if you dont pass the trh config variable, it will be fetched automatically.
 *
 * @param string $who must be "supp" or "cust", what other side is too me
 * @param int $id customer/supplier id
 * @param string $msgtype 6 character message type
 * @param string $data what to send
 * @param array $config optionally the companies trh configuration
 * @return bool
 */
function send_trhmsg($who, $id, $email, $msgtype, $data, $config = false)
{
    if (defined("CONSOLE")) {
        print "sending response:\n";
        print "\twho: {$who}\n";
        print "\tid: {$id}\n";
        print "\tmsgtype: {$msgtype}\n";
        print "\tdata: {$data}\n";
    }
    require_lib("mail.smtp");
    require_lib("mail.msg");
    /* configuration */
    if ($config === false) {
        $config = getTrhConfig();
    }
    extract($config);
    /* determines new message parameters */
    $subject = "trh_{$msgtype}";
    $body = array();
    $attachments = array();
    $headers = array();
    $compinfo = qryCompInfo();
    /* determine my ip address */
    if (empty($_SERVER["SERVER_NAME"])) {
        $myipaddr = "0.0.0.0";
    } else {
        $myipaddr = gethostbyname($_SERVER['SERVER_NAME']);
    }
    /* determine key request function */
    if ($who == "supp") {
        $keyFunc = "trhKeySupp";
    } else {
        $keyFunc = "trhKeyCust";
    }
    /* standard message body details */
    $body[] = "compname: {$compinfo['compname']}";
    $body[] = "ipaddr: {$myipaddr}";
    $body[] = "bustel: {$compinfo['tel']}";
    $body[] = "fromwho: " . ($who == "supp" ? "cust" : "supp");
    $body[] = "email: {$SMTP_FROM}";
    switch ($msgtype) {
        /* request a new key */
        case "reqkey":
            $subject .= " {$data}";
            break;
            /* respond to a newly requested key */
        /* respond to a newly requested key */
        case "rspkey":
            /* get my key from this guy */
            $qry = new dbSelect("keys", "trh", grp(m("cols", "(key).send_key AS mykey"), m("where", "{$who}id='{$id}'")));
            $qry->run();
            if ($qry->num_rows() <= 0) {
                return false;
            }
            $d = $qry->fetch_array();
            $mykey = $d["mykey"];
            $subject .= " {$data}";
            $body[] = "mykey: {$mykey}";
            break;
            /* requests a new purchase */
        /* requests a new purchase */
        case "reqpur":
            $keys = $keyFunc($id, "recv_key, send_key");
            $subject .= " {$keys['send_key']}";
            $body[] = "yourkey: {$keys['recv_key']}";
            $attachments["data.xml"] = $data;
            break;
            /* responds to a new purchase request */
        /* responds to a new purchase request */
        case "rsppur":
            $keys = $keyFunc($id, "recv_key, send_key");
            $subject .= " {$keys['send_key']}";
            $body[] = "yourkey: {$keys['recv_key']}";
            $body[] = "purid: {$data['purid']}";
            $body[] = "status: {$data['status']}";
            break;
    }
    /* create new mail message */
    $msg = new clsMailMsg();
    $msg->newMessage($SMTP_FROM, $SMTP_FROM, $subject, implode("\n", $body), $headers, true);
    if (count($attachments)) {
        foreach ($attachments as $fname => $contents) {
            $msg->addAttachment("text/plain", $fname, $data);
        }
    }
    $smtp = new clsSMTPMail();
    $ret = $smtp->sendMessages($SMTP_SERVER, 25, !empty($SMTP_USER), $SMTP_USER, $SMTP_PASS, $email, $msg->getNewMessage());
    if ($smtp->bool_success !== true) {
        return $ret;
    }
    return true;
}
Esempio n. 3
0
$smallest_wait = -1;
$ctr = 0;
while (true) {
    $companies = array();
    /* fetch the company list */
    if ($ctr == 0) {
        db_con("cubit");
        $sql = "SELECT c.code FROM companies c WHERE (true) {$wh}";
        $comps = new dbSql($sql);
        $comps->run();
        $companies = array();
        while ($row = $comps->fetch_array()) {
            /* read the companies configuration */
            print "Company Read: {$row['code']}\n";
            db_con("cubit_{$row['code']}");
            $cfg = getTrhConfig();
            /* not enabled */
            if ($cfg["MANAGEUSER"] <= 0 || empty($cfg["POP3_SERVER"]) || empty($cfg["SMTP_SERVER"])) {
                continue;
            }
            $companies[$row["code"]] = $cfg;
        }
        $comps->free();
    }
    /* run the routines */
    foreach ($companies as $code => $conf) {
        routine($code, $conf);
        if ($smallest_wait < 0 || $smallest_wait > $conf["INTERVAL"]) {
            $smallest_wait = $conf["INTERVAL"];
        }
    }