Changeset 3715 for trunk/gsdl/src/recpt
- Timestamp:
- 2003-01-28T10:01:25+13:00 (21 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/langaction.cpp
r3638 r3715 31 31 #include "gsdlunicode.h" 32 32 #include "langdb.h" 33 #include "receptionist.h" 33 34 #include "errno.h" 34 35 #include <sys/utsname.h> 35 36 36 37 37 /*====================* … … 49 49 *========================*/ 50 50 51 void add_visited_page (text_t dir, ostream & logout, text_t pageno) { 52 53 text_tarray oldpages; 54 bool visited = false; 55 56 // file 'logfile' contains all the page numbers, one number per line 57 text_t logfile = filename_cat(dir, "package_forms", "oldpages.log"); 58 59 //open the file as a read only file 60 ifstream readfile(logfile.getcstr(), ios::in); 61 62 // if file isn't opened, print error and return 63 if (!readfile) { 64 logout << "IN File " << logfile.getcstr() << " could not be found.\n"; 65 return; 66 } 67 68 // go through file, pushing each page number on to the end of a text_tarray 69 while (readfile.getline(temp, BUFFSIZE-1)) { 70 text_t t_temp = temp; 71 oldpages.push_back(temp); 72 if (strcmp(pageno.getcstr(),t_temp.getcstr()) == 0) { 73 visited = true; 74 } 75 } 76 readfile.close(); 77 78 if (visited == false) { 79 ofstream writefile(logfile.getcstr(), ios::out); 80 81 for (text_tarray::iterator page_itr = oldpages.begin(); 82 page_itr != oldpages.end(); 83 page_itr++) { 84 85 writefile << *page_itr <<endl; 86 } 87 time_t seconds; 88 seconds = time(NULL); 89 90 if (pageno == "2") 91 writefile << "1" <<endl; 92 93 writefile << pageno <<endl; 94 95 logout << "ADDING PAGE " << pageno.getcstr() << " " << seconds <<endl; 96 97 writefile.close(); 98 } 99 } 51 100 // gets the list of packages/files that contain the content of the web-forms 52 101 text_tarray get_pagenos(text_t dir, ostream &logout) … … 98 147 } 99 148 149 150 // set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros 151 // reponse contains 1 metadata field (Title) 152 100 153 bool langaction::init (ostream & /*logout*/) { 101 154 … … 176 229 void langaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/, 177 230 response_t &response,text_t &response_data, 178 ostream & /*logout*/) {231 ostream & logout) { 179 232 response = content; 180 233 response_data = "text/html"; … … 183 236 void langaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 184 237 recptprotolistclass *protos, ostream &logout) { 238 185 239 text_t text = ""; 186 240 text_t cmd = ""; … … 190 244 text_t pageno =""; 191 245 text_t lang = ""; 246 text_t baselanguage = ""; 247 248 //creates output stream to argsfile (dir is gsdlhome/tmp/lang) 249 text_t argsfile = filename_cat(dir, "arguments.arg"); 250 ofstream argsout(argsfile.getcstr(), ios::out); 251 252 //informs user and returns if output stream not opened 253 if(!argsout) { 254 logout << "File " << argsfile.getcstr() << " could not be opened\n"; 255 return; 256 } 257 258 //ensures access permissions make the file world writable 259 text_t changemode = "chmod a+w "; 260 changemode += argsfile; 261 gsdl_system(changemode, false, logout); 262 263 //write out the cgiargsclass passes as a parameter to the subroutine to the argsout file 264 argsout << args; 265 266 // utf8outconvertclass text_tutf8; 267 268 // for (cgiargsclass::iterator args_itr = args.begin(); 269 // args_itr != args.end(); 270 // args_itr++) { 271 272 // if(text_t_substring(*args_itr->first, pageno, logout)) { 273 // argsout << text_t2utf8 << "\"" << args_itr->first << "\"=\n\"" 274 // << (args_itr->second).value << "\"\n"; 275 // } 276 // } 277 278 //close the argsout output stream 279 argsout.close(); 280 281 if (args["nextlink"] != "") { 282 add_visited_page(dir,logout,args["nextlink"]); 283 } 284 285 //sets the current foreign language 286 if (args["ownchoice"] != "") { 287 lang = args["ownchoice"]; 288 } 289 else if (args["hiddenlanguage"] != "") { 290 lang = args["hiddenlanguage"]; 291 } 292 else { 293 lang = args["language"]; 294 } 295 296 //sets current base language 297 if (args["baselanguage"] != "") { 298 baselanguage = args["baselanguage"]; 299 } 192 300 193 301 // argument for page is of the form 'macrofile_pageno' so … … 199 307 if (splitarray.size() > 1) 200 308 pageno = splitarray[splitarray.size()-1]; 201 202 if (pageno == "picklanguage") 309 310 if (pageno == "fromsearch") { 311 text_t macroname = args["macroname"]; 312 text_t macrotext = args["macrotext"]; 313 314 logout << "macro data " << macroname.getcstr() << macrotext.getcstr() <<endl; 315 316 //calls the translator file to create HTML files 317 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "fromsearch.pl") + " " + macroname + " " + macrotext; 318 logout << "COMMAND: " << cmd.getcstr() <<endl; 319 320 if ((gsdl_system(cmd, true, logout)) != 0) { 321 logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 322 return; 323 } 324 325 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 326 return; 327 } 328 329 if (pageno == "picklanguage") { 203 330 pageno = "1"; 204 205 if (pageno.empty()) 331 332 //calls the translator file to create HTML files 333 // cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "translator.pl") + " " + lang + " " + baselanguage; 334 // if ((gsdl_system(cmd, true, logout)) != 0) { 335 // logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 336 // return; 337 // } 338 } 339 340 //generates the picklanguage page 341 if (pageno.empty()) { 206 342 pageno = "picklanguage"; 207 208 //produce the picklanguage webpage 209 if (pageno == "picklanguage") { 343 logout << "@ the 1st pg\n"; 210 344 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "picklanguage.pl"); 345 logout << cmd.getcstr() << " PICKLANGUAGE\n" <<endl; 211 346 if(gsdl_system(cmd,true,logout) != 0) 212 347 return; 213 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text); 348 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 349 214 350 return; 215 351 } 216 217 //creates output stream to argsfile (dir is gsdlhome/tmp/lang) 218 text_t argsfile = filename_cat(dir, "arguments.arg"); 219 ofstream argsout(argsfile.getcstr(), ios::out); 220 221 //informs user and returns if output stream not opened 222 if(!argsout) { 223 logout << "File " << argsfile.getcstr() << " could not be opened\n"; 224 return; 225 } 226 227 //ensures access permissions make the file world writable 228 text_t changemode = "chmod a+w "; 229 changemode += argsfile; 230 gsdl_system(changemode, false, logout); 231 232 //write out the cgiargsclass passes as a parameter to the subroutine to the argsout file 233 argsout << args; 234 235 //close the argsout output stream 236 argsout.close(); 237 238 //sets the current foreign language 239 if (args["ownchoice"] != "") { 240 lang = args["ownchoice"]; 241 } 242 else if (args["hiddenlanguage"] != "") { 243 lang = args["hiddenlanguage"]; 244 } 245 else { 246 lang = args["language"]; 247 } 248 text_t baselanguage = ""; 249 250 //sets current base language 251 if (args["baselanguage"] != "") { 252 baselanguage = args["baselanguage"]; 253 } 254 255 256 //calls the translator file to create HTML files 257 cmd = "perl " + filename_cat(gsdlhome, "bin", "script", "translator.pl") + " " + lang + " " + baselanguage; 258 259 if ((gsdl_system(cmd, true, logout)) != 0) { 260 logout << "Process " << cmd.getcstr() << " did not execute.../;-D\n"; 261 return; 262 } 263 352 264 353 //if no more pages will set pageno to thankyou script 265 354 pagenos = get_pagenos(dir,logout); 266 if (pagenos.empty()) 355 356 if (pagenos.empty() && pageno == "") 267 357 pageno = "thankyou"; 268 269 358 270 359 text_t &submitargs = args[pageno]; 271 text_t submit = "SUBMIT TRANSLATION >>";360 text_t submit = "SUBMIT TRANSLATION"; 272 361 273 362 //if the SUBMIT TRANSLATION >> button has been pushed … … 286 375 page_itr != pagenos.end(); 287 376 page_itr++) { 288 377 logout << pageno.getcstr() << " page number before" <<endl; 378 289 379 if (*page_itr == pageno) { 290 380 page_itr++; … … 296 386 break; 297 387 } 388 389 logout << pageno.getcstr() << " page number after" <<endl; 298 390 } 299 } 300 //want it to automatically load the next page here instead of reloading page 301 //that has just been translated with everything empty again. 302 303 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text); 391 add_visited_page(dir,logout,pageno); 392 } 393 394 pagenos = get_pagenos(dir,logout); 395 logout << "PAGENOS... " << pagenos.size() <<endl; 396 define_webpage(disp, protos, logout, pageno, lang, dir, pagenos, text, baselanguage); 304 397 } 305 398 306 399 void langaction::define_webpage (displayclass &disp, 307 400 recptprotolistclass *protos, ostream &logout, 308 text_t &pageno, text_t &lang, text_t &dir,309 text_tarray &pagenos, text_t &text ) {401 text_t pageno, text_t &lang, text_t &dir, 402 text_tarray &pagenos, text_t &text, text_t &baselanguage) { 310 403 311 404 // produces HTML page with the current pages contents … … 324 417 325 418 /* ============================ START WEB-FORM HTML CODE ============================ */ 419 text += "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>"; 420 326 421 text += "\n<input type=hidden name=\"a\" value=\"lang\">"; 327 422 text += "\n<input type=hidden name=\"p\" value=\"translang_"; … … 329 424 text += "\">\n"; 330 425 331 text += "<strong><br>\n"; 332 text += "</center><img src=\"_httpimg_/gsdlhead.gif\"><center><p>"; 333 text += "<img src=\"_httpimg_/divb.gif\"><p>"; 334 text += "<font size=\"7\">Greenstone Language Translation Facility</font></strong><p>\n"; 335 426 text += "_texttranshead_"; 427 336 428 337 429 //if not a special case page display translation info 338 430 if ((pageno != "thankyou") && (pageno !="picklanguage")) { 339 text += "<center><strong>You are currently translating page "; 431 432 logout << "PAGENOS " << pagenos.size() <<endl; 433 434 text += "<center><strong> _textcurrpage_ "; 340 435 text += pageno; 341 text += " of";436 text += " _textof_ "; 342 437 text += pagenos.size(); 343 text += " in to ";344 text += lang;345 438 text += "</strong></center><p><p>\n"; 346 439 } 347 440 441 utf8outconvertclass text_tutf8; 442 348 443 //read in HTML from file 349 444 while(readfile.getline(temp, BUFFSIZE-1)) { 350 445 text_t t_temp = temp; 351 446 text += t_temp; 447 448 //logout << t_temp.getcstr() <<endl; 449 450 // text_t2utf8.setinput(&t_temp); 451 // char *buffer = new char[t_temp.size()]; 452 // size_t num_chars; 453 // convertclass::status_t status; 454 // text_t2utf8.convert(buffer, t_temp.size(), num_chars, status); 455 // logout << buffer <<endl; 456 // delete buffer; 457 458 // for (cgiargsclass::iterator args_itr = args.begin(); 459 // args_itr != args.end(); 460 // args_itr++) { 461 462 // if(text_t_substring(*args_itr->first, pageno, logout)) { 463 // argsout << text_t2utf8 << "\"" << args_itr->first << "\"=\n\"" 464 // << (args_itr->second).value << "\"\n"; 465 // } 466 // } 467 468 // logout << t_temp.getcstr() <<endl; 352 469 text += "\n"; 353 470 } … … 356 473 //if not a special case page display translation info 357 474 if ((pageno != "thankyou") && (pageno != "picklanguage")) { 358 text += "<center><strong> You are currently translating page";475 text += "<center><strong> _textcurrpage_ "; 359 476 text += pageno; 360 text += " of";477 text += " _textof_ "; 361 478 text += pagenos.size(); 362 text += " in to "; 363 text += lang; 364 text += "</strong></center><br>\n"; 479 text += "</strong><br>\n"; 480 481 482 text_tarray oldpages; 483 484 // file 'logfile' contains all the page numbers, one number per line 485 text_t logfile = filename_cat(dir, "package_forms", "oldpages.log"); 486 487 //open the file as a read only file 488 ifstream reader(logfile.getcstr(), ios::in); 489 490 // if file isn't opened, print error and return 491 if (!reader) { 492 logout << "IN File " << logfile.getcstr() << " could not be found.\n"; 493 } 494 495 // go through file, pushing each page number on to the end of a text_tarray 496 while (reader.getline(temp, BUFFSIZE-1)) { 497 text += "<a href=\"_gwcgi_?a=lang&p=translang_"; 498 text += temp; 499 text += "&baselanguage="; 500 text += baselanguage; 501 text += "&language="; 502 text += lang; 503 text += "\"><strong>"; 504 text += temp; 505 text += "</strong></a>\n"; 506 507 } 508 509 text_t temp2 = ""; 510 511 for (text_tarray::iterator page_itr = pagenos.begin(); 512 page_itr != pagenos.end(); 513 page_itr++) { 514 515 logout << "TEMP2 " << temp2.getcstr() <<endl; 516 logout << "PAGENO " << pageno.getcstr() <<endl; 517 518 if (*page_itr == pageno) { 519 page_itr++; 520 if (page_itr != pagenos.end()) 521 temp2 = *page_itr; 522 else 523 temp2 = "thankyou"; 524 525 logout << "TEMP2 " << temp2.getcstr() <<endl; 526 logout << "PAGENO " << pageno.getcstr() <<endl; 527 528 break; 529 } 530 } 531 532 text += "<a href=\"_gwcgi_?a=lang&p=translang_"; 533 text += temp2; 534 text += "&baselanguage="; 535 text += baselanguage; 536 text += "&language="; 537 text += lang; 538 text += "&nextlink="; 539 text += pageno; 540 text += "\"><strong>"; 541 text += "NEXT>>"; 542 text += "</strong></a>\n"; 543 544 text += "</body></html>\n"; 545 546 reader.close(); 365 547 } 366 367 368 548 /* ============================ END WEB-FORM HTML CODE ============================ */ 549 369 550 370 551 // THE FOLLOWING MACROS ARE DEFINED IN translang.dm MACRO FILE … … 375 556 // disp.setmacro("formaction", "translang", "/cgi-bin/dg5/library"); 376 557 disp.setmacro("formaction", "translang", "_gwcgi_"); 558 559 text_t navigationbar = "<!-- Navigation Bar -->\n"; 560 navigationbar += "<table width=\"100%\" cellspacing=0 cellpadding=0>"; 561 navigationbar += "<tr valign=top><td rowspan=2 align=left>_imagecollection_</td>"; 562 navigationbar += "<td align=right>_javalinks_</td><td>"; 563 navigationbar += "_imageserch_</td></tr></table>"; 564 navigationbar += "\n</nobr>\n"; 565 navigationbar += "<!-- End of Navigation Bar -->\n"; 566 disp.setmacro ("navigationbar", "translang", navigationbar); 377 567 378 568 } … … 388 578 << ("_" + arg_p + ":footer_\n"); 389 579 580 logout << outconvert << disp << ("_" + arg_p + ":header_\n"); 581 390 582 return true; 391 583 } 392 584 393 585 394 395 -
trunk/gsdl/src/recpt/langaction.h
r3632 r3715 65 65 void define_webpage (displayclass &disp, 66 66 recptprotolistclass *protos, ostream &logout, 67 text_t &pageno, text_t &lang, text_t &dir,68 text_tarray &pagenos, text_t &text );67 text_t pageno, text_t &lang, text_t &dir, 68 text_tarray &pagenos, text_t &text, text_t &baselanguage); 69 69 70 70 71 71 }; 72 72
Note:
See TracChangeset
for help on using the changeset viewer.