redmine

Added support of appointment_id_to selection

@@ -87,6 +87,71 @@ Array @@ -87,6 +87,71 @@ Array
87 ) 87 )
88 */ 88 */
89 89
  90 +function stfcardid2login($stfcardid) {
  91 + error_log("stfcardid2login($stfcardid)");
  92 + static $stfcardid2login = array();
  93 +
  94 + $filename = '/opt/tmp/stfcardid2login.json';
  95 +
  96 + $s = stat($filename);
  97 +
  98 + if ($s === FALSE || (@$s[9]+3600*24) < time()) {
  99 + $apiKey = trim(file_get_contents('/etc/apikey-voip'));
  100 + $subscribers = json_decode(file_get_contents('http://new.voip.mephi.ru/subscribers.json?limit=65535&renderFilter=subscribers&apiKey='.urlencode($apiKey)), 1)['subscribers'];
  101 + foreach ($subscribers as &$subscriber) {
  102 + if (empty($subscriber['Login']['String']))
  103 + continue;
  104 +
  105 + foreach ($subscriber['Appointments'] as &$_a)
  106 + $stfcardid2login[$_a['StfCardId']] = $subscriber['Login']['String'];
  107 + }
  108 +
  109 + if (count($stfcardid2login) > 1000) {
  110 + file_put_contents($filename, json_encode($stfcardid2login));
  111 + }
  112 + }
  113 +
  114 + if (empty($stfcardid2login)) {
  115 + $stfcardid2login = json_decode(file_get_contents($filename), 1);
  116 + }
  117 +
  118 + error_log ('RS:'.$stfcardid2login[$stfcardid]);
  119 +
  120 +
  121 + return $stfcardid2login[$stfcardid];
  122 +
  123 +}
  124 +
  125 +function considerAppointment($key, &$appointment) {
  126 + global $inflect;
  127 + $appointment_name = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name);
  128 + $appointments = $appointment_name.' '.mb_strtoupper($appointment->subdivision->shortname);
  129 + $appointment_ofsubdivfull = $inflect->getInflectNoun($appointment->subdivision->name, 0);
  130 + $appointment_name_words = explode(' ', $appointment_name);
  131 + $appointment_ofsubdivfull_words = explode(' ', $appointment_ofsubdivfull);
  132 + if ($appointment_name_words[count($appointment_name_words)-1] == $appointment_ofsubdivfull_words[0]) {
  133 + unset($appointment_name_words[count($appointment_name_words)-1]);
  134 + }
  135 + if ($appointment_ofsubdivfull_words[0] == 'ректората') {
  136 + unset($appointment_ofsubdivfull_words[0]);
  137 + }
  138 + $appointments_full = join(' ', $appointment_name_words).' '.join(' ', $appointment_ofsubdivfull_words);
  139 + $appointments_wosubdiv = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name);
  140 + $signer_subdivs = '['.$appointment->subdivision->s_code.'] '.mb_strtoupper($appointment->subdivision->shortname);
  141 + $signer_subdivs_full = $appointment->subdivision->name;
  142 +
  143 + $_GET[$key.'-appointment-id'] = $appointment->w_id;
  144 + $_GET[$key.'-fullname'] = $appointment->employee->fullname;
  145 + $fullname_words = explode(' ', $_GET[$key.'-fullname']);
  146 + $_GET[$key.'-login'] = stfcardid2login($appointment->w_id);
  147 + $_GET[$key.'-name'] = mb_substr($fullname_words[1], 0, 1).'. '.mb_substr($fullname_words[2], 0, 1).'. '.$fullname_words[0];
  148 + $_GET[$key.'-appointment'] = $appointments_full;
  149 + $_GET[$key.'-appointment-wosubdiv'] = $appointments_wosubdiv;
  150 + $_GET[$key.'-subdivs'] = $signer_subdivs;
  151 + $_GET[$key.'-subdivs-full'] = $signer_subdivs_full;
  152 +}
  153 +
  154 +
