Commit 6090e114 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Commit "Duplicate Experiment" option and support, enabled for STUDLY()

users only.
parent c68b8fbc
...@@ -10,29 +10,94 @@ ...@@ -10,29 +10,94 @@
# #
function INITFORM($formfields, $projlist) function INITFORM($formfields, $projlist)
{ {
global $nsref, $guid; global $nsref, $guid, $copyid;
$defaults = array(); $defaults = array();
# #
# This stuff is here for netbuild. The initial post from netbuild will # This is for experiment copying ...
# include these; they point to the nsfile. The right approach for doing
# this is to have another page for netbuild that does some magic and
# redirects the browser to this page.
# #
if (isset($nsref)) { if (isset($copyid) && $copyid != "") {
if (strcmp($nsref, "") == 0 || !ereg("^[0-9]+$", $nsref)) unset($copypid);
unset($nsref); unset($copyeid);
else
$defaults[nsref] = $nsref; #
# See what kind of copy.
#
if (preg_match("/^(\d+)((?::[-\w]*)?)$/", $copyid, $matches)) {
$exptidx = $matches[1];
if (TBvalid_integer($exptidx)) {
#
# See if its a current experiment.
#
$query_result =
DBQueryFatal("select pid,eid from experiments ".
"where idx='$exptidx'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_row($query_result);
$copypid = $row[0];
$copyeid = $row[1];
}
}
}
elseif (preg_match("/^([-\w]+),([-\w]+)((?::[-\w]*)?)$/",
$copyid, $matches)) {
$copypid = $matches[1];
$copyeid = $matches[2];
}
#
# Current experiment; we can get some additional stuff.
#
if (isset($copypid) && isset($copyeid)) {
if (TBvalid_pid($copypid) && TBvalid_eid($copyeid)) {
$query_result =
DBQueryFatal("select expt_name from experiments ".
"where eid='$copyeid' and pid='$copypid'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_row($query_result);
$defaults["exp_description"] = $row[0];
}
}
# See if already a copy.
if (preg_match("/^([-\w]*)-Copy(\d*)$/", $copyeid, $matches2)) {
$copyeid = $matches2[1];
$copycount = "Copy" . (((int) $matches2[2]) + 1);
}
else
$copycount = "Copy0";
$defaults["exp_pid"] = $copypid;
$defaults["exp_id"] = "${copyeid}-${copycount}";
}
$defaults["copyid"] = $copyid;
} }
if (isset($guid)) { else {
if (strcmp($guid, "") == 0 || !ereg("^[0-9]+$", $guid)) unset($copyid);
unset($guid);
#
# This stuff is here for netbuild. The initial post from netbuild will
# include these; they point to the nsfile. The right approach for doing
# this is to have another page for netbuild that does some magic and
# redirects the browser to this page.
#
if (isset($nsref) && $nsref != "" && ereg("^[0-9]+$", $nsref))
$defaults[nsref] = $nsref;
else else
unset($nsref);
if (isset($guid) && $guid != "" && ereg("^[0-9]+$", $guid))
$defaults[guid] = $guid; $defaults[guid] = $guid;
else
unset($guid);
} }
# #
# For users that are in one project and one subgroup, it is usually # For users that are in one project and one subgroup, it is usually
# the case that they should use the subgroup, and since they also tend # the case that they should use the subgroup, and since they also tend
...@@ -193,6 +258,7 @@ function SPITFORM($formfields, $errors) ...@@ -193,6 +258,7 @@ function SPITFORM($formfields, $errors)
echo "</table><br>\n"; echo "</table><br>\n";
} }
else { else {
if (! isset($formfields['copyid'])) {
if (!isset($formfields[nsref]) && !isset($view['quiet'])) { if (!isset($formfields[nsref]) && !isset($view['quiet'])) {
if (STUDLY()) { if (STUDLY()) {
echo "<p><ul> echo "<p><ul>
...@@ -229,6 +295,7 @@ function SPITFORM($formfields, $errors) ...@@ -229,6 +295,7 @@ function SPITFORM($formfields, $errors)
"please fill out the following information:</p>"; "please fill out the following information:</p>";
} }
} }
}
} }
echo "<form name=form1 enctype=multipart/form-data echo "<form name=form1 enctype=multipart/form-data
...@@ -355,7 +422,16 @@ function SPITFORM($formfields, $errors) ...@@ -355,7 +422,16 @@ function SPITFORM($formfields, $errors)
# #
# NS file # NS file
# #
if (isset($formfields[nsref])) { if (isset($formfields['copyid'])) {
$copyid = $formfields['copyid'];
echo "<tr>
<td class='pad4'>Copy of experiment: &nbsp</td>
<td class='pad4'>$copyid</td>
<input type=hidden name=\"formfields[copyid]\" value='$copyid'>
</tr>\n";
}
elseif (isset($formfields[nsref])) {
$nsref = $formfields[nsref]; $nsref = $formfields[nsref];
if (isset($formfields[guid])) { if (isset($formfields[guid])) {
......
...@@ -152,7 +152,14 @@ if (isset($formfields[guid])) { ...@@ -152,7 +152,14 @@ if (isset($formfields[guid])) {
$errors["NS File GUID"] = "Invalid characters"; $errors["NS File GUID"] = "Invalid characters";
} }
} }
if (isset($formfields[nsref])) { if (isset($formfields['copyid'])) {
if ($formfields[copyid] == "" ||
!preg_match("/^[-\w,:]*$/", $formfields['copyid'])) {
$errors["Copy ID"] = "Invalid characters";
}
$nsfilelocale = "copyid";
}
elseif (isset($formfields[nsref])) {
if ($formfields[nsref] == "" || if ($formfields[nsref] == "" ||
!preg_match("/^\d+$/", $formfields[nsref])) { !preg_match("/^\d+$/", $formfields[nsref])) {
$errors["NS File Reference"] = "Invalid characters"; $errors["NS File Reference"] = "Invalid characters";
...@@ -297,8 +304,11 @@ if (! TBProjAccessCheck($uid, $exp_pid, $exp_gid, $TB_PROJECT_CREATEEXPT)) { ...@@ -297,8 +304,11 @@ if (! TBProjAccessCheck($uid, $exp_pid, $exp_gid, $TB_PROJECT_CREATEEXPT)) {
# #
# Figure out the NS file to give to the script. Eventually we will allow # Figure out the NS file to give to the script. Eventually we will allow
# it to come inline as an XML argument. # it to come inline as an XML argument.
# #
if ($nsfilelocale == "local") { if ($nsfilelocale == "copyid") {
$thensfile = "-c " . $formfields['copyid'];
}
elseif ($nsfilelocale == "local") {
# #
# No way to tell from here if this file actually exists, since # No way to tell from here if this file actually exists, since
# the web server runs as user nobody. The startexp script checks # the web server runs as user nobody. The startexp script checks
......
...@@ -240,6 +240,11 @@ if ($wireless) { ...@@ -240,6 +240,11 @@ if ($wireless) {
WRITESUBMENUBUTTON("Show History", WRITESUBMENUBUTTON("Show History",
"showstats.php3?showby=expt&which=$expindex"); "showstats.php3?showby=expt&which=$expindex");
if (STUDLY()) {
WRITESUBMENUBUTTON("Duplicate Experiment",
"beginexp_html.php3?copyid=${exp_pid},${exp_eid}");
}
if ($EXPOSEARCHIVE) { if ($EXPOSEARCHIVE) {
WRITESUBMENUBUTTON("Experiment File Archive", WRITESUBMENUBUTTON("Experiment File Archive",
"cvsweb/cvswebwrap.php3?exptidx=$expindex"); "cvsweb/cvswebwrap.php3?exptidx=$expindex");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment