-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaffixes.php
148 lines (137 loc) · 7.11 KB
/
affixes.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
<?php
require('./config/config.php');
require('./code/init.php');
require('./code/dbaccess.class.php');
require('./code/dbaccess-flags.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);
$db = new Database();
$dbaUsers = new dbaccessUsers($db);
$dbaFlags = new dbaccessFlags($db);
$template = new Template();
$template->SetPageVars($_GET['prj'], 'affixes', $dbaUsers);
$template->SetTrunkVar('TAB_TITLE', $ui['tabs']['affixes']);
$template->SetTrunkVars($ui['affixes']);
if ($db->connx) {
list($ok, $result) = $dbaFlags->listAllFlags($_GET['prj']);
if ($ok) {
if (count($result) > 0) {
$allflags = '';
foreach ($result as $data) {
$allflags .= '<a href="affixes.php?prj=' . $_GET['prj'] . '&flag=' . rawurlencode($data['flag']) . '">' . $data['flag'] . '</a> ';
}
$template->SetTrunkVar('ALLFLAGS', $allflags);
}
}
else {
$template->SetBranchVars('message', array('MESSAGE' => 'DATABASE ERROR'));
}
$rank = $dbaUsers->getUserRankFor($_GET['prj']);
if ($rank <= 3) {
$template->SetBranchVars('leftbuttons', $ui['flagLeftButtons']);
$template->SetBranchVars('newflag', $ui['flagNew']);
}
// flag and its affixes
if (isset($_GET['flag'])) {
function str_pad_u8($input, $pad_length) {
$length = $pad_length - iconv_strlen($input, "UTF-8");
if ($length > 0) {
return $input . str_repeat(' ', $length);
}
else {
return $input;
}
}
$flag = rawurldecode($_GET['flag']);
list($ok, $result) = $dbaFlags->selectFlag($_GET['prj'], $flag);
if (!$ok) {
setSysMsg('_dberror');
header(URL_HEADER . 'affixes.php?prj=' . $_GET['prj']);
exit;
}
if (count($result) > 0) {
$flag = stripslashes($flag);
if ($rank <= 3) {
$template->SetBranchVars('rightbuttons', $ui['flagRightButtons']);
$template->UpdateBranchVars('rightbuttons', array('FLAGNAME' => $flag,
'FLAGURL' => rawurlencode($flag)));
$template->SetBranchVars('editflag', $ui['flagEdit']);
$flagrules = '';
}
$i = 0;
foreach ($result as $data) {
if ($i == 0) {
$afftype = ($data['afftype'] == 'P') ? $ui['flagTypeVars']['prefix'] : $ui['flagTypeVars']['suffix'];
$mix = ($data['mix'] == 't') ? $ui['flagTypeVars']['mixyes'] : $ui['flagTypeVars']['mixno'];
$template->SetbranchVars('flag', $ui['flag']);
$template->UpdateBranchVars('flag', array('NAME' => $data['flag'],
'TYPE' => $afftype,
'MIX' => $mix));
if ($rank <= 3) {
$linehead = ($data['afftype'] == 'P') ? 'PFX ' . $flag . ' ' : 'SFX ' . $flag . ' ';
$firstline = ($data['mix'] == 't') ? $linehead . 'Y ' : $linehead . 'N ' ;
}
}
if ($data['flags'] != '') $flags = '/' . $data['flags']; else $flags = '';
$dictlbl = (isset($prjDicAbr[$data['dic']])) ? $prjDicAbr[$data['dic']] : 'error!';
$dictcell = ($data['dic'] != '*') ? '<samp>' . $dictlbl . '</samp>' : $dictlbl;
$morph = '';
if ($data['po'] != '') { $morph .= $dbaFlags->fieldToHunspell('po', $data['po']); }
if ($data['is'] != '') { $morph .= $dbaFlags->fieldToHunspell('is', $data['is']); }
if ($data['ds'] != '') { $morph .= $dbaFlags->fieldToHunspell('ds', $data['ds']); }
if ($data['ts'] != '') { $morph .= $dbaFlags->fieldToHunspell('ts', $data['ts']); }
if ($data['ip'] != '') { $morph .= $dbaFlags->fieldToHunspell('ip', $data['ip']); }
if ($data['dp'] != '') { $morph .= $dbaFlags->fieldToHunspell('dp', $data['dp']); }
if ($data['tp'] != '') { $morph .= $dbaFlags->fieldToHunspell('tp', $data['tp']); }
if ($data['sp'] != '') { $morph .= $dbaFlags->fieldToHunspell('sp', $data['sp']); }
$template->SetBranchVars('flag.rule', array('CUT' => $data['cut'],
'ADD' => $data['add'],
'FLAGS' => $flags,
'COND' => $data['cond'],
'GRAMM' => $morph,
'DIC' => $dictcell));
if ($rank <= 3) {
$cut = ($data['cut'] != '') ? $data['cut'] : '0';
$add = ($data['add'] != '') ? $data['add'] : '0';
$flagrules .= $linehead . ' '. str_pad_u8($cut, 16) . ' ' . str_pad_u8($add . $flags, 24) . ' ' . str_pad_u8($data['cond'], 16) . ' '
. $morph . ' di:' . $data['dic'];
$flagrules .= ($data['comment'] != '') ? ' #' . $data['comment'] . PHP_EOL : PHP_EOL;
}
$i = $i + 1;
}
$template->SetTrunkVars(array('NBRULES' => $i, 'RULES' => $ui['flag']['RULES']));
if ($rank <= 3) {
$firstline .= $i . "\n";
$flagrules = $firstline . $flagrules;
$template->UpdateBranchVars('editflag', array('FLAGRULES' => $flagrules));
}
}
}
// entry and flexions
if (isset($_POST['entry']) and strpos($_POST['entry'], '/') !== FALSE) {
$entry = stripslashes($_POST['entry']);
list($lemma, $flags) = preg_split('`/`', $entry, 2);
if ($lemma != '') {
require('./html/' . $_GET['prj'] . '/project_vars.php');
require('./code/entry.class.php');
$data = array('lemma' => $lemma, 'flags' => $flags);
$entry = new Entry($data);
$entry->createFlexions($dbaFlags, $_GET['prj'], $project, 0, 2);
$template->SetBranchVars('flexionslist', $ui['myEntry']);
$template->UpdateBranchVars('flexionslist', array('LEMMA' => $lemma,
'FLAGS' => $flags,
'NBFLEXIONS' => count($entry->flexions)));
foreach ($entry->flexions as $flexion) {
$template->SetBranchVars('flexionslist.flexion', array('LEMMA' => $flexion[0],
'MORPH' => $flexion[1]));
}
}
}
}
// display
$template->Grow('./html/div.head.tpl.html');
$template->Grow('./html/affixes.div.tpl.html');
$template->Grow('./html/div.foot.tpl.html');
?>