function org_waitingUser()
 {
     checkPerm('approve_waiting_user', false, 'directory', 'framework');
     require_once _base_ . '/lib/lib.form.php';
     require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
     require_once _base_ . '/lib/lib.table.php';
     require_once _base_ . '/lib/lib.usermanager.php';
     if (isset($_POST['ok_waiting'])) {
         $user_man = new UserManager();
         // Remove refused users
         $refused = array();
         $aopproved = array();
         if (isset($_POST['waiting_user_refuse'])) {
             while (list($idst) = each($_POST['waiting_user_refuse'])) {
                 $this->aclManager->deleteTempUser($idst, false, false, true);
             }
             $refused[] = $idst;
         }
         // Subscribed accepted users
         if (isset($_POST['waiting_user_accept'])) {
             $idst_usergroup = $this->aclManager->getGroup(false, ADMIN_GROUP_USER);
             $idst_usergroup = $idst_usergroup[ACL_INFO_IDST];
             $idst_oc = $this->aclManager->getGroup(false, '/oc_0');
             $idst_oc = $idst_oc[ACL_INFO_IDST];
             $idst_ocd = $this->aclManager->getGroup(false, '/ocd_0');
             $idst_ocd = $idst_ocd[ACL_INFO_IDST];
             $request = $this->aclManager->getTempUsers(false, true);
             while (list($idst) = each($_POST['waiting_user_accept'])) {
                 if ($this->aclManager->registerUser(addslashes($request[$idst]['userid']), addslashes($request[$idst]['firstname']), addslashes($request[$idst]['lastname']), $request[$idst]['pass'], addslashes($request[$idst]['email']), '', '', true, $idst)) {
                     $approved[] = $idst;
                     $this->aclManager->addToGroup($idst_usergroup, $idst);
                     $this->aclManager->addToGroup($idst_oc, $idst);
                     $this->aclManager->addToGroup($idst_ocd, $idst);
                     if ($request[$idst]['create_by_admin'] != 0) {
                         $pref = new UserPreferences($request[$idst]['create_by_admin']);
                         if ($pref->getAdminPreference('admin_rules.limit_user_insert') == 'on') {
                             $max_insert = $pref->getAdminPreference('admin_rules.max_user_insert');
                             $pref->setPreference('admin_rules.max_user_insert', $max_insert - 1);
                         }
                     }
                     $this->aclManager->deleteTempUser($idst, false, false, false);
                 }
             }
         }
         require_once _base_ . '/lib/lib.platform.php';
         require_once _base_ . '/lib/lib.eventmanager.php';
         // send the alert
         /*
         			if(!empty($refused)) {
         
         				$array_subst = array('[url]' => Get::sett('url'));
         
         				$msg_composer = new EventMessageComposer('admin_directory', 'framework');
         
         				$msg_composer->setSubjectLangText('email', '_REFUSED_USER_SBJ', false);
         				$msg_composer->setBodyLangText('email', '_REFUSED_USER_TEXT', $array_subst);
         
         				$msg_composer->setBodyLangText('sms', '_REFUSED_USER_TEXT_SMS', $array_subst);
         
         				createNewAlert(	'UserApproved', 'directory', 'edit', '1', 'Users refused',
         							$refused, $msg_composer );
         			}*/
         if (!empty($approved)) {
             $pl_man =& PlatformManager::createInstance();
             $array_subst = array('[url]' => Get::sett('url', ''));
             $msg_composer2 = new EventMessageComposer('admin_directory', 'framework');
             $msg_composer2->setSubjectLangText('email', '_APPROVED_USER_SBJ', false);
             $msg_composer2->setBodyLangText('email', '_APPROVED_USER_TEXT', $array_subst);
             $msg_composer2->setBodyLangText('sms', '_APPROVED_USER_TEXT_SMS', $array_subst);
             createNewAlert('UserApproved', 'directory', 'edit', '1', 'Users approved', $approved, $msg_composer2, true);
         }
         Util::jump_to('index.php?modname=directory&op=org_chart');
     } elseif (isset($_POST['cancel_waiting'])) {
         Util::jump_to('index.php?modname=directory&op=org_chart');
     } else {
         $tb = new Table(0, $this->lang->def('_WAITING_USERS'), $this->lang->def('_WAITING_USER_SUMMARY'));
         $type_h = array('', '', '', 'image', 'image');
         $cont_h = array($this->lang->def('_USERNAME'), $this->lang->def('_DIRECTORY_FULLNAME'), $this->lang->def('_BY'), '<img src="' . getPathImage('framework') . 'directory/wuser_accept.gif" alt="' . $this->lang->def('_ACCEPT') . '" ' . 'title="' . $this->lang->def('_ACCEPT_USER') . '" />', '<img src="' . getPathImage('framework') . 'directory/wuser_refuse.gif" alt="' . $this->lang->def('_REFUSE_USER') . '" ' . 'title="' . $this->lang->def('_REFUSE_USER_TITLE') . '" />');
         $tb->setColsStyle($type_h);
         $tb->addHead($cont_h);
         $temp_users = $this->aclManager->getTempUsers(false, true);
         if ($temp_users !== false) {
             $idst_admins = array();
             while (list($idst, $info) = each($temp_users)) {
                 if ($info['create_by_admin'] != 0) {
                     $idst_admins[] = $info['create_by_admin'];
                 }
             }
             $admins = $this->aclManager->getUsers($idst_admins);
             reset($temp_users);
             while (list($idst, $info) = each($temp_users)) {
                 if ($info['create_by_admin'] != 0) {
                     $creator = $admins[$info['create_by_admin']][ACL_INFO_LASTNAME] . ' ' . $admins[$info['create_by_admin']][ACL_INFO_FIRSTNAME];
                     if ($creator == '') {
                         $creator = $this->aclManager->relativeId($admins[$info['create_by_admin']][ACL_INFO_USERID]);
                     }
                 } else {
                     $creator = $this->lang->def('_DIRECOTRY_SELFREGISTERED');
                 }
                 $more = isset($_GET['id_user']) && $_GET['id_user'] == $idst ? '<a href="index.php?modname=directory&amp;op=org_waitinguser"><img src="' . getPathImage() . 'standard/less.gif"></a> ' : '<a href="index.php?modname=directory&amp;op=org_waitinguser&amp;id_user='******'"><img src="' . getPathImage() . 'standard/more.gif"></a> ';
                 $cont = array($more . $this->aclManager->relativeId($info['userid']), $info['lastname'] . ' ' . $info['firstname'], $creator, Form::getInputCheckbox('waiting_user_accept_' . $idst, 'waiting_user_accept[' . $idst . ']', $idst, false, '') . Form::getLabel('waiting_user_accept_' . $idst, $this->lang->def('_ACCEPT'), 'access-only'), Form::getInputCheckbox('waiting_user_refuse_' . $idst, 'waiting_user_refuse[' . $idst . ']', $idst, false, '') . Form::getLabel('waiting_user_refuse_' . $idst, $this->lang->def('_REFUSE_USER'), 'access-only'));
                 $tb->addBody($cont);
                 if (isset($_GET['id_user']) && $idst == $_GET['id_user']) {
                     $field = new FieldList();
                     $tb->addBodyExpanded($field->playFieldsForUser($idst, false, true), 'user_specific_info');
                 }
             }
         }
         $GLOBALS['page']->add(getTitleArea($this->lang->def('_WAITING_USERS'), 'directory') . '<div class="std_block">' . Form::openForm('waiting_user', 'index.php?modname=directory&amp;op=org_waitinguser') . $tb->getTable() . Form::openButtonSpace() . Form::getButton('ok_waiting', 'ok_waiting', $this->lang->def('_SAVE')) . Form::getButton('cancel_waiting', 'cancel_waiting', $this->lang->def('_UNDO')) . Form::closeButtonSpace() . Form::closeForm() . '</div>', 'content');
     }
 }
Exemple #2
0
function launchNotify($notify_is_a, $id_notify, $description, &$msg_composer)
{
    require_once _base_ . '/lib/lib.eventmanager.php';
    $recipients = array();
    $query_notify = "\r\n\tSELECT id_user\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forum_notifier\r\n\tWHERE id_notify = '" . $id_notify . "' AND\r\n\t\tnotify_is_a = '" . ($notify_is_a == 'forum' ? 'forum' : 'thread') . "' AND\r\n\t\tid_user <> '" . getLogUserId() . "'";
    if ($notify_is_a !== false) {
        $query_notify .= " AND notify_is_a = '" . ($notify_is_a == 'forum' ? 'forum' : 'thread') . "'";
    }
    $re = sql_query($query_notify);
    echo $query_notify;
    while (list($id_user) = sql_fetch_row($re)) {
        $recipients[] = $id_user;
    }
    if (!empty($recipients)) {
        createNewAlert($notify_is_a == 'forum' ? 'ForumNewThread' : 'ForumNewResponse', 'forum', $notify_is_a == 'forum' ? 'new_thread' : 'responce', 1, $description, $recipients, $msg_composer);
    }
    return;
}
Exemple #3
0
function updreader()
{
    checkPerm('mod');
    require_once _base_ . '/lib/lib.userselector.php';
    $lang =& DoceboLanguage::createInstance('advice', 'lms');
    $id_advice = importVar('id_advice', true, 0);
    $user_select = new UserSelector();
    $user_selected = $user_select->getSelection($_POST);
    $query_reader = "\r\n\t\tSELECT idUser\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_adviceuser\r\n\t\tWHERE idAdvice = '" . $id_advice . "'";
    $re_reader = sql_query($query_reader);
    $old_users = array();
    $found = false;
    $me = getLogUserId();
    while (list($id_user) = sql_fetch_row($re_reader)) {
        $old_users[] = $id_user;
        if ($id_user == $me) {
            $found = true;
        }
    }
    $add_reader = array_diff($user_selected, $old_users);
    $del_reader = array_diff($old_users, $user_selected);
    if (!$found) {
        $add_reader[] = $me;
    }
    $dest = array();
    if (is_array($add_reader)) {
        while (list(, $idst) = each($add_reader)) {
            $query_insert = "\r\n\t\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_adviceuser\r\n\t\t\t\t( idUser, idAdvice ) VALUES\r\n\t\t\t\t( \t'" . $idst . "',\r\n\t\t\t\t\t'" . $id_advice . "' )";
            sql_query($query_insert);
            $dest[] = $idst;
        }
    }
    if (is_array($del_reader)) {
        while (list(, $idst) = each($del_reader)) {
            $query_delete = "\r\n\t\t\t\tDELETE FROM " . $GLOBALS['prefix_lms'] . "_adviceuser\r\n\t\t\t\tWHERE idUser='******' AND idAdvice='" . $id_advice . "'";
            sql_query($query_delete);
        }
    }
    if (is_array($dest)) {
        require_once _base_ . '/lib/lib.eventmanager.php';
        $query_advice = "\r\n\t\t\tSELECT title, description, important\r\n\t\t\tFROM " . $GLOBALS['prefix_lms'] . "_advice\r\n\t\t\tWHERE idAdvice='" . (int) $id_advice . "'";
        list($title, $description, $impo) = sql_fetch_row(sql_query($query_advice));
        $msg_composer = new EventMessageComposer();
        $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT', false);
        $msg_composer->setBodyLangText('email', '_ALERT_TEXT', array('[url]' => Get::sett('url'), '[course]' => $GLOBALS['course_descriptor']->getValue('name'), '[title]' => stripslashes($title), '[text]' => stripslashes($description)));
        $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_SMS', array('[url]' => Get::sett('url'), '[course]' => $GLOBALS['course_descriptor']->getValue('name'), '[title]' => stripslashes($title), '[text]' => stripslashes($description)));
        createNewAlert('AdviceNew', 'advice', 'add', '1', 'Inserted advice ' . $title . ' in course ' . $_SESSION['idCourse'], $dest, $msg_composer);
    }
    Util::jump_to('index.php?modname=advice&op=advice');
}
 public function saveTrackStatusChange($idUser, $idCourse, $status)
 {
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     list($prev_status) = sql_fetch_row(sql_query("\r\n\t\tSELECT status\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\tWHERE idUser = '******' AND idCourse = '" . (int) $idCourse . "'"));
     $extra = '';
     if ($prev_status != $status) {
         switch ($status) {
             case _CUS_SUBSCRIBED:
                 //approved subscriptin for example
                 $extra = ", date_inscr = NOW()";
                 break;
             case _CUS_BEGIN:
                 //first access
                 UpdatesLms::resetCache();
                 $extra = ", date_first_access = NOW()";
                 break;
             case _CUS_END:
                 //end course
                 $extra = ", date_complete = NOW()";
                 break;
         }
     }
     if (!sql_query("\r\n\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\tSET status = '" . (int) $status . "' " . $extra . "\r\n\t\tWHERE idUser = '******' AND idCourse = '" . (int) $idCourse . "'")) {
         return false;
     }
     $re = sql_query("\r\n\t\tSELECT when_do\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_statuschangelog\r\n\t\tWHERE status_user = '******' AND\r\n\t\t\tidUser = '******' AND\r\n\t\t\tidCourse = '" . (int) $idCourse . "'");
     if (sql_num_rows($re)) {
         sql_query("\r\n\t\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_statuschangelog\r\n\t\t\tSET when_do = NOW()\r\n\t\t\tWHERE status_user = '******' AND\r\n\t\t\t\tidUser = '******' AND\r\n\t\t\t\tidCourse = '" . (int) $idCourse . "'");
     } else {
         sql_query("\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_statuschangelog\r\n\t\t\tSET status_user = '******',\r\n\t\t\t\tidUser = '******',\r\n\t\t\t\tidCourse = '" . (int) $idCourse . "',\r\n\t\t\t\twhen_do = NOW()");
     }
     if ($prev_status != $status && $status == _CUS_END) {
         // send alert
         if (!sql_num_rows($re)) {
             /*
             				//add course's competences scores to user
             				require_once($GLOBALS['where_lms'].'/lib/lib.competences.php');
             				$competences_man = new Competences_Manager();
             				$competences_man->AssignCourseCompetencesToUser($idCourse, $idUser);
             */
         }
         require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
         require_once _base_ . '/lib/lib.eventmanager.php';
         $teachers = Man_Course::getIdUserOfLevel($idCourse, '6');
         $cd = new DoceboCourse($idCourse);
         $acl_man =& Docebo::user()->getAclManager();
         $array_subst = array('[user]' => $acl_man->getUserName($idUser), '[course]' => $cd->getValue('name'));
         $msg_composer = new EventMessageComposer();
         $msg_composer->setSubjectLangText('email', '_USER_END_COURSE_SBJ', false);
         $msg_composer->setBodyLangText('email', '_USER_END_COURSE_TEXT', $array_subst);
         $msg_composer->setBodyLangText('sms', '_USER_END_COURSE_TEXT_SMS', $array_subst);
         // send message to the user subscribed
         createNewAlert('UserCourseEnded', 'status', 'modify', '1', 'User end course', $teachers, $msg_composer);
         //add course's competences scores to user
         /*
         require_once($GLOBALS['where_lms'].'/lib/lib.competences.php');
         $competences_man = new Competences_Manager();
         $competences_man->AssignCourseCompetencesToUser($idCourse, $idUser);
         */
         //increment coursecompleted if this course is in a coursepath
         require_once _lms_ . '/lib/lib.coursepath.php';
         $cpmodel = new CoursePath_Manager();
         $cpmodel->assignComplete($idCourse, $idUser);
     }
     return true;
 }
