function getTable($params)
 {
     $this->defaultUrl = $params['default_url'];
     $content = '';
     $content .= html_build_list_table_top(array($GLOBALS['Language']->getText('plugin_docman', 'view_documenttable_title'), $GLOBALS['Language']->getText('plugin_docman', 'view_documenttable_location'), $GLOBALS['Language']->getText('plugin_docman', 'admin_lock_infos_who'), $GLOBALS['Language']->getText('plugin_docman', 'admin_lock_infos_when')));
     // Get list of all locked documents in the project.
     $dPM = Docman_PermissionsManager::instance($params['group_id']);
     $lockInfos = $dPM->getLockFactory()->getProjectLockInfos($params['group_id']);
     $uH = UserHelper::instance();
     $hp = Codendi_HTMLPurifier::instance();
     require_once dirname(__FILE__) . '/../Docman_ItemFactory.class.php';
     $dIF = new Docman_ItemFactory($params['group_id']);
     $altRowClass = 0;
     foreach ($lockInfos as $row) {
         $trclass = html_get_alt_row_color($altRowClass++);
         $item = $dIF->getItemFromDb($row['item_id']);
         $parent = $dIF->getItemFromDb($item->getParentId());
         $content .= '<tr class="' . $trclass . '">';
         $content .= '<td>' . '<a href="/plugins/docman/?group_id=' . $params['group_id'] . '&action=details&id=' . $item->getId() . '">' . $item->getTitle() . '</a></td>';
         $content .= '<td>';
         if ($dIF->isRoot($parent)) {
             $content .= '</td>';
         } else {
             $content .= '<a href="' . $this->defaultUrl . '&action=show&id=' . $parent->getId() . '">' . $parent->getTitle() . '</a></td>';
         }
         $content .= '<td>' . $hp->purify($uH->getDisplayNameFromUserId($row['user_id'])) . '</td>';
         $content .= '<td>' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $row['lock_date']) . '</td>';
         $content .= '</tr>';
     }
     $content .= '</table>';
     return $content;
 }
 /**
  * Constuctor of the class
  *
  * @param User $user
  * @param Project $project
  * @param Docman_Document $item
  *
  * @return void
  */
 function __construct($user, $project, $item)
 {
     $this->user = $user;
     $this->project = $project;
     $docmanItemFactory = new Docman_ItemFactory();
     $this->item = $docmanItemFactory->getItemFromDb($item->getId());
 }
 public function docmanwatermark_toggle_item()
 {
     $itemId = $this->_controler->request->getValidated('item_id', 'UInt');
     if ($itemId != null && $this->_controler->userCanManage($itemId) && $this->_controler->request->isPost()) {
         $itemFactory = new Docman_ItemFactory();
         $dwItemFactory = new DocmanWatermark_ItemFactory();
         $dwLog = new DocmanWatermark_Log();
         $item = $itemFactory->getItemFromDb($itemId);
         $user = $this->_controler->getUser();
         if ($this->_controler->request->existAndNonEmpty('disable_watermarking')) {
             if ($dwItemFactory->disableWatermarking($itemId)) {
                 $dwLog->disableWatermarking($item, $user);
                 $dwItemFactory->notifyOnDisable($item, $user, $this->_controler->getDefaultUrl());
                 $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_disabled'));
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_disable_error'));
             }
         } else {
             if ($dwItemFactory->enableWatermarking($itemId)) {
                 $dwLog->enableWatermarking($item, $user);
                 $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_enabled'));
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'action_watermarking_enable_error'));
             }
         }
         $this->_controler->view = 'RedirectAfterCrud';
         $this->_controler->_viewParams['redirect_to'] = $this->_controler->getDefaultUrl() . '&action=details&id=' . $itemId . '&section=watermarking';
     } else {
         // Bad Item Id or attempt to fake the server, redirect to root
         // @todo: log those kind of attempt.
         $this->_controler->view = 'RedirectAfterCrud';
         $this->_controler->_viewParams['redirect_to'] = $this->_controler->getDefaultUrl();
     }
 }
 function _content($params)
 {
     $itemFactory = new Docman_ItemFactory($params['group_id']);
     $itemTree =& $itemFactory->getItemSubTree($params['item'], $params['user']);
     $displayItemTreeVisitor = new Docman_View_ItemTreeUlVisitor($this, array('theme_path' => $params['theme_path'], 'docman_icons' => $this->_getDocmanIcons($params), 'default_url' => $params['default_url'], 'show_options' => $this->_controller->request->exist('show_options') ? $this->_controller->request->get('show_options') : false, 'pv' => isset($params['pv']) ? $params['pv'] : false, 'report' => isset($params['report']) ? $params['report'] : false, 'item' => $params['item']));
     $itemTree->accept($displayItemTreeVisitor);
     $this->javascript .= $displayItemTreeVisitor->getJavascript();
     echo $displayItemTreeVisitor->toHtml();
 }
 public function gatherPermissions()
 {
     // Collect data
     $itemFactory = new Docman_ItemFactory($this->group->getId());
     $rootItem = $itemFactory->getRoot($this->group->getId());
     $this->parentTitles[$rootItem->getId()] = '';
     $output = array();
     $this->fetchPerms(array($rootItem->getId()), $output);
     return $output;
 }
 function display($params)
 {
     $itemFactory = new Docman_ItemFactory($params['group_id']);
     $nbItemsFound = 0;
     $itemIterator = $itemFactory->getItemList($params['item']->getId(), $nbItemsFound, array('user' => $params['user'], 'ignore_collapse' => true, 'ignore_obsolete' => true, 'filter' => $params['filter'], 'getall' => true));
     $result = array();
     foreach ($itemIterator as $item) {
         $result[] = $item->toRow();
     }
     return $result;
 }
 /**
  * Process the system event
  *
  * @return bool
  */
 public function process()
 {
     try {
         $project_id = (int) $this->getRequiredParameter(0);
         if ($this->system_event_manager->isProjectReindexationAlreadyQueued($project_id)) {
             $this->done('Skipped duplicate event');
             $this->logger->debug("Skipped duplicate event for project {$project_id} : " . self::NAME);
             return true;
         }
         $item_factory = Docman_ItemFactory::instance($project_id);
         $items = new Docman_ProjectItemsBatchIterator($item_factory, $project_id);
         $notindexed_collector = new FullTextSearch_NotIndexedCollector();
         $this->actions->reIndexProjectDocuments($items, $project_id, $notindexed_collector);
         if (!$notindexed_collector->isAtLeastOneIndexed()) {
             $this->error('Nothing has been indexed. See syslog for details.');
             return false;
         } else {
             if ($notindexed_collector->isAtLeastOneNotIndexed()) {
                 $this->warning('Some items were not indexed: [' . implode(', ', $notindexed_collector->getIds()) . ']. See syslog for details.');
             } else {
                 $this->done();
             }
         }
         return true;
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     return false;
 }
 function _getStatisticsFields($params)
 {
     $html = '';
     if (is_a($this->item, 'Docman_Folder')) {
         $if = Docman_ItemFactory::instance($this->_controller->getGroupId());
         $stats = $if->getFolderStats($this->item, $this->_controller->getUser());
         $size = $this->convertBytesToHumanReadable($stats['size']);
         // Summary
         $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_summary') . '</h3>';
         $html .= '<table class="docman_item_details_properties">';
         $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_size'), $size);
         $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_children_count'), $stats['count']);
         $html .= '</table>';
         // Details
         if ($stats['count'] > 0) {
             $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_details') . '</h3>';
             $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'details_statistics_details_description') . '</p>';
             $html .= '<table class="docman_item_details_properties">';
             arsort($stats['types']);
             foreach ($stats['types'] as $type => $stat) {
                 $html .= $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_statistics_item_type_' . strtolower($type)), $stat);
             }
             $html .= '</table>';
         }
     }
     return $html;
 }
 function display($params)
 {
     $result = array();
     $itemFactory = new Docman_ItemFactory($params['group_id']);
     $itemTree =& $itemFactory->getItemSubTree($params['item'], $params['user']);
     $items = $itemTree->getAllItems();
     $nb = $items->size();
     if ($nb) {
         $it =& $items->iterator();
         while ($it->valid()) {
             $o =& $it->current();
             $result[] = $o->toRow();
             $it->next();
         }
     }
     return $result;
 }
 function _getDirectLinkField()
 {
     $html = '';
     $itemFactory = new Docman_ItemFactory();
     if ($itemFactory->getItemTypeForItem($this->item) != PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) {
         $dpm =& Docman_PermissionsManager::instance($this->item->getGroupId());
         $um =& UserManager::instance();
         $user = $um->getCurrentUser();
         if (!$this->item->isObsolete() || $this->item->isObsolete() && $dpm->userCanAdmin($user)) {
             $label = $GLOBALS['Language']->getText('plugin_docman', 'details_properties_view_doc_lbl');
             $url = $this->url . '&action=show&id=' . $this->item->getId();
             $href = '<a href="' . $url . '">' . $GLOBALS['Language']->getText('plugin_docman', 'details_properties_view_doc_val') . '</a>';
         }
         $html = $this->_getPropertyRow($GLOBALS['Language']->getText('plugin_docman', 'details_properties_view_doc_lbl'), $href);
     }
     return $html;
 }
 function _content($params)
 {
     $html = '';
     $itemFactory = new Docman_ItemFactory($params['group_id']);
     $itemTree =& $itemFactory->getItemSubTree($params['item'], $params['user']);
     $items = $itemTree->getAllItems();
     $nb = $items->size();
     if ($nb) {
         $html .= '<table border="0" cellpadding="0" cellspacing="4" width="100%">';
         $folders = array();
         $documents = array();
         $it = $items->iterator();
         while ($it->valid()) {
             $o = $it->current();
             $this->is_folder = false;
             $o->accept($this);
             if ($this->is_folder) {
                 $folders[] = $o;
             } else {
                 $documents[] = $o;
             }
             $it->next();
         }
         $nb_of_columns = 4;
         $width = floor(100 / $nb_of_columns);
         $sort = create_function('&$a, &$b', 'return strnatcasecmp($a->getTitle(), $b->getTitle());');
         usort($folders, $sort);
         usort($documents, $sort);
         $cells = array_merge($folders, $documents);
         $rows = array_chunk($cells, $nb_of_columns);
         $item_parameters = array('icon_width' => '32', 'theme_path' => $params['theme_path'], 'get_action_on_icon' => new Docman_View_GetActionOnIconVisitor(), 'docman_icons' => $this->_getDocmanIcons($params), 'default_url' => $params['default_url'], 'show_options' => $this->_controller->request->exist('show_options') ? $this->_controller->request->get('show_options') : false, 'item' => $params['item']);
         foreach ($rows as $row) {
             $html .= '<tr style="vertical-align:top">';
             foreach ($row as $cell => $nop) {
                 $html .= '<td width="' . $width . '%">' . $this->_displayItem($row[$cell], $item_parameters) . '</td>';
             }
             $html .= '<td width="' . $width . '%">&nbsp;</td>';
             $html .= '</tr>';
         }
         $html .= '</table>' . "\n";
     }
     echo $html;
 }
 function getTable($params)
 {
     $html = '';
     // Get root
     $itemFactory = new Docman_ItemFactory($params['group_id']);
     $rootItem = $itemFactory->getRoot($params['group_id']);
     $nbItemsFound = 0;
     $itemIterator =& $itemFactory->getItemList($rootItem->getId(), $nbItemsFound, array('user' => $params['user'], 'ignore_collapse' => true, 'obsolete_only' => true));
     $table = html_build_list_table_top(array('Title', 'Obsolete date'));
     $altRowClass = 0;
     $itemIterator->rewind();
     while ($itemIterator->valid()) {
         $item =& $itemIterator->current();
         $type = $itemFactory->getItemTypeForItem($item);
         if ($type != PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) {
             $trclass = html_get_alt_row_color($altRowClass++);
             $table .= "<tr class=\"" . $trclass . "\">\n";
             // Name
             $docmanIcons =& $this->_getDocmanIcons($params);
             $icon_src = $docmanIcons->getIconForItem($item, $params);
             $icon = '<img src="' . $icon_src . '" class="docman_item_icon" />';
             $table .= "<td>";
             $table .= '<span style="white-space: nowrap;">';
             $table .= $icon;
             $url = $this->buildActionUrl($params, array('action' => 'details', 'id' => $item->getId()), false, true);
             $table .= '<a href="' . $url . '">';
             $table .= htmlentities($item->getTitle(), ENT_QUOTES, 'UTF-8');
             $table .= '</a>';
             $table .= '</span>';
             $table .= "</td>\n";
             // Obsolete date
             $table .= "<td>";
             $table .= format_date("Y-m-j", $item->getObsolescenceDate());
             $table .= "</td>\n";
             $table .= "</tr>\n";
         }
         $itemIterator->next();
     }
     $table .= "</table>\n";
     $html = $table;
     return $html;
 }
 public function setUp()
 {
     parent::setUp();
     $this->client = partial_mock('ElasticSearch_IndexClientFacade', array('index', 'update', 'delete', 'getMapping', 'setMapping', 'getIndexedElement'));
     $this->item_factory = mock('Docman_ItemFactory');
     Docman_ItemFactory::setInstance(200, $this->item_factory);
     $this->permissions_manager = mock('Docman_PermissionsItemManager');
     $metadata01 = stub('Docman_Metadata')->getId()->returns(1);
     $metadata02 = stub('Docman_Metadata')->getId()->returns(2);
     $hardcoded_metadata_title = stub('Docman_Metadata')->getLabel()->returns('title');
     stub($hardcoded_metadata_title)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
     $hardcoded_metadata_description = stub('Docman_Metadata')->getLabel()->returns('description');
     stub($hardcoded_metadata_description)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_TEXT);
     $hardcoded_metadata_owner = stub('Docman_Metadata')->getLabel()->returns('owner');
     stub($hardcoded_metadata_owner)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
     $hardcoded_metadata_create_date = stub('Docman_Metadata')->getLabel()->returns('create_date');
     stub($hardcoded_metadata_create_date)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
     $hardcoded_metadata_update_date = stub('Docman_Metadata')->getLabel()->returns('update_date');
     stub($hardcoded_metadata_update_date)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
     $hardcoded_metadata_status = stub('Docman_Metadata')->getLabel()->returns('status');
     stub($hardcoded_metadata_status)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_LIST);
     $hardcoded_metadata_obsolescence_date = stub('Docman_Metadata')->getLabel()->returns('obsolescence_date');
     stub($hardcoded_metadata_obsolescence_date)->getType()->returns(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
     $hardcoded_metadata = array($hardcoded_metadata_title, $hardcoded_metadata_description, $hardcoded_metadata_owner, $hardcoded_metadata_create_date, $hardcoded_metadata_update_date, $hardcoded_metadata_update_date, $hardcoded_metadata_obsolescence_date);
     $this->item = aDocman_File()->withId(101)->withTitle('Coin')->withOwnerId(123)->withDescription('Duck typing')->withGroupId(200)->build();
     stub($this->item)->getCreateDate()->returns(1403160945);
     stub($this->item)->getUpdateDate()->returns(1403160949);
     $first_search_type = array(PLUGIN_DOCMAN_METADATA_TYPE_TEXT, PLUGIN_DOCMAN_METADATA_TYPE_STRING);
     $this->metadata_factory = stub('Docman_MetadataFactory')->getRealMetadataList(false, $first_search_type)->returns(array($metadata01, $metadata02));
     stub($this->metadata_factory)->getHardCodedMetadataList()->returns($hardcoded_metadata);
     stub($this->metadata_factory)->getMetadataValue($this->item, $metadata01)->returns('val01');
     stub($this->metadata_factory)->getMetadataValue($this->item, $metadata02)->returns('val02');
     $this->approval_table_factories_factory = mock('Docman_ApprovalTableFactoriesFactory');
     stub($this->approval_table_factories_factory)->getSpecificFactoryFromItem($this->item)->returns(mock('Docman_ApprovalTableFileFactory'));
     $this->request_data_factory = new ElasticSearch_1_2_RequestDocmanDataFactory($this->metadata_factory, $this->permissions_manager, $this->approval_table_factories_factory);
     $max_indexed_file_size = 9;
     //our valid test file is 8 bits in size
     $this->actions = new FullTextSearchDocmanActions($this->client, $this->request_data_factory, mock('BackendLogger'), $max_indexed_file_size);
     stub($this->permissions_manager)->exportPermissions($this->item)->returns(array(3, 102));
     $this->version = stub('Docman_Version')->getPath()->returns(dirname(__FILE__) . '/_fixtures/file.txt');
     $this->big_version = stub('Docman_Version')->getPath()->returns(dirname(__FILE__) . '/_fixtures/big_file.txt');
     $this->params = aSetOfParameters()->withItem($this->item)->withVersion($this->version)->build();
 }
 function visitFolder(&$item, $params = array())
 {
     if ($this->dPm->userCanWrite($this->user, $item->getId())) {
         $this->actions['canNewDocument'] = true;
         $this->actions['canNewFolder'] = true;
         $pasteItemId = $this->if->getCutPreference($this->user, $item->getGroupId());
         $itemFactory = Docman_ItemFactory::instance($item->getGroupId());
         $parents = $itemFactory->getParents($item->getId());
         $this->actions['parents'] = $parents;
         if ($this->if->getCopyPreference($this->user) !== false || $pasteItemId !== false && $pasteItemId != $item->getId() && !(isset($parents[$pasteItemId]) && $parents[$pasteItemId])) {
             $this->actions['canPaste'] = true;
         }
     }
     $actions = $this->visitItem($item, $params);
     // Cannot lock nor unlock a folder yet.
     $this->actions['canUnlock'] = false;
     $this->actions['canLock'] = false;
     return $this->actions;
 }
 function getDropDownWidget($parentItem)
 {
     $itemFactory =& Docman_ItemFactory::instance($parentItem->getGroupId());
     $brotherIter = $itemFactory->getChildrenFromParent($parentItem);
     $vals = array('beginning', 'end', '--');
     $texts = array($GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_beg'), $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_end'), '----');
     $i = 3;
     $pm =& Docman_PermissionsManager::instance($parentItem->getGroupId());
     $um =& UserManager::instance();
     $user =& $um->getCurrentUser();
     $hp = Codendi_HTMLPurifier::instance();
     $brotherIter->rewind();
     while ($brotherIter->valid()) {
         $item = $brotherIter->current();
         if ($pm->userCanWrite($user, $item->getId())) {
             $vals[$i] = $item->getRank() + 1;
             $texts[$i] = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_after') . ' ' . $hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML);
             $i++;
         }
         $brotherIter->next();
     }
     // Cannot use html_build_select_box_from_arrays because of to lasy == operator
     // In this case because of cast string values are converted to 0 on cmp. So if
     // there is a rank == 0 ... so bad :/
     $html = '';
     $html = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_position') . ' ';
     $html .= '<select name="' . $this->dropDownName . '">' . "\n";
     $maxOpts = count($vals);
     for ($i = 0; $i < $maxOpts; $i++) {
         $selected = '';
         if ($vals[$i] === $this->selectedValue) {
             $selected = ' selected="selected"';
         }
         $html .= '<option value="' . $vals[$i] . '"' . $selected . '>' . $texts[$i] . '</option>' . "\n";
     }
     $html .= '</select>';
     return $html;
 }
 function _getSpecificProperties($params)
 {
     $html = '';
     $currentItemType = null;
     if (isset($params['force_item'])) {
         $currentItemType = Docman_ItemFactory::getItemTypeForItem($params['force_item']);
     }
     $specifics = array(array('type' => PLUGIN_DOCMAN_ITEM_TYPE_EMPTY, 'label' => $GLOBALS['Language']->getText('plugin_docman', 'new_document_empty'), 'obj' => isset($params['force_item']) && $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_EMPTY ? $params['force_item'] : new Docman_Empty(), 'checked' => $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_EMPTY), array('type' => PLUGIN_DOCMAN_ITEM_TYPE_LINK, 'label' => $GLOBALS['Language']->getText('plugin_docman', 'new_document_link'), 'obj' => isset($params['force_item']) && $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_LINK ? $params['force_item'] : new Docman_Link(), 'checked' => $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_LINK));
     $wikiAvailable = true;
     if (isset($params['group_id'])) {
         $pm = ProjectManager::instance();
         $go = $pm->getProject($params['group_id']);
         $wikiAvailable = $go->usesWiki() || $go->usesService('plugin_phpwiki');
     }
     if ($wikiAvailable) {
         $specifics[] = array('type' => PLUGIN_DOCMAN_ITEM_TYPE_WIKI, 'label' => $GLOBALS['Language']->getText('plugin_docman', 'new_document_wiki'), 'obj' => isset($params['force_item']) && $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_WIKI ? $params['force_item'] : new Docman_Wiki(), 'checked' => $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_WIKI);
     }
     $specifics[] = array('type' => PLUGIN_DOCMAN_ITEM_TYPE_FILE, 'label' => $GLOBALS['Language']->getText('plugin_docman', 'new_document_file'), 'obj' => isset($params['force_item']) && $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_FILE ? $params['force_item'] : new Docman_File(), 'checked' => $currentItemType !== null ? $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_FILE : true);
     if ($this->_controller->getProperty('embedded_are_allowed')) {
         $specifics[] = array('type' => PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE, 'label' => $GLOBALS['Language']->getText('plugin_docman', 'new_document_embedded'), 'obj' => isset($params['force_item']) && $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE ? $params['force_item'] : new Docman_EmbeddedFile(), 'checked' => $currentItemType == PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE);
     }
     $get_specific_fields = new Docman_View_GetSpecificFieldsVisitor();
     foreach ($specifics as $specific) {
         $html .= '<div><label class="docman-create-doctype radio" for="item_item_type_' . $specific['type'] . '">';
         $html .= '<input type="radio" name="item[item_type]" value="' . $specific['type'] . '" id="item_item_type_' . $specific['type'] . '" ' . ($specific['checked'] ? 'checked="checked"' : '') . '/>';
         $html .= '<b>' . $specific['label'] . '</b></label></div>';
         $html .= '<div style="padding-left:20px" id="item_item_type_' . $specific['type'] . '_specific_properties">';
         $fields = $specific['obj']->accept($get_specific_fields, array('request' => &$this->controller->request));
         $html .= '<table>';
         foreach ($fields as $field) {
             $html .= '<tr style="vertical-align:top;"><td><label>' . $field->getLabel() . '</label></td><td>' . $field->getField() . '</td></tr>';
         }
         $html .= '</table>';
         $html .= '</div>';
     }
     return $html;
 }
