cron-hpc.php 2.2 KB
<?php
exit(0);

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/IssueStatus.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/Attachment.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";

require_once "config.php";

$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_API);

/* NRNU Auto-report */

$answer = $redmine->api('issue')->all(array(
		'project_id'		=> '38', 			// project "hpc-request"
		'status_id'		=> STATUSID_NOTCONFIRMED,
	));

if (!isset($answer['issues']))
	exit(0);

$time = time();

foreach ($answer['issues'] as &$issue) {
	$issues_full = $redmine->api('issue')->show($issue['id'], array('include' => 'attachments'));
	$issue_full  = reset($issues_full);

	$have_memo = 0;
	if (isset($issue_full['attachments']))
		foreach ($issue_full['attachments'] as &$attachment)
			if ($attachment['description'] == 'Memorandum' || $attachment['description'] == 'Служебная записка') {
				$have_memo = 1;
				break;
			}

	if ($have_memo != 0)
		continue;

	foreach ($issue_full['custom_fields'] as $cfield) {
		switch ($cfield['name']) {
			case 'Имя пользователя (логин)':
				$login         = $cfield['value'];
				break;
			case 'E-mail':
				$contact_email = $cfield['value'];
				break;
		}
	}

	$user = $redmine->api('user')->show($issue_full['author']['id']);
	$user = $user['user'];

	$contact_fullname = $user['lastname'].' '.$user['firstname'];

	$data_array = array(
		'work-topic'		=> $issue_full['subject'],
		'issue-id'		=> $issue_full['id'],
		'contact-fullname'	=> $contact_fullname,
		'contact-email'		=> $contact_email,
		'preffered-login'	=> $login,
		'date-end'		=> '_________________',
	);

	$data_array_tmp = array();
	foreach($data_array as $k => &$v)
		$data_array_tmp[] = urlencode($k).'='.urlencode($v);

	$data = join('&', $data_array_tmp);
	file_get_contents('http://ut.mephi.ru/genpdf/request/hpc?'.$data);

}

?>