public function __construct()
 {
     parent::__construct();
     $oUser = new UserCore();
     $oUserModel = new UserCoreModel();
     $oExistsModel = new ExistsCoreModel();
     $oValidate = new Validate();
     $aUserData = json_decode($this->file->getFile('http://api.randomuser.me/?results=' . $this->httpRequest->post('num')), true);
     foreach ($aUserData['results'] as $aUser) {
         $aUser = $aUser['user'];
         $sEmail = trim($aUser['email']);
         $sUsername = trim($aUser['username']);
         if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail) && $oValidate->username($sUsername)) {
             $aData['username'] = $sUsername;
             $aData['email'] = $sEmail;
             $aData['first_name'] = $aUser['name']['first'];
             $aData['last_name'] = $aUser['name']['last'];
             $aData['password'] = $aUser['password'];
             $aData['sex'] = $aUser['gender'];
             $aData['match_sex'] = array($oUser->getMatchSex($aData['sex']));
             $aData['country'] = 'US';
             $aData['city'] = $aUser['location']['city'];
             $aData['state'] = $aUser['location']['state'];
             $aData['zip_code'] = $aUser['location']['zip'];
             $aData['birth_date'] = $this->dateTime->get($aUser['dob'])->date('Y-m-d');
             $aData['avatar'] = $aUser['picture']['large'];
             $aData['ip'] = Ip::get();
             $aData['profile_id'] = $oUserModel->add(escape($aData, true));
             $this->_addAvatar($aData, $oUser);
         }
     }
     unset($oUser, $oUserModel, $oExistsModel, $oValidate, $aUser, $aData, $aUserData);
     \PFBC\Form::setSuccess('form_add_fake_profiles', t('Users has been successfully added.'));
 }
 public function __construct()
 {
     parent::__construct();
     $this->_aFile = $_FILES['csv_file'];
     $sExtFile = $this->file->getFileExt($this->_aFile['name']);
     $sDelimiter = $this->httpRequest->post('delimiter');
     $sEnDelimiter = $this->httpRequest->post('enclosure');
     if ($sExtFile != 'csv' && $sExtFile != 'txt') {
         $sErrMsg = static::ERR_BAD_FILE;
     } elseif (!($rHandler = @fopen($this->_aFile['tmp_name'], 'rb'))) {
         $sErrMsg = static::ERR_BAD_FILE;
     } elseif (!($aFileData = @fgetcsv($rHandler, 0, $sDelimiter, $sEnDelimiter)) || !is_array($aFileData)) {
         $sErrMsg = static::ERR_BAD_FILE;
     }
     if (!empty($sErrMsg) && $sErrMsg == static::ERR_BAD_FILE) {
         $this->_removeTmpFile();
         \PFBC\Form::setError('form_import_user', t('Wrong file! Please select a valid CSV file containing data members.'));
         return;
         // Stop execution of the method.
     }
     /**
      * Default value...
      */
     $aGenderList = ['male', 'female', 'couple'];
     $sFiveChars = Various::genRnd($this->_aFile['name'], 5);
     $aTmpData = ['email' => 'pierrehenrysoriasanz' . $sFiveChars . '@hizup' . $sFiveChars . '.com', 'username' => 'Hizup' . $sFiveChars, 'password' => Various::genRnd(), 'first_name' => 'Alex' . $sFiveChars, 'last_name' => 'Rolli' . $sFiveChars, 'sex' => $aGenderList[mt_rand(0, 2)], 'match_sex' => $aGenderList[mt_rand(0, 2)], 'birth_date' => date('Y') - mt_rand(20, 40) . '-' . mt_rand(1, 12) . '-' . mt_rand(1, 28), 'country' => 'US', 'city' => 'Virginia', 'state' => 'Doswell', 'zip_code' => '23047', 'description' => 'Hi all!<br />How are you today?<br /> Bye ;)', 'website' => '', 'social_network_site' => '', 'ip' => Ip::get()];
     foreach ($aFileData as $sKey => $sVal) {
         // Clean the text to make comparisons easier...
         $sVal = strtolower(trim(str_replace(array('-', '_', ' '), '', $sVal)));
         // Test comparisons of strings and adding values in an array "$aTmpData"
         if ($sVal == 'username' || $sVal == 'login' || $sVal == 'user' || $sVal == 'nickname') {
             $aTmpData['username'] = $sKey;
         }
         if ($sVal == 'name' || $sVal == 'firstname') {
             $aTmpData['first_name'] = $sKey;
         }
         if ($sVal == 'lastname' || $sVal == 'surname') {
             $aTmpData['last_name'] = $sKey;
         }
         if ($sVal == 'matchsex' || $sVal == 'looking' || $sVal == 'lookingfor') {
             $aTmpData['match_sex'] = $sKey;
         }
         if ($sVal == 'sex' || $sVal == 'gender') {
             $aTmpData['sex'] = $sKey;
         }
         if ($sVal == 'email' || $sVal == 'mail') {
             $aTmpData['email'] = $sKey;
         }
         if ($sVal == 'desc' || $sVal == 'description' || $sVal == 'descriptionme' || $sVal == 'generaldescription' || $sVal == 'about' || $sVal == 'aboutme' || $sVal == 'bio' || $sVal == 'biography' || $sVal == 'comment') {
             $aTmpData['description'] = $sKey;
         }
         if ($sVal == 'country' || $sVal == 'countryid') {
             $aTmpData['country'] = $sKey;
         }
         if ($sVal == 'city' || $sVal == 'town') {
             $aTmpData['city'] = $sKey;
         }
         if ($sVal == 'state' || $sVal == 'district' || $sVal == 'province' || $sVal == 'region') {
             $aTmpData['state'] = $sKey;
         }
         if ($sVal == 'zip' || $sVal == 'zipcode' || $sVal == 'postal' || $sVal == 'postalcode') {
             $aTmpData['zip_code'] = $sKey;
         }
         if ($sVal == 'website' || $sVal == 'site' || $sVal == 'url') {
             $aTmpData['website'] = $sKey;
         }
         if ($sVal == 'birthday' || $sVal == 'birthdate' || $sVal == 'dateofbirth') {
             $aTmpData['birth_date'] = $this->dateTime->get($sKey)->date('Y-m-d');
         }
     }
     $iRow = 0;
     $oUser = new UserCore();
     $oUserModel = new UserCoreModel();
     $oExistsModel = new ExistsCoreModel();
     $oValidate = new Validate();
     while (($aFileData = fgetcsv($rHandler, 0, $sDelimiter, $sEnDelimiter)) !== false) {
         $aData[$iRow] = $aTmpData;
         // Set data by the default contents
         $sEmail = trim($aFileData[$aTmpData['email']]);
         if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail)) {
             $sUsername = trim($aFileData[$aTmpData['username']]);
             $sFirstName = trim($aFileData[$aTmpData['first_name']]);
             $sLastName = trim($aFileData[$aTmpData['last_name']]);
             $aData[$iRow]['username'] = $oUser->findUsername($sUsername, $sFirstName, $sLastName);
             $aData[$iRow]['first_name'] = $sFirstName;
             $aData[$iRow]['last_name'] = $sLastName;
             $aData[$iRow]['sex'] = trim($aFileData[$aTmpData['sex']]);
             $aData[$iRow]['match_sex'] = array(trim($aFileData[$aTmpData['match_sex']]));
             $aData[$iRow]['email'] = $sEmail;
             $aData[$iRow]['description'] = trim($aFileData[$aTmpData['description']]);
             $aData[$iRow]['country'] = trim($aFileData[$aTmpData['country']]);
             $aData[$iRow]['city'] = trim($aFileData[$aTmpData['city']]);
             $aData[$iRow]['state'] = trim($aFileData[$aTmpData['state']]);
             $aData[$iRow]['zip_code'] = trim($aFileData[$aTmpData['zip_code']]);
             $aData[$iRow]['website'] = trim($aFileData[$aTmpData['website']]);
             $aData[$iRow]['birth_date'] = trim($aFileData[$aTmpData['birth_date']]);
             $oUserModel->add(escape($aData[$iRow], true));
             $iRow++;
         }
     }
     $this->_removeTmpFile();
     unset($oUser, $oUserModel, $oExistsModel, $oValidate, $aTmpData, $aData);
     fclose($rHandler);
     Header::redirect(Uri::get(PH7_ADMIN_MOD, 'user', 'browse'), nt('%n% User has been successfully added.', '%n% Users has been successfully added.', $iRow));
 }
 /**
  * @param array $aFiles
  * @param string $sDelimiter Delimiter Field delimiter (one character).
  * @param string $sEnclosure Enclosure Field enclosure (one character).
  * @return void
  */
 public function __construct(array $aFiles, $sDelimiter, $sEnclosure)
 {
     parent::__construct();
     $this->_aFile = $aFiles;
     $sExtFile = $this->file->getFileExt($this->_aFile['name']);
     if ($sExtFile != 'csv' && $sExtFile != 'txt') {
         $this->_iErrType = static::ERR_BAD_FILE;
     } elseif ($this->_aFile['error'] == UPLOAD_ERR_INI_SIZE) {
         $this->_iErrType = static::ERR_TOO_LARGE;
     } elseif (!($rHandler = @fopen($this->_aFile['tmp_name'], 'rb'))) {
         $this->_iErrType = static::ERR_INVALID;
     } elseif (!($this->_aFileData = @fgetcsv($rHandler, 0, $sDelimiter, $sEnclosure)) || !is_array($this->_aFileData)) {
         $this->_iErrType = static::ERR_INVALID;
     }
     if (!empty($this->_iErrType)) {
         $this->_removeTmpFile();
         $this->_aRes = ['status' => false, 'msg' => $this->getErrMsg()];
     } else {
         $this->setDefVals();
         foreach ($this->_aFileData as $sKey => $sVal) {
             // Clean the text to make comparisons easier...
             $sVal = strtolower(trim(str_replace(['-', '_', ' '], '', $sVal)));
             // Test comparisons of strings and adding values in an array "ImportUser::$_aTmpData"
             if ($sVal == 'username' || $sVal == 'login' || $sVal == 'user' || $sVal == 'nickname') {
                 $this->_aTmpData['username'] = $sKey;
             }
             if ($sVal == 'name' || $sVal == 'firstname' || $sVal == 'forname') {
                 $this->_aTmpData['first_name'] = $sKey;
             }
             if ($sVal == 'lastname' || $sVal == 'surname') {
                 $this->_aTmpData['last_name'] = $sKey;
             }
             if ($sVal == 'matchsex' || $sVal == 'looking' || $sVal == 'lookingfor') {
                 $this->_aTmpData['match_sex'] = $sKey;
             }
             if ($sVal == 'sex' || $sVal == 'gender') {
                 $this->_aTmpData['sex'] = $sKey;
             }
             if ($sVal == 'email' || $sVal == 'mail') {
                 $this->_aTmpData['email'] = $sKey;
             }
             if ($sVal == 'desc' || $sVal == 'description' || $sVal == 'descriptionme' || $sVal == 'generaldescription' || $sVal == 'about' || $sVal == 'aboutme' || $sVal == 'bio' || $sVal == 'biography' || $sVal == 'comment') {
                 $this->_aTmpData['description'] = $sKey;
             }
             if ($sVal == 'country' || $sVal == 'countryid') {
                 $this->_aTmpData['country'] = $sKey;
             }
             if ($sVal == 'city' || $sVal == 'town') {
                 $this->_aTmpData['city'] = $sKey;
             }
             if ($sVal == 'state' || $sVal == 'district' || $sVal == 'province' || $sVal == 'region') {
                 $this->_aTmpData['state'] = $sKey;
             }
             if ($sVal == 'zip' || $sVal == 'zipcode' || $sVal == 'postal' || $sVal == 'postalcode' || $sVal == 'eircode') {
                 $this->_aTmpData['zip_code'] = $sKey;
             }
             if ($sVal == 'website' || $sVal == 'site' || $sVal == 'url') {
                 $this->_aTmpData['website'] = $sKey;
             }
             if ($sVal == 'birthday' || $sVal == 'birthdate' || $sVal == 'dateofbirth') {
                 $this->_aTmpData['birth_date'] = $sKey;
             }
         }
         $iRow = 0;
         $oUserModel = new UserCoreModel();
         $oExistsModel = new ExistsCoreModel();
         $oValidate = new Validate();
         while (($this->_aFileData = fgetcsv($rHandler, 0, $sDelimiter, $sEnclosure)) !== false) {
             $sEmail = trim($this->_aFileData[$this->_aTmpData['email']]);
             if ($oValidate->email($sEmail) && !$oExistsModel->email($sEmail)) {
                 $this->setData($iRow);
                 $oUserModel->add(escape($this->_aData[$iRow], true));
                 $iRow++;
             }
         }
         $this->_removeTmpFile();
         fclose($rHandler);
         unset($rHandler, $oUserModel, $oExistsModel, $oValidate, $this->_aTmpData, $this->_aFileData, $this->_aData);
         $this->_aRes = ['status' => true, 'msg' => nt('%n% user has been successfully added.', '%n% users has been successfully added.', $iRow)];
     }
 }