$vn_item_count++;
 if ($vn_item_count == 2) {
     $vs_class = "resultBg";
     $vn_item_count = 0;
 }
 $vn_occurrence_id = $vo_result->get('ca_occurrences.occurrence_id');
 $va_labels = $vo_result->getDisplayLabels($this->request);
 print "<div" . ($vs_class ? " class='{$vs_class}'" : "") . " style='clear:both;'>";
 $t_occurrence->load($vn_occurrence_id);
 $vs_padding = 0;
 $va_related_objects_links = $t_occurrence->get("ca_objects_x_occurrences.relation_id", array("returnAsArray" => true));
 if (sizeof($va_related_objects_links)) {
     $t_objects_x_occurrences = new ca_objects_x_occurrences();
     foreach ($va_related_objects_links as $vn_relation_id) {
         $t_objects_x_occurrences->load($vn_relation_id);
         $va_reps = $t_objects_x_occurrences->get("ca_objects_x_occurrences.representation_list", array("returnAsArray" => true, 'idsOnly' => true));
         if (is_array($va_reps)) {
             foreach ($va_reps as $vn_relation_id => $va_attr) {
                 $t_rep = new ca_object_representations($va_attr['representation_list']);
                 $va_info = $t_rep->getMediaInfo("media");
                 $vs_padding = round($va_info["thumbnail"]["HEIGHT"] / 2) - 7;
                 print "<div class='occThumb'>" . $t_rep->getMediaTag('media', 'thumbnail') . "</div><!-- end occThumb -->";
                 break;
             }
         }
         break;
     }
 }
 print "<div style='padding-top:" . $vs_padding . "px;'>" . caNavLink($this->request, join($va_labels, "; "), '', 'Detail', 'Occurrence', 'Show', array('occurrence_id' => $vn_occurrence_id));
 print ", " . $vo_result->get('ca_occurrences.type_id', array("convertCodesToDisplayText" => true));
 if ($vo_result->get('ca_occurrences.blankWorksheet')) {
             if ($ps_mode == "print" && in_array($vs_attribute_code, $va_attributes_for_occ_type)) {
                 print "<div class='unit'><input type='checkbox' checked name='print_fields[]' value='" . $vs_attribute_code . "'> <b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>";
                 print "<textarea name='{$vs_attribute_code}'></textarea>";
                 print "</div><!-- end unit -->";
             }
         }
     }
 }
 # --- related objects
 $va_related_objects_links = $t_occurrence->get("ca_objects_x_occurrences.relation_id", array("returnAsArray" => true));
 if (sizeof($va_related_objects_links)) {
     $t_objects_x_occurrences = new ca_objects_x_occurrences();
     $t_object = new ca_objects();
     foreach ($va_related_objects_links as $vn_relation_id) {
         $t_objects_x_occurrences->load($vn_relation_id);
         $va_reps = $t_objects_x_occurrences->get("ca_objects_x_occurrences.representation_list", array("returnAsArray" => true, 'idsOnly' => true));
         if (is_array($va_reps)) {
             foreach ($va_reps as $vn_i => $va_attr) {
                 $t_rep = new ca_object_representations($va_attr['representation_list']);
                 print "<div class='unit'>";
                 if ($ps_mode == "print") {
                     print "<input type='checkbox' checked name='print_fields[]' value='rep" . $t_rep->get("representation_id") . "'> ";
                 }
                 # --- open in media viewer
                 print "<a href='#' onclick='caMediaPanel.showPanel(\"" . caNavUrl($this->request, 'Detail', 'Object', 'GetRepresentationInfo', array('object_id' => $t_objects_x_occurrences->get("ca_objects.object_id"), 'representation_id' => $t_rep->getPrimaryKey())) . "\"); return false;' >" . $t_rep->getMediaTag('media', 'medium') . "</a>";
                 #print $t_rep->getMediaTag('media', 'medium');
                 print "</div><!-- end unit -->";
             }
         }
         print "<div class='unit' style='font-size:11px; font-style:italic;'>" . caNavLink($this->request, $t_objects_x_occurrences->get("ca_objects.preferred_labels.name"), '', 'Detail', 'Object', 'Show', array('object_id' => $t_objects_x_occurrences->get("ca_objects.object_id")));
         if ($va_dates = $t_objects_x_occurrences->get("ca_objects.date", array("returnAsArray" => true))) {
 public function downloadCustomWorksheet()
 {
     $o_purifier = new HTMLPurifier();
     $pn_occurrence_id = $this->request->getParameter('occurrence_id', pInteger);
     $pn_relation_id = $this->request->getParameter('relation_id', pInteger);
     $t_objects_x_occurrences = new ca_objects_x_occurrences($pn_relation_id);
     # --- get the images
     $pa_print_rep = $this->request->getParameter('print_reps', pArray);
     $va_images = array();
     if (is_array($pa_print_rep)) {
         $t_rep = new ca_object_representations();
         foreach ($pa_print_rep as $vn_i => $vn_rep_id) {
             $t_rep->load($vn_rep_id);
             $va_media_info = $t_rep->getMediaInfo('media');
             $vn_height = $va_media_info["large"]["HEIGHT"];
             $vn_width = $va_media_info["large"]["WIDTH"];
             if ($vn_height > 900) {
                 $vn_new_width = 900 * $vn_width / $vn_height;
                 $vs_image = "<img src='" . $t_rep->getMediaUrl('media', 'large') . "' style='height:900px; width:" . $vn_new_width . "px;'>";
             } else {
                 $vs_image = $t_rep->getMediaTag("media", "large");
             }
             $va_images[] = $vs_image;
         }
     }
     $this->view->setVar("images", $va_images);
     $t_lists = new ca_lists();
     $vn_original_date = $t_lists->getItemIDFromList("date_types", "dateOriginal");
     $vs_image_info = "<div style='font-size:11px; font-style:italic;'>" . $t_objects_x_occurrences->get("ca_objects.preferred_labels.name");
     if ($va_dates = $t_objects_x_occurrences->get("ca_objects.date", array("returnAsArray" => true))) {
         foreach ($va_dates as $va_date_info) {
             if ($va_date_info["dc_dates_types"] == $vn_original_date) {
                 $vs_image_info .= ", " . $va_date_info["dates_value"];
             }
         }
     }
     if ($t_objects_x_occurrences->get("ca_objects.repository")) {
         $vs_image_info .= ", " . $t_objects_x_occurrences->get("ca_objects.repository", array('delimiter' => ', ', 'convertCodesToDisplayText' => true));
     }
     $vs_image_info .= ", " . $t_objects_x_occurrences->get("ca_objects.idno") . "</div>";
     $this->view->setVar("image_info", $vs_image_info);
     # --- get the attributes the user may have altered
     $va_info = array();
     $va_attributes = $this->opa_worksheet_attributes;
     foreach ($va_attributes as $vs_attribute_code => $vs_title) {
         if ($vs_value = str_replace("\n", "<br/>", $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString)))) {
             if ($vs_attribute_code == "title") {
                 $va_info[$vs_attribute_code] = $vs_value;
             } else {
                 $va_info[$vs_attribute_code] = "<b>" . $vs_title . "</b><br/>" . $vs_value;
             }
         } else {
             $va_info[$vs_attribute_code] = "";
         }
     }
     $this->view->setvar("worksheet_info", $va_info);
     require_once __CA_LIB_DIR__ . '/core/Parsers/dompdf/dompdf_config.inc.php';
     if ($vs_title = $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString))) {
         $vs_output_filename = $vs_title;
     } else {
         $vs_output_filename = "NYSA_Custom_WorkSheet";
     }
     $vs_output_file_name = preg_replace("/[^A-Za-z0-9\\-]+/", '_', $vs_output_filename);
     header("Content-Disposition: attachment; filename=export_results.pdf");
     header("Content-type: application/pdf");
     $vs_content = $this->render($this->ops_theme . '/custom_worksheet_html.php');
     $o_pdf = new DOMPDF();
     // Page sizes: 'letter', 'legal', 'A4'
     // Orientation:  'portrait' or 'landscape'
     $o_pdf->set_paper("letter", "portrait");
     $o_pdf->load_html($vs_content, 'utf-8');
     $o_pdf->render();
     $o_pdf->stream($vs_output_file_name . ".pdf");
     return;
 }