1KA_F2F/admin/survey/classes/surveyData/old/prepareDataIncremental.php
2020-08-14 13:36:36 +02:00

101 lines
4.3 KiB
PHP

<?php
ob_start();
session_start();
set_time_limit(2400); # 30 minut
header('Cache-Control: no-cache');
header('Pragma: no-cache');
# očitno ta klic ne deluje vredu
include_once($_SERVER['DOCUMENT_ROOT'].'/function.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/admin/survey/definition.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
$anketa = (int)$_REQUEST['anketa'];
if ($_GET['action'] == 'createSingle') {
if ($anketa > 0) {
session_start();
// nastavimo jezik
$lang_admin = (isset($_REQUEST['lang_admin'])) ? $_REQUEST['lang_admin'] : 1;
$file = $site_path.'/lang/'.$lang_admin.'.php';
include($file);
unset($_SESSION['incrementalProgressBar'][$anketa]);
list($usec, $sec) = explode(" ", microtime());
# če
if ($_SESSION['incrementalProgressBar'][$anketa]['status'] != 1
# ali smo začeli pred 30 min ali več, potem dovolimo ponoven start
# || ($_SESSION['incrementalProgressBar'][$anketa]['status'] == 1
# && isset($_SESSION['incrementalProgressBar'][$anketa]['started'])
# && ($sec - (int)$_SESSION['incrementalProgressBar'][$anketa]['started']) > 1800
# )
){
SurveyTrackIncremental::write($anketa,'Progress bar -> Ajax started for survey: '.$anketa);
# pobrišemo staro sejo
unset($_SESSION['incrementalProgressBar'][$anketa]);
# nastavimo čas kdaj smo startali
$_SESSION['incrementalProgressBar'][$anketa]['started'] = $sec;
# nastavimo status da smo štartali
$_SESSION['incrementalProgressBar'][$anketa]['status'] = 1;
$_SESSION['incrementalProgressBar'][$anketa]['current'] = 0;
session_commit();
// Get the start time in microseconds, as a float value
$starttime = microtime(true);
$lock = new ExclusiveLock( "survey_lock_".$anketa, FALSE);
if( $lock->lock( ) == FALSE ) {
SurveyTrackIncremental::write($anketa,'LOCK: alreadyLocked for survey: '.$anketa);
#error("Locking failed");
} else {
# pozenemo generiranje datoteke
$CID = new CollectIncrementalData($anketa);
$CH = (int)$CID->createHeadFile();
// Get the difference between start and end in microseconds, as a float value
$diff = microtime(true) - $starttime;
// Break the difference into seconds and microseconds
$sec = intval($diff);
$micro = $diff - $sec;
// Format the result as you want it
// $final will contain something like "00:00:02.452"
$final = strftime('%T', mktime(0, 0, $sec)) . str_replace('0.', '.', sprintf('%.3f', $micro));
echo '<hr>1:'.$final;
$CD = (int)$CID->createDataFile();
}
$lock->unlock();
// Get the difference between start and end in microseconds, as a float value
$diff = microtime(true) - $starttime;
// Break the difference into seconds and microseconds
$sec = intval($diff);
$micro = $diff - $sec;
// Format the result as you want it
// $final will contain something like "00:00:02.452"
$final = strftime('%T', mktime(0, 0, $sec)) . str_replace('0.', '.', sprintf('%.3f', $micro));
echo '<hr>2:'.$final;
} else {
SurveyTrackIncremental::write($anketa,'Progress bar -> Ajax skiped for survey: '.$anketa);
}
}
} else if ($_GET['action'] == 'clear') {
if ($anketa > 0) {
session_start();
unset($_SESSION['incrementalProgressBar'][$anketa]);
session_commit();
}
}
ob_flush();
?>