redmine

Updated

@@ -3,3 +3,5 @@ mephimemo/body.tex @@ -3,3 +3,5 @@ mephimemo/body.tex
3 mephimemo/footer.tex 3 mephimemo/footer.tex
4 mephimemo/responsible.tex 4 mephimemo/responsible.tex
5 mephimemo/urlqr.tex 5 mephimemo/urlqr.tex
  6 +mephimemo/memo.aux
  7 +mephimemo/memo.fdb_latexmk
  1 +<?
  2 +
  3 +define('REDMINE_LOGIN', 'login');
  4 +define('REDMINE_PASSWORD', 'PaSsWoRd');
  5 +
  6 +?>
  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/Issue.php";
  6 +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php";
  7 +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
  8 +
  9 +require_once "config.php";
  10 +
  11 +function _tempdir_cleanup($dir) {
  12 +# system('rm -rf "'.$dir.'"');
  13 +}
  14 +
  15 +function tempdir($dir=FALSE, $prefix='php') {
  16 + $tempfile = tempnam(sys_get_temp_dir(),'');
  17 +
  18 + if (file_exists($tempfile))
  19 + unlink($tempfile);
  20 +
  21 + mkdir($tempfile);
  22 + if (is_dir($tempfile)) {
  23 + register_shutdown_function("_tempdir_cleanup", $tempfile);
  24 + return $tempfile;
  25 + }
  26 +
  27 + return FALSE;
  28 +}
  29 +
  30 +function body_parse($body) {
  31 + $_GET_withbraces = array();
  32 +
  33 + foreach ($_GET as $key => $value)
  34 + $_GET_withbraces['[{'.$key.'}]'] = $value;
  35 +
  36 + switch ($_GET['file']) {
  37 + case 'request/vpn':
  38 + if (isset($_GET['vlan']))
  39 + $_GET_withbraces['[{additional-access}]'] = 'Также прошу предоставить доступ к VLAN '. $_GET['vlan']. ' через данную учётную запись.';
  40 + if (!isset($_GET_withbraces['[{is-additional-login}]']));
  41 + $_GET_withbraces['[{is-additional-login}]'] = '';
  42 + break;
  43 + }
  44 +
  45 + $body = str_replace(array_keys($_GET_withbraces), array_values($_GET_withbraces), $body);
  46 +
  47 + return $body;
  48 +}
  49 +
  50 +switch ($_GET['file']) {
  51 + case 'request/vpn':
  52 + $project_id = 1;
  53 + $memo_subject = 'Запрос на учётную запись к vpn.mephi.ru';
  54 + break;
  55 + case 'request/vpn-private-net':
  56 + $project_id = 1;
  57 + $memo_subject = 'Запрос на доступ к VLAN через vpn.mephi.ru';
  58 + break;
  59 + case 'request/nix-hosting':
  60 + $project_id = 1;
  61 + $memo_subject = 'Заявка на предоставление nix-хостинга';
  62 + break;
  63 + case 'request/win-hosting':
  64 + $project_id = 1;
  65 + $memo_subject = 'Заявка на предоставление win-хостинга';
  66 + break;
  67 + case 'request/hpc':
  68 + $project_id = NULL; //38;
  69 + $memo_subject = 'Запрос на учётную запись к vpn.mephi.ru';
  70 + break;
  71 + default:
  72 + die('unknown memo-type');
  73 +}
  74 +
  75 +$tempdir = tempdir();
  76 +
  77 +if ($tempdir === FALSE)
  78 + die('Cannot create temporary directory');
  79 +
  80 +
  81 +exec('cp -a /var/www/ut.mephi.ru/ut-tex/mephimemo "'.$tempdir.'/"');
  82 +chdir($tempdir.'/mephimemo');
  83 +
  84 +ob_start();
  85 +print_r($_GET);
  86 +$_GET_print_r = ob_get_clean();
  87 +
  88 +$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD);
  89 +
  90 +if (!is_null($project_id)) {
  91 + $issue = $redmine->api('issue')->create(
  92 + array(
  93 + 'project_id' => $project_id,
  94 + 'subject' => $memo_subject,
  95 + 'description' => $_GET_print_r,
  96 + )
  97 + );
  98 +
  99 + $issue_id = $issue->id;
  100 +} else {
  101 + $issue_id = $_GET['issue-id'];
  102 +}
  103 +
  104 +if (!isset($_GET['date-end']))
  105 + $_GET['date-end'] = (date('Y')+1).'-12-31';
  106 +
  107 +foreach (array('fullname', 'phonenumber', 'email') as $key)
  108 + if (!isset($_GET['contact-'.$key]))
  109 + $_GET['contact-'.$key] = $_GET['user-'.$key];
  110 +
  111 +foreach ($_GET as $key => &$value)
  112 + $value = str_replace('_', '\_', $value);
  113 +
  114 +$body_template = file_get_contents('template/'.$_GET['file'].'.tex');
  115 +$body = body_parse($body_template);
  116 +
  117 +file_put_contents('header.tex', '\mmheader{Начальнику управления информатизации}{Н. Н. Романову}');
  118 +file_put_contents('body.tex', $body);
  119 +file_put_contents('footer.tex', '\mmfooter{'.$_GET['signer-appointment'].'}{'.$_GET{'signer-fullname'}.'}');
  120 +file_put_contents('responsible.tex', '\mmresponsible{'.$_GET['contact-fullname'].'}{'.$_GET{'contact-phonenumber'}.'}{'.$_GET['contact-email'].'}');
  121 +file_put_contents('urlqr.tex', '\mmredmineurlqr{'.$issue_id.'}');
  122 +
  123 +exec('make');
  124 +$pdf_content = file_get_contents('memo.pdf');
  125 +
  126 +$pdf_upload = json_decode( $redmine->api('attachment')->upload($pdf_content) );
  127 +
  128 +$redmine->api('issue')->attach(
  129 + $issue_id,
  130 + array(
  131 + 'token' => $pdf_upload->upload->token,
  132 + 'filename' => 'memorandum.pdf',
  133 + 'description' => 'Memorandum',
  134 + 'content_type'=> 'application/pdf'
  135 + )
  136 +);
  137 +
  138 +header('Content-type: application/pdf');
  139 +print $pdf_content;
  140 +
  141 +?>
