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

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

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