Annotation of loncom/publisher/lonpubmenu.pm, revision 1.2

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Construction Space Buttons for Top Frame 
                      3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
                     26: ###
                     27: 
                     28: package Apache::lonpubmenu;
                     29: use Apache::lonlocal;
                     30: use Apache::loncommon;
                     31: 
                     32: sub handler {
                     33:     my $r = shift;
                     34:     my %lt=&Apache::lonlocal::texthash(
                     35:                                        cnpd => 'Cannot publish directory',
                     36:                                        cnrd => 'Cannot retrieve directory',
                     37:                                        mcdi => 'Must create new subdirectory inside a directory',
                     38:                                        pubr => 'Publish this Resource',
                     39:                                        pubd => 'Publish this Directory',
                     40:                                        rtrv => 'Retrieve Old Version',
                     41:                                        pubs => 'Publish with Subdirectories',
                     42:                                        list => 'List Directory',
                     43:                                        uplo => 'Upload file',  
                     44:                                        dele => 'Delete',
                     45:                                        edit => 'Edit Catalog Information', 
                     46:                                        sela => 'Select Action',
                     47:                                        nfil => 'New file',
                     48:                                        nhtm => 'New HTML file',
                     49:                                        nprb => 'New problem',
                     50:                                        npag => 'New assembled page',
                     51:                                        nseq => 'New assembled sequence',
                     52:                                        ncrf => 'New custom rights file',
                     53:                                        nsty => 'New style file',
1.2     ! www        54:                                        nlib => 'New library file',
1.1       raeburn    55:                                        nsub => 'New subdirectory',
                     56:                                        renm => 'Rename current file to',
                     57:                                        move => 'Move current file to',
                     58:                                        copy => 'Copy current file to',
                     59:                                        type => 'Type Name Here',
                     60:                                        go => 'Go',
                     61:                                        prnt => 'Print'
                     62:                                       );
                     63:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['disp']);
                     64:     my $disp = $ENV{'form.disp'};
                     65: # set defaults for parent directory in case frameloc is unable to determine directory
                     66:     my $defaultdir = '/priv/'.$ENV{'user.name'}.'/'; 
                     67:     if ($ENV{'request.role'} =~ m#^ca\./[^/]+/([^/]+)#) {
                     68:         $defaultdir = '/priv/'.$1.'/';
                     69:     }
                     70:     $r->print(<<"ENDONE");
                     71: <html>
                     72: <head>
                     73: <title>LON-CAPA Publishing Frame</title>
                     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:         $r->print(<<"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:         $r->print(<<"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:     $r->print(<<"END");
                    233: //-->
                    234: </script>
                    235:     </head>
                    236:     <body bgcolor="#ccffdd" text='#002200' link='#003333' vlink='#006666'>
                    237: 	<table border="0" align="center"><tr><th bgcolor="#004400" height="20">
                    238: 	      <table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">
                    239: 		  <td bgcolor="#ccddaa" align="center">
                    240: END
                    241:     if ($disp eq 'dir') {
                    242:         $r->print('
                    243:                     <form name="publishdir" action="/adm/publish" target="_parent" method="post">
                    244:                       <input type="hidden" name="filename" value="" />
                    245:                       <input type="hidden" name="forcerepub" value="NO" />
                    246:                       <input type="button" value="'.$lt{'pubd'}.'" onclick="getdirname();" />
                    247:                     </form>
                    248:                  ');
                    249:     } else {
                    250:         $r->print('
                    251:                     <form name="publisher" action="/adm/publish" target="_parent" method="post">
                    252:                       <input type="hidden" name="filename" value="" />
                    253: 	              <input type="button" value="'.$lt{'pubr'}.'" onclick="getfilename();" />
                    254:                     </form>
                    255:                    ');
                    256:     }
                    257:     $r->print(<<"ENDTWO");
                    258: 		    </form>
                    259: 		  </td>
                    260: 		  <td bgcolor="#ccddaa" align="center">
                    261: 		    <form name="dpublisher" action="/adm/pubdir" target="LONCAPAToBePublished" method="post">
                    262: 		      <input type="hidden" name="filename" value="" />
                    263: 		      <input type="button" value="$lt{'list'}" onclick="getdfilename();" />
                    264: 		    </form>
                    265: 		  </td>
                    266: 		  <td bgcolor="#ccddaa" valign="top" align="center">
                    267: 		    <form name="upublisher" action="/adm/upload" target="_parent"
                    268: 			method="post" enctype="multipart/form-data">
                    269: 		      <input type="hidden" name="filename" value="" />
                    270: 		      <input type="file" name="upfile" size="20" />
                    271: 		      <input type="button" value="$lt{'uplo'}"  onclick="getufilename();" />
                    272: 		    </form>
                    273: 		  </td>
                    274: 		  <td rowspan="2" bgcolor="#ccddaa" align="center">
                    275: 		    <form name="printout" target="_parent" action="/adm/printout" method="post" onsubmit="getpostdata();">
                    276: 		      <input type="hidden" name="postdata" value="" />
                    277: 		      <input type="hidden" name="curseed" value="" />
                    278: 		      <input type="hidden" name="problemtype" value="" />
                    279: 		      <input type="button" value="$lt{'prnt'}" onclick="getpostdata();" />
                    280: 		    </form>
                    281: 		  </td>
                    282: 		</tr>
                    283:                 <tr valign="middle">
                    284: ENDTWO
                    285:     if ($disp eq 'dir') {
                    286:         $r->print(<<"ENDDIR");
                    287:                   <td bgcolor="#ccddaa" align="center">
                    288:                     <form name="publishsubdir" action="/adm/publish" target="_parent" method="post">
                    289:                       <input type="hidden" name="filename" value="" />
                    290:                       <input type="hidden" name="forcerepub" value="NO" />
                    291:                       <input type="hidden" name="pubrec" value="1" />
                    292:                       <input type="button" value="$lt{'pubs'}" onclick="getsubdirname();" />
                    293:                     </form>
                    294:                   </td>
                    295:                   <td bgcolor="#ccddaa">
                    296:                     <form name="editcat" action="/adm/cfile" target="_parent" method="post">
                    297:                       <input type="hidden" name="filename" value="" />
                    298:                       <input type="button" value="$lt{'edit'}" onclick="geteditcat();" />
                    299:                     </form>
                    300:                   </td>
                    301: ENDDIR
                    302:     } else {
                    303:         $r->print(<<"ENDFILE"); 
                    304: 		  <td bgcolor="#ccddaa" align="center">
                    305: 		    <form name="rpublisher" action="/adm/retrieve" target="_parent" method="post">
                    306: 		      <input type="hidden" name="filename" value="" />
                    307: 		      <input type="button" value="$lt{'rtrv'}" onclick="getrfilename();" />
                    308: 		    </form>
                    309: 		  </td>
                    310: 		  <td bgcolor="#ccddaa">
                    311: 		    <form name="del" action="/adm/cfile" target="_parent" method="post">
                    312: 		      <input type="hidden" name="filename" value="" />
                    313: 		      <input type="hidden" name="action" value="delete" />
                    314: 	              <input type="button" value="$lt{'dele'}" onclick="getdelfilename();" />
                    315: 		    </form>
                    316: 		  </td>
                    317: ENDFILE
                    318:     }
                    319:     $r->print(<<"ENDOPTIONS");
                    320: 		  <td bgcolor="#ccddaa" align="center">
                    321: 		    <form name="fileaction" action="/adm/cfile" target="_parent" method="post" onsubmit="getactionfilename();">
                    322: 		      <nobr>
                    323: 			<input type="hidden" name="filename" value="" />
                    324: 			  <select name="action">
                    325: 			    <option value="Select Action">$lt{'sela'}</option>
                    326: 			    <option value="newfile">$lt{'nfil'}:</option>
                    327: 			    <option value="newhtmlfile">$lt{'nhtm'}:</option>
                    328: 			    <option value="newproblemfile">$lt{'nprb'}:</option>
                    329:                             <option value="newpagefile">$lt{'npag'}:</option>
                    330:                             <option value="newsequencefile">$lt{'nseq'}:</option>
                    331:                             <option value="newrightsfile">$lt{'ncrf'}:</option>
                    332:                             <option value="newstyfile">$lt{'nsty'}:</option>
1.2     ! www       333:                             <option value="newlibraryfile">$lt{'nlib'}:</option>
1.1       raeburn   334: 			    <option value="newdir">$lt{'nsub'}:</option>
                    335: ENDOPTIONS
                    336:     if ($disp ne 'dir') {
                    337:         $r->print(<<"ENDPROBOPS");
                    338: 			    <option value="rename">$lt{'renm'}:</option>
                    339: 			    <option value="move">$lt{'move'}:</option>
                    340: 			    <option value="copy">$lt{'copy'}:</option>
                    341: ENDPROBOPS
                    342:     }
                    343:     $r->print(<<"ENDPAGE");
                    344: 			  </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();" />
                    345: 		      </nobr>
                    346: 		    </form>
                    347: 		   </td>
                    348: 		</tr>
                    349: 	      </table>
                    350: 	    </th>
                    351: 	  </tr>
                    352: 	</table>
                    353:     </body>
                    354:   </html>
                    355: ENDPAGE
                    356: }
                    357: 
                    358: 1;

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