/*
 * Program:
 *   clio.cpp
 * Summary:
 *   Experiments in visualizing page usage.
 * Authors:
 *   Samuel A. Rebelsky
 * Version:
 *   0.1 of July 2003.
 * Warning:
 *   The organization of this program is totally ad-hoc.
 */

int ww, wh;

/********************************************************/
/*                      Headers                         */
/*******************************************************/

extern "C"{
#include <stdlib.h>
#include "clio.h"
#include "cliographics.h"

//for glui
#include <string.h>
#include <GL/glut.h>
#include "glui.h"
}
/****************************************************/
/*                   Constants                      */
/****************************************************/

/* The "unit" of translation. */
#define TRANSLATE_UNIT 5

 
/* The "unit" of rotation (in degrees). */
#define ROTATE_UNIT 5

/* The width and height of the main widnow. */
#define WIDTH 1010
#define HEIGHT 900


/**************************************************/
/*                   Globals                      */
/**************************************************/

int mainWin;		/* The id of the main window. */
int xtrans;	/* The amount translated in the X dimension. */
int ytrans;	/* The amount translated in the Y dimension. */
int ztrans;	/* The amount translated in the Z dimension. */

/**************************************************/
/*              GLUI Controls                     */
/**************************************************/
char *name[]= {" ", "Category", "URL", "Time Spent",
              "Time Accessed", "Session","Windows"};
char *users[]= {"Lindseyd", "Rebelsky", "Brantley", "Bearywes",
                "ToTue"};
int numberOfStudents = 5;
char *start_time, *end_time;

int i;

/* "Live variables */
float scale = 1.0;
int   show_axes = 1;

/* Controls */
GLUI *glui, *glui2;
GLUI_RadioGroup *curr_vis_choices;
GLUI_Button *load_saved, *save_curr, *time_button, *done_button;
GLUI_Listbox *x_list, *y_list, *z_list, *w_list, 
  *h_list,*d_list, *c_list, *t_list, *l_list, *s_list, 
  *user1, *user2, *user3,*time_panel;
GLUI_EditText *s_box, *e_box;

enum {DAY_ALL=500, DAY_60, DAY_30, DAY_7, DAY_1, DAY_OTHER};


/* Callback ID's - passed to control func*/
enum {CHANGE_VISUALIZATION_ID=100, LOAD_SAVED_ID, SAVE_BUTTON_ID,DONE_BUTTON_ID
      ,CHANGE_X_ID
      , CHANGE_Y_ID, CHANGE_Z_ID, CHANGE_W_ID, CHANGE_H_ID
      , CHANGE_D_ID, CHANGE_C_ID, CHANGE_T_ID, CHANGE_L_ID, CHANGE_S_ID
      , CHANGE_USER_1_ID,CHANGE_USER_2_ID,CHANGE_USER_3_ID, CHANGE_TIME_ID
      , TIME_BUTTON_ID};

