Example #1
0
 function _special_field($options, $platform, $opt_link)
 {
     $lang =& DoceboLanguage::createInstance('register', $platform);
     // Check for error
     $out = '';
     $error = $this->_checkField($_POST, $options, $platform, false);
     if ($error['error']) {
         $this->error = true;
         $out .= '<div class="reg_err_data">' . $error['msg'] . '</div>';
         return $out;
     }
     // if the user had enter a code we must check if there are folder related to it and
     // add the folder's field
     $registration_code_type = Get::sett('registration_code_type', '0');
     $code_is_mandatory = Get::sett('mandatory_code', 'off');
     $reg_code = Get::req('reg_code', DOTY_MIXED, '');
     if ($registration_code_type === 'custom') {
         $reg_code = 'change_by_custom_operation';
     }
     $array_folder = false;
     $folder_group = false;
     $uma = new UsermanagementAdm();
     if ($reg_code != '') {
         switch ($registration_code_type) {
             case "0":
                 //nothin to do
                 break;
             case "tree_course":
                 //a mixed code, let's cut the tree part and go on with the tree_man
                 $reg_code = substr(str_replace('-', '', $reg_code), 0, 10);
                 //procced with tree_man
             //procced with tree_man
             case "tree_man":
                 // resolving the tree_man
                 $uma = new UsermanagementAdm();
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 break;
             case "code_module":
                 require_once _adm_ . '/lib/lib.code.php';
                 $code_manager = new CodeManager();
                 $valid_code = $code_manager->controlCodeValidity($reg_code);
                 if ($valid_code == 1) {
                     $array_folder = $code_manager->getOrgAssociateWithCode($reg_code);
                 }
                 break;
             case "tree_drop":
                 // from the dropdown we will recive the id of the folder
                 // then we get the oc and ocd
                 $array_folder = $uma->getFolderGroups($reg_code);
                 break;
             case "custom":
                 //Custom code
                 require_once _adm_ . '/lib/lib.field.php';
                 $field_man = new FieldList();
                 $id_common_filed_1 = $field_man->getFieldIdCommonFromTranslation('Filiale');
                 $id_common_filed_2 = $field_man->getFieldIdCommonFromTranslation('Codice Concessionario');
                 $query = "SELECT `translation`" . " FROM core_field_son" . " WHERE id_common_son = " . (int) $_POST['field_dropdown'][$id_common_filed_1] . " AND lang_code = '" . getLanguage() . "'";
                 list($filed_1_translation) = sql_fetch_row(sql_query($query));
                 $code_part = substr($filed_1_translation, 1, 1);
                 $reg_code = strtoupper($code_part . '_' . $_POST['field_textfield'][$id_common_filed_2]);
                 // resolving the tree_man
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 break;
         }
     }
     if ($array_folder !== false) {
         if ($folder_group === false) {
             $folder_group = array();
         }
         foreach ($array_folder as $id_org_folder) {
             $folder_group[] = Docebo::aclm()->getGroupST('/oc_' . $id_org_folder);
         }
     }
     // find all the related extra field
     $extra_field = new FieldList();
     $play_field = $extra_field->playFieldsForUser(0, isset($_POST['group_sel']) ? $_POST['group_sel'] : (isset($_POST['group_sel_implode']) ? explode(',', $_POST['group_sel_implode']) : $array_folder), false, true);
     if ($play_field === false) {
         return $this->_opt_in($options, $platform, $opt_link);
     }
     $mand_sym = '<span class="mandatory">*</span>';
     $out .= '<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>';
     $out .= Form::getHidden('next_step', 'next_step', 'opt_in') . Form::getHidden('register_userid', 'register[userid]', $_POST['register']['userid']) . Form::getHidden('register_email', 'register[email]', $_POST['register']['email']) . Form::getHidden('register_firstname', 'register[firstname]', $_POST['register']['firstname']) . Form::getHidden('register_lastname', 'register[lastname]', $_POST['register']['lastname']) . Form::getHidden('register_pwd', 'register[pwd]', $_POST['register']['pwd']) . Form::getHidden('register_pwd_retype', 'register[pwd_retype]', $_POST['register']['pwd_retype']) . Form::getHidden('register_privacy', 'register[privacy]', 'ok');
     if (!empty($_POST['group_sel'])) {
         //&& !empty($_POST['group_sel_implode'])) {
         $out .= Form::getHidden('group_sel_implode', 'group_sel_implode', isset($_POST['group_sel']) ? implode(',', $_POST['group_sel']) : (isset($_POST['group_sel_implode']) ? $_POST['group_sel_implode'] : ''));
     }
     $out .= ($reg_code != '' ? Form::getHidden('reg_code', 'reg_code', $reg_code) : '') . $play_field . Form::getBreakRow() . Form::closeElementSpace() . Form::openButtonSpace('reg_form_button') . Form::getButton('reg_button', 'reg_button', $lang->def('_REGISTER')) . Form::closeButtonSpace();
     return $out;
 }
