function _getDefaultValuesFields($params)
 {
     $mdFactory = new Docman_MetadataFactory($this->newItem->getGroupId());
     $inheritableMda = $mdFactory->getInheritableMdLabelArray(true);
     $mdIter = $this->newItem->getMetadataIterator();
     $mdHtmlFactory = new Docman_MetadataHtmlFactory();
     return $mdHtmlFactory->buildFieldArray($mdIter, $inheritableMda, true, $params['form_name'], $params['theme_path']);
 }
 function getMetaDataValuesTable($groupId, $mdId, $vals)
 {
     $mdf = new Docman_MetadataFactory($groupId);
     $mdLabel = $mdf->getLabelFromId($mdId);
     $mlvef = new Docman_MetadataListOfValuesElementFactory($mdId);
     $mlveIter = $mlvef->getIteratorByFieldId($mdId, $mdLabel, true);
     $html = '<h3>' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_confidentiality_field_values') . '</h3>';
     $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_select_field_values');
     $html .= '<form name="metadata_field_values" method="post" action="?group_id=' . $groupId . '&action=admin_set_watermark_metadata_values">';
     $titles = array();
     $titles[] = $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_use_watermark');
     $titles[] = $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_values');
     $mlveIter->rewind();
     $iter_empty = 1;
     if ($mlveIter->valid()) {
         $iter_empty = 0;
         $html .= html_build_list_table_top($titles, false, false, false);
     }
     $i = 1;
     while ($mlveIter->valid()) {
         $mdv = $mlveIter->current();
         $id = $mdv->getId();
         if (isset($vals['value_id'])) {
             $posValue = array_search($id, $vals['value_id']);
         } else {
             $posValue = false;
         }
         // exclude status field and None Value
         if ($id != 100 && $mdv->getName() != 'Status') {
             $name = $mdv->getName();
             $html .= '<tr class="' . html_get_alt_row_color($i) . '"><td align="center"><input type="checkbox" name="chk_' . $id . '"';
             if ($vals['watermark'][$posValue] == 1 && $posValue !== false) {
                 $html .= ' checked ';
             }
             $html .= '/></td>';
             $html .= '<td><b>' . $name . '</b></td>';
             $html .= '</tr>';
             $i++;
         }
         $mlveIter->next();
     }
     if (!$iter_empty) {
         $html .= '</table>';
         $html .= '<input name="submit_metadatafield_value" type="submit" value="' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_save_settings') . '">';
     } else {
         $html .= '<b>' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_disabled') . '</b>';
     }
     $html .= '</form>';
     return $html;
 }
 function Docman_MetadataSqlQueryChunk($md)
 {
     $this->mdv = 'mdv_' . $md->getLabel();
     $this->mdId = $md->getId();
     $this->isRealMetadata = Docman_MetadataFactory::isRealMetadata($md->getLabel());
     if ($this->isRealMetadata) {
         switch ($md->getType()) {
             case PLUGIN_DOCMAN_METADATA_TYPE_TEXT:
                 $this->field = $this->mdv . '.valueText';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_STRING:
                 $this->field = $this->mdv . '.valueString';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_DATE:
                 $this->field = $this->mdv . '.valueDate';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_LIST:
                 $this->field = $this->mdv . '.valueInt';
                 break;
         }
     } else {
         switch ($md->getLabel()) {
             case 'owner':
                 $this->field = 'i.user_id';
                 break;
             default:
                 $this->field = 'i.' . $md->getLabel();
         }
     }
 }
