Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
101 lines (94 loc) · 2.79 KB
/
Copy pathfunctions.php
File metadata and controls
101 lines (94 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
require 'libs/db.php';
function getQuestions ( $type = 'object', $lang = 'en' ) {
return R::find('questions', 'type = ? AND lang = ?', array($type, $lang));
}
function getQuestionById ( $id ) {
return R::findOne('questions', $id);
}
function getQuestion ( $age, $type, $checked = 1 ) {
return R::findOne('questions', 'age = ? AND type = ? AND checked = ?', array($age, $type, $checked));
}
function getLang ( $lang ) {
R::findAll('questions', 'lang = ?', array($lang) );
}
function addQuestion ( $question, $type, $age ) {
$questions = R::dispense( 'questions' );
$questions->question = $question;
$questions->type = $type;
$questions->age = $age;
R::store($questions);
return true;
}
function updateQuestion ( $id, $question ) {
$questions = R::load( 'questions', $id );
$questions->question = $question;
R::store($questions);
return true;
}
function addProblems ( $id_question, $gender, $problem ) {
$problems = R::dispense( 'problems' );
$problems->id_question = $id_question;
$problems->gender = $gender;
$problems->problem = $problem;
R::store($problems);
return true;
}
function getProblems ( $id_question ) {
return R::findAll('problems', 'id_question = ?', array($id_question));
}
function getProblem ( $id_question ) {
return R::findOne('problems', 'id_question = ?', array($id_question));
}
function setSettingsDefault ($timer1 = 100, $timer2 = 100) {
$settings = R::findOne('settings', 1);
if ( ! $settings ) {
$settings = R::dispense( 'settings' );
$settings->timer1 = $timer1;
$settings->timer2 = $timer2;
R::store($settings);
}
else {
$settings = R::load('settings', 1);
$settings->timer1 = $timer1;
$settings->timer2 = $timer2;
R::store($settings);
}
}
function setUser ($login = 'admin', $password = 'admin') {
$users = R::findOne('users', 1);
if ( !$users ) {
$user = R::dispense( 'users' );
$user->login = $login;
$user->password = password_hash($password,PASSWORD_DEFAULT);
R::store($user);
}
else {
$user = R::load( 'users', 1 );
$user->login = $login;
$user->password = password_hash($password,PASSWORD_DEFAULT);
R::store($user);
}
}
function removeQuestion ($id) {
$question = R::load('questions', $id);
R::trash($question);
}
function getSettings () {
return R::findOne('settings', 1);
}
function checkedToZero ($age, $type) {
$questions = R::findAll('questions', 'age = ? AND type = ?', array($age, $type));
foreach ($questions as $question) {
$quest = R::load('questions', $question->id);
$quest->checked = 0;
R::store($quest);
}
}
function addChecked ($id, $check, $age, $type) {
checkedToZero($age, $type);
$questions = R::load('questions', $id);
$questions->checked = 1;
R::store($questions);
}
// setSettingsDefault(10);