예제 #1
0
 public function storeUser_bk($post)
 {
     $app = JFactory::getApplication();
     $redshopMail = new redshopMail();
     // Start data into user table
     // Initialize some variables
     $db = JFactory::getDbo();
     $me = JFactory::getUser();
     $acl = JFactory::getACL();
     // Create a new JUser object
     $user = new JUser($post['id']);
     $original_gid = $user->get('gid');
     $post['name'] = isset($post['name']) ? $post['name'] : $post['username'];
     // Changed for shipping code moved out of condition
     if (!$user->bind($post)) {
         $app->enqueueMessage(JText::_('COM_REDSHOP_CANNOT_SAVE_THE_USER_INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
     $groups = $acl->get_object_groups($objectID, 'ARO');
     $this_group = strtolower($acl->get_group_name($groups[0], 'ARO'));
     if ($user->get('id') == $me->get('id') && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_BLOCK_YOURSELF');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'super administrator' && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_BLOCK_A_SUPER_ADMINISTRATOR');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'administrator' && $me->get('gid') == 24 && $user->get('block') == 1) {
         $msg = JText::_('COM_REDSHOP_WARNBLOCK');
         $app->enqueueMessage($msg, 'message');
         return false;
     } elseif ($this_group == 'super administrator' && $me->get('gid') != 25) {
         $msg = JText::_('COM_REDSHOP_YOU_CANNOT_EDIT_A_SUPER_ADMINISTRATOR_ACCOUNT');
         $app->enqueueMessage($msg, 'message');
         return false;
     }
     // Are we dealing with a new user which we need to create?
     $isNew = $user->get('id') < 1;
     if (!$isNew) {
         // If group has been changed and where original group was a Super Admin
         if ($user->get('gid') != $original_gid && $original_gid == 25) {
             // Count number of active super admins
             $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0';
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count <= 1) {
                 // Disallow change if only one Super Admin exists
                 $this->setRedirect('index.php?option=' . $option . '&view=user', JText::_('COM_REDSHOP_WARN_ONLY_SUPER'));
                 return false;
             }
         }
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         $app->enqueueMessage(JText::_('COM_REDSHOP_CANNOT_SAVE_THE_USER_INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     /*
      * Time for the email magic so get ready to sprinkle the magic dust...
      */
     if ($isNew) {
         $redshopMail->sendRegistrationMail($post);
     }
     // If updating self, load the new user object into the session
     if ($user->get('id') == $me->get('id')) {
         // Get an ACL object
         $acl = JFactory::getACL();
         // Get the user group from the ACL
         $grp = $acl->getAroGroup($user->get('id'));
         // Mark the user as logged in
         $user->set('guest', 0);
         $user->set('aid', 1);
         // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
         if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
             $user->set('aid', 2);
         }
         // Set the usertype based on the ACL group name
         $user->set('usertype', $grp->name);
         $session = JFactory::getSession();
         $session->set('user', $user);
     }
     // End data into user table
     return $user;
 }
 public function sendRegistrationMail($post)
 {
     $redshopMail = new redshopMail();
     $redshopMail->sendRegistrationMail($post);
 }
예제 #3
0
 public function storeRedshopUser($data, $user_id = 0, $admin = 0)
 {
     $redshopMail = new redshopMail();
     $extra_field = new extra_field();
     $helper = new redhelper();
     $data['user_email'] = $data['email'] = $data['email1'];
     $data['name'] = $name = $data['firstname'];
     $data['address_type'] = 'BT';
     $row = JTable::getInstance('user_detail', 'Table');
     if (isset($data['users_info_id']) && $data['users_info_id'] != 0) {
         $isNew = false;
         $row->load($data['users_info_id']);
         $data["old_tax_exempt_approved"] = $row->tax_exempt_approved;
         $user_id = $row->user_id;
     } else {
         $isNew = true;
         $data['password'] = JRequest::getVar('password1', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $app = JFactory::getApplication();
         $is_admin = $app->isAdmin();
         if ($data['is_company'] == 1) {
             if ($is_admin && $data['shopper_group_id'] != 0) {
                 $data['shopper_group_id'] = $data['shopper_group_id'];
             } else {
                 $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_COMPANY != 0 ? SHOPPER_GROUP_DEFAULT_COMPANY : 2;
             }
         } else {
             if ($is_admin && isset($data['shopper_group_id']) && $data['shopper_group_id'] != 0) {
                 $data['shopper_group_id'] = $data['shopper_group_id'];
             } else {
                 $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_PRIVATE != 0 ? SHOPPER_GROUP_DEFAULT_PRIVATE : 1;
             }
         }
     }
     if ($user_id > 0) {
         $joomlauser = new JUser($user_id);
         $data['username'] = $joomlauser->username;
         $data['name'] = $joomlauser->name;
         $data['email'] = $joomlauser->email;
     }
     if (SHOW_TERMS_AND_CONDITIONS == 1 && isset($data['termscondition']) && $data['termscondition'] == 1) {
         $data['accept_terms_conditions'] = 1;
     }
     $row->user_id = $data['user_id'] = $user_id;
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (USE_TAX_EXEMPT) {
         if (!$admin && $row->is_company == 1) {
             $row->requesting_tax_exempt = $data['tax_exempt'];
             if ($row->requesting_tax_exempt == 1) {
                 $redshopMail->sendRequestTaxExemptMail($row, $data['username']);
             }
         }
         // Sending tax exempted mails (tax_exempt_approval_mail)
         if (!$isNew && $admin && isset($data["tax_exempt_approved"]) && $data["old_tax_exempt_approved"] != $data["tax_exempt_approved"]) {
             if ($data["tax_exempt_approved"] == 1) {
                 $redshopMail->sendTaxExemptMail("tax_exempt_approval_mail", $data, $row->user_email);
             } else {
                 $redshopMail->sendTaxExemptMail("tax_exempt_disapproval_mail", $data, $row->user_email);
             }
         }
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Update user info id
     if (ECONOMIC_INTEGRATION) {
         $economic = new economic();
         $original_info_id = $row->users_info_id;
         if ($isNew) {
             $maxDebtor = $economic->getMaxDebtorInEconomic();
             if (count($maxDebtor) > 0) {
                 $maxDebtor = $maxDebtor[0];
                 if ($row->users_info_id <= $maxDebtor) {
                     $nextId = $maxDebtor + 1;
                     $sql = "UPDATE " . $this->_table_prefix . "users_info " . "SET users_info_id = " . (int) $nextId . " " . "WHERE users_info_id = " . (int) $row->users_info_id;
                     $this->_db->setQuery($sql);
                     $this->_db->Query();
                     $row->users_info_id = $nextId;
                 }
             }
         }
         $debtorHandle = $economic->createUserInEconomic($row);
         if ($row->is_company && trim($row->ean_number) != '' && JError::isError(JError::getError())) {
             $msg = JText::_('PLEASE_ENTER_EAN_NUMBER');
             JError::raiseWarning('', $msg);
             return false;
         }
     }
     $auth['users_info_id'] = $row->users_info_id;
     $this->_session->set('auth', $auth);
     // For non-registered customers
     if (!$row->user_id) {
         $row->user_id = 0 - $row->users_info_id;
         $row->store();
         $u = JFactory::getUser();
         $u->set('username', $row->user_email);
         $u->set('email', $row->user_email);
         $u->set('usertype', 'Registered');
         $date = JFactory::getDate();
         $u->set('registerDate', $date->toMySQL());
         $data['user_id'] = $row->user_id;
         $data['username'] = $row->user_email;
         $data['email'] = $row->user_email;
     }
     if (isset($data['newsletter_signup']) && $data['newsletter_signup'] == 1) {
         $this->newsletterSubscribe($row->user_id, $data);
     }
     $billisship = 1;
     if (!isset($data['billisship'])) {
         $billisship = 0;
     }
     // Info: field_section 6 :Userinformations
     $list_field = $extra_field->extra_field_save($data, 6, $row->users_info_id);
     if ($row->is_company == 0) {
         // Info: field_section 7 :Userinformations
         $list_field = $extra_field->extra_field_save($data, 7, $row->users_info_id);
     } else {
         // Info: field_section 8 :Userinformations
         $list_field = $extra_field->extra_field_save($data, 8, $row->users_info_id);
     }
     if ($billisship != 1) {
         $rowShip = $this->storeRedshopUserShipping($data);
     }
     if (REGISTER_METHOD != 1 && $isNew && $admin == 0) {
         if (REGISTER_METHOD == 2) {
             if (isset($data['createaccount']) && $data['createaccount'] == 1) {
                 $redshopMail->sendRegistrationMail($data);
             }
         } else {
             $redshopMail->sendRegistrationMail($data);
         }
     }
     if ($isNew) {
         JPluginHelper::importPlugin('highrise');
         $dispatcher = JDispatcher::getInstance();
         $hResponses = $dispatcher->trigger('oncreateHighriseUser', array());
     }
     /**
      * redCRM includes
      */
     if ($helper->isredCRM()) {
         $this->setoreredCRMDebtor($row);
     }
     return $row;
 }