/** * */ public function Info() { $o_dm = Datamodel::load(); $t_form = new ca_search_forms(); $this->view->setVar('form_count', $t_form->getFormCount(array('user_id' => $this->request->getUserID(), 'access' => __CA_SEARCH_FORM_EDIT_ACCESS__))); return $this->render('widget_search_form_info_html.php', true); }
protected function _isFormEditable() { $pn_form_id = $this->request->getParameter('form_id', pInteger); if ($pn_form_id == 0) { return true; } // allow creation of new forms $t_form = new ca_search_forms(); if (!$t_form->haveAccessToForm($this->request->getUserID(), __CA_BUNDLE_DISPLAY_EDIT_ACCESS__, $pn_form_id)) { // is user allowed to edit form? $this->notification->addNotification(_t("You cannot edit that form"), __NOTIFICATION_TYPE_ERROR__); $this->response->setRedirect(caNavUrl($this->request, 'manage', 'SearchForm', 'ListForms')); return false; } else { return true; } }
public function renderWidget($ps_widget_id, &$pa_settings) { parent::renderWidget($ps_widget_id, $pa_settings); $this->opo_view->setVar('request', $this->getRequest()); $t_form = new ca_search_forms(); if (!($vn_form_id = (int) $pa_settings["form_code"])) { $va_forms = caExtractValuesByUserLocale($t_form->getForms(array('table' => 'ca_objects', 'user_id' => $this->request->getUserID(), 'access' => __CA_SEARCH_FORM_READ_ACCESS__))); $va_tmp = array_keys($va_forms); $vn_form_id = array_shift($va_tmp); } $t_form->load($vn_form_id); $this->opo_view->setVar("t_form", $t_form); if ($t_form->haveAccessToForm($this->getRequest()->user->getUserID(), __CA_SEARCH_FORM_READ_ACCESS__)) { $vo_dm = Datamodel::load(); $vo_result_context = new ResultContext($this->getRequest(), $vo_dm->getTableName($t_form->get("table_num")), "advanced_search"); $va_form_data = $vo_result_context->getParameter('form_data'); $this->opo_view->setVar("controller_name", $this->getAdvancedSearchControllerNameForTable($vo_dm->getTableName($t_form->get("table_num")))); $this->opo_view->setVar('form_data', $va_form_data); $this->opo_view->setVar('form_elements', $t_form->getHTMLFormElements($this->getRequest(), $va_form_data)); } else { $t_form->clear(); } return $this->opo_view->render('main_html.php'); }
/** * Returns summary of current advanced search parameters suitable for display. * * @return string Summary of current search criteria ready for display */ public function getCriteriaForDisplay($pn_form_id = null) { $t_form = new ca_search_forms(); if (!($vn_form_id = $pn_form_id)) { if (!($vn_form_id = $this->opo_result_context->getParameter('form_id')) || !$t_form->haveAccessToForm($this->request->getUserID(), __CA_SEARCH_FORM_READ_ACCESS__, $vn_form_id)) { if (sizeof($va_forms = $t_form->getForms(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_SEARCH_FORM_READ_ACCESS__)))) { $va_tmp = array_keys($va_forms); $vn_form_id = array_shift($va_tmp); } } } $t_form->load($vn_form_id); $va_form_data = $this->opo_result_context->getParameter('form_data'); $va_buf = array(); if (!($t_model = $this->opo_datamodel->getTableInstance($this->ops_tablename, true))) { return '?'; } foreach ($va_form_data as $vs_bundle => $vs_value) { if (!trim($vs_value)) { continue; } $va_buf[] = $t_model->getDisplayLabel($vs_bundle) . ": " . $vs_value; } return join("; ", $va_buf); }
public function processSearchForms() { require_once __CA_MODELS_DIR__ . "/ca_search_forms.php"; require_once __CA_MODELS_DIR__ . "/ca_search_form_placements.php"; $o_config = Configuration::load(); $vo_dm = Datamodel::load(); if ($this->ops_base_name) { // "merge" profile and its base $va_forms = array(); if ($this->opo_base->searchForms) { foreach ($this->opo_base->searchForms->children() as $vo_form) { $va_forms[self::getAttribute($vo_form, "code")] = $vo_form; } } if ($this->opo_profile->searchForms) { foreach ($this->opo_profile->searchForms->children() as $vo_form) { $va_forms[self::getAttribute($vo_form, "code")] = $vo_form; } } } else { if ($this->opo_profile->searchForms) { foreach ($this->opo_profile->searchForms->children() as $vo_form) { $va_forms[self::getAttribute($vo_form, "code")] = $vo_form; } } } if (!is_array($va_forms) || sizeof($va_forms) == 0) { return true; } foreach ($va_forms as $vo_form) { $vs_form_code = self::getAttribute($vo_form, "code"); $vb_system = self::getAttribute($vo_form, "system"); $vs_table = self::getAttribute($vo_form, "type"); if (!($t_instance = $vo_dm->getInstanceByTableName($vs_table, true))) { continue; } if (method_exists($t_instance, 'getTypeList') && !sizeof($t_instance->getTypeList())) { continue; } // no types configured if ($o_config->get($vs_table . '_disable')) { continue; } $vn_table_num = (int) $vo_dm->getTableNum($vs_table); $t_form = $this->opb_updating ? ca_search_forms::find(array('form_code' => (string) $vs_form_code, 'table_num' => $vn_table_num), array('returnAs' => 'firstModelInstance')) : false; $t_form = $t_form ? $t_form : new ca_search_forms(); $t_form->setMode(ACCESS_WRITE); $t_form->set("form_code", (string) $vs_form_code); $t_form->set("is_system", (int) $vb_system); $t_form->set("table_num", $vn_table_num); $va_settings = $this->_processSettings($t_form, $vo_form->settings); if ($t_form->getPrimaryKey()) { $t_form->update(); } else { $t_form->set("user_id", 1); // let administrative user own these $t_form->insert(); } if ($t_form->numErrors()) { $this->addError("There was an error while inserting search form {$vs_form_code}: " . join(" ", $t_form->getErrors())); } else { self::addLabelsFromXMLElement($t_form, $vo_form->labels, $this->opa_locales); if ($t_form->numErrors()) { $this->addError("There was an error while inserting search form label for {$vs_form_code}: " . join(" ", $t_form->getErrors())); } if (!$this->processSearchFormPlacements($t_form, $vo_form->bundlePlacements, null)) { return false; } } // set user and group access if ($vo_form->userAccess) { $t_user = new ca_users(); $va_form_users = array(); foreach ($vo_form->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_form_users[$t_user->getUserID()] = $vn_access; } else { $this->addError("User name or access value invalid for search form {$vs_form_code} (permission item with user name '{$vs_user}')"); } } if (sizeof($va_form_users) > 0) { $t_form->addUsers($va_form_users); } } if ($vo_form->groupAccess) { $t_group = new ca_user_groups(); $va_form_groups = array(); foreach ($vo_form->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_form_groups[$t_group->getPrimaryKey()] = $vn_access; } else { $this->addError("Group code or access value invalid for search form {$vs_form_code} (permission item with group code '{$vs_group}')"); } } if (sizeof($va_form_groups) > 0) { $t_form->addUserGroups($va_form_groups); } } } return true; }
public function savePlacementsFromHTMLForm($po_request, $ps_form_prefix) { if ($vs_bundles = $po_request->getParameter($ps_form_prefix . '_ca_search_form_placementsdisplayBundleList', pString)) { $va_bundles = explode(';', $vs_bundles); $t_form = new ca_search_forms($this->getPrimaryKey()); $va_placements = $t_form->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_form->removePlacement($va_bundle_info['placement_id'], array('user_id' => $po_request->getUserID())); if ($t_form->numErrors()) { $this->errors = $t_form->errors; return false; } } } $va_locale_list = ca_locales::getLocaleList(array('index_by_code' => true)); $va_available_bundles = $t_form->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]+)_(.*)\$!", $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_form->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_form->numErrors()) { $this->errors = $t_form->errors; return false; } } else { $t_placement = new ca_search_form_placements($vn_placement_id, $va_available_bundles[$vs_bundle]['settings']); $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; } } } } }
public function getSearchFormsAsDOM() { $vo_forms = $this->opo_dom->createElement("searchForms"); $qr_forms = $this->opo_db->query("SELECT * FROM ca_search_forms"); while ($qr_forms->nextRow()) { $t_form = new ca_search_forms($qr_forms->get("form_id")); $vo_form = $this->opo_dom->createElement("searchForm"); $vo_form->setAttribute("code", $this->makeIDNO($qr_forms->get("form_code"))); $vo_form->setAttribute("type", $this->opo_dm->getTableName($qr_forms->get("table_num"))); $vo_form->setAttribute("system", $qr_forms->get("is_system")); $vo_labels = $this->opo_dom->createElement("labels"); $qr_form_labels = $this->opo_db->query("SELECT * FROM ca_search_form_labels WHERE form_id=?", $qr_forms->get("form_id")); while ($qr_form_labels->nextRow()) { $vo_label = $this->opo_dom->createElement("label"); $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_form_labels->get("locale_id"))); $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_form_labels->get("name")))); $vo_labels->appendChild($vo_label); } $vo_form->appendChild($vo_labels); if (is_array($t_form->getSettings())) { $vo_settings = $this->opo_dom->createElement("settings"); foreach ($t_form->getSettings() as $vs_setting => $va_value) { if (is_array($va_value)) { foreach ($va_value as $vs_value) { if (!is_array($vs_value)) { // ignore legacy search form settings which usually have nested arrays $vo_setting = $this->opo_dom->createElement("setting", $vs_value); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } } else { $vo_setting = $this->opo_dom->createElement("setting", $va_value); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } $vo_form->appendChild($vo_settings); } $vo_placements = $this->opo_dom->createElement("bundlePlacements"); $qr_placements = $this->opo_db->query("SELECT * FROM ca_search_form_placements WHERE form_id=? ORDER BY placement_id", $qr_forms->get("form_id")); while ($qr_placements->nextRow()) { $vo_placement = $this->opo_dom->createElement("placement"); $vo_placement->setAttribute("code", "p" . $qr_placements->get('placement_id')); $vo_placements->appendChild($vo_placement); $vo_placement->appendChild($this->opo_dom->createElement("bundle", caEscapeForXML($qr_placements->get("bundle_name")))); $t_placement = new ca_search_form_placements($qr_placements->get("placement_id")); if (is_array($t_placement->getSettings())) { $vo_settings = $this->opo_dom->createElement("settings"); foreach ($t_placement->getSettings() as $vs_setting => $va_values) { if (is_array($va_values)) { foreach ($va_values as $vs_key => $vs_value) { $vo_setting = $this->opo_dom->createElement("setting", $vs_value); $vo_setting->setAttribute("name", $vs_setting); if ($vs_setting == "label" || $vs_setting == "add_label") { $vo_setting->setAttribute("locale", $vs_key); } $vo_settings->appendChild($vo_setting); } } else { $vo_setting = $this->opo_dom->createElement("setting", $va_values); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } $vo_placement->appendChild($vo_settings); } } $vo_form->appendChild($vo_placements); $vo_forms->appendChild($vo_form); } return $vo_forms; }
public function getSearchFormsAsDOM() { $vo_forms = $this->opo_dom->createElement("searchForms"); $qr_forms = $this->opo_db->query("SELECT * FROM ca_search_forms"); while ($qr_forms->nextRow()) { /** @var ca_search_forms $t_form */ $t_form = new ca_search_forms($qr_forms->get("form_id")); $vo_form = $this->opo_dom->createElement("searchForm"); $vo_form->setAttribute("code", $this->makeIDNO($qr_forms->get("form_code"))); $vo_form->setAttribute("type", $this->opo_dm->getTableName($qr_forms->get("table_num"))); $vo_form->setAttribute("system", $qr_forms->get("is_system")); $vo_labels = $this->opo_dom->createElement("labels"); $qr_form_labels = $this->opo_db->query("SELECT * FROM ca_search_form_labels WHERE form_id=?", $qr_forms->get("form_id")); while ($qr_form_labels->nextRow()) { $vo_label = $this->opo_dom->createElement("label"); $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_form_labels->get("locale_id"))); $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_form_labels->get("name")))); $vo_labels->appendChild($vo_label); } $vo_form->appendChild($vo_labels); if (is_array($t_form->getSettings())) { $vo_settings = $this->opo_dom->createElement("settings"); foreach ($t_form->getSettings() as $vs_setting => $va_value) { if (is_array($va_value)) { foreach ($va_value as $vs_value) { if (!is_array($vs_value)) { // ignore legacy search form settings which usually have nested arrays $vo_setting = $this->opo_dom->createElement("setting", $vs_value); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } } else { $vo_setting = $this->opo_dom->createElement("setting", $va_value); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } $vo_form->appendChild($vo_settings); } // User and group access $va_users = $t_form->getUsers(); if (sizeof($va_users) > 0) { $vo_user_access = $this->opo_dom->createElement("userAccess"); $vo_form->appendChild($vo_user_access); foreach ($va_users as $va_user_info) { $vo_permission = $this->opo_dom->createElement("permission"); $vo_user_access->appendChild($vo_permission); $vo_permission->setAttribute("user", $va_user_info["user_name"]); $vo_permission->setAttribute("access", $this->_convertUserGroupAccessToString(intval($va_user_info['access']))); } } $va_groups = $t_form->getUserGroups(); if (sizeof($va_groups) > 0) { $vo_group_access = $this->opo_dom->createElement("groupAccess"); $vo_form->appendChild($vo_group_access); foreach ($va_groups as $va_group_info) { $vo_permission = $this->opo_dom->createElement("permission"); $vo_group_access->appendChild($vo_permission); $vo_permission->setAttribute("group", $va_group_info["code"]); $vo_permission->setAttribute("access", $this->_convertUserGroupAccessToString(intval($va_group_info['access']))); } } $vo_placements = $this->opo_dom->createElement("bundlePlacements"); $qr_placements = $this->opo_db->query("SELECT * FROM ca_search_form_placements WHERE form_id=? ORDER BY placement_id", $qr_forms->get("form_id")); while ($qr_placements->nextRow()) { $vo_placement = $this->opo_dom->createElement("placement"); $vo_placement->setAttribute("code", "p" . $qr_placements->get('placement_id')); $vo_placements->appendChild($vo_placement); $vo_placement->appendChild($this->opo_dom->createElement("bundle", caEscapeForXML($qr_placements->get("bundle_name")))); /** @var ca_search_form_placements $t_placement */ $t_placement = new ca_search_form_placements($qr_placements->get("placement_id")); if (is_array($t_placement->getSettings())) { $vo_settings = $this->opo_dom->createElement("settings"); foreach ($t_placement->getSettings() as $vs_setting => $va_values) { if (is_array($va_values)) { foreach ($va_values as $vs_key => $vs_value) { $vo_setting = $this->opo_dom->createElement("setting", $vs_value); $vo_setting->setAttribute("name", $vs_setting); if ($vs_setting == "label" || $vs_setting == "add_label") { if (is_numeric($vs_key)) { $vs_key = $this->opt_locale->localeIDToCode($vs_key); } $vo_setting->setAttribute("locale", $vs_key); } $vo_settings->appendChild($vo_setting); } } else { $vo_setting = $this->opo_dom->createElement("setting", $va_values); $vo_setting->setAttribute("name", $vs_setting); $vo_settings->appendChild($vo_setting); } } $vo_placement->appendChild($vo_settings); } } $vo_form->appendChild($vo_placements); $vo_forms->appendChild($vo_form); } return $vo_forms; }