/** * Check if a given registration code is valid * @param string $reg_code * @param string $registration_code_type * @return boolean */ public function checkRegistrationCode($reg_code, $registration_code_type) { $res = true; $uma = new UsermanagementAdm(); $code_is_mandatory = Get::sett('mandatory_code', 'off') == 'on'; 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 and resolve here the course part $course_code = substr(str_replace('-', '', $reg_code), 10, 10); $reg_code = substr(str_replace('-', '', $reg_code), 0, 10); //control course registration require_once _lms_ . '/lib/lib.course.php'; $man_course_user = new Man_CourseUser(); $jolly_code = Get::sett('jolly_course_code', ''); if ($jolly_code == '' || $jolly_code != $course_code) { $course_registration_result = $man_course_user->checkCode($course_code); if ($course_registration_result <= 0 && $code_is_mandatory) { $res = false; // invalid code } } //procced with tree_man //procced with tree_man case "tree_man": // resolving the tree_man $array_folder = $uma->getFoldersFromCode($reg_code); if (empty($array_folder) && $code_is_mandatory) { $res = false; // invalid 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 == 0) { $res = false; // code already used } elseif ($valid_code == -1 && $code_is_mandatory) { $res = false; // invalid code } break; case "tree_drop": // from the dropdown we will recive the id of the folder $array_folder = array($reg_code => $reg_code); $oc_folders = $uma->getOcFolders($array_folder); if (empty($oc_folders)) { $res = false; // invalid 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); if (empty($array_folder) && $code_is_mandatory) { $res = false; // invalid code } break; default: $res = false; // invalid code type break; } } else { $res = false; } return $res; }