Exemple #5
0
function subscribeFromCourse()
{
    require_once _base_ . '/lib/lib.form.php';
    require_once $GLOBALS['where_framework'] . '/lib/lib.directory.php';
    require_once _base_ . '/lib/lib.userselector.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course_managment.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 = Get::req('id_course', DOTY_INT, 0);
    $edition_id = Get::req('edition_id', DOTY_INT, 0);
    $alert = Get::req('alert', DOTY_INT, 0);
    $delete_prev = Get::req('delete_from_prev', DOTY_INT, 0);
    $sel = new Course_Manager();
    if (isset($_POST['subscribe_import'])) {
        $course_info = Man_Course::getCourseInfo($id_course);
        $level_idst =& getCourseLevel($id_course);
        if (count($level_idst) == 0) {
            $level_idst =& DoceboCourse::createCourseLevel($id_course);
        }
        $course_selected = $sel->getCourseSelection($_POST);
        if (empty($course_selected)) {
            Util::jump_to('index.php?modname=course&op=course_list&result=err');
        }
        $id_course = Get::req('id_course', DOTY_INT, 0);
        $level = Get::req('level', DOTY_INT, 0);
        $status = Get::req('status', DOTY_INT, 0);
        $gsel = array();
        foreach ($course_selected as $trash => $id) {
            $gsel[$id] = getCourseLevel($id);
        }
        $query = "SELECT idUser, idCourse, level" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idCourse IN (" . implode(',', $course_selected) . ")";
        if ($level) {
            $query .= " AND level = '" . $level . "'";
        }
        if ($status != '-2') {
            $query .= " AND status = '" . $status . "'";
        }
        $result = sql_query($query);
        $array_user = array();
        $user_subscribed = array();
        while (list($id_user, $id_prev_course, $lv_sel) = sql_fetch_row($result)) {
            if ($delete_prev) {
                removeSubscription($id_prev_course, $id_user, $gsel[$id_prev_course][$lv_sel]);
            }
            // Add in group for permission
            $acl_man->addToGroup($level_idst[$lv_sel], $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 . "', '" . $edition_id . "', '" . $lv_sel . "', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t");
            if ($re) {
                $user_subscribed[] = $id_user;
                addUserToTimeTable($id_user, $id_course, $edition_id);
            }
        }
        Docebo::user()->loadUserSectionST('/lms/course/private/');
        Docebo::user()->SaveInSession();
        require_once _base_ . '/lib/lib.eventmanager.php';
        $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name'], '[medium_time]' => $course_info['mediumTime'], '[course_name]' => $course_info['name'], '[course_code]' => $course['code']);
        if (!empty($user_subscribed) && $alert) {
            // message to user that is subscribed
            $msg_composer = new EventMessageComposer();
            $msg_composer->setSubjectLangText('email', '_NEW_USER_SUBSCRIBED_SUBJECT', false);
            $msg_composer->setBodyLangText('email', '_NEW_USER_SUBSCRIBED_TEXT', $array_subst);
            $msg_composer->setBodyLangText('sms', '_NEW_USER_SUBSCRIBED_TEXT_SMS', $array_subst);
            // send message to the user subscribed
            createNewAlert('UserCourseInserted', 'subscribe', 'insert', '1', 'User subscribed', $user_subscribed, $msg_composer);
        }
        Util::jump_to('index.php?modname=course&op=course_list&result=ok');
    }
    $sel->setLink('index.php?modname=meta_certificate&amp;op=new_assign');
    $sel->show_coursepath_selector = false;
    $sel->show_catalogue_selector = false;
    $array_level = CourseLevel::getLevels();
    $array_level['0'] = $lang->def('_ALL');
    $arr_status = array('-2' => $lang->def('_ALL'), _CUS_CONFIRMED => $lang->def('_USER_STATUS_CONFIRMED'), _CUS_SUBSCRIBED => $lang->def('_USER_STATUS_SUBS'), _CUS_BEGIN => $lang->def('_USER_STATUS_BEGIN'), _CUS_END => $lang->def('_USER_STATUS_END'), _CUS_SUSPEND => $lang->def('_SUSPENDED'), _CUS_CANCELLED => $lang->def('_USER_STATUS_CANCELLED'));
    $out->add(getTitleArea($lang->def('_IMPORT_FROM_COURSE')) . '<div class="std_block">' . Form::openForm('course_selection', 'index.php?modname=subscribe&amp;op=subscribe_from_course') . Form::openElementSpace() . Form::getDropdown($lang->def('_LEVEL_TO_IMPORT'), 'level', 'level', $array_level, isset($_POST['level']) ? $_POST['level'] : '0') . Form::getDropdown($lang->def('_STATUS_TO_IMPORT'), 'status', 'status', $arr_status, isset($_POST['status']) ? $_POST['status'] : '-2') . Form::getCheckbox($lang->def('_SEND_ALERT'), 'alert', 'alert', '1', $delete_prev) . Form::getCheckbox($lang->def('_DELETE'), 'delete_from_prev', 'delete_from_prev', '1', $delete_prev) . Form::closeElementSpace());
    $sel->loadSelector(false);
    $out->add(Form::getHidden('id_course', 'id_course', $id_course) . Form::getHidden('edition_id', 'edition_id', $edition_id) . Form::openButtonSpace() . Form::getBreakRow() . Form::getButton('subscribe_import', 'subscribe_import', $lang->def('_SUBSCRIBE')) . Form::getButton('undo_course', 'undo_course', $lang->def('_UNDO')) . Form::closeButtonSpace() . Form::closeForm() . '</div>');
}
 function extendedParsing($arrayState, $arrayExpand, $arrayCompress)
 {
     if (isset($arrayState['editpersonsave'])) {
         $idst = $_POST['idst'];
         $userid = $_POST['userid'];
         $firstname = $_POST['firstname'];
         $lastname = $_POST['lastname'];
         $pass = $_POST['pass'];
         $userlevel = $_POST['userlevel'];
         $olduserlevel = $_POST['olduserlevel'];
         if ($pass === '') {
             $pass = FALSE;
         }
         $email = $_POST['email'];
         if ($idst !== '') {
             //-extra field-----------------------------------------------
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             $fields = new FieldList();
             //$re_filled = $fields->isFilledFieldsForUser($idst);
             if ($userid != '') {
                 $info = $this->aclManager->getUser($idst, false);
                 $this->aclManager->updateUser($idst, $userid, $firstname, $lastname, $pass, $email, FALSE, FALSE);
                 //-extra field-----------------------------------------------
                 $fields->storeFieldsForUser($idst);
                 //-----------------------------------------------------------
                 // remove from old group level
                 $this->aclManager->removeFromGroup($olduserlevel, $idst);
                 // add to group level
                 $this->aclManager->addToGroup($userlevel, $idst);
                 if ($this->aclManager->absoluteId($userid) != $info[ACL_INFO_USERID] || $this->aclManager->encrypt($pass) != $info[ACL_INFO_PASS]) {
                     require_once _base_ . '/lib/lib.eventmanager.php';
                     $pl_man = PlatformManager::createInstance();
                     $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                     // message to user that is odified
                     $msg_composer = new EventMessageComposer();
                     $msg_composer->setSubjectLangText('email', '_MODIFIED_USER_SBJ', false);
                     $msg_composer->setBodyLangText('email', '_MODIFIED_USER_TEXT', $array_subst);
                     if ($pass != '') {
                         $msg_composer->setBodyLangText('email', '_PASSWORD_CHANGED', array('[password]' => $pass));
                     }
                     $msg_composer->setBodyLangText('sms', '_MODIFIED_USER_TEXT_SMS', $array_subst);
                     if ($pass != '') {
                         $msg_composer->setBodyLangText('sms', '_PASSWORD_CHANGED_SMS', array('[password]' => $pass));
                     }
                     createNewAlert('UserMod', 'directory', 'edit', '1', 'User ' . $userid . ' was modified', array($userid), $msg_composer);
                 }
                 $GLOBALS['page']->add(getResultUi($this->lang->def('_OPERATION_SUCCESSFUL')));
             } else {
                 $this->op = 'reedit_person';
                 //$GLOBALS['page']->add( getErrorUi( implode(',', $re_filled) ), 'content');
             }
         } else {
             if (isset($_POST['arr_idst_groups'])) {
                 $arr_idst_groups = unserialize(urldecode($_POST['arr_idst_groups']));
                 $acl =& Docebo::user()->getACL();
                 $arr_idst_all = $acl->getArrSTGroupsST($arr_idst_groups);
             } else {
                 $arr_idst_groups = FALSE;
                 $arr_idst_all = FALSE;
             }
             //-verify that userid is not already used
             if ($this->aclManager->getUserST($userid) !== FALSE) {
                 $GLOBALS['page']->add(getErrorUi($this->lang->def('_USERID_DUPLICATE')));
                 $_POST['userid'] = '';
                 $this->op = 'reedit_person';
             } else {
                 //-verify mandatory extra field--------------------------------
                 require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
                 $fields = new FieldList();
                 //$re_filled = $fields->isFilledFieldsForUser(0, $arr_idst_all);
                 if ($arr_idst_groups != FALSE && $userid != '') {
                     $idst = false;
                     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
                         $limit_insert = Docebo::user()->preference->getAdminPreference('admin_rules.limit_user_insert');
                         $max_insert = Docebo::user()->preference->getAdminPreference('admin_rules.max_user_insert');
                         $direct_insert = Docebo::user()->preference->getAdminPreference('admin_rules.direct_user_insert');
                         if ($limit_insert == 'off' || $limit_insert == 'on' && $max_insert > 0) {
                             if ($direct_insert == 'on') {
                                 Docebo::user()->preference->setPreference('admin_rules.max_user_insert', $max_insert - 1);
                                 $idst = $this->aclManager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '');
                                 require_once _base_ . '/lib/lib.preference.php';
                                 $preference = new UserPreferences($idst);
                                 $preference->savePreferences($_POST, 'ui.');
                                 require_once _base_ . "/lib/lib.eventmanager.php";
                                 $pl_man =& PlatformManager::createInstance();
                                 $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                                 // message to user that is inserted
                                 $msg_composer = new EventMessageComposer();
                                 $msg_composer->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
                                 $msg_composer->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
                                 $msg_composer->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
                                 createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' created', array($userid), $msg_composer);
                                 $GLOBALS['page']->add(getResultUi($this->lang->def('_INSERTED_NEW_USER')));
                             } else {
                                 $acl = Docebo::user()->getAcl();
                                 $idst = $this->aclManager->registerTempUser($userid, $firstname, $lastname, $pass, $email, 0, getLogUserId());
                                 require_once _base_ . "/lib/lib.eventmanager.php";
                                 $pl_man =& PlatformManager::createInstance();
                                 $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                                 // message to user that is waiting
                                 $msg_composer = new EventMessageComposer();
                                 $msg_composer->setSubjectLangText('email', '_WAITING_USER_SBJ', false);
                                 $msg_composer->setBodyLangText('email', '_WAITING_USER_TEXT', $array_subst);
                                 $msg_composer->setBodyLangText('sms', '_WAITING_USER_TEXT_SMS', $array_subst);
                                 // send message to the user subscribed
                                 createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' was modified', array($userid), $msg_composer);
                                 // set as recipients all who can approve a waiting user
                                 $msg_c_approve = new EventMessageComposer();
                                 $msg_c_approve->setSubjectLangText('email', '_TO_APPROVE_USER_SBJ', false);
                                 $msg_c_approve->setBodyLangText('email', '_TO_APPROVE_USER_TEXT', array('[url]' => Get::sett('url')));
                                 $msg_c_approve->setBodyLangText('sms', '_TO_APPROVE_USER_TEXT_SMS', array('[url]' => Get::sett('url')));
                                 $idst_approve = $acl->getRoleST('/framework/admin/directory/approve_waiting_user');
                                 $recipients = $this->aclManager->getAllRoleMembers($idst_approve);
                                 createNewAlert('UserNewModerated', 'directory', 'edit', '1', 'User ' . $userid . ' to moderate', $recipients, $msg_c_approve);
                                 $GLOBALS['page']->add(getResultUi($this->lang->def('_INSERTED_WAIT_FOR_ADMIN')));
                             }
                         }
                     } else {
                         $idst = $this->aclManager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '');
                         require_once _base_ . '/lib/lib.preference.php';
                         $preference = new UserPreferences($idst);
                         $preference->savePreferences($_POST, 'ui.');
                         require_once _base_ . "/lib/lib.eventmanager.php";
                         $pl_man =& PlatformManager::createInstance();
                         $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                         // message to user that is inserted
                         $msg_composer = new EventMessageComposer();
                         $msg_composer->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
                         $msg_composer->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
                         $msg_composer->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
                         createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' created', array($idst), $msg_composer);
                     }
                     if ($idst !== false) {
                         foreach ($arr_idst_groups as $idst_group) {
                             $this->aclManager->addToGroup($idst_group, $idst);
                         }
                         // add to group level
                         $this->aclManager->addToGroup($userlevel, $idst);
                         //-save extra field------------------------------------------
                         $fields->storeFieldsForUser($idst, $arr_idst_all);
                         //-----------------------------------------------------------
                     }
                 } else {
                     $this->op = 'reedit_person';
                     //$GLOBALS['page']->add(getErrorUi(implode('<br/>', $re_filled)), 'content');
                 }
             }
         }
     } elseif (isset($arrayState['deleteperson'])) {
         $idst = $_POST['idst'];
         if ($idst !== '') {
             require_once _base_ . "/lib/lib.eventmanager.php";
             $u_info = $this->aclManager->getUser($idst, false);
             $userid = $u_info[ACL_INFO_USERID];
             $pl_man =& PlatformManager::createInstance();
             $acl_man =& Docebo::user()->getAclManager();
             $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $acl_man->relativeId($userid));
             // message to user that is inserted
             $msg_composer = new EventMessageComposer();
             $msg_composer->setSubjectLangText('email', '_DELETED_USER_SBJ', false);
             $msg_composer->setBodyLangText('email', '_DELETED_USER_TEXT', $array_subst);
             $msg_composer->setBodyLangText('sms', '_DELETED_USER_TEXT_SMS', $array_subst);
             /*
             				createNewAlert(	'UserDel', 'directory', 'edit', '1', 'User '.$userid.' deleted',
             							array($idst), $msg_composer );*/
             $event =& DoceboEventManager::newEvent('UserDel', 'directory', 'edit', '1', 'User ' . addslashes($userid) . ' deleted');
             $event->setProperty('recipientid', implode(',', array($idst)));
             $event->setProperty('subject', $msg_composer->getSubject('email', getLanguage()));
             $event->setProperty('body', $msg_composer->getBody('email', getLanguage()));
             $msg_composer->prepare_serialize();
             $event->setProperty('MessageComposer', addslashes(rawurlencode(serialize($msg_composer))));
             $event->setProperty('userdeleted', $idst);
             DoceboEventManager::dispatch($event);
             $this->aclManager->deleteUser($idst);
             $GLOBALS['page']->add(getResultUi($this->lang->def('_OPERATION_SUCCESSFUL')));
         }
     }
     if (!isset($arrayState[$this->id])) {
         return;
     }
     foreach ($arrayState[$this->id] as $key => $action) {
         if ($key == 'save_newfolder') {
             $array_lang = Docebo::langManager()->getAllLangCode();
             $mand_lang = getLanguage();
             if (!isset($action[$mand_lang])) {
                 $this->op = 'newfolder';
             } else {
                 $folderName = array();
                 foreach ($array_lang as $langItem) {
                     $folderName[$langItem] = $arrayState[$this->id]['new_folder'][$langItem];
                 }
                 $this->tdb->addFolderByIdTranslation($this->selectedFolder, $folderName);
                 $this->refresh = TRUE;
             }
         } elseif ($key == 'save_renamefolder') {
             $array_lang = Docebo::langManager()->getAllLangCode();
             if ($this->getSelectedFolderId() == '0') {
                 $mand_lang = 'root';
             } else {
                 $mand_lang = getLanguage();
             }
             if (!isset($action[$mand_lang]) || $action[$mand_lang] == '') {
                 $this->op = 'renamefolder';
             } else {
                 $folder_id = $this->getSelectedFolderId();
                 $acl =& Docebo::user()->getACL();
                 //-extra field check mandatory -----------------------------
                 require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
                 $fields = new FieldList();
                 $fields->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
                 $fields->setFieldEntryTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDENTRYTABLE);
                 $folder_id = $this->getSelectedFolderId();
                 $folder =& $this->tdb->getFolderById($folder_id);
                 $ancestor = $this->tdb->getAllParentId($folder, $this->tdb);
                 array_push($ancestor, $folder_id);
                 //$filled = $fields->isFilledFieldsForUser($folder_id, $ancestor, FALSE );
                 //----------------------------------------------------------
                 //if( $filled === true ) {
                 $folderName = array();
                 if ($this->getSelectedFolderId() == '0') {
                     // is root
                     $folderName = $arrayState[$this->id]['rename_folder']['root'];
                     $query_root_name = "\r\n\t\t\t\t\t\t\tUPDATE " . $GLOBALS['prefix_fw'] . "_setting \r\n\t\t\t\t\t\t\tSET param_value = '" . $folderName . "'\r\n\t\t\t\t\t\t\tWHERE param_name = 'title_organigram_chart'";
                     sql_query($query_root_name);
                 } else {
                     foreach ($array_lang as $langItem) {
                         $folderName[$langItem] = $arrayState[$this->id]['rename_folder'][$langItem];
                     }
                     $this->tdb->updateFolderByIdTranslation($this->selectedFolder, $folderName);
                 }
                 //-extra field store --------------------------------------
                 $folder_idst = $this->tdb->getGroupST($folder_id);
                 $fl = new FieldList();
                 $fl->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
                 $fl->setFieldEntryTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDENTRYTABLE);
                 $arr_groups_filterd = $acl->getSTGroupsST($folder_idst, FILTER_FOLD);
                 $fl->storeFieldsForUser($folder_id, $ancestor, FALSE);
                 //----------------------------------------------------------
                 $this->refresh = TRUE;
                 if ($this->getSelectedFolderId() == '0') {
                     Util::jump_to('index.php?modname=directory&op=org_chart');
                 }
                 /*} else {
                 			
                 			$this->op = 'renamefolder';
                 			$GLOBALS['page']->add( getErrorUi(implode('<br/>', $filled)), 'content' );
                 		}*/
             }
         } elseif ($key == 'next_formfield1') {
             $this->op = 'folder_field2';
         } elseif ($key == 'save_formfield') {
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             if (isset($arrayState[$this->id]['field_set'])) {
                 $arr_fields = $arrayState[$this->id]['field_set'];
             } else {
                 $arr_fields = array();
             }
             if (isset($arrayState[$this->id]['field_mandatory'])) {
                 $arr_fields_mandatory = $arrayState[$this->id]['field_mandatory'];
             } else {
                 $arr_fields_mandatory = array();
             }
             $fl = new FieldList();
             $fl->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
             $arr_all_fields = $fl->getAllFields();
             $id_folder = $this->getSelectedFolderId();
             // remove all fields
             foreach ($arr_all_fields as $id_field => $field) {
                 $fl->removeFieldFromGroup($id_field, $id_folder);
             }
             // add selected fields
             foreach ($arr_fields as $id_field => $dummy_val) {
                 $fl->addFieldToGroup($id_field, $id_folder, isset($arr_fields_mandatory[$id_field]) ? $arr_fields_mandatory[$id_field] : 'false');
             }
         } elseif ($key == 'next1_assignfield') {
             $this->op = 'assign2_field';
         } elseif ($key == 'next2_assignfield') {
             $this->op = 'assign3_field';
         } elseif ($key == 'save_assignfield') {
             $arr_fields = $arrayState[$this->id]['field_set'];
             $arr_fields_mandatory = isset($arrayState[$this->id]['field_mandatory']) ? $arrayState[$this->id]['field_mandatory'] : array();
             $arr_fields_useraccess = isset($arrayState[$this->id]['field_useraccess']) ? $arrayState[$this->id]['field_useraccess'] : array();
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             $fl = new FieldList();
             foreach ($arr_fields as $id_filed => $status) {
                 switch ($status) {
                     case ORG_CHART_FIELD_NO:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()));
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()));
                         break;
                     case ORG_CHART_FIELD_NORMAL:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()));
                         $fl->addFieldToGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()), isset($arr_fields_mandatory[$id_filed]) ? $arr_fields_mandatory[$id_filed] : 'false', isset($arr_fields_useraccess[$id_filed]) ? $arr_fields_useraccess[$id_filed] : 'readonly');
                         break;
                     case ORG_CHART_FIELD_DESCEND:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()));
                         $fl->addFieldToGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()), isset($arr_fields_mandatory[$id_filed]) ? $arr_fields_mandatory[$id_filed] : 'false', isset($arr_fields_useraccess[$id_filed]) ? $arr_fields_useraccess[$id_filed] : 'readonly');
                         break;
                 }
             }
         } elseif ($key == $this->_getOpFolderField()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'folder_field';
         } elseif ($key == $this->_getOpImportUsers()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'import_users';
         } elseif ($key == 'next1_importusers') {
             $this->op = 'import_users2';
         } elseif ($key == 'next2_importusers') {
             $this->op = 'import_users3';
         } elseif ($key == $this->_getOpAssignField()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'assign_field';
         } elseif ($key == $this->_getOpAssignUser()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'addtotree';
         } elseif ($key == $this->_getOpCreateUser()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'create_user';
         } elseif ($key == $this->_getOpWaitingUser()) {
             $this->op = 'waiting_user';
         }
     }
     return;
     $arrayExpand = $arrayExpand;
     $arrayCompress = $arrayCompress;
 }
