redmine

A try to adapt to appointment selection

@@ -89,6 +89,102 @@ Array @@ -89,6 +89,102 @@ Array
89 89
90 $_GET = array_merge ($_GET, $_POST); 90 $_GET = array_merge ($_GET, $_POST);
91 //print_r ($_GET); die(); 91 //print_r ($_GET); die();
  92 +header( "Content-Type: text/plain" );
  93 +//print_r($_GET);
  94 +
  95 +$inflect = new Inflect();
  96 +$redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD);
  97 +
  98 +if (isset($_GET['signer-serialized'])) {
  99 + $user_serialized = base64_decode($_GET['signer-serialized']);
  100 + $hash = $_GET['signer-signature'];
  101 + $date = $_GET['signature-date'];
  102 +
  103 + $good_dates = array(date('Ymd', strtotime('-1 day')), date('Ymd'), date('Ymd', strtotime('+1 day')));
  104 +
  105 + if (!in_array($date, $good_dates)) {
  106 + die('Bad date');
  107 + }
  108 +
  109 + $_GET['current-date'] = substr($date, 6, 2).".".substr($date, 4, 2).".".substr($date, 0, 4);
  110 +
  111 + $good_signature = 0;
  112 + foreach ($SIGNKEYS as $key) {
  113 + if (sha1($user_serialized.$key.$date) === $hash) {
  114 + $good_signature = 1;
  115 + break;
  116 + }
  117 + }
  118 + if ($good_signature == 0)
  119 + die('Bad signature');
  120 +
  121 + $user = unserialize($user_serialized);
  122 + $user_redmine = NULL;
  123 + $username_drupal = $user->login;
  124 +
  125 + //print_r($user);
  126 +
  127 + $employee = $user->employee;
  128 +
  129 + $appointment = null;
  130 +
  131 + foreach ($employee->WORKPOSITIONS as $_appointment) {
  132 + if ($_appointment->w_id == $_GET['signer-appointment-id']) {
  133 + $appointment = $_appointment;
  134 + break;
  135 + }
  136 + }
  137 +
  138 + if (is_null($appointment)) {
  139 + die('Wrong appointment ID');
  140 + }
  141 +
  142 + $appointment_name = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name);
  143 + $appointments = $appointment_name.' '.mb_strtoupper($appointment->subdivision->shortname);
  144 + $appointment_ofsubdivfull = $inflect->getInflectNoun($appointment->subdivision->name, 0);
  145 + $appointment_name_words = explode(' ', $appointment_name);
  146 + $appointment_ofsubdivfull_words = explode(' ', $appointment_ofsubdivfull);
  147 + if ($appointment_name_words[count($appointment_name_words)-1] == $appointment_ofsubdivfull_words[0]) {
  148 + unset($appointment_name_words[count($appointment_name_words)-1]);
  149 + }
  150 + if ($appointment_ofsubdivfull_words[0] == 'ректората') {
  151 + unset($appointment_ofsubdivfull_words[0]);
  152 + }
  153 + $appointments_full = join(' ', $appointment_name_words).' '.join(' ', $appointment_ofsubdivfull_words);
  154 + $appointments_wosubdiv = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name);
  155 + $signer_subdivs = '['.$appointment->subdivision->s_code.'] '.mb_strtoupper($appointment->subdivision->shortname);
  156 + $signer_subdivs_full = $appointment->subdivision->name;
  157 +
  158 + $_GET['signer-fullname'] = $user->employee->fullname;
  159 + $_GET['signer-appointment'] = my_mb_ucfirst($appointments_full);
  160 + $_GET['signer-appointment-wosubdiv'] = my_mb_ucfirst($appointments_wosubdiv);
  161 + $_GET['signer-subdivs'] = $signer_subdivs;
  162 + $_GET['signer-subdivs-full'] = $signer_subdivs_full;
  163 +
  164 + foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) {
  165 + $_user['login'] = strtolower($_user['login']);
  166 + if ($_user['login'] == $username_drupal) {
  167 + $user_redmine = $redmine_admin->api('user')->show($_user['id']);
  168 + break;
  169 + }
  170 + }
  171 +
  172 + if (is_null($user_redmine))
  173 + die('Cannot find user "'.$username_drupal.'" in Redmine');
  174 +
  175 +
  176 + $api_key = $user_redmine['user']['api_key'];
  177 +
  178 +// file_put_contents("/tmp/user", print_r($user_redmine)); die();
  179 + $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key);
  180 +
  181 + $me = $redmine->api('user')->getCurrentUser()['user'];
  182 +} else {
  183 + die('Not authed');
  184 + $redmine = &$redmine_admin;
  185 +}
  186 +
  187 +//print_r($_GET);die();
