/** * Add a new Term and Condition * @param int language id * @param string the content * @param int term and condition type (0 or 1) * @param string explain changes * @return boolean sucess */ public static function add($language, $content, $type, $changes) { $legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); $last = self::get_last_condition($language); $language = Database::escape_string($language); $content = Database::escape_string($content); $type = intval($type); $changes = Database::escape_string($changes); $time = time(); if ($last['content'] != $content) { $version = intval(LegalManager::get_last_condition_version($language)); $version++; $sql = "INSERT INTO {$legal_table}\n\t\t\t\t\t\tSET language_id = '" . Database::escape_string($language) . "',\n\t\t\t\t\t\t\tcontent = '" . $content . "',\n\t\t\t\t\t\t\tchanges= '" . $changes . "',\n\t\t\t\t\t\t\ttype = '" . $type . "',\n\t\t\t\t\t\t\tversion = '" . Database::escape_string($version) . "',\n\t\t\t\t\t\t\tdate = '" . $time . "'"; $result = Database::query($sql); return true; } elseif ($last['type'] != $type && $language == $last['language_id']) { //update $id = $last['legal_id']; $sql = "UPDATE {$legal_table}\n\t\t\t\t\tSET changes= '" . $changes . "',\n\t\t\t\t\ttype = '" . $type . "',\n\t\t\t\t\tdate = '" . $time . "'\n\t\t\t\t\tWHERE legal_id= {$id} "; $result = Database::query($sql); return true; } else { return false; } }
/** * Add a new Term and Condition * @param int $language language id * @param string $content content * @param int $type term and condition type (0 or 1) * @param string $changes explain changes * @return boolean success */ public static function add($language, $content, $type, $changes) { $legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); $last = self::get_last_condition($language); $type = intval($type); $time = time(); if ($last['content'] != $content) { $version = intval(LegalManager::get_last_condition_version($language)); $version++; $params = ['language_id' => $language, 'content' => $content, 'changes' => $changes, 'type' => $type, 'version' => intval($version), 'date' => $time]; Database::insert($legal_table, $params); return true; } elseif ($last['type'] != $type && $language == $last['language_id']) { //update $id = $last['legal_id']; $params = ['changes' => $changes, 'type' => $type, 'date' => $time]; Database::update($legal_table, $params, ['legal_id => ?' => $id]); return true; } else { return false; } }
$term_preview = LegalManager::get_last_condition($language); //if is false we load from english if (!$term_preview) { $language = api_get_language_id('english'); //this must work $term_preview = LegalManager::get_last_condition($language); } } // Version and language $form->addElement('hidden', 'legal_accept_type', $term_preview['version'] . ':' . $term_preview['language_id']); $form->addElement('hidden', 'legal_info', $term_preview['legal_id'] . ':' . $term_preview['language_id']); if ($term_preview['type'] == 1) { $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree') . ' <a href="inscription.php?legal" target="_blank">' . get_lang('TermsAndConditions') . '</a>'); $form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required'); } else { $preview = LegalManager::show_last_condition($term_preview); $form->addElement('label', null, $preview); } } $form->addButtonCreate(get_lang('RegisterUser')); $course_code_redirect = Session::read('course_redirect'); if ($form->validate()) { $values = $form->getSubmitValues(1); // Make *sure* the login isn't too long if (isset($values['username'])) { $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH); } if (api_get_setting('registration.allow_registration_as_teacher') == 'false') { $values['status'] = STUDENT; } if (empty($values['official_code']) && !empty($values['username'])) {
/** * Checks whether we already approved the last version term and condition * @param int user id * @return bool true if we pass false otherwise */ function api_check_term_condition($user_id) { if (api_get_setting('registration.allow_terms_conditions') == 'true') { //check if exists terms and conditions if (LegalManager::count() == 0) { return true; } $extraFieldValue = new ExtraFieldValue('user'); $data = $extraFieldValue->get_values_by_handler_and_field_variable($user_id, 'legal_accept'); if (!empty($data) && isset($data['value'])) { $rowv = $data['value']; $user_conditions = explode(':', $rowv); $version = $user_conditions[0]; $lang_id = $user_conditions[1]; $real_version = LegalManager::get_last_version($lang_id); return $version >= $real_version; } return false; } return false; }
function count_mask() { return LegalManager::count(); }
} } else { if (isset($_user['user_id'])) { unset($_user['user_id']); } //Platform legal terms and conditions if (api_get_setting('allow_terms_conditions') == 'true') { if (isset($_POST['login']) && isset($_POST['password']) && isset($_SESSION['term_and_condition']['user_id'])) { $user_id = $_SESSION['term_and_condition']['user_id']; // user id // Update the terms & conditions $legal_type = null; //verify type of terms and conditions if (isset($_POST['legal_info'])) { $info_legal = explode(':', $_POST['legal_info']); $legal_type = LegalManager::get_type_of_terms_and_conditions($info_legal[0], $info_legal[1]); } //is necessary verify check if ($legal_type == 1) { if (isset($_POST['legal_accept']) && $_POST['legal_accept'] == '1') { $legal_option = true; } else { $legal_option = false; } } //no is check option if ($legal_type == 0) { $legal_option = true; } if (isset($_POST['legal_accept_type']) && $legal_option === true) { $cond_array = explode(':', $_POST['legal_accept_type']);
/** * Checks whether we already approved the last version term and condition * @param int user id * @return bool true if we pass false otherwise */ function api_check_term_condition($user_id) { if (api_get_setting('allow_terms_conditions') == 'true') { $t_uf = Database::get_main_table(TABLE_MAIN_USER_FIELD); $t_ufv = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES); //check if exists terms and conditions if (LegalManager::count() == 0) { return true; } // Check the last user version_id passed $sql = "SELECT field_value FROM {$t_ufv} ufv inner join {$t_uf} uf on ufv.field_id= uf.id\n WHERE field_value <> '' AND field_variable = 'legal_accept' AND user_id = " . intval($user_id); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $rowv = Database::fetch_row($res); $rowv = $rowv[0]; $user_conditions = explode(':', $rowv); $version = $user_conditions[0]; $lang_id = $user_conditions[1]; $real_version = LegalManager::get_last_version($lang_id); return $version >= $real_version; } return false; } return false; }