Exemple #7
0
 function savesel()
 {
     checkPerm('view');
     require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
     require_once _base_ . '/lib/lib.form.php';
     $lang =& DoceboLanguage::createInstance('register', 'lms');
     $mand_sym = '<span class="mandatory">*</span>';
     $extra_field = new FieldList();
     $GLOBALS['page']->add(getTitleArea($lang->def('_MYGROUP'), 'mygroup') . '<div class="std_block">', 'content');
     $selected = array();
     if (isset($_POST['group_sel'])) {
         $selected = $_POST['group_sel'];
     } elseif (isset($_POST['group_sel_implode'])) {
         $selected = explode(',', $_POST['group_sel_implode']);
     }
     $play_field = $extra_field->playFieldsForUser(getLogUserId(), $selected, false, false, array('readonly'));
     if (isset($_POST['save_field']) || $play_field === false || $play_field == '') {
         $re_filled = $extra_field->isFilledFieldsForUser(getLogUserId(), $selected);
         if (!$re_filled) {
             $GLOBALS['page']->add(getErrorUi($lang->def('_SOME_MANDATORY_EMPTY')), 'content');
         } else {
             $acl =& Docebo::user()->getAcl();
             $acl_man =& Docebo::user()->getAclManager();
             $groups =& $acl_man->getAllGroupsId(array('free', 'moderate'));
             $groups_id = array_keys($groups);
             $user_group = $acl->getSTGroupsST(getLogUserId());
             $add_groups = array_diff($selected, $user_group);
             $del_groups = array_diff($groups_id, $selected);
             $moderate_add = false;
             if (!empty($add_groups)) {
                 while (list(, $idst) = each($add_groups)) {
                     if ($groups[$idst]['type'] == 'free') {
                         $acl_man->addToGroup($idst, getLogUserId());
                     } elseif ($groups[$idst]['type'] == 'moderate') {
                         $acl_man->addToWaitingGroup($idst, getLogUserId());
                         $moderate_add = true;
                     }
                 }
             }
             if ($moderate_add === true) {
                 require_once _base_ . '/lib/lib.eventmanager.php';
                 // message to user that is odified
                 $msg_composer = new EventMessageComposer();
                 $msg_composer->setSubjectLangText('email', '_TO_APPROVE_GROUP_USER_SBJ', false);
                 $msg_composer->setBodyLangText('email', '_TO_APPROVE_GROUP_USER_TEXT', array('[url]' => Get::sett('url')));
                 $msg_composer->setBodyLangText('sms', '_TO_APPROVE_GROUP_USER_TEXT_SMS', array('[url]' => Get::sett('url')));
                 $idst_approve = $acl->getRoleST('/framework/admin/directory/editgroup');
                 $recipients = $acl_man->getAllRoleMembers($idst_approve);
                 createNewAlert('UserGroupModerated', 'directory', 'moderate', '1', 'User group subscription to moderate', $recipients, $msg_composer);
             }
             if (!empty($del_groups)) {
                 while (list(, $idst_group) = each($del_groups)) {
                     $extra_field->removeUserEntry(getLogUserId(), $idst_group);
                     $acl_man->removeFromGroup($idst_group, getLogUserId());
                 }
             }
             // Save fields
             $extra_field->storeFieldsForUser(getLogUserId());
             Util::jump_to('index.php?modname=mygroup&amp;op=group');
         }
     }
     $GLOBALS['page']->add('<div class="reg_note">' . $lang->def('_GROUPS_FIELDS') . '<ul class="reg_instruction">' . '<li>' . str_replace('[mandatory]', $mand_sym, $lang->def('_REG_MANDATORY')) . '</li>' . '</ul>' . '</div>' . Form::openForm('group_subscription', 'index.php?modname=mygroup&amp;op=savesel') . Form::openElementSpace() . Form::getHidden('group_sel_implode', 'group_sel_implode', isset($_POST['group_sel_implode']) ? $_POST['group_sel_implode'] : implode(',', $selected)) . $play_field . Form::getBreakRow() . Form::closeElementSpace() . Form::openButtonSpace() . Form::getButton('save_field', 'save_field', $lang->def('_SAVE')) . Form::closeButtonSpace() . Form::closeForm() . '</div>', 'content');
 }
