function report_import()
 {
     $groupId = $this->_controler->_actionParams['sGroupId'];
     $importReportId = $this->_controler->_actionParams['sImportReportId'];
     $importGroupId = $this->_controler->_actionParams['sImportGroupId'];
     $user =& $this->_controler->getUser();
     // Any user can importreports from any public projects and from
     // Private projects he is member of.
     $pm = ProjectManager::instance();
     $go = $pm->getProject($importGroupId);
     if ($go != false && ($go->isPublic() || !$go->isPublic() && $go->userIsMember())) {
         $srcReportFactory = new Docman_ReportFactory($importGroupId);
         // Get the mapping between src and current project metadata definition.
         $mdMap = array();
         $srcMdFactory = new Docman_MetadataFactory($importGroupId);
         $srcMdFactory->getMetadataMapping($groupId, $mdMap);
         // Get the mapping between src and current project items definition for the item involved
         // in the reports.
         $itemMapping = array();
         // Get involved items
         $srcReportItems = $srcReportFactory->getReportsItems($importReportId);
         if (count($srcReportItems) > 0) {
             // Get the subtree from the original docman on which reports applies
             $srcItemFactory = new Docman_ItemFactory($importGroupId);
             $srcItemTree = $srcItemFactory->getItemTreeFromLeaves($srcReportItems, $user);
             if ($srcItemTree !== null) {
                 // Final step: find in the current ($groupId) docman
                 $dstItemFactory = new Docman_ItemFactory($groupId);
                 $itemMapping = $dstItemFactory->getItemMapping($srcItemTree);
             }
         }
         // If user is admin he can create 'P' report otherwise everything is 'I'
         $forceScope = true;
         if ($this->_controler->userCanAdmin()) {
             $forceScope = false;
         }
         if ($importReportId !== null) {
             // Import only one report
             $report = $srcReportFactory->getReportById($importReportId);
             if ($report !== null) {
                 // User can import Project wide reports or his own Individual reports.
                 if ($report->getScope() == 'P' || $report->getScope() == 'I' && $report->getUserId() == $user->getId()) {
                     $srcReportFactory->cloneReport($report, $groupId, $mdMap, $user, $forceScope, $itemMapping);
                     $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'report_clone_success'));
                 } else {
                     $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'report_err_clone_iorp'));
                 }
             } else {
                 $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'report_err_notfound', array($importReportId)));
             }
         } else {
             // Import all personal and project reports from the given project.
             $srcReportFactory->copy($groupId, $mdMap, $user, $forceScope, $itemMapping);
             $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'report_clone_success'));
         }
     } else {
         $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_generic'));
     }
 }
 function getMetadataCompareTable(&$sthToImport)
 {
     $html = '';
     // True if there is sth to import in dst project.
     $sthToImport = false;
     // For source project, only get the 'Used' metadata.
     $srcMdFactory = new Docman_MetadataFactory($this->srcGo->getGroupId());
     $srcMdIter = $srcMdFactory->getMetadataForGroup(true);
     // For destination (current) project, get all metadata.
     $dstMdFactory = new Docman_MetadataFactory($this->dstGo->getGroupId());
     $dstMdIter = $dstMdFactory->getMetadataForGroup();
     $dstMdArray = $this->getArrayFromIterator($dstMdIter, 'getLabel');
     // Get mapping between the 2 definitions
     $mdMap = array();
     $srcMdFactory->getMetadataMapping($this->dstGo->getGroupId(), $mdMap);
     $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_desc', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName()));
     // Table
     $html .= "<table border=\"1\">\n";
     $html .= "<tr>\n";
     $html .= "<th colspan=\"2\">" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_prop') . "</th>\n";
     $html .= "<th>" . $this->srcGo->getPublicName() . "</th>\n";
     $html .= "<th>" . $this->dstGo->getPublicName() . "</th>\n";
     $html .= "<th>" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_diff', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName())) . "</th>\n";
     $html .= "<th>" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_action', array($this->dstGo->getPublicName())) . "</th>\n";
     $html .= "</tr>\n";
     // Keep a trace of metadata that matched in the dst metadata list.
     $matchingMd = array();
     $srcMdIter->rewind();
     while ($srcMdIter->valid()) {
         $srcMd = $srcMdIter->current();
         $dstMd = null;
         //
         // Compute the differences between the 2 projects
         //
         $dstMdStatus = 'missing';
         $dstMdLabel = '';
         if ($srcMdFactory->isRealMetadata($srcMd->getLabel())) {
             if (isset($mdMap['md'][$srcMd->getId()])) {
                 $dstMdLabel = $srcMdFactory->getLabelFromId($mdMap['md'][$srcMd->getId()]);
             }
         } else {
             $dstMdLabel = $srcMd->getLabel();
         }
         if (isset($dstMdArray[$dstMdLabel])) {
             $dstMd = $dstMdArray[$dstMdLabel];
             if ($dstMd !== false) {
                 $matchingMd[$dstMdLabel] = true;
                 $dstMdStatus = 'equivalent';
                 if ($dstMd->equals($srcMd)) {
                     $dstMdStatus = 'equals';
                 } else {
                     $sthToImport = true;
                 }
             } else {
                 $sthToImport = true;
             }
         } else {
             // The metadata is not in the metadata map list, check if it's
             // not a name conflict
             $dstMdi = $dstMdFactory->findByName($srcMd->getName());
             if ($dstMdi->count() == 1) {
                 $dstMdStatus = 'conflict';
             } else {
                 $sthToImport = true;
             }
         }
         //
         // Display result
         //
         $html .= "<tr>\n";
         // Property
         $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">";
         $html .= $srcMd->getName();
         $html .= "</td>";
         // Presence in source project
         $html .= "<td align=\"center\">";
         $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />';
         $html .= "</td>";
         // Presence in destination project
         $html .= "<td align=\"center\">";
         switch ($dstMdStatus) {
             case 'equals':
             case 'equivalent':
                 $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />';
                 break;
         }
         $html .= "</td>";
         // Differences
         $html .= "<td class=\"docman_md_" . $dstMdStatus . "\">";
         switch ($dstMdStatus) {
             case 'equivalent':
             case 'missing':
             case 'conflict':
                 $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_status_' . $dstMdStatus);
                 break;
         }
         $html .= "</td>";
         // Action
         $html .= "<td>";
         switch ($dstMdStatus) {
             case 'equals':
                 // Nothing to do
                 break;
             case 'equivalent':
                 $diffArray = $this->checkMdDifferences($srcMd, $dstMd, $mdMap['love']);
                 $diffStr = '<ul style="padding:0;padding-left:1.5em;margin:0;"><li>';
                 $diffStr .= implode('</li><li>', $diffArray);
                 $diffStr .= '</li></ul>';
                 $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_update_md', array($srcMd->getName(), $this->dstGo->getPublicName(), $diffStr));
                 break;
             case 'missing':
                 $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_import_md', array($srcMd->getName()));
                 break;
             case 'conflict':
                 $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_conflict');
                 break;
         }
         $html .= "</td>";
         $html .= "</tr>\n";
         //
         // List of values
         //
         if ($srcMd->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
             if ($dstMd !== null) {
                 $html .= $this->getLoveCompareTable($srcMd, $dstMd, $mdMap, $sthToImport);
             }
         }
         unset($dstMd);
         $srcMdIter->next();
     }
     // Append to the table the metadata in the dst project that where not
     // present in the src project.
     foreach ($dstMdArray as $md) {
         if (!isset($matchingMd[$md->getLabel()])) {
             $html .= "<tr>\n";
             // Name
             $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">";
             $html .= $md->getName();
             $html .= "</td>";
             // Presence in source project
             $html .= "<td></td>";
             // Presence in destination project
             $html .= "<td align=\"center\">";
             $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />';
             $html .= "</td>";
             // Differences
             $html .= "<td></td>";
             // Action
             $html .= "<td></td>";
             $html .= "</td>";
             $html .= "</tr>\n";
         }
     }
     $html .= "</table>\n";
     return $html;
 }