/** * Add user groups to the groups table, randomly assign them existing tokens. * @param integer $num number of groups to add, or configured value if null. */ private function populate_groups_add($num = null) { if (!isset($num)) { $num = Options::get('populate__groups'); } // Get all tokens that we have created. $tokens = $this->populate_tokens_get(); // Add all these groups. $count = 0; while ($count++ < $num) { // Create a new group. $group = Usergroup::create(array('name' => 'populate_' . $this->helper_random_name())); // assign tokens to this new group. $max_tokens = count($tokens) - 1; $num_tokens = rand(0, $max_tokens); while ($num_tokens-- > 0) { $token = rand(0, $max_tokens); ACL::grant_group($group->id, $tokens[$token]->id); } } return; }
$message=""; if (! $_POST["nom"]) { $message='<div class="error">'.$langs->trans("NameNotDefined").'</div>'; $action="create"; // Go back to create page } if (! $message) { $object->nom = trim($_POST["nom"]); $object->globalgroup = $_POST["globalgroup"]; $object->note = trim($_POST["note"]); $db->begin(); $id = $object->create(); if ($id > 0) { $db->commit(); Header("Location: fiche.php?id=".$object->id); exit; } else { $db->rollback(); $langs->load("errors"); $message='<div class="error">'.$langs->trans("ErrorGroupAlreadyExists",$object->nom).'</div>'; $action="create"; // Go back to create page