Ejemplo n.º 1
0
 function saveUserGroup()
 {
     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();
     $t_user_group = new ca_user_groups();
     if ($pn_group_id = $this->request->getParameter('group_id', pInteger)) {
         $t_user_group->load($pn_group_id);
     }
     # --- check for errors
     # --- group 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 user group");
     } else {
         $this->view->setVar("name", $ps_name);
     }
     # --- user group description - optional
     $ps_description = $o_purifier->purify($this->request->getParameter('description', pString));
     $this->view->setVar("description", $ps_description);
     if (sizeof($va_errors) == 0) {
         $t_user_group->setMode(ACCESS_WRITE);
         $t_user_group->set('name', $ps_name);
         $t_user_group->set('description', $ps_description);
         if ($t_user_group->get("group_id")) {
             $t_user_group->update();
         } else {
             $t_user_group->set('user_id', $this->request->getUserID());
             $t_user_group->set('code', 'lb_' . $this->request->getUserID() . '_' . time());
             $t_user_group->insert();
             if ($t_user_group->get("group_id")) {
                 $t_user_group->addUsers($this->request->getUserID());
             }
         }
         if ($t_user_group->numErrors()) {
             $va_errors["general"] = join("; ", $t_user_group->getErrors());
             $this->view->setVar('errors', $va_errors);
             $this->userGroupForm();
         } else {
             # --- add current user to group
             $this->view->setVar("message", _t('Saved user group.'));
             $this->render("Form/reload_html.php");
         }
     } else {
         $this->view->setVar('errors', $va_errors);
         $this->userGroupForm();
     }
 }