Esempio n. 4
0
 function setupNewItem($params)
 {
     $mdFactory = new Docman_MetadataFactory($params['group_id']);
     if (isset($params['force_item'])) {
         $this->newItem = $params['force_item'];
     } else {
         $this->newItem = $this->_getNewItem();
         $this->newItem->setParentId($params['item']->getId());
         $this->newItem->setGroupId($params['group_id']);
         $mdFactory->appendItemMetadataList($this->newItem);
         // Get default values
         $mdFactory->appendDefaultValuesToItem($this->newItem);
     }
     // Append, for list Metadata the list of values associated in the DB
     // (content of select box)
     $mdFactory->appendAllListOfValuesToItem($this->newItem);
 }
 /**
  * List the available metadata
  */
 function getMetadataTable($mdIter, $groupId, $defaultUrl)
 {
     $content = '';
     $mdFactory = new Docman_MetadataFactory($groupId);
     $content .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_title') . '</h3>' . "\n";
     $content .= $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_instructions') . "\n";
     $content .= html_build_list_table_top(array($GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_name'), $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_descr'), $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_status'), $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_delete')));
     $altRowClass = 0;
     $mdIter->rewind();
     while ($mdIter->valid()) {
         $md =& $mdIter->current();
         $canDelete = false;
         if ($mdFactory->isRealMetadata($md->getLabel())) {
             $canDelete = true;
         }
         $trclass = html_get_alt_row_color($altRowClass++);
         $content .= '<tr class="' . $trclass . '">';
         $nameUrl = $this->buildUrl($defaultUrl, array('action' => 'admin_md_details', 'md' => $md->getLabel()));
         $nameHref = '<a href="' . $nameUrl . '">' . $this->hp->purify($md->getName()) . '</a>';
         $content .= '<td>' . $nameHref . '</td>';
         $content .= '<td>' . $this->hp->purify($md->getDescription()) . '</td>';
         $content .= '<td>';
         if ($md->isRequired()) {
             $content .= "-";
         } else {
             if ($md->isUsed()) {
                 $content .= "Used";
             } else {
                 $content .= "Unused";
             }
         }
         $content .= '</td>';
         $trash = '-';
         if ($canDelete) {
             $link = $this->buildUrl($defaultUrl, array('action' => 'admin_delete_metadata', 'md' => $md->getLabel()));
             $warn = $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_delete_warn', $this->hp->purify($md->getName()));
             $alt = $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_list_delete_alt', $this->hp->purify($md->getName()));
             $trash = html_trash_link($link, $warn, $alt);
         }
         $content .= '<td>' . $trash . '</td>';
         $content .= '</tr>' . "\n";
         $mdIter->next();
     }
     $content .= '</table>' . "\n";
     return $content;
 }
