Example #1
0
 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $user->set('usertype', $newUsertype);
     $system = 2;
     // ID of Registered
     $user->groups = array();
     $user->groups[] = $system;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         return false;
     }
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info);
 }
Example #2
0
 protected function addToolbar()
 {
     JToolbarHelper::title(JText::_('COM_JOOMDLE_VIEW_MAPPINGS_TITLE'), 'mapping');
     JToolbarHelper::addNew('mapping.add');
     JToolbarHelper::deleteList('', 'mappings.delete');
     JHtmlSidebar::setAction('index.php?option=com_joomdle&view=mappings');
     JHtmlSidebar::addFilter(JText::_('COM_JOOMDLE_JOOMLA_COMPONENT'), 'filter_state', JHtml::_('select.options', JoomdleHelperMappings::getStateOptions(), 'value', 'text', $this->state->get('filter.state')));
 }
Example #3
0
 /**
  * Method to get the field options.
  *
  * @return	array	The field option objects.
  * @since	1.6
  */
 protected function getOptions()
 {
     $options = array();
     $params = JComponentHelper::getParams('com_joomdle');
     $app = $params->get('additional_data_source');
     $joomla_fields = JoomdleHelperMappings::get_fields($app);
     if (is_array($joomla_fields)) {
         foreach ($joomla_fields as $field) {
             $option['value'] = $field->id;
             $option['text'] = JText::_($field->name);
             $options[] = $option;
         }
     }
     return $options;
 }
Example #4
0
 /**
  * Method to get the field options.
  *
  * @return	array	The field option objects.
  * @since	1.6
  */
 protected function getOptions()
 {
     $options = array();
     $fields = array('firstname', 'lastname', 'email', 'icq', 'skype', 'yahoo', 'aim', 'msn', 'phone1', 'phone2', 'institution', 'department', 'address', 'city', 'country', 'lang', 'timezone', 'idnumber', 'description');
     foreach ($fields as $field) {
         $option['value'] = $field;
         $option['text'] = $field;
         $options[] = $option;
     }
     $moodle_custom_fields = JoomdleHelperMappings::get_moodle_fields();
     foreach ($moodle_custom_fields as $mf) {
         $option['value'] = "cf_" . $mf['id'];
         $option['text'] = $mf['name'];
         $options[] = $option;
     }
     return $options;
 }
Example #5
0
 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 2;
     }
     // Password comes hashed
     // On bind, Joomla hashes it again, so we save it before
     $password = $user_info['password'];
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Manually set original hashed password
     $user->password = $password;
     // Set some initial user values
     $user->set('id', 0);
     $user->groups = array();
     $user->groups[] = $newUsertype;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         JError::raiseError(500, $user->getError());
         return false;
     }
     // Set password in crypted form
     //		$u = new JObject ();
     //		$u->id = $user->id;
     //		$u->password = $password;
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info, false);
 }
Example #6
0
 function display($tpl = null)
 {
     global $mainframe;
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $this->assignRef('params', $params);
     $username = JRequest::getVar('username');
     if (!$username) {
         $username = $params->get('username');
     }
     if (!$username) {
         echo JText::_('COM_JOOMDLE_NO_USER_SELECTED');
         return;
     }
     $this->courses = JoomdleHelperContent::call_method('teacher_courses', $username);
     $this->username = $username;
     $this->user_info = JoomdleHelperMappings::get_user_info_for_joomla($this->username);
     $document = JFactory::getDocument();
     $document->setTitle($this->user_info['name']);
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     parent::display($tpl);
 }
Example #7
0
 /**
  * Gets the list of users
  *
  * @return	mixed	An array of data items on success, false on failure.
  * @since	1.6
  */
 public function getItems()
 {
     $db = JFactory::getDBO();
     $search = $this->getState('filter.search');
     if ($search) {
         $searchEscaped = $db->Quote('%' . $db->escape($search, true) . '%', false);
     } else {
         $searchEscaped = "";
     }
     $pagination = $this->getPagination();
     $limitstart = $pagination->limitstart;
     $limit = $pagination->limit;
     $listOrder = $this->state->get('list.ordering');
     $listDirn = $this->state->get('list.direction');
     $filter_order = $listOrder;
     $filter_order_Dir = $listDirn;
     $filter_type = $this->getState('filter.state');
     $mappings = JoomdleHelperMappings::getMappings($filter_type, $limitstart, $limit, $filter_order, $filter_order_Dir, $searchEscaped);
     return $mappings;
 }
