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'); }
function importCode_step2() { require_once _base_ . '/lib/lib.upload.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.import.php'; require_once _base_ . '/lib/lib.table.php'; if ($_FILES['file_import']['name'] == '') { Util::jump_to('index.php?modname=code&op=list&result=err'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $path . $savefile)) { sl_open_fileoperations(); if (!sl_upload($_FILES['file_import']['tmp_name'], $path . $savefile)) { sl_close_fileoperations(); Util::jump_to('index.php?modname=code&op=list&result=err'); } sl_close_fileoperations(); } else { Util::jump_to('index.php?modname=directory&op=listgroup&import_result=-1'); } } $lang =& DoceboLanguage::createInstance('code'); $code_manager = new CodeManager(); $id_code_group = Get::req('id_code_group', DOTY_INT, '0'); cout(getTitleArea($lang->def('_CODE')) . '<div class="std_block">'); $separator = Get::req('import_separator', DOTY_MIXED, ','); $first_row_header = isset($_POST['import_first_row_header']) ? $_POST['import_first_row_header'] == 'true' : FALSE; $import_charset = Get::req('import_charset', DOTY_MIXED, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $code_added = array(); $code_error = array(); $code_present = array(); if (is_array($row = $src->get_first_row()) && !empty($row)) { $code = addslashes($row[0]); $result = $code_manager->addCode($code, $id_code_group); if ($result === 'dup') { $code_present[] = $code; } elseif ($result) { $code_added[] = $code; } else { $code_error[] = $code; } } while (is_array($row = $src->get_next_row()) && !empty($row)) { $code = addslashes($row[0]); $result = $code_manager->addCode($code, $id_code_group); if ($result === 'dup') { $code_present[] = $code; } elseif ($result) { $code_added[] = $code; } else { $code_error[] = $code; } } $src->close(); unset($row); sl_open_fileoperations(); sl_unlink($path . $savefile); sl_close_fileoperations(); cout(getBackUi('index.php?modname=code&op=list', $lang->def('_BACK')) . '<br/>' . $lang->def('_CODE_ADDED') . ' : ' . count($code_added) . '<br/>' . $lang->def('_CODE_PRESENT') . ' : ' . count($code_present) . '<br/>' . $lang->def('_CODE_ERROR') . ' : ' . count($code_error) . '<br/>'); if (count($code_present)) { $tb = new Table(false, $lang->def('_CODE_PRESENT'), $lang->def('_CODE_PRESENT')); $type_h = array('align_center'); $cont_h = array($lang->def('_CODE')); $tb->setColsStyle($type_h); $tb->addHead($cont_h); foreach ($code_present as $code) { $cont = array(); $cont[] = stripslashes($code); $tb->addBody($cont); } cout($tb->getTable()); } if (count($code_error)) { $tb = new Table(false, $lang->def('_CODE_ERROR'), $lang->def('_CODE_ERROR')); $type_h = array('align_center'); $cont_h = array($lang->def('_CODE')); $tb->setColsStyle($type_h); $tb->addHead($cont_h); foreach ($code_error as $code) { $cont = array(); $cont[] = stripslashes($code); $tb->addBody($cont); } cout($tb->getTable()); } cout(getBackUi('index.php?modname=code&op=list', $lang->def('_BACK')) . '</div>'); }
function loadImportCourseUser2() { require_once _base_ . '/lib/lib.upload.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.import.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.course.php'; require_once _base_ . '/lib/lib.table.php'; $lang =& DoceboLanguage::CreateInstance('subscribe', 'lms'); $back_url = 'index.php?modname=course&op=course_list'; $acl_man =& Docebo::user()->getAclManager(); $out =& $GLOBALS['page']; $out->setWorkingZone('content'); $id_course = importVar('id_course', true, 0); $id_course_edition = importVar('edition', true, 0); $level_idst =& getCourseLevel($id_course); if (count($level_idst) == 0) { $level_idst =& DoceboCourse::createCourseLevel($id_course); } // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); Util::jump_to($back_url . '&import_result=-1'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $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($back_url . '&import_result=-1'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD'); Util::jump_to($back_url . '&create_result=-1'); } } $out->add(getTitleArea($lang->def('_SUBSCRIBE')) . '<div class="std_block">'); $separator = importVar('import_separator', false, ','); if ($separator == '') { $separator = ','; } $first_row_header = importVar('import_first_row_header', false, false); $import_charset = importVar('import_charset', false, 'UTF-8'); if (trim($import_charset) === '') { $import_charset = 'UTF-8'; } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $user_added = 0; $user_error = 0; $user_not_needed = 0; $id_user_added = array(); $counter = 0; if (is_array($row = $src->get_first_row()) && !empty($row)) { $user_info = $acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; // Add in group for permission $acl_man->addToGroup($level_idst['3'], $id_user); // Add to edition group if ($id_course_edition > 0) { $group = '/lms/course_edition/' . $id_course_edition . '/subscribed'; $group_idst = $acl_man->getGroupST($group); if ($group_idst === FALSE) { $group_idst = $acl_man->registerGroup($group, 'all the user of a course edition', true, "course"); } $acl_man->addToGroup($group_idst, $id_user); } // Add in table $re = sql_query("\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t( idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr )\r\n\t\t\tVALUES\r\n\t\t\t( '" . $id_user . "', '" . $id_course . "', '" . $id_course_edition . "', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); if ($re) { addUserToTimeTable($id_user, $id_course, $id_course_edition); $user_added++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_CORRECT'; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $id_course . "'" . " AND edition_id = '" . $id_course_edition . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $counter++; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } while (is_array($row = $src->get_next_row()) && !empty($row)) { $user_info = $acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; // Add in group for permission $acl_man->addToGroup($level_idst['3'], $id_user); // Add to edition group if ($id_course_edition > 0) { $group = '/lms/course_edition/' . $id_course_edition . '/subscribed'; $group_idst = $acl_man->getGroupST($group); if ($group_idst === FALSE) { $group_idst = $acl_man->registerGroup($group, 'all the user of a course edition', true, "course"); } $acl_man->addToGroup($group_idst, $id_user); } // Add in table $re = sql_query("\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t( idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr )\r\n\t\t\tVALUES\r\n\t\t\t( '" . $id_user . "', '" . $id_course . "', '" . $id_course_edition . "', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); if ($re) { addUserToTimeTable($id_user, $id_course, $id_course_edition); $user_added++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_CORRECT'; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $id_course . "'" . " AND edition_id = '" . $id_course_edition . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $counter++; } else { $user_error++; $id_user_added[$counter]['id_user'] = $id_user; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } } $src->close(); unset($row); $type_h = array('align_center', 'align_center', 'align_center', 'align_center'); $cont_h = array($lang->def('_USERNAME'), $lang->def('_LASTNAME'), $lang->def('_FIRSTNAME'), $lang->def('_INSER_STATUS')); $tb = new Table(false, $lang->def('_USER_SUBSCRIBED'), $lang->def('_USER_SUBSCRIBED')); $tb->addHead($cont_h, $type_h); while (list(, $id_user_added_detail) = each($id_user_added)) { $cont = array(); $user_info = $acl_man->getUser($id_user_added_detail['id_user'], false); $cont[] = $acl_man->relativeId($user_info[ACL_INFO_USERID]); $cont[] = $user_info[ACL_INFO_FIRSTNAME]; $cont[] = $user_info[ACL_INFO_LASTNAME]; $cont[] = $lang->def($id_user_added_detail['status']); $tb->addBody($cont); } sl_open_fileoperations(); sl_unlink($path . $savefile); sl_close_fileoperations(); $out->add(getBackUi($back_url, $lang->def('_BACK')) . '<b>' . $lang->def('_INSERT_CORRECT') . ' : ' . '</b>' . $user_added . ' ' . '<b>' . $lang->def('_OPERATION_FAILURE') . ' : ' . '</b>' . $user_error . ' ' . '<b>' . $lang->def('_INSERT_NOT_NEEDED') . ' : ' . '</b>' . $user_not_needed . '<br/>' . '<br/>' . $tb->getTable() . '<br/>' . getBackUi($back_url, $lang->def('_BACK')) . '</div>'); }
public function import_csv() { if (!$this->permissions['subscribe_course']) { $this->render('invalid', array('message' => $this->_getErrorMessage('no permission'), 'back_url' => 'index.php?r=' . $this->link_course . '/show')); return; } require_once _base_ . '/lib/lib.form.php'; //Step info $step = Get::req('step', DOTY_INT, 1); if (isset($_POST['next'])) { $step++; } if (isset($_POST['back'])) { $step--; } if (isset($_POST['undo'])) { $step = 0; } switch ($step) { case '0': Util::jump_to('index.php?r=' . $this->link_course . '/show'); break; case '1': $course_info = $this->model->getCourseInfoForSubscription(); $course_name = ($course_info['code'] !== '' ? '[' . $course_info['code'] . '] ' : '') . $course_info['name']; $params = array('table' => $tb, 'id_course' => $this->id_course, 'id_date' => $this->id_date, 'id_edition' => $this->id_edition, 'course_name' => $course_name, 'model' => $this->model); $this->render('import_csv_step_1', $params); break; case '2': require_once _lms_ . '/lib/lib.course.php'; require_once _base_ . '/lib/lib.upload.php'; require_once _adm_ . '/lib/lib.import.php'; $separator = Get::req('import_separator', DOTY_MIXED, ','); $first_row_header = Get::req('import_first_row_header', DOTY_BOOL, false); $import_charset = Get::req('import_charset', DOTY_MIXED, 'UTF-8'); $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } $back_url = 'index.php?r=' . $this->link . '/show&id_course=' . $this->id_course . '&id_edition=' . $this->id_edition . '&id_date=' . $this->id_date; // ----------- file upload ----------------------------------------- if ($_FILES['file_import']['name'] == '') { $_SESSION['last_error'] = Lang::t('_FILEUNSPECIFIED'); jumpTo($back_url . '&err=_file_unspecified'); } else { $path = '/appCore/'; $savefile = mt_rand(0, 100) . '_' . time() . '_' . $_FILES['file_import']['name']; if (!file_exists($GLOBALS['where_files_relative'] . $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', 'subscribe'); jumpTo($back_url . '&err=_err_upload'); } sl_close_fileoperations(); } else { $_SESSION['last_error'] = Lang::t('_ERROR_UPLOAD', 'subscribe'); jumpTo($back_url . '&err=_err_upload'); } } $src = new DeceboImport_SourceCSV(array('filename' => $GLOBALS['where_files_relative'] . $path . $savefile, 'separator' => $separator, 'first_row_header' => $first_row_header, 'import_charset' => $import_charset)); $src->connect(); $user_added = 0; $user_error = 0; $user_not_needed = 0; $id_user_added = array(); $counter = 0; $course_info = $this->model->getCourseInfoForSubscription(); $can_subscribe = true; $max_num_subscribe = $course_info['max_num_subscribe']; $subscribe_method = $course_info['subscribe_method']; if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) { $limited_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.limit_course_subscribe'); $max_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.max_course_subscribe'); $direct_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.direct_course_subscribe'); if ($limited_subscribe == 'on') { $limited_subscribe = true; } else { $limited_subscribe = false; } if ($direct_subscribe == 'on') { $direct_subscribe = true; } else { $direct_subscribe = false; } } else { $limited_subscribe = false; $max_subscribe = 0; $direct_subscribe = true; } if (is_array($row = $src->get_first_row()) && !empty($row)) { $user_info = $this->acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; if ($can_subscribe) { require_once _lms_ . '/lib/lib.course.php'; $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } if (!$direct_subscribe) { $waiting = 1; } else { $waiting = 0; } if (!$limited_subscribe || $max_subscribe) { //$this->acl_man->addToGroup($level_idst['3'], $id_user); $this->_addToCourseGroup($level_idst['3'], $id_user); if ($this->model->subscribeUser($id_user, '3', $waiting)) { $user_added++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_CORRECT'; $user_subscribed[] = $id_user; $max_subscribe--; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $this->id_course . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; $this->acl_man->removeFromGroup($level_idst['3'], $id_user); } } } } } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } $counter++; } while (is_array($row = $src->get_next_row()) && !empty($row)) { $user_info = $this->acl_man->getUser(false, $row[0]); if ($user_info) { $id_user = $user_info[ACL_INFO_IDST]; if ($can_subscribe) { require_once _lms_ . '/lib/lib.course.php'; $docebo_course = new DoceboCourse($this->id_course); $level_idst =& $docebo_course->getCourseLevel($this->id_course); if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& $docebo_course->createCourseLevel($this->id_course); } if (!$direct_subscribe) { $waiting = 1; } else { $waiting = 0; } if (!$limited_subscribe || $max_subscribe) { //$this->acl_man->addToGroup($level_idst['3'], $id_user); $this->_addToCourseGroup($level_idst['3'], $id_user); if ($this->model->subscribeUser($id_user, '3', $waiting)) { $user_added++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_CORRECT'; $user_subscribed[] = $id_user; $max_subscribe--; } else { $query = "SELECT COUNT(*)" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = '******'" . " AND idCourse = '" . $this->id_course . "'"; list($control) = sql_fetch_row(sql_query($query)); if ($control) { $user_not_needed++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_NOT_NEEDED'; } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; $this->acl_man->removeFromGroup($level_idst['3'], $id_user); } } } } } else { $user_error++; $id_user_added[$counter]['id_user'] = $row[0]; $id_user_added[$counter]['status'] = '_OPERATION_FAILURE'; } $counter++; } $src->close(); unset($row); require_once _base_ . '/lib/lib.table.php'; $type_h = array('align_center', 'align_center', 'align_center', 'align_center'); $cont_h = array(Lang::t('_USERNAME', 'subscribe'), Lang::t('_LASTNAME', 'subscribe'), Lang::t('_FIRSTNAME', 'subscribe'), Lang::t('_INSER_STATUS', 'subscribe')); $tb = new Table(false, Lang::t('_USER_SUBSCRIBED', 'subscribe'), Lang::t('_USER_SUBSCRIBED', 'subscribe')); $tb->addHead($cont_h, $type_h); while (list(, $id_user_added_detail) = each($id_user_added)) { $cont = array(); $user_info = $this->acl_man->getUser(false, $id_user_added_detail['id_user']); $cont[] = $this->acl_man->relativeId($user_info[ACL_INFO_USERID]); $cont[] = $user_info[ACL_INFO_FIRSTNAME]; $cont[] = $user_info[ACL_INFO_LASTNAME]; $cont[] = Lang::t($id_user_added_detail['status'], 'subscribe'); $tb->addBody($cont); } sl_open_fileoperations(); sl_unlink($GLOBALS['where_files_relative'] . $path . $savefile); sl_close_fileoperations(); $course_info = $this->model->getCourseInfoForSubscription(); $course_name = ($course_info['code'] !== '' ? '[' . $course_info['code'] . '] ' : '') . $course_info['name']; $params = array('table' => $tb, 'id_course' => $this->id_course, 'id_date' => $this->id_date, 'id_edition' => $this->id_edition, 'course_name' => $course_name, 'back_link' => getBackUi('index.php?r=' . $this->link . '/show&id_course=' . $this->id_course . '&id_edition=' . $this->id_edition . '&id_date=' . $this->id_date, Lang::t('_BACK', 'subscribe'))); $this->render('import_csv_step_2', $params); break; } }
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; }