function _initReport($item)
 {
     $reportFactory = new Docman_ReportFactory($this->getGroupId());
     if ($this->reportId === null && $this->request->exist('report_id')) {
         $this->reportId = (int) $this->request->get('report_id');
     }
     $report =& $reportFactory->get($this->reportId, $this->request, $item, $this->feedback);
     $this->_viewParams['filter'] =& $report;
 }
 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'));
     }
 }
 /**
  * Clone reports of one project into another one
  *
  * @param $srcReport       Original report.
  * @param $dstGroupId      Id of the destination project.
  * @param $metadataMapping Mapping between $srcReport project metadata and $dstGroupId metadata (for fields associated to reports).
  * @param $user            User who will own the newly created reports.
  * @param $forceScopeToI   Force scope of the new reports to I (individual).
  * @param $itemMapping     Mapping between $srcReport project items and $dstGroupId items (for folders associated to report).
  */
 function cloneReport($srcReport, $dstGroupId, $metadataMapping, $user, $forceScopeToI = false, $itemMapping = array())
 {
     $dstReportFactory = new Docman_ReportFactory($dstGroupId);
     $srcFilterFactory = new Docman_FilterFactory($this->groupId);
     // Create new report
     // @php5: clone
     $dstReport = clone $srcReport;
     $dstReport->setGroupId($dstGroupId);
     $dstReport->setUserId($user->getId());
     if ($forceScopeToI) {
         $dstReport->setScope('I');
     }
     // Be carful with reports associated to an item.
     if ($srcReport->getGroupId() != $dstGroupId) {
         if ($srcReport->getItemId() !== null && $srcReport->getItemId() != 0 && isset($itemMapping[$srcReport->getItemId()])) {
             $dstReport->setItemId($itemMapping[$srcReport->getItemId()]);
         } else {
             $dstReport->setItemId(0);
         }
     }
     // Save report
     $rId = $dstReportFactory->createReport($dstReport);
     if ($rId !== false) {
         $dstReport->setId($rId);
         // Copy filters
         $srcFilterFactory->copy($srcReport, $dstReport, $metadataMapping);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Entry point
  */
 function toHtml($params)
 {
     $html = '';
     $html .= $this->getReportSelector($params['item']);
     $toggleIc = '<img src="' . util_get_image_theme("ic/toggle_minus.png") . '" id="docman_toggle_filters" >';
     $toggle = '<a href="#" title="' . $GLOBALS['Language']->getText('plugin_docman', 'report_toggle_tooltip') . '">' . $toggleIc . '</a>';
     $title = $GLOBALS['Language']->getText('plugin_docman', 'filters');
     $hidden_fields = '';
     $hidden_fields .= '<input type="hidden" name="group_id" value="' . $this->report->getGroupId() . '" />';
     $hidden_fields .= '<input type="hidden" name="id" value="' . $params['item']->getId() . '" />';
     $hidden_fields .= '<input type="hidden" name="action" value="search" />';
     $global_txt = $this->hp->purify($params['docman']->request->get('global_txt'));
     $html .= "<div id=\"docman_filters_title\">\n";
     $html .= '<form method="get" action="?" id="plugin_docman_report_form_global">';
     $html .= $toggle;
     $html .= ' ' . $title . ' ';
     $html .= $hidden_fields;
     $html .= '<input type="text" 
     				 class="text_field" 
     				 title="' . $GLOBALS['Language']->getText('plugin_docman', 'filters_global_txt') . '" 
     				 value="' . $global_txt . '" 
     				 name="global_txt" 
     				 />';
     $html .= '<input type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_apply') . '" name="global_filtersubmit" />';
     $html .= '</form>';
     $html .= "</div>\n";
     $html .= "<div id=\"docman_filters_fieldset\">\n";
     $html .= '<div style="float: left;">';
     $html .= '<form name="plugin_docman_filters" method="get" action="?" id="plugin_docman_report_form" >';
     $html .= $hidden_fields;
     $displayedFilters = array();
     $html .= $this->getSelectedFilters($params, $displayedFilters);
     $html .= $this->getFiltersOptions($params, $displayedFilters);
     $html .= $this->getReportOptions();
     $html .= '<input id="docman_report_submit" name="filtersubmit" type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_apply') . '">';
     $html .= '&nbsp;';
     $html .= '<input id="docman_report_submit" name="clear_filters" type="submit" value="' . $GLOBALS['Language']->getText('plugin_docman', 'report_clear_filters') . '">';
     $html .= '</form>';
     $html .= "</div> <!-- left -->\n";
     $html .= '<div style="float: right;">';
     //Retrieve the minimum length allowed when searching pattern
     $dao = Docman_ReportFactory::getDao();
     $minLen = $dao->getMinLengthForPattern();
     $html .= '<div class="docman_help">' . $GLOBALS['Language']->getText('plugin_docman', 'search_help', array($minLen)) . '</div>';
     $html .= '</div>';
     $html .= '<div style="clear: both;"></div>';
     $html .= "</div> <!-- docman_filters_fieldset -->\n";
     $html .= "\n<!-- filter list -->\n";
     return $html;
 }
 /**
  *
  */
 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;
 }