/**************************************************/
/*           Rotation Matrices                    */
/**************************************************/
float view_rotate[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
float obj_pos[] = { 0.0, 0.0, 0.0 };

/**************************************************/
/*           Lighting Attributes                  */
/**************************************************/
float light0_position[]= {0.0f,0.0f, 50.0f, 0.0f};
float light0_ambient[]= {0.0f, 0.0f, 0.0f, 1.0f};
float light0_diffuse[]= {1.0f,1.0f, 1.0f, 1.0f};
float light0_specular[]= {0.0, 0.0, 0.0, 1.0};

float light1_position[]={50,50,-50};
float light1_ambient[]= {0.0f, 0.0f, 0.0f, 1.0f};
float light1_diffuse[]= {1.0f,1.0f, 1.0f, 1.0f};
float light1_specular[]= {0.0, 0.0, 0.0, 1.0};

/**************************************************/
/*           Material Attributes                  */
/**************************************************/
float mat_diff_amb[]= {0.0f, 0.0f, 0.0f, 1.0f};
float mat_emission[] = {0.3, 0.2, 0.2, 0.0};


/*************************************************/
/*               Predeclarations                 */
/*************************************************/

/* GLUT CALLBACKS */


/* Display the current world. */
void display(void);

/* Handle keyboard input. */
void keyboard(unsigned char, int, int);

/* Handle a change in size to the window */
void resize(int, int);
void reshape2D(int, int);

/* Set up everything. */
void clioInit(void);

/* Set up GLUI Interface */
void setUpUserInterface(void);

void mouse(int button, int state, int x, int y);
void control_cb(int ID);
void motion(int x, int y);


/********************************************/
/*          Local Functions                 */
/********************************************/
float (*getFunc(int ID))(pagevisit *);




/**********************************************/
/**********************************************/
/**********************************************/


/*******************************************/
/*                   Main                  */
/*******************************************/

int 
main (int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 
  glutInitWindowPosition(0,0);     
  glutInitWindowSize(WIDTH, HEIGHT);               
           
  mainWin = glutCreateWindow("Exploring Clio's Worlds"); 
  
  clioInit();                                           
  
  glutDisplayFunc( display );
  wh = glutGet(GLUT_WINDOW_HEIGHT);  
  ww = glutGet(GLUT_WINDOW_WIDTH); 
  GLUI_Master.set_glutReshapeFunc( resize );  
  GLUI_Master.set_glutKeyboardFunc( keyboard );
  GLUI_Master.set_glutSpecialFunc( NULL );
  GLUI_Master.set_glutMouseFunc( mouse );
  glutMotionFunc( motion );
  
  /****************************************/
  /*       Set up OpenGL lights           */
  /****************************************/                                       
  glShadeModel(GL_FLAT);              
  //glEnable(GL_LIGHTING);
  

  //Automatically scales normal vectors to unit length
  glEnable(GL_NORMALIZE);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  

  
  /******************************************************/
  /*            Set up Material Properties              */
  /******************************************************/
  glEnable(GL_COLOR_MATERIAL);
  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_diff_amb);



  /***************************************************/
  /*            Enable z-buffering                   */
  /***************************************************/

  glEnable(GL_DEPTH_TEST);

  /***************************************************/
  /*       Set up user Interface controls            */
  /***************************************************/
  setUpUserInterface();
  
  // Register the idle callback with GLUI, *not* with GLUT 
  GLUI_Master.set_glutIdleFunc( NULL );

  glutMainLoop();
} //main


/*****************************************************/
/*              clioInit()                           */ 
/*****************************************************/

/*
 * Procedure:
 *   clioInit
 * Purpose:
 *   Initializes everything for this version of Clio 3D to work.
 */
void clioInit(void)
{
  glClearColor(0.0, 0.0, 0.0, 0.0); //clear to black
  


  //sets viewport taking into account the submenu size
  int tx, ty,tw,th;
  GLUI_Master.get_viewport_area(&tx, &ty, &tw, &th);
  glViewport(tx, ty, tw,th);
  // glViewport(0,0,ww, wh);

  glMatrixMode(GL_PROJECTION);	//sets 'camera' or field of view matrix
  glLoadIdentity();		//loads current matrix
  //glOrtho(-10.0, 110.0,-10.0, 110.0, -10.0, 110.0); 
  glOrtho(0.0, 110.0,-10.0, 110.0, -10.0, 110.0); 

			
  glMatrixMode(GL_MODELVIEW);

  // Prepare test values
  loadData(NULL);
  // Set up default visualization
  cityScape();

  glFinish();
} // clioInit



/******************************************/
/*         void display()                 */
/******************************************/

void display(void)
{


  int i,j,k;
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  //initial position of light source
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);

  //constant amount of light at every point
   glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  
  //partially absorbed/ partially reflected
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);

  //direction of a perfect reflection
  glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
  //Need glOrtho here?
  
  glLightfv(GL_LIGHT1, GL_POSITION, light0_position);
  glLightfv(GL_LIGHT1, GL_AMBIENT, light0_ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light0_diffuse);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light0_specular);
  

  if (show_axes){
    glDisable(GL_LIGHTING);
    
    glPushMatrix();
    glScalef( scale, scale, scale);

    /* Show X, Y, and Z axis (R,G,B) so that I can tell what's going on. */
    glBegin(GL_LINES);
      glColor3f(1.0, 0.0, 0.0);
      glVertex3f(0.0, 0.0, 0.0);
      glVertex3f(500.0, 0.0, 0.0);
      
      glColor3f(0.0, 1.0, 0.0);
      glVertex3f(0.0, 0.0, 0.0);
      glVertex3f(0.0, 500.0, 0.0);
      
      glColor3f(0.0, 0.0, 1.0);
      glVertex3f(0.0, 0.0, 0.0);
      glVertex3f(0.0, 0.0, 500.0);
    glEnd();
    
    glPopMatrix();
    glEnable(GL_LIGHTING);
  }

  glMatrixMode( GL_MODELVIEW);
  glLoadIdentity();
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);

  glLoadIdentity();
  glTranslatef( 0.0, 0.0, -2.6f);
  glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2]);
  fprintf(stderr, "Z POSITION %i\n", obj_pos[2]);
  glMultMatrixf( view_rotate );

  glScalef( scale, scale, scale);
  
  glPushMatrix();
  //render objects using: translate, then draw, then pop