Esempio n. 6
0
 /**
  * Should be transfered in Docman_Metadata
  * @param DOMDocument $doc
  * @return DOMNode
  */
 public function getMetadataDef(DOMDocument $doc)
 {
     $propdefs = $doc->createElement('propdefs');
     $mdFactory = new Docman_MetadataFactory($this->groupId);
     foreach ($mdFactory->getRealMetadataList() as $metadata) {
         $propdef = $doc->createElement('propdef');
         $propdef->setAttribute('name', $metadata->getName());
         switch ($metadata->getType()) {
             case PLUGIN_DOCMAN_METADATA_TYPE_TEXT:
                 $type = 'text';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_STRING:
                 $type = 'string';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_DATE:
                 $type = 'date';
                 break;
             case PLUGIN_DOCMAN_METADATA_TYPE_LIST:
                 $type = 'list';
                 break;
         }
         $propdef->setAttribute('type', $type);
         $propdef->setAttribute('multivalue', $metadata->getIsMultipleValuesAllowed() ? 'true' : 'false');
         $propdef->setAttribute('empty', $metadata->getIsEmptyAllowed() ? 'true' : 'false');
         if ($metadata->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
             $loveFactory = new Docman_MetadataListOfValuesElementFactory($metadata->getId());
             foreach ($loveFactory->getListByFieldId($metadata->getId(), $metadata->getLabel(), true) as $love) {
                 if ($love->getId() != 100) {
                     $value = $doc->createElement('value');
                     $value->appendChild($doc->createTextNode($love->getName()));
                     $propdef->appendChild($value);
                 }
             }
         }
         $propdefs->appendChild($propdef);
     }
     return $propdefs;
 }
 /**
  * This function return an iterator on a list of documents (no folders).
  *
  * How it works:
  * 1. Get the list of all documents that match the criteria (if
  *    any!). (permissions apply).
  *    Note: the final list of documents is a subset of this result.
  * 2. Get the list of folders behind $parentId (permissions apply).
  * 3. Check that each document in list 1. is in a folder of list 2.
  * 5. Apply limits ($start, $offset) is only a subset of the list is required.
  * 6. If needed, add the metadata to the items. 
  */
 function &getItemSubTreeAsList($parentId, &$nbItemsFound, $params = null)
 {
     $_parentId = (int) $parentId;
     $user =& $params['user'];
     // Prepare filters if any
     $filter = null;
     if (isset($params['filter'])) {
         $filter =& $params['filter'];
     }
     // Obsolescence
     $searchItemsParams = array();
     if (isset($params['ignore_obsolete'])) {
         $searchItemsParams['ignore_obsolete'] = $params['ignore_obsolete'];
     }
     // Range of documents to return
     $start = 0;
     if (isset($params['start'])) {
         $start = $params['start'];
     }
     $end = 25;
     if (isset($params['offset'])) {
         $end = $start + $params['offset'];
     }
     $dao =& $this->_getItemDao();
     //
     // Build Folder List
     //
     $parentItem = $this->getItemFromDb($parentId);
     $dPm = Docman_PermissionsManager::instance($parentItem->getGroupId());
     $folderList = array($parentId => &$parentItem);
     $pathIdArray = array($parentId => array());
     $pathTitleArray = array($parentId => array());
     $parentIds = array($parentId);
     $folderIds = array($parentId);
     $i = 0;
     do {
         $i++;
         $dar = $dao->searchSubFolders($parentIds);
         $parentIds = array();
         $itemIds = array();
         $itemRows = array();
         if ($dar && !$dar->isError()) {
             $dar->rewind();
             while ($dar->valid()) {
                 $row = $dar->current();
                 $itemRows[$row['item_id']] = $row;
                 $itemIds[] = $row['item_id'];
                 $parentIds[$row['item_id']] = $row['item_id'];
                 $dar->next();
             }
             // Fetch all the permissions at the same time
             $dPm->retreiveReadPermissionsForItems($itemIds, $user);
             // Build hierarchy: only keep displayable items
             foreach ($itemIds as $id) {
                 if ($dPm->userCanRead($user, $id)) {
                     $folderList[$id] =& $this->getItemFromRow($itemRows[$id]);
                     // Update path
                     $pathIdArray[$id] = array_merge($pathIdArray[$folderList[$id]->getParentId()], array($id));
                     $pathTitleArray[$id] = array_merge($pathTitleArray[$folderList[$id]->getParentId()], array($folderList[$id]->getTitle()));
                 } else {
                     unset($parentIds[$id]);
                 }
             }
         }
     } while (count($parentIds) > 0);
     //
     // Keep only documents in allowed subfolders
     //
     $mdFactory = new Docman_MetadataFactory($this->groupId);
     $ci = null;
     if ($filter !== null) {
         $ci = $filter->getColumnIterator();
     }
     //
     // Build Document list
     //
     $itemArray = array();
     if (isset($params['obsolete_only']) && $params['obsolete_only']) {
         $dar = $dao->searchObsoleteByGroupId($this->groupId);
     } else {
         $dar = $dao->searchByGroupId($this->groupId, $filter, $searchItemsParams);
     }
     $nbItemsFound = 0;
     if ($dar && !$dar->isError()) {
         $this->preloadItemPerms($dar, $user, $this->groupId);
         $dar->rewind();
         while ($dar->valid()) {
             $row = $dar->current();
             // The document is not is one of the allowed subfolder so we
             // can delete it. As a side effect decrease the number of
             // document found.
             if ($dPm->userCanRead($user, $row['item_id']) && isset($folderList[$row['parent_id']])) {
                 if ($nbItemsFound >= $start && $nbItemsFound < $end || isset($params['getall']) && $params['getall']) {
                     $itemArray[$row['item_id']] =& $this->getItemFromRow($row);
                     // Append Path
                     $itemArray[$row['item_id']]->setPathTitle($pathTitleArray[$row['parent_id']]);
                     $itemArray[$row['item_id']]->setPathId($pathIdArray[$row['parent_id']]);
                     // Append metadata
                     if ($ci !== null) {
                         $ci->rewind();
                         while ($ci->valid()) {
                             $c = $ci->current();
                             if ($c->md !== null && $mdFactory->isRealMetadata($c->md->getLabel())) {
                                 $mdFactory->addMetadataValueToItem($itemArray[$row['item_id']], $c->md);
                             }
                             $ci->next();
                         }
                     }
                 }
                 $nbItemsFound++;
             }
             $dar->next();
         }
     }
     $docIter =& new ArrayIterator($itemArray);
     return $docIter;
 }
 protected function getNodeForMetadata(Docman_Metadata $metadata)
 {
     $metaDataFactory = new Docman_MetadataFactory($metadata->getGroupId());
     if ($metaDataFactory->isRealMetadata($metadata->getLabel())) {
         $node = $this->doc->createElement('property');
         $node->setAttribute('title', $metadata->getName());
         if ($metadata->getValue() instanceof ArrayIterator) {
             $this->getNodeForMetadataValues($metadata->getValue(), $node);
         } else {
             $value = $metadata->getValue();
             if ($value != '' && $metadata->getType() == PLUGIN_DOCMAN_METADATA_TYPE_DATE) {
                 $value = date('c', $value);
             }
             $node->appendChild($this->doc->createTextNode($value));
         }
         return $node;
     }
 }
 /**
  * Checks that the updating property have a non-empty name,
  * and if the name have been changed, also checks that the same
  * name is not already taken by another property
  */
 private function validateUpdateMetadata($name, $label)
 {
     $name = trim($name);
     if ($name == '') {
         $valid = false;
         $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_missing'));
     } else {
         $mdFactory = new Docman_MetadataFactory($this->groupId);
         $md = $mdFactory->getFromLabel($label);
         // name has changed
         if ($md !== null && $md->getName() != $name) {
             if ($mdFactory->findByName($name)->count() == 0) {
                 $valid = true;
             } else {
                 $valid = false;
                 $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_exists', $name));
             }
         } else {
             $valid = true;
         }
     }
     return $valid;
 }
 function _getInheritableMetadata()
 {
     if ($this->inheritableMetadataArray === null) {
         $mdFactory = new Docman_MetadataFactory($this->item->getGroupId());
         $inheritableMda = $mdFactory->getInheritableMdLabelArray(true);
         $mdIter = $this->item->getMetadataIterator();
         $mdHtmlFactory = new Docman_MetadataHtmlFactory();
         $this->inheritableMetadataArray = $mdHtmlFactory->buildFieldArray($mdIter, $inheritableMda, true, $this->formName, $this->theme_path);
     }
     return $this->inheritableMetadataArray;
 }
 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);
     }
 }
 /**
  *
  */
 function cloneFilter($srcFilter, $dstReport, $metadataMapping)
 {
     $dstMdFactory = new Docman_MetadataFactory($dstReport->getGroupId());
     $newLabel = null;
     if ($dstMdFactory->isRealMetadata($srcFilter->md->getLabel())) {
         // Check if there is a corresponding MD in the dst project
         // Should never happens in case of initial template clone
         // but main exists with 'clone this report' function
         if (isset($metadataMapping['md'][$srcFilter->md->getId()])) {
             // For real metadata, create MD based on the new ID
             $newLabel = 'field_' . $metadataMapping['md'][$srcFilter->md->getId()];
         }
     } else {
         // Check in use
         $newLabel = $srcFilter->md->getLabel();
     }
     if ($newLabel !== null) {
         $dstFilterFactory = $this->getFilterFactory($dstReport->getGroupId());
         $gsMd = $this->getGlobalSearchMetadata();
         if ($newLabel == $gsMd->getLabel()) {
             $newMd = $gsMd;
         } else {
             $itMd = $this->getItemTypeSearchMetadata();
             if ($newLabel == $itMd->getLabel()) {
                 $newMd = $itMd;
             } else {
                 $newMd = $dstMdFactory->getFromLabel($newLabel);
             }
         }
         if ($newMd->isUsed()) {
             // Create new filter
             $dstFilter = $dstFilterFactory->createFromMetadata($newMd, $dstReport->getAdvancedSearch());
             // Append values
             $this->cloneFilterValues($srcFilter, $dstFilter, $metadataMapping);
             // Save filter
             $dstFilterFactory->createFilter($dstReport->getId(), $dstFilter);
         }
     }
 }
