function ioTask_UITaskRun(&$module, $action) { checkPerm('view'); require_once _base_ . '/lib/lib.form.php'; $connMgr =& $module->get_connMgr(); $lang =& $module->get_lang(); $out =& $module->get_out(); $form = new Form(); $dimport = new DoceboImport(); $params = $connMgr->get_task_byname(key($action)); $task_name = $params[CONNMGR_TASK_NAME]; $out->setWorkingZone('content'); $out->add(getTitleArea($lang->def('_TASKS'), 'iotask')); $out->add('<div class="std_block">'); $out->add($form->getFormHeader($lang->def('_TASK_RUNNED'))); $out->add($form->openForm('task_delete', 'index.php?modname=iotask&op=display&gotab=tasks')); $out->add($form->openElementSpace()); $out->add($form->getHidden('task_name', 'task_name', $task_name)); $report = $dimport->execute_task($task_name); if (!is_array($report)) { $out->add($report); } else { $out->add($form->getLineBox($lang->def('_TASK_INSERTED'), $report[0]['inserted'])); $out->add($form->getLineBox($lang->def('_OPERATION_SUCCESSFUL'), $report[0]['removed'])); $out->add($form->getLineBox($lang->def('_OPERATION_FAILURE'), count($report) - 1)); foreach ($report as $index => $elem_report) { if ($index !== 0) { $out->add($index . ' - ' . '(' . implode(', ', $report[$index][0]) . ')' . ' - ' . $report[$index][1]); } } } $out->add($form->closeElementSpace()); $out->add($form->openButtonSpace()); $out->add($form->getButton('close', 'close', $lang->def('_CLOSE'))); $out->add($form->closeButtonSpace()); $out->add($form->closeForm()); $out->add('</div>'); }
function importToGroup_step3() { $back_url = 'index.php?modname=directory&op=listgroup'; $filename = $_POST['filename']; $separator = importVar('import_separator', false, ','); $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = importVar('import_charset', false, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } require_once $GLOBALS['where_framework'] . '/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 ImportGroupUser(array('dbconn' => $GLOBALS['dbConn'])); $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 = getTitleArea($this->lang->def('_ORG_CHART_IMPORT_USERS', 'organization_chart'), 'directory_group') . '<div class="std_block">'; $tree .= getBackUi($back_url, $this->lang->def('_BACK')); $tree .= getResultUi(str_replace("[count]", $result[0], $this->lang->def('_GROUP_ASSIGN_COUNT'))); if (count($result) > 1) { require_once _base_ . '/lib/lib.table.php'; $tree .= $this->lang->def('_ERRORS') . ': <b>' . (count($result) - 1) . '</b><br/>'; $table = new Table(Get::sett('visuItem'), $this->lang->def('_ERRORS'), $this->lang->def('_ERRORS')); $table->setColsStyle(array('', '')); $table->addHead(array($this->lang->def('_ROW'), $this->lang->def('_DESCRIPTION'))); 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')); $tree .= '</div>'; $GLOBALS['page']->add($tree, 'content'); }
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 doTasks() { $out = ''; $connMgr =& $this->get_connMgr(); $taskParams =& $connMgr->get_first_task(); $dimport = new DoceboImport(); while ($taskParams !== FALSE) { if ($connMgr->is_task_todo($taskParams)) { $report = $dimport->execute_task($taskParams[CONNMGR_TASK_NAME]); if (!is_array($report)) { $out .= '<iotask name="' . $taskParams[CONNMGR_TASK_NAME] . '" inserted="0" removed="0" >'; $out .= '<result>' . $report . '</result>'; } else { $out .= '<iotask name="' . $taskParams[CONNMGR_TASK_NAME] . '"' . ' inserted="' . $report[0]['inserted'] . '"' . ' removed="' . $report[0]['removed'] . '" >'; foreach ($report as $index => $elem_report) { if ($index !== 0) { $out .= '<row index="' . $index . '">'; $out .= '<pk>' . implode(', ', $report[$index][0]) . '</pk>'; $out .= '<error>' . $report[$index][1] . '</error>'; $out .= '</row>'; } } } $out .= '</iotask>'; } $taskParams =& $connMgr->get_next_task(); } return $out; }
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; }