public function sel_usersTask()
 {
     require_once _adm_ . '/lib/lib.directory.php';
     require_once _adm_ . '/class.module/class.directory.php';
     $base_url = 'index.php?r=adm/functionalroles/show';
     //check permissions: we should have mod privileges to assign users to the role group
     if (!$this->permissions['mod']) {
         Util::jump_to($base_url);
     }
     //read inputs
     $id_fncrole = Get::req('id_fncrole', DOTY_INT, -1);
     if ($id_fncrole <= 0) {
         $this->render('invalid', array('message' => $this->_getErrorMessage('invalid fncrole'), 'back_url' => $base_url));
         return;
     }
     //navigation urls
     $back_url = 'index.php?r=adm/functionalroles/man_users&id=' . (int) $id_fncrole;
     $jump_url = 'index.php?r=adm/functionalroles/sel_users&id_fncrole=' . (int) $id_fncrole;
     //competence details
     $info = $this->model->getFunctionalRoleInfo($id_fncrole);
     $name = $this->model->getFunctionalRoleName($id_fncrole);
     //page_title
     $page_title_arr = array($base_url => Lang::t('_FUNCTIONAL_ROLE', 'fncroles'), $back_url => Lang::t('_USERS', 'fncroles') . ': ' . $name, Lang::t('_ASSIGN_USERS', 'fncroles'));
     if (isset($_POST['cancelselector'])) {
         //--- UNDO: return to catalogue list -------------------------------------
         Util::jump_to($back_url);
     } elseif (isset($_POST['okselector'])) {
         //--- SAVE: users selection has been done --------------------------------
         $acl_man = Docebo::user()->getAclManager();
         $user_selector = new UserSelector();
         $selection = $user_selector->getSelection();
         $members_existent = $this->model->getMembers($id_fncrole);
         //retrieve newly selected users
         $_common_members = array_intersect($members_existent, $selection);
         $_new_members = array_diff($selection, $_common_members);
         //new users to add
         $_old_members = array_diff($members_existent, $_common_members);
         //old users to delete
         unset($_common_members);
         //free some memory
         //insert newly selected users in database
         $res1 = $this->model->assignMembers($id_fncrole, $_new_members);
         $res2 = $this->model->deleteMembers($id_fncrole, $_old_members);
         // apply enroll rules
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->applyRulesMultiLang('_LOG_USERS_TO_FNCROLE', $_new_members, false, $id_fncrole);
         //go back to main page, with result message
         Util::jump_to($back_url . '&res=' . ($res1 && $res2 ? 'ok_users' : 'err_users'));
     } else {
         //--- USER SELECTION IS IN PROGRESS: show selector -----------------------
         $user_selector = new UserSelector();
         $user_selector->show_user_selector = TRUE;
         $user_selector->show_group_selector = TRUE;
         $user_selector->show_orgchart_selector = TRUE;
         $user_selector->show_fncrole_selector = FALSE;
         //we can't assign functional roles to other functional roles ...
         //there should be a "role selector" too ...
         //$user_select->show_orgchart_simple_selector = TRUE;
         //filter selectable user by sub-admin permission
         $acl_man = Docebo::user()->getAclManager();
         $user_selector->setUserFilter('exclude', array($acl_man->getAnonymousId()));
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
             $user_selector->setUserFilter('user', $admin_users);
             $user_selector->setUserFilter('group', $admin_tree);
         }
         if (Get::req('is_updating', DOTY_INT, false)) {
             //...
         } else {
             //set initial selection
             $selection = $this->model->getMembers($id_fncrole);
             $user_selector->requested_tab = PEOPLEVIEW_TAB;
             $user_selector->resetSelection($selection);
         }
         $user_selector->addFormInfo(Form::getHidden('is_updating', 'is_updating', 1) . Form::getHidden('id_fncrole', 'id_fncrole', $id_fncrole));
         //draw selector
         $user_selector->loadSelector(Util::str_replace_once('&', '&amp;', $jump_url), $page_title_arr, Lang::t('_ASSIGN_USERS_TO_FNCROLE', 'fncroles'), true);
     }
 }
