// TODO: Fix this shit!
#include "../../../admin.h"
#include "../../../users.h"
#include "parser_getusers.h"
PARSER_GET_USERS::PARSER_GET_USERS(const ADMIN * ca, USERS * u)
    : PARSER(),
      result(""),
      currAdmin(ca),
      users(u)
{
}
PARSER_GET_USERS::~PARSER_GET_USERS()
{
}
bool PARSER_GET_USERS::StartTag(const char * name, const char ** attr)
{
    std::string tag(name);
    if (tag != "GetUsers") {
        return false;
    }
    return true;
}
bool PARSER_GET_USERS::EndTag(const char * name)
{
    std::string tag(name);
    if (tag != "GetUsers") {
        return false;
    }
    int handle = users->OpenSearch();
    if (!handle) {
        printfd(__FILE__, "PARSER_GET_USERS::EndTag() OpenSearch error\n");
        users->CloseSearch(handle);
        result = "";
        return false;
    }
    std::stringstream answer;
    answer << "\n";
    while (1) {
        user_iter ui;
        if (users->SearchNext(handle, &ui)) {
            break;
        }
        answer << "\t\n";
        answer << "\t\tGetLogin() << "\"/>\n";
        if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd) {
            answer << "\t\tproperty.password.Get() << "\"/>\n";
        } else {
            answer << "\t\t\n";
        }
        answer << "\t\tproperty.cash.Get() << "\"/>\n";
        answer << "\t\tproperty.freeMb.Get() << "\"/>\n";
        answer << "\t\tproperty.credit.Get() << "\"/>\n";
        if (ui->property.nextTariff.Get() != "") {
            answer << "\t\tproperty.tariffName.Get()
                   << "/" << ui->property.nextTariff.Get() << "\"/>\n";
        } else {
            answer << "\t\tproperty.tariffName.Get() << "\"/>\n";
        }
        std::string encoded;
        Encode12str(encoded, ui->property.note.Get());
        answer << "\t\t\n";
        Encode12str(encoded, ui->property.phone.Get());
        answer << "\t\t\n";
        Encode12str(encoded, ui->property.address.Get());
        answer << "\t\t\n";
        Encode12str(encoded, ui->property.email.Get());
        answer << "\t\t\n";
        Encode12str(encoded, ui->property.realName.Get());
        answer << "\t\t\n";
        Encode12str(encoded, ui->property.group.Get());
        answer << "\t\t\n";
        // TODO: Fix this shit!
        // 
        Encode12str(encoded, ui->property.userdata0.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata1.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata2.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata3.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata4.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata5.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata6.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata7.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata8.Get()); answer << "\t\t\n";
        Encode12str(encoded, ui->property.userdata9.Get()); answer << "\t\t\n";
        // 
        answer << "\t\tGetConnected() << "\"/>\n";
        answer << "\t\tproperty.alwaysOnline.Get() << "\"/>\n";
        answer << "\t\tGetCurrIP()) << "\"/>\n";
        answer << "\t\tGetPingTime() << "\"/>\n";
        answer << "\t\tproperty.ips.Get() << "\"/>\n";
        answer << "\t\tproperty.lastCashAdd.Get() << "\"/>\n";
        answer << "\t\tproperty.lastCashAddTime.Get() << "\"/>\n";
        answer << "\t\tproperty.lastActivityTime.Get() << "\"/>\n";
        answer << "\t\tproperty.creditExpire.Get() << "\"/>\n";
        answer << "\t\tproperty.disabled.Get() << "\"/>\n";
        answer << "\t\tproperty.passive.Get() << "\"/>\n";
        answer << "\t\tproperty.disabledDetailStat.Get() << "\"/>\n";
        // TODO: Fix this shit!
        // 
        answer << "\t\tproperty.up.Get());
        DIR_TRAFF down(ui->property.down.Get());
        for (int i = 0; i < DIR_NUM; ++i) {
            answer << "MU" << i << "=\"" << up[i] << "\" ";
            answer << "MD" << i << "=\"" << down[i] << "\" ";
        }
        answer << "/>\n";
        // 
        answer << "\t\n";
    }
    answer << "";
    users->CloseSearch(handle);
    result = answer.str();
    return true;
}