90 $_GET = array_merge ($_GET, $_POST); 155 $_GET = array_merge ($_GET, $_POST);
91 header( "Content-Type: text/plain" ); 156 header( "Content-Type: text/plain" );
92 //print_r ($_GET); die(); 157 //print_r ($_GET); die();
@@ -141,27 +206,9 @@ if (isset($_GET['signer-serialized'])) { @@ -141,27 +206,9 @@ if (isset($_GET['signer-serialized'])) {
141 die('Wrong appointment ID'); 206 die('Wrong appointment ID');
142 } 207 }
143 208
144 - $appointment_name = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name); 209 +
145 - $appointments = $appointment_name.' '.mb_strtoupper($appointment->subdivision->shortname); 210 + @$appointment->employee = $user->employee;
146 - $appointment_ofsubdivfull = $inflect->getInflectNoun($appointment->subdivision->name, 0); 211 + considerAppointment('signer', $appointment);
147 - $appointment_name_words = explode(' ', $appointment_name);  
148 - $appointment_ofsubdivfull_words = explode(' ', $appointment_ofsubdivfull);  
149 - if ($appointment_name_words[count($appointment_name_words)-1] == $appointment_ofsubdivfull_words[0]) {  
150 - unset($appointment_name_words[count($appointment_name_words)-1]);  
151 - }  
152 - if ($appointment_ofsubdivfull_words[0] == 'ректората') {  
153 - unset($appointment_ofsubdivfull_words[0]);  
154 - }  
155 - $appointments_full = join(' ', $appointment_name_words).' '.join(' ', $appointment_ofsubdivfull_words);  
156 - $appointments_wosubdiv = preg_replace('/ [0-9]*.[0-9]$/', '', $appointment->name);  
157 - $signer_subdivs = '['.$appointment->subdivision->s_code.'] '.mb_strtoupper($appointment->subdivision->shortname);  
158 - $signer_subdivs_full = $appointment->subdivision->name;  
159 -  
160 - $_GET['signer-fullname'] = $user->employee->fullname;  
161 - $_GET['signer-appointment'] = $appointments_full;  
162 - $_GET['signer-appointment-wosubdiv'] = $appointments_wosubdiv;  
163 - $_GET['signer-subdivs'] = $signer_subdivs;  
164 - $_GET['signer-subdivs-full'] = $signer_subdivs_full;  
165 212
166 foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) { 213 foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) {
167 $_user['login'] = strtolower($_user['login']); 214 $_user['login'] = strtolower($_user['login']);
@@ -186,6 +233,17 @@ if (isset($_GET['signer-serialized'])) { @@ -186,6 +233,17 @@ if (isset($_GET['signer-serialized'])) {
186 $redmine = &$redmine_admin; 233 $redmine = &$redmine_admin;
187 } 234 }
188 235
  236 +foreach (array('contact', 'user', 'recipient') as $key) {
  237 + if (empty($_GET[$key.'-appointment-id']))
  238 + continue;
  239 +
  240 + $w_id = $_GET[$key.'-appointment-id'];
  241 +
  242 + $appointment = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getworkpositioninfo&w_id=".urlencode($w_id) ));
  243 +
  244 + considerAppointment($key, $appointment);
  245 +}
  246 +
189 //print_r($redmine);print_r($_GET);die(); 247 //print_r($redmine);print_r($_GET);die();
190 248
191 $dont_inflect_patterns = array( 249 $dont_inflect_patterns = array(
@@ -338,8 +396,8 @@ function my_mb_ucfirst($str, $e='utf-8') { @@ -338,8 +396,8 @@ function my_mb_ucfirst($str, $e='utf-8') {
338 } 396 }
339 397
340 //This cycle for situation when we could not receive enought info from node_common 398 //This cycle for situation when we could not receive enought info from node_common
341 - 399 +// TODO: remove this block, it's obsolete
342 -foreach (array('signer', 'contact', 'user') as $key) { 400 +foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
343 if (!empty($_GET[$key.'-e_id'])) { 401 if (!empty($_GET[$key.'-e_id'])) {
344 $e_id = $_GET[$key.'-e_id']; 402 $e_id = $_GET[$key.'-e_id'];
345 403
@@ -347,12 +405,12 @@ foreach (array('signer', 'contact', 'user') as $key) { @@ -347,12 +405,12 @@ foreach (array('signer', 'contact', 'user') as $key) {
347 $employee = ((array)$employees); 405 $employee = ((array)$employees);
348 $employee = reset($employee); 406 $employee = reset($employee);
349 } else 407 } else
350 - if (!empty($_GET[$key.'-login'])) { 408 + /*if (!empty($_GET[$key.'-login'])) {
351 $login = $_GET[$key.'-login']; 409 $login = $_GET[$key.'-login'];
352 $employees = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&username=".urlencode($login) )); 410 $employees = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&username=".urlencode($login) ));
353 $employee = ((array)$employees); 411 $employee = ((array)$employees);
354 $employee = reset($employee); 412 $employee = reset($employee);
355 - } else 413 + } else*/
356 continue; 414 continue;
357 415
358 $appointments = array(); 416 $appointments = array();
@@ -380,7 +438,7 @@ foreach (array('signer', 'contact', 'user') as $key) { @@ -380,7 +438,7 @@ foreach (array('signer', 'contact', 'user') as $key) {
380 } 438 }
381 439
382 //DE base64 subdivs 440 //DE base64 subdivs
383 -foreach (array('signer', 'contact', 'user') as $key) { 441 +foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
384 if (!empty($_GET[$key.'-e_id'])) 442 if (!empty($_GET[$key.'-e_id']))
385 continue; 443 continue;
386 444
@@ -403,7 +461,7 @@ foreach (array('fullname' => 40, 'phonenumber' => 20, 'email' => 30, 'appointmen @@ -403,7 +461,7 @@ foreach (array('fullname' => 40, 'phonenumber' => 20, 'email' => 30, 'appointmen
403 $_GET['contact-'.$key] = $_GET['user-'.$key]; 461 $_GET['contact-'.$key] = $_GET['user-'.$key];
404 } 462 }
405 463
406 -foreach (array('signer', 'contact', 'user') as $key) { 464 +foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
407 if (empty($_GET[$key.'-name'])) 465 if (empty($_GET[$key.'-name']))
408 $_GET[$key.'-name'] = $_GET[$key.'-fullname']; 466 $_GET[$key.'-name'] = $_GET[$key.'-fullname'];
409 467
@@ -468,7 +526,7 @@ foreach (array('signer', 'contact', 'user') as $key) { @@ -468,7 +526,7 @@ foreach (array('signer', 'contact', 'user') as $key) {
468 } 526 }
469 } 527 }
470 528
471 -foreach (array('signer', 'contact', 'user') as $key) { 529 +foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
472 foreach (array('', 'of-', 'to-') as $key_prefix) { 530 foreach (array('', 'of-', 'to-') as $key_prefix) {
473 $appointment_w_fullsubdiv = array(); 531 $appointment_w_fullsubdiv = array();
474 532
@@ -664,7 +722,7 @@ foreach ($files as $file) { @@ -664,7 +722,7 @@ foreach ($files as $file) {
664 $memo_subject = 'Заявка на модернизацию ЛВС'; 722 $memo_subject = 'Заявка на модернизацию ЛВС';
665 break; 723 break;
666 case 'request/custom': 724 case 'request/custom':
667 - $project_id = redmine_proj_identifier2id ($_GET['credentials']); 725 + $project_id = redmine_proj_identifier2id ($_GET['recipient-login']);
668 $memo_subject = 'Служебная записка'; 726 $memo_subject = 'Служебная записка';
669 $me['id'] = $user_redmine['user']['id']; 727 $me['id'] = $user_redmine['user']['id'];
670 $replacement_is_already_done = true; 728 $replacement_is_already_done = true;
@@ -911,8 +969,7 @@ foreach ($files as $file) { @@ -911,8 +969,7 @@ foreach ($files as $file) {
911 $footer = ''; 969 $footer = '';
912 break; 970 break;
913 case 'request/custom': 971 case 'request/custom':
914 - $cred_parts = split('<br>', $_GET['cred-id']); 972 + $header = '\mmheader{'.my_mb_ucfirst($_GET['to-recipient-appointment-w-fullsubdiv-cap']).'}{'.my_mb_ucfirst($_GET['to-recipient-name']).'}';
915 - $header = '\mmheader{'.$cred_parts[0].'}{'.$cred_parts[1].'}';  
916 $body = latexSpecialChars1(str_replace("\n", "\n\n", $body)); 973 $body = latexSpecialChars1(str_replace("\n", "\n\n", $body));
917 $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['signer-name'].'}{'.$_GET['current-date'].'}{}'; 974 $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['signer-name'].'}{'.$_GET['current-date'].'}{}';
918 // $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['current-date'].'}{'.$_GET['signer-name'].'}{}'; 975 // $footer = '\mmfooter{'.my_mb_ucfirst($_GET['signer-appointment']).'}{'.$_GET['current-date'].'}{'.$_GET['signer-name'].'}{}';
@@ -1000,9 +1057,9 @@ foreach ($files as $file) { @@ -1000,9 +1057,9 @@ foreach ($files as $file) {
1000 case 'request/custom': //AASD 1057 case 'request/custom': //AASD
1001 $issue_props = 1058 $issue_props =
1002 array( 1059 array(
1003 - 'assigned_to_id' => redmine_login2id($_GET['credentials']), 1060 + 'assigned_to_id' => redmine_login2id($_GET['recepient-login']),
1004 'project_id' => $project_id, 1061 'project_id' => $project_id,
1005 - 'subject' => 'Служебная записка '.(explode('<br>', $_GET['cred-id'])[1]).' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"), 1062 + 'subject' => 'Служебная записка '.$_GET['to-recipient-name'].' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"),
1006 'description' => "<pre>".$text."</pre>", 1063 'description' => "<pre>".$text."</pre>",
1007 1064
1008 ); 1065 );