public function importusers() { $base_url = 'index.php?r=' . $this->link . '/show'; //check permissions if (!$this->permissions['add_user']) { Util::jump_to($base_url); } $idOrg = Get::req('id', DOTY_INT, -1); if ($idOrg < 0) { return false; } $step = Get::req('step', DOTY_INT, 1); $params = array('id_org' => $idOrg, 'step' => $step); $undo = Get::req('import_groupcancel', DOTY_MIXED, false); if ($undo) { Util::jump_to($base_url); } switch ($step) { case 1: $params['orgchart_list'] = $this->model->getOrgChartDropdownList(Docebo::user()->getIdSt()); break; case 2: require_once _base_ . '/lib/lib.upload.php'; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { //$_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to($base_url . '&err=no_file'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists(Get::rel_path('base') . '/files' . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); //$_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($base_url . '&err=no_upload'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($base_url . '&err=no_upload'); } } require_once _adm_ . '/modules/org_chart/import.org_chart.php'; $separator_info = Get::req('import_separator', DOTY_STRING, ','); $separator = false; switch ($separator_info) { case "comma": $separator = ","; break; case "dotcomma": $separator = ";"; break; case "manual": $separator = Get::req('import_separator_manual', DOTY_STRING, ""); break; } $first_row_header = Get::req('import_first_row_header', DOTY_STRING, 'false') == 'true'; $import_charset = Get::req('import_charset', DOTY_STRING, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $pwd_force_change_policy = Get::req('pwd_force_change_policy', DOTY_STRING, 'do_nothing'); $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => $idOrg, 'pwd_force_change_policy' => $pwd_force_change_policy, 'send_alert' => 0, 'insert_update' => 0)); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $params['UIMap'] = $importer->getUIMap(); $params['filename'] = $GLOBALS['where_files_relative'] . $path . $savefile; $params['first_row_header'] = $first_row_header; $params['separator'] = $separator; $params['import_charset'] = $import_charset; $params['pwd_force_change_policy'] = $pwd_force_change_policy; break; case 3: $filename = Get::req('filename', DOTY_STRING, ""); if ($filename == "") { return false; } $separator = Get::req('import_separator', DOTY_STRING, ','); $first_row_header = Get::req('import_first_row_header', DOTY_STRING, 'false') == 'true'; $import_charset = Get::req('import_charset', DOTY_STRING, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } require_once _adm_ . '/modules/org_chart/import.org_chart.php'; $src = new DeceboImport_SourceCSV(array('filename' => $filename, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => $idOrg, 'pwd_force_change_policy' => Get::req('pwd_force_change_policy', DOTY_STRING, 'do_nothing'), 'send_alert' => Get::pReq('send_alert', DOTY_INT, 0), 'insert_update' => Get::pReq('insert_update', DOTY_INT, 0))); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $importer->parseMap(); $results = $importer->doImport(); $users = $dst->getNewImportedIdst(); //apply enroll rules if (!empty($users)) { $enrollrules = new EnrollrulesAlms(); $enrollrules->newRules('_NEW_IMPORTED_USER', $users, 'all', $idOrg); } $src->close(); $dst->close(); $buffer = ""; if (count($results) > 1) { require_once _base_ . '/lib/lib.table.php'; $buffer .= Lang::t('_ERRORS', 'admin_directory') . ': <b>' . (count($results) - 1) . '</b><br/>'; $table = new Table(Get::sett('visuItem', 25), Lang::t('_ERRORS', 'admin_directory'), Lang::t('_ERRORS', 'admin_directory')); $table->setColsStyle(array('', '')); $table->addHead(array(Lang::t('_ROW', 'admin_directory'), Lang::t('_DESCRIPTION', 'admin_directory'))); foreach ($results as $key => $err_val) { if ($key != 0) { $table->addBody(array($key, $err_val)); } } $buffer .= $table->getTable(); } if ($buffer === '') { $buffer = '<br/><br/>'; } $params['backUi'] = getBackUi($base_url, Lang::t('_BACK', 'standard')); $params['resultUi'] = Lang::t('_IMPORT', 'standard') . ': <b>' . ($first_row_header ? $results[0] - 1 : $results[0]) . '</b><br />'; $params['results'] = $results; $params['table'] = $buffer; // remove uploaded file: require_once _base_ . '/lib/lib.upload.php'; sl_open_fileoperations(); unlink($filename); sl_close_fileoperations(); break; } $this->render('importusers', $params); }
function loadImportUsers3() { $back_url = 'index.php?modname=directory&op=org_chart'; $tdb =& $this->tdb; $folder = $tdb->getFolderById($this->getSelectedFolderId()); $back_url = 'index.php?modname=directory&op=org_chart'; $filename = $_POST[$this->id]['filename']; $separator = isset($_POST['import_separator']) ? $_POST['import_separator'] : ','; $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = isset($_POST['import_charset']) ? $_POST['import_charset'] : 'UTF-8'; if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } require_once dirname(__FILE__) . '/import.org_chart.php'; $src = new DeceboImport_SourceCSV(array('filename' => $filename, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $dst = new ImportUser(array('dbconn' => $GLOBALS['dbConn'], 'tree' => &$this)); $src->connect(); $dst->connect(); $importer = new DoceboImport(); $importer->setSource($src); $importer->setDestination($dst); $importer->parseMap(); $result = $importer->doImport(); $src->close(); $dst->close(); // print total processed rows $tree = ""; $tree .= getBackUi($back_url, $this->lang->def('_BACK')); $tree .= getResultUi(str_replace("%count%", $result[0], $this->lang->def('_OPERATION_SUCCESSFUL'))); if (count($result) > 1) { require_once _base_ . '/lib/lib.table.php'; $tree .= str_replace("%count%", count($result) - 1, $this->lang->def('_OPERATION_FAILURE')); $table = new Table(Get::sett('visuItem'), $this->lang->def('_OPERATION_FAILURE'), $this->lang->def('_OPERATION_FAILURE')); $table->setColsStyle(array('', '')); $table->addHead(array($this->lang->def('_OPERATION_FAILURE'), $this->lang->def('_OPERATION_FAILURE'))); foreach ($result as $key => $err_val) { if ($key != 0) { $table->addBody(array($key, $err_val)); } } $tree .= $table->getTable(); } $tree .= getBackUi($back_url, $this->lang->def('_BACK')); return $tree; }