18 public static function create($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
29 $code = self::generateRandomCode();
30 $chk =
$ilDB->queryF(
"SELECT code_id FROM " . self::DB_TABLE .
" WHERE code = %s", array(
"text"), array(
$code));
31 $found = (bool)
$ilDB->numRows($chk);
34 if (is_array($local_roles)) {
35 $local_roles = implode(
";", $local_roles);
37 if ($limit ==
"relative" && is_array($limit_date)) {
38 $limit_date = serialize($limit_date);
42 'code_id' => array(
'integer',
$id),
43 'code' => array(
'text',
$code),
44 'generated_on' => array(
'integer', $stamp),
45 'role' => array(
'integer', $role),
46 'role_local' => array(
'text', $local_roles),
47 'alimit' => array(
'text', $limit),
48 'alimitdt' => array(
'text', $limit_date),
49 'reg_enabled' => array(
'integer',$reg_type),
50 'ext_enabled' => array(
'integer',$ext_type)
60 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
63 $max = strlen(
$map) - 1;
64 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
70 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
77 $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
80 $set =
$ilDB->query(
"SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
82 if ($rec =
$ilDB->fetchAssoc($set)) {
86 $sql =
"SELECT * FROM " . self::DB_TABLE . $where;
88 if ($order_field ==
'generated') {
89 $order_field =
'generated_on';
91 $sql .=
" ORDER BY " . $order_field .
" " . $order_direction;
95 $ilDB->setLimit((
int) $limit, (
int) $offset);
96 $set =
$ilDB->query($sql);
98 while ($rec =
$ilDB->fetchAssoc($set)) {
99 $rec[
'generated'] = $rec[
'generated_on'];
102 return array(
"cnt" => $cnt,
"set" =>
$result);
109 $ilDB = $DIC[
'ilDB'];
111 $set =
$ilDB->query(
"SELECT * FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
113 while ($rec =
$ilDB->fetchAssoc($set)) {
123 $ilDB = $DIC[
'ilDB'];
126 return $ilDB->manipulate(
"DELETE FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
135 $ilDB = $DIC[
'ilDB'];
137 $set =
$ilDB->query(
"SELECT DISTINCT(generated_on) genr FROM " . self::DB_TABLE .
" ORDER BY genr");
139 while ($rec =
$ilDB->fetchAssoc($set)) {
145 protected static function filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
149 $ilDB = $DIC[
'ilDB'];
153 $where[] =
$ilDB->like(
"code",
"text",
"%" . $filter_code .
"%");
156 $where[] =
"role = " .
$ilDB->quote($filter_role,
"integer");
158 if ($filter_generated) {
159 $where[] =
"generated_on = " .
$ilDB->quote($filter_generated,
"text");
161 if ($filter_access_limitation) {
162 $where[] =
"alimit = " .
$ilDB->quote($filter_access_limitation,
"text");
164 if (
sizeof($where)) {
165 return " WHERE " . implode(
" AND ", $where);
171 public static function getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
175 $ilDB = $DIC[
'ilDB'];
178 $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
181 $set =
$ilDB->query(
"SELECT code FROM " . self::DB_TABLE . $where .
" ORDER BY code_id");
183 while ($rec =
$ilDB->fetchAssoc($set)) {
199 $ilDB = $DIC[
'ilDB'];
201 $set =
$ilDB->query(
"SELECT used FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote(
$code,
"text"));
202 $set =
$ilDB->fetchAssoc($set);
203 if ($set && !$set[
"used"]) {
218 $ilDB = $DIC[
'ilDB'];
220 $query =
'SELECT code_id FROM reg_registration_codes ' .
221 'WHERE used = ' .
$ilDB->quote(0,
'integer') .
' ' .
222 'AND reg_enabled = ' .
$ilDB->quote(1,
'integer') .
' ' .
223 'AND code = ' .
$ilDB->quote($a_code,
'text');
226 return $res->numRows() ? true :
false;
233 $ilDB = $DIC[
'ilDB'];
235 return (
bool)
$ilDB->update(self::DB_TABLE, array(
"used" => array(
"timestamp", time())), array(
"code" => array(
"text",
$code)));
242 $ilDB = $DIC[
'ilDB'];
244 $set =
$ilDB->query(
"SELECT role FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote(
$code,
"text"));
246 if (isset(
$row[
"role"])) {
255 $ilDB = $DIC[
'ilDB'];
257 $set =
$ilDB->query(
"SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
258 " FROM " . self::DB_TABLE .
259 " WHERE code = " .
$ilDB->quote(
$code,
"text"));
static getCodeData($code)
static getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static deleteCodes(array $ids)
static getGenerationDates()
if(!array_key_exists('StateId', $_REQUEST)) $id
static filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static create($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
static getCodeRole($code)
foreach($_POST as $key=> $value) $res
static isValidRegistrationCode($a_code)
Check if given code is a valid registration code.
static loadCodesByIds(array $ids)
Class ilRegistrationCode.
static generateRandomCode()
static getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static isUnusedCode($code)
Check if code has been used already type $ilDB.