/**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\GroupController::showEditFormAction()} method.
  *
  * @param Request $request incoming request.
  * @return string Rendered page content.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $errors = array();
     $group_id = $request->attributes->get('group_id', false);
     $parent_group = $request->request->get('parentgroup');
     if (!$parent_group || !preg_match("/^\\d{1,10}\$/", $parent_group)) {
         $parent_group = null;
     }
     $name = $request->request->get('name');
     $description = $request->request->get('description');
     $common_name = $request->request->get('commonname');
     $common_description = $request->request->get('commondescription');
     $email = $request->request->get('email');
     $weight = $request->request->get('weight');
     $title = $request->request->get('title');
     $chat_title = $request->request->get('chattitle');
     $host_url = $request->request->get('hosturl');
     $logo = $request->request->get('logo');
     if (!$name) {
         $errors[] = no_field("Name");
     }
     if ($email != '' && !MailUtils::isValidAddress($email)) {
         $errors[] = wrong_field("E-mail");
     }
     if (!preg_match("/^(\\d{1,10})?\$/", $weight)) {
         $errors[] = wrong_field("Weight");
     }
     if (!$weight) {
         $weight = 0;
     }
     $existing_group = group_by_name($name);
     $duplicate_name = !$group_id && $existing_group || $group_id && $existing_group && $group_id != $existing_group['groupid'];
     if ($duplicate_name) {
         $errors[] = getlocal("Please choose another name because a group with that name already exists.");
     }
     if (count($errors) != 0) {
         $request->attributes->set('errors', $errors);
         // The form should be rebuild. Invoke appropriate action.
         return $this->showFormAction($request);
     }
     if (!$group_id) {
         // Greate new group
         $new_dep = create_group(array('vclocalname' => $name, 'vclocaldescription' => $description, 'vccommonname' => $common_name, 'vccommondescription' => $common_description, 'vcemail' => $email, 'iweight' => $weight, 'parent' => $parent_group, 'vctitle' => $title, 'vcchattitle' => $chat_title, 'vchosturl' => $host_url, 'vclogo' => $logo));
         // Redirect an operator to group's member page.
         $redirect_to = $this->generateUrl('group_members', array('group_id' => (int) $new_dep['groupid']));
     } else {
         // Update exisitng group
         update_group(array('groupid' => $group_id, 'vclocalname' => $name, 'vclocaldescription' => $description, 'vccommonname' => $common_name, 'vccommondescription' => $common_description, 'vcemail' => $email, 'iweight' => $weight, 'parent' => $parent_group, 'vctitle' => $title, 'vcchattitle' => $chat_title, 'vchosturl' => $host_url, 'vclogo' => $logo));
         // Redirect an operator to group's page.
         $redirect_to = $this->generateUrl('group_edit', array('group_id' => $group_id));
     }
     return $this->redirect($redirect_to);
 }
Example #2
0
    mysql_close($link);
}
if (isset($_POST['name'])) {
    $groupid = verifyparam("gid", "/^(\\d{1,9})?\$/", "");
    $name = getparam('name');
    $description = getparam('description');
    $commonname = getparam('commonname');
    $commondescription = getparam('commondescription');
    $email = getparam('email');
    if (!$name) {
        $errors[] = no_field("form.field.groupname");
    }
    if ($email != '' && !is_valid_email($email)) {
        $errors[] = wrong_field("form.field.mail");
    }
    $existing_group = group_by_name($name);
    if (!$groupid && $existing_group || $groupid && $existing_group && $groupid != $existing_group['groupid']) {
        $errors[] = getlocal("page.group.duplicate_name");
    }
    if (count($errors) == 0) {
        if (!$groupid) {
            $newdep = create_group($name, $description, $commonname, $commondescription, $email);
            header("Location: {$webimroot}/operator/groupmembers.php?gid=" . $newdep['groupid']);
            exit;
        } else {
            update_group($groupid, $name, $description, $commonname, $commondescription, $email);
            header("Location: {$webimroot}/operator/group.php?gid={$groupid}&stored");
            exit;
        }
    } else {
        $page['formname'] = topage($name);