Exemple #8
0
 function upcourseinfo()
 {
     checkPerm('mod');
     $array_lang = Docebo::langManager()->getAllLangCode();
     $user_status = 0;
     if (isset($_POST['user_status'])) {
         while (list($status) = each($_POST['user_status'])) {
             $user_status |= 1 << $status;
         }
     }
     $file_sponsor = '';
     $file_logo = '';
     $re = true;
     $show_level = 0;
     if (isset($_POST['course_show_level'])) {
         while (list($lv) = each($_POST['course_show_level'])) {
             $show_level |= 1 << $lv;
         }
     }
     $query_course = "\r\n\tUPDATE " . $GLOBALS['prefix_lms'] . "_course \r\n\tSET code = '" . $_POST['course_code'] . "', \r\n\t\tname = '" . $_POST['course_name'] . "', \r\n\t\tdescription = '" . $_POST['course_descr'] . "', \r\n\t\tlang_code = '" . $array_lang[$_POST['course_lang']] . "', \r\n\t\tstatus = '" . (int) $_POST['course_status'] . "', \r\n\t\tlevel_show_user = '******', \r\n\t\tmediumTime = '" . $_POST['course_medium_time'] . "',\r\n\t\tpermCloseLO = '" . $_POST['course_em'] . "', \r\n\t\tuserStatusOp = '" . $user_status . "', \r\n\t\tdifficult = '" . $_POST['course_difficult'] . "', \r\n\t\tshow_progress = '" . (isset($_POST['course_progress']) ? 1 : 0) . "', \r\n\t\tshow_time = '" . (isset($_POST['course_time']) ? 1 : 0) . "', \r\n\t\tshow_extra_info = '" . (isset($_POST['course_advanced']) ? 1 : 0) . "', \r\n\t\tshow_rules = '" . (int) $_POST['course_show_rules'] . "' \r\n\tWHERE idCourse = '" . $_SESSION['idCourse'] . "'";
     if (!sql_query($query_course)) {
         $re = false;
     }
     $acl_man =& Docebo::user()->getAclManager();
     // send alert
     require_once _base_ . '/lib/lib.eventmanager.php';
     $msg_composer = new EventMessageComposer();
     $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT_MODCOURSE_INFO', false);
     $msg_composer->setBodyLangText('email', '_ALERT_TEXT_MODCOURSE_INFO', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_code'], '[course]' => $_POST['course_name']));
     $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_MODCOURSE_INFO_SMS', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_code'], '[course]' => $_POST['course_name']));
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     $course_man = new Man_Course();
     $recipients = $course_man->getIdUserOfLevel($_SESSION['idCourse']);
     createNewAlert('CoursePorpModified', 'course', 'add', '1', 'Inserted course ' . $_POST['course_name'], $recipients, $msg_composer);
     Util::jump_to('index.php?modname=course&op=infocourse&result=' . ($re ? 'ok' : 'err'));
 }
 public function setUnsubscribeRequest($id_user, $id_course, $id_edition = FALSE, $id_date = FALSE)
 {
     if ($id_user <= 0 || $id_course <= 0) {
         return FALSE;
     }
     $cmodel = new CourseAlms();
     $cinfo = $cmodel->getCourseModDetails($id_course);
     switch ((int) $cinfo['auto_unsubscribe']) {
         case 0:
             return FALSE;
             break;
         case 1:
         case 2:
             if ($cinfo['unsubscribe_date_limit'] != "" && $cinfo['unsubscribe_date_limit'] != "0000-00-00 00:00:00") {
                 if ($cinfo['unsubscribe_date_limit'] < date("Y-m-d H:i:s")) {
                     return FALSE;
                 }
             }
             break;
     }
     if ($id_date > 0) {
         $query = "UPDATE %lms_course_date_user SET requesting_unsubscribe = 1, requesting_unsubscribe_date = NOW() " . " WHERE id_user = "******" AND id_date = " . (int) $id_date;
     } else {
         if ($id_edition > 0) {
             $query = "UPDATE %lms_course_editions_user SET requesting_unsubscribe = 1, requesting_unsubscribe_date = NOW() " . " WHERE id_user = "******" AND id_edition = " . (int) $id_edition;
         } else {
             $query = "UPDATE %lms_courseuser SET requesting_unsubscribe = 1, requesting_unsubscribe_date = NOW() " . " WHERE idUser = "******" AND idCourse = " . (int) $id_course;
         }
     }
     $res = $this->db->query($query);
     // check and send message for unsibscription moderated
     if ($res && (int) $cinfo['auto_unsubscribe'] == 1) {
         //moderated self unsubscribe
         $userinfo = $this->acl_man->getUser($id_user);
         $array_subst = array('[url]' => Get::sett('url'), '[course]' => $cinfo['name'], '[firstname]' => $userinfo[ACL_INFO_FIRSTNAME], '[lastname]' => $userinfo[ACL_INFO_LASTNAME], '[userid]' => $this->acl_man->relativeId($userinfo[ACL_INFO_USERID]));
         // message to user that is waiting
         require_once _base_ . '/lib/lib.eventmanager.php';
         $msg_composer = new EventMessageComposer('subscribe', 'lms');
         $msg_composer->setSubjectLangText('email', '_NEW_USER_UNSUBS_WAITING_SUBJECT', false);
         $msg_composer->setBodyLangText('email', '_NEW_USER_UNSUBS_WAITING_TEXT', $array_subst);
         $msg_composer->setSubjectLangText('sms', '_NEW_USER_UNSUBS_WAITING_SUBJECT_SMS', false);
         $msg_composer->setBodyLangText('sms', '_NEW_USER_UNSUBS_WAITING_TEXT_SMS', $array_subst);
         $acl =& Docebo::user()->getAcl();
         $acl_man =& $this->acl_man;
         $recipients = array();
         $idst_group_god_admin = $acl->getGroupST(ADMIN_GROUP_GODADMIN);
         $recipients = $acl_man->getGroupMembers($idst_group_god_admin);
         $idst_group_admin = $acl->getGroupST(ADMIN_GROUP_ADMIN);
         $idst_admin = $acl_man->getGroupMembers($idst_group_admin);
         require_once _adm_ . '/lib/lib.adminmanager.php';
         foreach ($idst_admin as $id_user) {
             $adminManager = new AdminManager();
             $acl_manager =& $acl_man;
             $idst_associated = $adminManager->getAdminTree($id_user);
             $array_user =& $acl_manager->getAllUsersFromIdst($idst_associated);
             $array_user = array_unique($array_user);
             $array_user[] = $array_user[0];
             unset($array_user[0]);
             $control_user = array_search(getLogUserId(), $array_user);
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'course'" . " AND id_entry = '" . $id_course . "'";
             list($control_course) = mysql_fetch_row(mysql_query($query));
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'coursepath'" . " AND id_entry IN" . " (" . " SELECT id_path" . " FROM " . Get::cfg('prefix_lms') . "_coursepath_courses" . " WHERE id_item = '" . $id_course . "'" . " )";
             list($control_coursepath) = mysql_fetch_row(mysql_query($query));
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'catalogue'" . " AND id_entry IN" . " (" . " SELECT idCatalogue" . " FROM " . Get::cfg('prefix_lms') . "_catalogue_entry" . " WHERE idEntry = '" . $id_course . "'" . " )";
             list($control_catalogue) = mysql_fetch_row(mysql_query($query));
             if ($control_user && ($control_course || $control_coursepath || $control_catalogue)) {
                 $recipients[] = $id_user;
             }
         }
         $recipients = array_unique($recipients);
         createNewAlert('UserCourseRemovedModerate', 'unsubscribe', 'insert', '1', 'User unsubscribed with moderation', $recipients, $msg_composer);
     }
     return $res ? TRUE : FALSE;
 }
 function approveusers()
 {
     if (!$this->permissions['moderate']) {
         die("You can't access");
     }
     require_once _lms_ . '/lib/lib.course.php';
     require_once _base_ . '/lib/lib.preference.php';
     $id_course = Get::req('id_course', DOTY_INT, 0);
     $course_info = Man_Course::getCourseInfo($id_course);
     $edition_id = Get::req('id_edition', DOTY_INT, 0);
     $re = true;
     $approve_user = array();
     $deny_user = array();
     if (isset($_POST['waiting_user'])) {
         $man_course = new Man_Course();
         $waiting_users =& $man_course->getWaitingSubscribed($id_course);
         $tot_deny = array();
         require_once _lms_ . '/lib/lib.course.php';
         require_once _lms_ . '/admin/modules/subscribe/subscribe.php';
         $docebo_course = new DoceboCourse($id_course);
         $group_levels = $docebo_course->getCourseLevel($id_course);
         if (count($group_levels) == 0 || $group_levels[1] == '') {
             $group_levels =& $docebo_course->createCourseLevel($id_course);
         }
         while (list($id_user, $action) = each($_POST['waiting_user'])) {
             if ($action == 0) {
                 // approved -----------------------------------------------
                 $text_query = "\r\n\t\t\t\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t\t\tSET waiting = 0,\r\n\t\t\t\t\t\tstatus = '" . _CUS_SUBSCRIBED . "'\r\n\t\t\t\t\tWHERE idCourse = '" . $id_course . "' AND idUser = '******' ";
                 $text_query .= "AND edition_id='" . $edition_id . "'";
                 $result = sql_query($text_query);
                 if ($result) {
                     $approve_user[] = $id_user;
                 }
                 $re &= $result;
             } elseif ($action == 1) {
                 // refused --------------------------------------------------
                 $level = $waiting_users['users_info'][$id_user]['level'];
                 $sub_by = $waiting_users['users_info'][$id_user]['subscribed_by'];
                 $result = removeSubscription($id_course, $id_user, $group_levels[$level], $edition_id);
                 if ($sub_by != 0 && $id_user != $sub_by) {
                     if (isset($tot_deny[$sub_by])) {
                         $tot_deny[$sub_by]++;
                     } else {
                         $tot_deny[$sub_by] = 1;
                     }
                 }
                 if ($result) {
                     $deny_user[] = $id_user;
                 }
                 $re &= $result;
             }
         }
     }
     if (!empty($tot_deny)) {
         while (list($id_user, $inc) = each($tot_deny)) {
             $pref = new UserPreferences($id_user);
             $max_subscribe = $pref->getAdminPreference('admin_rules.max_course_subscribe');
             $pref->setPreference('admin_rules.max_course_subscribe', $max_subscribe + $inc);
         }
     }
     require_once _base_ . '/lib/lib.eventmanager.php';
     $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name']);
     if (!empty($approve_user)) {
         $msg_composer = new EventMessageComposer();
         $msg_composer->setSubjectLangText('email', '_APPROVED_SUBSCRIBED_SUBJECT', false);
         $msg_composer->setBodyLangText('email', '_APPROVED_SUBSCRIBED_TEXT', $array_subst);
         $msg_composer->setBodyLangText('email', "\n\n" . $_POST['subscribe_accept'], array(), true);
         $msg_composer->setBodyLangText('sms', '_APPROVED_SUBSCRIBED_TEXT_SMS', $array_subst);
         // send message to the user subscribed
         createNewAlert('UserCourseInserted', 'subscribe', 'approve', '1', 'User course approve', $approve_user, $msg_composer, true);
     }
     if (!empty($deny_user)) {
         $msg_composer = new EventMessageComposer();
         $msg_composer->setSubjectLangText('email', '_DENY_SUBSCRIBED_SUBJECT', false);
         $msg_composer->setBodyLangText('email', '_DENY_SUBSCRIBED_TEXT', $array_subst);
         $msg_composer->setBodyLangText('email', "\n\n" . $_POST['subscribe_refuse'], array(), true);
         $msg_composer->setSubjectLangText('sms', '_DENY_SUBSCRIBED_SUBJECT_SMS', false);
         $msg_composer->setBodyLangText('sms', '_DENY_SUBSCRIBED_TEXT_SMS', $array_subst);
         // send message to the user subscribed
         createNewAlert('UserCourseInserted', 'subscribe', 'deny', '1', 'User course deny', $deny_user, $msg_composer, true);
     }
     Util::jump_to('index.php?r=' . $this->link_course . '/show&res=' . ($re ? 'ok' : 'err'));
 }
 function confirmRegister($platform, $options)
 {
     $lang =& DoceboLanguage::createInstance('register', $platform);
     $acl_man =& Docebo::user()->getAclManager();
     $acl =& Docebo::user()->getAcl();
     if (!isset($_GET['random_code'])) {
     }
     $random_code = $_GET['random_code'];
     if (strpos($random_code, '?') !== false) {
         $random_code = substr($random_code, 0, strpos($random_code, '?'));
     }
     $request = $acl_man->getTempUserInfo(false, $random_code);
     if (time() > fromDatetimeToTimestamp($request['request_on']) + 3600 * (int) $options['hour_request_limit']) {
         $out = '<div class="reg_err_data">' . $lang->def('_REG_ELAPSEDREQUEST', 'register') . '</div>';
         $time_limit = time() - 3600 * (int) $options['hour_request_limit'];
         if (Get::sett('registration_code_type', '0') == 'code_module') {
             // free the code from the old association
             require_once _adm_ . '/lib/lib.code.php';
             $code_manager = new CodeManager();
             $code_manager->resetUserAssociation($code, $request['idst']);
         }
         $acl_man->deleteTempUser(false, false, $time_limit, true);
         return $out;
     }
     if ($options['register_type'] == 'self' || $options['register_type'] == 'self_optin') {
         if ($acl_man->registerUser(addslashes($request['userid']), addslashes($request['firstname']), addslashes($request['lastname']), $request['pass'], addslashes($request['email']), '', '', true, $request['idst'], '', '', $request['facebook_id'], $request['twitter_id'], $request['linkedin_id'], $request['google_id'])) {
             // $google_id
             // remove temporary enter
             $acl_man->deleteTempUser($request['idst'], false, false, false);
             $acl_man->updateUser($request['idst'], FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, date("Y-m-d H:i:s"));
             // subscribe to base group
             $idst_usergroup = $acl_man->getGroup(false, ADMIN_GROUP_USER);
             $idst_usergroup = $idst_usergroup[ACL_INFO_IDST];
             $idst_oc = $acl_man->getGroup(false, '/oc_0');
             $idst_oc = $idst_oc[ACL_INFO_IDST];
             $idst_ocd = $acl_man->getGroup(false, '/ocd_0');
             $idst_ocd = $idst_ocd[ACL_INFO_IDST];
             $acl_man->addToGroup($idst_usergroup, $request['idst']);
             $acl_man->addToGroup($idst_oc, $request['idst']);
             $acl_man->addToGroup($idst_ocd, $request['idst']);
             //  aggiunta notifica UserNewWaiting
             require_once _base_ . "/lib/lib.eventmanager.php";
             // set as recipients all who can approve a waiting user
             $msg_c_new = new EventMessageComposer();
             $msg_c_new->setSubjectLangText('email', '_TO_NEW_USER_SBJ', false);
             $msg_c_new->setBodyLangText('email', '_TO_NEW_USER_TEXT', array('[url]' => Get::sett('url')));
             $msg_c_new->setBodyLangText('sms', '_TO_NEW_USER_TEXT_SMS', array('[url]' => Get::sett('url')));
             $idst_approve = $acl->getRoleST('/framework/admin/directory/approve_waiting_user');
             $recipients = $acl_man->getAllRoleMembers($idst_approve);
             if (!empty($recipients)) {
                 createNewAlert('UserNewWaiting', 'directory', 'edit', '1', 'User waiting for approvation', $recipients, $msg_c_new);
             }
             // end
             $out = '<div class="reg_success">' . $lang->def('_REG_YOUR_ABI_TO_ACCESS', 'register') . '</div>';
             return $out;
         } else {
             $out = '<div class="reg_err_data">' . $lang->def('_REG_CONFIRM_FAILED', 'register') . '</div>';
             return $out;
         }
     } elseif ($options['register_type'] == 'moderate') {
         if ($acl_man->confirmTempUser($request['idst'])) {
             if (Get::sett('use_code_module') == 'on') {
                 require_once $GLOBALS['where_framework'] . '/lib/lib.code.php';
                 $code_manager = new CodeManager();
                 $code = $code_manager->getCodeAssociate($request['idst']);
                 if ($code !== false) {
                     $array_course = $code_manager->getCourseAssociateWithCode($code);
                     $array_folder = $code_manager->getOrgAssociateWithCode($code);
                     if (count($array_course)) {
                         foreach ($array_course as $id_course) {
                             require_once $GLOBALS['where_lms'] . '/lib/lib.subscribe.php';
                             $subscribe = new CourseSubscribe_Management();
                             $subscribe->subscribeUser($request['idst'], $id_course, '3');
                         }
                     }
                     if (count($array_folder)) {
                         foreach ($array_folder as $id_folder) {
                             $group = $acl_man->getGroup($id_folder, false);
                             $group_d = $acl_man->getGroup(false, '/ocd_' . str_replace('/oc_', '', $group[ACL_INFO_GROUPID]));
                             if ($group) {
                                 $acl_man->addToGroup($group[ACL_INFO_IDST], $request['idst']);
                             }
                             if ($group_d) {
                                 $acl_man->addToGroup($group_d[ACL_INFO_IDST], $request['idst']);
                             }
                         }
                     }
                 }
             }
             $out = '<div class="reg_success">' . Lang::t('_REG_WAIT_FOR_ADMIN_OK', 'register') . '</div>';
             // send alert to admin that can approve
             require_once _base_ . "/lib/lib.eventmanager.php";
             // set as recipients all who can approve a waiting user
             $msg_c_approve = new EventMessageComposer();
             $msg_c_approve->setSubjectLangText('email', '_TO_APPROVE_USER_SBJ', false);
             $msg_c_approve->setBodyLangText('email', '_TO_APPROVE_USER_TEXT', array('[url]' => Get::sett('url')));
             $msg_c_approve->setBodyLangText('sms', '_TO_APPROVE_USER_TEXT_SMS', array('[url]' => Get::sett('url')));
             $idst_approve = $acl->getRoleST('/framework/admin/directory/approve_waiting_user');
             $recipients = $acl_man->getAllRoleMembers($idst_approve);
             if (!empty($recipients)) {
                 createNewAlert('UserNewModerated', 'directory', 'edit', '1', 'User waiting for approvation', $recipients, $msg_c_approve);
             }
             return $out;
         } else {
             $out = '<div class="reg_err_data">' . $lang->def('_REG_CONFIRM_FAILED', 'register') . '</div>';
             return $out;
         }
     }
 }
 function createuser_action()
 {
     //check permissions
     if (!$this->permissions['add_user']) {
         $output = array('success' => false, 'message' => $this->_getErrorMessage('no permission'));
         echo $this->echoResult($output);
         return;
     }
     $userid = Get::req('username', DOTY_STRING, '');
     $password = Get::Req('password', DOTY_STRING, '');
     $password_confirm = Get::req('password_confirm', DOTY_STRING, '');
     $output = array();
     if ($userid == '') {
         $output['success'] = false;
         $output['message'] = Lang::t('_ERR_INVALID_USER', 'register');
         echo $this->echoResult($output);
         return;
     }
     if ($password != $password_confirm) {
         $output['success'] = false;
         $output['message'] = Lang::t('_ERR_PASSWORD_NO_MATCH', 'register');
         echo $this->echoResult($output);
         return;
     }
     $userdata = new stdClass();
     $userdata->userid = trim($userid);
     $userdata->firstname = trim(Get::req('firstname', DOTY_STRING, ''));
     $userdata->lastname = trim(Get::req('lastname', DOTY_STRING, ''));
     $userdata->email = trim(Get::req('email', DOTY_STRING, ''));
     $userdata->password = $password;
     $userdata->force_change = trim(Get::Req('force_changepwd', DOTY_INT, 0));
     /* $userdata->facebook_id = Get::pReq('facebook_id', DOTY_STRING, '');
     		$userdata->twitter_id = Get::pReq('twitter_id', DOTY_STRING, '');
     		$userdata->linkedin_id = Get::pReq('linkedin_id', DOTY_STRING, '');
     		$userdata->google_id = Get::pReq('google_id', DOTY_STRING, ''); */
     if (Docebo::user()->user_level == ADMIN_GROUP_GODADMIN) {
         $userdata->level = Get::req('level', DOTY_STRING, ADMIN_GROUP_USER);
     } else {
         $userdata->level = ADMIN_GROUP_USER;
     }
     if (!$this->model->checkUserid($userdata->userid)) {
         $output['success'] = false;
         $output['message'] = Lang::t('_USERID_DUPLICATE', 'organization_chart');
         echo $this->echoResult($output);
         return;
     }
     if (!$this->_canUseLevel($userdata->level)) {
         $output['success'] = false;
         $output['message'] = Lang::t('_OPERATION_FAILURE', 'standard');
         echo $this->echoResult($output);
         return;
     }
     if (Get::sett('pass_change_first_login', 'off') == 'on') {
         $userdata->force_change = 1;
     }
     $userdata->preferences =& $_POST;
     $folders = Get::req('sel', DOTY_MIXED, false);
     $idst = $this->model->createUser($userdata, $folders);
     if (is_numeric($idst) && $idst > 0) {
         $output['success'] = true;
         $output['idst'] = $idst;
         $output['total_users'] = $this->model->getUsersCount();
         $output['message'] = Lang::t('_OPERATION_SUCCESSFUL', 'standard') . ': ' . $userid;
         // Send alert:
         require_once _base_ . '/lib/lib.eventmanager.php';
         $acl_man = Docebo::user()->getAclManager();
         $array_subst = array('[url]' => Get::sett('url'), '[userid]' => $userid, '[password]' => $password);
         $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);
         if (!empty($recipients)) {
             createNewAlert('UserNew', 'directory', 'edit', '1', 'New user created', $recipients, $e_msg);
             ob_clean();
         }
         // Increment the counter for users created by this admin:
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             $admin_pref = new AdminPreference();
             $pref = $admin_pref->getAdminRules(Docebo::user()->getIdSt());
             if ($pref['admin_rules.limit_user_insert'] == 'on') {
                 $user_pref = new UserPreferences(Docebo::user()->getIdSt());
                 $user_created_count = (int) $user_pref->getPreference('user_created_count');
                 $user_created_count++;
                 $user_pref->setPreference('user_created_count', $user_created_count);
                 if ($user_created_count >= $pref['admin_rules.max_user_insert']) {
                     $output['force_page_refresh'] = true;
                     $output['message'] = Lang::t('_USER_CREATED_MAX_REACHED', 'admin_directory');
                 }
             }
         }
     } else {
         $output['success'] = false;
         $output['message'] = Lang::t('_OPERATION_FAILURE', 'standard');
     }
     $this->echoResult($output);
 }
