$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['id']; $params = [ 'changes' => $changes, 'type' => $type, 'date' => $time ]; Database::update($legal_table, $params, ['id => ?' => $id]); return true; } else { return false; } } /** * @param int $id */ public static function delete($id) { /* $legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); $id = intval($id); $sql = "DELETE FROM $legal_table WHERE id = '".$id."'"; */ } /** * Gets the last version of a Term and condition by language * @param int $language language id * @return array all the info of a Term and condition */ public static function get_last_condition_version($language) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $language = Database::escape_string($language); $sql = "SELECT version FROM $legal_conditions_table WHERE language_id = '".$language."' ORDER BY id DESC LIMIT 1 "; $result = Database::query($sql); $row = Database::fetch_array($result); if (Database::num_rows($result) > 0) { return $row['version']; } else { return 0; } } /** * Gets the data of a Term and condition by language * @param int $language language id * @return array all the info of a Term and condition */ public static function get_last_condition($language) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $language = Database::escape_string($language); $sql = "SELECT * FROM $legal_conditions_table WHERE language_id = '".$language."' ORDER BY version DESC LIMIT 1 "; $result = Database::query($sql); $result = Database::fetch_array($result, 'ASSOC'); if (isset($result['content'])) { $result['content'] = self::replaceTags($result['content']); } return $result; } /** * Check if an specific version of an agreement exists * * @param int $language * @param int $version * * @return bool */ public static function hasVersion($language, $version) { $table = Database::get_main_table(TABLE_MAIN_LEGAL); $language = intval($language); $version = intval($version); if (empty($language)) { return false; } $sql = "SELECT version FROM $table WHERE language_id = '$language' AND version = '$version' LIMIT 1 "; $result = Database::query($sql); if (Database::num_rows($result) > 0) { return true; } else { return false; } } /** * @param string $content * @return string */ public static function replaceTags($content) { if (strpos($content, '{{sessions}}')) { $sessionListToString = ''; $sessionList = SessionManager::get_sessions_by_user(api_get_user_id()); if ($sessionList) { $sessionListToString = get_lang('SessionList').'