Example #8
0
 static function save_user_info_joomla16($user_info, $use_utf8_decode = true)
 {
     $db = JFactory::getDBO();
     $username = $user_info['username'];
     $id = JUserHelper::getUserId($username);
     $user = JFactory::getUser($id);
     $mappings = JoomdleHelperMappings::get_app_mappings('joomla16');
     foreach ($mappings as $mapping) {
         $additional_info[$mapping->joomla_field] = $user_info[$mapping->moodle_field];
         //			$user_info[$mapping->moodle_field] = json_encode ($user_info[$mapping->moodle_field]);
         if (strncmp($mapping->moodle_field, 'cf_', 3) == 0) {
             $data = JoomdleHelperMappings::get_moodle_custom_field_value($user_info, $mapping->moodle_field);
             JoomdleHelperMappings::set_field_value_joomla16($mapping->joomla_field, $data, $id);
         } else {
             if ($use_utf8_decode) {
                 // Removed when Joomla started using json encoded values in profile table
                 JoomdleHelperMappings::set_field_value_joomla16($mapping->joomla_field, utf8_decode($user_info[$mapping->moodle_field]), $id);
             } else {
                 JoomdleHelperMappings::set_field_value_joomla16($mapping->joomla_field, $user_info[$mapping->moodle_field], $id);
             }
         }
     }
     return $additional_info;
 }
Example #9
0
    <?php 
if ($this->params->get('show_page_heading', 1)) {
    ?>
    <h1>
    <?php 
    echo $this->escape($this->params->get('page_heading'));
    ?>
    </h1>
    <?php 
}
?>

