Exemplo n.º 1
0
 function saveSetInfo()
 {
     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
     if ($this->request->getParameter('set_id', pInteger)) {
         $t_set = $this->_getSet(__CA_EDIT_READ_ACCESS__);
     } else {
         $t_set = new ca_sets();
     }
     # --- check for errors
     # --- set name - required
     $ps_name = $o_purifier->purify($this->request->getParameter('name', pString));
     if (!$ps_name) {
         $va_errors["name"] = _t("Please enter the name of your lightbox");
     } else {
         $this->view->setVar("name", $ps_name);
     }
     # --- set description - optional
     $ps_description = $o_purifier->purify($this->request->getParameter('description', pString));
     $this->view->setVar("description", $ps_description);
     $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();
     if (sizeof($va_errors) == 0) {
         $t_set->setMode(ACCESS_WRITE);
         $t_set->set('access', 1);
         #$t_set->set('access', $this->request->getParameter('access', pInteger));
         if ($t_set->get("set_id")) {
             # --- edit/add description
             $t_set->replaceAttribute(array('description' => $ps_description, 'locale_id' => $g_ui_locale_id), 'description');
             $t_set->update();
         } else {
             $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
             $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->setForm();
         } else {
             # --- save name
             if (sizeof($va_labels = caExtractValuesByUserLocale($t_set->getLabels(array($g_ui_locale_id), __CA_LABEL_TYPE_PREFERRED__)))) {
                 # --- edit label
                 foreach ($va_labels as $vn_set_id => $va_label) {
                     $t_set->editLabel($va_label[0]['label_id'], array('name' => $ps_name), $g_ui_locale_id);
                 }
             } else {
                 # --- 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"));
             $this->view->setVar("message", _t('Saved lightbox.'));
             $this->render("Form/reload_html.php");
         }
     } else {
         $this->view->setVar('errors', $va_errors);
         $this->setForm();
     }
 }
Exemplo n.º 2
0
 public function saveSetInfo()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
         return;
     }
     global $g_ui_locale_id;
     // current locale_id for user
     $va_errors_edit_set = array();
     $t_set = new ca_sets();
     $pn_set_id = $this->request->getParameter('set_id', pInteger);
     $ps_name = $this->request->getParameter('name', pString);
     if (!$ps_name) {
         $va_errors_edit_set["name"] = _t("You must enter a name for your collection");
     }
     $vs_desc = $this->request->getParameter('description', pString);
     if (sizeof($va_errors_edit_set) == 0) {
         if ($t_set->load($pn_set_id) && $t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $t_set->setMode(ACCESS_WRITE);
             $t_set->set('access', $this->request->getParameter('access', pInteger));
             // edit/add description
             $va_intro_texts = $t_set->getAttributesByElement('set_intro');
             if (sizeof($va_intro_texts)) {
                 // edit existing attribute
                 $vn_attribute_id = $va_intro_texts[0]->getAttributeID();
                 $t_set->editAttribute($vn_attribute_id, 'set_intro', array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id));
             } else {
                 // create new attribute
                 $t_set->addAttribute(array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id), 'set_intro');
             }
             $t_set->update();
             if (sizeof($va_labels = caExtractValuesByUserLocale($t_set->getLabels(array($g_ui_locale_id), __CA_LABEL_TYPE_PREFERRED__)))) {
                 // edit label
                 foreach ($va_labels as $vn_set_id => $va_label) {
                     $t_set->editLabel($va_label[0]['label_id'], array('name' => $ps_name), $g_ui_locale_id);
                 }
             } else {
                 // add new label
                 $t_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true);
             }
         }
     }
     $this->view->setVar('errors_edit_set', $va_errors_edit_set);
     $this->index();
 }
Exemplo n.º 3
0
 /**
  *
  */
 public function saveSetInfo()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
         return;
     }
     global $g_ui_locale_id;
     // current locale_id for user
     $va_errors_edit_set = array();
     $o_purifier = new HTMLPurifier();
     $t_set = new ca_sets();
     $pn_set_id = $this->request->getParameter('set_id', pInteger);
     $ps_name = $o_purifier->purify($this->request->getParameter('name', pString));
     if (!$ps_name) {
         $va_errors_edit_set["name"] = _t("You must enter a name for your lightbox");
     }
     $vs_desc = $o_purifier->purify($this->request->getParameter('description', pString));
     if (sizeof($va_errors_edit_set) == 0) {
         if ($t_set->load($pn_set_id) && $t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $t_set->setMode(ACCESS_WRITE);
             $t_set->set('access', $this->request->getParameter('access', pInteger));
             // edit/add description
             $t_set->replaceAttribute(array('locale_id' => $g_ui_locale_id, 'set_description' => $vs_desc), 'set_description');
             $t_set->update();
             if (sizeof($va_labels = caExtractValuesByUserLocale($t_set->getLabels(array($g_ui_locale_id), __CA_LABEL_TYPE_PREFERRED__)))) {
                 // edit label
                 foreach ($va_labels as $vn_set_id => $va_label) {
                     $t_set->editLabel($va_label[0]['label_id'], array('name' => $ps_name), $g_ui_locale_id);
                 }
             } else {
                 // add new label
                 $t_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true);
             }
         } else {
             $this->view->setVar('message', _t("You can not edit this set.  You have read only access."));
         }
     }
     $this->view->setVar('errors_edit_set', $va_errors_edit_set);
     $this->index();
 }