function subscribe()
{
    checkPerm('view');
    require_once _base_ . '/lib/lib.form.php';
    $form = new Form();
    if (isset($_POST['course_autoregistration_code'])) {
        require_once _lms_ . '/lib/lib.course.php';
        $out =& $GLOBALS['page'];
        $out->setWorkingZone('content');
        $code = $_POST['course_autoregistration_code'];
        $code = strtoupper($code);
        $code = str_replace('-', '', $code);
        $registration_code_type = Get::sett('registration_code_type', '0');
        if ($registration_code_type == 'tree_course') {
            $code = substr($code, 10, 10);
        }
        $course_registration_result = false;
        $man_course_user = new Man_CourseUser();
        $course_registration_result = $man_course_user->subscribeUserWithCode($code, getLogUserId());
        $out->add(getTitleArea(Lang::t('_AUTOREGISTRATION', 'course_autoregistration')) . '<div class="std_block">');
        if ($course_registration_result > 0) {
            $out->add(str_replace('[course_added]', $course_registration_result, Lang::t('_OPERATION_SUCCESSFUL', 'course_autoregistration')));
            $out->add('<br/><a href="index.php?r=' . _after_login_ . '">' . Lang::t('_BACK_TO_COURSE', 'course_autoregistration') . '</a>');
        } else {
            if ($course_registration_result == -1) {
                $out->add(getErrorUi(Lang::t('_CODE_ALREDY_USED', 'course_autoregistration')));
                $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
            } else {
                if ($course_registration_result == -2) {
                    $out->add(getErrorUi(Lang::t('_SUBSCRIPTION_NOT_ALLOWED_YET', 'course_autoregistration')));
                    $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                } else {
                    require_once _adm_ . '/lib/lib.code.php';
                    $code = $_POST['course_autoregistration_code'];
                    $code_manager = new CodeManager();
                    $valid_code = $code_manager->controlCodeValidity($code);
                    if ($valid_code == 1) {
                        $array_course = $code_manager->getAvailableCourseAssociateWithCode($code);
                        require_once _lms_ . '/lib/lib.course.php';
                        $man_course = new Man_Course();
                        $array_course_name = array();
                        $counter = 0;
                        require_once _lms_ . '/lib/lib.subscribe.php';
                        $subscribe = new CourseSubscribe_Management();
                        foreach ($array_course as $id_course) {
                            $query_control = "SELECT COUNT(*)" . " FROM %lms_courseuser" . " WHERE idCourse = " . $id_course . " AND idUser = "******"index.php?r=' . _after_login_ . '">' . Lang::t('_BACK_TO_COURSE', 'course_autoregistration') . '</a>');
                        } else {
                            if (sizeof($array_course) == 0) {
                                $out->add(getErrorUi(Lang::t('_SUBSCRIPTION_NOT_ALLOWED_YET', 'course_autoregistration')));
                            } else {
                                $out->add(getErrorUi(Lang::t('_ALREADY_SUBSCRIBED', 'course_autoregistration')));
                            }
                            $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                        }
                    } else {
                        if ($valid_code == 0) {
                            $out->add(getErrorUi(Lang::t('_CODE_ALREDY_USED', 'course_autoregistration')));
                        } else {
                            $out->add(getErrorUi(Lang::t('_CODE_NOT_VALID', 'course_autoregistration')));
                        }
                        $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                    }
                }
            }
        }
        $out->add('</div>');
    }
}