#ifdef BOXES
  for (i = 0; i <= 3; i++) {
    for (j = 0; j <= 3; j++) {
      for (k = 0; k <= 3; k++) {
        clioBox(1,MAXC,
                500-500*i, 500-500*j, 500-500*k,
                50, 50, 50);
      }
    }
  }
#endif /* BOXES */
  
  glutSolidTeapot(5.0);
  
  for (i = 0; i < numvisits; ++i) {
    clioBox(getColor(visits+i), getShade(visits+i),
            getX(visits+i), getY(visits+i), getZ(visits+i),
            getW(visits+i), getH(visits+i), getD(visits+i));
  } /* for */
  
  glFinish();  
  glutSwapBuffers();
} //display

/*
 * Procedure:
 *   keyboard
 * Purpose:
 *   React to the user's choice of keyboard key.
 * Possibilities:
 *   a/A: translate in x axis
 *   w/W: translate in y axis
 *   s/S: translate in z axis
 *   x/X: rotate around x axis
 *   d/D: rotate around y axis
 *   c/C: rotate around z axis
 *   1-2: select a display scheme
 */
void keyboard(unsigned char key, int x, int y)
{
  //lPushMatrix();
  printf("%c\n", key);
  switch (key) {
    // Restore
    case ' ': 
      glTranslatef(-xtrans, -ytrans, -ztrans);
      xtrans = 0;
      ytrans = 0;
      ztrans = 0;

    // Translations
    case 'a': 
      glTranslatef(TRANSLATE_UNIT, 0.0, 0.0); 
      xtrans += TRANSLATE_UNIT;
      break;
    case 'A': 
      glTranslatef(-TRANSLATE_UNIT, 0.0, 0.0); 
      xtrans -= TRANSLATE_UNIT;
      break;
    case 'w': 
      glTranslatef(0.0, TRANSLATE_UNIT, 0.0); 
      ytrans += TRANSLATE_UNIT;
      break;
    case 'W': 
      glTranslatef(0.0, -TRANSLATE_UNIT, 0.0); 
      ytrans -= TRANSLATE_UNIT;
      break;
    case 's': 
      glTranslatef(0.0, 0.0, TRANSLATE_UNIT); 
      ztrans += TRANSLATE_UNIT;
      break;
    case 'S': 
      glTranslatef(0.0, 0.0, -TRANSLATE_UNIT); 
      ztrans -= TRANSLATE_UNIT;
      break;

    // Rotations
    case 'x': glRotatef(ROTATE_UNIT, 1.0, 0.0,0.0); break;
    case 'X': glRotatef(-ROTATE_UNIT, 1.0, 0.0, 0.0); break;
    case 'd': glRotatef(ROTATE_UNIT, 0.0, 1.0, 0.0); break;
    case 'D': glRotatef(-ROTATE_UNIT, 0.0, 1.0, 0.0); break;
    case 'c': glRotatef(ROTATE_UNIT, 0.0, 0.0, 1.0); break;
    case 'C': glRotatef(-ROTATE_UNIT, 0.0, 0.0, 1.0); break;
    
    // Display Schemes 
    case '1': cityScape(); break;
    case '2': boxesInSpace(); break;
  } // switch
  //lPopMatrix();
  glutPostRedisplay();
} // keyboard

/*********************************Resize Routines****************************/

void resize(int width, int height)
{
#ifdef RESIZE_CODE 
  if (height == 0) height = 1;
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0, width / height, 0.5, 1600.0);
  glViewport(0, 0, width, height);
  glTranslatef(0.0, -5.0, -150.0);
  

  glMatrixMode(GL_MODELVIEW);
