/**
  * 
  */
 public function Info()
 {
     $o_dm = Datamodel::load();
     $t_display = new ca_bundle_displays($vn_display_id = $this->_getDisplayID());
     $this->view->setVar('bundle_displays', caExtractValuesByUserLocale($t_display->getBundleDisplays(array('user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_EDIT_ACCESS__)), null, array()));
     return $this->render('widget_bundle_display_info_html.php', true);
 }
 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;
     }
 }
 public function savePlacementsFromHTMLForm($po_request, $ps_form_prefix, $ps_placement_code)
 {
     if ($vs_bundles = $po_request->getParameter("{$ps_placement_code}{$ps_form_prefix}displayBundleList", pString)) {
         $va_bundles = explode(';', $vs_bundles);
         $t_display = new ca_bundle_displays($this->getPrimaryKey());
         if ($this->inTransaction()) {
             $t_display->setTransaction($this->getTransaction());
         }
         $va_placements = $t_display->getPlacements(array('user_id' => $po_request->getUserID()));
         // remove deleted bundles
         foreach ($va_placements as $vn_placement_id => $va_bundle_info) {
             if (!in_array($va_bundle_info['bundle_name'] . '_' . $va_bundle_info['placement_id'], $va_bundles)) {
                 $t_display->removePlacement($va_bundle_info['placement_id'], array('user_id' => $po_request->getUserID()));
                 if ($t_display->numErrors()) {
                     $this->errors = $t_display->errors;
                     return false;
                 }
             }
         }
         $va_locale_list = ca_locales::getLocaleList(array('index_by_code' => true));
         $va_available_bundles = $t_display->getAvailableBundles();
         foreach ($va_bundles as $vn_i => $vs_bundle) {
             // get settings
             if (preg_match('!^(.*)_([\\d]+)$!', $vs_bundle, $va_matches)) {
                 $vn_placement_id = (int) $va_matches[2];
                 $vs_bundle = $va_matches[1];
             } else {
                 $vn_placement_id = null;
             }
             $vs_bundle_proc = str_replace(".", "_", $vs_bundle);
             $va_settings = array();
             foreach ($_REQUEST as $vs_key => $vs_val) {
                 if (preg_match("!^{$vs_bundle_proc}_([\\d]+)_([^\\d]+.*)\$!", $vs_key, $va_matches)) {
                     // is this locale-specific?
                     if (preg_match('!(.*)_([a-z]{2}_[A-Z]{2})$!', $va_matches[2], $va_locale_matches)) {
                         $vn_locale_id = isset($va_locale_list[$va_locale_matches[2]]) ? (int) $va_locale_list[$va_locale_matches[2]]['locale_id'] : 0;
                         $va_settings[(int) $va_matches[1]][$va_locale_matches[1]][$vn_locale_id] = $vs_val;
                     } else {
                         $va_settings[(int) $va_matches[1]][$va_matches[2]] = $vs_val;
                     }
                 }
             }
             if ($vn_placement_id === 0) {
                 $t_display->addPlacement($vs_bundle, $va_settings[$vn_placement_id], $vn_i + 1, array('user_id' => $po_request->getUserID(), 'additional_settings' => $va_available_bundles[$vs_bundle]['settings']));
                 if ($t_display->numErrors()) {
                     $this->errors = $t_display->errors;
                     return false;
                 }
             } else {
                 $t_placement = new ca_bundle_display_placements($vn_placement_id, $va_available_bundles[$vs_bundle]['settings']);
                 if ($this->inTransaction()) {
                     $t_placement->setTransaction($this->getTransaction());
                 }
                 $t_placement->setMode(ACCESS_WRITE);
                 $t_placement->set('rank', $vn_i + 1);
                 if (is_array($va_settings[$vn_placement_id])) {
                     //foreach($va_settings[$vn_placement_id] as $vs_setting => $vs_val) {
                     foreach ($t_placement->getAvailableSettings() as $vs_setting => $va_setting_info) {
                         $vs_val = isset($va_settings[$vn_placement_id][$vs_setting]) ? $va_settings[$vn_placement_id][$vs_setting] : null;
                         $t_placement->setSetting($vs_setting, $vs_val);
                     }
                 }
                 $t_placement->update();
                 if ($t_placement->numErrors()) {
                     $this->errors = $t_placement->errors;
                     return false;
                 }
             }
         }
     }
 }
Example #4
0
 public function processDisplays()
 {
     require_once __CA_MODELS_DIR__ . "/ca_bundle_displays.php";
     require_once __CA_MODELS_DIR__ . "/ca_bundle_display_placements.php";
     require_once __CA_MODELS_DIR__ . "/ca_bundle_display_type_restrictions.php";
     $o_config = Configuration::load();
     $vo_dm = Datamodel::load();
     if ($this->ops_base_name) {
         // "merge" profile and its base
         $va_displays = array();
         if ($this->opo_base->displays) {
             foreach ($this->opo_base->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
         if ($this->opo_profile->displays) {
             foreach ($this->opo_profile->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
     } else {
         if ($this->opo_profile->displays) {
             foreach ($this->opo_profile->displays->children() as $vo_display) {
                 $va_displays[self::getAttribute($vo_display, "code")] = $vo_display;
             }
         }
     }
     if (!is_array($va_displays) || sizeof($va_displays) == 0) {
         return true;
     }
     foreach ($va_displays as $vo_display) {
         $vs_display_code = self::getAttribute($vo_display, "code");
         $vb_system = self::getAttribute($vo_display, "system");
         $vs_table = self::getAttribute($vo_display, "type");
         if ($o_config->get($vs_table . '_disable')) {
             continue;
         }
         $t_display = $this->opb_updating ? ca_bundle_displays::find(array('code' => $vs_display_code, 'type' => $vs_table), array('returnAs' => 'firstModelInstance')) : false;
         $t_display = $t_display ? $t_display : new ca_bundle_displays();
         $t_display->setMode(ACCESS_WRITE);
         $t_display->set("display_code", $vs_display_code);
         $t_display->set("is_system", $vb_system);
         $t_display->set("table_num", $vo_dm->getTableNum($vs_table));
         $t_display->set("user_id", 1);
         // let administrative user own these
         $this->_processSettings($t_display, $vo_display->settings);
         if ($t_display->getPrimaryKey()) {
             $t_display->update();
         } else {
             $t_display->insert();
         }
         if ($t_display->numErrors()) {
             $this->addError("There was an error while inserting display {$vs_display_code}: " . join(" ", $t_display->getErrors()));
         } else {
             self::addLabelsFromXMLElement($t_display, $vo_display->labels, $this->opa_locales);
             if ($t_display->numErrors()) {
                 $this->addError("There was an error while inserting display label for {$vs_display_code}: " . join(" ", $t_display->getErrors()));
             }
             if (!$this->processDisplayPlacements($t_display, $vo_display->bundlePlacements, null)) {
                 return false;
             }
         }
         if ($vo_display->typeRestrictions) {
             foreach ($vo_display->typeRestrictions->children() as $vo_restriction) {
                 $t_list = new ca_lists();
                 $t_list_item = new ca_list_items();
                 $vs_restriction_code = trim((string) self::getAttribute($vo_restriction, "code"));
                 $vs_type = trim((string) self::getAttribute($vo_restriction, "type"));
                 $t_instance = $vo_dm->getInstanceByTableNum($vn_table_num = $vo_dm->getTableNum($vs_table));
                 $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                 if ($vs_type) {
                     $t_list->load(array('list_code' => $vs_type_list_name));
                     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'idno' => $vs_type));
                 }
                 $vn_type_id = $vs_type ? $t_list_item->getPrimaryKey() : null;
                 $t_restriction = $this->opb_updating ? ca_bundle_display_type_restrictions::find(array('table_num' => $vn_table_num, 'type_id' => $vn_type_id), array('returnAs' => 'firstModelInstance')) : false;
                 $t_restriction = $t_restriction ? $t_restriction : new ca_bundle_display_type_restrictions();
                 $t_restriction->setMode(ACCESS_WRITE);
                 $t_restriction->set('table_num', $vn_table_num);
                 $t_restriction->set('include_subtypes', (bool) $vo_restriction->includeSubtypes ? 1 : 0);
                 $t_restriction->set('type_id', $vn_type_id);
                 $t_restriction->set('display_id', $t_display->getPrimaryKey());
                 $this->_processSettings($t_restriction, $vo_restriction->settings);
                 if ($t_restriction->getPrimaryKey()) {
                     $t_restriction->update();
                 } else {
                     $t_restriction->insert();
                 }
                 if ($t_restriction->numErrors()) {
                     $this->addError("There was an error while inserting type restriction {$vs_restriction_code} in display {$vs_display_code}: " . join("; ", $t_restriction->getErrors()));
                 }
             }
         }
         if ($vo_display->userAccess) {
             $t_user = new ca_users();
             $va_display_users = array();
             foreach ($vo_display->userAccess->children() as $vo_permission) {
                 $vs_user = trim((string) self::getAttribute($vo_permission, "user"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_user->load(array('user_name' => $vs_user))) {
                     $va_display_users[$t_user->getUserID()] = $vn_access;
                 } else {
                     $this->addError("User name or access value invalid for display {$vs_display_code} (permission item with user name '{$vs_user}')");
                 }
             }
             if (sizeof($va_display_users) > 0) {
                 $t_display->addUsers($va_display_users);
             }
         }
         if ($vo_display->groupAccess) {
             $t_group = new ca_user_groups();
             $va_display_groups = array();
             foreach ($vo_display->groupAccess->children() as $vo_permission) {
                 $vs_group = trim((string) self::getAttribute($vo_permission, "group"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_group->load(array('code' => $vs_group))) {
                     $va_display_groups[$t_group->getPrimaryKey()] = $vn_access;
                 } else {
                     $this->addError("Group code or access value invalid for display {$vs_display_code} (permission item with group code '{$vs_group}')");
                 }
             }
             if (sizeof($va_display_groups) > 0) {
                 $t_display->addUserGroups($va_display_groups);
             }
         }
     }
     return true;
 }
Example #5
0
 /**
  * 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;
 }
 public function getDisplaysAsXML()
 {
     $t_display = new ca_bundle_displays();
     /** @var Datamodel $o_dm */
     $o_dm = Datamodel::load();
     $this->opt_locale = new ca_locales();
     $va_displays = $t_display->getBundleDisplays();
     $vs_buf = "<displays>\n";
     foreach ($va_displays as $vn_i => $va_display_by_locale) {
         $va_locales = array_keys($va_display_by_locale);
         $va_info = $va_display_by_locale[$va_locales[0]];
         if (!$t_display->load($va_info['display_id'])) {
             continue;
         }
         $vs_buf .= "\t<display code='" . ($va_info['display_code'] && preg_match('!^[A-Za-z0-9_]+$!', $va_info['display_code']) ? $va_info['display_code'] : 'display_' . $va_info['display_id']) . "' type='" . $o_dm->getTableName($va_info['table_num']) . "' system='" . $t_display->get('is_system') . "'>\n";
         $vs_buf .= "\t\t<labels>\n";
         foreach ($va_display_by_locale as $vn_locale_id => $va_display_info) {
             if (strlen($this->opt_locale->localeIDToCode($vn_locale_id)) > 0) {
                 $vs_buf .= "\t\t\t<label locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'><name>" . caEscapeForXML($va_display_info['name']) . "</name></label>\n";
             }
         }
         $vs_buf .= "\t\t</labels>\n";
         $va_settings = $t_display->getSettings();
         if (sizeof($va_settings) > 0) {
             $vs_buf .= "\t\t<settings>\n";
             foreach ($va_settings as $vs_setting => $vm_val) {
                 if (is_array($vm_val)) {
                     foreach ($vm_val as $vn_i => $vn_val) {
                         $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n";
                     }
                 } else {
                     $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_val . "]]></setting>\n";
                 }
             }
             $vs_buf .= "\t\t</settings>\n";
         }
         // User and group access
         $va_users = $t_display->getUsers();
         if (sizeof($va_users) > 0) {
             $vs_buf .= "\t\t<userAccess>\n";
             foreach ($va_users as $va_user_info) {
                 $vs_buf .= "\t\t\t<permission user='******' access='" . $this->_convertUserGroupAccessToString(intval($va_user_info['access'])) . "'/>\n";
             }
             $vs_buf .= "\t\t</userAccess>\n";
         }
         $va_groups = $t_display->getUserGroups();
         if (sizeof($va_groups) > 0) {
             $vs_buf .= "\t\t<groupAccess>\n";
             foreach ($va_groups as $va_group_info) {
                 $vs_buf .= "\t\t\t<permission group='" . $va_group_info["code"] . "' access='" . $this->_convertUserGroupAccessToString(intval($va_group_info['access'])) . "'/>\n";
             }
             $vs_buf .= "\t\t</groupAccess>\n";
         }
         $va_placements = $t_display->getPlacements();
         $vs_buf .= "<bundlePlacements>\n";
         foreach ($va_placements as $vn_placement_id => $va_placement_info) {
             $vs_buf .= "\t\t<placement code='" . preg_replace("![^A-Za-z0-9_]+!", "_", $va_placement_info['bundle_name']) . "'><bundle>" . $va_placement_info['bundle_name'] . "</bundle>\n";
             $va_settings = caUnserializeForDatabase($va_placement_info['settings']);
             if (is_array($va_settings)) {
                 $vs_buf .= "<settings>\n";
                 foreach ($va_settings as $vs_setting => $vm_value) {
                     switch ($vs_setting) {
                         case 'label':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_locale_id => $vm_locale_specific_value) {
                                     if (preg_match("/^[a-z]{2,3}\\_[A-Z]{2,3}\$/", $vn_locale_id)) {
                                         // locale code
                                         $vs_locale_code = $vn_locale_id;
                                     } else {
                                         if (!($vs_locale_code = $this->opt_locale->localeIDToCode($vn_locale_id))) {
                                             $vs_locale_code = 'en_US';
                                         }
                                     }
                                     $vs_buf .= "<setting name='label' locale='" . $vs_locale_code . "'>" . caEscapeForXML($vm_locale_specific_value) . "</setting>\n";
                                 }
                             }
                             break;
                         case 'restrict_to_relationship_types':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_val) {
                                     $t_rel_type = new ca_relationship_types($vn_val);
                                     if ($t_rel_type->getPrimaryKey()) {
                                         $vs_value = $t_rel_type->get('type_code');
                                         $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n";
                                     }
                                 }
                             }
                             break;
                         case 'restrict_to_types':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_val) {
                                     $t_item = new ca_list_items($vn_val);
                                     if ($t_item->getPrimaryKey()) {
                                         $vs_value = $t_item->get('idno');
                                         $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n";
                                     }
                                 }
                             }
                             break;
                         default:
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_i => $vn_val) {
                                     $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n";
                                 }
                             } else {
                                 $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_value . "]]></setting>\n";
                             }
                             break;
                     }
                 }
                 $vs_buf .= "</settings>\n";
             }
             $vs_buf .= "\t\t</placement>\n";
         }
         $vs_buf .= "</bundlePlacements>\n";
         $vs_buf .= "\t</display>\n";
     }
     $vs_buf .= "</displays>\n";
     return $vs_buf;
 }
