function onGroupJoin(&$group, $memberid)
 {
     // Get sync mappings
     $mappings = self::getJomSocialGroupSyncMappings();
     if (empty($mappings)) {
         return;
     }
     // Instantiate JomSocial
     require_once JPATH_ROOT . '/' . 'administrator/components/com_community/defines.php';
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php';
     jimport('joomla.user.helper');
     $model = CFactory::getModel('Groups');
     foreach ($mappings as $mapping) {
         if ($model->isMember($member, $mapping['jsgroup_id'])) {
             // Add user to jgroup members table
             JUserHelper::addUserToGroup($userid, $mapping['jgroup_id']);
         } else {
             JUserHelper::removeUserFromGroup($userid, $mapping['jgroup_id']);
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Testing removeUserFromGroup().
  *
  * @param   string   $userId    User id
  * @param   integer  $groupId   Group to remove user from
  * @param   boolean  $expected  Expected params
  *
  * @dataProvider casesRemoveUserFromGroup
  * @covers  JUserHelper::removeUserFromGroup
  * @return  void
  */
 public function testRemoveUserFromGroup($userId, $groupId, $expected)
 {
     $this->markTestSkipped('Unexpected test failure in CMS environment');
     $this->assertThat(JUserHelper::removeUserFromGroup($userId, $groupId), $this->equalTo($expected));
 }
	/**
	 * Testing removeUserFromGroup().
	 *
	 * @param   string   $userId    User id
	 * @param   integer  $groupId   Group to remove user from
	 * @param   boolean  $expected  Expected params
	 *
	 * @dataProvider casesRemoveUserFromGroup
	 * @covers  JUserHelper::removeUserFromGroup
	 * @return  void
	 */
	public function testRemoveUserFromGroup($userId, $groupId, $expected)
	{
		$this->assertThat(
			JUserHelper::removeUserFromGroup($userId, $groupId),
			$this->equalTo($expected)
		);
	}
Ejemplo n.º 4
0
 /**
  * Helper wrapper method for removeUserFromGroup
  *
  * @param   integer  $userId   The id of the user.
  * @param   integer  $groupId  The id of the group.
  *
  * @return  boolean  True on success
  *
  * @see     JUserHelper::removeUserFromGroup()
  * @since   3.4
  */
 public function removeUserFromGroup($userId, $groupId)
 {
     return JUserHelper::removeUserFromGroup($userId, $groupId);
 }
Ejemplo n.º 5
0
 /**
  * Testing removeUserFromGroup().
  *
  * @param   string   $userId    User id
  * @param   integer  $groupId   Group to remove user from
  * @param   boolean  $expected  Expected params
  *
  * @dataProvider casesRemoveUserFromGroup
  * @covers  JUserHelper::removeUserFromGroup
  * @return  void
  */
 public function testRemoveUserFromGroup($userId, $groupId, $expected)
 {
     $this->assertEquals($expected, JUserHelper::removeUserFromGroup($userId, $groupId));
 }
Ejemplo n.º 6
0
 public function save($data)
 {
     $pk = !empty($data['user_id']) ? $data['user_id'] : 0;
     $user = JUser::getInstance($pk);
     $my = JFactory::getUser();
     $db = $this->getDbo();
     $params = JComponentHelper::getParams('com_bt_socialconnect');
     //load plugin assigment
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('btsocialconnect');
     if ($params->get('remove_user') && $user->id == 0) {
         $data['username'] = $data['email'];
     }
     //If "name" was removed
     if (!isset($data["name"])) {
         $data['name'] = $data['user_fields']['first_name'] . ' ' . $data['user_fields']['last_name'];
     }
     //Check groups of user when save
     if (!empty($data['groups'])) {
         $iAmSuperAdmin = $my->authorise('core.admin');
         if ($iAmSuperAdmin && $my->get('id') == $pk) {
             $stillSuperAdmin = false;
             $myNewGroups = $data['groups'];
             foreach ($myNewGroups as $group) {
                 $stillSuperAdmin = $stillSuperAdmin ? $stillSuperAdmin : JAccess::checkGroup($group, 'core.admin');
             }
             if (!$stillSuperAdmin) {
                 $this->setError(JText::_('COM_BT_SOCIALCONNECT_ERROR_CANNOT_DEMOTE_SELF'));
                 return false;
             }
         }
     }
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError($user->getError());
         return false;
     }
     //Get value user field
     $user_fields = $data['user_fields'];
     if ($user->save()) {
         // Add group for user from usergroup field
         $group = $this->getUserGroupField();
         if ($group) {
             // removed all group defined in usergroup field
             $newGroup = $data['user_fields'][$group->alias];
             if (in_array($newGroup, $group->default_values['group'])) {
                 $oldGroup = array_diff($group->default_values['group'], array($newGroup));
                 // add group which user has selected
                 JUserHelper::addUserToGroup($user->id, $newGroup);
                 foreach ($oldGroup as $gr) {
                     JUserHelper::removeUserFromGroup($user->id, $gr);
                 }
             }
         }
         $this->setState('socialconnect.id', $user->id);
         $this->prepareFolders($this->saveDir);
         $this->prepareFolders($this->images_path);
         $path_image_avartar = $this->images_path;
         $data['user_id'] = $user->id;
         $data['params'] = $user->params;
         $IdUserOld = self::GetUserids();
         $IdOld = self::findIdOld($data['user_id'], $IdUserOld);
         $Oldata = self::getOldata($user->id);
         //Upload image
         if (isset($_FILES["user_fields"]["tmp_name"]) && !empty($_FILES["user_fields"]["tmp_name"])) {
             $source = $_FILES["user_fields"]["tmp_name"];
             foreach ($source as $key => $imgSource) {
                 if (!empty($imgSource)) {
                     $info = getimagesize($imgSource);
                     $imageExt = str_replace('image/', '', $info['mime']);
                     $imageName = md5($data['user_id'] . strtotime("now")) . '_(' . $data['username'] . '_' . $key . ')_' . '.' . $imageExt;
                     if (!empty($imgSource)) {
                         if (JFile::copy($imgSource, $path_image_avartar . $imageName)) {
                             foreach ($Oldata as $img) {
                                 @unlink(JPATH_SITE . '/images/bt_socialconnect/avatar/' . $img->{$key});
                             }
                             $user_fields[$key] = $imageName;
                         } else {
                             return false;
                         }
                     }
                 }
             }
         }
         //Conver string to save
         $keys = array_keys($user_fields);
         $values = array_values($user_fields);
         $value = array();
         foreach ($values as $key => $field) {
             if (is_array($field)) {
                 $field = implode(',', $field);
             }
             if (empty($field)) {
                 $field = '';
             }
             $value[] = '\'' . $db->escape($field) . '\'';
         }
         // End
         //Check user is new or no
         if ($IdOld >= 0) {
             $data['updated_time'] = JFactory::getDate()->toSql();
             $update = '';
             foreach ($keys as $i => &$key) {
                 $key = $db->escape($key);
                 $update .= $key . '=' . $value[$i] . ($i < count($keys) - 1 ? ',' : '');
             }
             //Update Bt_users
             $query = 'UPDATE  #__bt_users SET ' . $update . ' WHERE  user_id =' . (int) $data['user_id'];
             $db->setQuery($query);
             $result = $db->query();
             //Update Bt_connection
             if (isset($data['enabled_publishing']) && is_array($data['enabled_publishing'])) {
                 foreach ($data['enabled_publishing'] as $key => $value) {
                     $query = 'UPDATE  #__bt_connections  SET  enabled_publishing =\'' . $value . '\',updated_time =\'' . $data['updated_time'] . '\' WHERE user_id =\'' . $data['user_id'] . '\' AND social_type =\'' . $key . '\'';
                     $db->setQuery($query);
                     $db->query();
                 }
             }
         } else {
             if (!empty($keys)) {
                 $key = ',' . implode(',', $keys);
             } else {
                 $key = '';
             }
             if (!empty($value)) {
                 $value = ',' . implode(',', $value);
             } else {
                 $value = '';
             }
             //INSERT INTO  #__bt_users(user_id,profile_link,birthday,avatar) values(1,'http://','')
             $query = 'INSERT INTO  #__bt_users(user_id' . $key . ') VALUES(\'' . $data['user_id'] . '\'' . $value . ')';
             $db->setQuery($query);
             $db->query();
             // Check user is social connect network or register nomal
             if (isset($data['socialId']) && $data['socialId'] != '') {
                 if (!self::checkSocialID($data['socialId'], $data['loginType'], $data['user_id'])) {
                     $data['created_time'] = JFactory::getDate()->toSql();
                     $data['updated_time'] = '';
                     $query = 'INSERT INTO  #__bt_connections VALUES(\'' . '' . '\',\'' . $data['user_id'] . '\',\'' . $data['socialId'] . '\', \'' . $data['loginType'] . '\',\'' . $data['access_token'] . '\',\'' . $data['params'] . '\',\'' . $data['enabled_publishing'] . '\', \'' . $data['created_time'] . '\', \'' . $data['updated_time'] . '\')';
                     $db->setQuery($query);
                     $db->query();
                     //Auto login if user is social network connect
                     self::loginSocial($data['email']);
                 }
             } else {
                 //Check config auto login when save
                 if ($params->get('userautologin', 1) == '1') {
                     $app = JFactory::getApplication();
                     if (!$app->isAdmin()) {
                         self::loginSocial($data['email']);
                     }
                 }
             }
         }
         $results = $dispatcher->trigger('onBtSocialconnectSave', array($data, ''));
         // update bt property if exists
         if (file_exists(JPATH_ADMINISTRATOR . '/components/com_bt_property/com_bt_property.php')) {
             $params = JComponentHelper::getParams('com_bt_property');
             if ($params->get('agent_agency')) {
                 if (isset($data['user_fields'][$params->get('agent_agency')])) {
                     $agency = $data['user_fields'][$params->get('agent_agency')];
                     $query = ' SELECT count(*) FROM #__bt_property_agents where agent_id =' . $user->id;
                     $agency = $db->escape($agency);
                     if ($agency) {
                         $db->setQuery($query);
                         if ($db->loadResult()) {
                             $query = 'UPDATE #__bt_property_agents set agency_id= ' . $agency . ' where agent_id =' . $user->id;
                         } else {
                             $query = 'INSERT INTO #__bt_property_agents(agency_id,agent_id,hits) VALUES(' . $agency . ',' . $user->id . ',0)';
                         }
                         $db->setQuery($query);
                         $db->query();
                     }
                 }
             }
         }
         // end bt properties
         return true;
     } else {
         $this->setError($user->getError());
         return false;
     }
 }
Ejemplo n.º 7
0
 public function processTransaction($data)
 {
     if (!$this->loginUser()) {
         throw new Exception("Cannot login admin");
     }
     $userObj = UserService::getUserByEmail($data->reservationData->userData->email);
     if (isset($userObj->id)) {
         JUserHelper::addUserToGroup($userObj->id, 8);
     } else {
         throw new Exception("Cannot find client account " . $data->reservationData->userData->email);
     }
     if (!$this->loginClient($data->reservationData->userData->email, $data->userData->password)) {
         throw new Exception("Cannot login");
     }
     //error_reporting(E_ALL);
     //ini_set('display_errors','On');
     // create reservation product
     $vmProduct = JModel::getInstance("Product", "VirtueMartModel");
     $product = array();
     $product['product_name'] = $data->reservationData->hotel->hotel_name . " Reservation(" . $data->confirmation_id . ") from " . $data->reservationData->userData->start_date . ' to ' . $data->reservationData->userData->end_date;
     $product['slug'] = "hotel_reservation";
     $product['notification_template'] = 1;
     $product['product_unit'] = 'KG';
     $product['product_available_date'] = date("Y-m-d");
     $product['mprices'] = array('product_price' => array($data->cost > 0 ? $data->cost : $data->total));
     $product['mprices']['basePrice'] = array(0);
     //$product['mprices']['product_currency']=array(191);
     $product['mprices']['product_tax_id'] = array(0);
     $product['mprices']['salesPrice'] = array('');
     $product['mprices']['price_quantity_start'] = array('');
     $product['mprices']['price_quantity_end'] = array('');
     $product['mprices']['product_override_price'] = array('');
     $product['mprices']['virtuemart_product_price_id'] = array('');
     $product['mprices']['product_override_price'] = array('');
     $product['mprices']['virtuemart_shoppergroup_id'] = array('');
     $product['mprices']['product_discount_id'] = array(0);
     $product['mprices']['product_price_publish_up'] = array('');
     $product['mprices']['product_price_publish_down'] = array('');
     $product['mprices']['override'] = array('');
     $vmProduct->store($product);
     //add product to cart
     $cart = VirtueMartCart::getCart();
     $_POST['virtuemart_product_id'] = $vmProduct->_id;
     JRequest::setVar('virtuemart_product_id', $vmProduct->_id);
     JRequest::setVar('quantity', array(1));
     $cart->add();
     //update Bill TO info virtuemart
     $lastName = $data->reservationData->userData->last_name;
     $name = $data->reservationData->userData->first_name . " " . $data->reservationData->userData->last_name;
     $db = JFactory::getDBO();
     $country = $data->reservationData->userData->country;
     $query = "select * from #__virtuemart_countries where lower(country_name) like lower('%{$country}%') limit 0,1";
     $db->setQuery($query);
     $countryData = $db->loadObject();
     $vmCountryId = 0;
     if (count($countryData) > 0) {
         $vmCountryId = $countryData->virtuemart_country_id;
     }
     $query = "insert into #__virtuemart_userinfos(`virtuemart_user_id`,`address_type`,`name`,`first_name`,`last_name`,`phone_1`,`address_1`,`city`,`virtuemart_country_id`,`zip`,`created_by`) values( '" . JFactory::getUser()->id . "','BT','" . $name . "','" . $data->reservationData->userData->first_name . "','" . $lastName . "','" . $data->reservationData->userData->phone . "', '" . $data->reservationData->userData->address . "','" . $data->reservationData->userData->city . "',{$vmCountryId} ,'" . $data->reservationData->userData->postal_code . "','" . $data->confirmation_id . "')";
     $db->setQuery($query);
     if (!$db->query()) {
         throw new Exception("Cannot update billing info");
     }
     JUserHelper::removeUserFromGroup(JFactory::getUser()->id, 8);
     $result = new stdClass();
     $result->transaction_id = 0;
     $result->amount = $data->cost > 0 ? $data->cost : $data->total;
     $result->payment_date = date("Y-m-d");
     $result->response_code = 0;
     $result->confirmation_id = $data->confirmation_id;
     $result->currency = $data->reservationData->hotel->hotel_currency;
     $result->processor_type = $this->type;
     $result->status = PAYMENT_REDIRECT;
     $result->payment_status = PAYMENT_STATUS_PENDING;
     return $result;
 }
Ejemplo n.º 8
0
 public static function updateGid($user_id, $gid, $unblock = false, $action = 'add')
 {
     try {
         jimport('joomla.user.helper');
         $user_id = (int) $user_id;
         if (!is_array($gid)) {
             $gid = explode(',', $gid);
         }
         JArrayHelper::toInteger($gid);
         // old version
         if (RSMembershipHelper::getConfig('replace_gid')) {
             JUserHelper::setUserGroups($user_id, $gid);
         } else {
             foreach ($gid as $group) {
                 if ($action == 'add') {
                     self::syslog('gid', "Adding user({$user_id}) to group({$group})");
                     JUserHelper::addUserToGroup($user_id, $group);
                 } elseif ($action == 'remove') {
                     self::syslog('gid', "Removing user({$user_id}) from group({$group})");
                     JUserHelper::removeUserFromGroup($user_id, $group);
                 }
             }
         }
         if ($unblock) {
             RSMembership::enableUser($user_id);
         }
     } catch (Exception $e) {
         self::syslog('gid', "Error on changing group for user({$user_id}). Message: " . $e->getMessage());
     }
 }