#endif /* RESISE_CODE */

  ww = width;
  wh = height;
} // resize

void reshape2D(int w, int h)	/* generic 2D reshape callback */
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0,w,0,h);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
} //reshape2D


/****************************Control Functions*******************************/
void mouse(int button, int state, int x, int y)
{
}

void control_cb(int ID)
{
  switch(ID){
  

  case CHANGE_VISUALIZATION_ID:
    switch(curr_vis_choices->get_int_val()){
    case 0:
      load_saved->disable();
      //Boxes in Space
      boxesInSpace();
      break;
    case 1:
      load_saved->disable();
      //City Scape
      cityScape();
      break;
    case 2:
      //Enable Load Saved Button
      load_saved->enable();
      break;
    }
    glutPostRedisplay();
    break;
  


  case LOAD_SAVED_ID:
    //load saved id 
    break;
  

  case CHANGE_X_ID:
    getX = getFunc(x_list->get_int_val());
    break;
  case CHANGE_Y_ID:
    getY = getFunc(y_list->get_int_val());
    break;
  case CHANGE_Z_ID:
    getZ = getFunc(z_list->get_int_val());
    break;
  case CHANGE_W_ID:
    getW = getFunc(w_list->get_int_val());
    break;
  case CHANGE_H_ID:
    getH = getFunc(h_list->get_int_val());
    break;
  case CHANGE_D_ID:
    getD = getFunc(d_list->get_int_val());
    break;
  case CHANGE_C_ID:
    getColor =(int (*)(pagevisit *)) getFunc(c_list->get_int_val());
    break;
  case CHANGE_L_ID:
    //no light
    break;
  case CHANGE_T_ID:
    //no texture
    break;
  case CHANGE_S_ID:
    getShape = (int (*)(pagevisit *)) getFunc(s_list->get_int_val());
    break;
     
 
  case DONE_BUTTON_ID:
    //when done setting attributes, display them
    glutPostRedisplay();
    break;
  
  case SAVE_BUTTON_ID:
    //save current attributes
    break;

  case CHANGE_USER_1_ID:
    //get different data
    //position on screen
    glutPostRedisplay;
    break;
  case CHANGE_USER_2_ID:
    //get different data
    //position on screen
    glutPostRedisplay;
    break;
  case CHANGE_USER_3_ID:
    //get different data
    //position on screen
    glutPostRedisplay;
    break;
  
  case CHANGE_TIME_ID:
    s_box->disable();
    e_box->disable();

    switch(time_panel->get_int_val()){
    case DAY_ALL:
      break;
    case DAY_60:
      break;
    case DAY_30:
      break;
    case DAY_7:
      break;
    case DAY_1:
      break;
    case DAY_OTHER:
      s_box->enable();
      e_box->enable();
      break;
    }
    break;

  case TIME_BUTTON_ID:
    //read e_box
    //read s_box
    //get new data
    glutPostRedisplay();
    break;
  }
}

void motion(int x, int y)
{
}

/*****************************HELPER FUNCTIONS*****************************/

float (*getFunc(int ID))(pagevisit *)
{
  switch(ID){
  case 200:
    //  nothing
    return NULL;
    break;
  case 201:
    //  category
    return &getTypeC;
    break;
  case 202:
    //  URL
    return &getPageC;
    break;
  case 203:
    //  time spent
    return &getLengthC;
    break;
  case 204:
    //  time accessed
    return &getStartC;
    break;
  case 205:
    //  session
    return (float (*)(pagevisit*))&getUWSD;
    break;
  case 206:
    //  windows (bid)
    return (float (*)(pagevisit*)) &getUWSD;
    break;
  }
}


/* Function :
 *     CalculateVectorNormal
 * Purpose:
 *      Given three points of a 3D pane, this function
 *      calculates the normal vector of that plane
 * Parameters:
 *      fVert1[] == array for 1st point (x, y, z)
 *      fVert2[] == array for 2nd point (x, y, z)
 *      fVert3[] == array for 3rd point (x, y, z)
 * Returns:
 *      fNormalX == X vector for the normal vector
 *      fNormalY == Y vector for the normal vector
 *      fNormalZ == Z vector for the normal vector
 * History: Date     Author
 *          3/22/95  GGB
 * Location:
 *   <http://support.microsoft.com/default.aspx?
      scid=http://support.microsoft.com:80/
      support/kb/articles/Q131/1/30.asp&NoWebContent=1>
 * Last Reviewed:
 *     12/17/2000
 */



