/** * */ public function addItem() { global $g_ui_locale_id; // current locale_id for user if (!$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form')); return; } if (!($t_set = $this->_getSet(__CA_SET_EDIT_ACCESS__))) { if ($t_set = $this->_getSet(__CA_SET_READ_ACCESS__)) { $this->view->setVar('message', _t("You can not add items to this set. You have read only access.")); $this->index(); return; } # --- if there is not a set for this user, make a new set for them $t_new_set = new ca_sets(); $vn_new_set_id = null; $t_new_set->setMode(ACCESS_WRITE); $t_new_set->set('access', 0); $t_new_set->set('table_num', 57); // 57=ca_objects $t_list = new ca_lists(); $vn_set_id = $t_list->getItemIDFromList('set_types', $this->request->config->get('user_set_type')); $t_new_set->set('type_id', $vn_set_id); $t_new_set->set('user_id', $this->request->getUserID()); $t_new_set->set('set_code', $this->request->getUserID() . '_' . time()); // create new attribute $t_new_set->insert(); if (!$t_new_set->numErrors()) { if ($vn_new_set_id = $t_new_set->getPrimaryKey()) { $t_new_set->addLabel(array('name' => _t("Your first lightbox")), $g_ui_locale_id, null, true); // select the current set $this->request->user->setVar('current_set_id', $vn_new_set_id); //clear t_new_set object so form appears blank and load t_set so edit form is populated $t_new_set = new ca_sets(); $t_set = new ca_sets($vn_new_set_id); } } } if (!$t_set) { $va_errors[] = _t('Could not create lightbox for user'); } else { $pn_item_id = null; $pn_object_id = $this->request->getParameter('object_id', pInteger); if (!$t_set->isInSet("ca_objects", $pn_object_id, $t_set->get("set_id"))) { if ($pn_item_id = $t_set->addItem($pn_object_id, array(), $this->request->getUserID())) { // // Select primary representation // $t_object = new ca_objects($pn_object_id); $vn_rep_id = $t_object->getPrimaryRepresentationID(); // get representation_id for primary $t_item = new ca_set_items($pn_item_id); $t_item->addSelectedRepresentation($vn_rep_id); // flag as selected in item vars $t_item->update(); $va_errors = array(); $this->view->setVar('message', _t("Successfully added item. %1Click here to resume your search%2.", "<a href='" . caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $pn_object_id)) . "'>", "</a>")); } else { $va_errors[] = _t('Could not add item to lightbox'); } } else { $this->view->setVar('message', _t("Item already in set. %1Click here to resume your search%2.", "<a href='" . caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $pn_object_id)) . "'>", "</a>")); } } //$t_row = new ca_objects($pn_object_id); $this->view->setVar('errors', $va_errors); $this->index(); }
public function AjaxAddItem() { if (!$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm')); return; } global $g_ui_locale_id; // current locale_id for user $va_errors = array(); $o_purifier = new HTMLPurifier(); # --- set_id is passed through form, otherwise we're saving a new set, and adding the item to it if ($this->request->getParameter('set_id', pInteger)) { $t_set = $this->_getSet(__CA_EDIT_READ_ACCESS__); if (!$t_set && ($t_set = $this->_getSet(__CA_SET_READ_ACCESS__))) { $va_errors["general"] = _t("You can not add items to this lightbox. You have read only access."); $this->view->setVar('errors', $va_errors); $this->addItemForm(); return; } } else { $t_set = new ca_sets(); # --- set name - if not sent, make a decent default $ps_name = $o_purifier->purify($this->request->getParameter('name', pString)); if (!$ps_name) { $ps_name = _t("Your lightbox"); } # --- set description - optional $ps_description = $o_purifier->purify($this->request->getParameter('description', pString)); $t_list = new ca_lists(); $vn_set_type_user = $t_list->getItemIDFromList('set_types', $this->request->config->get('user_set_type')); $t_object = new ca_objects(); $vn_object_table_num = $t_object->tableNum(); $t_set->setMode(ACCESS_WRITE); $t_set->set('access', 1); #$t_set->set('access', $this->request->getParameter('access', pInteger)); $t_set->set('table_num', $vn_object_table_num); $t_set->set('type_id', $vn_set_type_user); $t_set->set('user_id', $this->request->getUserID()); $t_set->set('set_code', $this->request->getUserID() . '_' . time()); # --- create new attribute if ($ps_description) { $t_set->addAttribute(array('description' => $ps_description, 'locale_id' => $g_ui_locale_id), 'description'); } $t_set->insert(); if ($t_set->numErrors()) { $va_errors["general"] = join("; ", $t_set->getErrors()); $this->view->setVar('errors', $va_errors); $this->addItemForm(); return; } else { # --- save name - add new label $t_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true); # --- select the current set $this->request->user->setVar('current_set_id', $t_set->get("set_id")); } } if ($t_set) { $pn_item_id = null; $pn_object_id = $this->request->getParameter('object_id', pInteger); if ($pn_object_id) { if (!$t_set->isInSet("ca_objects", $pn_object_id, $t_set->get("set_id"))) { if ($pn_item_id = $t_set->addItem($pn_object_id, array(), $this->request->getUserID())) { // // Select primary representation // $t_object = new ca_objects($pn_object_id); $vn_rep_id = $t_object->getPrimaryRepresentationID(); // get representation_id for primary $t_item = new ca_set_items($pn_item_id); $t_item->addSelectedRepresentation($vn_rep_id); // flag as selected in item vars $t_item->update(); $va_errors = array(); $this->view->setVar('message', _t("Successfully added item.")); $this->render("Form/reload_html.php"); } else { $va_errors["message"] = _t('Could not add item to lightbox'); $this->render("Form/reload_html.php"); } } else { $this->view->setVar('message', _t("Item already in lightbox.")); $this->render("Form/reload_html.php"); } } else { $this->view->setVar('message', _t("Object ID is not defined")); $this->render("Form/reload_html.php"); } } }
public function RecordRepresentationSelection() { $pn_item_id = $this->request->getParameter('item_id', pInteger); $pn_representation_id = $this->request->getParameter('representation_id', pInteger); $pn_selected = $this->request->getParameter('selected', pInteger); $va_errors = array(); $t_set_item = new ca_set_items($pn_item_id); $t_set = new ca_sets($t_set_item->get('set_id')); if (!$t_set->getPrimaryKey() || !$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { // TODO: proper error reporting or redirect? return; } if (!$t_set_item->getPrimaryKey()) { $va_errors[] = _t("Invalid set item"); } if (!sizeof($va_errors)) { $t_set = new ca_sets($t_set_item->get('set_id')); if (!$t_set->getPrimaryKey()) { $va_errors[] = _t("Invalid set"); } if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { $va_errors[] = _t("You do not have access to this set"); } if (!sizeof($va_errors)) { if ((bool) $pn_selected) { $t_set_item->addSelectedRepresentation($pn_representation_id); } else { $t_set_item->removeSelectedRepresentation($pn_representation_id); } $t_set_item->update(); $va_errors = $t_set_item->getErrors(); } } $this->view->setVar("errors", $va_errors); $this->view->setVar('representation_id', $pn_representation_id); $this->view->setVar('item_id', $pn_item_id); $this->render("ajax_select_representation_json.php"); }