Exemplo n.º 2
0
 function addUser($params)
 {
     try {
         $functionalrolesadm = new FunctionalrolesAdm();
         $result = $functionalrolesadm->assignMembers($params["id_fncrole"], array(0 => $params["id_user"]));
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->applyRulesMultiLang('_LOG_USERS_TO_FNCROLE', array(0 => $params["id_user"]), false, $params["id_fncrole"]);
         $result = $params["id_user"];
     } catch (Exception $e) {
         $result = false;
     }
     return $result;
 }
Exemplo n.º 3
0
 public function createUser($params, $userdata)
 {
     if (defined("_API_DEBUG") && _API_DEBUG) {
         file_put_contents('create_user.txt', "\n\n----------------\n\n" . print_r($params, true) . " || " . print_r($userdata, true), FILE_APPEND);
     }
     $set_idst = isset($params['idst']) ? $params['idst'] : false;
     //fix grifomultimedia soap	argument [auth a.b.]
     $userdata = !isset($userdata['userid']) && isset($params) ? $params : $userdata;
     if (!isset($userdata['userid'])) {
         return false;
     }
     $id_user = $this->aclManager->registerUser($userdata['userid'], isset($userdata['firstname']) ? $userdata['firstname'] : '', isset($userdata['lastname']) ? $userdata['lastname'] : '', isset($userdata['password']) ? $userdata['password'] : '', isset($userdata['email']) ? $userdata['email'] : '', '', isset($userdata['signature']) ? $userdata['signature'] : '', false, $set_idst, isset($userdata['pwd_expire_at']) ? $userdata['pwd_expire_at'] : '');
     // suspend
     if (isset($userdata['valid']) && $userdata['valid'] == '0') {
         $res = $this->aclManager->suspendUser($id_user);
     }
     // registration code:
     if ($id_user && !empty($userdata['reg_code']) && !empty($userdata['reg_code_type'])) {
         require_once _base_ . '/lib/lib.usermanager.php';
         $user_manager = new UserManager();
         $uma = new UsermanagementAdm();
         $reg_code_res = $user_manager->_render->processRegistrationCode($this->aclManager, $uma, $id_user, $userdata['reg_code'], $userdata['reg_code_type']);
         if ($reg_code_res['success'] == false) {
             $this->aclManager->deleteUser($id_user);
             $output = array('success' => false, 'message' => 'Registration Code Error: ' . $reg_code_res['msg']);
             $id_user = false;
             return $output;
         }
     }
     if (!$id_user) {
         if (defined("_API_DEBUG") && _API_DEBUG) {
             file_put_contents('create_user.txt', "?!: " . var_export($id_user, true), FILE_APPEND);
         }
         return false;
     }
     if ($id_user) {
         if (!isset($userdata['role'])) {
             $level = ADMIN_GROUP_USER;
         } else {
             switch ($userdata['role']) {
                 case 'godadmin':
                     $level = ADMIN_GROUP_GODADMIN;
                     break;
                 case 'admin':
                     $level = ADMIN_GROUP_ADMIN;
                     break;
                 case 'pubadmin':
                     $level = ADMIN_GROUP_PUBLICADMIN;
                     break;
                 default:
                     $level = ADMIN_GROUP_USER;
                     break;
             }
         }
         //subscribe to std groups
         $group = $this->aclManager->getGroupST($level);
         //'/framework/level/user');
         $this->aclManager->addToGroup($group, $id_user);
         $group = $this->aclManager->getGroupST('/oc_0');
         $this->aclManager->addToGroup($group, $id_user);
         $group = $this->aclManager->getGroupST('/ocd_0');
         $this->aclManager->addToGroup($group, $id_user);
         if (isset($userdata['language'])) {
             require_once _base_ . '/lib/lib.preference.php';
             $user_pref = new UserPreferences($id_user);
             $user_pref->setLanguage($userdata['language']);
         }
         //check if some additional fields have been set
         $okcustom = true;
         if (isset($userdata['_customfields'])) {
             require_once _adm_ . '/lib/lib.field.php';
             $fields =& $userdata['_customfields'];
             if (count($fields) > 0) {
                 $fl = new FieldList();
                 $okcustom = $fl->storeDirectFieldsForUser($id_user, $fields);
             }
         }
         $entities = array();
         if (isset($userdata['orgchart'])) {
             $branches = explode(";", $userdata['orgchart']);
             if (is_array($branches)) {
                 foreach ($branches as $branch) {
                     $idOrg = $this->_getBranch($branch);
                     if ($idOrg !== false) {
                         $oc = $this->aclManager->getGroupST('/oc_' . $idOrg);
                         $ocd = $this->aclManager->getGroupST('/ocd_' . $idOrg);
                         $this->aclManager->addToGroup($oc, $id_user);
                         $this->aclManager->addToGroup($ocd, $id_user);
                         $entities[$oc] = $oc;
                         $entities[$ocd] = $ocd;
                     }
                 }
             }
         }
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->newRules('_NEW_USER', array($id_user), $userdata['language'], 0, !empty($entities) ? $entities : false);
         // save external user data:
         if ($params['ext_not_found'] && !empty($params['ext_user']) && !empty($params['ext_user_type'])) {
             $pref_path = 'ext.user.' . $params['ext_user_type'];
             $pref_val = 'ext_user_' . $params['ext_user_type'] . "_" . (int) $params['ext_user'];
             $pref = new UserPreferencesDb();
             $pref->assignUserValue($id_user, $pref_path, $pref_val);
             if (defined("_API_DEBUG") && _API_DEBUG) {
                 file_put_contents('create_user.txt', print_r($id_user, true) . " || " . print_r($pref_path, true) . " || " . print_r($pref_val, true), FILE_APPEND);
             }
         } else {
             if (defined("_API_DEBUG") && _API_DEBUG) {
                 file_put_contents('create_user.txt', "??: \n\n" . print_r($params, true), FILE_APPEND);
             }
         }
     }
     return $id_user;
 }