Example #7
0
 /**
  * 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;
 }
 public function getDisplaysAsXML($pa_options = null)
 {
     $t_display = new ca_bundle_displays();
     $o_dm = Datamodel::load();
     $this->opt_locale = new ca_locales();
     $va_displays = $t_display->getBundleDisplays();
     $vs_buf = "<displays>\n";
     foreach ($va_displays as $vn_i => $va_display_by_locale) {
         $va_locales = array_keys($va_display_by_locale);
         $va_info = $va_display_by_locale[$va_locales[0]];
         if (!$t_display->load($va_info['display_id'])) {
             continue;
         }
         $vs_buf .= "\t<display code='" . ($va_info['display_code'] && preg_match('!^[A-Za-z0-9_]+$!', $va_info['display_code']) ? $va_info['display_code'] : 'display_' . $va_info['display_id']) . "' type='" . $o_dm->getTableName($va_info['table_num']) . "' system='" . $t_display->get('is_system') . "'>\n";
         $vs_buf .= "\t\t<labels>\n";
         foreach ($va_display_by_locale as $vn_locale_id => $va_display_info) {
             if (strlen($this->opt_locale->localeIDToCode($vn_locale_id)) > 0) {
                 $vs_buf .= "\t\t\t<label locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'><name>" . caEscapeForXML($va_display_info['name']) . "</name></label>\n";
             }
         }
         $vs_buf .= "\t\t</labels>\n";
         $va_placements = $t_display->getPlacements();
         //print_R(($va_placements));
         $vs_buf .= "<bundlePlacements>\n";
         foreach ($va_placements as $vn_placement_id => $va_placement_info) {
             $vs_buf .= "\t\t<placement code='" . preg_replace("![^A-Za-z0-9_]+!", "_", $va_placement_info['bundle_name']) . "'><bundle>" . $va_placement_info['bundle_name'] . "</bundle>\n";
             $va_settings = caUnserializeForDatabase($va_placement_info['settings']);
             if (is_array($va_settings)) {
                 $vs_buf .= "<settings>\n";
                 foreach ($va_settings as $vs_setting => $vm_value) {
                     switch ($vs_setting) {
                         case 'label':
                             //restrict_to_relationship_types
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_locale_id => $vm_locale_specific_value) {
                                     $vs_buf .= "<setting name='label' locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'>" . caEscapeForXML($vm_locale_specific_value) . "</setting>\n";
                                 }
                             }
                             break;
                         default:
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_i => $vn_val) {
                                     $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'>" . caEscapeForXML($vn_val) . "</setting>\n";
                                 }
                             } else {
                                 $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'>" . caEscapeForXML($vm_value) . "</setting>\n";
                             }
                             break;
                     }
                 }
                 $vs_buf .= "</settings>\n";
             }
             $vs_buf .= "\t\t</placement>\n";
         }
         $vs_buf .= "</bundlePlacements>\n";
         $vs_buf .= "\t</display>\n";
     }
     $vs_buf .= "</displays>\n";
     //print_R($va_displays);
     return $vs_buf;
 }
 /**
  * Generates display summary of record data based upon a bundle display for print (PDF)
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function PrintSummary($pa_options = null)
 {
     AssetLoadManager::register('tableList');
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     $t_display = new ca_bundle_displays();
     $va_displays = $t_display->getBundleDisplays(array('table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'restrictToTypes' => array($t_subject->getTypeID())));
     if (!($vn_display_id = $this->request->getParameter('display_id', pInteger)) || !isset($va_displays[$vn_display_id])) {
         if (!($vn_display_id = $this->request->user->getVar($t_subject->tableName() . '_summary_display_id')) || !isset($va_displays[$vn_display_id])) {
             $va_tmp = array_keys($va_displays);
             $vn_display_id = $va_tmp[0];
         }
     }
     $this->view->setVar('t_display', $t_display);
     $this->view->setVar('bundle_displays', $va_displays);
     // Check validity and access of specified display
     if ($t_display->load($vn_display_id) && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
         $this->view->setVar('display_id', $vn_display_id);
         $va_placements = $t_display->getPlacements(array('returnAllAvailableIfEmpty' => true, 'table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'no_tooltips' => true, 'format' => 'simple', 'settingsOnly' => true));
         $va_display_list = array();
         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'])) {
                 if ($vs_tmp = array_shift(caExtractValuesByUserLocale(array($va_settings['label'])))) {
                     $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);
         $this->request->user->setVar($t_subject->tableName() . '_summary_display_id', $vn_display_id);
         $vs_format = $this->request->config->get("summary_print_format");
     } else {
         $vn_display_id = $t_display = null;
         $this->view->setVar('display_id', null);
         $this->view->setVar('placements', array());
     }
     //
     // PDF output
     //
     if (!$vn_display_id || !$t_display || !is_array($va_template_info = caGetPrintTemplateDetails('summary', "{$this->ops_table_name}_" . $t_display->get('display_code') . "_summary"))) {
         if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "{$this->ops_table_name}_summary"))) {
             if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "summary"))) {
                 $this->postError(3110, _t("Could not find view for PDF"), "BaseEditorController->PrintSummary()");
                 return;
             }
         }
     }
     $va_barcode_files_to_delete = array();
     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"));
         $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $t_subject, $va_template_info['path'], array('checkAccess' => $this->opa_access_values));
         $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, 'print_summary.pdf'));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseEditorController->PrintSummary()");
     }
 }
 /**
  * Generates display summary of record data based upon a bundle display for print (PDF)
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function PrintSummary($pa_options = null)
 {
     require_once __CA_LIB_DIR__ . "/core/Print/html2pdf/html2pdf.class.php";
     JavascriptLoadManager::register('tableList');
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     //
     // Is record of correct type?
     //
     $va_restrict_to_types = null;
     if ($t_subject->getAppConfig()->get('perform_type_access_checking')) {
         $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_table_name, array('access' => __CA_BUNDLE_ACCESS_READONLY__));
     }
     if (is_array($va_restrict_to_types) && !in_array($t_subject->get('type_id'), $va_restrict_to_types)) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2560?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     //
     // Does user have access to row?
     //
     if ($t_subject->getAppConfig()->get('perform_item_level_access_checking')) {
         if ($t_subject->checkACLAccessForUser($this->request->user) == __CA_ACL_NO_ACCESS__) {
             $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2580?r=' . urlencode($this->request->getFullUrlPath()));
             return;
         }
     }
     $t_display = new ca_bundle_displays();
     $va_displays = $t_display->getBundleDisplays(array('table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'restrictToTypes' => array($t_subject->getTypeID())));
     if (!($vn_display_id = $this->request->getParameter('display_id', pInteger)) || !isset($va_displays[$vn_display_id])) {
         if (!($vn_display_id = $this->request->user->getVar($t_subject->tableName() . '_summary_display_id')) || !isset($va_displays[$vn_display_id])) {
             $va_tmp = array_keys($va_displays);
             $vn_display_id = $va_tmp[0];
         }
     }
     $this->view->setVar('t_display', $t_display);
     $this->view->setVar('bundle_displays', $va_displays);
     // Check validity and access of specified display
     if ($t_display->load($vn_display_id) && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
         $this->view->setVar('display_id', $vn_display_id);
         $va_placements = $t_display->getPlacements(array('returnAllAvailableIfEmpty' => true, 'table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'no_tooltips' => true, 'format' => 'simple', 'settingsOnly' => true));
         $va_display_list = array();
         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'])) {
                 if ($vs_tmp = array_shift(caExtractValuesByUserLocale(array($va_settings['label'])))) {
                     $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);
         $this->request->user->setVar($t_subject->tableName() . '_summary_display_id', $vn_display_id);
         $vs_format = $this->request->config->get("summary_print_format");
     } else {
         $this->view->setVar('display_id', null);
         $this->view->setVar('placements', array());
     }
     try {
         $vs_content = $this->render('print_summary_html.php');
         $vo_html2pdf = new HTML2PDF('P', $vs_format, 'en');
         $vo_html2pdf->setDefaultFont("dejavusans");
         $vo_html2pdf->WriteHTML($vs_content);
         $vo_html2pdf->Output('summary.pdf');
         $vb_printed_properly = true;
     } catch (Exception $e) {
         $vb_printed_properly = false;
         $o_event_log = new Eventlog();
         $o_event_log->log(array('CODE' => 'DEBG', 'MESSAGE' => $vs_msg = _t("Could not generate PDF: %1", preg_replace('![^A-Za-z0-9 \\-\\?\\/\\.]+!', ' ', $e->getMessage())), 'SOURCE' => 'BaseEditorController->PrintSummary()'));
         $this->postError(3100, $vs_msg, "BaseEditorController->PrintSummary()");
     }
 }