protected function _isDisplayEditable()
 {
     $pn_display_id = $this->request->getParameter('display_id', pInteger);
     if ($pn_display_id == 0) {
         return true;
     }
     // allow creation of new displays
     $t_display = new ca_bundle_displays();
     if (!$t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_EDIT_ACCESS__, $pn_display_id)) {
         // is user allowed to edit display?
         $this->notification->addNotification(_t("You cannot edit that display"), __NOTIFICATION_TYPE_ERROR__);
         $this->response->setRedirect(caNavUrl($this->request, 'manage', 'BundleDisplays', 'ListDisplays'));
         return false;
     } else {
         return true;
     }
 }
 /**
  * Generate  export file of current result
  */
 protected function _genExport($pt_subject, $ps_template, $ps_output_filename, $ps_title = null)
 {
     $this->view->setVar('t_subject', $pt_subject);
     if (substr($ps_template, 0, 5) === '_pdf_') {
         $va_template_info = caGetPrintTemplateDetails('summary', substr($ps_template, 5));
     } elseif (substr($ps_template, 0, 9) === '_display_') {
         $vn_display_id = substr($ps_template, 9);
         $t_display = new ca_bundle_displays($vn_display_id);
         if ($vn_display_id && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
             $this->view->setVar('t_display', $t_display);
             $this->view->setVar('display_id', $vn_display_id);
             $va_display_list = array();
             $va_placements = $t_display->getPlacements(array('settingsOnly' => true));
             foreach ($va_placements as $vn_placement_id => $va_display_item) {
                 $va_settings = caUnserializeForDatabase($va_display_item['settings']);
                 // get column header text
                 $vs_header = $va_display_item['display'];
                 if (isset($va_settings['label']) && is_array($va_settings['label'])) {
                     $va_tmp = caExtractValuesByUserLocale(array($va_settings['label']));
                     if ($vs_tmp = array_shift($va_tmp)) {
                         $vs_header = $vs_tmp;
                     }
                 }
                 $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings);
             }
             $this->view->setVar('placements', $va_display_list);
         } else {
             $this->postError(3100, _t("Invalid format %1", $ps_template), "DetailController->_genExport()");
             return;
         }
         $va_template_info = caGetPrintTemplateDetails('summary', 'summary');
     } else {
         $this->postError(3100, _t("Invalid format %1", $ps_template), "DetailController->_genExport()");
         return;
     }
     //
     // PDF output
     //
     if (!is_array($va_template_info)) {
         $this->postError(3110, _t("Could not find view for PDF"), "DetailController->_genExport()");
         return;
     }
     //
     // Tag substitution
     //
     // Views can contain tags in the form {{{tagname}}}. Some tags, such as "itemType" and "detailType" are defined by
     // the detail controller. More usefully, you can pull data from the item being detailed by using a valid "get" expression
     // as a tag (Eg. {{{ca_objects.idno}}}. Even more usefully for some, you can also use a valid bundle display template
     // (see http://docs.collectiveaccess.org/wiki/Bundle_Display_Templates) as a tag. The template will be evaluated in the
     // context of the item being detailed.
     //
     $va_defined_vars = array_keys($this->view->getAllVars());
     // get list defined vars (we don't want to copy over them)
     $va_tag_list = $this->getTagListForView($va_template_info['path']);
     // get list of tags in view
     foreach ($va_tag_list as $vs_tag) {
         if (in_array($vs_tag, $va_defined_vars)) {
             continue;
         }
         if (strpos($vs_tag, "^") !== false || strpos($vs_tag, "<") !== false) {
             $this->view->setVar($vs_tag, $pt_subject->getWithTemplate($vs_tag, array('checkAccess' => $this->opa_access_values)));
         } elseif (strpos($vs_tag, ".") !== false) {
             $this->view->setVar($vs_tag, $pt_subject->get($vs_tag, array('checkAccess' => $this->opa_access_values)));
         } else {
             $this->view->setVar($vs_tag, "?{$vs_tag}");
         }
     }
     try {
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $vs_content = $this->render($va_template_info['path']);
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf'));
         $vb_printed_properly = true;
     } catch (Exception $e) {
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "DetailController->_genExport()");
     }
     return;
 }
 /**
  * Generate  export file of current result
  */
 protected function _genExport($po_result, $ps_template, $ps_output_filename, $ps_title = null)
 {
     if ($this->opo_result_context) {
         $this->opo_result_context->setParameter('last_export_type', $ps_output_type);
         $this->opo_result_context->saveContext();
     }
     if (substr($ps_template, 0, 5) === '_pdf_') {
         $va_template_info = caGetPrintTemplateDetails('results', substr($ps_template, 5));
     } elseif (substr($ps_template, 0, 9) === '_display_') {
         $vn_display_id = substr($ps_template, 9);
         $t_display = new ca_bundle_displays($vn_display_id);
         if ($vn_display_id && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
             $this->view->setVar('display', $t_display);
             $va_placements = $t_display->getPlacements(array('settingsOnly' => true));
             foreach ($va_placements as $vn_placement_id => $va_display_item) {
                 $va_settings = caUnserializeForDatabase($va_display_item['settings']);
                 // get column header text
                 $vs_header = $va_display_item['display'];
                 if (isset($va_settings['label']) && is_array($va_settings['label'])) {
                     $va_tmp = caExtractValuesByUserLocale(array($va_settings['label']));
                     if ($vs_tmp = array_shift($va_tmp)) {
                         $vs_header = $vs_tmp;
                     }
                 }
                 $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings);
             }
             $this->view->setVar('display_list', $va_display_list);
         } else {
             $this->postError(3100, _t("Invalid format %1", $ps_template), "FindController->_genExport()");
             return;
         }
         $va_template_info = caGetPrintTemplateDetails('results', 'display');
     } else {
         $this->postError(3100, _t("Invalid format %1", $ps_template), "FindController->_genExport()");
         return;
     }
     //
     // PDF output
     //
     if (!is_array($va_template_info)) {
         $this->postError(3110, _t("Could not find view for PDF"), "FindController->_genExport()");
         return;
     }
     try {
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         set_time_limit(600);
         $vs_content = $this->render($va_template_info['path']);
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('results'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf'));
         $vb_printed_properly = true;
     } catch (Exception $e) {
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "FindController->_genExport()");
     }
     return;
 }