We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36416
    • 589 Posts
    Quote from: Eol at Feb 05, 2008, 07:24 AM

    Does anyone have working "Manager2Web" synchronization plugin for 0.9.6?

    Ok, here are some modifications to the plugin:
    //<?php
    /**
     *  Manager2Web
     *  Synchronizes a web user account with a manager user accocunt
     *  Created by Raymond Irving May, 2005
     *  Modified to support MODx 0.9.6 by: Eol ([email protected]) 
     */
    
    function updateWebUser($mngr) {
    /**
     *  Updates an account
     */
     global $modx;
      $uid = $mngr['username'];
      // check for existing account
      $rs = $modx->dbQuery("SELECT * FROM ".$modx->getFullTableName("web_users")." WHERE username='$uid'");
      $count = $modx->recordCount($rs);
      $allowed = array("fullname","email","phone","mobilephone","blocked","blockeduntil","blockedafter",
                       "dob","gender","country","state","zip","fax","photo","comment");
      $fields = array();
      foreach($mngr as $key=>$value) {
        if (in_array($key, $allowed)) {
          $fields[$key] = $mngr[$key];
        }
      }
      if ($count > 0) {
        // update existing web account
        $modx->updIntTableRow($fields, "web_user_attributes", " internalKey='".$web['id']."'");
        $modx->updIntTableRow(array("password"=>$mngr["password"]), "web_users", " id='".$web["id"]."'");
        $action = "Updated";
      } else {
        // create new account
        $modx->putIntTableRow(array("username"=>$mngr["username"], "password"=>$mngr["password"]), "web_users");
        $fields["internalKey"] = mysql_insert_id();
        $modx->putIntTableRow($fields, "web_user_attributes");
        $action = "Created";
        //TODO -o Eol: send admin mail to new webuser
      }
      if (isset($action)) {
        return "$action webuser: [$uid]";
      } else {
        return false;
      }
    }//function updateWebUser
    
    $e = &$modx->Event;
    switch ($e->name) {
     case "OnUserFormSave":
      if ($_POST["Manager2Web"]) {
        $mgruserid = $e->params["id"];
        $sql = "SELECT mu.username,mu.password, ma.*
                FROM ".$modx->getFullTableName("manager_users")." mu
                INNER JOIN ".$modx->getFullTableName("user_attributes")." ma ON ma.internalKey = mu.id
                WHERE mu.id = '$mgruserid'";
        $rs = $modx->dbQuery($sql);
        if (!$rs) {
          $msg = "Error querying database ".mysql_error();
          $modx->logEvent(0, 3, $msg, $e->activePlugin);
        } else {
          $row = $modx->fetchRow($rs);
          // update account
          if ($msg = updateWebUser($row)) {
            if ($logging) $modx->logEvent(0, 1, $msg, $e->activePlugin);
          }
        }
      }
     break;
    
     case "OnUserFormRender":
      $html = "<div class=\"sectionHeader\">Manager2Web</div>
     <div class=\"sectionBody\">
      <input type=\"checkbox\" name=\"Manager2Web\" value=\"1\" checked=\"checked\" />
      Select this option to create/synchronize a web user account when saving.
     </div>";
      $e->output($html);
     break;
    }
    //?>
    


    Current version uses OnUserFormSave event instead of (disabled?) OnManagerSaveUser.
    Plugin configuration:
    &logging=Info Logging;int;0
      • 7231
      • 4,205 Posts
      What do these modifications provide? Or is this to make it 0.9.6 compatible?
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 36416
        • 589 Posts
        Quote from: dev_cw at Feb 06, 2008, 06:58 AM

        What do these modifications provide? Or is this to make it 0.9.6 compatible?

        Working in 0.9.6 + slightly better error/info logging.
          • 25663 MODX Staff
          • 12,272 Posts
          Thanks Eol, mind adding it as a new version to the Repository?
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 36416
            • 589 Posts
            Quote from: rthrash at Feb 06, 2008, 08:42 AM

            Thanks Eol, mind adding it as a new version to the Repository?

            Sure, if no one mind my free-spirited refactorings, embedding single language messages, and not testing in PHP4... wink

            And I need to know if it works as intended for others.
              • 19119
              • 22 Posts
              Hi, I tried to use what Eol did with Web2Manager, but it still doesn’t work.

              I used the button feedback on the website (if it’s useful).

              Does someone have a solution huh

              Thanks
                • 4172
                • 5,888 Posts
                seems to work great on 1.0.0, thanks!
                wishlist for this:
                atach webusers to webgroups with same managergroupnames.
                synchronise weblogin with managerlogin.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 38162
                  • 97 Posts
                  Update: Web2Manager 0.3.3
                  I found creating a Manager user from a Web user a more common task (at least for me), thus I added the functionality to this plugin. (ZIP file attached)

                  Recommendation
                  Tbh I originally disliked the fact that Manager and Web users are separated however, prefer it this way now. Thanks to this plugin, but also because I found it useful to have a clean overview of who is able to access the Manager. smiley
                  I recommend to let everyone sign up as web user then promote the ’managers’ using this plugin.

                  Changes
                  - Added a Web->Manager functionality. It finally lives up to its name now. wink
                  - Checkbox on Web user profiles is disabled by default (to safe admins from accidentally promoting members to Manager users).
                  - Fixed a few other issues and compatibility restrictions (e.g. editing didn’t work for me before, fixed now).
                  - Added a ReadMe file with description and installation guide

                  Test & Version
                  I made this on MODx Evolution 1.0.2 and tested all options and combinations systematically. If you face problems getting it to run, please add more infos than a "this doesn’t work for me" kind of reply. Any other feedback is appreciated as well. tongue

                  @Staff
                  You can replace the old version in the repository with this one (if you want), since it still shows the very first version which doesn’t even work on the current MODx release.

                  And...
                  Have FUN!
                    • 26931
                    • 2,314 Posts
                    hey N!Ce, thanks for sharing! smiley
                      • 38162
                      • 97 Posts
                      You’re welcome. smiley