We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25564
    • 17 Posts
    Hi all smiley

    Is it possible, while adding webuser (in backend) to automaticly generate a default page accessible only for this user (and of course manager)

    thx in advance
    rgds

    ps. sorry for my english i hope that u understand what i have on mind
      • 25663 MODX Staff
      • 12,272 Posts
      You would need to create a plugin that in turn creates the page and also creates the appropriate doc group, saving everything appropriately.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 25564
        • 17 Posts
        thx smiley

        i figured this out too and i’ll try to write it this evening

        wow modx is a nice piece of soft

        rgds
          • 22770
          • 285 Posts
          If you work out how to do this, post it here! I’d be really interested in how you do it.
            • 25564
            • 17 Posts
            oki

            so i wrote little plugin which generate a default private page for each new added user.
            (it creates unique doc group , web user group, set webgroup access and set home page for user)

            plugin need to be set up OnWebSaveUser event

            here is the source:
            (i know this code is ugly wink but i am not a pro php developer)

            //retrive last inserted webuser id
            $user_id=$modx->db->select("id","modx_web_users","", "id DESC","1");
            $last = mysql_fetch_assoc($user_id);
            $user_id=$last[id];
            
            //check if user is member of any group
            $is_member=$modx->db->select("id","modx_web_groups","webuser = $user_id", "","");
            $total_rows = $modx->db->getRecordCount( $is_member );
            
            //if not
            if($total_rows==0){
            //get last page id
            $id=$modx->db->select("id","modx_site_content","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $page_id=$last[id];
            $page_id++;
            
            //get last inserted document group name id
            $id=$modx->db->select("id","modx_documentgroup_names ","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $doc_name_id=$last[id];
            $doc_name_id++;
            
            //create unique doc group name
            $sql = "INSERT INTO modx_documentgroup_names VALUES($doc_name_id,'$doc_group$user_id',0,0)";
            $modx->db->query($sql);
            
            //get last inserted document group id
            $id=$modx->db->select("id","modx_document_groups","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $doc_group_id=$last[id];
            $doc_group_id++;
            
            //create unique doc group
            $sql = "INSERT INTO modx_document_groups VALUES($doc_group_id,$doc_name_id,$page_id) ";
            $modx->db->query($sql);
            
            //get last inserted web group name  id
            $id=$modx->db->select("id","modx_webgroup_names","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $web_group_name_id=$last[id];
            $web_group_name_id++;
            
            //create unique web group name
            $prefix="web_group_";
            $sql = "INSERT INTO modx_webgroup_names VALUES($web_group_name_id,'$prefix$user_id')";
            $modx->db->query($sql);
            
            //get last inserted web group access  id
            $id=$modx->db->select("id","modx_webgroup_access","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $web_group_access_id=$last[id];
            $web_group_access_id++;
            
            //add web group access for user
            $sql = "INSERT INTO modx_webgroup_access VALUES($web_group_access_id,$web_group_name_id,$doc_name_id) ";
            $modx->db->query($sql);
            
            //get last inserted web group id
            $id=$modx->db->select("id","modx_web_groups","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $web_group_id=$last[id];
            $web_group_id++;
            
            //add user to webgroup
            $sql = "INSERT INTO modx_web_groups VALUES($web_group_id,$web_group_name_id,$user_id) ";
            $modx->db->query($sql);
            
            //set homepage for user
            $sql = "INSERT INTO modx_web_user_settings VALUES($user_id,'login_home',$page_id) ";
            $modx->db->query($sql);
            
            
            //create page
            $sql ="INSERT INTO `modx_site_content` VALUES ($page_id, 'document', 'text/html', 'test', 'test', '', '', '', 1, 0, 0, 0, 0, 'test', '<p>test</p>', 1, 5, 6, 1, 1, 1, 1182963293, 1, 1182963829, 0, 0, 0, 1182963293, 1, '', 0, 0, 0, $doc_name_id, 0, 0, 0)";
            $modx->db->query($sql);
            
            
            
            }
            else{
            return 0;
            }
            


            for now it dont have a lot configuration but it will try to change it later
            plugin conf :
            &doc_group=doc group prefix;string;doc_group_


            in backend web users/docs group settings everything seems to work just fine,
            but
            issue#1 - when i am log in as a new created user - i can see link to private page (which is good) but i can not access this page, while i am trying to open private page - home page is displayed (but adress is pointing to private page :/ )

            any ideas how to solve it ??

            also i would like to close repeating code
            example :
            //get last inserted web group access  id
            $id=$modx->db->select("id","modx_webgroup_access","", "id DESC","1");
            $last = mysql_fetch_assoc($id);
            $web_group_access_id=$last[id];
            $web_group_access_id++;

            in to function() - i was trying to do thatt but whithout good results

            i will be greatfull for any help

            rgds
              • 25564
              • 17 Posts
              ok so this is actual source and it works except issue#1:
              when i am log in as a new created user - i can see link to private page (which is good) but i can not access this page, while i am trying to open private page - home page is displayed (but adress is pointing to private page :/ )


              //retrive last inserted webuser id
              $user_id=$modx->db->select("id","modx_web_users","", "id DESC","1");
              $last = mysql_fetch_assoc($user_id);
              $user_id=$last[id];
              
              //check if user is member of any group
              $is_member=$modx->db->select("id","modx_web_groups","webuser = $user_id", "","");
              $total_rows = $modx->db->getRecordCount( $is_member );
              
              //if not
              if($total_rows==0){
              
              
              //create unique doc group name
              $sql = "INSERT INTO modx_documentgroup_names VALUES (NULL,'$doc_group$user_id',0,0)";
              $modx->db->query($sql);
              $last_docgroup_name_id=$modx->db->getInsertId();
              
              //create page
              $sql ="INSERT INTO `modx_site_content` VALUES (NULL, 'document', 'text/html', 'test', 'test', '', '', '', 1, 0, 0, 0, 0, 'test', '<p>test</p>', 1, 5, 6, 1, 1, 1, 1182963293, 1, 1182963829, 0, 0, 0, 1182963293, 1, '', 0, 0, 0, 1, 0, 0, 0)";
              $modx->db->query($sql);
              $last_page_id=$modx->db->getInsertId();
              
              //create unique doc group 
              $sql = "INSERT INTO modx_document_groups  (document_group,document) VALUES($last_docgroup_name_id,$last_page_id) ";
              $modx->db->query($sql);
              $last_docgroup_id=$modx->db->getInsertId();
              
              //create unique web group name
              $prefix="web_group_";
              $sql = "INSERT INTO modx_webgroup_names VALUES(NULL,'$prefix$user_id')";
              $modx->db->query($sql);
              $last_webgroup_name_id=$modx->db->getInsertId();
              
              //add user to webgroup
              $sql = "INSERT INTO modx_web_groups VALUES(NULL,$last_webgroup_name_id,$user_id) ";
              $modx->db->query($sql);
              
              
              //add web group access to doc groups
              $sql = "INSERT INTO modx_webgroup_access VALUES(NULL,$last_webgroup_name_id,$last_docgroup_name_id) ";
              $modx->db->query($sql);
              
              
              
              //set homepage for user
              $sql = "INSERT INTO modx_web_user_settings VALUES($user_id,'login_home',$last_page_id) ";
              $modx->db->query($sql);
              
              }
              else{
              return 0;
              }
              



              i figured out that when i maualy (trough manager) resave just created doc (created by this plugin) everything works just fine and only database change is in table ’modx_document_groups` - ’id’ of added group is incrase by 1 ( i tried do this in plugin :$variable +2 , but it wasnt work )

              any ideas ??

              why i need to resave this page ?
                • 7455
                • 2,204 Posts
                its all about caching you need to clear cach for the new page take a look at the newspublisher at line 289 you will see this:

                 // empty cache
                if($clearcache==1){
                include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
                $sync = new synccache();
                $sync->setCachepath("assets/cache/");
                $sync->setReport(false);
                $sync->emptyCache(); // first empty the cache 
                


                try implementing this in your plugin and it wil work
                  follow me on twitter: @dimmy01
                  • 25564
                  • 17 Posts
                  yes u have right it is all about cache so

                  i’ve hardcoded $clearcache=1
                  and then put at the end this code

                  if($clearcache==1){
                  include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
                  $sync = new synccache();
                  $sync->setCachepath("assets/cache");
                  $sync->setReport(false);
                  $sync->emptyCache(); // first empty the cache 
                  }



                  and while saving user i recived this
                  Warning: opendir(assets/cache/) [function.opendir]: failed to open dir: No such file or directory in /manager/processors/cache_sync.class.processor.php on line 49
                  
                  Warning: fopen(assets/cache/siteCache.idx.php) [function.fopen]: failed to open stream: No such file or directory in /manager/processors/cache_sync.class.processor.php on line 199
                  Cannot open file (assets/cache/siteCache.idx.php)
                  


                  i’ve tryed to change cache file permision but that didnt help :/

                  i am keep looking...

                    • 4041
                    • 788 Posts
                    looks to me that the cache path is not correct since the snippet code you used and the plugin code are in different directories.

                    try this:
                    $sync->setCachepath($modx->config['base_path']."assets/cache");


                    if that doesnt work, look at the code for other plugins and see how they handle the same situation...
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 25564
                      • 17 Posts
                      EDIT: @breezer:yes excacly smiley


                      oki smiley

                      i found little different piece of code :
                      include_once($modx->config['base_path'] . "manager/processors/cache_sync.class.processor.php");
                      $sync = new synccache();
                      $sync->setCachepath($modx->config['base_path'] . "assets/cache/");
                      $sync->setReport(false);
                      $sync->emptyCache();
                      $modx->clearCache(); // double clear cache


                      and it works smiley !

                      @Dimmy thx for showing me direction smiley

                      so now i need to only find out how to refresh doc tree and add more conf options for customizing page

                      thx once again

                      any one knows how to refresh doc tree tongue