}
    /**
     * save the timing data
     * @param $json
     * @return bool
     */
    function saveJson($json)
    {
        $authenticationAndSecurity = new authenticationAndSecurity();
        $reporterCookieName = 'timerCookie';
        if (null !== $authenticationAndSecurity->getcookie($reporterCookieName)) {
            $reporterName = $authenticationAndSecurity->getSingleCookie($reporterCookieName);
        } else {
            die('Error: no reporter cookie');
        }
        if ($this->createTimeJsonFile($reporterName, $json)) {
            $this->removeOldFiles($reporterName);
            return true;
        } else {
            return false;
        }
    }
}
$timeJsonSaveAjax = new timeJsonSaveAjax();
$authenticationAndSecurity = new authenticationAndSecurity();
$json = $authenticationAndSecurity->getPost('json');
if ($timeJsonSaveAjax->saveJson($json)) {
    return 'successful server file creation';
} else {
    return 'failed';
}
 /**
  * create tickets from form data
  */
 function submit()
 {
     $authenticationAndSecurity = new authenticationAndSecurity();
     $csvClass = new csvClass();
     $isAjax = $authenticationAndSecurity->getGet("ajax");
     $GLOBALS['newline'] = '<br/>';
     $newLine = $GLOBALS["newline"];
     if ($isAjax !== 'true') {
         echo $newLine . $newLine . "------------------------------" . $newLine . "    Youtrack csv importer     " . $newLine . "------------------------------" . $newLine;
         if (null !== $authenticationAndSecurity->getPost("test")) {
             echo "-- Testing progress --" . $newLine;
         } else {
             echo "-- Progress --" . $newLine;
         }
     }
     $posts = $this->organisePosts();
     $posts = $this->organiseAttachments($posts);
     date_default_timezone_set('Europe/London');
     $csvLogFolder = __DIR__ . '/../../log/createByForm/' . date("Y-m-d");
     $csvLogFileName = time() . '.csv';
     // creates csv log before sending to guzzle as guzzle dosnt fail gracefully
     if ($GLOBALS['createByFormTransferLog']) {
         $this->createFolder($csvLogFolder);
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     }
     $posts = $this->sendPostData($posts);
     if ($GLOBALS['createByFormTransferLog']) {
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     } elseif ($GLOBALS['createByFormTransferErrorLog']) {
         $posts = $this->removeSuccessfulPosts($posts);
         $this->createFolder($csvLogFolder);
         $csvClass->createCsv($posts, $csvLogFolder . '/' . $csvLogFileName);
     }
     if ($isAjax !== 'true') {
         if (null !== $authenticationAndSecurity->getPost("test")) {
             echo $newLine . "---- Test Finished -----" . $newLine;
         } else {
             echo $newLine . "---- Upload Finished -----" . $newLine;
         }
     } else {
         echo json_encode($GLOBALS['createByFormAjax']);
     }
 }
<?php

/**
 * download all issues in a project in a csv
 */
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/getCustomSettings.php';
require_once __DIR__ . '/getDataFromYoutrack.php';
require_once __DIR__ . '/authenticationAndSecurity.php';
$getDataFromYoutrack = new getDataFromYoutrack();
$authenticationAndSecurity = new authenticationAndSecurity();
$filename = $authenticationAndSecurity->getPost('filename');
$url = $youtrackUrl . '/rest/export/' . $authenticationAndSecurity->getPost('project') . '/issues';
$res = $getDataFromYoutrack->rest($url, 'get');
$filepath = '../export/' . $filename;
$file = fopen($filepath, "w") or die("Unable to open file!");
fwrite($file, $res);
fclose($file);
chmod($file, $GLOBALS['filePermissions']);
if (file_exists($filepath)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . basename($filepath));
    header('Expires: 1');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    header('Content-type: text/xml');
    readfile($filepath);
    exit;
}
<?php

/**
 * ticket search on time tracker page
 */
require_once __DIR__ . '/getCustomSettings.php';
require_once __DIR__ . '/getDataFromYoutrack.php';
$getDataFromYoutrack = new getDataFromYoutrack();
$authenticationAndSecurity = new authenticationAndSecurity();
$project = htmlspecialchars($authenticationAndSecurity->getPost("project"));
$query = htmlspecialchars($authenticationAndSecurity->getPost("query"));
$after = htmlspecialchars($authenticationAndSecurity->getPost("after"));
$after = $after ? $after : 0;
echo json_encode($getDataFromYoutrack->getTicketsFromSearch($project, $query, $maximumReturned = 100, $after));
<?php

/**
 * download a csv with field options
 */
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/getCustomSettings.php';
require_once __DIR__ . '/getDataFromYoutrack.php';
require_once __DIR__ . '/authenticationAndSecurity.php';
$getYoutrackData = new getDataFromYoutrack();
$authenticationAndSecurity = new authenticationAndSecurity();
require_once __DIR__ . '/csv.php';
$csvClass = new csvClass();
use Ddeboer\DataImport\Writer\CsvWriter;
$youtrackFields = [];
$filename = $authenticationAndSecurity->getPost('filename');
list($youtrackFieldsList, $youtrackFields) = $getYoutrackData->getCustomFieldsWithDetails();
$youtrackFields['user'] = $getYoutrackData->getUsers();
array_push($youtrackFieldsList, 'user');
/**
 * organises fields into more usable format, removing empty
 * @param array $array youtrack fields
 * @return array
 */
function reorganiseArray($array)
{
    $newArray = [];
    foreach ($array as $key => $value) {
        $i = 0;
        foreach ($value as $key2 => $val) {
            if (!isset($newArray[$i])) {
} else {
    $GLOBALS["newline"] = "\n";
    $_POST["user"] = $options['u'];
    $_POST["password"] = $options['p'];
    if (isset($options['t'])) {
        $_POST['test'] = true;
    }
    if (strpos('/', $options['f']) == false) {
        $csv = new SplFileObject(__DIR__ . '/../uploads/' . $options['f']);
    } else {
        $csv = new SplFileObject($options['f']);
    }
}
$newLine = $GLOBALS["newline"];
$reader = new CsvReader($csv);
$reader->setHeaderRowNumber(0);
$mappings = ['Project' => 'project', 'AssigneeGroup' => 'assigneeGroup', 'Summary' => 'summary'];
$mappingConverter = new MappingItemConverter($mappings);
echo $newLine . $newLine . "------------------------------" . $newLine . "    Youtrack csv importer     " . $newLine . "------------------------------" . $newLine;
if (null !== $authenticationAndSecurity->getPost("newline")) {
    echo "-- Testing progress --" . $newLine;
} else {
    echo "-- Progress --" . $newLine;
}
$workflow = new Workflow($reader);
$workflow->addItemConverter($mappingConverter)->addWriter(new ApiWriter())->process();
if (null !== $authenticationAndSecurity->getPost("newline")) {
    echo $newLine . "---- Test Finished -----" . $newLine;
} else {
    echo $newLine . "---- Upload Finished -----" . $newLine;
}