<?php

mh_define('TABLE_MAILBEEZ_SHRTNR_IDX', DB_PREFIX . 'mailbeez_shrtnr_idx');


class mailbeez_shrtnr
{
    function __construct()
    {

    }

    function set($valueString)
    {
        $token = $this->generateToken($valueString);
        $insertSql = "INSERT IGNORE INTO " . TABLE_MAILBEEZ_SHRTNR_IDX ."
                        SET token = '" . $token . "',
                            shrtnr_value = '" . $valueString . "',
                            date_added = now()";
        mh_db_query($insertSql);
        return $token;
    }

    function get($token)
    {
        $query_sql = "select * from " . TABLE_MAILBEEZ_SHRTNR_IDX . "
                             where token = '" . $token . "' ";
        $query = mh_db_query($query_sql);
        if (mh_db_num_rows($query) > 0) {
            $result = mh_db_fetch_array($query);

            $data = array('last_read' => 'now()');
            mh_db_perform(TABLE_MAILBEEZ_SHRTNR_IDX, $data, 'update', 'token="' . $token . '"');
            return $result['shrtnr_value'];
        }
        return false;
    }

    function generateToken($valueString)
    {
        return md5($valueString);
    }

    function dropOldEntries($days = 90)
    {


    }

}