Example #1
0
/**
 * Import users into database from a file located on the server.
 * Function registered as service.
 * @param  string The csv (only csv) file containing users tom import
 * @param  string Security key (as found in configuration file)
 * @return string Error message
 */
function import_users_from_file($filepath, $security_key)
{
    global $_configuration;
    $errors_returned = array(0 => 'success', 1 => 'file import does not exist', 2 => 'no users to import', 3 => 'wrong datas in file', 4 => 'security error');
    // Check whether this script is launch by server and security key is ok.
    if (empty($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] || $security_key != $_configuration['security_key']) {
        return $errors_returned[4];
    }
    // Libraries
    require_once 'import.lib.php';
    // Check is users file exists.
    if (!is_file($filepath)) {
        return $errors_returned[1];
    }
    // Get list of users
    $users = parse_csv_data($filepath);
    if (count($users) == 0) {
        return $errors_returned[2];
    }
    // Check the datas for each user
    $errors = validate_data($users);
    if (count($errors) > 0) {
        return $errors_returned[3];
    }
    // Apply modifications in database
    save_data($users);
    return $errors_returned[0];
    // Import successfull
}
$interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'), "name" => get_lang('PlatformAdmin'));
set_time_limit(0);
$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
$user_id_error = array();
$error_message = '';
if (isset($_POST['formSent']) && $_POST['formSent'] and $_FILES['import_file']['size'] !== 0) {
    $file_type = 'csv';
    Security::clear_token();
    $tok = Security::get_token();
    $allowed_file_mimetype = array('csv', 'xml');
    $error_kind_file = false;
    $uploadInfo = pathinfo($_FILES['import_file']['name']);
    $ext_import_file = $uploadInfo['extension'];
    if (in_array($ext_import_file, $allowed_file_mimetype)) {
        if (strcmp($file_type, 'csv') === 0 && $ext_import_file == $allowed_file_mimetype[0]) {
            $users = parse_csv_data($_FILES['import_file']['tmp_name']);
            $errors = validate_data($users);
            $error_kind_file = false;
        } elseif (strcmp($file_type, 'xml') === 0 && $ext_import_file == $allowed_file_mimetype[1]) {
            $users = parse_xml_data($_FILES['import_file']['tmp_name']);
            $errors = validate_data($users);
            $error_kind_file = false;
        } else {
            $error_kind_file = true;
        }
    } else {
        $error_kind_file = true;
    }
    // List user id with error.
    $users_to_insert = $user_id_error = array();
    if (is_array($errors)) {
Example #3
0
 public function setInput($data)
 {
     $this->title = 'PHPUnit tests : Memory';
     $this->yAxis->label = 'Test memory, bytes';
     $subdata = array();
     foreach (glob($this->prevDir . '/*/logs/phpunit.xml.speed') as $f) {
         $d = parse_csv_data($f);
         if (count($d) == 0) {
             continue;
         }
         $sum = 0;
         foreach ($d as $row) {
             $sum += $row['memory'];
         }
         $subdata[] = $sum / count($d);
     }
     $sum = 0;
     foreach ($data as $row) {
         $sum += $row['memory'];
     }
     $subdata[] = $sum / count($data);
     $this->data['Memory'] = new ezcGraphArrayDataSet($subdata);
     foreach ($this->data as $k => $v) {
         $this->data[$k]->symbol = ezcGraph::BULLET;
         foreach ($this->data[$k] as $key => $v2) {
             $this->data[$k]->symbol[$key] = ezcGraph::NO_SYMBOL;
         }
     }
 }