Exemplo n.º 4
0
 function _opt_in($options, $platform, $opt_link)
 {
     $social = new Social();
     $lang =& DoceboLanguage::createInstance('register', $platform);
     // Check for error
     $out = '';
     $error = $this->_checkField($_POST, $options, $platform, true);
     if ($error['error']) {
         $this->error = true;
         return '<div class="reg_err_data">' . $error['msg'] . '</div>';
     }
     // Insert temporary
     $random_code = md5($_POST['register']['userid'] . mt_rand() . mt_rand() . mt_rand());
     // register as temporary user and send mail
     $acl_man =& Docebo::user()->getAclManager();
     $iduser = $acl_man->registerTempUser($_POST['register']['userid'], $_POST['register']['firstname'], $_POST['register']['lastname'], $_POST['register']['pwd'], $_POST['register']['email'], $random_code);
     if ($iduser === false) {
         $out .= '<div class="reg_err_data">' . $lang->def('_OPERATION_FAILURE') . '</div>';
         $this->error = true;
         return $out;
     }
     // facebook register:
     if ($social->isActive('facebook')) {
         if (isset($_SESSION['fb_info']) && is_array($_SESSION['fb_info'])) {
             $social = new Social();
             $social->connectAccount('facebook', $_SESSION['fb_info']['id'], $iduser, true);
             unset($_SESSION['fb_info']);
         }
     }
     // ----
     // add base inscription policy
     $enrollrules = new EnrollrulesAlms();
     $enrollrules->newRules('_NEW_USER', array($iduser), Lang::get());
     // subscribe to groups -----------------------------------------
     if (isset($_POST['group_sel_implode'])) {
         $groups = explode(',', $_POST['group_sel_implode']);
         while (list(, $idst) = each($groups)) {
             $acl_man->addToGroup($idst, $iduser);
             // FORMA: added the inscription policy
             $enrollrules = new EnrollrulesAlms();
             $enrollrules->applyRulesMultiLang('_LOG_USERS_TO_GROUP', array((string) $iduser), false, (int) $idst, true);
             // END FORMA
         }
     }
     //if the user had enter a code we must check if there are folder related to it and add the folder's field
     $registration_code_type = Get::sett('registration_code_type', '0');
     $code_is_mandatory = Get::sett('mandatory_code', 'off') == 'on';
     $reg_code = Get::req('reg_code', DOTY_MIXED, '');
     if ($registration_code_type === 'custom') {
         $reg_code = 'change_by_custom_operation';
     }
     $array_folder = false;
     $uma = new UsermanagementAdm();
     $reg_code_res = $this->processRegistrationCode($acl_man, $uma, $iduser, $reg_code, $registration_code_type);
     if ($reg_code_res['success'] == false) {
         $acl_man->deleteTempUser($iduser);
         $this->error = true;
         return '<div class="reg_err_data">' . $reg_code_res['msg'] . '</div>';
     }
     // save language selected
     require_once _base_ . '/lib/lib.preference.php';
     $preference = new UserPreferences($iduser);
     $preference->setPreference('ui.language', Lang::get());
     // Save fields
     $extra_field = new FieldList();
     $extra_field->setFieldEntryTable($GLOBALS['prefix_fw'] . '_field_userentry');
     $extra_field->storeFieldsForUser($iduser);
     // Send mail
     $admin_mail = $options['mail_sender'];
     // FIX BUG 399
     //$link = str_replace('&amp;', '&', $opt_link.( strpos($opt_link, '?') === false ? '?' : '&' ).'random_code='.$random_code);
     $link = Get::sett('url', '') . 'index.php?modname=login&op=register_opt&random_code=' . $random_code;
     // END FIX BUG 399
     $text = $lang->def('_REG_MAIL_TEXT');
     $text = str_replace('[userid]', $_POST['register']['userid'], $text);
     $text = str_replace('[firstname]', $_POST['register']['firstname'], $text);
     $text = str_replace('[lastname]', $_POST['register']['lastname'], $text);
     $text = str_replace('[password]', $_POST['register']['pwd'], $text);
     $text = str_replace('[link]', '' . $link . '', $text);
     $text = str_replace('[hour]', $options['hour_request_limit'], $text);
     $text = stripslashes($text);
     //check register_type != self (include all previous cases except the new one "self without opt-in")
     if (strcmp($options['register_type'], 'self') != 0) {
         require_once _base_ . '/lib/lib.mailer.php';
         $mailer = DoceboMailer::getInstance();
         if (!$mailer->SendMail($admin_mail, $_POST['register']['email'], Lang::t('_MAIL_OBJECT', 'register'), $text, false, array(MAIL_REPLYTO => $admin_mail, MAIL_SENDER_ACLNAME => false))) {
             if ($registration_code_type == 'code_module') {
                 // ok, the registration has failed, let's remove the user association form the code
                 $code_manager = new CodeManager();
                 $code_manager->resetUserAssociation($code, $iduser);
             }
             $acl_man->deleteTempUser($iduser);
             $this->error = true;
             $out .= '<div class="reg_err_data">' . $lang->def('_OPERATION_FAILURE') . '</div>';
         } else {
             $out .= '<div class="reg_success">' . $lang->def('_REG_SUCCESS') . '</div>';
         }
     }
     //end
     $_GET['random_code'] = $random_code;
     $_GET['idst'] = $iduser;
     //check register_type = self
     if (strcmp($options['register_type'], 'self') == 0) {
         $text_self = $lang->def('_REG_MAIL_TEXT_SELF');
         $text_self = str_replace('[userid]', $_POST['register']['userid'], $text_self);
         $text_self = str_replace('[firstname]', $_POST['register']['firstname'], $text_self);
         $text_self = str_replace('[lastname]', $_POST['register']['lastname'], $text_self);
         $text_self = str_replace('[password]', $_POST['register']['pwd'], $text_self);
         require_once _base_ . '/lib/lib.mailer.php';
         $mailer = DoceboMailer::getInstance();
         if (!$mailer->SendMail($admin_mail, $_POST['register']['email'], Lang::t('_MAIL_OBJECT_SELF', 'register'), $text_self, false, false)) {
             $out .= '<div class="reg_err_data">' . $lang->def('_OPERATION_FAILURE') . '</div>';
         } else {
             $this->confirmRegister($this->_platform, $options);
             $out .= '<div class="reg_success">' . $lang->def('_REG_SUCCESS_SELF') . '</div>';
         }
     }
     //end
     return $out;
 }
 public function assignmembers()
 {
     $id = Get::req('id_group', DOTY_INT, -1);
     $base_url = 'index.php?r=adm/groupmanagement/';
     $back_url = $base_url . 'show_users&id=' . (int) $id;
     $jump_url = $base_url . 'assignmembers';
     $next_url = $base_url . 'show_users&id=' . (int) $id;
     //check permissions: we should have add privileges to create groups
     if (!$this->permissions['associate_user']) {
         Util::jump_to($back_url);
     }
     if ($id > 0) {
         $acl = Docebo::user()->getAclManager();
         $selector = new UserSelector();
         $cancel = Get::req('cancelselector', DOTY_MIXED, false);
         $save = Get::req('okselector', DOTY_MIXED, false);
         if ($cancel) {
             Util::jump_to($back_url);
         } elseif ($save) {
             $selection = $selector->getSelection($_POST);
             $res = $this->model->saveGroupMembers($id, $selection);
             // apply rules
             $enrollrules = new EnrollrulesAlms();
             $enrollrules->applyRulesMultiLang('_LOG_USERS_TO_GROUP', $selection, false, $id);
             Util::jump_to($next_url . ($res ? '&res=ok_assignuser' : '&res=err_assignuser'));
         } else {
             $selector->show_user_selector = TRUE;
             $selector->show_group_selector = TRUE;
             $selector->show_orgchart_selector = TRUE;
             $selector->show_fncrole_selector = FALSE;
             $group = $this->model->getGroupInfo($id, true);
             if (Get::req('is_updating', DOTY_INT, false)) {
             } else {
                 $members = $this->model->getGroupMembers($id);
                 $selector->requested_tab = PEOPLEVIEW_TAB;
                 $selector->resetSelection($members);
             }
             $selector->addFormInfo(Form::getHidden('is_updating', 'is_updating', 1) . Form::getHidden('id_group', 'id_group', $id));
             $sel_title = array('index.php?r=adm/groupmanagement/show' => Lang::t('_GROUPS', 'admin_directory'), 'index.php?r=adm/groupmanagement/show_users&amp;id=' . $id => Lang::t('_ASSIGN_USERS', 'admin_directory') . ': ' . Docebo::aclm()->relativeId($group->groupid), Lang::t('_ADD', 'admin_directory'));
             $selector->loadSelector(Util::str_replace_once('&', '&amp;', $jump_url), $sel_title, '', true);
         }
     } else {
     }
 }
 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);
 }
