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 _getReportSettings($reportId)
 {
     $html = '';
     $um =& UserManager::instance();
     $user = $um->getCurrentUser();
     $dpm =& Docman_PermissionsManager::instance($this->groupId);
     $isAdmin = $dpm->userCanAdmin($user);
     $reportFactory = new Docman_ReportFactory($this->groupId);
     $r = $reportFactory->getReportById($reportId);
     if ($r != null && $r->getGroupId() == $this->groupId) {
         $txts = array($GLOBALS['Language']->getText('plugin_docman', 'report_scope_I'), $GLOBALS['Language']->getText('plugin_docman', 'report_scope_P'));
         $vals = array('I', 'P');
         $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_info') . '</p>';
         $html .= '<form name="docman_report_update" method="post" action="?" class="docman_form">';
         $html .= '<input type="hidden" name="group_id" value="' . $this->groupId . '">';
         $html .= '<input type="hidden" name="action" value="report_upd">';
         $html .= '<input type="hidden" name="report_id" value="' . $r->getId() . '">';
         $html .= '<table>';
         // Scope
         if ($dpm->userCanAdmin($user)) {
             $html .= '<tr>';
             $html .= '<td>' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_scope') . '</td>';
             $html .= '<td>';
             $html .= html_build_select_box_from_arrays($vals, $txts, 'scope', $r->getScope(), false);
             $html .= '</td>';
             $html .= '</tr>';
         }
         // Description
         $html .= '<tr>';
         $html .= '<td>' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_description') . '</td>';
         $html .= '<td>';
         $html .= '<textarea name="description">' . $r->getDescription() . '</textarea>';
         $html .= '</td>';
         $html .= '</tr>';
         // Title
         $title = "";
         if ($r->getTitle() !== null) {
             $title = $r->getTitle();
         }
         $html .= '<tr>';
         $html .= '<td>' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_title') . '</td>';
         $html .= '<td>';
         $html .= '<input type="text" name="title" value="' . $title . '" class="text_field" />';
         $html .= '</td>';
         $html .= '</tr>';
         // Image
         $image = "";
         if ($r->getImage() !== null) {
             $image = $r->getImage();
         }
         $html .= '<tr>';
         $html .= '<td>' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_image') . '</td>';
         $html .= '<td>';
         $html .= '<input type="text" name="image" value="' . $image . '" />';
         $html .= ' ' . $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_image_help');
         $html .= '</td>';
         $html .= '</tr>';
         // Current image
         $html .= '<tr>';
         $html .= '<td>';
         $html .= $GLOBALS['Language']->getText('plugin_docman', 'report_settings_report_image_current');
         $html .= '</td>';
         $reportHtml = new Docman_ReportHtml($r, $this, $this->defaultUrl);
         $html .= '<td>';
         $html .= $reportHtml->getReportImage();
         $html .= '</td>';
         $html .= '</tr>';
         // Submit
         $html .= '<tr>';
         $html .= '<td colspan="2">';
         $html .= '<input type="submit" name="sub" value="' . $GLOBALS['Language']->getText('global', 'btn_update') . '">';
         $html .= '</td>';
         $html .= '</tr>';
         $html .= '</table>';
         $html .= '</form>';
     }
     return $html;
 }