<?php elgg_load_css('upload_users.css'); elgg_load_js('jquery.form'); elgg_load_js('upload_users.js'); $upload = new UploadUsers(); /// Get the upload form $body = $upload->getUploadForm(); echo $body;
<?php /** * Upload users. Processes the uploaded file and prints a report of the cerated files. * * @package upload_users * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Jaakko Naakka / Mediamaisteri Group * @copyright Mediamaisteri Group 2009 * @link http://www.mediamaisteri.com/ */ $upload = new UploadUsers(); elgg_push_context('admin'); /// Get the input from the form or hidden fields $encoding = get_input('encoding'); $delimiter = get_input('delimiter'); $notification = get_input('notification'); $confirm = get_input('confirm', false); /// Set the parameters $upload->setEncoding($encoding); $upload->setDelimiter($delimiter); $upload->setNotification($notification); if (!$confirm) { /// Open the file if (!$upload->openFile('csvfile')) { forward("admin/users/upload"); } /// Process the file if (!$upload->processFile()) { forward("admin/users/upload"); }
<?php $guid = get_input('guid'); $file = get_entity($guid); if (!elgg_instanceof($file, 'object', 'upload_users_file')) { register_error(elgg_echo('upload_users:error:file_open_error')); forward("admin/users/upload"); } if ($file->status !== 'imported') { set_time_limit(0); $imp = new UploadUsers(); $imp->setNotificationFlag($file->notification); $imp->setUpdateExistingUsersFlag($file->update_existing_users); $imp->setFixUsernamesFlag($file->fix_usernames); $imp->setFixPasswordsFlag($file->fix_passwords); $imp->setHeaderMapping($file->getHeaderMapping()); $imp->setRequiredFieldMapping($file->getRequiredFieldMapping()); $data = $file->parseCSV(); $report = $imp->processRecords($data); if (($handle = fopen($file->getFilenameOnFilestore(), 'w')) !== FALSE) { $headerDisplayed = false; foreach ($report as $data) { // Add a header row if it hasn't been added yet if (!$headerDisplayed) { // Use the keys from $data as the titles fputcsv($handle, array_keys($data)); $headerDisplayed = true; } // Put the data into the stream fputcsv($handle, $data); } fclose($handle);