Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Just change
    $tableprefix = "wp_mus2";

    Thread Starter matfraysse

    (@matfraysse)

    Up please

    HERE WE ARE !
    I’ve build a script to fastly assign your users to groups !
    Copy the code in a .php file, and run it on your web server.

    Enjoy

    <?php
    // Script to fastly assign users to groups (after a cvs import for exemple) using UAM plugin
    // Script by Matthieu FRAYSSE //
    // WARNING : SAVE YOUR DATABASE BEFORE WORKING !
    // I rejected any responsibility or damage to your data !!!
    ////////////////////////////////////////////////////////////
    // Please configure the script here ! //
    ////////////////////////////////////////////////////////////
    $host = "www.yourdatabase.com"; // Your host
    $dbname = "BD_NAME"; // Name of the database
    $dbuser = "USER_NAME"; // User name
    $dbpassword = "PASSWORD"; // Password
    
    $tableprefix = "wp_mus2"; // If your database uses a prefix , write it here , otherwise do not write anything
    //////////////////////////////
    // END OF THE CONFIGURATION //
    //////////////////////////////
    ?>
    <?php // DB Connexion
    try
    {
        $bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', ''.$dbuser.'', ''.$dbpassword.'');
    }
    catch (Exception $e)
    {
            die('Erreur : ' . $e->getMessage());
    }
    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Group assing</title>
    </head>
    <body>
    <?php // Script to add user to a group if form set and display confirmation message
    if (isset($_POST['groupassign'])){
    	$UAMgroups = $bdd->query('SELECT * FROM <code>'.$tableprefix.'uam_accessgroups</code>');
    	$groups = $UAMgroups->fetch();
    
    	echo "<p>".$_POST['userdisplayname']." has been assign to group (".$_POST['groupassign'].")</p>";
    	$bdd->query("INSERT INTO ".$tableprefix."uam_accessgroup_to_object (<code>object_id</code>, <code>object_type</code>, <code>group_id</code>) VALUES ('".$_POST['userid']."', 'user', '".$_POST['groupassign']."')");
    }
    ?>
    <?php // Récupérationd des groupes UAM
    
    ?>
    <?php // Récupération des comptes
    $reponse = $bdd->query('SELECT * FROM <code>'.$tableprefix.'users</code>');
    ?>
    <table width="100%" height="52" border="1">
      <tbody>
        <tr>
          <td height="22" bgcolor="#CFFEFF">User name</td>
          <td bgcolor="#CFFEFF">User ID</td>
          <td bgcolor="#CFFEFF">Current user group(s)</td>
          <td bgcolor="#CFFEFF">Group selector</td>
        </tr>
        <?
    while ($donnees = $reponse->fetch())
    {
    	?>
        <tr>
          <td width="25%" height="22"><?php echo $donnees['display_name']; ?></td>
          <td width="25%"><?php echo $donnees['ID']; ?></td>
          <td width="25%"><? // Query to get the current user groups
    		   $usergroup = $bdd->query("SELECT * FROM ".$tableprefix."uam_accessgroup_to_object, ".$tableprefix."users, ".$tableprefix."uam_accessgroups WHERE ".$tableprefix."uam_accessgroup_to_object.object_id=".$tableprefix."users.ID AND ".$tableprefix."uam_accessgroups.ID=".$tableprefix."uam_accessgroup_to_object.group_id AND ".$tableprefix."users.ID='".$donnees['ID']."'");
    		while ($usergrouptest = $usergroup->fetch())
    		{
    			echo $usergrouptest['groupname']." ";
    		}
    		   ?></td>
          <td width="25%"><form action="script.php" method="post" name="form1" id="form1">
              <label for="groupassign">Group</label>
              <select name="groupassign" id="groupassign" title="groupselect">
                <option>Select a group</option>
                <?php
    $UAMgroups = $bdd->query('SELECT * FROM <code>'.$tableprefix.'uam_accessgroups</code>');
    while ($groups = $UAMgroups->fetch())
    {
    ?>
                <option value="<?php echo $groups['ID']; ?>"><?php echo $groups['groupname']; ?></option>
                <?php
    }
    ?>
              </select>
              <input type="submit" name="submit" id="submit" value="Assign">
              <input name="userid" type="hidden" id="userid" value="<?php echo $donnees['ID']; ?>">
              <input name="userdisplayname" type="hidden" id="userdisplayname" value="<?php echo $donnees['display_name']; ?>">
            </form></td>
        </tr>
        <?php
    
    }
    ?>
      </tbody>
    </table>
    </body>
    </html>

    Ok i founded !
    Autorisations are stored in uam_accessgroup_to_object in database.
    To add an autorisation to an user we must use a request like :
    INSERT INTOuam_accessgroup_to_object(object_id,object_type,group_id`) VALUES
    (’22’, ‘user’, 5);`

    object_id must correspond to the user id in the users table of your database
    group_id must correspond to id of a UAM group in uam_accessgroups table of your database

    I’ve got the same request !
    I use CSV Members Import and UAM.
    I’ve got 400 users to create, and to assign in groups !

    Please help us.

Viewing 5 replies - 1 through 5 (of 5 total)