Example #17
0
 /**
  * Remind a user about the document he is supposed to review
  *
  * @param Docman_ApprovalTable $table      Approval table
  * @param Integer              $reviewerId Id of the reviewer
  *
  * @return Boolean
  */
 private function notifyIndividual(Docman_ApprovalTable $table, $reviewerId)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $um = UserManager::instance();
     $reviewer = $um->getUserById($reviewerId);
     if (!$reviewer->getEmail()) {
         return;
     }
     if ($table instanceof Docman_ApprovalTableFile) {
         $versionFactory = new Docman_VersionFactory();
         $version = $versionFactory->getSpecificVersionById($table->getVersionId(), 'plugin_docman_version');
         $itemId = "";
         if ($version) {
             $itemId = $version->getItemId();
         }
     } elseif ($table) {
         $itemId = $table->getItemId();
     }
     if (!$itemId) {
         return;
     }
     $itemFactory = new Docman_ItemFactory();
     $docmanItem = $itemFactory->getItemFromDb($itemId);
     if (!$docmanItem) {
         return;
     }
     $subject = $GLOBALS['Language']->getText('plugin_docman', 'approval_reminder_mail_subject', array($GLOBALS['sys_name'], $docmanItem->getTitle()));
     $mailMgr = new MailManager();
     $mailPrefs = $mailMgr->getMailPreferencesByUser($reviewer);
     if ($mailPrefs == Codendi_Mail_Interface::FORMAT_HTML) {
         $html_body = $this->getBodyHtml($table, $docmanItem);
     }
     $text_body = $this->getBodyText($table, $docmanItem);
     $mail_notification_builder = new MailNotificationBuilder(new MailBuilder(TemplateRendererFactory::build()));
     return $mail_notification_builder->buildAndSendEmail($this->getItemProject($docmanItem), array($reviewer->getEmail()), $subject, $html_body, $text_body, $this->getReviewUrl($docmanItem), DocmanPlugin::TRUNCATED_SERVICE_NAME, new MailEnhancer());
 }
 /**
  * Get the list of all futur obsolete documents and warn document owner
  * about this obsolescence.
  */
 function notifyFuturObsoleteDocuments()
 {
     $pm = ProjectManager::instance();
     $itemFactory = new Docman_ItemFactory(0);
     //require_once('common/mail/TestMail.class.php');
     //$mail = new TestMail();
     //$mail->_testDir = '/local/vm16/codev/servers/docman-2.0/var/spool/mail';
     $itemIter = $itemFactory->findFuturObsoleteItems();
     $itemIter->rewind();
     while ($itemIter->valid()) {
         $item =& $itemIter->current();
         // Users
         $um =& UserManager::instance();
         $owner =& $um->getUserById($item->getOwnerId());
         // Project
         $group = $pm->getProject($item->getGroupId());
         // Date
         $obsoDate = util_timestamp_to_userdateformat($item->getObsolescenceDate(), true);
         // Urls
         $baseUrl = get_server_url() . $this->pluginPath . '/index.php?group_id=' . $item->getGroupId() . '&id=' . $item->getId();
         $directUrl = $baseUrl . '&action=show';
         $detailUrl = $baseUrl . '&action=details';
         $subj = $this->txt('obso_warn_email_subject', array($GLOBALS['sys_name'], $item->getTitle()));
         $body = $this->txt('obso_warn_email_body', array($item->getTitle(), $group->getPublicName(), $obsoDate, $directUrl, $detailUrl));
         $mail_notification_builder = new MailNotificationBuilder(new MailBuilder(TemplateRendererFactory::build()));
         $mail_notification_builder->buildAndSendEmail($group, array($owner->getEmail()), $subj, '', $body, $baseUrl, DocmanPlugin::TRUNCATED_SERVICE_NAME, new MailEnhancer());
         $itemIter->next();
     }
 }
 private function indexAllProjectDocuments(Docman_ProjectItemsBatchIterator $document_iterator, $project_id, FullTextSearch_NotIndexedCollector $notindexed_collector)
 {
     $this->logger->debug('indexing all project documents #' . $project_id);
     $this->initializeProjetMapping($project_id);
     $document_iterator->rewind();
     $docman_item_factory = Docman_ItemFactory::instance($project_id);
     while ($batch = $document_iterator->next()) {
         $this->indexBatch($batch, $notindexed_collector);
     }
 }
 function visitFolder(&$item, $params = array())
 {
     $content = '';
     if ($this->_controller->userCanWrite($this->item->getid())) {
         $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newdocument') . '</dt><dd>';
         $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newdocument_cancreate', Docman_View_View::buildUrl($this->url, array('action' => 'newDocument', 'id' => $item->getId())));
         $content .= '</dd>';
         $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newfolder') . '</dt><dd>';
         $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_newfolder_cancreate', Docman_View_View::buildUrl($this->url, array('action' => 'newFolder', 'id' => $item->getId())));
         //{{{ Paste
         $itemFactory = Docman_ItemFactory::instance($item->getGroupId());
         $copiedItemId = $itemFactory->getCopyPreference($this->_controller->getUser());
         $cutItemId = $itemFactory->getCutPreference($this->_controller->getUser(), $item->getGroupId());
         $srcItem = null;
         if ($copiedItemId !== false && $cutItemId === false) {
             $srcItem = $itemFactory->getItemFromDb($copiedItemId);
         } elseif ($copiedItemId === false && $cutItemId !== false && $item->getId() != $cutItemId) {
             $srcItem = $itemFactory->getItemFromDb($cutItemId);
         }
         if ($srcItem && !$itemFactory->isInSubTree($this->item->getId(), $srcItem->getId())) {
             $content .= '</dd>';
             $content .= '<dt>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_paste') . '</dt><dd>';
             $copyurl = Docman_View_View::buildUrl($this->url, array('action' => 'action_paste', 'id' => $this->item->getId()));
             $content .= $GLOBALS['Language']->getText('plugin_docman', 'details_actions_paste_canpaste', array($copyurl, $this->hp->purify($srcItem->getTitle(), CODEX_PURIFIER_CONVERT_HTML)));
         }
         //}}}
     }
     $content .= '</dd>';
     return $content;
 }
 function massUpdate($srcItemId, $mdLabel, $itemIdArray)
 {
     $mdFactory = new Docman_MetadataFactory($this->groupId);
     if ($mdFactory->isRealMetadata($mdLabel)) {
         $md = $mdFactory->getFromLabel($mdLabel);
         $dao =& $this->getDao();
         $dao->massUpdate($srcItemId, $md->getId(), $md->getType(), $itemIdArray);
     } else {
         $itemFactory = new Docman_ItemFactory($this->groupId);
         $itemFactory->massUpdate($srcItemId, $mdLabel, $itemIdArray);
     }
 }
