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

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:     }
1.4     ! albertel   71:     my $js=
1.1       raeburn    72: <script type="text/javascript">
                     73: //<!--
                     74: function frameloc() {
                     75:     if (parent.LONCAPAToBePublished.location.pathname.indexOf("/~")!=-1) {
                     76:        parent.lastknownpriv=parent.LONCAPAToBePublished.location.pathname;
                     77:     }
                     78: // alert ('We are at '+parent.lastknownpriv);
                     79:     return unescape(parent.lastknownpriv);
                     80: }
                     81: 
                     82: function getdfilename() {
                     83:     var currloc = frameloc();
                     84:     var currdir;
                     85:     if (currloc.indexOf("/") != -1) {   
                     86:         var loclength = currloc.length;
                     87:         var lastslash = currloc.lastIndexOf("/");
                     88:         if (loclength == lastslash+1) {
                     89:             return;
                     90:         }
                     91:         else {
                     92:             currdir = currloc.substring(0,lastslash+1);
                     93:             if (currdir.indexOf("~") != -1) {
                     94:                 currdir = currdir.substring(currdir.indexOf("~")+1,currdir.length);
                     95:                 currdir = "/priv/"+currdir
                     96:                 top.location=currdir
                     97:                 return;
                     98:             }
                     99:         }
                    100:     }
                    101:     top.location="$defaultdir";
                    102: }
                    103: 
                    104: function getufilename() {
                    105:   document.upublisher.filename.value=frameloc();
                    106:   if (document.upublisher.filename.value.indexOf('/adm/pubdir')!=-1) {
                    107:       document.upublisher.filename.value=document.dpublisher.filename.value;
                    108:   }
                    109:   document.upublisher.submit();
                    110: }
                    111: 
                    112: function getactionfilename() {
                    113:   document.fileaction.filename.value=frameloc();
                    114:   var test=document.fileaction.action.selectedIndex;
                    115:   if (test == 8) { // trying to create a directory
                    116:       if (document.fileaction.filename.value.indexOf('/adm/pubdir')!=-1) {
                    117:           document.fileaction.filename.value=document.dpublisher.filename.value;
                    118:       }
                    119:       if ((document.fileaction.filename.value.charAt(
                    120:            document.fileaction.filename.value.length-1)!='/') &&
                    121:            (document.fileaction.filename.value.indexOf('/adm/pubdir')==-1)) {
                    122:           alert('$lt{'mcdi'}');
                    123:           return;
                    124:       }
                    125:    }
                    126:    document.fileaction.submit();
                    127: }
                    128: 
                    129: function getcurseed() {
                    130:   if (parent.LONCAPAToBePublished.document.lonhomework
                    131:        &&
                    132:       parent.LONCAPAToBePublished.document.lonhomework.rndseed
                    133:        &&
                    134:       parent.LONCAPAToBePublished.document.lonhomework.rndseed.value) {
                    135:     return parent.LONCAPAToBePublished.document.lonhomework.rndseed.value;
                    136:   }
                    137:   return 0;
                    138: }
                    139: 
                    140: function getproblemtype() {
                    141:   if (parent.LONCAPAToBePublished.document.lonhomework) {
                    142:      var optionelement;
                    143:      var valueIndex=0;
                    144:      for (var optionIndex=0;
                    145:           optionIndex < parent.LONCAPAToBePublished.document.lonhomework.problemtype.options.length;
                    146: 	  optionIndex++)
                    147:      {
                    148:          optionElement=parent.LONCAPAToBePublished.document.lonhomework.problemtype.options[optionIndex];
                    149: 	 if (optionElement.selected) {
                    150: 	    return optionElement.value;
                    151:          }	  
                    152:      } 	  
                    153:   }
                    154:   return 0;
                    155: }
                    156: 
                    157: function getpostdata() {
                    158:   document.printout.postdata.value=frameloc();
                    159:   document.printout.curseed.value=getcurseed();
                    160:   document.printout.problemtype.value=getproblemtype();
                    161:   document.printout.submit();
                    162: }
                    163: ENDONE
                    164: 
                    165:     if ($disp eq 'dir') {
1.4     ! albertel  166:         $js .= <<"ENDDIR";
1.1       raeburn   167: function getdirname() {
                    168:     document.publishdir.filename.value=frameloc();
                    169:     pubdir(document.publishdir)
                    170: }
                    171: 
                    172: function getsubdirname() {
                    173:     document.publishsubdir.filename.value=frameloc();
                    174:     pubrecdir(document.publishsubdir)
                    175: }
                    176: 
                    177: function geteditcat() {
                    178:     top.location=frameloc()+'default.meta'
                    179: }
                    180: 
                    181: function pubdir(theform) {
                    182:     if (confirm('Publish complete directory?')) {
                    183:         forcepub(theform)
                    184:         theform.submit();
                    185:     }
                    186: }
                    187: function pubrecdir(theform) {
                    188:     if (confirm('Publish directory and all subdirectories?')) {
                    189:         forcepub(theform);
                    190:         theform.submit();
                    191:     }
                    192: }
                    193: 
                    194: function forcepub(theform) {
                    195:     if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
                    196:         theform.forcerepub.value="ON";
                    197:     }
                    198: }
                    199: ENDDIR
                    200:     } else {
1.4     ! albertel  201:         $js.=<<"ENDRES";
1.1       raeburn   202: function getfilename() {
                    203:     document.publisher.filename.value=frameloc();
                    204:     if ((document.publisher.filename.value.charAt(
                    205:       document.publisher.filename.value.length-1)!='/') &&
                    206:       (document.publisher.filename.value.indexOf('/adm/pubdir')==-1)) {
                    207:         document.publisher.submit();
                    208:     } else {
                    209:         alert('$lt{'cnpd'}');
                    210:     }
                    211: }
                    212: 
                    213: function getrfilename() {
                    214:   document.rpublisher.filename.value=frameloc();
                    215:    if ((document.rpublisher.filename.value.charAt(
                    216:         document.rpublisher.filename.value.length-1)!='/') &&
                    217:        (document.rpublisher.filename.value.indexOf('/adm/pubdir')==-1)) {
                    218:         document.rpublisher.submit();
                    219:    } else {
                    220:       alert('$lt{'cnrd'}');
                    221:    }
                    222: }
                    223: 
                    224: function getdelfilename() {
                    225:   document.del.filename.value=frameloc();
                    226:   document.del.submit();
                    227: }
                    228: ENDRES
                    229:     }
1.4     ! albertel  230:     my $start_page = 
        !           231: 	&Apache::loncommon::start_page('Publishing Frame',$js,
        !           232: 				       {'only_body' => 1,});
        !           233:     my $end_page = 
        !           234: 	&Apache::loncommon::end_page();
1.1       raeburn   235:     $r->print(<<"END");
1.4     ! albertel  236: $start_page
1.1       raeburn   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>
1.4     ! albertel  353: $end_page
1.1       raeburn   354: ENDPAGE
                    355: }
                    356: 
                    357: 1;

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