Changeset 12516
- Timestamp:
- 2006-08-24T11:18:36+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/depositoraction.cpp
r12480 r12516 65 65 #include <iostream> 66 66 //#include <cstdlib> 67 #include "cgicc/CgiDefs.h"68 #include "cgicc/Cgicc.h"69 70 using namespace cgicc;71 72 extern Cgicc *formData;73 67 74 68 depositoraction::depositoraction () … … 78 72 lastpage = 0; 79 73 80 do_udcol = false;81 82 //remove these if removed from depositoraction.h83 badsources = false;84 failedsources.erase(failedsources.begin(), failedsources.end());85 86 74 cgiarginfo arg_ainfo; 87 75 arg_ainfo.shortname = "a"; … … 109 97 arg_ainfo.savedarginfo = cgiarginfo::must; 110 98 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; 111 111 112 112 //the name of the file to be added … … 147 147 argsinfo.addarginfo (NULL, arg_ainfo); 148 148 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 disk155 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); 156 156 157 157 arg_ainfo.shortname = "di1dirname"; … … 171 171 argsinfo.addarginfo (NULL, arg_ainfo); 172 172 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 disk179 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 disk187 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" page198 // via the "changing an existing collection" page199 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 // wi ll be set if we arrived at the "source data" page208 // via the "changing an existing collection" page173 // 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 209 209 arg_ainfo.shortname = "di1esrce"; 210 210 arg_ainfo.longname = "depositor specific"; … … 215 215 argsinfo.addarginfo (NULL, arg_ainfo); 216 216 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 disk224 argsinfo.addarginfo (NULL, arg_ainfo);225 226 //we don't need this in the depositor227 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 disk234 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); 235 235 236 236 } … … 239 239 } 240 240 241 //I think we need this too 241 242 242 bool depositoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, recptprotolistclass * protos, ostream &logout) { 243 243 244 245 244 wizardaction::check_cgiargs(argsinfo,args,protos,logout); 246 247 245 248 246 text_t ¤t_page = args["p"]; … … 254 252 // to read from the key.db database at the same time. 255 253 256 //right now, anyone can do anything until it's ti le to build254 //right now, anyone can do anything until it's time to build 257 255 if (current_page == "select") { 258 256 //authenticate the user if authentication is available … … 271 269 // Consider recoding at some point in the future. 272 270 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 332 294 if (current_page == "select") { 333 295 … … 393 355 text_t lastpage_textt = args["di1lastpage"]; 394 356 int lastpage = lastpage_textt.getint(); 395 396 357 if (currpage > lastpage) { 397 398 358 lastpage++; 399 359 text_t lastpage_textt(lastpage); … … 401 361 } 402 362 } 403 404 363 return true; 405 364 } … … 409 368 recptprotolistclass *protos, ostream &logout) { 410 369 411 // define_internal_macros sets the following macros: 370 // define_internal_macros sets some/all of the following macros (depending 371 // on cgiargs): 412 372 // 413 // list the macros when I have a chance 414 373 // _pagescriptextra_ 374 // _header_ 375 // _depositorbar_ 376 // _textfailmsg_ 377 // _di1userfile_ 378 // _di1userfilesize_ 415 379 416 380 text_t &depositor_page = args["p"]; … … 429 393 430 394 if (depositor_page == "select") { 431 395 set_fullnamemenu (disp, args, protos, logout); 432 396 } 433 397 … … 446 410 447 411 if((stepstring) == "step" || (depositor_page == "depositonly") ) { 448 disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]);449 disp.setmacro("di1userfile","depositor",args["di1userfile"]);450 } 451 452 //set up the depositor bar412 disp.setmacro("di1userfile","depositor",args["di1userfile"]); 413 disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]); 414 } 415 416 //set up the depositor bar 453 417 text_t depositorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n"; 454 418 455 419 if(stepstring == "step") { 456 420 457 421 here = depositor_page.begin(); 458 422 text_t stepnums = substr(here+4,here+5); … … 464 428 // again, begin with the select bar... 465 429 //the first button - selecting a collection 466 467 430 for(int i = 1; i <= numsteps; i++) { 468 469 431 text_t numstr(i); 470 432 if(i <= lastpage && i == stepnum) { … … 502 464 503 465 depositorbar += "</tr></table>\n"; 504 505 } 506 466 467 } 468 507 469 if ((depositor_page == "bildcancel") || (depositor_page == "bildfail")) { 508 509 470 510 471 for(int i = 1; i <= numsteps; i++) { 511 472 … … 533 494 534 495 if(depositor_page == "bilddone"){ 535 496 536 497 for(int i = 1; i <= numsteps; i++) { 537 498 … … 559 520 560 521 if (depositor_page == "bildfail") { 522 561 523 text_t textfailmsg = "_textfailmsg"; 562 524 textfailmsg.push_back(failcode); … … 577 539 disp.setmacro ("faillog", "depositor", dm_safe(faillog)); 578 540 } 579 580 581 582 541 } 542 583 543 584 544 //basic framework … … 638 598 639 599 } 600 640 601 if ((depositor_page == "bild") || (depositor_page == "depositoronly")) { 641 602 642 603 text_t filename_textt = args["di1userfile"]; 643 604 text_t timestamp_str = args["di1timestamp"]; 644 645 605 //check to make sure a file was uploaded 646 606 //if more than one upload occurred, the last one is taken … … 649 609 } else { 650 610 651 652 611 text_t col_dirname = filename_cat(gsdlhome,"collect",args[macro_prefix+"dirname"]); 653 612 text_t import_dirname = filename_cat(col_dirname,"import"); … … 670 629 text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str); 671 630 text_t tmpfile = filename_cat(tmpdir,filename_textt); 672 673 631 text_t filename = filename_cat(dirname, filename_textt); 674 632 if(!file_copy(tmpfile, filename)) { 675 633 cerr << "Unable to copy " << tmpfile << " to " << filename << endl; 676 634 } 677 678 679 635 cerr << "*** filename = " << filename_textt << endl; 680 636 681 637 //write the metadata file 682 638 write_metadata_file(args, filename_textt, timestamp_str); … … 714 670 } 715 671 716 717 672 return true; 718 673
Note:
See TracChangeset
for help on using the changeset viewer.