@@ -65,9 +65,9 @@ @@ -65,9 +65,9 @@
65 \small{ 65 \small{
66 Ответственное лицо:\\ 66 Ответственное лицо:\\
67 \vspace{0.2cm} 67 \vspace{0.2cm}
68 - {#1}\\ 68 + ФИО: {#1}\\
69 - IP телефон: {#2}\\ 69 + телефон: {#2}\\
70 - Эл. почта: {#3} 70 + эл. почта: {#3}
71 } 71 }
72 \end{flushleft} 72 \end{flushleft}
73 } 73 }
@@ -78,8 +78,10 @@ @@ -78,8 +78,10 @@
78 \newcommand{\mmredmineurlqr}[1]{ 78 \newcommand{\mmredmineurlqr}[1]{
79 \begin{flushright} 79 \begin{flushright}
80 \parbox{2.1cm}{ 80 \parbox{2.1cm}{
81 - \psbarcode{{http://redmine.ut.mephi.ru/issues/#1}}{}{qrcode} 81 + \psbarcode{{https://redmine.ut.mephi.ru/issues/#1}}{}{qrcode}
82 } 82 }
  83 + \\
  84 + \tiny https://redmine.ut.mephi.ru/issues/#1
83 \end{flushright} 85 \end{flushright}
84 } 86 }
85 87
  1 +Прошу предоставить [{user-appointment}] [{user-fullname}] доступ к ресурсам высокопроизводительного вычислительного центра НИЯУ МИФИ для [{reason-for}].
  2 +
  3 +Предпочитаемое имя пользователя: [{preffered-login}].
  4 +
  5 +Срок окончания работ: [{date-end}]
  1 +Прошу предоставить хостинг на базе «[{os}]» для размещения ресурса «[{domainnames}
  1 +Прошу предоставить [{user-appointment}] [{user-fullname}] доступ к VLAN [{vlan}] посредством сервиса VPN НИЯУ МИФИ по адресу «vpn.mephi.ru» для [{reason-for}].
  2 +
  3 +Имя пользователя: [{preffered-login}].
  1 +Прошу предоставить [{user-appointment}] [{user-fullname}] [{is-additional-login}] учётную запись к сервису VPN НИЯУ МИФИ по адресу «vpn.mephi.ru» для [{reason-for}].
  2 +
  3 +Предпочитаемое имя пользователя: [{preffered-login}].
  4 +
  5 +[{additional-access}]
  1 +Прошу предоставить хостинг на базе «[{os}]» для размещения ресурса «[{domainnames}