1 amember - multiple subdomain moodles

Discussion in 'Troubleshooting' started by sabbok, May 26, 2008.

  1. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    Hi,

    I started a thread over in integration, many views but absolutely no responses so I'm going to try here to see if I get a different audience and hopefully a response as this is something I've read can be done, but no tutorials or write ups on the "how" part yet.

    Reference here:

    http://www.amember.com/forum/showthread.php?t=7852

    Anyone have any ideas?:confused: Really need some help on this, I'm not exactly a php guru so I'm kinda running outta steam on this quickly.
  2. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    Wow, no one from support with any ideas?
  3. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Hey Sabbok, I don't believe that Amember is set up to manage multiple instances in that way.

    My best guess on how to get it working the way you want is to copy the moodle plugin into multiple directories (moodle1, moodle2, etc) under plugins (modifying any plugin identifies in the code/config of the plugin) and configure them each. I've done in this in the past to get two instances of VBulletin going and it works quite well.
  4. calisolllc

    calisolllc Member

    Joined:
    Feb 19, 2007
    Messages:
    194
    Sabbok, this has nothing to dp with amember support, this is a community of users and owners of amember
  5. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    calisolllc

    Yeah, thanks. I'm aware that this is user driven, however, much like the business I work for, we do have senior support, who are encouraged from time to time to view the forums and offer opinions/suggestions/help as required, I was hoping these guys did the same in addition to other users (hence my statement of tickets and forum combinations for assistance)

    I have attempted to submit tickets on issues, but responses are slow (due to the long weekend I'm guessing) and I'm trying everything in desperation to work through a resolution.

    Thank you
  6. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    Hey Skippy,

    Yeah I did exactly that and was able to get quite far, but there seems to be a disconnect as soon as the second plugin gets enabled. And thanks for actually replying, I was begining to wonder if I was just talking to myself :)

    The error I get when doing that, even though it works, is this from the first plugin:

    WARNING: implode() [function.implode]: Invalid arguments passed in line 207 of file moodle.inc.php

    Which looks to be session issues based on this function:

    Code:
    function check_logged_in($get_session=0)
        {
    		global $db;
    		$moodle_settings = $this->moodle_get_settings();
    		$sessioncookie = $this->moodle_get_config('sessioncookie');
    		$session_cookiename = 'MoodleSession'.$sessioncookie;
    		$session_test_cookiename = 'MoodleSessionTest'.$sessioncookie;
    		
    		$session_cookie_value = $_COOKIE[$session_cookiename];
    		$session_test_cookie_value = $_COOKIE[$session_test_cookiename];
    		
    		if (!$session_cookie_value)
    			return array('', '');
    		
    		$dbsessions = $this->moodle_get_config('dbsessions');
    		
    		if ($dbsessions)
    			$session_data = urldecode($this->query_one("SELECT sessdata FROM [db]sessions2 WHERE sesskey = '".$db->escape($session_cookie_value)."'"));
    		else
    			[I]$session_data = implode('',@file($moodle_settings['dataroot']."/sessions/sess_".$session_cookie_value));[/I]
    
    		if (!$session_data)
    			return array('', '');
    		else
    			$session_exist = 1;
    			
    		$session_data = $this->moodle_parse_session_data($session_data);
    		
    		if ($get_session==1) return array($session_exist, $session_data);
    		
    		if (!$session_data['username'] || $session_data['id'] == 0)
    			return array('', '');
    		
    		$res = $db->query("SELECT * FROM {$db->config['prefix']}members WHERE login = '".$db->escape($session_data['username'])."'");
    		if (!$res)
    			return array('', '');
    		$member = mysql_fetch_assoc($res);
    		if (md5($member['pass']) == $session_data['password']) // password match
    			return array($member['login'], $member['pass']);
    		else
    			return array('', '');
    	}
    Now the silly part is I haven't been able to figure out a way to distinguish 1 moodle db from another moodle db so that the available courses (products) can be distinguished by the system so there isn't any confusion when linking back from the moodle portals to aMember...

    eh, work in progress I guess.
  7. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    HAHA got it

    Ok,

    Well went back over everything again after watching an episode of NCIS and got it.

    Attached is the file that is working for me right now, just do a search and replace on the tag "MYPORTAL" (without quotes). I recommend PSPad for this, its what I use and its nice enough not to mess with the code.

    :eek:!!!WARNING!!!:eek:
    Test this in a NON-PRODUCTION environment before putting live, I take no responsibility if you crash your own server due to lack of caution.

    What you'll want to do is create multiple plugin directories, for example:

    /public_html/amember/plugins/protect/moodle/
    /public_html/amember/plugins/protect/moodle1/
    /public_html/amember/plugins/protect/moodle2/

    (when doing the search and replace, ensure to use the directory name "moodle", "moodle1", "moodle2" as the name you are going to replace the MYPORTAL with)

    After this, follow the readme attached in the zip.

    In the prodcut page it'll show up as a seperate group of courses you can assign users to. Good times had by all.


    So after everyting, what did this accomplish?

    This will allow you to have 1 amember main control multiple moodle subdomains while keeping everything seperate from each other. In my case, it allows me to have multiple custom portals for seperate customers (competing customers) while allowing them all to use the same products.

    (btw just a hack, no custom code in the files)



    ***************************************************************

    Update, actually the rconfig goes crazy after subscription is made....

    suck...

    back to the drawing board.
  8. jimjwright

    jimjwright New Member

    Joined:
    Sep 12, 2007
    Messages:
    162
    Hello,

    Just curious all configured plugins are called by amember on user signup with function check_uniq_login(). If I understand correctly you have configured multiple plugins to different instances of moodle with a different database. So does this mean when someone signs up thru Amember that the username has to be unique across all of your moodle instances/databases. If not I guess I don't get it.

    In addition amember calls all plugins with function xxxx_added() when a subscription is added. One of the parameters to this function is product_id. Most plugins I have seen ignore this parameter. This is where you would demultiplex a product to a particular database if you needed to. I would think when a subscription was added and moodle plugin was ignoring this parameter that the user would be added to all of your moodle databases and not to a particular one. If not I guess I really don't get it.

    Without knowing what your trying to do and whether membership needs to be unique across all instances then I guess I'm just conjecturing. I guess I'm more curious than anything because the plugin architecture I would think would need to be reworked if you really wanted to limit membership to a particular instance of a plugin because not all defined plugin callouts pass the product id.

    Jimmy
  9. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    Hi Jim,

    No the membership doesn't need to be unique across all DB's, but product isolation between all portals needs to be there. For example:

    My aMember site (http://mysite.com/amember) will be the signup, registration, and product manager for my subdomains:

    http://sub1.mysite.com/
    http://sub2.mysite.com/

    All of which are moodle site. All sites have the exact same courses, but the pricing will be different on each site. Amember will control all aspects of the course from enrollment to expirations and removal of accounts in moodle.

    So ultimately this is my grand idea. I hope it makes sense, cause I'm having a hard time thinking of a different way to put it :(

    I guess my only alternative then is to just use the "moodle network" option, link all of my DB's together, and hope for the best.
  10. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    suck

    So after getting everything setup, register a test user, click to activate/confirm account with first attempt to login and we get:

    Code:
    WARNING: Invalid argument supplied for foreach() in line 296 of file moodle.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 272 of file moodle.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 273 of file moodle.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 274 of file moodle.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 275 of file moodle.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 276 of file moodle.inc.php
    WARNING: Invalid argument supplied for foreach() in line 296 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 272 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 273 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 274 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 275 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 276 of file moodle_MYPORTAL.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 39 of file new_rewrite.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /home/kendrikl/public_html/amember/rconfig.inc.php(16) : eval()'d code:328) in line 227 of file check.inc.php
    grrrrr :mad:
  11. jimjwright

    jimjwright New Member

    Joined:
    Sep 12, 2007
    Messages:
    162
    Hello,

    I guess my question is how are you associating a particular "product/subscription/course" defined in Amember products to a particular moodle site. Did you "add_product_field" in plugin to do the association? If you did this then you could associate a particular product to a particular site/database when configuring the product in the admin/product section of amember. If you didn't and the moodle plugin does not already do this then again I don't get it. Its not to say that I'm right, I've been wrong many times, it just means that I really don't get it. I also do not have the moodle plugin to reference so I am flying blind to how it is implemented. I'm really more interested in how you tie the product to a particular instance of moodle. I would think just replicating the plugin would not be enough that you would have to add some more code to plugin to do this.

    Jimmy
  12. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Perhaps it is the series of CSI you are watching?

    Have you considered NY CSI versus Flordia CSI?

    Just a thought ;-)
  13. jimjwright

    jimjwright New Member

    Joined:
    Sep 12, 2007
    Messages:
    162
    Hello,

    Ignore my previous comments. I saw that moodle plug-in was free to download. I downloaded and looked at code and it looks like it should work.

    I do believe the user will be added to all of your databases, independent of whether there are courses to be configured for that subdomain or not. I guess that is not a big deal.

    You might have some issues if you specify an empty course list for a subdomain instance. Hopefully the code can handle it.

    Anyway good luck your plan of attack should work.

    Jimmy
  14. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    NP Jim, thanks for at least checking it out...

    I haven't tried a blank course list (all my portals are setup right now), but it seems the issue has now migrated to rconfig.inc.php (encoded by ioncube) and 2 other files I haven't located yet. Hopefully the support guys will get around to looking at my ticket soon and at least tell my what's up regarding the rconfig errors.

    Think I'll start working on setting up the moodle backend user auth (moodle network) and drop this idea.
  15. sabbok

    sabbok New Member

    Joined:
    Apr 29, 2008
    Messages:
    33
    I have a fix for this that I will post shortly from Alex (thanks again alex you rock)

    I just want to test it out and ensure its working before I post it up.

Share This Page