function fetchFolder($folder, $params)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $selected = '';
     if (!isset($params['selected']) || !$params['selected']) {
         if ($this->docman->userCanWrite($folder['id']) && (!$params['select'] || $params['select'] == $folder['id'])) {
             $selected = 'checked="checked"';
             $params['selected'] = true;
         }
     }
     $disabled = $this->docman->userCanWrite($folder['id']) ? '' : 'disabled="disabled"';
     $label_classes = $selected ? 'docman_item_actual_parent' : '';
     $h = '<li  class="' . Docman_View_Browse::getItemClasses(array('is_last' => $params['is_last'])) . '">';
     $h .= '<label for="item_parent_id_' . $folder['id'] . '" class="' . $label_classes . '" >';
     $h .= '<input type="radio" ' . $selected . ' name="' . $params['input_name'] . '" value="' . $folder['id'] . '" id="item_parent_id_' . $folder['id'] . '" ' . $disabled . ' />';
     $h .= '<img src="' . $folder['icon_src'] . '" class="docman_item_icon" />';
     $h .= $hp->purify($folder['title'], CODENDI_PURIFIER_CONVERT_HTML) . '</label>';
     $h .= '<script type="text/javascript">docman.addParentFoldersForNewItem(' . $folder['id'] . ', ' . $folder['parent_id'] . ", '" . $hp->purify(addslashes($folder['title']), CODENDI_PURIFIER_CONVERT_HTML) . "');</script>\n";
     $h .= '<ul class="docman_items">';
     $params['is_last'] = false;
     $nb = count($folder['items']);
     $i = 0;
     foreach ($folder['items'] as $item) {
         $i++;
         if ($i == $nb) {
             $params['is_last'] = true;
         }
         $h .= $this->fetchFolder($item, $params);
     }
     return $h . '</ul></li>';
 }
 function _content($params)
 {
     $html = '';
     $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'admin_view_instructions') . '</p>';
     $html .= '<form action="' . $params['default_url'] . '" method="POST">';
     $html .= '<select name="selected_view" onchange="this.form.submit()">';
     $sBo =& Docman_SettingsBo::instance($params['group_id']);
     $actual = $sBo->getView();
     $views = Docman_View_Browse::getDefaultViews();
     foreach ($views as $view) {
         $html .= '<option value="' . $view . '" ' . ($actual == $view ? 'selected="selected"' : '') . '>' . $GLOBALS['Language']->getText('plugin_docman', 'view_' . $view) . '</option>';
     }
     $html .= '</select>';
     $html .= '<input type="hidden" name="action" value="admin_change_view" />';
     $html .= '<noscript><input type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" /></noscript>';
     echo $html;
 }
 function request()
 {
     if ($this->request->exist('action') && ($this->request->get('action') == 'plugin_docman_approval_reviewer' || $this->request->get('action') == 'plugin_docman_approval_requester')) {
         if ($this->request->get('hide')) {
             user_set_preference('hide_' . $this->request->get('action'), 1);
         } else {
             user_del_preference('hide_' . $this->request->get('action'));
         }
         exit;
     }
     if (!$this->request->exist('group_id')) {
         $this->feedback->log('error', 'Project is missing.');
         $this->_setView('Error');
     } else {
         $_groupId = (int) $this->request->get('group_id');
         $pm = ProjectManager::instance();
         $project = $pm->getProject($_groupId);
         if ($project == false) {
             $this->feedback->log('error', 'Project is missing.');
             $this->_setView('Error');
             return;
         }
         // Browser alert
         $this->_checkBrowserCompliance();
         //token for redirection
         $tok =& new Docman_Token();
         $this->_viewParams['docman'] =& $this;
         $this->_viewParams['user'] =& $this->getUser();
         $this->_viewParams['token'] = $tok->getToken();
         $this->_viewParams['default_url'] = $this->getDefaultUrl();
         $this->_viewParams['theme_path'] = $this->getThemePath();
         $this->_viewParams['group_id'] = (int) $this->request->get('group_id');
         if ($this->request->exist('version_number')) {
             $this->_viewParams['version_number'] = (int) $this->request->get('version_number');
         }
         if ($this->request->exist('section')) {
             $this->_viewParams['section'] = $this->request->get('section');
         } else {
             if ($this->request->get('action') == 'permissions') {
                 $this->_viewParams['section'] = 'permissions';
             }
         }
         $view = $this->request->exist('action') ? $this->request->get('action') : 'show';
         $this->_viewParams['action'] = $view;
         // Start is used by Table view (like LIMIT start,offset)
         if ($this->request->exist('start')) {
             $this->_viewParams['start'] = (int) $this->request->get('start');
         }
         if ($this->request->exist('pv')) {
             $this->_viewParams['pv'] = (int) $this->request->get('pv');
         }
         if ($this->request->exist('report')) {
             $this->_viewParams['report'] = $this->request->get('report');
             $views = Docman_View_Browse::getDefaultViews();
             $validator = new Valid_WhiteList('report', $views);
             $views_keys = array_keys($views);
             $default_view = $views[$views_keys[0]];
             $this->_viewParams['report'] = $this->request->getValidated('report', $validator, $default_view);
         }
         $item_factory =& $this->_getItemFactory();
         $root =& $item_factory->getRoot($this->request->get('group_id'));
         if (!$root) {
             // Install
             $_gid = (int) $this->request->get('group_id');
             $pm = ProjectManager::instance();
             $project = $pm->getProject($_gid);
             $tmplGroupId = (int) $project->getTemplate();
             $this->_cloneDocman($tmplGroupId, $_gid, false);
             if (!$item_factory->getRoot($_gid)) {
                 $item_factory->createRoot($_gid, 'roottitle_lbl_key');
             }
             $this->_viewParams['redirect_to'] = $_SERVER['REQUEST_URI'];
             $this->view = 'Redirect';
         } else {
             $id = $this->request->get('id');
             if (!$id && $this->request->exist('item')) {
                 $i = $this->request->get('item');
                 if (isset($i['id'])) {
                     $id = $i['id'];
                 }
             }
             if ($id) {
                 $item =& $item_factory->getItemFromDb($id);
                 if (!$item) {
                     $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_item_deleted'));
                     $this->_setView('DocmanError');
                 }
             } else {
                 $item =& $root;
             }
             if ($item) {
                 // Load report
                 // If the item (folder) defined in the report is not the
                 // same than the current one, replace it.
                 $this->_initReport($item);
                 if ($this->_viewParams['filter'] !== null && $this->_viewParams['filter']->getItemId() !== null && $this->_viewParams['filter']->getItemId() != $item->getId()) {
                     $reportItem = $item_factory->getItemFromDb($this->_viewParams['filter']->getItemId());
                     // If item defined in the report exists, use it
                     // otherwise raise an error
                     if (!$reportItem) {
                         $this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'error_report_baditemid'));
                     } else {
                         unset($item);
                         $item = $reportItem;
                     }
                 }
                 if ($this->request->get('action') == 'ajax_reference_tooltip') {
                     $this->groupId = $item->getGroupId();
                 }
                 if ($item->getGroupId() != $this->getGroupId()) {
                     $pm = ProjectManager::instance();
                     $g = $pm->getProject($this->getGroupId());
                     $this->_set_doesnot_belong_to_project_error($item, $g);
                 } else {
                     $user = $this->getUser();
                     $dpm = $this->_getPermissionsManager();
                     $can_read = $dpm->userCanAccess($user, $item->getId());
                     $folder_or_document = is_a($item, 'Docman_Folder') ? 'folder' : 'document';
                     if (!$can_read) {
                         if ($this->request->get('action') == 'ajax_reference_tooltip') {
                             $this->_setView('AjaxReferenceTooltipError');
                         } else {
                             $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_view'));
                             $this->_setView('PermissionDeniedError');
                         }
                     } else {
                         $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']);
                         $mdFactory->appendItemMetadataList($item);
                         $get_show_view =& new Docman_View_GetShowViewVisitor();
                         $this->_viewParams['item'] =& $item;
                         if (strpos($view, 'admin') === 0 && !$this->userCanAdmin()) {
                             $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_admin'));
                             $this->view = $item->accept($get_show_view, $this->request->get('report'));
                         } else {
                             if ($item->isObsolete()) {
                                 $this->feedback->log('warning', $this->txt('warning_obsolete'));
                             }
                             $this->_dispatch($view, $item, $root, $get_show_view);
                         }
                     }
                 }
             }
         }
     }
 }
 function admin_change_view()
 {
     $request =& HTTPRequest::instance();
     $group_id = (int) $request->get('group_id');
     if ($request->exist('selected_view') && Docman_View_Browse::isViewAllowed($request->get('selected_view'))) {
         require_once 'Docman_SettingsBo.class.php';
         $sBo =& Docman_SettingsBo::instance($group_id);
         if ($sBo->updateView($request->get('selected_view'))) {
             $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'info_settings_updated'));
         } else {
             $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_settings_updated'));
         }
     }
 }
 function _displayItem(&$item, $params)
 {
     $li_displayed = false;
     if ($this->stripFirstNode && !$this->firstNodeStripped) {
         $this->firstNodeStripped = true;
         if (isset($this->params['display_description']) && $this->params['display_description']) {
             $this->html .= '<p>' . $item->getDescription() . '</p>';
         }
     } else {
         if ($item !== null && $this->_canDisplayItem($item)) {
             $this->html .= '<li id="item_' . $item->getId() . '" class="' . Docman_View_Browse::getItemClasses($params) . '">';
             $params['expanded'] = true;
             $open = '_open';
             if (!isset($this->params['item_to_move']) && user_get_preference(PLUGIN_DOCMAN_EXPAND_FOLDER_PREF . '_' . $item->getGroupId() . '_' . $item->getId()) === false) {
                 $params['expanded'] = false;
                 $open = '';
             }
             $icon_src = $this->params['docman_icons']->getIconForItem($item, $params);
             $icon = '<img src="' . $icon_src . '" class="docman_item_icon" />';
             $this->html .= '<div>';
             $action = isset($this->params['item_to_move']) ? false : $item->accept($this->get_action_on_icon, array('view' => &$this->view));
             if ($action) {
                 $class = $item->accept($this->get_class_for_link, array('view' => &$this->view));
                 if ($class) {
                     $class .= $open;
                 }
                 $url = Docman_View_View::buildUrl($this->params['default_url'], array('action' => $action, 'id' => $item->getId()));
                 $this->html .= '<a href="' . $url . '" class="' . $class . '">';
             }
             $this->html .= $icon;
             if ($action) {
                 $this->html .= '</a>';
             }
             $this->html .= '<span class="docman_item_title">';
             if ($action) {
                 $url = Docman_View_View::buildActionUrl($this->params, array('action' => 'show', 'id' => $item->getId()), false, isset($params['popup_doc']) ? true : false);
                 $this->html .= '<a href="' . $url . '" id="docman_item_title_link_' . $item->getId() . '">';
             }
             $this->html .= $this->hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML);
             if ($action) {
                 $this->html .= '</a>';
             }
             $this->html .= '</span>';
             $this->html .= $this->view->getItemMenu($item, $this->params);
             $this->js .= $this->view->getActionForItem($item);
             $this->html .= '</div>';
             if (trim($item->getDescription()) != '') {
                 $this->html .= '<div class="docman_item_description">' . $this->hp->purify($item->getDescription(), CODENDI_PURIFIER_BASIC, $item->getGroupId()) . '</div>';
             }
             $li_displayed = true;
         }
     }
     return $li_displayed;
 }
 function visitFolder(&$item, $params = array())
 {
     return Docman_View_Browse::getViewForCurrentUser($item->getGroupId(), $params);
 }
 function _displayItem(&$item, $params)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $html = '<div id="item_' . $item->getId() . '" class="' . Docman_View_Browse::getItemClasses($params) . '" style="position:relative;">';
     $show_options = isset($params['show_options']) && $params['show_options'] == $item->getId();
     $icon_src = $params['docman_icons']->getIconForItem($item, $params);
     $icon = '<img src="' . $icon_src . '" class="docman_item_icon" style="vertical-align:middle; text-decoration:none;" />';
     $icon_url = $this->buildUrl($params['default_url'], array('action' => $item->accept($params['get_action_on_icon'], array('view' => $this)), 'id' => $item->getId()));
     $title_url = $this->buildUrl($params['default_url'], array('action' => 'show', 'id' => $item->getId()));
     $html .= '<div><a href="' . $icon_url . '">' . $icon . '</a>';
     $html .= '<span class="docman_item_title"><a href="' . $title_url . '" id="docman_item_title_link_' . $item->getId() . '">' . $hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML) . '</a></span>';
     $html .= '</a>';
     //Show/hide options {{{
     $html .= $this->getItemMenu($item, $params);
     $this->javascript .= $this->getActionForItem($item);
     //}}}
     if (trim($item->getDescription()) != '') {
         $html .= '<div class="docman_item_description">' . $hp->purify($item->getDescription(), CODENDI_PURIFIER_BASIC) . '</div>';
     }
     $html .= '</div>';
     $html .= '</div>';
     return $html;
 }
 function getViewForCurrentUser($group_id, $report = '')
 {
     if ($report != '') {
         $pref = $report;
     } else {
         $pref = user_get_preference(PLUGIN_DOCMAN_VIEW_PREF . '_' . $group_id);
         if (!$pref) {
             $sBo =& Docman_SettingsBo::instance($group_id);
             $pref = $sBo->getView();
         }
     }
     if (!$pref || !Docman_View_Browse::isViewAllowed($pref)) {
         $pref = 'Tree';
     }
     return $pref;
 }