Esempio n. 13
0
 /**
  * 
  */
 public function &getMetadataFromLabel($label)
 {
     $metadata_value = $this->getHardCodedMetadataValue($label);
     $metadata = null;
     // can't refactor with early return as it returns value by ref :(
     if ($metadata_value !== null) {
         $metadata = Docman_MetadataFactory::getHardCodedMetadataFromLabel($label, $metadata_value);
     } elseif (isset($this->_metadata[$label])) {
         $metadata = $this->_metadata[$label];
     }
     return $metadata;
 }
 function _dispatch($view)
 {
     $user = $this->getUser();
     $dpm = Docman_PermissionsManager::instance($this->getGroupId());
     switch ($view) {
         case 'admin_watermark':
             $group_id = $this->request->get('group_id');
             $dwmdf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmdf->getMetadataIdFromGroupId($group_id);
             $this->_viewParams['md_id'] = $md_id;
             $this->_viewParams['group_id'] = $group_id;
             $md_arr = array();
             $dmf = new Docman_MetadataFactory($group_id);
             $mdIter = $dmf->getMetadataForGroup(true);
             $mdIter->rewind();
             while ($mdIter->valid()) {
                 $md = $mdIter->current();
                 $md_arr[] = $md->getId();
                 $mdIter->next();
             }
             if ($md_id != 0 && !in_array($md_id, $md_arr)) {
                 $this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_metadata_deleted'));
             }
             $this->view = 'AdminWatermark';
             break;
         case 'admin_set_watermark_metadata':
             $group_id = $this->request->get('group_id');
             $id = $this->request->get('md_id');
             $this->_actionParams['group_id'] = $group_id;
             $this->_actionParams['md_id'] = $id;
             $dwm = new DocmanWatermark_Metadata();
             $dwm->setId($id);
             $dwm->setGroupId($group_id);
             $this->action = 'setup_metadata';
             $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata'));
             $this->_viewParams['redirect_to'] = '?group_id=' . $group_id . '&action=admin_watermark';
             $this->view = 'RedirectAfterCrud';
             break;
         case 'admin_set_watermark_metadata_values':
             $mdf = new Docman_MetadataFactory($this->request->get('group_id'));
             $dwmf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmf->getMetadataIdFromGroupId($this->request->get('group_id'));
             $mdLabel = $mdf->getLabelFromId($md_id);
             $mlvef = new Docman_MetadataListOfValuesElementFactory($md_id);
             $mlveIter = $mlvef->getIteratorByFieldId($md_id, $mdLabel, true);
             $mlveIter->rewind();
             $arrValues = array();
             $arrVals = array();
             while ($mlveIter->valid()) {
                 $dmv = $mlveIter->current();
                 $dwmv = new DocmanWatermark_MetadataValue();
                 if ($this->request->exist('chk_' . $dmv->getId())) {
                     $watermark = 1;
                 } else {
                     $watermark = 0;
                 }
                 $dwmv->setValueId($dmv->getId());
                 $dwmv->setWatermark($watermark);
                 $arrValues[] = $dwmv;
                 $arrVals['value_id'][] = $dmv->getId();
                 $arrVals['watermark'][] = $watermark;
                 $mlveIter->next();
             }
             $iterValues = new ArrayIterator($arrValues);
             $this->_actionParams['group_id'] = $this->request->get('group_id');
             $this->_actionParams['md_values'] = $iterValues;
             $this->action = 'setup_metadata_values';
             $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata_values'));
             $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark';
             $this->view = 'RedirectAfterCrud';
             break;
         case 'admin_import_from_project':
             $this->_actionParams['src_group_id'] = $this->request->get('project');
             $this->_actionParams['target_group_id'] = $this->request->get('group_id');
             $dwmif = new DocmanWatermark_MetadataImportFactory();
             $dwmif->setSrcProjectId($this->request->get('project'));
             $dwmif->setTargetProjectId($this->request->get('group_id'));
             $dmf = new Docman_MetadataFactory($this->request->get('project'));
             $dwmf = new DocmanWatermark_MetadataFactory();
             $md_id = $dwmf->getMetadataIdFromGroupId($dwmif->getSrcProjectId());
             $mdIter = $dmf->findByName($dwmf->getMetadataNameFromId($md_id));
             $mdIter->rewind();
             $md = $mdIter->current();
             $this->_actionParams['md'] = $md;
             $mdMap = $dwmif->getWatermarkMetadataMap($md);
             if ($mdMap['md'] != 0) {
                 $this->action = 'import_from_project';
                 $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_imported_from_project'));
                 $this->_viewParams['md_id'] = $md_id;
                 $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark';
             } else {
                 $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_import_from_project_not_match'));
                 $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_import_metadata_check&import_group_id=' . $this->request->get('project');
             }
             $this->view = 'RedirectAfterCrud';
             break;
         case 'docmanwatermark_toggle_item':
             $this->action = 'docmanwatermark_toggle_item';
             break;
         default:
             die(htmlspecialchars($view) . ' is not supported');
             break;
     }
 }
 function initFilters(&$report, $request, &$feedback)
 {
     $filterFactory = new Docman_FilterFactory($this->groupId);
     $mdFactory = new Docman_MetadataFactory($this->groupId);
     $mdIter = $mdFactory->getMetadataForGroup(true);
     $mdIter->rewind();
     while ($mdIter->valid()) {
         $md = $mdIter->current();
         $filter = $filterFactory->createFilterOnMatch($md, $request, $report->getAdvancedSearch());
         $this->_validateFilterAndCreate($report, $filter, $feedback);
         $mdIter->next();
     }
     // Special case for a fake metadata: generic text search
     $filter = $filterFactory->getGlobalSearchFilter($request);
     $this->_validateFilterAndCreate($report, $filter, $feedback);
     $filter = $filterFactory->getItemTypeSearchFilter($request, $report->getAdvancedSearch());
     $this->_validateFilterAndCreate($report, $filter, $feedback);
 }
 /**
  * Returns the list of values for the given list metadata.
  */
 function getMetadataListOfValues()
 {
     $request =& $this->_controler->request;
     $groupId = $request->get('group_id');
     $metadataFactory = new Docman_MetadataFactory($groupId);
     $metadataLovFactory = new Docman_MetadataListOfValuesElementFactory();
     $label = $request->get('label');
     $md = $metadataFactory->getFromLabel($label);
     $res = array();
     if ($md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
         foreach ($metadataLovFactory->getListByFieldId($md->id, $md->label, true) as $val) {
             $res[] = $val;
         }
     }
     $this->_controler->_viewParams['action_result'] = $res;
 }