Example #22
0
 private function getParentItem(Docman_Item $item, Project $project)
 {
     if (!$item->getParentId()) {
         return;
     }
     return Docman_ItemFactory::instance($project->getID())->getItemFromDb($item->getParentId());
 }
 /**
  * For a given Item, add the default metadata values.
  */
 function appendDefaultValuesToItem(&$item)
 {
     // Get parent
     $itemFactory = new Docman_ItemFactory();
     $parentItem = $itemFactory->getItemFromDb($item->getParentId());
     $this->appendItemMetadataList($parentItem);
     // Get inheritables metadata
     $inheritableMdla = $this->getInheritableMdLabelArray();
     $this->appliesItem1MetadataToItem2($parentItem, $item, $inheritableMdla);
 }
Example #24
0
$request = HTTPRequest::instance();
$pm = PluginManager::instance();
$p = $pm->getPluginByName('docman');
if ($p && $pm->isPluginAvailable($p)) {
    // Need to setup the controller so the notification & logging works (setup in controler constructor)
    $controler = new Docman_Controller($p, $p->getPluginPath(), $p->getThemePath(), $request);
} else {
    $GLOBALS['Response']->redirect('/');
}
$func = $request->getValidated('func', new Valid_WhiteList('func', array('confirm_restore_item', 'confirm_restore_version')));
$groupId = $request->getValidated('group_id', 'uint', 0);
$id = $request->getValidated('id', 'uint', 0);
if ($request->existAndNonEmpty('func')) {
    switch ($func) {
        case 'confirm_restore_item':
            $itemFactory = new Docman_ItemFactory($groupId);
            $item = $itemFactory->getItemFromDb($id, array('ignore_deleted' => true));
            if ($itemFactory->restore($item)) {
                $url = $p->getPluginPath() . '/?group_id=' . $groupId . '&action=details&id=' . $id . '&section=properties';
                $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docman', 'item_restored', array($url)), CODENDI_PURIFIER_DISABLED);
                $GLOBALS['Response']->redirect('/admin/show_pending_documents.php?group_id=' . $groupId . '&focus=item');
            } else {
                exit_error($Language->getText('plugin_docman', 'error'), $Language->getText('plugin_docman', 'item_not_restored'));
            }
            break;
        case 'confirm_restore_version':
            $versionFactory = new Docman_VersionFactory();
            $version = $versionFactory->getSpecificVersionById($id);
            if ($versionFactory->restore($version)) {
                $url = $p->getPluginPath() . '/?group_id=' . $groupId . '&action=details&id=' . $version->getItemId() . '&section=history';
                $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_docman', 'version_restored', array($url)), CODENDI_PURIFIER_DISABLED);
 function _getReviewCurrentVersion()
 {
     $version = null;
     $itemFactory = Docman_ItemFactory::instance($this->item->getGroupId());
     $itemType = $itemFactory->getItemTypeForItem($this->item);
     // Get current version for file, embeddedfile and wiki
     switch ($itemType) {
         case PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE:
         case PLUGIN_DOCMAN_ITEM_TYPE_FILE:
             $currentVersion = $this->item->getCurrentVersion();
             $version = $currentVersion->getNumber();
             break;
         case PLUGIN_DOCMAN_ITEM_TYPE_WIKI:
             $version = $itemFactory->getCurrentWikiVersion($this->item);
             break;
     }
     return $version;
 }
 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 getReportImage()
 {
     $html = '';
     if ($this->report->getImage() !== null) {
         $itemId = $this->report->getImage();
         if ($itemId > 0) {
             // Get Item
             $itemFactory = new Docman_ItemFactory($this->report->getGroupId());
             $item = $itemFactory->getItemFromDb($itemId);
             if ($item !== null) {
                 // Check perms
                 $dPm =& Docman_PermissionsManager::instance($item->getGroupId());
                 $user =& $this->getCurrentUser();
                 $html .= "<div style=\"text-align:center\">\n";
                 if ($dPm->userCanRead($user, $item->getId())) {
                     $html .= '<img src="' . $this->defaultUrl . '&id=' . $itemId . '" >';
                 } else {
                     $html .= $GLOBALS['Language']->getText('plugin_docman', 'report_image_not_readable');
                 }
                 $html .= "</div>\n";
             }
         }
     }
     return $html;
 }
 public function getTree(DOMDocument $doc)
 {
     // Get root item
     $itemFactory = new Docman_ItemFactory($this->groupId);
     $user = UserManager::instance()->getCurrentUser();
     $rootItem = $itemFactory->getRoot($this->groupId);
     $tree = $itemFactory->getItemSubTree($rootItem, $user, true, true);
     $xmlExport = new Docman_XMLExportVisitor($doc);
     $xmlExport->setDataPath($this->dataPath);
     return $xmlExport->getXML($tree);
 }
 /**
  * Return an item factory
  *
  * @param Integer $groupId
  * @return Docman_ItemFactory
  */
 function _getItemFactory($groupId = 0)
 {
     return Docman_ItemFactory::instance($groupId);
 }
 function &getItemHierarchy($rootItem)
 {
     if (!isset($this->hierarchy[$rootItem->getId()])) {
         $itemFactory = new Docman_ItemFactory($rootItem->getGroupId());
         $this->hierarchy[$rootItem->getId()] =& $itemFactory->getItemTree($rootItem, $this->getUser(), false, true);
     }
     return $this->hierarchy[$rootItem->getId()];
 }