92 188
93 $dont_inflect_patterns = array( 189 $dont_inflect_patterns = array(
94 '/^нач\./', 190 '/^нач\./',
@@ -175,7 +271,6 @@ function latexSpecialChars( $string ) { @@ -175,7 +271,6 @@ function latexSpecialChars( $string ) {
175 271
176 272
177 $test = "Test characters: # $ % & ~ _ ^ \ { }."; 273 $test = "Test characters: # $ % & ~ _ ^ \ { }.";
178 -header( "content-type:text/plain" );  
179 274
180 function latexSpecialChars1( $string ) 275 function latexSpecialChars1( $string )
181 { 276 {
@@ -240,8 +335,6 @@ function my_mb_ucfirst($str, $e='utf-8') { @@ -240,8 +335,6 @@ function my_mb_ucfirst($str, $e='utf-8') {
240 return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e); 335 return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e);
241 } 336 }
242 337
243 -$inflect = new Inflect();  
244 -  
245 //This cycle for situation when we could not receive enought info from node_common 338 //This cycle for situation when we could not receive enought info from node_common
246 339
247 foreach (array('signer', 'contact', 'user') as $key) { 340 foreach (array('signer', 'contact', 'user') as $key) {
@@ -290,10 +383,10 @@ foreach (array('signer', 'contact', 'user') as $key) { @@ -290,10 +383,10 @@ foreach (array('signer', 'contact', 'user') as $key) {
290 continue; 383 continue;
291 384
292 if (isset($_GET[$key.'-subdivs'])){ 385 if (isset($_GET[$key.'-subdivs'])){
293 - $_GET[$key.'-subdivs'] = base64_decode($_GET[$key.'-subdivs']); 386 + $_GET[$key.'-subdivs'] = $_GET[$key.'-subdivs'];
294 } 387 }
295 if (isset($_GET[$key.'-subdivs-full'])){ 388 if (isset($_GET[$key.'-subdivs-full'])){
296 - $_GET[$key.'-subdivs-full'] = base64_decode($_GET[$key.'-subdivs-full']); 389 + $_GET[$key.'-subdivs-full'] = $_GET[$key.'-subdivs-full'];
297 } 390 }
298 } 391 }
299 392
@@ -439,51 +532,8 @@ foreach (array('videocheck', 'confcheck', 'webtrans', 'telebridge', 'otherconf', @@ -439,51 +532,8 @@ foreach (array('videocheck', 'confcheck', 'webtrans', 'telebridge', 'otherconf',
439 } 532 }
440 } 533 }
441 534
442 -  
443 -$redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD);  
444 $me = NULL; 535 $me = NULL;
445 536
446 -if (isset($_GET['user-serialized'])) {  
447 - $user_drupal_serialized = base64_decode($_GET['user-serialized']);  
448 - $hash = $_GET['user-signature'];  
449 - $good_signature = 0;  
450 - foreach ($SIGNKEYS as $key) {  
451 - if (sha1($user_drupal_serialized.$key) === $hash) {  
452 - $good_signature = 1;  
453 - break;  
454 - }  
455 - }  
456 - if ($good_signature == 0)  
457 - die('Bad signature');  
458 -  
459 - $user_drupal = unserialize($user_drupal_serialized);  
460 -  
461 - $user_redmine = NULL;  
462 -  
463 - $username_drupal = strtolower(split('@', $user_drupal->user_id)[0]);  
464 -  
465 - foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) {  
466 - $_user['login'] = strtolower($_user['login']);  
467 - if ($_user['login'] == $username_drupal) {  
468 - $user_redmine = $redmine_admin->api('user')->show($_user['id']);  
469 - break;  
470 - }  
471 - }  
472 -  
473 - if (is_null($user_redmine))  
474 - die('Cannot find user "'.$username_drupal.'" in Redmine');  
475 -  
476 -  
477 - $api_key = $user_redmine['user']['api_key'];  
478 -  
479 -// file_put_contents("/tmp/user", print_r($user_redmine)); die();  
480 - $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key);  
481 -  
482 - $me = $redmine->api('user')->getCurrentUser()['user'];  
483 -} else {  
484 - die('Not authed');  
485 - $redmine = &$redmine_admin;  
486 -}  
487 537
488 switch($_GET['vacation-type']) { 538 switch($_GET['vacation-type']) {
489 case 'main': 539 case 'main':
@@ -869,6 +919,8 @@ foreach ($files as $file) { @@ -869,6 +919,8 @@ foreach ($files as $file) {
869 file_put_contents('footer.tex', $footer); 919 file_put_contents('footer.tex', $footer);
870 file_put_contents('responsible.tex', '\mmresponsibleskip'); 920 file_put_contents('responsible.tex', '\mmresponsibleskip');
871 921
  922 + print_r($_GET);die();
  923 +
872 if (empty($issue_id)) { 924 if (empty($issue_id)) {
873 if (!is_null($project_id)) { 925 if (!is_null($project_id)) {
874 file_put_contents('urlqr.tex', ''); 926 file_put_contents('urlqr.tex', '');