import ws.*;

public class p_GetClientsB
{

  public WTableList Request(WServer oServer, WParamList oParamList)
  { 
    int rc, i, n, NumOfRows;
    WTableList oTableList, oTableListRun;
    WParamList oParamListRun;
    WTable     oTableRun, oTable0, oTable1;
    String     sz, szItemID;
    WUtil      oUtil;

    oTableList    = new WTableList(oServer);
    oTableListRun = new WTableList(oServer);
    oParamListRun = new WParamList(oServer);
    oTableRun     = new WTable(oServer);
    oTable0       = new WTable(oServer);
    oTable1       = new WTable(oServer);
    oUtil         = new WUtil();

    // Params

    // Table0
    oTable0.CreateCol(10);   // 0  Count
    oTable0.CreateRow();
    oTableList.AddTable(oTable0);  // Table 0

    // Clients
    oParamListRun.Clean();
    rc = oServer.Request("p_GetClients", oParamListRun, oTableListRun);
    if (rc != 0)
      return oTableListRun;      
    oTableListRun.GetTable(0, oTableRun);

    // Table1
    oTable1.CreateCol(100);   // 0  Select
    oTable1.CreateCol(100);   // 1  Name
    oTable1.CreateCol(100);   // 2  Addr
    oTable1.CreateCol(50);    // 3  City
    oTable1.CreateCol(50);    // 4  Prov
    oTable1.CreateCol(10);    // 5  PC
    oTable1.CreateCol(50);    // 6  Country
    oTable1.CreateCol(50);    // 7  Phone
    oTable1.CreateCol(50);    // 8  Email
    oTable1.SetTRParam("style='background-color: #f5f5f5'","style='background-color: #eeeeee'");

    NumOfRows = oTableRun.GetNumOfRows();

    n = 0;
    for(i=0; i < NumOfRows; i++)
    {
      szItemID = oTableRun.GetField(i,0);
      if (oUtil.GetInt(szItemID) != 0)
      {
        oTable1.CreateRow();

        // Select
        sz = "<INPUT TYPE='RADIO' NAME='ItemID' VALUE='" + szItemID + "'>";
        oTable1.SetField(n,0,sz);
        // Name
        oTable1.SetField(n,1,oTableRun.GetField(i,1));
        // Addr
        oTable1.SetField(n,2,oTableRun.GetField(i,2));
        // City
        oTable1.SetField(n,3,oTableRun.GetField(i,3));
        // Prov
        oTable1.SetField(n,4,oTableRun.GetField(i,4));
        // PC
        oTable1.SetField(n,5,oTableRun.GetField(i,5));
        // Country
        oTable1.SetField(n,6,oTableRun.GetField(i,6));
        // Phone
        oTable1.SetField(n,7,oTableRun.GetField(i,7));
        // Email
        oTable1.SetField(n,8,oTableRun.GetField(i,8));
        n++;
      }
    }
    oTableList.AddTable(oTable1);  // Table 1

    // Count
    oTable0.SetField(0,0,oUtil.SetInt(n));

    oServer.SetOutputPage("p_Clients");  

    return oTableList; 
  }
}