Changeset 2401 for trunk/gsdl/src
- Timestamp:
- 2001-05-11T15:58:47+12:00 (23 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/collectoraction.cpp
r2379 r2401 52 52 disabled = true; 53 53 do_mkcol = false; 54 badsources = false; 55 failedsources.erase(failedsources.begin(), failedsources.end()); 54 56 gsdlosc = NULL; 55 57 gsdlhomec = NULL; … … 140 142 argsinfo.addarginfo (NULL, arg_ainfo); 141 143 142 arg_ainfo.shortname = "bc1inputdir1";143 arg_ainfo.longname = "collector specific";144 arg_ainfo.multiplechar = true;145 arg_ainfo.defaultstatus = cgiarginfo::weak;146 arg_ainfo.argdefault = "";147 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk148 argsinfo.addarginfo (NULL, arg_ainfo);149 150 arg_ainfo.shortname = "bc1inputdir2";151 arg_ainfo.longname = "collector specific";152 arg_ainfo.multiplechar = true;153 arg_ainfo.defaultstatus = cgiarginfo::weak;154 arg_ainfo.argdefault = "";155 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk156 argsinfo.addarginfo (NULL, arg_ainfo);157 158 arg_ainfo.shortname = "bc1inputdir3";159 arg_ainfo.longname = "collector specific";160 arg_ainfo.multiplechar = true;161 arg_ainfo.defaultstatus = cgiarginfo::weak;162 arg_ainfo.argdefault = "";163 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk164 argsinfo.addarginfo (NULL, arg_ainfo);165 166 arg_ainfo.shortname = "bc1inputdir4";167 arg_ainfo.longname = "collector specific";168 arg_ainfo.multiplechar = true;169 arg_ainfo.defaultstatus = cgiarginfo::weak;170 arg_ainfo.argdefault = "";171 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk172 argsinfo.addarginfo (NULL, arg_ainfo);173 174 144 // only set when one of the fields was changed in 175 145 // the "collection info" page … … 226 196 arg_ainfo.argdefault = "0"; 227 197 arg_ainfo.savedarginfo = cgiarginfo::must; 198 argsinfo.addarginfo (NULL, arg_ainfo); 199 200 arg_ainfo.shortname = "bc1filenum"; 201 arg_ainfo.longname = "collector specific"; 202 arg_ainfo.multiplechar = true; 203 arg_ainfo.defaultstatus = cgiarginfo::weak; 204 arg_ainfo.argdefault = "1"; 205 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 206 argsinfo.addarginfo (NULL, arg_ainfo); 207 208 arg_ainfo.shortname = "bc1httpnum"; 209 arg_ainfo.longname = "collector specific"; 210 arg_ainfo.multiplechar = true; 211 arg_ainfo.defaultstatus = cgiarginfo::weak; 212 arg_ainfo.argdefault = "1"; 213 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 214 argsinfo.addarginfo (NULL, arg_ainfo); 215 216 arg_ainfo.shortname = "bc1ftpnum"; 217 arg_ainfo.longname = "collector specific"; 218 arg_ainfo.multiplechar = true; 219 arg_ainfo.defaultstatus = cgiarginfo::weak; 220 arg_ainfo.argdefault = "1"; 221 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 222 argsinfo.addarginfo (NULL, arg_ainfo); 223 224 arg_ainfo.shortname = "bc1fileinput"; 225 arg_ainfo.longname = "collector specific"; 226 arg_ainfo.multiplechar = true; 227 arg_ainfo.multiplevalue = true; 228 arg_ainfo.defaultstatus = cgiarginfo::weak; 229 arg_ainfo.argdefault = ""; 230 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 231 argsinfo.addarginfo (NULL, arg_ainfo); 232 233 arg_ainfo.shortname = "bc1httpinput"; 234 arg_ainfo.longname = "collector specific"; 235 arg_ainfo.multiplechar = true; 236 arg_ainfo.multiplevalue = true; 237 arg_ainfo.defaultstatus = cgiarginfo::weak; 238 arg_ainfo.argdefault = ""; 239 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 240 argsinfo.addarginfo (NULL, arg_ainfo); 241 242 arg_ainfo.shortname = "bc1ftpinput"; 243 arg_ainfo.longname = "collector specific"; 244 arg_ainfo.multiplechar = true; 245 arg_ainfo.multiplevalue = true; 246 arg_ainfo.defaultstatus = cgiarginfo::weak; 247 arg_ainfo.argdefault = ""; 248 arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk 249 argsinfo.addarginfo (NULL, arg_ainfo); 250 251 // will be set when we've just come from the "source data" page 252 arg_ainfo.shortname = "bc1fromsrce"; 253 arg_ainfo.longname = "collector specific"; 254 arg_ainfo.multiplechar = false; 255 arg_ainfo.defaultstatus = cgiarginfo::weak; 256 arg_ainfo.argdefault = "0"; 257 arg_ainfo.savedarginfo = cgiarginfo::mustnot; 228 258 argsinfo.addarginfo (NULL, arg_ainfo); 229 259 } … … 323 353 enum source_t {default_arg, compressed_arg, cgi_arg, program_arg}; 324 354 text_tmap saved_args; 325 saved_args["bc1inputdir1"] = "";326 saved_args["bc1inputdir2"] = "";327 saved_args["bc1inputdir3"] = "";328 saved_args["bc1inputdir4"] = "";329 355 saved_args["bc1fullname"] = ""; 330 356 saved_args["bc1contactemail"] = ""; 331 357 saved_args["bc1aboutdesc"] = ""; 332 358 saved_args["bc1clone"] = ""; 359 saved_args["bc1clonecol"] = ""; 360 saved_args["bc1filenum"] = ""; 361 saved_args["bc1httpnum"] = ""; 362 saved_args["bc1ftpnum"] = ""; 363 saved_args["bc1fileinput"] = ""; 364 saved_args["bc1httpinput"] = ""; 365 saved_args["bc1ftpinput"] = ""; 333 366 334 367 // update the argdb database with any arguments that were set … … 465 498 } 466 499 delete fbldc; 500 } 501 } 502 503 if (args["bc1fromsrce"] == "1") { 504 505 // we've just come from the "source data" page so we need to check that 506 // input sources are valid 507 if (!check_sources(args, logout)) { 508 args["p"] = "srce"; 467 509 } 468 510 } … … 701 743 } 702 744 703 // set the _fullnamemenu_ macro (and _warnindex_ if we're on the "srce" page) 745 // set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if 746 // we're on the "srce" page) 704 747 void collectoraction::set_fullnamemenu (displayclass &disp, cgiargsclass &args, 705 748 recptprotolistclass *protos, ostream &logout) { … … 719 762 text_tarray fullnames; 720 763 vector<bool> write_protected; 764 bool is_selected = false; 721 765 int selected_index = 0; 722 766 int index = 0; … … 727 771 if ((*rprotolist_here).p != NULL) { 728 772 729 // don't include z39.50 collection 773 // don't include z39.50 collections 730 774 comerror_t err = noError; 731 775 if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") { … … 760 804 else write_protected.push_back(false); 761 805 762 if (*collist_here == currentname) selected_index = index; 806 if (*collist_here == currentname) { 807 is_selected = true; 808 selected_index = index; 809 } 763 810 index ++; 764 811 } … … 773 820 text_t warnindex; 774 821 text_t fullnamemenu = "<select name=\"bc1dirname\">\n"; 775 if (current_page == "srce") fullnamemenu = "<select name=\"bc1clonecol\" onChange=\"menuchange();\">\n"; 822 if (current_page == "srce") { 823 fullnamemenu = "<select name=\"bc1clonecol\" onChange=\"menuchange();\">\n"; 824 fullnamemenu += "<option value=defaultstructure"; 825 if (!is_selected) fullnamemenu += " selected>"; 826 else fullnamemenu.push_back('>'); 827 fullnamemenu += "default structure\n"; 828 } 776 829 for (int i = 0; i < index; i ++) { 777 830 // don't want write protected collections in list on "change existing … … 779 832 if (write_protected[i] && current_page == "existing") continue; 780 833 fullnamemenu += "<option value=\"" + dirnames[i] + "\""; 781 if (i == selected_index) fullnamemenu += " selected"; 834 if ((i == 0 && !is_selected && current_page != "srce") || 835 (is_selected && i == selected_index)) { 836 fullnamemenu += " selected"; 837 selected_index++; 838 is_selected = false; 839 } 782 840 fullnamemenu.push_back ('>'); 783 841 fullnamemenu += fullnames[i]; … … 787 845 // (if creating clone collection list) 788 846 if (current_page == "srce") { 789 if (!first) warnindex.push_back(','); 847 if (first) warnindex += "0,"; 848 else warnindex.push_back(','); 790 849 if (uses_weird_plugin (dirnames[i])) { 791 850 warnindex += text_t (1); … … 798 857 fullnamemenu += "</select>\n"; 799 858 800 if (!first) { 801 disp.setmacro ("fullnamemenu", "collector", fullnamemenu); 802 if (current_page == "srce") 803 disp.setmacro ("warnindex", "collector", warnindex); 804 } 859 disp.setmacro ("fullnamemenu", "collector", fullnamemenu); 860 if (current_page == "srce") { 861 disp.setmacro ("warnindex", "collector", warnindex); 862 disp.setmacro ("selectedindex", "collector", text_t(selected_index)); 863 } 864 } 865 866 // set _filelist_, _httplist_, _ftplist_ and _badsources_ macros 867 void collectoraction::set_inputsourceboxes (displayclass &disp, cgiargsclass &args, 868 ostream &logout) { 869 870 if (badsources) disp.setmacro ("badsources", "collector", "1"); 871 872 int numfileboxes = args["bc1filenum"].getint(); 873 int numhttpboxes = args["bc1httpnum"].getint(); 874 int numftpboxes = args["bc1ftpnum"].getint(); 875 876 text_t filelist = get_source_box(args["bc1fileinput"], numfileboxes, "file"); 877 text_t httplist = get_source_box(args["bc1httpinput"], numhttpboxes, "http"); 878 text_t ftplist = get_source_box(args["bc1ftpinput"], numftpboxes, "ftp"); 879 880 disp.setmacro("filelist", "collector", dm_safe(filelist)); 881 disp.setmacro("httplist", "collector", dm_safe(httplist)); 882 disp.setmacro("ftplist", "collector", dm_safe(ftplist)); 883 884 // reset badsources and failedsources variables 885 badsources = false; 886 failedsources.erase(failedsources.begin(), failedsources.end()); 887 } 888 889 text_t collectoraction::get_source_box (text_t inputarg, int numboxes, text_t boxtype) { 890 891 text_tarray files; 892 // this relies on filenames/URLs/ftp addresses not being able to contain 893 // commas 894 splitchar (inputarg.begin(), inputarg.end(), ',', files); 895 896 text_t rv = "<table border=0>\n"; 897 for (int i = 0; i < numboxes; i++) { 898 rv += "<tr><td><input type=text name=\"bc1" + boxtype + "input\" value=\""; 899 if (i < files.size()) { 900 rv += files[i]; 901 } 902 rv += "\" size=50></td>"; 903 if (badsources) { 904 if ((i < files.size()) && (!files[i].empty())) { 905 if (failedsources[files[i]] == "1") { 906 rv += "<td width=40>no</td>"; 907 } else { 908 rv += "<td width=40>yes</td>"; 909 } 910 } else { 911 rv += "<td width=40></td>"; 912 } 913 } 914 if (i+1 == numboxes) { 915 rv += "<td><a href=\"javascript:more('" + boxtype + "')\">more</a></td></tr>\n"; 916 } else { 917 rv += "<td></td></tr>\n"; 918 } 919 } 920 rv += "</table>\n"; 921 922 return rv; 805 923 } 806 924 … … 836 954 837 955 // define it as a macro 838 disp.setmacro("cfgfile", "collector",dm_safe(cfgtext));956 disp.setmacro("cfgfile", "collector", dm_safe(cfgtext)); 839 957 840 958 } else { … … 887 1005 // _gsdlhome_ - the gsdlhome path (dm_safe) 888 1006 1007 // _filelist_ -- these three display "input source" text boxes 1008 // _httplist_ -- for the "source data" page 1009 // _ftplist_ -- 1010 1011 // _badsources_ -- will be set to "1" if we've come from the 1012 // "source data" page and there's a problem 1013 // with the input sources 1014 889 1015 text_t &collector_page = args["p"]; 890 1016 int esrce = args["bc1esrce"].getint(); … … 1030 1156 if (collector_page == "bildstatus") 1031 1157 set_statusline (disp, args, logout); 1158 if (collector_page == "srce") { 1159 set_inputsourceboxes (disp, args, logout); 1160 } 1032 1161 1033 1162 disp.setmacro ("gsdlhome", "collector", dm_safe(gsdlhome)); … … 1507 1636 } 1508 1637 1509 if (!args["bc1inputdir1"].empty()) 1510 options += " -download \"" + args["bc1inputdir1"] + "\""; 1511 if (!args["bc1inputdir2"].empty()) 1512 options += " -download \"" + args["bc1inputdir2"] + "\""; 1513 if (!args["bc1inputdir3"].empty()) 1514 options += " -download \"" + args["bc1inputdir3"] + "\""; 1515 if (!args["bc1inputdir4"].empty()) 1516 options += " -download \"" + args["bc1inputdir4"] + "\""; 1638 text_tarray files; 1639 text_t filevals = args["bc1fileinput"]; 1640 // this relies on filenames not being able to contain commas 1641 splitchar (filevals.begin(), filevals.end(), ',', files); 1642 text_tarray::const_iterator here = files.begin(); 1643 text_tarray::const_iterator end = files.end(); 1644 while (here != end) { 1645 options += " -download \"" + *here + "\""; 1646 here ++; 1647 } 1648 text_tarray https; 1649 text_t httpvals = args["bc1httpinput"]; 1650 // this relies on URLs not being able to contain commas 1651 splitchar (httpvals.begin(), httpvals.end(), ',', https); 1652 here = https.begin(); 1653 end = https.end(); 1654 while (here != end) { 1655 options += " -download \"" + *here + "\""; 1656 here ++; 1657 } 1658 text_tarray ftps; 1659 text_t ftpvals = args["bc1ftpinput"]; 1660 // this relies on ftp addresses not being able to contain commas 1661 splitchar (ftpvals.begin(), ftpvals.end(), ',', ftps); 1662 here = ftps.begin(); 1663 end = ftps.end(); 1664 while (here != end) { 1665 options += " -download \"" + *here + "\""; 1666 here ++; 1667 } 1517 1668 1518 1669 if (logevents) { … … 1707 1858 return header; 1708 1859 } 1860 1861 bool collectoraction::check_sources (cgiargsclass &args, ostream &logout) { 1862 1863 bool found = false; 1864 1865 // check local filesystem for file:// sources 1866 text_tarray files; 1867 text_t filevals = args["bc1fileinput"]; 1868 // this relies on filenames not being able to contain commas 1869 splitchar (filevals.begin(), filevals.end(), ',', files); 1870 text_tarray::const_iterator here = files.begin(); 1871 text_tarray::const_iterator end = files.end(); 1872 while (here != end) { 1873 text_t file = format_url(*here); 1874 if (!file_exists(file) && !directory_exists(file)) { 1875 failedsources[*here] = "1"; 1876 badsources = true; 1877 } 1878 found = true; 1879 here ++; 1880 } 1881 1882 // ping http:// sources 1883 files.erase(files.begin(), files.end()); 1884 text_t httpvals = args["bc1httpinput"]; 1885 // this relies on URLs not being able to contain commas 1886 splitchar (httpvals.begin(), httpvals.end(), ',', files); 1887 here = files.begin(); 1888 end = files.end(); 1889 while (here != end) { 1890 if (gsdl_system ("perl -S ping.pl -quiet http://" + format_url(*here), true, logout)) { 1891 failedsources[*here] = "1"; 1892 badsources = true; 1893 } 1894 found = true; 1895 here++; 1896 } 1897 1898 // ping ftp:// sources 1899 files.erase(files.begin(), files.end()); 1900 text_t ftpvals = args["bc1ftpinput"]; 1901 // this relies on FTP addresses not being able to contain commas 1902 splitchar (ftpvals.begin(), ftpvals.end(), ',', files); 1903 here = files.begin(); 1904 end = files.end(); 1905 while (here != end) { 1906 if (gsdl_system ("perl -S ping.pl -quiet ftp://" + format_url(*here), true, logout)) { 1907 failedsources[*here] = "1"; 1908 badsources = true; 1909 } 1910 found = true; 1911 here++; 1912 } 1913 1914 // set badsources if there weren't any sources at all 1915 if (!found) badsources = true; 1916 1917 if (badsources) return false; 1918 return true; 1919 } 1920 1921 // format_url simply strips "http://", "ftp://", or "file://" off the 1922 // beginning of url if they're there 1923 text_t collectoraction::format_url (const text_t &url) { 1924 text_t::const_iterator begin = url.begin(); 1925 text_t::const_iterator end = url.end(); 1926 1927 if (url.size() >= 7) { 1928 text_t prefix = substr(begin, begin+7); 1929 if (prefix == "http://" || prefix == "file://") { 1930 return substr(begin+7, end); 1931 } 1932 } 1933 if (url.size() >= 6) { 1934 if (substr(begin, begin+6) == "ftp://") { 1935 return substr(begin+6, end); 1936 } 1937 } 1938 return url; 1939 } -
trunk/gsdl/src/recpt/collectoraction.h
r1778 r2401 45 45 bool do_mkcol; 46 46 47 bool badsources; 48 text_tmap failedsources; 49 47 50 text_t get_button (const text_t &thispage, const text_t &color, 48 51 const text_t &type, bool enabled); … … 50 53 void set_fullnamemenu (displayclass &disp, cgiargsclass &args, 51 54 recptprotolistclass *protos, ostream &logout); 55 56 void set_inputsourceboxes (displayclass &disp, cgiargsclass &args, 57 ostream &logout); 58 59 text_t get_source_box (text_t inputarg, int numboxes, text_t boxtype); 52 60 53 61 void set_cfgfile (displayclass &disp, cgiargsclass &args, ostream &logout); … … 88 96 text_t get_event_header (cgiargsclass &args); 89 97 98 bool check_sources (cgiargsclass &args, ostream &logout); 99 100 text_t format_url (const text_t &url); 101 90 102 public: 91 103 collectoraction ();
Note:
See TracChangeset
for help on using the changeset viewer.