Exemple #13
0
 function writemessage()
 {
     $send_all = true;
     // checkPerm('send_all', true);
     $send_upper = true;
     // checkPerm('send_upper', true);
     if (!$send_all && !$send_upper) {
         die("You can't access");
     }
     require_once _base_ . '/lib/lib.userselector.php';
     $out = $GLOBALS['page'];
     $out->setWorkingZone('content');
     $from = importVar('out');
     $acl_man =& Docebo::user()->getAclManager();
     $um =& UrlManager::getInstance("message");
     if (!isset($_POST['message']['recipients'])) {
         if (isset($_GET['reply_recipients'])) {
             $user_selected = unserialize(stripslashes(urldecode($_GET['reply_recipients'])));
             $recipients = urlencode(serialize($user_selected));
         } else {
             $user_select = new UserSelector();
             $user_selected = $user_select->getSelection($_POST);
             $recipients = urlencode(serialize($user_selected));
         }
     } else {
         $user_selected = unserialize(urldecode($_POST['message']['recipients']));
         $recipients = urlencode($_POST['message']['recipients']);
     }
     $title_url = $this->mvc_urls ? "index.php?r=message/show" . ($from == 'out' ? '&active_tab=outbox' : '') : $um->getUrl($from == 'out' ? '&active_tab=outbox' : '');
     $output = "";
     $output .= $this->messageGetTitleArea(array($title_url => Lang::t('_MESSAGES'), Lang::t('_SEND')), 'message') . '<div class="std_block">';
     if (isset($_POST['send'])) {
         if ($_POST['message']['subject'] == '') {
             $output .= getErrorUi(Lang::t('_MUST_INS_SUBJECT'));
         } else {
             // send message
             $attach = '';
             if ($_FILES['message']['tmp_name']['attach'] != '') {
                 $attach = $this->saveMessageAttach($_FILES['message']);
             }
             $query_mess = "\r\n\t\t\t\tINSERT INTO %adm_message\r\n\t\t\t\t( idCourse, sender, posted, title, textof, attach, priority ) VALUES\r\n\t\t\t\t(\r\n\t\t\t\t\t'" . $_POST['msg_course_filter'] . "',\r\n\t\t\t\t\t'" . getLogUserId() . "',\r\n\t\t\t\t\t'" . date("Y-m-d H:i:s") . "',\r\n\t\t\t\t\t'" . $_POST['message']['subject'] . "',\r\n\t\t\t\t\t'" . $_POST['message_textof'] . "',\r\n\t\t\t\t\t'" . addslashes($attach) . "',\r\n\t\t\t\t\t'" . $_POST['message']['priority'] . "'\r\n\t\t\t\t)";
             if (!$this->db->query($query_mess)) {
                 if ($attach) {
                     deleteAttach($attach);
                 }
                 $jump_url = $this->mvc_urls ? "index.php?r=message/show&result=err" : $um->getUrl('result=err');
                 Util::jump_to($jump_url);
             }
             list($id_message) = $this->db->fetch_row($this->db->query("SELECT LAST_INSERT_ID()"));
             if (!in_array(getLogUserId(), $user_selected)) {
                 $user_selected[] = getLogUserId();
             }
             $send_to_idst =& $acl_man->getAllUsersFromIdst($user_selected);
             $re = true;
             $recip_alert = array();
             if (is_array($send_to_idst)) {
                 $logged_user = getLogUserId();
                 while (list(, $id_recipient) = each($send_to_idst)) {
                     $query_recipients = "\r\n\t\t\t\t\t\tINSERT INTO %adm_message_user\r\n\t\t\t\t\t\t( idMessage, idUser, idCourse, `read` ) VALUES\r\n\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t'" . $id_message . "',\r\n\t\t\t\t\t\t\t'" . $id_recipient . "',\r\n\t\t\t\t\t\t\t'" . $_POST['msg_course_filter'] . "',\r\n\t\t\t\t\t\t\t'" . ($id_recipient == $logged_user ? _MESSAGE_MY : _MESSAGE_UNREADED) . "'\r\n\t\t\t\t\t\t) ";
                     $re_single = $this->db->query($query_recipients);
                     if ($re_single && $id_recipient != $logged_user) {
                         $recip_alert[] = $id_recipient;
                     }
                     $re &= $re_single;
                 }
                 if (!empty($recip_alert)) {
                     require_once _lms_ . '/lib/lib.course.php';
                     require_once _base_ . '/lib/lib.eventmanager.php';
                     $is_course = false;
                     if (isset($_SESSION['idCourse']) && isset($GLOBALS['course_descriptor'])) {
                         $course_name = $GLOBALS['course_descriptor']->getValue('name');
                         $is_course = true;
                     } elseif ($_POST['msg_course_filter'] != 0 && is_numeric($_POST['msg_course_filter'])) {
                         $idCourse = $_POST['msg_course_filter'];
                         $query_course = "SELECT name FROM %lms_course WHERE idCourse = " . $idCourse;
                         $course_result = $this->db->fetch_row($this->db->query($query_course));
                         list($name) = $course_result;
                         $course_name = $name;
                         $is_course = true;
                     } else {
                         $course_name = '';
                     }
                     // message to user that is odified
                     $msg_composer = new EventMessageComposer();
                     $msg_composer->setSubjectLangText('email', '_YOU_RECIVE_MSG_SUBJECT', false);
                     if (!$is_course) {
                         $msg_composer->setBodyLangText('email', '_YOU_RECIVE_MSG_TEXT', array('[url]' => _MESSAGE_PL_URL, '[course]' => $course_name, '[from]' => Docebo::user()->getUsername()));
                         $msg_composer->setBodyLangText('sms', '_YOU_RECIVE_MSG_TEXT_SMS', array('[url]' => _MESSAGE_PL_URL, '[course]' => $course_name, '[from]' => Docebo::user()->getUsername()));
                     } else {
                         $msg_composer->setBodyLangText('email', '_YOU_RECIVE_MSG_TEXT_COURSE', array('[url]' => _MESSAGE_PL_URL, '[course]' => $course_name, '[from]' => Docebo::user()->getUsername()));
                         $msg_composer->setBodyLangText('sms', '_YOU_RECIVE_MSG_TEXT_SMS_COURSE', array('[url]' => _MESSAGE_PL_URL, '[course]' => $course_name, '[from]' => Docebo::user()->getUsername()));
                     }
                     createNewAlert('MsgNewReceived', 'directory', 'moderate', '1', 'User group subscription to moderate', $recip_alert, $msg_composer);
                 }
             }
             $jump_url = $this->mvc_urls ? "index.php?r=message/show&result=" . ($re ? 'ok' : 'err') : $um->getUrl('result=' . ($re ? 'ok' : 'err'));
             Util::jump_to($jump_url);
         }
     }
     $prio_arr = array('5' => Lang::t('_VERYHIGH', 'message'), '4' => Lang::t('_HIGH', 'message'), '3' => Lang::t('_NORMAL', 'message'), '2' => Lang::t('_LOW', 'message'), '1' => Lang::t('_VERYLOW', 'message'));
     $first = true;
     $attach = '';
     if (!is_array($user_selected) || empty($user_selected)) {
         $write_url = $this->mvc_urls ? 'index.php?r=message/write' : $um->getUrl('op=writemessage');
         $output .= '<span class="text_bold">' . Lang::t('_NO_RECIPIENTS_SELECTED') . '</span>' . Form::openForm('message', $write_url, false, false, 'multipart/form-data') . Form::getHidden('out', 'out', $from) . Form::getHidden('msg_course_filter', 'msg_course_filter', $_POST['msg_course_filter']) . Form::getHidden('message_recipients', 'message[recipients]', $recipients) . Form::openButtonSpace() . Form::getButton('back_recipients', 'back_recipients', Lang::t('_BACK')) . Form::closeButtonSpace() . Form::closeForm();
         return;
     }
     $only_users =& $acl_man->getUsers($user_selected);
     $only_groups = $acl_man->getGroups($user_selected);
     $output .= '<span class="text_bold">' . Lang::t('_RECIPIENTS') . '</span>' . '<div class="recipients">';
     if (is_array($only_groups) && !empty($only_groups)) {
         $output .= '<strong>';
         while (list(, $group_info) = each($only_groups)) {
             if ($first) {
                 $first = false;
             } else {
                 $attach = ', ';
             }
             $groupid = substr($group_info[ACL_INFO_GROUPID], strrpos($group_info[ACL_INFO_GROUPID], '/') + 1);
             $output .= $attach . $groupid;
             // find user of group
             $members = $acl_man->getGroupAllUser($group_info[ACL_INFO_IDST]);
             $group_users =& $acl_man->getUsers($members);
             $output .= ' <span class="message_group_members">( ';
             $m_first = true;
             while (list(, $user_info) = each($group_users)) {
                 if ($m_first) {
                     $m_first = false;
                 } else {
                     $attach = ', ';
                 }
                 $output .= $attach . ($user_info[ACL_INFO_LASTNAME] . $user_info[ACL_INFO_FIRSTNAME] ? $user_info[ACL_INFO_LASTNAME] . ' ' . $user_info[ACL_INFO_FIRSTNAME] : $acl_man->relativeId($user_info[ACL_INFO_USERID]));
             }
             $output .= ' )</span> ';
         }
         $output .= '</strong>';
     }
     $acl_man->setContext('/');
     if (is_array($only_users) && !empty($only_users)) {
         while (list(, $user_info) = each($only_users)) {
             if ($first) {
                 $first = false;
             } else {
                 $attach = ', ';
             }
             $output .= $attach . ($user_info[ACL_INFO_LASTNAME] . $user_info[ACL_INFO_FIRSTNAME] ? $user_info[ACL_INFO_LASTNAME] . ' ' . $user_info[ACL_INFO_FIRSTNAME] : $acl_man->relativeId($user_info[ACL_INFO_USERID]));
         }
     }
     $id_forward = importVar('id_forward', true, 0);
     $sql_text = "SELECT message.textof, message.title FROM %adm_message AS message WHERE message.idMessage = '" . $id_forward . "'";
     $title = '';
     $text_message = '';
     if ($message_forward = $this->db->fetch_row($this->db->query($sql_text))) {
         list($text_message, $title) = $message_forward;
         $title = 'Reply: ' . $title;
         $text_message = '<br /><br /><font color="#808080">-------<br /><br />' . $text_message . '</font>';
     }
     $write_url = $this->mvc_urls ? 'index.php?r=message/write' : $um->getUrl('op=writemessage');
     $output .= '</div><br />' . Form::openForm('message', $write_url, false, false, 'multipart/form-data') . Form::getHidden('out', 'out', $from) . Form::getHidden('msg_course_filter', 'msg_course_filter', $_POST['msg_course_filter']) . Form::getHidden('message_recipients', 'message[recipients]', $recipients) . Form::getTextfield(Lang::t('_SUBJECT'), 'message_subject', 'message[subject]', 255, isset($_POST['message']['subject']) ? $_POST['message']['subject'] : "{$title}") . Form::getDropdown(Lang::t('_PRIORITY'), 'message_priority', 'message[priority]', $prio_arr, isset($_POST['message']['priority']) ? $_POST['message']['priority'] : 3) . Form::getTextarea(Lang::t('_TEXTOF'), 'message_textof', 'message_textof', isset($_POST['message_textof']) ? $_POST['message_textof'] : "{$text_message}") . Form::getFilefield(Lang::t('_ATTACHMENT'), 'message_attach', 'message[attach]', 255) . Form::openButtonSpace() . Form::getButton('back_recipients', 'back_recipients', Lang::t('_BACK')) . Form::getButton('send', 'send', Lang::t('_SEND')) . Form::getButton('undo', 'undo', Lang::t('_UNDO')) . Form::closeButtonSpace() . Form::closeForm() . '</div>';
     cout($output, 'content');
 }
 public function subscribeToCourse()
 {
     $id_course = Get::req('id_course', DOTY_INT, 0);
     $id_date = Get::req('id_date', DOTY_INT, 0);
     $id_edition = Get::req('id_edition', DOTY_INT, 0);
     $id_user = Docebo::user()->getIdSt();
     $docebo_course = new DoceboCourse($id_course);
     require_once _lms_ . '/admin/models/SubscriptionAlms.php';
     $model = new SubscriptionAlms($id_course, $id_edition, $id_date);
     $course_info = $model->getCourseInfoForSubscription();
     $userinfo = $this->acl_man->getUser($id_user);
     $level_idst =& $docebo_course->getCourseLevel($id_course);
     if (count($level_idst) == 0 || $level_idst[1] == '') {
         $level_idst =& $docebo_course->createCourseLevel($id_course);
     }
     $waiting = 0;
     if ($course_info['subscribe_method'] != 2) {
         $waiting = 1;
     }
     $userlevel_subscrip = $this->get_userlevel_subscription($id_user);
     //UG
     //UG		$this->acl_man->addToGroup($level_idst[3], $id_user);
     $this->acl_man->addToGroup($level_idst[$userlevel_subscrip], $id_user);
     //UG
     //UG		if($model->subscribeUser($id_user, 3, $waiting))
     if ($model->subscribeUser($id_user, $userlevel_subscrip, $waiting)) {
         $res['success'] = true;
         $res['new_status_code'] = '';
         if ($id_edition != 0 || $id_date != 0) {
             $must_change_status = $this->model->controlSubscriptionRemaining($id_course);
             $res['new_status'] = '';
             if (!$must_change_status) {
                 $res['new_status'] = '<p class="cannot_subscribe">' . Lang::t('_NO_EDITIONS', 'catalogue') . '</p>';
             }
         } else {
             if ($waiting == 1) {
                 $res['new_status'] = '<p class="cannot_subscribe">' . Lang::t('_WAITING', 'catalogue') . '</p>';
                 $res['new_status_code'] = 'waiting';
             } else {
                 $res['new_status'] = '<p class="subscribed">' . Lang::t('_USER_STATUS_ENTER', 'catalogue') . '</p>';
                 $res['new_status_code'] = 'subscribed';
             }
         }
         $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name'], '[firstname]' => $userinfo[ACL_INFO_FIRSTNAME], '[lastname]' => $userinfo[ACL_INFO_LASTNAME]);
         // message to user that is waiting
         require_once _base_ . '/lib/lib.eventmanager.php';
         $msg_composer = new EventMessageComposer('subscribe', 'lms');
         $msg_composer->setSubjectLangText('email', '_NEW_USER_SUBS_WAITING_SUBJECT', false);
         $msg_composer->setBodyLangText('email', '_NEW_USER_SUBS_WAITING_TEXT', $array_subst);
         $msg_composer->setSubjectLangText('sms', '_NEW_USER_SUBS_WAITING_SUBJECT_SMS', false);
         $msg_composer->setBodyLangText('sms', '_NEW_USER_SUBS_WAITING_TEXT_SMS', $array_subst);
         $acl =& Docebo::user()->getAcl();
         $acl_man =& $this->acl_man;
         $recipients = array();
         $idst_group_god_admin = $acl->getGroupST(ADMIN_GROUP_GODADMIN);
         $recipients = $acl_man->getGroupMembers($idst_group_god_admin);
         $idst_group_admin = $acl->getGroupST(ADMIN_GROUP_ADMIN);
         $idst_admin = $acl_man->getGroupMembers($idst_group_admin);
         require_once _adm_ . '/lib/lib.adminmanager.php';
         foreach ($idst_admin as $id_user) {
             $adminManager = new AdminManager();
             $acl_manager =& $acl_man;
             $idst_associated = $adminManager->getAdminTree($id_user);
             $array_user =& $acl_manager->getAllUsersFromIdst($idst_associated);
             $array_user = array_unique($array_user);
             $array_user[] = $array_user[0];
             unset($array_user[0]);
             $control_user = array_search(getLogUserId(), $array_user);
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'course'" . " AND id_entry = '" . $id_course . "'";
             list($control_course) = mysql_fetch_row(mysql_query($query));
             /*if($control)
             		$recipients[] = $id_user;*/
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'coursepath'" . " AND id_entry IN" . " (" . " SELECT id_path" . " FROM " . Get::cfg('prefix_lms') . "_coursepath_courses" . " WHERE id_item = '" . $id_course . "'" . " )";
             list($control_coursepath) = mysql_fetch_row(mysql_query($query));
             /*if($control)
             		$recipients[] = $id_user;*/
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'catalogue'" . " AND id_entry IN" . " (" . " SELECT idCatalogue" . " FROM " . Get::cfg('prefix_lms') . "_catalogue_entry" . " WHERE idEntry = '" . $id_course . "'" . " )";
             list($control_catalogue) = mysql_fetch_row(mysql_query($query));
             if ($control_user && ($control_course || $control_coursepath || $control_catalogue)) {
                 $recipients[] = $id_user;
             }
         }
         $recipients = array_unique($recipients);
         createNewAlert('UserCourseInsertModerate', 'subscribe', 'insert', '1', 'User subscribed with moderation', $recipients, $msg_composer);
         $res['message'] = UIFeedback::info(Lang::t('_SUBSCRIPTION_CORRECT', 'catalogue'), true);
     } else {
         $this->acl_man->removeFromGroup($level_idst[3], $id_user);
         $res['success'] = false;
         $res['message'] = UIFeedback::error(Lang::t('_SUBSCRIPTION_ERROR', 'catalogue'), true);
     }
     echo $this->json->encode($res);
 }
