Changeset 12516


Ignore:
Timestamp:
2006-08-24T11:18:36+12:00 (18 years ago)
Author:
kjdon
Message:

Added Stefan's fileupload code to replace use of cgicc by depositor. Commented out some of the cgiargs that I don't think are being used

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/depositoraction.cpp

    r12480 r12516  
    6565#include <iostream>
    6666//#include <cstdlib>
    67 #include "cgicc/CgiDefs.h"
    68 #include "cgicc/Cgicc.h"
    69 
    70 using namespace cgicc;
    71 
    72 extern Cgicc *formData;
    7367
    7468depositoraction::depositoraction ()
     
    7872  lastpage = 0;
    7973
    80   do_udcol = false;
    81 
    82   //remove these if removed from depositoraction.h
    83   badsources = false;
    84   failedsources.erase(failedsources.begin(), failedsources.end());
    85 
    8674  cgiarginfo arg_ainfo;
    8775  arg_ainfo.shortname = "a";
     
    10997  arg_ainfo.savedarginfo = cgiarginfo::must;
    11098  argsinfo.addarginfo (NULL, arg_ainfo);
     99 
     100  // the fileupload info that cgiwrapper produces - we parse the fileupload_t
     101  // and set di1userfile, di1userfilesize
     102  arg_ainfo.shortname = "di1userfileinfo";
     103  arg_ainfo.longname = "depositor specific";
     104  arg_ainfo.fileupload = true;
     105  arg_ainfo.savedarginfo = cgiarginfo::mustnot; 
     106  argsinfo.addarginfo (NULL, arg_ainfo);
     107
     108  // essential: reset fileupload to default as we are not setting
     109  // it for each arg
     110  arg_ainfo.fileupload = false;
    111111
    112112  //the name of the file to be added
     
    147147  argsinfo.addarginfo (NULL, arg_ainfo);
    148148
    149   arg_ainfo.shortname = "di1fullname";
    150   arg_ainfo.longname = "depositor specific";
    151   arg_ainfo.multiplechar = true;
    152   arg_ainfo.defaultstatus = cgiarginfo::weak;
    153   arg_ainfo.argdefault = g_EmptyText;
    154   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    155   argsinfo.addarginfo (NULL, arg_ainfo);
     149//   arg_ainfo.shortname = "di1fullname";
     150//   arg_ainfo.longname = "depositor specific";
     151//   arg_ainfo.multiplechar = true;
     152//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     153//   arg_ainfo.argdefault = g_EmptyText;
     154//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     155//   argsinfo.addarginfo (NULL, arg_ainfo);
    156156
    157157  arg_ainfo.shortname = "di1dirname";
     
    171171  argsinfo.addarginfo (NULL, arg_ainfo);
    172172
    173   arg_ainfo.shortname = "di1clone";
    174   arg_ainfo.longname = "depositor specific";
    175   arg_ainfo.multiplechar = false;
    176   arg_ainfo.defaultstatus = cgiarginfo::weak;
    177   arg_ainfo.argdefault = "0";
    178   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    179   argsinfo.addarginfo (NULL, arg_ainfo);
    180 
    181   arg_ainfo.shortname = "di1clonecol";
    182   arg_ainfo.longname = "depositor specific";
    183   arg_ainfo.multiplechar = true;
    184   arg_ainfo.defaultstatus = cgiarginfo::weak;
    185   arg_ainfo.argdefault = g_EmptyText;
    186   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    187   argsinfo.addarginfo (NULL, arg_ainfo);
    188 
    189   arg_ainfo.shortname = "cfgfile";
    190   arg_ainfo.longname = "configuration file contents";
    191   arg_ainfo.multiplechar = true;
    192   arg_ainfo.defaultstatus = cgiarginfo::weak;
    193   arg_ainfo.argdefault = g_EmptyText;
    194   arg_ainfo.savedarginfo = cgiarginfo::mustnot;
    195   argsinfo.addarginfo (NULL, arg_ainfo);
    196 
    197   // will be set if we arrived at the "configure collection" page
    198   // via the "changing an existing collection" page
    199   arg_ainfo.shortname = "di1econf";
    200   arg_ainfo.longname = "depositor specific";
    201   arg_ainfo.multiplechar = false;
    202   arg_ainfo.defaultstatus = cgiarginfo::weak;
    203   arg_ainfo.argdefault = "0";
    204   arg_ainfo.savedarginfo = cgiarginfo::must;
    205   argsinfo.addarginfo (NULL, arg_ainfo);
    206 
    207   // will be set if we arrived at the "source data" page
    208   // via the "changing an existing collection" page
     173//   arg_ainfo.shortname = "di1clone";
     174//   arg_ainfo.longname = "depositor specific";
     175//   arg_ainfo.multiplechar = false;
     176//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     177//   arg_ainfo.argdefault = "0";
     178//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     179//   argsinfo.addarginfo (NULL, arg_ainfo);
     180
     181//   arg_ainfo.shortname = "di1clonecol";
     182//   arg_ainfo.longname = "depositor specific";
     183//   arg_ainfo.multiplechar = true;
     184//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     185//   arg_ainfo.argdefault = g_EmptyText;
     186//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     187//   argsinfo.addarginfo (NULL, arg_ainfo);
     188
     189//   arg_ainfo.shortname = "cfgfile";
     190//   arg_ainfo.longname = "configuration file contents";
     191//   arg_ainfo.multiplechar = true;
     192//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     193//   arg_ainfo.argdefault = g_EmptyText;
     194//   arg_ainfo.savedarginfo = cgiarginfo::mustnot;
     195//   argsinfo.addarginfo (NULL, arg_ainfo);
     196
     197//   // will be set if we arrived at the "configure collection" page
     198//   // via the "changing an existing collection" page
     199//   arg_ainfo.shortname = "di1econf";
     200//   arg_ainfo.longname = "depositor specific";
     201//   arg_ainfo.multiplechar = false;
     202//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     203//   arg_ainfo.argdefault = "0";
     204//   arg_ainfo.savedarginfo = cgiarginfo::must;
     205//   argsinfo.addarginfo (NULL, arg_ainfo);
     206
     207  // wizard uses this to see if we are working with an existing collection:
     208  // set the default to 1
    209209  arg_ainfo.shortname = "di1esrce";
    210210  arg_ainfo.longname = "depositor specific";
     
    215215  argsinfo.addarginfo (NULL, arg_ainfo);
    216216
    217   arg_ainfo.shortname = "di1input";
    218   arg_ainfo.longname = "depositor specific";
    219   arg_ainfo.multiplechar = true;
    220   arg_ainfo.multiplevalue = true;
    221   arg_ainfo.defaultstatus = cgiarginfo::weak;
    222   arg_ainfo.argdefault = g_EmptyText;
    223   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    224   argsinfo.addarginfo (NULL, arg_ainfo);
    225 
    226   //we don't need this in the depositor
    227   arg_ainfo.shortname = "di1inputtype";
    228   arg_ainfo.longname = "depositor specific";
    229   arg_ainfo.multiplechar = true;
    230   arg_ainfo.multiplevalue = true;
    231   arg_ainfo.defaultstatus = cgiarginfo::weak;
    232   arg_ainfo.argdefault = g_EmptyText;
    233   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
    234   argsinfo.addarginfo (NULL, arg_ainfo);
     217//   arg_ainfo.shortname = "di1input";
     218//   arg_ainfo.longname = "depositor specific";
     219//   arg_ainfo.multiplechar = true;
     220//   arg_ainfo.multiplevalue = true;
     221//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     222//   arg_ainfo.argdefault = g_EmptyText;
     223//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     224//   argsinfo.addarginfo (NULL, arg_ainfo);
     225
     226//   //we don't need this in the depositor
     227//   arg_ainfo.shortname = "di1inputtype";
     228//   arg_ainfo.longname = "depositor specific";
     229//   arg_ainfo.multiplechar = true;
     230//   arg_ainfo.multiplevalue = true;
     231//   arg_ainfo.defaultstatus = cgiarginfo::weak;
     232//   arg_ainfo.argdefault = g_EmptyText;
     233//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
     234//   argsinfo.addarginfo (NULL, arg_ainfo);
    235235
    236236}
     
    239239}
    240240
    241 //I think we need this too
     241
    242242bool depositoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, recptprotolistclass * protos, ostream &logout) {
    243243
    244 
    245244  wizardaction::check_cgiargs(argsinfo,args,protos,logout);
    246 
    247245
    248246  text_t &current_page = args["p"];
     
    254252  // to read from the key.db database at the same time.
    255253
    256   //right now, anyone can do anything until it's tile to build
     254  //right now, anyone can do anything until it's time to build
    257255  if (current_page == "select") {
    258256    //authenticate the user if authentication is available
     
    271269  // Consider recoding at some point in the future.
    272270
    273   const_file_iterator file = formData->getFile("di1userfile");
    274 
    275   if(file != formData->getFiles().end()) {
    276 
    277     time_t timestamp = time(NULL);
    278     text_t timestamp_str(timestamp);
    279     args["di1timestamp"] = timestamp_str;
    280 
    281     const char* filename_str = (*file).getFilename().c_str();
    282     // Although cgicc documentation says this will be the tail filename,
    283     // upload from IE provides evidence to the contrary (although file upload
    284     // from Mozilla under Windows is OK).
    285    
    286     // Explicitly look for IE case, and remove prefix
    287     char* file_str;
    288     char* tstart = rindex(filename_str,'\\');
    289     if (tstart != NULL) {
    290       file_str = strdup(tstart);
    291     }
    292     else {
    293       file_str = strdup(filename_str);
    294     }
    295 
    296 
    297     text_t filename_textt(file_str);
    298     args["di1userfile"] = filename_textt; 
    299 
    300     int filesize = (*file).getDataLength();
    301     text_t filesize_textt(filesize);
    302     args["di1userfilesize"] = filesize_textt;
    303 
    304 
    305      text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
    306      bool tflag = mk_dir(tmpdir);
    307      text_t tmpfile = filename_cat(tmpdir,file_str);
    308      ofstream tout(tmpfile.getcstr());
    309      if(!tout.is_open()) {
    310        cerr << " Cannot write file " << tmpfile << endl;
    311      }
    312      else {
    313        (*file).writeToStream(tout);
    314      }
    315 
    316      free(file_str);
    317    }
    318 
    319    
    320    /* ***** TO BE DELETED WHEN I'M SURE ITS NOT NEEDED
    321    //obtain fields from form
    322    // Iterate through the vector, and store in args     
    323    for(const_form_iterator iter = formData->getElements().begin();
    324     iter != formData->getElements().end();
    325     ++iter) { 
    326     const char* name_cstr = iter->getName().c_str();
    327     const char* value_cstr = iter->getValue().c_str();
    328     args.setarg (name_cstr, value_cstr, cgiarg_t::cgi_arg);
    329    }
    330    */
    331 
     271  fileupload_t *fileupload = args.getargfile("di1userfileinfo");
     272  if (fileupload != NULL) {
     273    if (!(*fileupload).tmp_name.empty() && file_exists((*fileupload).tmp_name)) {
     274      // create the timestamp
     275      time_t timestamp = time(NULL);
     276      text_t timestamp_str(timestamp);
     277      args["di1timestamp"] = timestamp_str;
     278
     279      // set filename and size from the fileupload struct
     280      args["di1userfilesize"] = (*fileupload).size;
     281      args["di1userfile"] = (*fileupload).name;
     282      // copy the file into its temporary location
     283      text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
     284      bool tflag = mk_dir(tmpdir);
     285      text_t tmpfile = filename_cat(tmpdir,(*fileupload).name);
     286      if (!file_copy((*fileupload).tmp_name, tmpfile)) {
     287    cerr << "Depositor error: cannot save uploaded fileto  "<<tmpfile<<endl;
     288      } else {
     289    cerr << "Depositor: saved uploaded file to "<<tmpfile<<endl;
     290      }
     291    }
     292  }
     293 
    332294  if (current_page == "select") { 
    333295 
     
    393355    text_t lastpage_textt = args["di1lastpage"];
    394356    int lastpage = lastpage_textt.getint();
    395    
    396357    if (currpage > lastpage) {
    397  
    398358      lastpage++;
    399359      text_t lastpage_textt(lastpage);
     
    401361    }
    402362  }
    403 
    404363  return true;
    405364
     
    409368                          recptprotolistclass *protos, ostream &logout) {
    410369
    411   // define_internal_macros sets the following macros:
     370  // define_internal_macros sets some/all of the following macros (depending
     371  // on cgiargs):
    412372  //
    413   // list the macros when I have a chance
    414 
     373  // _pagescriptextra_
     374  // _header_
     375  // _depositorbar_
     376  // _textfailmsg_
     377  // _di1userfile_
     378  // _di1userfilesize_
    415379
    416380  text_t &depositor_page = args["p"];
     
    429393
    430394  if (depositor_page == "select") {
    431         set_fullnamemenu (disp, args, protos, logout);
     395    set_fullnamemenu (disp, args, protos, logout);
    432396  }
    433397
     
    446410
    447411  if((stepstring) == "step" || (depositor_page == "depositonly") ) {
    448       disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]);
    449       disp.setmacro("di1userfile","depositor",args["di1userfile"]);
    450   }
    451 
    452   //setup the depositor bar
     412    disp.setmacro("di1userfile","depositor",args["di1userfile"]);
     413    disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]);
     414  }
     415
     416  //set up the depositor bar
    453417  text_t depositorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n";
    454418
    455419  if(stepstring == "step") {
    456  
     420
    457421    here = depositor_page.begin();
    458422    text_t stepnums = substr(here+4,here+5);
     
    464428    // again, begin with the select bar...
    465429    //the first button - selecting a collection
    466 
    467430    for(int i = 1; i <= numsteps; i++) {
    468 
    469431      text_t numstr(i);
    470432      if(i <= lastpage && i == stepnum) {
     
    502464
    503465    depositorbar += "</tr></table>\n";
    504 
    505   }
    506 
     466   
     467  }
     468 
    507469  if ((depositor_page == "bildcancel") || (depositor_page == "bildfail")) {
    508 
    509 
     470 
    510471    for(int i = 1; i <= numsteps; i++) {
    511472
     
    533494
    534495  if(depositor_page == "bilddone"){
    535      
     496   
    536497    for(int i = 1; i <= numsteps; i++) {
    537498
     
    559520
    560521  if (depositor_page == "bildfail") {
     522 
    561523    text_t textfailmsg = "_textfailmsg";
    562524    textfailmsg.push_back(failcode);
     
    577539    disp.setmacro ("faillog", "depositor", dm_safe(faillog));
    578540  }
    579 
    580 
    581 
    582541}
     542
    583543
    584544//basic framework
     
    638598     
    639599  }
     600
    640601  if ((depositor_page == "bild") || (depositor_page == "depositoronly")) {
    641602
    642603    text_t filename_textt = args["di1userfile"];
    643604    text_t timestamp_str = args["di1timestamp"];
    644 
    645605    //check to make sure a file was uploaded
    646606    //if more than one upload occurred, the last one is taken
     
    649609    } else {
    650610   
    651 
    652611      text_t col_dirname = filename_cat(gsdlhome,"collect",args[macro_prefix+"dirname"]);
    653612      text_t import_dirname = filename_cat(col_dirname,"import");
     
    670629      text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
    671630      text_t tmpfile = filename_cat(tmpdir,filename_textt);
    672 
    673631      text_t filename = filename_cat(dirname, filename_textt); 
    674632      if(!file_copy(tmpfile, filename)) {
    675633    cerr << "Unable to copy " << tmpfile << " to " << filename << endl;
    676634      }
    677 
    678 
    679635      cerr << "*** filename = " << filename_textt << endl;
    680 
     636     
    681637      //write the metadata file
    682638      write_metadata_file(args, filename_textt, timestamp_str);
     
    714670  }
    715671 
    716 
    717672  return true;
    718673
Note: See TracChangeset for help on using the changeset viewer.