redmine

Updated

[submodule "genpdf/lib/3dparty/Inflect"]
path = genpdf/lib/3dparty/Inflect
url = https://github.com/mephi-ut/Inflect
[submodule "genpdf/3rdparty/number-to-words"]
path = genpdf/3rdparty/number-to-words
url = https://github.com/kwn/number-to-words
... ...
number-to-words @ 6ca25054
Subproject commit 6ca25054089341a162c53dd6e81cff6478e5f5f5
... ...
... ... @@ -309,7 +309,7 @@ foreach (array('contact', 'user', 'recipient') as $key) {
$appointment = appointment_voip2cps($appointment_voip);
}*/
//if ($key == "recipient") { if (!empty($_COOKIE['debug'])) { print_r($_GET);var_dump($w_id);print_r($appointment);die(); } }
//if ($key == "user") { if (!empty($_COOKIE['debug'])) { print_r($_GET);var_dump($w_id);print_r($appointment);die(); } }
considerAppointment($key, $appointment);
}
... ...
<?php
require_once "lib/3rdparty/Inflect/Inflect.php";
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/NumberToWords.php';
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/Legacy/Numbers/Words.php';
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/Legacy/Numbers/Words/Locale/Ru.php';
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/Exception/NumberToWordsException.php';
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/NumberTransformer/NumberTransformer.php';
require_once '/var/www/ut.mephi.ru/ut-tex/genpdf/3rdparty/number-to-words/src/NumberTransformer/RussianNumberTransformer.php';
require_once "config.php";
use NumberToWords\NumberToWords;
$_GET = array_merge ($_GET, $_POST);
header( "Content-Type: text/plain" );
//print_r ($_GET); die();
//print_r($_GET);
$me = NULL;
$inflect = new Inflect();
if (!isset($_GET['signer-serialized']))
die('Not authed');
$user_serialized = base64_decode($_GET['signer-serialized']);
$hash = $_GET['signer-signature'];
$date = $_GET['signature-date'];
$good_dates = array(date('Ymd', strtotime('-1 day')), date('Ymd'), date('Ymd', strtotime('+1 day')));
if (!in_array($date, $good_dates)) {
die('Bad date');
}
$_GET['current-date'] = substr($date, 6, 2).".".substr($date, 4, 2).".".substr($date, 0, 4);
$good_signature = 0;
foreach ($SIGNKEYS as $key) {
if (sha1($user_serialized.$key.$date) === $hash) {
$good_signature = 1;
break;
}
}
if ($good_signature == 0)
die('Bad signature');
$user = unserialize($user_serialized);
$user_redmine = NULL;
$username_drupal = $user->login;
$username_real = $username_drupal;
if (in_array($username_real, $ADMINS)) {
if (!empty($_GET['force-login'])) {
$username_drupal = $_GET['force-login'];
$user = json_decode(file_get_contents("https://ut.mephi.ru/getldapentry.php?username=". urlencode($username_drupal) ));
@$user->employee = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&usevoip=true&username=".urlencode($username_drupal) ));
@$user->oauth = $user_oauth;
@$user->login = $login;
//print_r($user);
$_GET['signer-appointment-id'] = empty($_GET['force-appointment-id']) ? $user->employee->WORKPOSITIONS[0]->w_id : $_GET['force-appointment-id'];
}
}
$subordinate_units = array();
if (!empty($user->employee->WORKPOSITIONS)) {
foreach($user->employee->WORKPOSITIONS as $workposition) {
if ($workposition->is_head) {
$subordinate_units[$workposition->subdivision->s_id] = $workposition->subdivision;
}
}
}
//print_r($user);
$employee = $user->employee;
$appointment = null;
foreach ($employee->WORKPOSITIONS as $_appointment) {
if ($_appointment->w_id == $_GET['signer-appointment-id']) {
$appointment = $_appointment;
break;
}
}
if (empty($employee)) {
die("The employee doesn't exists");
}
$dont_inflect_patterns = array(
'/^нач\./',
'/^зам\./',
'/^заф\./',
'/^нач\./',
'/^\./',
'/^спец\./',
);
$inflect_cut_patterns = array(
//'/^(.*)[иы]й[ ]/', // Commented due to task: https://tasks.mephi.ru/issues/49157
'/^\[\d+\] /',
);
$inflect_appointment_abj_patterns = array(
'/^(.*)[иы]й[ ]/', // https://tasks.mephi.ru/issues/49157
);
$inflect_ignore_ending_patterns = array(
'[ ].*',
);
function _tempdir_cleanup($dir) {
# system('rm -rf "'.$dir.'"');
}
function tempdir($dir=FALSE, $prefix='php') {
$tempfile = tempnam(sys_get_temp_dir(),'');
if (file_exists($tempfile))
unlink($tempfile);
mkdir($tempfile);
if (is_dir($tempfile)) {
register_shutdown_function("_tempdir_cleanup", $tempfile);
return $tempfile;
}
return FALSE;
}
function body_parse($body, $data) {
$data_withbraces = array();
foreach ($data as $key => $value)
$data_withbraces['[{'.$key.'}]'] = $value;
$body = str_replace(array_keys($data_withbraces), array_values($data_withbraces), $body);
return $body;
}
function error($str) {
die($str);
header('Location: '.$_GET['callback_url'].'?errmsg='.urlencode($str));
error_log($str);
exit(0);
}
function latexSpecialChars( $string )
{
$map = array(
"#"=>"\\#",
"$"=>"\\$",
"%"=>"\\%",
"&"=>"\\&",
"~"=>"\\~{}",
"_"=>"\\_",
"^"=>"\\^{}",
"\\"=>"\\textbackslash ",
"{"=>"\\{",
"}"=>"\\}",
);
return preg_replace( "/([\^\%~\\\\#\$%&_\{\}])/e", "\$map['$1']", $string );
}
function my_mb_ucfirst($str, $e='utf-8') {
$fc = mb_strtoupper(mb_substr($str, 0, 1, $e), $e);
return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e);
}
function formatDate($date) {
$date = split('T', split(' ', $date)[0])[0];
$words = split('-', $date);
return $words[2].'.'.$words[1].'.'.$words[0];
}
$file = $_GET['file'];
$datas = array();
switch ($file) {
case 'form/updatesalary':
case 'form/updateenddate': {
$themes_raw = json_decode(file_get_contents('https://sd.mephi.ru/api/9/get_themes.json?api_key=JY3FUioBmsu1o'), 1);
$themes = array();
foreach($themes_raw as $theme_raw) {
$themes['1'.$theme_raw['bcod'].$theme_raw['ecod']] = $theme_raw;
}
//print_r($themes);die();
function newFormularData($stfCardId) {
global $themes;
$salaries = array(
'1-1' => 7800,
'1-2' => 7810,
'2-1' => 7820,
'2-2' => 7830,
'2-3' => 7840,
'2-4' => 7850,
'2-5' => 7855,
'3-1' => 7860,
'3-2' => 7870,
'3-3' => 7880,
'3-4' => 7890,
'3-5' => 7900,
'4-1' => 7910,
'4-2' => 7920,
'4-3' => 7930,
'4-4' => 8240,
'4-5' => 8585,
'4-6' => 8925,
);
$a = json_decode(file_get_contents('https://sd.mephi.ru/api/1/formulars.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_StfCardId='.preg_replace('/[^0-9]+/', '', $stfCardId)), 1)[0];
$profKvalLevel = preg_replace('/[.].*+/', '', @$a['ProfKvalLevel']);
$salary = $a['RateAmount']*$salaries[(@$a['ProfKvalGroup']).'-'.$profKvalLevel];
$employeePrefix = '';
if ($a['Cod_Tip_formular']==3 || $a['Cod_Tip_formular']==5) { // Совместитель
$as = json_decode(file_get_contents('https://sd.mephi.ru/api/1/formulars.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_EmpGUID'.preg_replace('/[^0-9]+/', '', $a['EmpGUID'])), 1);
$employeePrefix = '________________________________';
foreach ($as as $_a) {
if ($_a['Cod_Tip_formular'] == 2) {
$words0 = split(' ', chop($a['Name']));
$words1 = split(' ', $inflect->getInflectName($a['Name_podr'], 0));
if ($words0[count($words0)-1] == $words1[0]) {
unset($words0[count($words0)-1]);
}
$employeePrefix = join(' ', array_merge($words0, $words1));
break;
}
}
}
$unitName = '_________________';
$unitHead = '_________________';
if (!empty($a['ChiefName'])) {
//$unitHeadFullname = $curUnit['ChiefName'];
$unitName = mb_strtoupper(chop($a['Podr_BriefName'])).' ['.$a['Code'].']';
$unitHeadFullname = preg_replace('/[ ][ ]+/', ' ', chop(str_replace(array('и.о. ', 'и.о.'), array('', ''), preg_replace('/[0-9].*+/', '', chop($a['ChiefName'])))));
$unitHeadNameWords = split(' ', preg_replace('/[А-Я][.]/', '', $unitHeadFullname));
$unitHeadLastname = $unitHeadNameWords[0];
if (mb_strtoupper($a['SurName']) == mb_strtoupper($unitHeadLastname)) {
$curUnit = json_decode(file_get_contents('https://sd.mephi.ru/api/1/units.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_id='.preg_replace('/[^0-9]+/', '', $a['OrgDiv'])), 1)[0];
$parentUnit = json_decode(file_get_contents('https://sd.mephi.ru/api/1/units.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_id='.preg_replace('/[^0-9]+/', '', $curUnit['ParentId'])), 1)[0];
$unitName = mb_strtoupper(chop($parentUnit['BriefName'])).' ['.$parentUnit['Code'].']';
$unitHeadFullname = $parentUnit['ChiefName'];
$unitHeadNameWords = split(' ', preg_replace('/[А-Я][.]/', '', $unitHeadFullname));
$unitHeadLastname = $unitHeadNameWords[0];
}
if (count($unitHeadNameWords) != 3) {
$employeesByLastname = json_decode(file_get_contents('https://sd.mephi.ru/api/1/formulars.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_SurName='.preg_replace('/[^а-яА-Я]+/', '', $unitHeadLastname)), 1);
$fullnames = array();
foreach ($employeesByLastname as $employee) {
$fullnames[$employee['SurName'].' '.$employee['FirstName'].' '.$employee['MiddleName']] = true;
}
if (count($fullnames) == 1) {
$unitHeadFullname = $fullnames[0];
$unitHeadNameWords = split(' ', $unitHeadFullname);
}
}
if (count($unitHeadNameWords) == 3) {
$unitHead = $unitHeadNameWords[0].' '.mb_substr($unitHeadNameWords[1], 0, 1).'.'.mb_substr($unitHeadNameWords[2], 0, 1).'.';
}
}
$numberToWords = new NumberToWords();
$numberTransformer = $numberToWords->getNumberTransformer('ru');
$account = '_____________';
$account_manager = '_________________';
if (!empty($themes[$a['Code']])) {
//$account = $themes[$a['Code']]['theme'];
}
return array(
'of-prorector' => '_________________',
'prorector' => '_________________',
'attorney-date' => '«___» __________ 20___г',
'attorney-code' => '_____________',
'of-unit' => $unitName,
'unit-head' => $unitHead,
'employee' => $a['SurName'].' '.mb_substr($a['FirstName'], 0, 1).'.'.mb_substr($a['MiddleName'], 0, 1).'.',
'employee-full' => $employeePrefix.$a['SurName'].' '.$a['FirstName'].' '.$a['MiddleName'],
'employment-contract-date' => formatDate($a['ContDate']),
'employment-contract-code' => $a['ContNo'],
'ProfKvalGroup' => @$a['ProfKvalGroup'],
'ProfKvalLevel' => $profKvalLevel,
'Salary' => $salary.' руб.',
'SalaryText' => $numberTransformer->toWords($salary).' рублей ноль копеек',
'MultiplyingFactor' => '______',
'MultiplyingFactorReason' => '_________________________________',
'endDateWas' => formatDate($a['EndDate']),
'endDateBecame' => $_GET['newEndDate'],
'account' => $account,
'account-manager' => $account_manager,
'change-date' => '«___» __________ 20___г',
);
}
switch ($_GET['object-type']) {
case 'employee':
$employee_id = @$_GET['employee-id'];
if (empty($employee_id))
die('employee_id is empty');
$employee = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&e_id=".urlencode($employee_id) ), 1)[$employee_id];
foreach ($employee['WORKPOSITIONS'] as $idx => $workposition) {
if (empty($subordinate_units[$workposition['s_id']])) {
unset($employee['WORKPOSITIONS'][$idx]);
}
}
if (empty($employee['WORKPOSITIONS'])) {
die("Нет должностей данного сотрудника в вашем подчинении");
}
foreach ($employee['WORKPOSITIONS'] as $workposition) {
$newData = newFormularData($workposition['w_id']);
if (!empty($newData)) {
$datas[] = $newData;
}
}
// $unit;
break;
case 'unit':
$unit_id = @$_GET['unit-id'];
if (empty($unit_id))
die('unit_id is empty');
if (empty($subordinate_units[$unit_id]))
die('У вас нет прав для доступа к данному подразделению');
$unit_id_asu = preg_replace('/[^0-9]+/', '', $unit_id);
$unit_ids = array($unit_id_asu);
$check_unit_ids = array($unit_id_asu);
while ($id = array_shift($check_unit_ids)) {
$units = json_decode(file_get_contents('https://sd.mephi.ru/api/1/units.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_ParentId='.$id), 1);
foreach ($units as &$unit) {
array_push($unit_ids, $unit['id']);
array_push($check_unit_ids, $unit['id']);
}
}
$formulars = array();
foreach($unit_ids as $unit_id) {
$l_formulars = json_decode(file_get_contents('https://sd.mephi.ru/api/1/formulars.json?from_local_db=true&active_only=true&api_key='.SDAPI_KEY.'&filter_OrgDiv='.$unit_id), 1);
$formulars = array_merge($formulars, $l_formulars);
}
foreach ($formulars as &$formular) {
$newData = newFormularData($formular['StfCardId']);
if (!empty($newData)) {
$datas[] = $newData;
}
}
break;
default:
die('Unknown object type: '.$_GET['object-type']);
}
break;
}
default:
die("Don't know how to generate PDF for ".$file);
}
//print_r($_GET); print_r($user); print_r($datas);die();
if (empty($datas)) {
die("Нет данных для обработки");
}
foreach ($datas as $data) {
$tempdir = tempdir();
if ($tempdir === FALSE)
die('Cannot create temporary directory');
exec('cp -a /var/www/'.$_SERVER['SERVER_NAME'].'/ut-tex/mephimemo "'.$tempdir.'/"');
chdir($tempdir.'/mephimemo');
file_put_contents("request.data", print_r($data, true));
foreach ($data as $key => &$value)
$value = latexSpecialChars($value);
file_put_contents("request.data.fixed", print_r($data, true));
switch ($file) {
case 'form/updatesalary':
case 'form/updateenddate':
$header = '\mmsagreementheader{'.$data['of-prorector'].'}{'.$data['attorney-date'].'}{'.$data['attorney-code'].'}{'.$data['employee-full'].'}{'.$data['employment-contract-date'].'}{'.$data['employment-contract-code'].'}{'.$data['change-date'].'}';
$footer = '\mmsagreementfooter{'.$data['prorector'].'}{'.$data['of-unit'].'}{'.$data['unit-head'].'}{'.$data['account'].'}{'.$data['account-manager'].'}{}{}{'.$data['employee'].'}';
break;
}
$body_template = file_get_contents('template/'.$file.'.tex');
$body = body_parse($body_template, $data);
file_put_contents('header.tex', $header);
file_put_contents('body.tex', $body);
file_put_contents('footer.tex', $footer);
file_put_contents('responsible.tex', '');
file_put_contents('urlqr.tex', '');
exec('make');
$pdf_content = file_get_contents('memo.pdf');
if ( empty($pdf_content) )
{
error('Can not create pdf');
}
if (preg_match('/Firefox/i', $_SERVER['HTTP_USER_AGENT'])) {
system('convert -density 400 memo.pdf memo.png');
system('convert -density 400 memo*.png memo_png.pdf');
$pdfs_path[] = getcwd().'/memo_png.pdf';
$pdf_content = file_get_contents('memo_png.pdf');
} else
$pdfs_path[] = getcwd().'/memo.pdf';
$pdfs_content[] = $pdf_content;
}
$count = count($pdfs_path);
if ($count == 0) {
exit(0);
}
header('Content-type: application/pdf');
if ($count == 1) {
print $pdfs_content[0];
exit(0);
}
if ($count > 1) {
$tempdir = tempdir();
chdir($tempdir);
system('pdfunite '.join(' ', $pdfs_path).' memo_unite.pdf');
print file_get_contents('memo_unite.pdf');
exit(0);
}
?>
... ...
... ... @@ -180,14 +180,14 @@
\textbf{Работник:}
\newline
\newline
\signature{employee}
\signature{#8}
\blankdate
\newline
\newline
\newline
\newline
\textbf{Настоящее доп. соглашение составлено в 2-х экземплярах (один из которых хранится в отделе кадров, а другой получил)}
\signature{employee}
\signature{#8}
\blankdate
\end{multicols}
}
... ...
\begin{enumerate}
\item В пункте 1.4 Трудового договора слова «окончание работы [{endDateWas}]» заменить словами «окончание работы {{endDateBecame}}».
\item В пункте 1.4 Трудового договора слова «окончание работы [{endDateWas}]» заменить словами «окончание работы [{endDateBecame}]».
\end{enumerate}
... ...
... ... @@ -5,7 +5,7 @@
\item «п.3.4. Заработная плата по настоящему трудовому договору выплачивается два раза в месяц
\item Профессиональная квалификационная группа [{ProfKvalGroup}]
\item Профессиональный квалификационный уровень [{ProfKvalLevel}]
\item Должностной оклад в соответствии с профессональной квалификационной группой и профессиональным квалафикационным уровнем работника составляет [{Salary}] ([{SalaryText}])
\item Должностной оклад в соответствии с профессиональной квалификационной группой и профессиональным квалификационным уровнем работника составляет [{Salary}] ([{SalaryText}])
\item Повышающий коэффициент [{MultiplyingFactor}] [{MultiplyingFactorReason}
\end{description}
}
... ...