title: get user enroll day and enrolled period of a given course with given user id
body: <p>I  working on send email when user manually enrolled to course.,by now i can send a email when user enroll to the system what i want to know is send enrollment expire date with the email,so  if i can get from database that will work for me..,(any other method which can get this insie enroll unction also fine) </p>
  
  <p>this is where i try to pass this parameters</p>
  
  <pre><code> public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timestart = 0, $timeend = 0, $status = NULL, $recovergrades = NULL) {
      global $DB;
  
      $alreadyenroled = $DB-&gt;record_exists('user_enrolments', array('enrolid' =&gt; $instance-&gt;id, 'userid' =&gt; $userid));
      parent::enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
      if (!$alreadyenroled &amp;&amp; $instance-&gt;customint4) {
          // Don't email immediately - give the admin a chance to remove users
          // who were added by mistake
          $this-&gt;queue_welcome_message($instance-&gt;id, $userid,$timestart,$timeend);
      }
  }
  
   protected function queue_welcome_message($instanceid, $userid,$timestart,$timeend) {
      global $DB;
  
      if ($DB-&gt;record_exists('enrol_manual_email', array('instanceid' =&gt; $instanceid,
                                                         'userid' =&gt; $userid,'ts' =&gt; $timestart,'te' =&gt; $timeend))) {
          return;
      }
  
      $ins = new stdClass();
      $ins-&gt;instanceid = $instanceid;
      $ins-&gt;userid = $userid;
      ////edit lasitha
      $ins-&gt;ts = $timestart;
      $ins-&gt;te = $timeend;
      $DB-&gt;insert_record('enrol_manual_email', $ins);
  }
  </code></pre>