Esempio n. 17
0
 function fetchLogsForItem($item_id, $display_access_logs)
 {
     $html = '';
     $uh = UserHelper::instance();
     $hp = Codendi_HTMLPurifier::instance();
     $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs') . '</h3>';
     $dar = $this->dao->searchByItemIdOrderByTimestamp($item_id);
     if ($dar && !$dar->isError()) {
         if ($dar->valid()) {
             $titles = array();
             $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_when');
             $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_who');
             $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_what');
             $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_old_value');
             $titles[] = $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_new_value');
             $html .= html_build_list_table_top($titles, false, false, false);
             $odd_even = array('boxitem', 'boxitemalt');
             $i = 0;
             $_previous_date = -1;
             $_previous_auth = -1;
             while ($dar->valid()) {
                 $row = $dar->current();
                 if ($row['type'] != PLUGIN_DOCMAN_EVENT_ACCESS || $display_access_logs) {
                     $user = $row['user_id'] ? $hp->purify($uh->getDisplayNameFromUserId($row['user_id'])) : $GLOBALS['Language']->getText('plugin_docman', 'details_history_anonymous');
                     $html .= '<tr class="' . $odd_even[$i++ % count($odd_even)] . '">';
                     $html .= '<td>' . html_time_ago($row['time']) . '</td>';
                     $html .= '<td>' . $user . '</td>';
                     if ($row['type'] == PLUGIN_DOCMAN_EVENT_METADATA_UPDATE) {
                         $_old_v = $row['old_value'];
                         $_new_v = $row['new_value'];
                         $mdFactory = new Docman_MetadataFactory($row['group_id']);
                         $md =& $mdFactory->getFromLabel($row['field']);
                         if ($md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) {
                             $mdlovebo = new Docman_MetadataListOfValuesElementFactory();
                             $_old_e =& $mdlovebo->getByElementId($row['old_value'], $md->getLabel());
                             $_new_e =& $mdlovebo->getByElementId($row['new_value'], $md->getLabel());
                             if ($_old_e !== null) {
                                 $_old_v = $_old_e->getName();
                             }
                             if ($_new_e !== null) {
                                 $_new_v = $_new_e->getName();
                             }
                         } else {
                             if ($md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_DATE) {
                                 $_old_v = format_date($GLOBALS['Language']->getText('system', 'datefmt'), $_old_v);
                                 $_new_v = format_date($GLOBALS['Language']->getText('system', 'datefmt'), $_new_v);
                             }
                         }
                         $html .= '<td>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_change_field', array($md->getName())) . '</td>';
                         $html .= '<td>' . $_old_v . '</td>';
                         $html .= '<td>' . $_new_v . '</td>';
                     } elseif ($row['type'] == PLUGIN_DOCMAN_EVENT_WIKIPAGE_UPDATE) {
                         $old_version = $row['old_value'];
                         $new_version = $row['new_value'];
                         $dIF = $this->_getItemFactory($row['group_id']);
                         $pagename = $dIF->getItemFromDb($item_id)->getPageName();
                         $difflink = '/wiki/index.php?group_id=' . $row['group_id'];
                         $difflink .= '&pagename=' . urlencode($pagename) . '&action=diff';
                         $difflink .= '&versions%5b%5d=' . $old_version . '&versions%5b%5d=' . $new_version;
                         $html .= '<td colspan>' . $this->getText($row['type']) . '</td>';
                         $html .= '<td colspan="2" align="center"><a href=' . $difflink . '>diffs</a>';
                     } elseif ($row['type'] == PLUGIN_DOCMAN_EVENT_SET_VERSION_AUTHOR) {
                         $newUser = $row['new_value'];
                         $html .= '<td>' . $this->getText($row['type']) . '</td>';
                         $html .= "<td>&nbsp;</td>";
                         $html .= "<td>{$newUser}</td>";
                     } elseif ($row['type'] == PLUGIN_DOCMAN_EVENT_SET_VERSION_DATE) {
                         $newDate = format_date($GLOBALS['Language']->getText('system', 'datefmt'), $row['new_value']);
                         $html .= '<td>' . $this->getText($row['type']) . '</td>';
                         $html .= "<td>&nbsp;</td>";
                         $html .= "<td>{$newDate}</td>";
                     } elseif ($row['type'] == PLUGIN_DOCMAN_EVENT_DEL_VERSION) {
                         $old_version = $row['old_value'];
                         $html .= '<td>' . $this->getText($row['type']) . '</td>';
                         $html .= '<td colspan="2" align="center">' . $old_version . '</td>';
                     } elseif ($row['type'] == PLUGIN_DOCMAN_EVENT_RESTORE_VERSION) {
                         $versionNumber = $row['old_value'];
                         $html .= '<td>' . $this->getText($row['type']) . '</td>';
                         $html .= '<td colspan="2" align="center">' . $versionNumber . '</td>';
                     } else {
                         $html .= '<td colspan>' . $this->getText($row['type']) . '</td><td colspan="2">&nbsp;</td>';
                     }
                     $html .= '</tr>';
                     $_previous_date = $row['time'];
                     $_previous_auth = $row['user_id'];
                 }
                 $dar->next();
             }
             $html .= '</table>';
         } else {
             $html .= '<div>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_no') . '</div>';
         }
     } else {
         $html .= '<div>' . $GLOBALS['Language']->getText('plugin_docman', 'details_history_logs_error') . '</div>';
         $html .= $dar->isError();
     }
     return $html;
 }
 function isValidLabel($label)
 {
     $valid = false;
     if (Docman_MetadataFactory::isHardCodedMetadata($label)) {
         $valid = true;
     } else {
         $valid = Docman_MetadataFactory::isRealMetadata($label);
     }
     return $valid;
 }
 /**
  *
  */
 function getFiltersOptions($params, $displayedFilters)
 {
     $html = '';
     $html .= '<div id="docman_report_options">';
     $html .= '<strong>' . $GLOBALS['Language']->getText('plugin_docman', 'report_filters_options') . '</strong>&nbsp;';
     //
     // Add a new filter
     //
     $html .= $GLOBALS['Language']->getText('plugin_docman', 'report_add_filter');
     $html .= '&nbsp;';
     $html .= '<select name="add_filter" id="plugin_docman_report_add_filter">';
     $html .= $this->getSelectOption('--', '--');
     // Std metadata
     $mdFactory = new Docman_MetadataFactory($this->report->getGroupId());
     $mdIter = $mdFactory->getMetadataForGroup(true);
     $mdIter->rewind();
     while ($mdIter->valid()) {
         $md =& $mdIter->current();
         if (!in_array($md->getLabel(), $displayedFilters)) {
             $html .= $this->getSelectOption($md->getLabel(), $md->getName(), '');
         }
         $mdIter->next();
     }
     // Special filters
     $gsmd = $this->report->getGlobalSearchMetadata();
     $itmd = $this->report->getItemTypeSearchMetadata();
     $showGlobalSearch = !in_array($gsmd->getLabel(), $displayedFilters);
     $showItemTypeSearch = !in_array($itmd->getLabel(), $displayedFilters);
     if ($showGlobalSearch || $showItemTypeSearch) {
         $html .= $this->getSelectOption('--', '--');
         if ($showGlobalSearch) {
             $html .= $this->getSelectOption($gsmd->getLabel(), $gsmd->getName(), '');
         }
         if ($showItemTypeSearch) {
             $html .= $this->getSelectOption($itmd->getLabel(), $itmd->getName(), '');
         }
     }
     $html .= '</select>';
     //
     // Advanced search
     //
     if ($this->report->advancedSearch) {
         $html .= '<input type="hidden" name="advsearch" value="1" />';
         $advSearchToggle = 0;
     } else {
         $advSearchToggle = 1;
     }
     $advSearchUrl = $this->view->_buildSearchUrl($params, array('advsearch' => $advSearchToggle));
     $html .= '&nbsp;';
     $html .= $GLOBALS['Language']->getText('plugin_docman', 'filters_advsearch_' . $advSearchToggle, array($advSearchUrl));
     $html .= '</div><!-- docman_report_options-->';
     return $html;
 }
 private function getCustomDateMetadata(Docman_Item $item)
 {
     $this->metadata_factory->setRealGroupId($item->getGroupId());
     return $this->metadata_factory->getRealMetadataList(false, array(PLUGIN_DOCMAN_METADATA_TYPE_DATE));
 }
 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'));
     }
 }
Esempio n. 22
0
 function Docman_FilterList($md)
 {
     $mdFactory = new Docman_MetadataFactory($md->getGroupId());
     $mdFactory->appendMetadataValueList($md, false);
     parent::Docman_Filter($md);
     $this->setValue(0);
 }
 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;
 }