File:  [LON-CAPA] / loncom / publisher / lonpubmenu.pm
Revision 1.6: download - view: text, annotated - select for diffs
Thu Feb 26 16:10:49 2009 UTC (15 years, 2 months ago) by schafran
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_99_1, version_2_8_99_0, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
Catalog Information is now metadata.

    1: # The LearningOnline Network with CAPA
    2: # Construction Space Buttons for Top Frame 
    3: #
    4: # $Id: lonpubmenu.pm,v 1.6 2009/02/26 16:10:49 schafran Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::lonpubmenu;
   31: use Apache::lonlocal;
   32: use Apache::lonnet;
   33: use Apache::loncommon;
   34: 
   35: sub handler {
   36:     my $r = shift;
   37:     my %lt=&Apache::lonlocal::texthash(
   38:                                        cnpd => 'Cannot publish directory',
   39:                                        cnrd => 'Cannot retrieve directory',
   40:                                        mcdi => 'Must create new subdirectory inside a directory',
   41:                                        pubr => 'Publish this Resource',
   42:                                        pubd => 'Publish this Directory',
   43:                                        rtrv => 'Retrieve Old Version',
   44:                                        pubs => 'Publish with Subdirectories',
   45:                                        list => 'List Directory',
   46:                                        uplo => 'Upload file',  
   47:                                        dele => 'Delete',
   48:                                        edit => 'Edit Metadata', 
   49:                                        sela => 'Select Action',
   50:                                        nfil => 'New file',
   51:                                        nhtm => 'New HTML file',
   52:                                        nprb => 'New problem',
   53:                                        npag => 'New assembled page',
   54:                                        nseq => 'New assembled sequence',
   55:                                        ncrf => 'New custom rights file',
   56:                                        nsty => 'New style file',
   57:                                        nlib => 'New library file',
   58:                                        nsub => 'New subdirectory',
   59:                                        renm => 'Rename current file to',
   60:                                        move => 'Move current file to',
   61:                                        copy => 'Copy current file to',
   62:                                        type => 'Type Name Here',
   63:                                        go => 'Go',
   64:                                        prnt => 'Print'
   65:                                       );
   66:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['disp']);
   67:     my $disp = $env{'form.disp'};
   68: # set defaults for parent directory in case frameloc is unable to determine directory
   69:     my $defaultdir = '/priv/'.$env{'user.name'}.'/'; 
   70:     if ($env{'request.role'} =~ m#^ca\./[^/]+/([^/]+)#) {
   71:         $defaultdir = '/priv/'.$1.'/';
   72:     }
   73:     my $js=
   74: <script type="text/javascript">
   75: //<!--
   76: function frameloc() {
   77:     if (parent.LONCAPAToBePublished.location.pathname.indexOf("/~")!=-1) {
   78:        parent.lastknownpriv=parent.LONCAPAToBePublished.location.pathname;
   79:     }
   80: // alert ('We are at '+parent.lastknownpriv);
   81:     return unescape(parent.lastknownpriv);
   82: }
   83: 
   84: function getdfilename() {
   85:     var currloc = frameloc();
   86:     var currdir;
   87:     if (currloc.indexOf("/") != -1) {   
   88:         var loclength = currloc.length;
   89:         var lastslash = currloc.lastIndexOf("/");
   90:         if (loclength == lastslash+1) {
   91:             return;
   92:         }
   93:         else {
   94:             currdir = currloc.substring(0,lastslash+1);
   95:             if (currdir.indexOf("~") != -1) {
   96:                 currdir = currdir.substring(currdir.indexOf("~")+1,currdir.length);
   97:                 currdir = "/priv/"+currdir
   98:                 top.location=currdir
   99:                 return;
  100:             }
  101:         }
  102:     }
  103:     top.location="$defaultdir";
  104: }
  105: 
  106: function getufilename() {
  107:   document.upublisher.filename.value=frameloc();
  108:   if (document.upublisher.filename.value.indexOf('/adm/pubdir')!=-1) {
  109:       document.upublisher.filename.value=document.dpublisher.filename.value;
  110:   }
  111:   document.upublisher.submit();
  112: }
  113: 
  114: function getactionfilename() {
  115:   document.fileaction.filename.value=frameloc();
  116:   var test=document.fileaction.action.selectedIndex;
  117:   if (test == 8) { // trying to create a directory
  118:       if (document.fileaction.filename.value.indexOf('/adm/pubdir')!=-1) {
  119:           document.fileaction.filename.value=document.dpublisher.filename.value;
  120:       }
  121:       if ((document.fileaction.filename.value.charAt(
  122:            document.fileaction.filename.value.length-1)!='/') &&
  123:            (document.fileaction.filename.value.indexOf('/adm/pubdir')==-1)) {
  124:           alert('$lt{'mcdi'}');
  125:           return;
  126:       }
  127:    }
  128:    document.fileaction.submit();
  129: }
  130: 
  131: function getcurseed() {
  132:   if (parent.LONCAPAToBePublished.document.lonhomework
  133:        &&
  134:       parent.LONCAPAToBePublished.document.lonhomework.rndseed
  135:        &&
  136:       parent.LONCAPAToBePublished.document.lonhomework.rndseed.value) {
  137:     return parent.LONCAPAToBePublished.document.lonhomework.rndseed.value;
  138:   }
  139:   return 0;
  140: }
  141: 
  142: function getproblemtype() {
  143:   if (parent.LONCAPAToBePublished.document.lonhomework) {
  144:      var optionelement;
  145:      var valueIndex=0;
  146:      for (var optionIndex=0;
  147:           optionIndex < parent.LONCAPAToBePublished.document.lonhomework.problemtype.options.length;
  148: 	  optionIndex++)
  149:      {
  150:          optionElement=parent.LONCAPAToBePublished.document.lonhomework.problemtype.options[optionIndex];
  151: 	 if (optionElement.selected) {
  152: 	    return optionElement.value;
  153:          }	  
  154:      } 	  
  155:   }
  156:   return 0;
  157: }
  158: 
  159: function getpostdata() {
  160:   document.printout.postdata.value=frameloc();
  161:   document.printout.curseed.value=getcurseed();
  162:   document.printout.problemtype.value=getproblemtype();
  163:   document.printout.submit();
  164: }
  165: ENDONE
  166: 
  167:     if ($disp eq 'dir') {
  168:         $js .= <<"ENDDIR";
  169: function getdirname() {
  170:     document.publishdir.filename.value=frameloc();
  171:     pubdir(document.publishdir)
  172: }
  173: 
  174: function getsubdirname() {
  175:     document.publishsubdir.filename.value=frameloc();
  176:     pubrecdir(document.publishsubdir)
  177: }
  178: 
  179: function geteditcat() {
  180:     top.location=frameloc()+'default.meta'
  181: }
  182: 
  183: function pubdir(theform) {
  184:     if (confirm('Publish complete directory?')) {
  185:         forcepub(theform)
  186:         theform.submit();
  187:     }
  188: }
  189: function pubrecdir(theform) {
  190:     if (confirm('Publish directory and all subdirectories?')) {
  191:         forcepub(theform);
  192:         theform.submit();
  193:     }
  194: }
  195: 
  196: function forcepub(theform) {
  197:     if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
  198:         theform.forcerepub.value="ON";
  199:     }
  200: }
  201: ENDDIR
  202:     } else {
  203:         $js.=<<"ENDRES";
  204: function getfilename() {
  205:     document.publisher.filename.value=frameloc();
  206:     if ((document.publisher.filename.value.charAt(
  207:       document.publisher.filename.value.length-1)!='/') &&
  208:       (document.publisher.filename.value.indexOf('/adm/pubdir')==-1)) {
  209:         document.publisher.submit();
  210:     } else {
  211:         alert('$lt{'cnpd'}');
  212:     }
  213: }
  214: 
  215: function getrfilename() {
  216:   document.rpublisher.filename.value=frameloc();
  217:    if ((document.rpublisher.filename.value.charAt(
  218:         document.rpublisher.filename.value.length-1)!='/') &&
  219:        (document.rpublisher.filename.value.indexOf('/adm/pubdir')==-1)) {
  220:         document.rpublisher.submit();
  221:    } else {
  222:       alert('$lt{'cnrd'}');
  223:    }
  224: }
  225: 
  226: function getdelfilename() {
  227:   document.del.filename.value=frameloc();
  228:   document.del.submit();
  229: }
  230: ENDRES
  231:     }
  232:     my $start_page = 
  233: 	&Apache::loncommon::start_page('Publishing Frame',$js,
  234: 				       {'only_body' => 1,});
  235:     my $end_page = 
  236: 	&Apache::loncommon::end_page();
  237:     $r->print(<<"END");
  238: $start_page
  239: 	<table border="0" align="center"><tr><th bgcolor="#004400" height="20">
  240: 	      <table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">
  241: 		  <td bgcolor="#ccddaa" align="center">
  242: END
  243:     if ($disp eq 'dir') {
  244:         $r->print('
  245:                     <form name="publishdir" action="/adm/publish" target="_parent" method="post">
  246:                       <input type="hidden" name="filename" value="" />
  247:                       <input type="hidden" name="forcerepub" value="NO" />
  248:                       <input type="button" value="'.$lt{'pubd'}.'" onclick="getdirname();" />
  249:                     </form>
  250:                  ');
  251:     } else {
  252:         $r->print('
  253:                     <form name="publisher" action="/adm/publish" target="_parent" method="post">
  254:                       <input type="hidden" name="filename" value="" />
  255: 	              <input type="button" value="'.$lt{'pubr'}.'" onclick="getfilename();" />
  256:                     </form>
  257:                    ');
  258:     }
  259:     $r->print(<<"ENDTWO");
  260: 		    </form>
  261: 		  </td>
  262: 		  <td bgcolor="#ccddaa" align="center">
  263: 		    <form name="dpublisher" action="/adm/pubdir" target="LONCAPAToBePublished" method="post">
  264: 		      <input type="hidden" name="filename" value="" />
  265: 		      <input type="button" value="$lt{'list'}" onclick="getdfilename();" />
  266: 		    </form>
  267: 		  </td>
  268: 		  <td bgcolor="#ccddaa" valign="top" align="center">
  269: 		    <form name="upublisher" action="/adm/upload" target="_parent"
  270: 			method="post" enctype="multipart/form-data">
  271: 		      <input type="hidden" name="filename" value="" />
  272: 		      <input type="file" name="upfile" size="20" />
  273: 		      <input type="button" value="$lt{'uplo'}"  onclick="getufilename();" />
  274: 		    </form>
  275: 		  </td>
  276: 		  <td rowspan="2" bgcolor="#ccddaa" align="center">
  277: 		    <form name="printout" target="_parent" action="/adm/printout" method="post" onsubmit="getpostdata();">
  278: 		      <input type="hidden" name="postdata" value="" />
  279: 		      <input type="hidden" name="curseed" value="" />
  280: 		      <input type="hidden" name="problemtype" value="" />
  281: 		      <input type="button" value="$lt{'prnt'}" onclick="getpostdata();" />
  282: 		    </form>
  283: 		  </td>
  284: 		</tr>
  285:                 <tr valign="middle">
  286: ENDTWO
  287:     if ($disp eq 'dir') {
  288:         $r->print(<<"ENDDIR");
  289:                   <td bgcolor="#ccddaa" align="center">
  290:                     <form name="publishsubdir" action="/adm/publish" target="_parent" method="post">
  291:                       <input type="hidden" name="filename" value="" />
  292:                       <input type="hidden" name="forcerepub" value="NO" />
  293:                       <input type="hidden" name="pubrec" value="1" />
  294:                       <input type="button" value="$lt{'pubs'}" onclick="getsubdirname();" />
  295:                     </form>
  296:                   </td>
  297:                   <td bgcolor="#ccddaa">
  298:                     <form name="editcat" action="/adm/cfile" target="_parent" method="post">
  299:                       <input type="hidden" name="filename" value="" />
  300:                       <input type="button" value="$lt{'edit'}" onclick="geteditcat();" />
  301:                     </form>
  302:                   </td>
  303: ENDDIR
  304:     } else {
  305:         $r->print(<<"ENDFILE"); 
  306: 		  <td bgcolor="#ccddaa" align="center">
  307: 		    <form name="rpublisher" action="/adm/retrieve" target="_parent" method="post">
  308: 		      <input type="hidden" name="filename" value="" />
  309: 		      <input type="button" value="$lt{'rtrv'}" onclick="getrfilename();" />
  310: 		    </form>
  311: 		  </td>
  312: 		  <td bgcolor="#ccddaa">
  313: 		    <form name="del" action="/adm/cfile" target="_parent" method="post">
  314: 		      <input type="hidden" name="filename" value="" />
  315: 		      <input type="hidden" name="action" value="delete" />
  316: 	              <input type="button" value="$lt{'dele'}" onclick="getdelfilename();" />
  317: 		    </form>
  318: 		  </td>
  319: ENDFILE
  320:     }
  321:     $r->print(<<"ENDOPTIONS");
  322: 		  <td bgcolor="#ccddaa" align="center">
  323: 		    <form name="fileaction" action="/adm/cfile" target="_parent" method="post" onsubmit="getactionfilename();">
  324: 		      <nobr>
  325: 			<input type="hidden" name="filename" value="" />
  326: 			  <select name="action">
  327: 			    <option value="Select Action">$lt{'sela'}</option>
  328: 			    <option value="newfile">$lt{'nfil'}:</option>
  329: 			    <option value="newhtmlfile">$lt{'nhtm'}:</option>
  330: 			    <option value="newproblemfile">$lt{'nprb'}:</option>
  331:                             <option value="newpagefile">$lt{'npag'}:</option>
  332:                             <option value="newsequencefile">$lt{'nseq'}:</option>
  333:                             <option value="newrightsfile">$lt{'ncrf'}:</option>
  334:                             <option value="newstyfile">$lt{'nsty'}:</option>
  335:                             <option value="newlibraryfile">$lt{'nlib'}:</option>
  336: 			    <option value="newdir">$lt{'nsub'}:</option>
  337: ENDOPTIONS
  338:     if ($disp ne 'dir') {
  339:         $r->print(<<"ENDPROBOPS");
  340: 			    <option value="rename">$lt{'renm'}:</option>
  341: 			    <option value="move">$lt{'move'}:</option>
  342: 			    <option value="copy">$lt{'copy'}:</option>
  343: ENDPROBOPS
  344:     }
  345:     $r->print(<<"ENDPAGE");
  346: 			  </select>&nbsp;<input type="text" name="newfilename" value="$lt{'type'}" onfocus="if (this.value == '$lt{'type'}') this.value=''" />&nbsp;<input type="button" value="$lt{'go'}" onclick="getactionfilename();" />
  347: 		      </nobr>
  348: 		    </form>
  349: 		   </td>
  350: 		</tr>
  351: 	      </table>
  352: 	    </th>
  353: 	  </tr>
  354: 	</table>
  355: $end_page
  356: ENDPAGE
  357: }
  358: 
  359: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>