<?php 
if (is_array($this->teachers)) {
    foreach ($this->teachers as $teacher) {
        $user_info = JoomdleHelperMappings::get_user_info_for_joomla($teacher['username']);
        if (!count($user_info)) {
            //not a Joomla user
            continue;
        }
        ?>
        <div class="joomdle_user_list_item">
            <div class="joomdle_user_list_item_pic">
			<?php 
        // Use thumbs if available
        if (array_key_exists('thumb_url', $user_info) && $user_info['thumb_url'] != '') {
            $user_info['pic_url'] = $user_info['thumb_url'];
        }
        ?>
                <a href="<?php 
        echo JRoute::_("index.php?option=com_joomdle&view=teacher&username="******"&Itemid={$itemid}");
Example #10
0
 static function sync_joomla_profiles($user_ids)
 {
     foreach ($user_ids as $id) {
         /* If user not already in Joomla, warn user and continue to next item */
         if ($id < 0) {
             JError::raiseWarning(500, JText::_('COM_JOOMDLE_USER_ID_DOES_NOT_EXIT_IN_JOOMLA') . ": " . $id);
             continue;
         }
         $user = JFactory::getUser($id);
         /* If user not already in Moodle, warn user and continue to next item */
         if (!JoomdleHelperContent::call_method('user_exists', $user->username)) {
             JError::raiseWarning(500, JText::_('CJ_USER_ID_DOES_NOT_EXIT_IN_MOODLE') . ": " . $user->username);
             continue;
         }
         JoomdleHelperMappings::sync_user_to_joomla($user->username);
     }
 }
Example #11
0
		<tfoot>
                        <tr>
                                <td colspan="10">
                                        <?php 
echo $this->pagination->getListFooter();
?>
                                </td>
                        </tr>
                </tfoot>
             <tbody>
                    <?php 
$k = 0;
$i = 0;
foreach ($this->items as $row) {
    $checked = JHTML::_('grid.id', $i, $row->id);
    $profile_url = JoomdleHelperMappings::get_profile_url($row->username);
    $app_id = $row->id;
    ?>
                           <tr class="<?php 
    echo "row{$k}";
    ?>
">
                                  <td><?php 
    echo $row->id;
    ?>
</td>
                                  <td><?php 
    echo $checked;
    ?>
</td>
                                  <td><a target="_blank" href="<?php 
Example #12
0
                                <td colspan="10">
                                        <?php 
echo $this->pagination->getListFooter();
?>
                                </td>
                        </tr>
                </tfoot>
             <tbody>
                    <?php 
$k = 0;
$i = 0;
foreach ($this->users as $row) {
    $checked = JHTML::_('grid.id', $i, $row['id']);
    //$j_account      = JHTML::_('grid.published', $row, $i );
    //					   $row['name'] = $row['firstname'] . " " . $row['lastname'];
    $profile_url = JoomdleHelperMappings::get_profile_url($row['username']);
    $app_id = $row['id'];
    ?>
                           <tr class="<?php 
    echo "row{$k}";
    ?>
">
                                  <td><?php 
    echo $row['id'];
    ?>
</td>
                                  <td><?php 
    echo $checked;
    ?>
</td>
                                  <td><a target="_blank" href="<?php 
Example #13
0
 function unenrol()
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $course_id = JRequest::getVar('course_id');
     $course_id = (int) $course_id;
     $login_url = JoomdleHelperMappings::get_login_url($course_id);
     if (!$user->id) {
         $mainframe->redirect($login_url);
     }
     $params = $mainframe->getParams();
     $user = JFactory::getUser();
     $username = $user->username;
     JoomdleHelperContent::call_method('unenrol_user', $username, $course_id);
     // Redirect to caller URI
     $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
     $mainframe->redirect($url);
 }
Example #14
0
echo $this->pageclass_sfx;
?>
">
    <h1>
        <?php 
echo $this->course_info['fullname'] . ': ';
?>
        <?php 
echo JText::_('COM_JOOMDLE_STUDENTS');
?>
    </h1>

<?php 
if (is_array($this->users)) {
    foreach ($this->users as $id => $student) {
        $user_info = JoomdleHelperMappings::get_user_info_for_joomla($student['username']);
        if (!count($user_info)) {
            //not a Joomla user
            continue;
        }
        ?>
    <div class="joomdle_user_list_item">
        <div class="joomdle_user_list_item_pic">
		<?php 
        // Use thumbs if available
        if (array_key_exists('thumb_url', $user_info) && $user_info['thumb_url'] != '') {
            $user_info['pic_url'] = $user_info['thumb_url'];
        }
        ?>
		<?php 
        if (array_key_exists('profile_url', $user_info) && $user_info['profile_url']) {
Example #15
0
	function applicate () {

		$mainframe = JFactory::getApplication();

		$params =$mainframe->getParams();
		$show_motivation = $params->get( 'show_detail_application_motivation', 'no' );
		$show_experience = $params->get( 'show_detail_application_experience', 'no' );

		$user = JFactory::getUser();

		$course_id = JRequest::getVar( 'course_id' );
		$course_id = (int) $course_id;

		$login_url = JoomdleHelperMappings::get_login_url ($course_id);
		if (!$user->id)
			$mainframe->redirect($login_url);
		//	$mainframe->redirect(JURI::base ().'index.php?option=com_user&view=login');

		$motivation = JRequest::getVar( 'motivation' );
		$experience = JRequest::getVar( 'experience' );

		$message = '';
		if (($show_motivation == 'mandatory') && (!$motivation))
		{
			$url = JRoute::_ ("index.php?option=com_joomdle&view=detail&course_id=$course_id");
			$message = JText::_( 'COM_JOOMDLE_MOTIVATION_MISSING' );
			$this->setRedirect($url, $message);
			return;
		}
		if (($show_experience == 'mandatory') && (!$experience))
		{
			$url = JRoute::_ ("index.php?option=com_joomdle&view=detail&course_id=$course_id");
			$message = JText::_( 'COM_JOOMDLE_EXPERIENCE_MISSING' );
			$this->setRedirect($url, $message);
			return;
		}

		$user = JFactory::getUser();
		$username = $user->get('username');

		$message = JText::_( 'COM_JOOMDLE_MAX_APPLICATIONS_REACHED' );
		if (!JoomdleHelperApplications::user_can_applicate ($user->id, $course_id, $message))
        {
            $url = JRoute::_ ("index.php?option=com_joomdle&view=detail&course_id=$course_id");
            $this->setRedirect($url, $message);
            return;
        }


		if (JoomdleHelperApplications::applicate_for_course ($username, $course_id, $motivation, $experience))
		{
			// Redirect to course detail page by default
			$url = JRoute::_ ("index.php?option=com_joomdle&view=detail&course_id=$course_id");
			$message = JText::_( 'COM_JOOMDLE_APPLICATION_FOR_COURSE_DONE' );

			// Get custom redirect url and message
			$additional_message = '';
			$new_url = '';
			$app                = JFactory::getApplication();
			$results = $app->triggerEvent('onCourseApplicationDone', array($course_id, $user->id, &$additional_message, &$new_url));

			if ($additional_message)
				$message .= '<br>' . $additional_message;
			if ($new_url)
				$url = $new_url;
		}
		else {
			$url = JRoute::_ ("index.php?option=com_joomdle&view=detail&course_id=$course_id");
			$message = JText::_( 'COM_JOOMDLE_APPLICATION_FOR_COURSE_ALREADY_DONE' );
		}



		//$mainframe->redirect ($url);
		$this->setRedirect($url, $message);
	}
Example #16
0
 static function set_field_value_hikashop($field, $value, $user_id)
 {
     $db = JFactory::getDBO();
     switch ($field) {
         case 'address_country':
             $value = JoomdleHelperMappings::get_hikashop_country_from_moodle($value);
             break;
         default:
             break;
     }
     $db = JFactory::getDBO();
     $query = "SELECT user_id " . ' FROM #__hikashop_user' . " WHERE  user_cms_id = " . $db->Quote($user_id);
     $db->setQuery($query);
     $hikashop_user_id = $db->loadResult();
     $query = ' UPDATE #__hikashop_address' . ' SET ' . $field . '=' . $db->Quote($value) . " WHERE address_user_id = " . $db->Quote($hikashop_user_id);
     $db->setQuery($query);
     $db->query();
     return true;
 }
Example #17
0
    function updateUser ($method, $params)
    {
		$user_info = $params[0];
        return JoomdleHelperMappings::save_user_info ($user_info, false);
    }