diff --git a/genpdf/genpdf.php b/genpdf/genpdf.php index e03da64..5943ee0 100644 --- a/genpdf/genpdf.php +++ b/genpdf/genpdf.php @@ -89,6 +89,102 @@ Array $_GET = array_merge ($_GET, $_POST); //print_r ($_GET); die(); +header( "Content-Type: text/plain" ); +//print_r($_GET); + +$inflect = new Inflect(); +$redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); + +if (isset($_GET['signer-serialized'])) { + $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; + + //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 (is_null($appointment)) { + die('Wrong appointment ID'); + } + + $appointment_name = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name); + $appointments = $appointment_name.' '.mb_strtoupper($appointment->subdivision->shortname); + $appointment_ofsubdivfull = $inflect->getInflectNoun($appointment->subdivision->name, 0); + $appointment_name_words = explode(' ', $appointment_name); + $appointment_ofsubdivfull_words = explode(' ', $appointment_ofsubdivfull); + if ($appointment_name_words[count($appointment_name_words)-1] == $appointment_ofsubdivfull_words[0]) { + unset($appointment_name_words[count($appointment_name_words)-1]); + } + if ($appointment_ofsubdivfull_words[0] == 'ректората') { + unset($appointment_ofsubdivfull_words[0]); + } + $appointments_full = join(' ', $appointment_name_words).' '.join(' ', $appointment_ofsubdivfull_words); + $appointments_wosubdiv = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name); + $signer_subdivs = '['.$appointment->subdivision->s_code.'] '.mb_strtoupper($appointment->subdivision->shortname); + $signer_subdivs_full = $appointment->subdivision->name; + + $_GET['signer-fullname'] = $user->employee->fullname; + $_GET['signer-appointment'] = my_mb_ucfirst($appointments_full); + $_GET['signer-appointment-wosubdiv'] = my_mb_ucfirst($appointments_wosubdiv); + $_GET['signer-subdivs'] = $signer_subdivs; + $_GET['signer-subdivs-full'] = $signer_subdivs_full; + + 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 "'.$username_drupal.'" in Redmine'); + + + $api_key = $user_redmine['user']['api_key']; + +// file_put_contents("/tmp/user", print_r($user_redmine)); die(); + $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key); + + $me = $redmine->api('user')->getCurrentUser()['user']; +} else { + die('Not authed'); + $redmine = &$redmine_admin; +} + +//print_r($_GET);die(); $dont_inflect_patterns = array( '/^нач\./', @@ -175,7 +271,6 @@ function latexSpecialChars( $string ) { $test = "Test characters: # $ % & ~ _ ^ \ { }."; -header( "content-type:text/plain" ); function latexSpecialChars1( $string ) { @@ -240,8 +335,6 @@ function my_mb_ucfirst($str, $e='utf-8') { return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e); } -$inflect = new Inflect(); - //This cycle for situation when we could not receive enought info from node_common foreach (array('signer', 'contact', 'user') as $key) { @@ -290,10 +383,10 @@ foreach (array('signer', 'contact', 'user') as $key) { continue; if (isset($_GET[$key.'-subdivs'])){ - $_GET[$key.'-subdivs'] = base64_decode($_GET[$key.'-subdivs']); + $_GET[$key.'-subdivs'] = $_GET[$key.'-subdivs']; } if (isset($_GET[$key.'-subdivs-full'])){ - $_GET[$key.'-subdivs-full'] = base64_decode($_GET[$key.'-subdivs-full']); + $_GET[$key.'-subdivs-full'] = $_GET[$key.'-subdivs-full']; } } @@ -439,51 +532,8 @@ foreach (array('videocheck', 'confcheck', 'webtrans', 'telebridge', 'otherconf', } } - -$redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); $me = NULL; -if (isset($_GET['user-serialized'])) { - $user_drupal_serialized = base64_decode($_GET['user-serialized']); - $hash = $_GET['user-signature']; - $good_signature = 0; - foreach ($SIGNKEYS as $key) { - if (sha1($user_drupal_serialized.$key) === $hash) { - $good_signature = 1; - break; - } - } - if ($good_signature == 0) - die('Bad signature'); - - $user_drupal = unserialize($user_drupal_serialized); - - $user_redmine = NULL; - - $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 "'.$username_drupal.'" in Redmine'); - - - $api_key = $user_redmine['user']['api_key']; - -// file_put_contents("/tmp/user", print_r($user_redmine)); die(); - $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key); - - $me = $redmine->api('user')->getCurrentUser()['user']; -} else { - die('Not authed'); - $redmine = &$redmine_admin; -} switch($_GET['vacation-type']) { case 'main': @@ -869,6 +919,8 @@ foreach ($files as $file) { file_put_contents('footer.tex', $footer); file_put_contents('responsible.tex', '\mmresponsibleskip'); + print_r($_GET);die(); + if (empty($issue_id)) { if (!is_null($project_id)) { file_put_contents('urlqr.tex', '');