Esempio n. 1
0
$op = operator_by_id($opId);
if (!$op) {
    $errors[] = getlocal("no_such_operator");
} else {
    if (isset($_POST['op'])) {
        if (!$canmodify) {
            $errors[] = getlocal('page_agent.cannot_modify');
        }
        if (count($errors) == 0) {
            $new_groups = array();
            foreach ($page['groups'] as $group) {
                if (verifyparam("group" . $group['groupid'], "/^on\$/", "") == "on") {
                    $new_groups[] = $group['groupid'];
                }
            }
            update_operator_groups($op['operatorid'], $new_groups);
            header("Location: {$webimroot}/operator/opgroups.php?op={$opId}&stored");
            exit;
        }
    }
}
$page['formgroup'] = array();
$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : "-not found-";
$page['canmodify'] = $canmodify ? "1" : "";
if ($op) {
    foreach (get_operator_groupids($opId) as $rel) {
        $page['formgroup'][] = $rel['groupid'];
    }
}
$page['stored'] = isset($_GET['stored']);
prepare_menu($operator);
Esempio n. 2
0
 /**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\Operator\GroupsController::showFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  * @throws NotFoundException If the operator with specified ID is not found
  *   in the system.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $operator = $this->getOperator();
     $operator_in_isolation = in_isolation($operator);
     $op_id = $request->attributes->getInt('operator_id');
     // Check if the target operator exists
     $op = operator_by_id($op_id);
     if (!$op) {
         throw new NotFoundException('The operator is not found.');
     }
     // Get all groups that are available for the target operator.
     $groups = $operator_in_isolation ? get_groups_for_operator($operator) : get_all_groups();
     // Build list of operator's new groups.
     $new_groups = array();
     foreach ($groups as $group) {
         if ($request->request->get('group' . $group['groupid']) == 'on') {
             $new_groups[] = $group['groupid'];
         }
     }
     // Update operator's group and redirect the current operator to the same
     // page using GET method.
     update_operator_groups($op['operatorid'], $new_groups);
     $redirect_to = $this->generateUrl('operator_groups', array('operator_id' => $op_id, 'stored' => true));
     return $this->redirect($redirect_to);
 }