#!/usr/bin/perl
# stta_mvobjs.cgi
# Move/rename/copy STTA objects
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require './stta-lib.pl';

&ReadParse();
if ( !$in{type} ) { &redirect("index.cgi"); }
$objtype=$in{type};
$postform="mv".$objtype;
$titleform="index_mv".$objtype;
$multiobj=$in{multi} || "1";
$grptype=$objtype;
$obj_type=$objtype;
if ( $objtype =~ /apps/ ) {  $grptype="grpapps" };
if ( $objtype =~ /hosts/ ) {  $grptype="grphosts" };
if ( $objtype eq "ou" || $objtype eq "users" || $objtype eq "sysusers") { 
     $grptype="ou";
     $obj_type="ous";
};
if ( $objtype eq "sysusers") {  $postform="mvusers" ; $titleform="index_mvusers" };

&headerstta($text{$titleform}, "", $postform,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" ); 

 print "<hr><p>\n";
 print "<SCRIPT SRC=\"global.js\">\n"; 
 print "</SCRIPT>\n"; 
 print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
 print "<!--\n"; 
 print "/*  Strings for locales  */\n"; 
 print "var msg0=\"".$text{'msg_0'},"\";\n";
 print "var msg1=\"".$text{'msg_1'},"\";\n";
 print "var msg2=\"".$text{'msg_2'},"\";\n";
 print "var msg3=\"".$text{'msg_3'},"\";\n";
 print "var msg4=\"".$text{'msg_4'},"\";\n";
 print "var msg5=\"".$text{'msg_5'},"\";\n";
 print "var msg6=\"".$text{'msg_6'},"\";\n";
 print "var msg7=\"".$text{'msg_7'},"\";\n";
 print "var msg8=\"".$text{'msg_8'},"\";\n";
 print "var ask_confadmin=true;\n"; 
 print "\n"; 
 &htmlCheckAlias($obj_type);
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Check_fields(obj) {\n"; 
 print "     if ( get_value(\"select\",obj.destgrp) == \"none\" ) {\n";
 print "          alert(obj.destgrp.name+\":\"+msg1);\n";
 print "                    obj.destgrp.focus();\n";
 print "          return false;\n";
 print "     }         \n";
 print "     if ( checkAlias_".$obj_type."(obj.newalias) == true ) {\n";
 print "          return false;\n";
 print "     }         \n";
 if ( $objtype =~ /usr/ || $objtype =~ /users/ ) {
    print "     if ( emptyField(obj.userdn)) {\n";
    print "          alert(obj.orgobj.name+\":\"+msg1);\n";
    print "                    obj.orgobj.focus();\n";
    print "          return false;\n";
    print "     }         \n";
    print "     if ( obj.userdn.value == \"-\" ) {\n";
    print "          alert(obj.orgobj.name+\" (\"+obj.userdn.value+\"):\"+msg8+\" OS usr\");\n";
    print "                    obj.orgobj.focus();\n";
    print "          return false;\n";
    print "     }         \n";
 }
 print "\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";
print "<tr $tb> <td><font color='$revtext'><b>".eval("\$text{'titidx_$postform'}")."</b></td> </tr>\n" ;
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=\"fmvobjs\" ACTION=\"mvobjs.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"$postform\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"objtype\" VALUE=\"$objtype\">\n";
 print "<tr><td valign=top>",&hlink("<b>$text{'task'}</b>","fmvtask"),"&nbsp;</td>\n";
 print "   <td valign=top><select NAME=\"task\">\n";
 print "          <option VALUE=\"move\">",&hlink("<b>$text{'move'}</b>","fobjmv"),"\n";
 if ( $objtype =~ /grp/ || $objtype =~ /ou/ ) {
      print "        </select></td></tr>\n";
 } else {
      print "          <option VALUE=\"copy\">",&hlink("<b>$text{'copy'}</b>","fobjcp"),"\n";
      print "        </select></td></tr>\n";
 }
 print "<tr><td valign=top><b>$text{'obj_origin'}</b>&nbsp;</td></tr>\n";
 print "<tr><td valign=top>",&hlink("<b>$text{'f_obj'}</b>","fobj"),"&nbsp;</td>\n";
 if ( $objtype =~ /usr/ || $objtype =~ /users/ ) {
       print "  <input TYPE=\"hidden\" NAME=\"userdn\" VALUE=\"\">\n";
       print "  <input TYPE=\"hidden\" NAME=\"userou\" VALUE=\"\">\n";
       print "<td>";
       &htmlWinLdapUsers($text{'selusr_win'},"fmvobjs.orgobj");
       print "<input TYPE=\"text\" NAME=\"orgobj\" VALUE=\"\" cols=\"22\" size=\"12\" onFocus=\"this.value=getCookie('username');fmvobjs.userdn.value=getCookie('dn');fmvobjs.userou.value=getCookie('userou');\" onChange=\"fmvobjs.userdn.value='';\">\n";
       print "        </td>\n";
 } else {
    if ( $multiobj eq "1" ) {
         print "<td valign=top><textarea wrap=auto name=orgobj rows=5 cols=10>",
             join("\n", split(/,/ , $orgobj)),"</textarea>\n";
         if ( $objtype eq "hosts" ) {
              print "<input type=button onClick='ifield = document.forms[0].orgobj; if ( ifield.value == \"$orgobj\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/host_chooser.cgi?multi=$multiobj&f=textarea&host=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"...\">\n";
         }
         print "<input type=button onClick='ifield = document.forms[0].orgobj; if ( ifield.value == \"$orgobj\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=$objtype&multi=$multiobj&ord=ens&deft=alias&f=textarea&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";
   
    } else {
         print "   <td valign=top><select NAME=\"orgobj\">\n";
         print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selobj'}</b>","fselobjs"),"\n";
         %h_obj=eval("\&list_$objtype()");
         &out_htmlselobj(\%h_obj,"descrip","alias",$orgobj);
         print "        </select>\n";
         print "<input type=button onClick='selfield = document.forms[0].orgobj; ifield = document.forms[0].orgobj.options[document.forms[0].orgobj.selectedIndex]; if ( ifield.value == \"$orgobj\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=$objtype&multi=$multiobj&ord=ens&deft=alias&f=select&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";
    }
 }
 print "</tr>";
 print "<tr><td valign=top><b>$text{'obj_target'}</b>&nbsp;</td></tr>\n";
 print "<tr><td valign=top>",&hlink("<b>$text{'f_newname'}</b>","fnewname"),"&nbsp; </td>\n";
 print "<td valign=top><input TYPE=\"text\" NAME=\"newobj\" VALUE=\"\" cols=\"35\" size=\"35\">\n</tr>";
 print "<tr><td valign=top><b> $text{'l_alias'}</b>&nbsp;</td>";
 print "<td valign=top><input TYPE=\"text\" NAME=\"newalias\" VALUE=\"\" cols=\"12\" size=\"12\" ALIGN=left  onChange=\"checkAlias_".$obj_type."(this); return false\"></td></tr>\n";
 print "<tr><td valign=top>",&hlink("<b>$text{'f_obj'}</b>","fobj"),"&nbsp;</td>\n";
 print "   <td valign=top><select NAME=\"destgrp\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selobj'}</b>","fselobjs"),"\n";
 if ( $grptype eq "ou" ) {
     %h_obj=&list_ous();
 }  else { %h_obj=eval("\&list_$grptype()");  }
 &out_htmlselobj(\%h_obj,"descrip","alias",$destgrp);
 print "        </select>\n";
 $multiobj="0";
 print "<input type=button onClick='selfield = document.forms[0].destgrp; ifield = document.forms[0].destgrp.options[document.forms[0].destgrp.selectedIndex]; if ( ifield.value == \"$destgrp\" ) { ifield.value = \"\" } ; grpchooser = window.open(\"/stta/obj_chooser.cgi?type=$grptype&multi=$multiobj&ord=ens&deft=alias&f=select&obj=\"+escape(ifield.value), \"grpchooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); grpchooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";
 print "</tr>";

 print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
 print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";
 print "	</form>\n"; 
 print "<tr><tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;



