diff --git a/include/distribution.php b/include/distribution.php index 7a9f69e..20aa389 100644 --- a/include/distribution.php +++ b/include/distribution.php @@ -592,6 +592,29 @@ class distribution { { return "objectMakeUrl()."\">$this->sName"; } + + function objectMoveChildren($iNewId) + { + /* Keep track of how many children we modified */ + $iCount = 0; + + foreach($this->aTestingIds as $iTestId) + { + $oTest = new testData($iTestId); + $oTest->iDistributionId = $iNewId; + if($oTest->update(TRUE)) + $iCount++; + else + return FALSE; + } + + return $iCount; + } + + function objectGetid() + { + return $this->iDistributionId; + } } ?> diff --git a/include/objectManager.php b/include/objectManager.php index 90443e3..073a7df 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -249,6 +249,52 @@ class ObjectManager $this->delete_entry(); } + /* Display a page where the user can select which object the children of the current + object can be moved to */ + function display_move_children() + { + $oObject = new $this->sClass($this->iId); + if(!$oObject->canEdit()) + { + echo "Insufficient privileges.
\n"; + return FALSE; + } + + /* We only allow moving to non-queued objects */ + if(!$hResult = $oObject->objectGetEntries(false, false)) + { + echo "Failed to get list of objects.
\n"; + return FALSE; + } + + /* Display some help text */ + echo "

Move all child objects of ".$oObject->objectMakeLink()." to the entry "; + echo "selected below, and delete ".$oObject->objectMakeLink()." afterwards.

\n"; + + echo "\n"; + echo html_tr(array( + "Name", + "Move here"), + "color4"); + + for($i = 0; $oRow = mysql_fetch_object($hResult); $i++) + { + $oCandidate = $oObject->objectGetInstanceFromRow($oRow); + if($oCandidate->objectGetId() == $this->iId) + { + $i++; + continue; + } + + echo html_tr(array( + $oCandidate->objectMakeLink(), + "makeUrl("moveChildren", $this->iId). + "&iNewId=".$oCandidate->objectGetId()."\">Move here"), + ($i % 2) ? "color0" : "color1"); + } + echo "
\n"; + } + /* Display screen for submitting a new entry of given type */ function add_entry($sBackLink, $sErrors = "") { @@ -291,6 +337,15 @@ class ObjectManager $oObject = new $this->sClass($this->iId); + /* Display a link to the move child objects page if the class has the necessary + functions and the user has edit rights. Not all classes have child objects. */ + if(method_exists($oObject, "objectMoveChildren") && + method_exists($oObject, "objectGetId") && $oObject->canEdit()) + { + echo "makeUrl("showMoveChildren", $this->iId, + "Move Child Objects")."\">Move child objects

\n"; + } + $oObject->display(); echo html_back_link(1, $sBackLink); diff --git a/objectManager.php b/objectManager.php index bac7399..7ee5fc5 100644 --- a/objectManager.php +++ b/objectManager.php @@ -82,6 +82,10 @@ if($oObject->iId) $oObject->display_entry_for_editing($REQUEST_URI, $sErrors); break; + case "showMoveChildren": + $oObject->display_move_children(); + break; + default: $oObject->view($REQUEST_URI); break;