diff --git a/.gitignore b/.gitignore index 3fcd5ff..136b279 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ mephimemo/responsible.tex mephimemo/urlqr.tex mephimemo/memo.aux mephimemo/memo.fdb_latexmk +*.log diff --git a/genpdf/genpdf.php b/genpdf/genpdf.php index a8cbea5..e03da64 100644 --- a/genpdf/genpdf.php +++ b/genpdf/genpdf.php @@ -4,6 +4,7 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/AbstractApi.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/SimpleXMLElement.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/User.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php"; +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/IssueCategory.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Membership.php"; require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php"; @@ -86,6 +87,9 @@ Array ) */ +$_GET = array_merge ($_GET, $_POST); +//print_r ($_GET); die(); + $dont_inflect_patterns = array( '/^нач\./', '/^зам\./', @@ -150,13 +154,90 @@ function error($str) { exit(0); } +function latexSpecialChars( $string ) { + $string = str_replace("\\textbackslash", "\\", $string ); + $string = str_replace("\\", "\\textbackslash", $string ); + + $map = array( + "#"=>"\\#", + "$"=>"\\$", + "%"=>"\\%", + "&"=>"\\&", + "~"=>"\\~{}", + "_"=>"\\_", + "^"=>"\\^{}", + "{"=>"\\{", + "}"=>"\\}", + + ); + return preg_replace( "/([\^\%~#\$%&_\{\}])/e", "\$map['$1']", $string ); +} + -//DE base64 subdivs -if (isset($_GET['signer-subdivs'])){ - $_GET['signer-subdivs'] = base64_decode($_GET['signer-subdivs']); +$test = "Test characters: # $ % & ~ _ ^ \ { }."; +header( "content-type:text/plain" ); + +function latexSpecialChars1( $string ) +{ + $map = array( + "#"=>"\\#", + "$"=>"\\$", + "%"=>"\\%", + "&"=>"\\&", + "~"=>"\\~{}", + "_"=>"\\_", + "^"=>"\\^{}", + "\\"=>"\\textbackslash", + "{"=>"\\{", + "}"=>"\\}", + ); + return preg_replace( "/([\^\%~\\\\#\$%&_\{\}])/e", "\$map['$1']", $string ); +} + + + + + +function redmine_login2id ($login) { + error_log("redmine_login2id($login)"); + static $login2id = array(); + + if (empty($login2id)) { + $lines = split("\n", file_get_contents('/home/xaionaro/redmine_users.csv')); + + foreach ($lines as &$line) { + $words = split("\t", $line); + $login2id[strtolower($words[1])] = $words[0]; + } + } + + error_log('R: '.$login2id[strtolower($login)]); + return $login2id[strtolower($login)]; +} + +function redmine_proj_identifier2id ($ident) { + error_log("redmine_proj_identifier($ident)"); + static $ident2id = array(); + + if (empty($ident2id)) { + $lines = split("\n", file_get_contents('/home/xaionaro/redmine_projects.csv')); + + foreach ($lines as &$line) { + $words = split("\t", $line); + $ident2id[strtolower($words[1])] = $words[0]; + } + } + + error_log ('RI:'.$ident2id[strtolower($ident)]); + + + return $ident2id[strtolower($ident)]; } -if (isset($_GET['signer-subdivs-full'])){ - $_GET['signer-subdivs-full'] = base64_decode($_GET['signer-subdivs-full']); + + +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); } $inflect = new Inflect(); @@ -167,31 +248,53 @@ foreach (array('signer', 'contact', 'user') as $key) { if (!empty($_GET[$key.'-e_id'])) { $e_id = $_GET[$key.'-e_id']; - $employees = json_decode(file_get_contents("http://cps.mephi.ru/?cmd=getemployeeinfo&e_id=". urlencode($e_id) )); + $employees = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&e_id=". urlencode($e_id) )); $employee = ((array)$employees); $employee = reset($employee); } else if (!empty($_GET[$key.'-login'])) { $login = $_GET[$key.'-login']; - $employees = json_decode(file_get_contents("http://cps.mephi.ru/?cmd=getemployeeinfo&username=".urlencode($login) )); + $employees = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&username=".urlencode($login) )); $employee = ((array)$employees); $employee = reset($employee); } else continue; - $appointments = array(); + $appointments = array(); + $subdivs = array(); + $subdivs_full = array(); + $appointments_wosubdiv = array(); foreach($employee->WORKPOSITIONS as $workposition) { - $appointments[] = preg_replace('/ [0-9]*.[0-9]$/', '', $workposition->name).' '.mb_strtoupper($workposition->subdivision->shortname); + $appointments[] = preg_replace('/ [0-9]*.[0-9]$/', '', $workposition->name).' '.mb_strtoupper($workposition->subdivision->shortname); + $subdivs[] = $workposition->subdivision->shortname; + $subdivs_full[] = $workposition->subdivision->name; + $appointments_wosubdiv[] = preg_replace('/ [0-9]*.[0-9]$/', '', $workposition->name); } $fullname = $employee->fullname; $name = mb_substr($employee->firstname, 0, 1).'.'.mb_substr($employee->middlename, 0, 1).'. '. $employee->lastname; $appointment = join(', ',$appointments); + + $_GET[$key.'-fullname'] = $fullname; + $_GET[$key.'-name'] = $name; + $_GET[$key.'-appointment'] = $appointment; + $_GET[$key.'-subdivs'] = join(', ',$subdivs); + $_GET[$key.'-subdivs-full'] = join('; ',$subdivs_full); + $_GET[$key.'-appointment-wosubdiv'] = join(', ',$appointments_wosubdiv); + //$appointments_wosubdiv = split(', ', $_GET[$key.'-appointment-wosubdiv']); +} - $_GET[$key.'-fullname'] = $fullname; - $_GET[$key.'-name'] = $name; - $_GET[$key.'-appointment'] = $appointment; +//DE base64 subdivs +foreach (array('signer', 'contact', 'user') as $key) { + if (!empty($_GET[$key.'-e_id'])) + continue; + if (isset($_GET[$key.'-subdivs'])){ + $_GET[$key.'-subdivs'] = base64_decode($_GET[$key.'-subdivs']); + } + if (isset($_GET[$key.'-subdivs-full'])){ + $_GET[$key.'-subdivs-full'] = base64_decode($_GET[$key.'-subdivs-full']); + } } foreach (array('fullname' => 40, 'phonenumber' => 20, 'email' => 30, 'appointment' => 40, 'pgp-id' => 12) as $key => $space) { @@ -213,10 +316,22 @@ foreach (array('signer', 'contact', 'user') as $key) { if (empty($_GET[$key_prefix.'-'.$key.'-fullname'])) $_GET[$key_prefix.'-'.$key.'-fullname'] = $inflect->getInflectName($_GET[$key.'-fullname'], $case); - if (empty($_GET[$key_prefix.'-'.$key.'-subdivs-full'])) { - $words = split(' ', $_GET['signer-subdivs-full']); - $words[0] = $inflect->getInflectNoun($words[0], $case); - $_GET[$key_prefix.'-'.$key.'-subdivs-full'] = join(' ', $words); + if (empty($_GET[$key_prefix.'-'.$key.'-name'])) { + $words = explode(' ', $_GET[$key.'-name']); + $fwords = explode(' ', $_GET[$key_prefix.'-'.$key.'-fullname']); + $_GET[$key_prefix.'-'.$key.'-name'] = $words[0].' '.$words[1].' '.$fwords[0]; + } + + if (empty($_GET[$key_prefix.'-'.$key.'-subdivs-full']) && !empty($_GET[$key.'-subdivs-full'])) { + $subdivs_full = split('; ', $_GET[$key.'-subdivs-full']); + + foreach($subdivs_full as &$subdiv_full) { + $words = split(' ', $subdiv_full); + $words[0] = $inflect->getInflectNoun($words[0], $case); + $subdiv_full = join(' ', $words); + } + + $_GET[$key_prefix.'-'.$key.'-subdivs-full'] = $subdivs_full; } if (empty($_GET[$key_prefix.'-'.$key.'-appointment'])) { @@ -229,41 +344,68 @@ foreach (array('signer', 'contact', 'user') as $key) { } // working with appointments - $appointments = split(', ', $_GET[$key.'-appointment']); - foreach ($appointments as &$appointment) { - $matches = NULL; - $ignored_ending = ''; - - $appointment = preg_replace($inflect_cut_patterns, '', $appointment); - error_log('Appointment: '.$appointment); - - foreach($inflect_ignore_ending_patterns as $inflect_ignore_ending_pattern) { - if (preg_match('/'.$inflect_ignore_ending_pattern.'$/u', $appointment, $matches, PREG_OFFSET_CAPTURE)) { - foreach ($matches as &$match) { - $ignored_ending .= $match[0]; - $appointment = mb_substr($appointment, 0, -mb_strlen($match[0])); + foreach (array('', '-wosubdiv') as $postfix) { + $appointments = split(', ', $_GET[$key.'-appointment'.$postfix]); + foreach ($appointments as &$appointment) { + $matches = NULL; + $ignored_ending = ''; + + $appointment = preg_replace($inflect_cut_patterns, '', $appointment); + error_log('Appointment'.$postfix.': '.$appointment); + + foreach($inflect_ignore_ending_patterns as $inflect_ignore_ending_pattern) { + if (preg_match('/'.$inflect_ignore_ending_pattern.'$/u', $appointment, $matches, PREG_OFFSET_CAPTURE)) { + foreach ($matches as &$match) { + $ignored_ending .= $match[0]; + $appointment = mb_substr($appointment, 0, -mb_strlen($match[0])); + } } } - } - $appointment = $inflect->getInflectNoun($appointment, $case); + $appointment = $inflect->getInflectNoun($appointment, $case); - $appointment .= $ignored_ending; - $_GET[$key_prefix.'-'.$key.'-appointment'] = $appointment; - } + $appointment .= $ignored_ending; + $_GET[$key_prefix.'-'.$key.'-appointment'.$postfix] = $appointment; + } - $_GET[$key_prefix.'-'.$key.'-appointment'] = join(', ', $appointments); + $_GET[$key_prefix.'-'.$key.'-appointment'.$postfix] = join(', ', $appointments); + } } } -$signer_appointment_wosubdiv_words = split(' ', $_GET['signer-appointment-wosubdiv']); -$signer_subdivs_full_words = split(' ', $_GET['of-signer-subdivs-full']); -error_log('DDD: '.serialize($signer_appointment_wosubdiv_words)); -error_log('WWW: '.serialize($signer_subdivs_full_words)); -if ($signer_appointment_wosubdiv_words[count($signer_appointment_wosubdiv_words)-1] === $signer_subdivs_full_words[0]) - unset($signer_appointment_wosubdiv_words[count($signer_appointment_wosubdiv_words)-1]); +foreach (array('signer', 'contact', 'user') as $key) { + foreach (array('', 'of-', 'to-') as $key_prefix) { + $appointment_w_fullsubdiv = array(); + + $appointments_wosubdiv = is_array($_GET[$key_prefix.$key.'-appointment-wosubdiv']) ? $_GET[$key_prefix.$key.'-appointment-wosubdiv'] : split(', ', $_GET[$key_prefix.$key.'-appointment-wosubdiv']); + + foreach ($appointments_wosubdiv as $id => &$appointment_wosubdiv) { + + $appointment_wosubdiv_words = split(' ', $appointment_wosubdiv); + $subdivs_full_words = split(' ', $_GET['of-'.$key.'-subdivs-full'][$id]); + if ($appointment_wosubdiv_words[count($appointment_wosubdiv_words)-1] === $subdivs_full_words[0]) + unset($appointment_wosubdiv_words[count($appointment_wosubdiv_words)-1]); + + $appointment_wosubdiv_dedup = join(' ', $appointment_wosubdiv_words); -$_GET['signer-appointment-wosubdiv-dedup'] = join(' ', $signer_appointment_wosubdiv_words); + if ($_GET['of-'.$key.'-subdivs-full'][$id] == 'ректората') { + $appointment_w_fullsubdiv_item = $appointment_wosubdiv_dedup; + } else { + $appointment_w_fullsubdiv_item = $appointment_wosubdiv_dedup.' '.$_GET['of-'.$key.'-subdivs-full'][$id]; + } + + if ($appointment_w_fullsubdiv_item == " ") { + $appointment_w_fullsubdiv_item = str_pad('', 60, '_'); + } + $appointment_w_fullsubdiv[] = $appointment_w_fullsubdiv_item; + + } + + $_GET[$key_prefix.$key.'-appointment-w-fullsubdiv'] = $appointment_w_fullsubdiv;//join(', ', $appointment_w_fullsubdiv); + + } +} +//print_r($_GET); die(); foreach (array('work-date-end' => 'Срок окончания работ') as $key => $descr) { $_GET[$key.'-descr'] = $descr.': '. @@ -292,26 +434,11 @@ foreach (array('videocheck', 'confcheck', 'webtrans', 'telebridge', 'otherconf', //govnocode 2.0 else{ -/* -// if ($_GET['video-type'] == 'Нет') -// die('Ошибка: не выбран флажок видеосъемки'); - if (isset($_GET['usermount1']) || isset($__GET['record1'])) - die('Ошибка: не выбран флажок видеоконференции'); - if (isset($_GET['record2'])) - die('Ошибка: не выбран флажок вебтрансляции'); - if (isset($_GET['usermount2']) || isset($_GET['record3'])) - die('Ошибка: не выбран флажок проведения телемоста'); - if (isset($_GET['otherconftext'])) - die('Ошибка: не выбран флажок "Другое"'); -*/ - $_GET[$key] = 'Нет'; } } -//Jim's simple diagnostics -//print_r($_GET);die(); $redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); $me = NULL; @@ -332,15 +459,19 @@ if (isset($_GET['user-serialized'])) { $user_drupal = unserialize($user_drupal_serialized); $user_redmine = NULL; - foreach ($redmine_admin->api('user')->all(array('name' => split('@', $user_drupal->user_id)[0]))['users'] as &$_user) { - if (strtolower($_user['login']).'@mephi.ru' == strtolower($user_drupal->user_id)) { + + $username_drupal = strtolower(split('@', $user_drupal->user_id)[0]); + + foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) { + $_user['login'] = strtolower($_user['login']); + if ($_user['login'] == $username_drupal) { $user_redmine = $redmine_admin->api('user')->show($_user['id']); break; } } if (is_null($user_redmine)) - die('Cannot find user "'.$user_drupal->name.'" in Redmine'); + die('Cannot find user "'.$username_drupal.'" in Redmine'); $api_key = $user_redmine['user']['api_key']; @@ -354,7 +485,26 @@ if (isset($_GET['user-serialized'])) { $redmine = &$redmine_admin; } - +switch($_GET['vacation-type']) { + case 'main': + $_GET['vacation-type'] = 'ежегодный основной оплачиваемый отпуск'; + $_GET['of-vacation'] = 'ежегодного основного оплачиваемого отпуска'; + break; + case 'educational': + $_GET['vacation-type'] = 'учебный отпуск'; + $_GET['of-vacation'] = 'учебного отпуска'; + break; + case 'free': + $_GET['vacation-type'] = 'отпуск без сохранения заработной платы'; + $_GET['of-vacation'] = 'отпуска без сохранения заработной платы'; + break; + case 'parental': + $_GET['vacation-type'] = 'отпуск по уходу за ребёнком до достижения им возраста трёх лет'; + $_GET['of-vacation'] = 'отпуска по уходу за ребёнком до достижения им возраста трёх лет'; + break; +} + +$_GET_orig = $_GET; $custom_fields = NULL; @@ -362,10 +512,11 @@ $custom_fields_keys = array(); $files = split(',', $_GET['file']); -$replacement_is_already_done = false; - $pdfs = array(); foreach ($files as $file) { + $split_appointments = false; +// $replacement_is_already_done = false; + $file_eff = $file; switch ($file) { case 'request/domain-name': @@ -373,22 +524,6 @@ foreach ($files as $file) { $memo_subject = 'Запрос на регистрацию доменного имени'; $file_eff = $file;//.' '.$_GET['target-type']; - $_GET['domain-name'] = $_GET['domain-name'].'.mephi.ru'; - - switch ($_GET['target-type']) { - case 'ipaddr': - $_GET['target-type'] = 'IP-адресом'; - $_GET['target-id'] = $_GET['ipaddr']; - break; - case 'container-name': - $_GET['target-type'] = 'контейнером'; - $_GET['target-id'] = '«'.$_GET['container-name'].'»'; - break; - case 'issue-id': - $_GET['target-type'] = 'ранее предоставленным хостингом по заявке'; - $_GET['target-id'] = '#'.$_GET['issue-id']; - break; - } break; case 'request/vpn': $project_id = 84; @@ -429,27 +564,9 @@ foreach ($files as $file) { break; case 'request/vacation': $project_id = 118; -// $project_id = 1; + // $project_id = 1; $memo_subject = 'Заявление на отпуск'; - switch($_GET['vacation-type']) { - case 'main': - $_GET['vacation-type'] = 'ежегодный основной оплачиваемый отпуск'; - $_GET['of-vacation'] = 'ежегодного основного оплачиваемого отпуска'; - break; - case 'educational': - $_GET['vacation-type'] = 'учебный отпуск'; - $_GET['of-vacation'] = 'учебного отпуска'; - break; - case 'free': - $_GET['vacation-type'] = 'отпуск без сохранения заработной платы'; - $_GET['of-vacation'] = 'отпуска без сохранения заработной платы'; - break; - case 'parental': - $_GET['vacation-type'] = 'отпуск по уходу за ребёнком до достижения им возраста трёх лет'; - $_GET['of-vacation'] = 'отпуска по уходу за ребёнком до достижения им возраста трёх лет'; - break; - } $time_from = strtotime($_GET['days-from']); $time_to = strtotime($_GET['days-to']); @@ -460,13 +577,18 @@ foreach ($files as $file) { $_GET['days-count'] = ($days_diff + 1); + $split_appointments = true; + break; case 'request/temporary-acting': + // print_r($_GET); die(); if (!isset($_GET['user-e_id'])) continue 2; if (substr($_GET['of-user-fullname'], 0, 2) == '\_') - $_GET['of-user-fullname'] = '\\\\'."\n".$_GET['of-user-fullname']; + $_GET['of-user-fullname'] = '\\\\'."\n".$_GET['of-user-fullname']; + + $split_appointments = true; break; case 'request/voip-transfer-equipment': $project_id = 1;//18; @@ -481,214 +603,451 @@ foreach ($files as $file) { $project_id = 12871; $memo_subject = 'Заявка на предоставление PHP хостинга'; break; + case 'request/itsupport': + $project_id = 121; + $memo_subject = 'Заявка в службу технической поддержки'; + $custom_fields_keys = array ( 14 => 'contact-phonenumber', 13 => 'contact-place', 4 => 'subdivision'); + break; + case 'request/lanmodern': + $project_id = 31; + $memo_subject = 'Заявка на модернизацию ЛВС'; + break; + case 'request/custom': + $project_id = redmine_proj_identifier2id ($_GET['credentials']); + $memo_subject = 'Служебная записка'; + $me['id'] = $user_redmine['user']['id']; + $replacement_is_already_done = true; + + break; default: die('unknown memo-type'); - } - - if (!is_null($me)) - $redmine_admin->api('membership')->create($project_id, array('user_id' => $me['id'], 'role_ids' => array(ROLE_CUSTOMER))); - switch ($file) { - case 'request/voip3': - case 'request/cps': - case 'request/php': - if (empty($_GET['subdiv-code'])) { - if (!empty($_SERVER['HTTP_REFERER'])) { - header('Location: '.$_SERVER['HTTP_REFERER'].'?errmsg='.urlencode('Не указан код подразделения')); - exit(0); - } else - die('"subdiv-code" is not set'); + if (!is_null($me)) { + // $membership = $redmine_admin->api('user')->show($me['id'], array('include' => array('memberships',))); + $current_membership = $redmine_admin->api('membership')->all($project_id); + + + + //History of issue: If we have one user with role id:20, we can't create a custumer role. + //We must update roles for this user, for update we must know inner structure of memberships + + //for debug + // print_r ($current_membership['memberships']); + + +// echo "ME:".$me['id']."\n"; + + foreach ($current_membership['memberships'] as $global_key => $member){ + + // echo "MEMBER KEY: $global_key\n"; + // print_r ($member); die(); + + // echo $member['user']['id']."\n"; + + if ($member['user']['id'] == $me['id']){ + $cur_roles=array(); + $membership_id = $current_membership['memberships'][$global_key]['id']; + foreach($current_membership['memberships'][$global_key]['roles'] as $role) { + $cur_roles[] = $role['id']; + } + //print_r($current_membership['memberships'][$global_key]);print_r($cur_roles);die(); + $result = $redmine_admin->api('membership')->update($membership_id, array ('role_ids' => array_merge($cur_roles, array(ROLE_CUSTOMER)))); + // echo "RESULT $result \n @ $membership_id \n"; die(); } - $subdivs = json_decode(file_get_contents('https://cps.mephi.ru/?cmd=getsubdivinfo&s_code='.$_GET['subdiv-code'])); - $subdiv = $subdivs->result->s0; - $_GET['subdiv-name'] = $subdiv->name; - break; - case 'request/video': - if (empty($_GET['subdiv-code'])) { - if (!empty($_SERVER['HTTP_REFERER'])) { - header('Location: '.$_SERVER['HTTP_REFERER'].'?errmsg='.urlencode('Не указан код подразделения')); - exit(0); - } else - die('"subdiv-code" is not set'); + + else { + $result = $redmine_admin->api('membership')->create($project_id, array('user_id' => $me['id'], 'role_ids' => array(ROLE_CUSTOMER))); + } - $subdivs = json_decode(file_get_contents('https://cps.mephi.ru/?cmd=getsubdivinfo&s_code='.$_GET['subdiv-code'])); - $subdiv = $subdivs->result->s0; - $_GET['subdiv-name'] = $subdiv->name; - break; + + + } + //TODO: PUT ALL ROLES + // echo $result; + // die(); } - foreach($custom_fields_keys as $id => $key) - $custom_fields[] = array('id' => $id, 'value' => empty($_GET[$key]) ? '0' : $_GET[$key]); +// error_log(print_r($_GET_orig, 1)); + + $signer_appointment_count = 1; + $user_appointment_count = 1; + foreach ($_GET_orig as $k => $v) { + if ($split_appointments) { + if ($split_appointments && (strstr($k, "signer-") || strstr($k, "user-")) && (strstr($k, "appointment") || strstr($k, "subdiv"))) { + error_log($k.' => '.print_r($v, 1)); + if (is_array($v)) { + $_GET_array[$k] = $v; + } else { + $_GET_array[$k] = split(',', $v); + } + if (strstr($k, "signer-")) { + $signer_appointment_count = count($_GET_array[$k]); + } else + if (strstr($k, "user-")) { + $user_appointment_count = count($_GET_array[$k]); + } + continue; + } + } + if (is_array($v)) { + $v = join(', ', $v); + } + $_GET_array[$k] = array($v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v, $v); + } - $tempdir = tempdir(); + if ($split_appointments) { + $_GET_array_new = array(); + $i = 0; + while ($i < $signer_appointment_count) { + $j = 0; + while ($j < $user_appointment_count) { + $appointment_i = $i + $j * $signer_appointment_count; + + foreach ($_GET_array as $k => $v) { + if (strstr($k, "appointment") || strstr($k, "subdiv")) { + if (strstr($k, "signer-")) { + $_GET_array_new[$k][$appointment_i] = $v[$i]; + } else + if (strstr($k, "user-")) { + $_GET_array_new[$k][$appointment_i] = $v[$j]; + } + } else { + $_GET_array_new[$k] = $v; + } + } + $j++; + } + $i++; + } + $_GET_array = $_GET_array_new; + } - if ($tempdir === FALSE) - die('Cannot create temporary directory'); + $appointment_count = $signer_appointment_count * $user_appointment_count; + $appointment_i = 0; + do { + foreach ($_GET_array as $k => $v) { + $_GET[$k] = $v[$appointment_i]; + } - exec('cp -a /var/www/ut.mephi.ru/ut-tex/mephimemo "'.$tempdir.'/"'); - chdir($tempdir.'/mephimemo'); - file_put_contents("request.get", print_r($_GET, true)); + switch ($file) { + case 'request/voip3': + case 'request/cps': + case 'request/php': + if (empty($_GET['subdiv-code'])) { + if (!empty($_SERVER['HTTP_REFERER'])) { + header('Location: '.$_SERVER['HTTP_REFERER'].'?errmsg='.urlencode('Не указан код подразделения')); + exit(0); + } else + die('"subdiv-code" is not set'); + } + $subdivs = json_decode(file_get_contents('https://cps.mephi.ru/?cmd=getsubdivinfo&s_code='.$_GET['subdiv-code'])); + $subdiv = $subdivs->result->s0; + $_GET['subdiv-name'] = $subdiv->name; + break; + case 'request/video': + if (empty($_GET['subdiv-code'])) { + if (!empty($_SERVER['HTTP_REFERER'])) { + header('Location: '.$_SERVER['HTTP_REFERER'].'?errmsg='.urlencode('Не указан код подразделения')); + exit(0); + } else + die('"subdiv-code" is not set'); + } + $subdivs = json_decode(file_get_contents('https://cps.mephi.ru/?cmd=getsubdivinfo&s_code='.$_GET['subdiv-code'])); + $subdiv = $subdivs->result->s0; + $_GET['subdiv-name'] = $subdiv->name; + break; + case 'request/domain-name': + $_GET['domain-name'] = $_GET['domain-name'].'.mephi.ru'; - if (!$replacement_is_already_done) { - foreach ($_GET as $key => &$value) - $value = str_replace(array('\\', '_', '#'), array('{\textbackslash}', '\_', '\\#'), $value); + switch ($_GET['target-type']) { + case 'ipaddr': + $_GET['target-type'] = 'IP-адресом'; + $_GET['target-id'] = $_GET['ipaddr']; + break; + case 'container-name': + $_GET['target-type'] = 'контейнером'; + $_GET['target-id'] = '«'.$_GET['container-name'].'»'; + break; + case 'issue-id': + $_GET['target-type'] = 'ранее предоставленным хостингом по заявке'; + $_GET['target-id'] = '#'.$_GET['issue-id']; + break; + } - $replacement_is_already_done = true; - } + break; - file_put_contents("request.get.fixed", print_r($_GET, true)); + } - #ob_start(); - #print_r($_GET); - #$_GET_print_r = ob_get_clean(); - $text = ''; + foreach($custom_fields_keys as $id => $key) + $custom_fields[] = array('id' => $id, 'value' => empty($_GET[$key]) ? '0' : $_GET[$key]); - /* - if (empty($_GET['date-end'])) - $_GET['date-end'] = (date('Y')+1).'-12-31'; - */ + $tempdir = tempdir(); - $body_template = file_get_contents('template/'.$file_eff.'.tex'); - $body = body_parse($body_template); + if ($tempdir === FALSE) + die('Cannot create temporary directory'); - switch ($file) { - case 'request/vacation': - $header = '\mmheaderstatement{Начальнику отдела кадров НИЯУ МИФИ}{}'; - $footer = ''; - break; - case 'request/temporary-acting': - $header = '\mmheadermemo{\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_}{\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_}'; - $footer = ' -\mmfooter{'.$_GET['signer-appointment'].'}{'.$_GET{'signer-name'}.'}{}{} -\\ -\mmfooter{'.$_GET['user-appointment'].'}{'.$_GET{'user-name'}.'}{}{Согласен:} -'; - break; - case 'request/voip-transfer-equipment': - $header = '\mmfullheader{'.$_GET['subdiv-name'].'}{Начальнику управления информатизации}{Романову Н.Н.}'; - break; - case 'request/video'; - $header = '\mmfullheader{Утверждаю}{Начальник управления информатизации}{/Романов Н.Н./}'; - break; - default: - $header = '\mmheader{Начальнику управления информатизации}{Н. Н. Романову}'; - $footer = '\mmfooter{'.$_GET['signer-appointment'].'}{'.$_GET{'signer-name'}.'}{}{}'; - } - file_put_contents('header.tex', $header); - file_put_contents('body.tex', $body); - file_put_contents('footer.tex', $footer); - file_put_contents('responsible.tex', '\mmresponsibleskip'); - - if (empty($issue_id)) { - if (!is_null($project_id)) { - file_put_contents('urlqr.tex', ''); - exec('make'); - exec('pdftotext memo.pdf'); - - $text = file_get_contents('memo.txt'); - unlink('memo.pdf'); - - switch($file) { - case 'request/php': - $issue_props = - array( - 'assigned_to_id' => USERID_KVMARTINOV, - 'project_id' => $project_id, - 'subject' => $memo_subject, - 'description' => $text, - ); - break; - case 'request/nix-hosting': - $issue_props = - array( - 'assigned_to_id' => USERID_AMGLADTSIN, - 'project_id' => $project_id, - 'subject' => $memo_subject, - 'description' => $text, - ); - break; - default: - $issue_props = - array( - 'assigned_to_id' => USERID_EVVLASOV, - 'project_id' => $project_id, - 'subject' => $memo_subject, - 'description' => $text, - ); - } - if (!is_null($custom_fields)) - $issue_props['custom_fields'] = $custom_fields; + exec('cp -a /var/www/ut.mephi.ru/ut-tex/mephimemo "'.$tempdir.'/"'); + chdir($tempdir.'/mephimemo'); + file_put_contents("request.get", print_r($_GET, true)); + + + if (!$replacement_is_already_done) { + + foreach ($_GET as $key => &$value) + $value = str_replace(array('\\', '_', '#', '"', '"', '&', '$'), array('{\textbackslash}', '\_', '\\#', '"', '"', '\&', '\$'), $value); + + $replacement_is_already_done = true; + } + + file_put_contents("request.get.fixed", print_r($_GET, true)); - // print_r ($issue_props); - error_log(base64_encode(serialize($issue_props))); - $result = $redmine->api('issue')->create($issue_props); - $issue = json_decode($result); - $issue = $issue->issue; - error_log(base64_encode(serialize($issue))); - error_log('issue: '.$issue->id); - if (empty($issue->id)) - error('Wrong parameters: '.$result); + #ob_start(); + #print_r($_GET); + #$_GET_print_r = ob_get_clean(); + $text = ''; - $issue_id = $issue->id; + /* + if (empty($_GET['date-end'])) + $_GET['date-end'] = (date('Y')+1).'-12-31'; + */ - } else { - $issue_id = $_GET['issue-id']; + if (!empty($_GET['category_id'])) { + $category = $redmine_admin->api('issue_category')->show($_GET['category_id']); + $_GET['category'] = $category['issue_category']['name']; } - } - file_put_contents('urlqr.tex', '\mmredmineurlqr{'.$issue_id.'}'); + $body_template = file_get_contents('template/'.$file_eff.'.tex'); + $body = body_parse($body_template); + + switch ($file) { + case 'request/vacation': + $header = '\mmheaderstatement{Начальнику отдела кадров НИЯУ МИФИ}{от '.$_GET['of-signer-appointment-w-fullsubdiv'].' '.$_GET{'of-signer-fullname'}.'}'; + $footer = ''; + break; + case 'request/temporary-acting': + $header = '\mmheadermemo{\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_}{\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_}'; + $footer = ' +\mmfooter{'.$_GET['signer-appointment-w-fullsubdiv'].'}{'.$_GET{'signer-name'}.'}{}{} +\\ +\mmfooter{'.(empty($_GET['user-appointment-w-fullsubdiv'])||$_GET['user-appointment-w-fullsubdiv']==" "?'\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_':$_GET['user-appointment-w-fullsubdiv']).'}{'.$_GET{'user-name'}.'}{}{} +'; + break; + case 'request/voip-transfer-equipment': + $header = '\mmfullheader{'.$_GET['subdiv-name'].'}{Начальнику управления информатизации}{Романову Н.Н.}'; + break; + case 'request/video'; + $header = '\mmfullheader{Утверждаю}{Начальник управления информатизации}{/Романов Н.Н./}'; + + break; + + case 'request/itsupport': + $header = '\mmheader{Начальнику отдела технической поддержки}{Солодовникову А.В}'; + $footer =''; + break; + case 'request/php': + $header = '\mmheader{Начальнику управления информатизации}{Н. Н. Романову}'; + break; + case 'request/custom': + $cred_parts = split('
', $_GET['cred-id']); + $header = '\mmheader{'.$cred_parts[0].'}{'.$cred_parts[1].'}'; + $body = latexSpecialChars1(str_replace("\n", "\n\n", $body)); + $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['signer-name'].'}{'.$_GET['current-date'].'}{}'; + // $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['current-date'].'}{'.$_GET['signer-name'].'}{}'; + break; + + default: + $header = '\mmheader{Начальнику управления информатизации}{Н. Н. Романову}'; + $footer = '\mmfooter{'.$_GET['signer-appointment'].'}{'.$_GET{'signer-name'}.'}{}{}'; + } + file_put_contents('header.tex', $header); + file_put_contents('body.tex', $body); + file_put_contents('footer.tex', $footer); + file_put_contents('responsible.tex', '\mmresponsibleskip'); + + if (empty($issue_id)) { + if (!is_null($project_id)) { + file_put_contents('urlqr.tex', ''); + exec('make'); + exec('pdftotext memo.pdf'); + + $text = file_get_contents('memo.txt'); + unlink('memo.pdf'); + + switch($file) { + case 'request/php': + $issue_props = + array( + 'assigned_to_id' => USERID_KVMARTINOV, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + case 'request/nix-hosting': + $issue_props = + array( + 'assigned_to_id' => USERID_AMGLADTSIN, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + case 'request/hpc': + $issue_props = + array( + 'assigned_to_id' => USERID_AAANIKEEV, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + case 'request/itsupport': + $issue_props = + array( + 'assigned_to_id' => USERID_AVSOLODOVNIKOV, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + case 'request/lanmodern': + $issue_props = + array( + 'assigned_to_id' => USERID_VSSKIBA, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + + case 'request/video': + $issue_props = + array( + 'assigned_to_id' => USERID_OYMAZETOV, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + break; + + + + case 'request/custom': //AASD + $issue_props = + array( + 'assigned_to_id' => redmine_login2id($_GET['credentials']), + 'project_id' => $project_id, + 'subject' => 'Служебная записка '.(explode('
', $_GET['cred-id'])[1]).' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"), + 'description' => "
".$text."
", + + ); + break; + + case 'request/vacation': + $issue_props = + array( + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => "
".$text."
", + ); + break; + + default: + $issue_props = + array( + 'assigned_to_id' => USERID_EVVLASOV, + 'project_id' => $project_id, + 'subject' => $memo_subject, + 'description' => $text, + ); + } - if (isset($user_redmine['user']['id'])) - $redmine_admin->api('issue')->addWatcher($issue_id, $user_redmine['user']['id']); + if (!is_null($custom_fields)) + $issue_props['custom_fields'] = $custom_fields; - switch ($file) { - case 'request/hpc': - file_put_contents('responsible.tex', '\mmresponsible{'.$_GET['contact-name'].'}{'.$_GET{'contact-phonenumber'}.'}{'.$_GET['contact-email'].'}'); - $redmine_admin->api('issue')->addWatcher($issue_id, USERID_AAANIKEEV); - $redmine_admin->api('issue')->addWatcher($issue_id, USERID_BIRCOPH); - case 'request/cps': - case 'request/voip3': - case 'request/voip-softphone': - $redmine_admin->api('issue')->addWatcher($issue_id, USERID_NNROMANOV); - $redmine_admin->api('issue')->addWatcher($issue_id, USERID_DYOKUNEV); - break; - case 'request/voip-transfer-equipment': - case 'request/vacation': - case 'request/temporary-acting': - break; - default: - file_put_contents('responsible.tex', '\mmresponsible{'.$_GET['contact-name'].'}{'.$_GET{'contact-phonenumber'}.'}{'.$_GET['contact-email'].'}'); - } + if (!empty($_GET['category_id'])) + $issue_props['category_id'] = $_GET['category_id']; - exec('make'); - $pdf_content = file_get_contents('memo.pdf'); + // print_r ($issue_props); + error_log(base64_encode(serialize($issue_props))); - $pdf_upload = json_decode( $redmine_admin->api('attachment')->upload($pdf_content) ); + $result = $redmine->api('issue')->create($issue_props); + $issue = json_decode($result); + $issue = $issue->issue; + error_log(base64_encode(serialize($issue))); + error_log('issue: '.$issue->id); + if (empty($issue->id)) + error('Wrong parameters: '.$result); - $redmine_admin->api('issue')->attach( - $issue_id, - array( - 'token' => $pdf_upload->upload->token, - 'filename' => 'sluzhebnaya_zapiska.pdf', - 'description' => 'Служебная записка', - 'content_type'=> 'application/pdf' - ) - ); + $issue_id = $issue->id; - 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'; + } else { + $issue_id = $_GET['issue-id']; + } + } + + file_put_contents('urlqr.tex', '\mmredmineurlqr{'.$issue_id.'}'); + + if (isset($user_redmine['user']['id'])) + $redmine_admin->api('issue')->addWatcher($issue_id, $user_redmine['user']['id']); + + switch ($file) { + case 'request/hpc': + file_put_contents('responsible.tex', '\mmresponsible{'.$_GET['contact-name'].'}{'.$_GET{'contact-phonenumber'}.'}{'.$_GET['contact-email'].'}'); + $redmine_admin->api('issue')->addWatcher($issue_id, USERID_AAANIKEEV); + $redmine_admin->api('issue')->addWatcher($issue_id, USERID_BIRCOPH); + case 'request/cps': + case 'request/voip3': + case 'request/voip-softphone': + $redmine_admin->api('issue')->addWatcher($issue_id, USERID_NNROMANOV); + $redmine_admin->api('issue')->addWatcher($issue_id, USERID_DYOKUNEV); + break; + case 'request/lanmodern': + // $redmine_admin->api('issue')->addWatcher($issue_id, USERID_PVMAKAROV); + // $redmine_admin->api('issue')->addWatcher($issue_id, USERID_RYVORONINA); + break; + case 'request/voip-transfer-equipment': + case 'request/vacation': + case 'request/temporary-acting': + case 'request/php': + case 'request/itsupport': + case 'request/custom': + break; + default: + file_put_contents('responsible.tex', '\mmresponsible{'.$_GET['contact-name'].'}{'.$_GET{'contact-phonenumber'}.'}{'.$_GET['contact-email'].'}'); + } - $pdfs_content[] = $pdf_content; + exec('make'); + $pdf_content = file_get_contents('memo.pdf'); + + $pdf_upload = json_decode( $redmine_admin->api('attachment')->upload($pdf_content) ); + + $redmine_admin->api('issue')->attach( + $issue_id, + array( + 'token' => $pdf_upload->upload->token, + 'filename' => 'sluzhebnaya_zapiska.pdf', + 'description' => 'Служебная записка', + 'content_type'=> 'application/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; + error_log("$appointment_i < $appointment_count"); + } while (++$appointment_i < $appointment_count); } $count = count($pdfs_path); diff --git a/genpdf/lib/3dparty/Inflect b/genpdf/lib/3dparty/Inflect index c1aa9da..754ec13 160000 --- a/genpdf/lib/3dparty/Inflect +++ b/genpdf/lib/3dparty/Inflect @@ -1 +1 @@ -Subproject commit c1aa9da69af1be2977cc941cbb2fd47a22cf02e2 +Subproject commit 754ec13a3789333e9c0a2f858116d0aec7edd238 diff --git a/mephimemo/mephimemo.cls b/mephimemo/mephimemo.cls index 15baed9..55fb125 100644 --- a/mephimemo/mephimemo.cls +++ b/mephimemo/mephimemo.cls @@ -129,7 +129,7 @@ % memorandum footer % #1 - position % #2 - name -% #3 - comment +% #3 - comment (date) \newcommand{\mmfooter}[4]{ \vspace{\stretch{1}} \begin{flushleft} @@ -138,9 +138,10 @@ \begin{flushright} {#1}\\ \vspace{0.7cm} - {#3} - \hspace{5cm} + {#2} + + {#3} \end{flushright} } @@ -171,7 +172,7 @@ \psbarcode{{https://tasks.mephi.ru/issues/#1}}{eclevel=L width=1.2 height=1.2}{qrcode} } \\ - \tiny https://tasks.mephi.ru/issues/#1 + \small https://tasks.mephi.ru/issues/#1 \end{flushright} } diff --git a/mephimemo/template/request/custom.tex b/mephimemo/template/request/custom.tex new file mode 100644 index 0000000..0f47fbc --- /dev/null +++ b/mephimemo/template/request/custom.tex @@ -0,0 +1 @@ +[{description}] diff --git a/mephimemo/template/request/itsupport.tex b/mephimemo/template/request/itsupport.tex new file mode 100644 index 0000000..d4c323a --- /dev/null +++ b/mephimemo/template/request/itsupport.tex @@ -0,0 +1,8 @@ +Прошу осуществить техническую поддержку по следующей проблеме:\\ +[{problem-description}] \\ +\\ +Категория: [{category}]\\ +\\ +№ кабинета: [{contact-place}] \\ +№ телефона: [{contact-phonenumber}] + diff --git a/mephimemo/template/request/lanmodern.tex b/mephimemo/template/request/lanmodern.tex new file mode 100644 index 0000000..e16a3fd --- /dev/null +++ b/mephimemo/template/request/lanmodern.tex @@ -0,0 +1 @@ +В связи с производственной необходимостью прошу Вас дать указание произвести модернизацию локальной вычислительной сети в кабинете(ах) [{contact-place}] diff --git a/mephimemo/template/request/php.tex b/mephimemo/template/request/php.tex index d95882a..8a19111 100644 --- a/mephimemo/template/request/php.tex +++ b/mephimemo/template/request/php.tex @@ -3,15 +3,15 @@ \\ \textbf{Веб-ресурс} \\ -\begin{tabular}{ l l } -Наименование & [{resourse-description}] \\ +\begin{tabular}{ l p {10 cm} } +Наименование & [{resourse-description}]\\ Доменное имя & [{resourse-domain}] \\ \end{tabular} \\ \\ \textbf{Подразделение} \\ -\begin{tabular}{ l l } +\begin{tabular}{ l p {10 cm} } Номер & [{subdiv-code}] \\ Наименование & «[{subdiv-name}]»\\ \end{tabular} @@ -25,6 +25,12 @@ Контактный тел. (ip или моб.) & [{user-phonenumber}] \\ Эл. почта (@mephi.ru) & [{user-email}] \\ \end{tabular} - - +\\ +\\ +\textbf{Руководитель подразделения} +\\ +\begin{tabular}{ l l } +ФИО полностью & [{fullname}] \\ +Должность & [{appointment}] \\ +\end{tabular} diff --git a/mephimemo/template/request/temporary-acting.tex b/mephimemo/template/request/temporary-acting.tex index 9324422..4142801 100644 --- a/mephimemo/template/request/temporary-acting.tex +++ b/mephimemo/template/request/temporary-acting.tex @@ -1 +1 @@ -Прошу вас разрешить возложить обязанности [{of-signer-appointment}] на время моего [{of-vacation}] с [{days-from}] по [{days-to}] на [{of-user-appointment}] [{of-user-fullname}] с компенсацией разницы в окладах. +Прошу вас разрешить возложить обязанности [{of-signer-appointment-w-fullsubdiv}] на время моего [{of-vacation}] с [{days-from}] по [{days-to}] на [{of-user-appointment-w-fullsubdiv}] [{of-user-fullname}] с компенсацией разницы в окладах. diff --git a/mephimemo/template/request/vacation.tex b/mephimemo/template/request/vacation.tex index 162a461..16d2f31 100644 --- a/mephimemo/template/request/vacation.tex +++ b/mephimemo/template/request/vacation.tex @@ -1,9 +1,9 @@ Прошу предоставить мне [{vacation-type}] на [{days-count}] [{days-descr}] с [{days-from}] по [{days-to}]. \begin{flushright} -[{signer-appointment-wosubdiv-dedup}] [{of-signer-subdivs-full}]\\ +[{signer-appointment-w-fullsubdiv}]\\ \vspace{0.7cm} -\_\_\_\_\_\_\_\_\_\_\_\_\_ [{signer-fullname}] +\_\_\_\_\_\_\_\_\_\_\_\_\_ [{signer-name}] \end{flushright} \vspace{1cm}