Showing
3 changed files
with
140 additions
and
8 deletions
genpdf/decide-note.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/AbstractApi.php"; | ||
4 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/SimpleXMLElement.php"; | ||
5 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/User.php"; | ||
6 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php"; | ||
7 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/IssueCategory.php"; | ||
8 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php"; | ||
9 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Membership.php"; | ||
10 | +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php"; | ||
11 | + | ||
12 | +require_once "lib/3rdparty/Inflect/Inflect.php"; | ||
13 | + | ||
14 | +require_once "config.php"; | ||
15 | + | ||
16 | +function redmine_proj_identifier2id ($ident) { | ||
17 | + error_log("redmine_proj_identifier($ident)"); | ||
18 | + static $ident2id = array(); | ||
19 | + | ||
20 | + if (empty($ident2id)) { | ||
21 | + $lines = split("\n", file_get_contents('/opt/redmine_projects.csv')); | ||
22 | + | ||
23 | + foreach ($lines as &$line) { | ||
24 | + $words = split("\t", $line); | ||
25 | + $ident2id[strtolower($words[1])] = $words[0]; | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + error_log ('RI:'.$ident2id[strtolower($ident)]); | ||
30 | + | ||
31 | + | ||
32 | + return $ident2id[strtolower($ident)]; | ||
33 | +} | ||
34 | + | ||
35 | +foreach (array('issueId', 'action', 'signature') as $k) | ||
36 | + if (empty($k)) | ||
37 | + die('field "'.$k.'" is empty'); | ||
38 | + | ||
39 | +$isGoodSignature = false; | ||
40 | + | ||
41 | +foreach ($SIGNKEYS as $key) { | ||
42 | + if (sha1($_GET['issueId'].$key) == $_GET['signature']) { | ||
43 | + $isGoodSignature = true; | ||
44 | + break; | ||
45 | + } | ||
46 | +} | ||
47 | + | ||
48 | +if ($isGoodSignature === false) { | ||
49 | + die('bad signature'); | ||
50 | +} | ||
51 | + | ||
52 | +$redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); | ||
53 | +$issue = $redmine_admin->api('issue')->show($_GET['issueId'])['issue']; | ||
54 | + | ||
55 | +$assignedTo = $redmine_admin->api('user' )->show($issue['assigned_to']['id']); | ||
56 | + | ||
57 | +$api_key = $assignedTo['user']['api_key']; | ||
58 | +$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key); | ||
59 | + | ||
60 | +switch ($_GET['action']) { | ||
61 | + case 'agree': | ||
62 | + header('Content-Type: text/plain'); | ||
63 | + | ||
64 | + $recipientId = NULL; | ||
65 | + foreach ( $issue['custom_fields'] as $cf) { | ||
66 | + if ($cf['id'] == 95) { | ||
67 | + $recipientId = $cf['value']; | ||
68 | + break; | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + if (is_null($recipientId)) { | ||
73 | + die('Cannot find recipient custom field in issue: '.$_GET['issueId']); | ||
74 | + } | ||
75 | + $recipient = $redmine_admin->api('user')->show($recipientId)['user']; | ||
76 | + | ||
77 | + if (empty($recipient['mail'])) { | ||
78 | + die('Cannot find login of user with ID: '.$recipientId); | ||
79 | + } | ||
80 | + | ||
81 | + //print @json_encode($redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_NEW, 'project_id' => redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])), 'assigned_to_id' => $recipient['id']))); | ||
82 | + $result = $redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_NEW, 'project_id' => redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])), 'assigned_to_id' => $recipient['id'])); | ||
83 | + if ($result == true) { | ||
84 | + header('Location: https://tasks.mephi.ru/issues/'.$_GET['issueId']); | ||
85 | + } | ||
86 | + break; | ||
87 | + case 'decline': | ||
88 | + header('Content-Type: text/plain'); | ||
89 | + | ||
90 | + //print @json_encode($redmine->api('issue')->update($_GET['issueId'], array('status_id' => STATUSID_DECLINED))); | ||
91 | + $result = $redmine->api('issue')->update($_GET['issueId'], array('status_id' => STATUSID_DECLINED)); | ||
92 | + if ($result == true) { | ||
93 | + header('Location: https://tasks.mephi.ru/issues/'.$_GET['issueId']); | ||
94 | + } | ||
95 | + break; | ||
96 | + default: | ||
97 | + die('Unknown action: '.$_GET['action']); | ||
98 | +} | ||
99 | + | ||
100 | + | ||
101 | +?> |
@@ -143,6 +143,10 @@ header( "Content-Type: text/plain" ); | @@ -143,6 +143,10 @@ header( "Content-Type: text/plain" ); | ||
143 | //print_r ($_GET); die(); | 143 | //print_r ($_GET); die(); |
144 | //print_r($_GET); | 144 | //print_r($_GET); |
145 | 145 | ||
146 | +if (isset($_GET['signer2user'])) { | ||
147 | + $_GET['user-appointment-id'] = $_GET['signer-appointment-id']; | ||
148 | +} | ||
149 | + | ||
146 | $me = NULL; | 150 | $me = NULL; |
147 | 151 | ||
148 | $inflect = new Inflect(); | 152 | $inflect = new Inflect(); |
@@ -786,7 +790,13 @@ foreach ($files as $file) { | @@ -786,7 +790,13 @@ foreach ($files as $file) { | ||
786 | break; | 790 | break; |
787 | case 'request/custom': | 791 | case 'request/custom': |
788 | //print_r($_GET);die(); | 792 | //print_r($_GET);die(); |
789 | - $project_id = redmine_proj_identifier2id ($_GET['recipient-login']); | 793 | + if ($_GET['user-appointment-id'] != $_GET['signer-appointment-id']) { |
794 | + $project_id = 15971; | ||
795 | + $_GET['recipient-redmine-id'] = redmine_login2id($_GET['recipient-login']); | ||
796 | + $custom_fields_keys = array (95 => 'recipient-redmine-id'); | ||
797 | + } else { | ||
798 | + $project_id = redmine_proj_identifier2id ($_GET['recipient-login']); | ||
799 | + } | ||
790 | $memo_subject = 'Служебная записка'; | 800 | $memo_subject = 'Служебная записка'; |
791 | $me['id'] = $user_redmine['user']['id']; | 801 | $me['id'] = $user_redmine['user']['id']; |
792 | $replacement_is_already_done = true; | 802 | $replacement_is_already_done = true; |
@@ -1051,7 +1061,8 @@ foreach ($files as $file) { | @@ -1051,7 +1061,8 @@ foreach ($files as $file) { | ||
1051 | case 'request/custom': | 1061 | case 'request/custom': |
1052 | $header = '\mmheader{'.my_mb_ucfirst($_GET['to-recipient-appointment-w-fullsubdiv-cap']).'}{'.my_mb_ucfirst($_GET['to-recipient-name']).'}'; | 1062 | $header = '\mmheader{'.my_mb_ucfirst($_GET['to-recipient-appointment-w-fullsubdiv-cap']).'}{'.my_mb_ucfirst($_GET['to-recipient-name']).'}'; |
1053 | $body = latexSpecialChars1(str_replace("\n", "\n\n", $body)); | 1063 | $body = latexSpecialChars1(str_replace("\n", "\n\n", $body)); |
1054 | - $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['signer-name'].'}{'.$_GET['current-date'].'}{}'; | 1064 | + $footer = '\mmfooter{'.my_mb_ucfirst($_GET['user-appointment']).'}{'.$_GET['user-name'].'}{'.$_GET['current-date'].'}{}'; |
1065 | + | ||
1055 | 1066 | ||
1056 | 1067 | ||
1057 | // $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['current-date'].'}{'.$_GET['signer-name'].'}{}'; | 1068 | // $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['current-date'].'}{'.$_GET['signer-name'].'}{}'; |
@@ -1155,14 +1166,19 @@ foreach ($files as $file) { | @@ -1155,14 +1166,19 @@ foreach ($files as $file) { | ||
1155 | 1166 | ||
1156 | 1167 | ||
1157 | 1168 | ||
1158 | - case 'request/custom': //AASD | 1169 | + case 'request/custom': |
1170 | + if ($_GET['user-appointment-id'] != $_GET['signer-appointment-id']) { | ||
1171 | + $assigned_to_id = redmine_login2id($_GET['user-login']); | ||
1172 | + } else { | ||
1173 | + $assigned_to_id = redmine_login2id($_GET['recepient-login']); | ||
1174 | + } | ||
1175 | + | ||
1159 | $issue_props = | 1176 | $issue_props = |
1160 | array( | 1177 | array( |
1161 | - 'assigned_to_id' => redmine_login2id($_GET['recepient-login']), | 1178 | + 'assigned_to_id' => $assigned_to_id, |
1162 | 'project_id' => $project_id, | 1179 | 'project_id' => $project_id, |
1163 | 'subject' => 'Служебная записка '.$_GET['to-recipient-name'].' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"), | 1180 | 'subject' => 'Служебная записка '.$_GET['to-recipient-name'].' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"), |
1164 | 'description' => "<pre>".$text."</pre>", | 1181 | 'description' => "<pre>".$text."</pre>", |
1165 | - | ||
1166 | ); | 1182 | ); |
1167 | break; | 1183 | break; |
1168 | 1184 | ||
@@ -1210,7 +1226,8 @@ foreach ($files as $file) { | @@ -1210,7 +1226,8 @@ foreach ($files as $file) { | ||
1210 | if (!empty($_GET['category_id'])) | 1226 | if (!empty($_GET['category_id'])) |
1211 | $issue_props['category_id'] = $_GET['category_id']; | 1227 | $issue_props['category_id'] = $_GET['category_id']; |
1212 | 1228 | ||
1213 | - | 1229 | + //print_r($issue_props);die(); |
1230 | + | ||
1214 | error_log(base64_encode(serialize($issue_props))); | 1231 | error_log(base64_encode(serialize($issue_props))); |
1215 | 1232 | ||
1216 | $key = serialize($issue_props); | 1233 | $key = serialize($issue_props); |
@@ -1241,7 +1258,21 @@ foreach ($files as $file) { | @@ -1241,7 +1258,21 @@ foreach ($files as $file) { | ||
1241 | } | 1258 | } |
1242 | } | 1259 | } |
1243 | 1260 | ||
1244 | - file_put_contents('urlqr.tex', '\mmredmineurlqr{'.$issue_id.'}'); | 1261 | + $qr = '\mmredmineurlqr{'.$issue_id.'}'; |
1262 | + switch($file) { | ||
1263 | + case 'request/custom': | ||
1264 | + if ($_GET['user-appointment-id'] != $_GET['signer-appointment-id']) { | ||
1265 | + $qr .= ' | ||
1266 | +\vspace{-2.8cm} | ||
1267 | +\begin{flushleft} | ||
1268 | + Подготовил(а):\\\\ | ||
1269 | + '.$_GET['signer-name'].' | ||
1270 | +\end{flushleft}'; | ||
1271 | + } | ||
1272 | + break; | ||
1273 | + } | ||
1274 | + | ||
1275 | + file_put_contents('urlqr.tex', $qr); | ||
1245 | 1276 | ||
1246 | if (isset($user_redmine['user']['id'])) | 1277 | if (isset($user_redmine['user']['id'])) |
1247 | $redmine_admin->api('issue')->addWatcher($issue_id, $user_redmine['user']['id']); | 1278 | $redmine_admin->api('issue')->addWatcher($issue_id, $user_redmine['user']['id']); |
-
Please register or login to post a comment