Exemplo n.º 7
0
 /**
  * @param array data to insert; is an array with keys the names of cols and
  *				values the data
  * @return TRUE if the row was succesfully inserted, FALSE otherwise
  **/
 function add_row($row)
 {
     $acl =& Docebo::user()->getACL();
     $acl_manager = Docebo::aclm();
     foreach ($row as $k => $v) {
         if ($row[$k] !== false) {
             $row[$k] = trim($v);
         }
     }
     $userid = strtolower(addslashes($this->_convert_char($row['userid'])));
     $firstname = ucfirst(strtolower(addslashes($this->_convert_char($row['firstname']))));
     $lastname = ucfirst(strtolower(addslashes($this->_convert_char($row['lastname']))));
     $pass = addslashes($this->_convert_char($row['pass']));
     $email = addslashes($this->_convert_char($row['email']));
     $force_change = '';
     switch ($this->pwd_force_change_policy) {
         case "by_setting":
             $force_change = Get::sett('pass_change_first_login', 'off') == 'on' ? 1 : 0;
             break;
         case "true":
             $force_change = 1;
             break;
         case 'false':
             $force_change = 0;
             break;
     }
     $idst = false;
     $is_an_update = false;
     if ($this->insert_update) {
         // check if we need to update alredy existent users
         $idst = $acl_manager->getUserST($userid);
         if ($idst !== false) {
             $result = $acl_manager->updateUser($idst, $userid, $firstname, $lastname, $pass, $email, FALSE, FALSE, FALSE, TRUE, $force_change, FALSE, FALSE, FALSE, FALSE);
             $is_an_update = true;
             // the user exist but the update query fails
             if (!$result) {
                 $this->last_error = 'Error on update user';
                 return FALSE;
             }
         }
     }
     if ($idst === FALSE) {
         // create a new user
         $idst = $acl_manager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '', FALSE, FALSE, '', $force_change, FALSE, FALSE, FALSE, FALSE);
     }
     if ($idst !== false) {
         $result = TRUE;
         $this->idst_imported[$idst] = $idst;
         if (!$is_an_update) {
             // -- Add user to registered users group if not importing into root ---
             $acl_manager->addToGroup($this->idst_oc, $idst);
             $acl_manager->addToGroup($this->idst_ocd, $idst);
             // -- add to group level ----------------------------------------------
             $acl_manager->addToGroup($this->userlevel, $idst);
         }
         // --------------------------------------------------------------------
         if (isset($row['tree_name']) && $row['tree_name'] != '') {
             $row['tree_name'] = strtolower($row['tree_name']);
             if (isset($this->orgchart[$row['tree_name']])) {
                 $f = $this->orgchart[$row['tree_name']];
                 $acl_manager->addToGroup($f->idst_oc, $idst);
                 $acl_manager->addToGroup($f->idst_ocd, $idst);
                 // apply enroll rules
                 $enrollrules = new EnrollrulesAlms();
                 $enrollrules->newRules('_NEW_IMPORTED_USER', array($idst), 'all', $f->idOrg);
             }
         } elseif ($this->idst_group != $this->idst_oc) {
             $acl_manager->addToGroup($this->idst_group, $idst);
             $acl_manager->addToGroup($this->idst_desc, $idst);
         }
         $array_subst = array('[url]' => Get::sett('url'), '[userid]' => $userid, '[password]' => $pass);
         //send email alert
         if ($this->send_alert) {
             $e_msg = new EventMessageComposer();
             $e_msg->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
             $e_msg->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
             $e_msg->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
             $recipients = array($idst);
             createNewAlert('UserNew', 'directory', 'edit', '1', 'New user created', $recipients, $e_msg, true);
         }
         //-save extra field------------------------------------------
         /*
         $arr_idst_all = $acl->getArrSTGroupsST(array($this->idst_group,$this->idst_desc));
         $arr_fields = $this->fl->getFieldsFromIdst($arr_idst_all);
         $arr_fields_toset = array();
         foreach( $arr_fields as $field_id => $field_info)
         	if(isset($row[$field_id]) && $row[$field_id] !== false)
         		$arr_fields_toset[$field_id] = addslashes($this->_convert_char($row[$field_id]));
         */
         foreach ($row as $field_id => $field_value) {
             if (isset($this->arr_fields[$field_id])) {
                 $arr_fields_toset[$field_id] = addslashes($this->_convert_char($field_value));
             }
         }
         if (count($arr_fields_toset) > 0) {
             $result = $this->fl->storeDirectFieldsForUser($idst, $arr_fields_toset, false);
         }
         //-----------------------------------------------------------
         if (!$result) {
             $this->last_error = Lang::t('_ORG_IMPORT_ERR_STORECUSTOMFIELDS') . ' : <b>' . $userid . '</b>';
         }
         return $result;
     } else {
         $this->last_error = Lang::t('_OPERATION_FAILURE') . ' : <b>' . $userid . '</b>';
         return FALSE;
     }
 }