/*****************************************************/
/*               setUpUserInterface()                */
/*****************************************************/

/*
 * Procedure:
 *     setUpUserInterface()
 * Purpose:
 *     Sets up the GLUI user interface user in Clio 3D
 *     and establishes the call back fuctions or "live
 *     variables" used to react to user input
 */

void setUpUserInterface(void)
{
  glPushMatrix();

  /*****************************************************/
  /*              GLUI Floating Panel                  */
  /*****************************************************/
 
  glui = GLUI_Master.create_glui("Navigation Controls");

  GLUI_Panel *nav= glui->add_panel("Navigation Controls"); 
  
  GLUI_Rotation *rotation= glui->add_rotation_to_panel(nav,"Rotation",
                                                       view_rotate); 

 
  GLUI_Translation *xy= glui->add_translation_to_panel(nav,"Translation",
                                                       GLUI_TRANSLATION_XY, 
                                                       obj_pos);

  GLUI_Translation *z= glui->add_translation_to_panel(nav,"Zoom",
                                                      GLUI_TRANSLATION_Z, 
                                                      &obj_pos[2]);
  z->set_speed( 5);

  GLUI_Spinner *scale_spinner = 
    glui->add_spinner_to_panel( nav, "Scale:",
				GLUI_SPINNER_FLOAT, &scale);
  scale_spinner->set_float_limits( .2f, 4.0 );
  scale_spinner->set_alignment( GLUI_ALIGN_LEFT );

  glui->add_checkbox_to_panel( nav, "Draw axes", &show_axes );



  
 
  glui->set_main_gfx_window(mainWin);

  /*****************************************************/
  /*              GLUI Bottom Panel                    */
  /*****************************************************/
  
  glui2 = GLUI_Master.create_glui_subwindow( mainWin,
                                             GLUI_SUBWINDOW_BOTTOM );
   /***************************************/
  /*   Current Visualization Selection    */
  /****************************************/
  GLUI_Panel *currVisSelection = 
    glui2->add_panel("Current Visualization");

  curr_vis_choices=
    glui2->add_radiogroup_to_panel(currVisSelection,
                                  NULL,CHANGE_VISUALIZATION_ID,control_cb);
  glui2->add_radiobutton_to_group( curr_vis_choices, "Boxes in Space" );
  glui2->add_radiobutton_to_group( curr_vis_choices, "City Scape" );
  glui2->add_radiobutton_to_group( curr_vis_choices, "Other" );
    
  load_saved =
    glui2->add_button_to_panel(currVisSelection, "Load Saved", 
                               LOAD_SAVED_ID, control_cb);
  load_saved->disable();					     
     glui2->add_column(false);
 
  /***************************************/
  /*     Visualization Attributes        */
  /***************************************/
  

  GLUI_Panel *currVisAttributes =
    glui2->add_panel("Visualization Attributes");
  
  x_list = glui2->add_listbox_to_panel(currVisAttributes, "X Position",
                                       NULL, CHANGE_X_ID, control_cb);
  for(i=0; i < 7; ++i)
    x_list->add_item(200+i,name[i]);
  //default is city scape
  x_list->set_int_val(7);
      
  y_list = glui2->add_listbox_to_panel(currVisAttributes, "Y Position",
                                       NULL, CHANGE_Y_ID, control_cb);
  for(i=0; i < 7; ++i)
    y_list->add_item(200+i,name[i]);
  y_list->set_int_val(4);

  z_list = glui2->add_listbox_to_panel(currVisAttributes, "Z Position",
                                       NULL, CHANGE_Z_ID, control_cb);

  for(i=0; i < 7; ++i)
    z_list->add_item(200+i,name[i]);
  z_list->set_int_val(0);

  w_list = glui2->add_listbox_to_panel(currVisAttributes, "Width",
                                       NULL, CHANGE_W_ID, control_cb);
  for(i=0; i < 7; ++i)
    w_list->add_item(200+i,name[i]);
  w_list->set_int_val(0);

  glui2->add_column_to_panel(currVisAttributes,false);


  h_list = glui2->add_listbox_to_panel(currVisAttributes, "Height",
                                       NULL, CHANGE_H_ID, control_cb);
  for(i=0; i < 7; ++i)
    h_list->add_item(200+i,name[i]);
  h_list->set_int_val(3);
  

  d_list = glui2->add_listbox_to_panel(currVisAttributes, "Depth",
                                       NULL, CHANGE_D_ID, control_cb);
  
  for(i=0; i < 7; ++i)
    d_list->add_item(200+i,name[i]);
  d_list->set_int_val(3);

  c_list = glui2->add_listbox_to_panel(currVisAttributes, "Color",
                                       NULL, CHANGE_C_ID, control_cb);
  for(i=0; i < 7; ++i)
    c_list->add_item(200+i,name[i]);
  

  t_list = glui2->add_listbox_to_panel(currVisAttributes, "Texture",
                                       NULL, CHANGE_T_ID, control_cb);
  for(i=0; i < 7; ++i)
    t_list->add_item(200+i,name[i]);

  glui2->add_column_to_panel(currVisAttributes,false);


  l_list = glui2->add_listbox_to_panel(currVisAttributes, "Lighting",
                                       NULL, CHANGE_L_ID, control_cb);
  for(i=0; i < 7; ++i)
    l_list->add_item(200+i,name[i]);
  


  s_list = glui2->add_listbox_to_panel(currVisAttributes, "Shape",
                                       NULL, CHANGE_S_ID, control_cb);
  for(i=0; i < 7; ++i)
    s_list->add_item(200+i,name[i]);
  glui2->add_separator_to_panel(currVisAttributes);
  
  done_button =
    glui2->add_button_to_panel(currVisAttributes, "Done",
                               DONE_BUTTON_ID, control_cb);
  save_curr =
    glui2->add_button_to_panel(currVisAttributes, "Save Current Settings",
                               SAVE_BUTTON_ID, control_cb);

  glui2->add_column(false);
  /***************************************/
  /*      Current Student Selection      */
  /***************************************/
  GLUI_Panel *currStudents = 
    glui2->add_panel("Students Visualized");
  
  /*callback id's for list of students = 300 + position 
    in array*/
  user1 = 
    glui2->add_listbox_to_panel(currStudents, "Student 1", NULL
                               ,CHANGE_USER_1_ID, control_cb);
  for(i=0; i < numberOfStudents; ++i)
    user1->add_item(300+i, users[i]); 

  user2 = glui2->add_listbox_to_panel(currStudents, "Student 2", NULL
                               ,CHANGE_USER_2_ID, control_cb);
  for(i=0; i < numberOfStudents; ++i)
    user2->add_item(300+i, users[i]); 


 user3 = glui2->add_listbox_to_panel(currStudents, "Student 3", NULL
                               ,CHANGE_USER_3_ID, control_cb);
  for(i=0; i < numberOfStudents; ++i)
    user3->add_item(300+i, users[i]); 
  
  glui2->add_column(false);
  
  GLUI_Panel *dataSelect = 
    glui2->add_panel("Data Selection");
  
  time_panel =
    glui2->add_listbox_to_panel(dataSelect, "Time Period", NULL,
                               CHANGE_TIME_ID, control_cb);
  time_panel->add_item(DAY_ALL, "All");
  time_panel->add_item(DAY_60,"Last 60 days");
  time_panel->add_item(DAY_30,"Last 30 days");
  time_panel->add_item(DAY_7,"Last week");
  time_panel->add_item(DAY_1,"Today only");
  time_panel->add_item(DAY_OTHER, "Other");

  s_box=
    glui2->add_edittext_to_panel(dataSelect, "Start time",
                                 GLUI_EDITTEXT_TEXT, &start_time); 
  s_box->disable();

  e_box=
    glui2->add_edittext_to_panel(dataSelect, "End time",
                                 GLUI_EDITTEXT_TEXT, &end_time); 
  e_box->disable();

  time_button =
    glui2->add_button_to_panel(dataSelect, "Ok",
                               TIME_BUTTON_ID, control_cb);
  time_button->disable();

  glui2->set_main_gfx_window( mainWin );

  glPopMatrix();

}  

