diff --git a/module/product/control.php b/module/product/control.php index 5c37ab4d87..0df3a80264 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -353,18 +353,20 @@ class product extends control $this->lang->product->switcherMenu = $this->loadModel('product')->getSwitcher($productID); $this->lang->product->mainMenuAction = $this->product->getProductMainAction(); - $product = $this->product->getById($productID); - /* Get the projects linked with this product. */ - $notRemoveProduct = array(); - $linkStoriesProjects = array(); + /* Init vars. */ + $product = $this->product->getById($productID); + $notRemovePRJ = array(); $canChangePGM = true; $singleLinkProjects = array(); $multipleLinkProjects = array(); + $linkStoriesProjects = array(); - $notRemoveProduct = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('product')->eq($productID)->fetchPairs('project', 'product'); - if(!empty($notRemoveProduct)) $canChangePGM = false; + /* Link the projects stories under this product. */ + $notRemovePRJ = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('product')->eq($productID)->fetchPairs('project', 'product'); + if(!empty($notRemovePRJ)) $canChangePGM = false; + /* Get the projects linked with this product. */ $projectPairs = $this->product->getProjectPairsByProduct($productID); if(!empty($projectPairs)) @@ -386,7 +388,7 @@ class product extends control } else { - if(isset($notRemoveProduct[$projectID])) $linkStoriesProjects[$projectID] = $projectName; + if(isset($notRemovePRJ[$projectID])) $linkStoriesProjects[$projectID] = $projectName; } } } @@ -466,9 +468,9 @@ class product extends control $this->view->lines = array('') + $this->loadModel('tree')->getLinePairs(); $this->view->URSRPairs = $this->loadModel('custom')->getURSRPairs(); $this->view->canChangePGM = $canChangePGM; - $this->view->linkStoriesProjects = $linkStoriesProjects; $this->view->singleLinkProjects = $singleLinkProjects; $this->view->multipleLinkProjects = $multipleLinkProjects; + $this->view->linkStoriesProjects = $linkStoriesProjects; unset($this->lang->product->typeList['']); $this->display(); diff --git a/module/product/js/edit.js b/module/product/js/edit.js index 93d9adcd40..94b63241b0 100644 --- a/module/product/js/edit.js +++ b/module/product/js/edit.js @@ -15,6 +15,12 @@ $(function() }) }); +/** + * Set projects of change program. + * + * @access public + * @return void + */ function setChangeProjects() { var projects = ','; diff --git a/module/product/model.php b/module/product/model.php index 181529d58b..388d84f041 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -1519,39 +1519,43 @@ class productModel extends model public function updateProjects($productID, $singleLinkProjects = array(), $multipleLinkProjects = array()) { $programID = $_POST['program']; - foreach($singleLinkProjects as $id => $project) + foreach($singleLinkProjects as $projectID => $projectName) { - if($project) + if($projectName) { $this->dao->update(TABLE_PROJECT) ->set('parent')->eq($programID) - ->set('path')->eq(',' . $programID . ',' . $id . ',') - ->where('id')->eq($id) + ->set('path')->eq(',' . $programID . ',' . $projectID . ',') + ->where('id')->eq($projectID) ->exec(); } } - foreach($multipleLinkProjects as $id => $project) + foreach($multipleLinkProjects as $projectID => $projectName) { - if(strpos($_POST['changeProjects'], ',' . $id . ',') !== false) + if(strpos($_POST['changeProjects'], ',' . $projectID . ',') !== false) { $this->dao->delete()->from(TABLE_PROJECTPRODUCT) - ->where('project')->eq($id) + ->where('project')->eq($projectID) ->andWhere('product')->ne($productID) ->exec(); $this->dao->update(TABLE_PROJECT) ->set('parent')->eq($programID) - ->set('path')->eq(',' . $programID . ',' . $id . ',') - ->where('id')->eq($id) + ->set('path')->eq(',' . $programID . ',' . $projectID . ',') + ->where('id')->eq($projectID) ->exec(); + + $this->loadModel('action')->create('project', $projectID, 'Managed', '', $productID); } else { $this->dao->delete()->from(TABLE_PROJECTPRODUCT) - ->where('project')->eq($id) + ->where('project')->eq($projectID) ->andWhere('product')->eq($productID) ->exec(); + $newProducts = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchPairs('product','product'); + $this->loadModel('action')->create('project', $projectID, 'Managed', '', join(',', $newProducts)); } } } diff --git a/module/product/view/edit.html.php b/module/product/view/edit.html.php index 90f582057f..41b93f8bb3 100644 --- a/module/product/view/edit.html.php +++ b/module/product/view/edit.html.php @@ -18,7 +18,7 @@