Exemple #15
0
function insCourseEdition()
{
    checkPerm('mod');
    require_once _base_ . '/lib/lib.upload.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once _base_ . '/lib/lib.multimedia.php';
    $array_lang = Docebo::langManager()->getAllLangCode();
    $array_lang[] = 'none';
    $id_course = $_POST['course_id'];
    if ($_POST['course_edition_name'] == '') {
        $_POST['course_edition_name'] = Lang::t('_NO_NAME', 'course', 'lms');
    }
    $path = '/appLms/' . Get::sett('pathcourse');
    if (substr($path, -1) != '/' && substr($path, -1) != '\\') {
        $path = $path . '/';
    }
    $file_sponsor = '';
    $file_logo = '';
    $file_material = '';
    $file_othermaterial = '';
    $error = 0;
    $show_level = 0;
    $user_status = 0;
    if (isset($_POST['user_status'])) {
        while (list($status) = each($_POST['user_status'])) {
            $user_status |= 1 << $status;
        }
    }
    if (isset($_POST['course_edition_show_level'])) {
        while (list($lv) = each($_POST['course_edition_show_level'])) {
            $show_level |= 1 << $lv;
        }
    }
    sl_open_fileoperations();
    if ($_FILES['course_edition_user_material']['tmp_name'] != '') {
        $file_material = 'edition_user_material_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_user_material']['name'];
        $re = createImageFromTmp($_FILES['course_edition_user_material']['tmp_name'], $path . $file_material, $_FILES['course_edition_user_material']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_material = '';
        }
    }
    if ($_FILES['course_edition_otheruser_material']['tmp_name'] != '') {
        $file_othermaterial = 'edition_otheruser_material_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_otheruser_material']['name'];
        $re = createImageFromTmp($_FILES['course_edition_otheruser_material']['tmp_name'], $path . $file_othermaterial, $_FILES['course_edition_otheruser_material']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_othermaterial = '';
        }
    }
    if ($_FILES['course_edition_sponsor_logo']['tmp_name'] != '') {
        $file_sponsor = 'edition_sponsor_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_sponsor_logo']['name'];
        $re = createImageFromTmp($_FILES['course_edition_sponsor_logo']['tmp_name'], $path . $file_sponsor, $_FILES['course_edition_sponsor_logo']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_sponsor = '';
        }
    }
    if ($_FILES['course_edition_logo']['tmp_name'] != '') {
        $file_logo = 'edition_logo_' . mt_rand(0, 100) . '_' . time() . '_' . $_FILES['course_edition_logo']['name'];
        $re = createImageFromTmp($_FILES['course_edition_logo']['tmp_name'], $path . $file_logo, $_FILES['course_edition_logo']['name'], 150, 150, true);
        if (!$re) {
            $error = 1;
            $file_sponsor = '';
        }
    }
    sl_close_fileoperations();
    // if subsribe gap is defined with the date -------------------------------
    if ($_POST["can_subscribe"] != "2") {
        $sub_start_date = "NULL";
        $sub_end_date = "NULL";
    } else {
        $sub_start_date = "'" . Format::dateDb($_POST["sub_start_date"], "date") . "'";
        $sub_end_date = "'" . Format::dateDb($_POST["sub_end_date"], "date") . "'";
    }
    // insert the course in database -----------------------------------------------------------
    $hour_begin = '-1';
    $hour_end = '-1';
    if ($_POST['hour_begin']['hour'] != '-1') {
        $hour_begin = strlen($_POST['hour_begin']['hour']) == 1 ? '0' . $_POST['hour_begin']['hour'] : $_POST['hour_begin']['hour'];
        if ($_POST['hour_begin']['quarter'] == '-1') {
            $hour_begin .= ':00';
        } else {
            $hour_begin .= ':' . $_POST['hour_begin']['quarter'];
        }
    }
    if ($_POST['hour_end']['hour'] != '-1') {
        $hour_end = strlen($_POST['hour_end']['hour']) == 1 ? '0' . $_POST['hour_end']['hour'] : $_POST['hour_end']['hour'];
        if ($_POST['hour_end']['quarter'] == '-1') {
            $hour_end .= ':00';
        } else {
            $hour_end .= ':' . $_POST['hour_end']['quarter'];
        }
    }
    $query_course_edition = "\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_course_edition\r\n\t\tSET idCourse \t\t\t= '" . $id_course . "',\r\n\t\t\tcode \t\t\t\t= '" . $_POST['course_edition_code'] . "',\r\n\t\t\tname \t\t\t\t= '" . $_POST['course_edition_name'] . "',\r\n\t\t\tdescription \t\t= '" . $_POST['course_edition_descr'] . "',\r\n\t\t\tstatus \t\t\t\t= '" . (int) $_POST['course_edition_status'] . "',\r\n\r\n\t\t\tdate_begin \t\t\t= '" . Format::dateDb($_POST['course_edition_date_begin'], 'date') . "',\r\n\t\t\tdate_end \t\t\t= '" . Format::dateDb($_POST['course_edition_date_end'], 'date') . "',\r\n\t\t\thour_begin \t\t\t= '" . $hour_begin . "',\r\n\t\t\thour_end \t\t\t= '" . $hour_end . "',\r\n\r\n\t\t\timg_material \t\t= '" . $file_material . "',\r\n\t\t\timg_othermaterial \t= '" . $file_othermaterial . "',\r\n\r\n\t\t\tmin_num_subscribe \t= '" . (int) $_POST["min_num_subscribe"] . "',\r\n\t\t\tmax_num_subscribe \t= '" . (int) $_POST["max_num_subscribe"] . "',\r\n\t\t\tprice \t\t\t\t= '" . $_POST["edition_price"] . "',\r\n\t\t\tadvance \t\t\t= '" . $_POST["edition_advance"] . "',\r\n\r\n\t\t\tedition_type \t\t= '" . $_POST["edition_type"] . "',\r\n\t\t\tallow_overbooking \t= '" . (isset($_POST["allow_overbooking"]) ? 1 : 0) . "',\r\n\t\t\tcan_subscribe \t\t= '" . (int) $_POST["can_subscribe"] . "',\r\n\t\t\tsub_start_date \t\t= " . $sub_start_date . ",\r\n\t\t\tsub_end_date \t\t= " . $sub_end_date . "";
    if (!sql_query($query_course_edition)) {
        $error = 1;
        if ($file_sponsor != '') {
            sl_unlink($path . $file_sponsor);
        }
        if ($file_logo != '') {
            sl_unlink($path . $file_logo);
        }
        if ($file_material != '') {
            sl_unlink($path . $file_material);
        }
        if ($file_othermaterial != '') {
            sl_unlink($path . $file_othermaterial);
        }
        Util::jump_to('index.php?modname=course&op=course_list&result=err_course');
    } else {
        $edition_id = sql_insert_id();
        $acl_manager =& Docebo::user()->getAclManager();
        $group = '/lms/course_edition/' . $edition_id . '/subscribed';
        $group_idst = $acl_manager->getGroupST($group);
        if ($group_idst === FALSE) {
            $group_idst = $acl_manager->registerGroup($group, 'all the user of a course edition', true, "course");
        }
        // send alert ---------------------------------------------------------------------------
        require_once _base_ . '/lib/lib.eventmanager.php';
        $msg_composer = new EventMessageComposer();
        $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT', false);
        $msg_composer->setBodyLangText('email', '_ALERT_TEXT', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_edition_code'], '[course]' => $_POST['course_edition_name']));
        $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_SMS', array('[url]' => Get::sett('url'), '[course_code]' => $_POST['course_edition_code'], '[course]' => $_POST['course_edition_name']));
        require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
        $course_man = new Man_Course();
        $recipients = $course_man->getIdUserOfLevel($id_course);
        createNewAlert('CoursePropModified', 'course', 'add', '1', 'Inserted course ' . $_POST['course_name'], $recipients, $msg_composer);
        Util::jump_to('index.php?modname=course&op=course_list&result=ok_course');
    }
}
 function add_row($row, $pk)
 {
     $id_course = false;
     if ($row['code'] == '') {
         $row['code'] = $this->default_cols['code'];
     }
     if ($row['name'] == '') {
         $row['name'] = $this->default_cols['name'];
     }
     if ($row['description'] == '') {
         $row['description'] = $this->default_cols['description'];
     }
     if ($row['lang_code'] == '') {
         $row['lang_code'] = $this->default_cols['lang_code'];
     }
     if ($row['status'] == '') {
         $row['status'] = $this->default_cols['status'];
     }
     if ($row['subscribe_method'] == '') {
         $row['subscribe_method'] = $this->default_cols['subscribe_method'];
     }
     if ($row['permCloseLO'] == '') {
         $row['permCloseLO'] = $this->default_cols['permCloseLO'];
     }
     if ($row['difficult'] == '') {
         $row['difficult'] = $this->default_cols['difficult'];
     }
     if ($row['show_progress'] == '') {
         $row['show_progress'] = $this->default_cols['show_progress'];
     }
     if ($row['show_time'] == '') {
         $row['show_time'] = $this->default_cols['show_time'];
     }
     if ($row['show_extra_info'] == '') {
         $row['show_extra_info'] = $this->default_cols['show_extra_info'];
     }
     if ($row['show_rules'] == '') {
         $row['show_rules'] = $this->default_cols['show_rules'];
     }
     if ($row['date_begin'] == '') {
         $row['date_begin'] = $this->default_cols['date_begin'];
     }
     if ($row['date_end'] == '') {
         $row['date_end'] = $this->default_cols['date_end'];
     }
     if ($row['valid_time'] == '') {
         $row['valid_time'] = $this->default_cols['valid_time'];
     }
     if ($row['max_num_subscribe'] == '') {
         $row['max_num_subscribe'] = $this->default_cols['max_num_subscribe'];
     }
     if ($row['prize'] == '') {
         $row['prize'] = $this->default_cols['prize'];
     }
     if ($row['selling'] == '') {
         $row['selling'] = $this->default_cols['selling'];
     }
     // check if the course identified by the pk alredy exits
     $id_course = $this->get_row_by_pk($pk);
     if ($id_course === false) {
         $this->last_error = 'Error in search query : ( ' . mysql_error() . ' )';
         return false;
     }
     if ($id_course === 'jump') {
         return true;
     }
     $is_add = false;
     if ($id_course === 0) {
         $is_add = true;
         // course is to add
         $query_course = "\r\n\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_course \r\n\t\t\tSET idCategory = '0', \r\n\t\t\t\tcode = '" . addslashes($row['code']) . "', \r\n\t\t\t\tname = '" . addslashes($row['name']) . "', \r\n\t\t\t\tdescription = '" . $row['description'] . "', \r\n\t\t\t\tlang_code = '" . $row['lang_code'] . "', \r\n\t\t\t\tstatus = '" . $row['status'] . "', \r\n\t\t\t\tsubscribe_method = '" . $row['subscribe_method'] . "',\r\n\t\t\t\tpermCloseLO = '" . $row['permCloseLO'] . "', \r\n\t\t\t\tdifficult = '" . $row['difficult'] . "', \r\n\t\t\t\tshow_progress = '" . $row['show_progress'] . "', \r\n\t\t\t\tshow_time = '" . $row['show_time'] . "', \r\n\t\t\t\tshow_extra_info = '" . $row['show_extra_info'] . "', \r\n\t\t\t\tshow_rules = '" . $row['show_rules'] . "', \r\n\t\t\t\tdate_begin = '" . $row['date_begin'] . "', \r\n\t\t\t\tdate_end = '" . $row['date_end'] . "', \r\n\t\t\t\tvalid_time = '" . $row['valid_time'] . "',\r\n\t\t\t\tmax_num_subscribe = '" . $row['max_num_subscribe'] . "', \r\n\t\t\t\tprize = '" . $row['prize'] . "',\r\n\t\t\t\tselling = '" . $row['selling'] . "',\r\n\t\t\t\timported_from_connection = '" . $this->get_name() . "'";
         if (!sql_query($query_course)) {
             $this->last_error = 'Error in insert query : ( ' . mysql_error() . ' )' . '<!-- ' . $query_course . ' -->';
             return false;
         }
         $id_course = mysql_insert_id();
         // import the menu
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             $re &= sql_query("\r\n\t\t\t\tINSERT INTO " . $GLOBALS['prefix_fw'] . "_admin_course \r\n\t\t\t\t( id_entry, type_of_entry, idst_user ) VALUES \r\n\t\t\t\t( '" . $id_course . "', 'course', '" . getLogUserId() . "') ");
         }
         //if the scs exist create a room
         if ($GLOBALS['where_scs'] !== false) {
             require_once $GLOBALS['where_scs'] . '/lib/lib.room.php';
             $rules = array('room_name' => $row['name'], 'room_type' => 'course', 'id_source' => $id_course);
             $admin_rules = getAdminRules();
             $rules = array_merge($rules, $admin_rules);
             $re = insertRoom($rules);
         }
         $course_idst = DoceboCourse::createCourseLevel($id_course);
         require_once $GLOBALS['where_lms'] . '/lib/lib.manmenu.php';
         if (!cerateCourseMenuFromCustom($this->std_menu_to_assign, $id_course, $course_idst)) {
             $this->last_error = 'Error in menu assignament';
             return false;
         }
     } else {
         // course is to update
         $query_course = "\r\n\t\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_course \r\n\t\t\tSET code = '" . addslashes($row['code']) . "', \r\n\t\t\t\tname = '" . addslashes($row['name']) . "', \r\n\t\t\t\tdescription = '" . $row['description'] . "', \r\n\t\t\t\tlang_code = '" . $row['lang_code'] . "', \r\n\t\t\t\tstatus = '" . $row['status'] . "', \r\n\t\t\t\tsubscribe_method = '" . $row['subscribe_method'] . "',\r\n\t\t\t\tpermCloseLO = '" . $row['permCloseLO'] . "', \r\n\t\t\t\tdifficult = '" . $row['difficult'] . "', \r\n\t\t\t\tshow_progress = '" . $row['show_progress'] . "', \r\n\t\t\t\tshow_time = '" . $row['show_time'] . "', \r\n\t\t\t\tshow_extra_info = '" . $row['show_extra_info'] . "', \r\n\t\t\t\tshow_rules = '" . $row['show_rules'] . "', \r\n\t\t\t\tdate_begin = '" . $row['date_begin'] . "', \r\n\t\t\t\tdate_end = '" . $row['date_end'] . "', \r\n\t\t\t\tvalid_time = '" . $row['valid_time'] . "',\r\n\t\t\t\tmax_num_subscribe = '" . $row['max_num_subscribe'] . "', \r\n\t\t\t\tprize = '" . $row['prize'] . "',\r\n\t\t\t\tselling = '" . $row['selling'] . "'\r\n\t\t\tWHERE idCourse = '" . $id_course . "'";
         if (!sql_query($query_course)) {
             $this->last_error = 'Error in update query : ( ' . mysql_error() . ' )' . '<!-- ' . $query_course . ' -->';
             return false;
         }
     }
     if ($id_course != false) {
         if ($this->cache_inserted) {
             $this->arr_id_inserted[] = $id_course;
         }
         if ($this->sendnotify == 1) {
             // send notify
             if ($is_add) {
                 require_once $GLOBALS['where_framework'] . '/lib/lib.eventmanager.php';
                 $msg_composer = new EventMessageComposer();
                 $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT', false);
                 $msg_composer->setBodyLangText('email', '_ALERT_TEXT', array('[url]' => Get::sett('url'), '[course_code]' => $row['code'], '[course]' => $row['name']));
                 $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_SMS', array('[url]' => Get::sett('url'), '[course_code]' => $row['code'], '[course]' => $row['name']));
                 require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
                 $course_man = new Man_Course();
                 $recipients = $course_man->getIdUserOfLevel($id_course);
                 createNewAlert('CoursePropModified', 'course', 'add', '1', 'Inserted course ' . $_POST['course_name'], $recipients, $msg_composer);
             }
         }
         return true;
     }
     $this->last_error = 'Unknow error';
     return false;
 }
 function delete_bypk($pk)
 {
     $arr_id = $this->get_row_bypk($pk);
     if ($this->on_delete == 1) {
         $res &= $this->sub_man->suspendUserWithConnection($arr_id['idst_user'], $arr_id['id_course'], $this->get_name());
     } else {
         $re_ins = $this->sub_man->unsubscribeUserWithConnection($arr_id['idst_user'], $arr_id['id_course'], $this->get_name());
     }
     if ($re_ins === 'jump') {
         return true;
     }
     if ($re_ins) {
         if ($this->sendnotify == 1) {
             $array_subst = array('[url]' => Get::sett('url'), '[course]' => $arr_id['course_name']);
             // message to user that is waiting
             $msg_composer = new EventMessageComposer();
             $msg_composer->setSubjectLangText('email', '_DEL_USER_SUBSCRIPTION_SUBJECT', false);
             $msg_composer->setBodyLangText('email', '_DEL_USER_SUBSCRIPTION_TEXT', $array_subst);
             $msg_composer->setBodyLangText('sms', '_DEL_USER_SUBSCRIPTION_TEXT_SMS', $array_subst);
             // send message to the user subscribed
             createNewAlert('UserCourseRemoved', 'subscribe', 'remove', '1', 'User removed form a course', array($arr_id['idst_user']), $msg_composer);
         }
     }
     return $re_ins;
 }
 /**
  * @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;
     }
 }