redmine

Added support of appointment_id_to selection

... ... @@ -87,6 +87,71 @@ Array
)
*/
function stfcardid2login($stfcardid) {
error_log("stfcardid2login($stfcardid)");
static $stfcardid2login = array();
$filename = '/opt/tmp/stfcardid2login.json';
$s = stat($filename);
if ($s === FALSE || (@$s[9]+3600*24) < time()) {
$apiKey = trim(file_get_contents('/etc/apikey-voip'));
$subscribers = json_decode(file_get_contents('http://new.voip.mephi.ru/subscribers.json?limit=65535&renderFilter=subscribers&apiKey='.urlencode($apiKey)), 1)['subscribers'];
foreach ($subscribers as &$subscriber) {
if (empty($subscriber['Login']['String']))
continue;
foreach ($subscriber['Appointments'] as &$_a)
$stfcardid2login[$_a['StfCardId']] = $subscriber['Login']['String'];
}
if (count($stfcardid2login) > 1000) {
file_put_contents($filename, json_encode($stfcardid2login));
}
}
if (empty($stfcardid2login)) {
$stfcardid2login = json_decode(file_get_contents($filename), 1);
}
error_log ('RS:'.$stfcardid2login[$stfcardid]);
return $stfcardid2login[$stfcardid];
}
function considerAppointment($key, &$appointment) {
global $inflect;
$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[$key.'-appointment-id'] = $appointment->w_id;
$_GET[$key.'-fullname'] = $appointment->employee->fullname;
$fullname_words = explode(' ', $_GET[$key.'-fullname']);
$_GET[$key.'-login'] = stfcardid2login($appointment->w_id);
$_GET[$key.'-name'] = mb_substr($fullname_words[1], 0, 1).'. '.mb_substr($fullname_words[2], 0, 1).'. '.$fullname_words[0];
$_GET[$key.'-appointment'] = $appointments_full;
$_GET[$key.'-appointment-wosubdiv'] = $appointments_wosubdiv;
$_GET[$key.'-subdivs'] = $signer_subdivs;
$_GET[$key.'-subdivs-full'] = $signer_subdivs_full;
}
$_GET = array_merge ($_GET, $_POST);
header( "Content-Type: text/plain" );
//print_r ($_GET); die();
... ... @@ -141,27 +206,9 @@ if (isset($_GET['signer-serialized'])) {
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'] = $appointments_full;
$_GET['signer-appointment-wosubdiv'] = $appointments_wosubdiv;
$_GET['signer-subdivs'] = $signer_subdivs;
$_GET['signer-subdivs-full'] = $signer_subdivs_full;
@$appointment->employee = $user->employee;
considerAppointment('signer', $appointment);
foreach ($redmine_admin->api('user')->all(array('name' => $username_drupal))['users'] as &$_user) {
$_user['login'] = strtolower($_user['login']);
... ... @@ -186,6 +233,17 @@ if (isset($_GET['signer-serialized'])) {
$redmine = &$redmine_admin;
}
foreach (array('contact', 'user', 'recipient') as $key) {
if (empty($_GET[$key.'-appointment-id']))
continue;
$w_id = $_GET[$key.'-appointment-id'];
$appointment = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getworkpositioninfo&w_id=".urlencode($w_id) ));
considerAppointment($key, $appointment);
}
//print_r($redmine);print_r($_GET);die();
$dont_inflect_patterns = array(
... ... @@ -338,8 +396,8 @@ function my_mb_ucfirst($str, $e='utf-8') {
}
//This cycle for situation when we could not receive enought info from node_common
foreach (array('signer', 'contact', 'user') as $key) {
// TODO: remove this block, it's obsolete
foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
if (!empty($_GET[$key.'-e_id'])) {
$e_id = $_GET[$key.'-e_id'];
... ... @@ -347,12 +405,12 @@ foreach (array('signer', 'contact', 'user') as $key) {
$employee = ((array)$employees);
$employee = reset($employee);
} else
if (!empty($_GET[$key.'-login'])) {
/*if (!empty($_GET[$key.'-login'])) {
$login = $_GET[$key.'-login'];
$employees = json_decode(file_get_contents("https://cps.mephi.ru/?cmd=getemployeeinfo&username=".urlencode($login) ));
$employee = ((array)$employees);
$employee = reset($employee);
} else
} else*/
continue;
$appointments = array();
... ... @@ -380,7 +438,7 @@ foreach (array('signer', 'contact', 'user') as $key) {
}
//DE base64 subdivs
foreach (array('signer', 'contact', 'user') as $key) {
foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
if (!empty($_GET[$key.'-e_id']))
continue;
... ... @@ -403,7 +461,7 @@ foreach (array('fullname' => 40, 'phonenumber' => 20, 'email' => 30, 'appointmen
$_GET['contact-'.$key] = $_GET['user-'.$key];
}
foreach (array('signer', 'contact', 'user') as $key) {
foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
if (empty($_GET[$key.'-name']))
$_GET[$key.'-name'] = $_GET[$key.'-fullname'];
... ... @@ -468,7 +526,7 @@ foreach (array('signer', 'contact', 'user') as $key) {
}
}
foreach (array('signer', 'contact', 'user') as $key) {
foreach (array('signer', 'contact', 'user', 'recipient') as $key) {
foreach (array('', 'of-', 'to-') as $key_prefix) {
$appointment_w_fullsubdiv = array();
... ... @@ -664,7 +722,7 @@ foreach ($files as $file) {
$memo_subject = 'Заявка на модернизацию ЛВС';
break;
case 'request/custom':
$project_id = redmine_proj_identifier2id ($_GET['credentials']);
$project_id = redmine_proj_identifier2id ($_GET['recipient-login']);
$memo_subject = 'Служебная записка';
$me['id'] = $user_redmine['user']['id'];
$replacement_is_already_done = true;
... ... @@ -911,8 +969,7 @@ foreach ($files as $file) {
$footer = '';
break;
case 'request/custom':
$cred_parts = split('<br>', $_GET['cred-id']);
$header = '\mmheader{'.$cred_parts[0].'}{'.$cred_parts[1].'}';
$header = '\mmheader{'.my_mb_ucfirst($_GET['to-recipient-appointment-w-fullsubdiv-cap']).'}{'.my_mb_ucfirst($_GET['to-recipient-name']).'}';
$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'].'}{}';
... ... @@ -1000,9 +1057,9 @@ foreach ($files as $file) {
case 'request/custom': //AASD
$issue_props =
array(
'assigned_to_id' => redmine_login2id($_GET['credentials']),
'assigned_to_id' => redmine_login2id($_GET['recepient-login']),
'project_id' => $project_id,
'subject' => 'Служебная записка '.(explode('<br>', $_GET['cred-id'])[1]).' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"),
'subject' => 'Служебная записка '.$_GET['to-recipient-name'].' от '.$_GET['of-signer-name'].', '.date(" Y.m.d, H:i:s"),
'description' => "<pre>".$text."</pre>",
);
... ...