-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproposition.php
227 lines (213 loc) · 12.7 KB
/
proposition.php
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
require('./config/config.php');
require('./code/init.php');
require('./code/dbaccess.class.php');
require('./code/dbaccess-flags.class.php');
require('./code/dbaccess-propositions.class.php');
require('./code/dbaccess-users.class.php');
require('./code/template.class.php');
require('./html/' . $_GET['prj'] . '/project_vars.php');
$ui = parse_ini_file('./html/' . $_GET['prj'] . '/ui.ini', TRUE);
if (!(isset($_GET['id']) and preg_match('`^[0-9]+$`', $_GET['id']))) {
setSysMsg('_wrongurl');
header(URL_HEADER . 'home.php?prj=' . $_GET['prj']);
exit;
}
$db = new Database();
if (!$db->connx) {
header(URL_HEADER . 'home.php?prj=' . $_GET['prj']);
exit;
}
$dbaUsers = new dbaccessUsers($db);
$dbaFlags = new dbaccessFlags($db);
$dbaPropositions = new dbaccessPropositions($db);
$template = new Template();
$template->SetPageVars($_GET['prj'], 'proposition', $dbaUsers);
$template->SetBranchVars('script', array('FILENAME' => './js/widgets_control.js'));
$template->SetBranchVars('script', array('FILENAME' => './js/ajaxcmd.js'));
$template->SetBranchVars('script', array('FILENAME' => './lib/autosuggest/autosuggest.js'));
$template->SetBranchVars('script', array('FILENAME' => './html/'. $_GET['prj'] .'/tags.js'));
$langlinks = file_get_contents('./html/' . $_GET['prj'] . '/langlinks.div.html');
$template->SetTrunkVar('LANGLINKS', $langlinks);
$cmd = (isset($_GET['cmd'])) ? $_GET['cmd'] : NULL;
$tab = (isset($_GET['tab']) and strlen($_GET['tab']) === 1) ? $_GET['tab'] : 'E';
$value = (isset($_GET['value']) and strlen($_GET['value']) === 1) ? $_GET['value'] : FALSE;
switch ($cmd) {
case 'prev': list($ok, $result) = $dbaPropositions->selectNextProposition($_GET['prj'], $_GET['id'], FALSE, $value, $tab); break;
case 'next': list($ok, $result) = $dbaPropositions->selectNextProposition($_GET['prj'], $_GET['id'], TRUE, $value, $tab); break;
default: list($ok, $result) = $dbaPropositions->selectProposition($_GET['prj'], $_GET['id']);
}
if (!$ok) {
setSysMsg($result);
header(URL_HEADER . 'home.php?prj=' . $_GET['prj']);
exit;
}
if (count($result) > 0) {
require('./config/img_vars.php');
require('./code/entry.class.php');
$rank = $dbaUsers->getUserRankFor($_GET['prj']);
$data = $result[0];
$template->SetGlobalVar('_IDPROP_', $data['id_prop']);
$template->SetTrunkVar('TAB_TITLE', $data['action'] . ' ' . $data['lemma']);
$entry = new Entry($data);
switch ($data['action']) {
case '+':
$action = $ui['propLabelVars']['add'];
break;
case '-':
$action = ($data['id_entry'] == NULL) ? $ui['propLabelVars']['del'] : '<a href="entry.php?prj=' . $_GET['prj'] . '&id=' . $data['id_entry'] . '">' . $ui['propLabelVars']['del'] . '</a>';
break;
case '>':
$action = ($data['id_entry'] == NULL) ? $ui['propLabelVars']['modif'] : '<a href="entry.php?prj=' . $_GET['prj'] . '&id=' . $data['id_entry'] . '">' . $ui['propLabelVars']['modif'] . '</a>';
break;
}
$login = '<a href="member.php?prj=' . $_GET['prj'] . '&id_user=' . $data['id_user'] . '">' . $data['login'] . '</a>';
setlocale(LC_TIME, $ui['datetime']['locale']);
$date = strftime($ui['datetime']['dpattern'], $data['date']);
$fd = (isset($_GET['fd'])) ? 2 : $project['flexionsDepth'];
$entry->createFlexions ($dbaFlags, $_GET['prj'], $project, 0, $fd);
$allflexions = (isset($_COOKIE['login']) and $entry->is2lvlFlexions) ? '<a href="proposition.php?prj=' . $_GET['prj'] . '&id=' . $data['id_prop'] . '&fd=2">[' . $ui['entryVars']['allflexions'] . ']</a>' : '';
$template->SetBranchVars('prop', $ui['proposition']);
$subcmd = '';
$notifopacity = '0.33';
if (isset($_SESSION['id_user'])) {
list($ok, $res) = $dbaPropositions->checkSubscription($_GET['prj'], $data['id_prop'], $_SESSION['id_user']);
$notifopacity = ($res === TRUE) ? '1': '0.33';
$subcmd = 'switchPropSubscription(\'{{_PRJ_}}\', {{_IDPROP_}});';
}
$template->UpdateBranchVars('prop', array('ACTIONIMG' => $uiImgAction[$data['action']],
'VALUEIMG' => $uiImgValue[$data['value']],
'ACTION' => $action,
'LABEL' => $data['lemma'],
'LOGIN' => $login,
'DATE' => $date,
'ENTRY' => $entry->createHtmlPresentation(),
'NOTIFOPAC' => $notifopacity,
'SUBCMD' => $subcmd,
'NBNOTIF' => $data['nbnotif'],
'NBFLEXIONS' => count($entry->flexions) . ' ' . $ui['entry']['flexions'],
'ALLFLEXIONS' => $allflexions
));
$template->SetBranchVars('nav', $ui['propNav']);
$template->UpdateBranchVars('nav', array('DATETIME' => $data['date'],
'TAB' => '&tab='.$data['tab']
));
// custom links
$links = $entry->createLinks();
$template->UpdateBranchVars('prop', array('SRCLINKS' => $links, 'CUSTOMLINKS' => str_replace('%s', htmlentities($data['lemma'], ENT_COMPAT, 'UTF-8'), $links)));
// flexions
foreach ($entry->flexions as $flexion) {
if (isset($prjDic[$flexion[2]])) {
$flexdic = ($flexion[2] != '*') ? ' <samp>[' . $prjDicAbr[$flexion[2]] . ']</samp>' : '';
}
else {
$flexdic = ' <samp>[' . $ui['sysMsg']['_error'] . ']</samp>';
}
$template->SetBranchVars('prop.flexion', array('LEMMA' => $flexion[0] . ' <a href="http://www.dicollecte.org/dictionary.php?prj=fr&lemma='.$flexion[0].'">→</a>',
'MORPH' => $flexion[1] . $flexdic));
}
// comments
if ($data['nbcomments'] > 0) {
require('./code/dbaccess-comments.class.php');
$dbaComments = new dbaccessComments($db);
list($ok, $result, $nbOccur) = $dbaComments->selectByProp($_GET['prj'], $data['id_prop']);
if ($ok) {
if ($nbOccur > 0) {
$template->SetGlobalVar('_CONFIRMDELETECOM_', $ui['commentGlob']['_CONFIRMDELETECOM_']);
foreach ($result as $datac) {
$date = strftime($ui['datetime']['dtpattern'], $datac['datetime']);
$template->SetBranchVars('comment', array('IDUSER' => $datac['id_user'],
'IDCOM' => $datac['id_com'],
'LOGIN' => $datac['login'],
'COMMENT' => $datac['comment'],
'DATE' => $date));
if ($rank <= 2 or (isset($_SESSION['id_user']) and $datac['id_user'] == $_SESSION['id_user'])) {
$template->SetBranchVars('comment.commactions', array('IDCOM' => $datac['id_com']));
if (!$datac['autocom']) {
$template->SetBranchVars('comment.commedit', $ui['editComment']);
$template->UpdateBranchVars('comment.commedit', array('IDCOM' => $datac['id_com'],
'MAXLENGTH' => $ui['newComment']['MAXLENGTH']));
}
}
}
}
}
else {
$template->SetBranchVars('message', array('MSGHEAD' => 'DATABASE ERROR',
'MESSAGE' => 'Sorry, something went wrong.'));
}
}
// your comment
if (isset($_COOKIE['login']) and ($data['tab'] == 'E' or $data['tab'] == 'R')) {
$template->SetBranchVars('yourcomment', $ui['newComment']);
}
// edition
if ($data['tab'] == 'E' and ($rank <= 5 or ($rank <= 7 and isset($_SESSION['id_user']) and $_SESSION['id_user'] == $data['id_user']))) {
$template->SetBranchVars('prop.priority', array());
$template->SetTrunkVar('STARVALUE', $data['prio']);
if ($data['action'] == '+' or $data['action'] == '>') {
require('./config/db_vars.php');
$template->SetBranchVars('prop.editbutton', $ui['propEditButton']);
$template->SetBranchVars('prop.edit', $ui['propEdit']);
$isUDisabled = ($rank > 3) ? 'disabled="disabled"' : '';
$template->UpdateBranchVars('prop.edit', array('ENTRYFORM' => $entry->createHtmlForm(), 'UDISABLED' => $isUDisabled));
}
}
// proposition under consideration
if ($data['tab'] == 'E' and $rank <= 5) {
$template->SetBranchVars('action', $ui['propAction']);
$template->SetBranchVars('action.evaluate', $ui['propActionEval']);
$template->SetBranchVars('action.forbidbutton', array('FORBID' => $ui['propActionVars']['forbid'],
'CONFIRMFORBID' => $ui['propActionVars']['confirmforbid']));
$template->SetBranchVars('action.trashbutton', array('TRASH' => $ui['propActionVars']['trash'],
'CONFIRMTRASH' => $ui['propActionVars']['confirmtrash']));
if ($data['action'] == '-') {
$template->SetBranchVars('action.changeaction', array('CHANGEACTION' => $ui['propActionVars']['changetomodif'],
'CONFIRMCHANGE' => $ui['propActionVars']['confirmchangetomodif']));
}
elseif ($data['action'] == '>') {
$template->SetBranchVars('action.changeaction', array('CHANGEACTION' => $ui['propActionVars']['changetodel'],
'CONFIRMCHANGE' => $ui['propActionVars']['confirmchangetodel']));
}
if ($rank <= 3 or $rank <= $project['dictDirectEdition']) {
$template->SetBranchVars('action.applybutton', array('APPLYDUBIOUS' => $ui['propActionVars']['applydubious'],
'CONFIRMAPPLYDUBIOUS' => $ui['propActionVars']['confirmapplydubious'],
'VALIDAPPLY' => $ui['propActionVars']['validapply'],
'CONFIRMVALIDAPPLY' => $ui['propActionVars']['confirmvalidapply']
));
}
}
// rejected proposition
if ($data['tab'] == 'R' and $rank <= 5) {
$template->SetBranchVars('action', $ui['propAction']);
if ($data['action'] != '>' and $data['action'] != '-' and $data['value'] != 'I') {
$template->SetBranchVars('action.reevalbutton', array('REEVAL' => $ui['propActionVars']['reeval'],
'CONFIRMREEVAL' => $ui['propActionVars']['confirmreeval']));
}
$template->SetBranchVars('action.trashbutton', array('TRASH' => $ui['propActionVars']['trash'],
'CONFIRMTRASH' => $ui['propActionVars']['confirmtrash']));
}
// proposition in the basket
if ($data['tab'] == 'T' and $rank <= 5) {
$template->SetBranchVars('action', $ui['propAction']);
if ($data['value'] != 'I' and $data['action'] != '>' and $data['action'] != '-') {
$template->SetBranchVars('action.reevalbutton', array('REEVAL' => $ui['propActionVars']['reeval'],
'CONFIRMREEVAL' => $ui['propActionVars']['confirmreeval']));
}
$template->SetBranchVars('action.forbidbutton', array('FORBID' => $ui['propActionVars']['forbid'],
'CONFIRMFORBID' => $ui['propActionVars']['confirmforbid']));
if ($rank <= 2) {
$template->SetBranchVars('action.erasebutton', array('ERASE' => $ui['propActionVars']['erase'],
'CONFIRMERASE' => $ui['propActionVars']['confirmerase']));
}
}
}
else {
$template->SetBranchVars('message', array('MSGHEAD' => $ui['propMsg']['nothing'],
'MESSAGE' => $ui['propMsg']['nothingmsg']));
}
// display
$template->Grow('./html/div.head.tpl.html');
$template->Grow('./html/proposition.div.tpl.html');
$template->Grow('./html/div.foot.tpl.html');
?>