0) {
$this->ank_id = $anketa;
// polovimo vrsto tabel (aktivne / neaktivne)
SurveyInfo :: getInstance()->SurveyInit($this->ank_id);
$this->db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
// Inicializiramo in polovimo nastavitve missing profila
SurveyStatusProfiles::Init($this->ank_id);
SurveyUserSetting::getInstance()->Init($this->ank_id, $global_user_id);
SurveyStatusProfiles::Init($this->ank_id);
SurveyMissingProfiles :: Init($this->ank_id,$global_user_id);
SurveyConditionProfiles :: Init($this->ank_id, $global_user_id);
SurveyZankaProfiles :: Init($this->ank_id, $global_user_id);
SurveyTimeProfiles :: Init($this->ank_id, $global_user_id);
SurveyDataSettingProfiles :: Init($this->ank_id);
#inicializiramo class za datoteke
$SDF = SurveyDataFile::get_instance();
$SDF->init($anketa);
$this->headFileName = $SDF->getHeaderFileName();
$this->dataFileName = $SDF->getDataFileName();
$this->dataFileStatus = $SDF->getStatus();
SurveyAnalysis::Init($this->ank_id);
//polovimo podatke o nastavitvah trenutnega profila (missingi..)
SurveyAnalysis::$missingProfileData = SurveyMissingProfiles::getProfile(SurveyAnalysis::$currentMissingProfile);
#preberemo HEADERS iz datoteke
SurveyAnalysis::$_HEADERS = unserialize(file_get_contents($this->headFileName));
# odstranimo sistemske variable tipa email, ime, priimek, geslo
SurveyAnalysis::removeSystemVariables();
# polovimo frekvence
SurveyAnalysis::getFrequencys();
$this->creportProfile = SurveyUserSetting :: getInstance()->getSettings('default_creport_profile');
$this->creportProfile = isset($this->creportProfile) && $this->creportProfile != '' ? $this->creportProfile : 0;
$this->creportAuthor = SurveyUserSetting :: getInstance()->getSettings('default_creport_author');
$this->creportAuthor = isset($this->creportAuthor) && $this->creportAuthor != '' ? $this->creportAuthor : $global_user_id;
$this->expanded = (isset($_GET['expanded'])) ? $_GET['expanded'] : 0;
}
else {
echo 'Invalid Survey ID!';
exit();
}
}
// Izrisemo izdelano porocilo
function displayReport(){
global $lang;
global $global_user_id;
# zakeširamo vsebino, in jo nato po potrebi zapišpemo v html
if ($this->returnAsHtml != false) {
ob_start();
}
if ($this->isArchive == false && $this->publicCReport == false) {
echo '';
$this->displayProfilePopups();
// Prva vrstica - seznam poročil
echo '
';
// Seznam porocil
echo '
';
// Seznam avtorjevih porocil
// Prvo default porocilo
$sql = sisplet_query("SELECT value FROM srv_user_setting_for_survey WHERE sid='$this->ank_id' AND uid='$global_user_id' AND what='creport_default_profile_name'");
if(mysqli_num_rows($sql) == 0){
echo '
';
}
// Loop po ostalih lastnih porocilih
$sqlReports = sisplet_query("SELECT * FROM srv_custom_report_profiles WHERE ank_id='$this->ank_id' AND usr_id='$global_user_id'");
while($rowReports = mysqli_fetch_array($sqlReports)){
echo '
';
echo $rowReports['name'];
echo '
';
}
// Loop po deljenih porocilih
$sqlSharedReports = sisplet_query("SELECT s.*, u.email FROM srv_custom_report_share s, users u WHERE ank_id='$this->ank_id' AND share_usr_id='$global_user_id' AND u.id=s.author_usr_id");
while($rowSharedReports = mysqli_fetch_array($sqlSharedReports)){
// Ce gre za osnovno porocilo ki ga ne more pobrisati
if($rowSharedReports['profile_id'] == 0){
// Dobimo ime osnovnega porocila
$what = 'creport_default_profile_name';
$sqlN = sisplet_query("SELECT value FROM srv_user_setting_for_survey WHERE sid='$this->ank_id' AND uid='".$rowSharedReports['author_usr_id']."' AND what='$what'");
if(mysqli_num_rows($sqlN) == '0'){
$default_name = $lang['srv_custom_report_default'];
}
else{
$rowN = mysqli_fetch_array($sqlN);
$default_name = ($rowN['value'] == '') ? $lang['srv_custom_report_default'] : $rowN['value'];
}
echo '
';
}
// Ce gre za dodatno porocilo ga imamo normalno v bazi
else{
$sql = sisplet_query("SELECT * FROM srv_custom_report_profiles WHERE ank_id='$this->ank_id' AND usr_id='".$rowSharedReports['author_usr_id']."'");
while($row = mysqli_fetch_array($sql)){
echo '
';
}
// Izrisemo sumarnik element
function displayDesc($reportElement, $expanded){
global $lang;
// Naslov
$spr = SurveyAnalysis::$_HEADERS[$reportElement['spr1']];
if($reportElement['spr1'] == '')
$title = $lang['srv_select_spr'];
else
$title = $spr['variable'].' - '.$spr['naslov'];
$subtitle = '('.$lang['srv_descriptor'].')';
$title .= ' '.$subtitle.'';
// Glava elementa (naslov, ikone...)
$this->displayReportElementHead($reportElement, $expanded, $title);
// Nastavitve elementa
$this->displayReportElementSettings($reportElement, $expanded);
// Izpis tabele ali grafa za posamezen vnos
echo '
';
if($expanded != 0){
SurveyAnalysis::displayDescriptives($reportElement['spr1']);
// Na novo napolnimo headers ker se resetira??
SurveyAnalysis::$_HEADERS = unserialize(file_get_contents($this->headFileName));
}
echo '
';
}
// Izrisemo sumarnik element
function displayChart($reportElement, $expanded){
global $lang;
// Naslov
$spr = SurveyAnalysis::$_HEADERS[$reportElement['spr1']];
if($reportElement['spr1'] == '')
$title = $lang['srv_select_spr'];
else
$title = $spr['variable'].' - '.$spr['naslov'];
$subtitle = '('.$lang['srv_chart'].')';
$title .= ' '.$subtitle.'';
// Glava elementa (naslov, ikone...)
$this->displayReportElementHead($reportElement, $expanded, $title);
// Nastavitve elementa
$this->displayReportElementSettings($reportElement, $expanded);
// Izpis tabele ali grafa za posamezen vnos
echo '
';
}
// Dodajanje elementa porocila
function addNewElement($id=0){
global $lang;
// Dodajanje vmes in na zacetku
if($id != 0){
echo ''.$lang['srv_custom_report_add'].'';
echo ''.$lang['srv_custom_report_add_text'].'';
if($id > 0)
echo ''.$lang['srv_add_pagebreak'].'';
}
// Dodajanje na dnu (brez page breaka)
if($id == 0){
echo '';
echo '';
}
}
public static function checkEmpty($ank_id){
global $global_user_id;
$creportProfile = SurveyUserSetting :: getInstance()->getSettings('default_creport_profile');
$creportProfile = isset($creportProfile) ? $creportProfile : 0;
$creportAuthor = SurveyUserSetting :: getInstance()->getSettings('default_creport_author');
$creportAuthor = isset($creportAuthor) ? $creportAuthor : $global_user_id;
// preverimo ce je ze kaksen element v porocilu
$sql = sisplet_query("SELECT id FROM srv_custom_report WHERE ank_id='$ank_id' AND usr_id='$creportAuthor' AND profile='$creportProfile' ");
if(mysqli_num_rows($sql) > 0){
$empty = false;
}
else{
$empty = true;
}
return $empty;
}
function setUpReturnAsHtml($returnAsHtml = false) {
$this->returnAsHtml = $returnAsHtml; # ali vrne rezultat analiz kot html ali ga izpiše
SurveyAnalysis::setUpReturnAsHtml($returnAsHtml);
}
function setUpIsForArchive($isArchive = false) {
$this->isArchive = $isArchive; # nastavimo da smo v arhivu
SurveyAnalysis::setUpIsForArchive($isArchive);
}
function setUpIsForPublic($publicCReport = false) {
$this->publicCReport = $publicCReport;
SurveyAnalysis::$publicAnalyse = $publicCReport;
SurveyAnalysis::$printPreview = $publicCReport;
SurveyChart::$publicChart = $publicCReport;
}
function displaySettingsProfiles(){
global $site_path;
global $global_user_id;
global $lang;
$time_created = '';
$time_edit = '';
$what = 'creport_default_profile_name';
$sql = sisplet_query("SELECT value FROM srv_user_setting_for_survey WHERE sid='$this->ank_id' AND uid='$global_user_id' AND what='$what'");
if(mysqli_num_rows($sql) == 0){
$default_name = $lang['srv_custom_report_default'];
}
else{
$row = mysqli_fetch_array($sql);
$default_name = $row['value'];
}
$profile = $this->getProfile($this->creportProfile);
$name = $profile['name'];
echo '
'.$lang['srv_custom_report_profile_title'].'
';
echo '
';
// Prednastavljen profil
echo '';
echo '
'.$default_name.'
';
// Loop po lastnih porocilih
$sql = sisplet_query("SELECT * FROM srv_custom_report_profiles WHERE ank_id='$this->ank_id' AND usr_id='$global_user_id'");
while($row = mysqli_fetch_array($sql)){
echo '
'.$row['name'].'
';
// Preberemo cas kreiranja porocila
if($this->creportProfile == $row['id'])
$time_created = $row['time_created'];
}
// Loop po deljenih porocilih drugih urednikov ankete
$sqlA = sisplet_query("SELECT s.*, u.email FROM srv_custom_report_share s, users u WHERE ank_id='$this->ank_id' AND share_usr_id='$global_user_id' AND u.id=s.author_usr_id");
while($rowA = mysqli_fetch_array($sqlA)){
// Ce gre za osnovno porocilo ki ga ne more pobrisati
if($rowA['profile_id'] == 0){
// Dobimo ime osnovnega porocila
$what = 'creport_default_profile_name';
$sqlN = sisplet_query("SELECT value FROM srv_user_setting_for_survey WHERE sid='$this->ank_id' AND uid='".$rowA['author_usr_id']."' AND what='$what'");
if(mysqli_num_rows($sqlN) == '0'){
$default_name = $lang['srv_custom_report_default'];
}
else{
$rowN = mysqli_fetch_array($sqlN);
$default_name = ($rowN['value'] == '') ? $lang['srv_custom_report_default'] : $rowN['value'];
}
echo '
';
}
// Ce gre za dodatno porocilo ga imamo normalno v bazi
else{
$sql = sisplet_query("SELECT * FROM srv_custom_report_profiles WHERE ank_id='$this->ank_id' AND usr_id='".$rowA['author_usr_id']."'");
while($row = mysqli_fetch_array($sql)){
echo '
';
// Preberemo cas kreiranja porocila
if($this->creportProfile == $row['id'])
$time_created = $row['time_created'];
}
}
}
echo '';
// Ce je izbran custom profil imamo na dnu gumba brisi in preimenuj, pri default pa samo preimenuj
// Preimenuje, brise in share lahko samo za lastna porocila
if($this->creportAuthor == $global_user_id){
echo '
';
}
function displayProfilePopups(){
global $lang;
global $global_user_id;
$profile = $this->getProfile($this->creportProfile);
$name = $profile['name'];
// div za kreacijo novega
echo '
';
echo '';
echo '';
}
// Funkcije ajaxa
public function ajax() {
global $lang;
global $global_user_id;
global $site_url;
$_GET['m'] = 'analysis_creport';
if (isset ($_POST['anketa']))
$this->ank_id = $_POST['anketa'];
if (isset ($_POST['element_id']))
$element_id = $_POST['element_id'];
if (isset ($_POST['what']))
$what = $_POST['what'];
if (isset ($_POST['value']))
$value = $_POST['value'];
// Nastavimo se nacin (skrcen/razsirjen)
$this->expanded = (isset($_POST['expanded']) ? $_POST['expanded'] : 0);
// Dodajanje praznega elementa v report
if($_GET['a'] == 'add_empty_element'){
// dodajanje vmes
if($element_id > 0){
$sql = sisplet_query("SELECT vrstni_red FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND id='$element_id' AND profile='$this->creportProfile'");
$row = mysqli_fetch_assoc($sql);
$vrstni_red = $row['vrstni_red'] + 1;
// Prestevilcimo elemente
$sql = sisplet_query("UPDATE srv_custom_report SET vrstni_red=vrstni_red+1 WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND vrstni_red>='$vrstni_red' AND profile='$this->creportProfile'");
$s = sisplet_query("INSERT INTO srv_custom_report (ank_id, usr_id, vrstni_red, profile, time_edit) VALUES('$this->ank_id', '$this->creportAuthor', '$vrstni_red', '$this->creportProfile', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$el_id = mysqli_insert_id($GLOBALS['connect_db']);
}
//dodajanje na zacetku
elseif($element_id == -1){
// Prestevilcimo elemente
$sql = sisplet_query("UPDATE srv_custom_report SET vrstni_red=vrstni_red+1 WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND profile='$this->creportProfile'");
$s = sisplet_query("INSERT INTO srv_custom_report (ank_id, usr_id, vrstni_red, profile, time_edit) VALUES('$this->ank_id', '$this->creportAuthor', '1', '$this->creportProfile', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$el_id = mysqli_insert_id($GLOBALS['connect_db']);
}
// dodajanje na koncu
else{
$sql = sisplet_query("SELECT vrstni_red FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND profile='$this->creportProfile' ORDER BY vrstni_red DESC");
if(mysqli_num_rows($sql) > 0){
$row = mysqli_fetch_assoc($sql);
$vrstni_red = $row['vrstni_red'] + 1;
}
else
$vrstni_red = 1;
$s = sisplet_query("INSERT INTO srv_custom_report (ank_id, usr_id, vrstni_red, profile, time_edit) VALUES('$this->ank_id', '$this->creportAuthor', '$vrstni_red', '$this->creportProfile', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$el_id = mysqli_insert_id($GLOBALS['connect_db']);
}
$this->displayReport();
echo '';
}
// Dodajanje ze nastavljenega elementa v report (klik na zvezdico)
if($_GET['a'] == 'add_element'){
if (isset ($_POST['type']))
$type = $_POST['type'];
if (isset ($_POST['sub_type']))
$sub_type = $_POST['sub_type'];
if (isset ($_POST['spr1']))
$spr1 = $_POST['spr1'];
if (isset ($_POST['spr2']))
$spr2 = $_POST['spr2'];
if (isset ($_POST['insert']))
$insert = $_POST['insert'];
// Vstavljanje
if($insert == 1){
// Razberemo vrstni red
$sql = sisplet_query("SELECT vrstni_red FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND profile='$this->creportProfile' ORDER BY vrstni_red DESC");
if(mysqli_num_rows($sql) > 0){
$row = mysqli_fetch_assoc($sql);
$vrstni_red = $row['vrstni_red'] + 1;
}
else
$vrstni_red = 1;
$sql = sisplet_query("INSERT INTO srv_custom_report (ank_id, usr_id, vrstni_red, type, sub_type, spr1, spr2, profile, time_edit) VALUES('$this->ank_id', '$this->creportAuthor', '$vrstni_red', '$type', '$sub_type', '$spr1', '$spr2', '$this->creportProfile', NOW())");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
echo $vrstni_red;
}
// brisanje
else{
// Preberemo vrstni red elementa, ki ga brisemo
$sql = sisplet_query("SELECT id, vrstni_red FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND type='$type' AND sub_type='$sub_type' AND spr1='$spr1' AND spr2='$spr2' AND profile='$this->creportProfile'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['vrstni_red'];
$element_id = $row['id'];
$sql = sisplet_query("DELETE FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND id='$element_id' AND profile='$this->creportProfile'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
// Prestevilcimo elemente
$sql = sisplet_query("UPDATE srv_custom_report SET vrstni_red=vrstni_red-1, time_edit=NOW() WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND vrstni_red>'$vrstni_red' AND profile='$this->creportProfile'");
echo -1;
}
}
// Brisanje elementa
if($_GET['a'] == 'delete_element'){
$sql = sisplet_query("SELECT vrstni_red FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND id='$element_id' AND profile='$this->creportProfile'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['vrstni_red'];
$sql = sisplet_query("DELETE FROM srv_custom_report WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
// Prestevilcimo elemente
$sql = sisplet_query("UPDATE srv_custom_report SET vrstni_red=vrstni_red-1, time_edit=NOW() WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND vrstni_red>'$vrstni_red' AND profile='$this->creportProfile'");
$this->displayReport();
}
// Editiranje elementa v reportu
if($_GET['a'] == 'edit_element'){
// Preklop na navaden tip (freq, sums, graf, desc)
if($what == 'type' && $value < 5){
$sql = sisplet_query("SELECT type FROM srv_custom_report WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
$row = mysqli_fetch_array($sql);
// Ce preklapljamo iz crosstabov, meansov ali ttesta - resetiramo spremenljivke
if($row['type'] > 4){
$s = sisplet_query("UPDATE srv_custom_report SET $what='$value', spr1='', spr2='', time_edit=NOW() WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
}
else{
$s = sisplet_query("UPDATE srv_custom_report SET $what='$value', time_edit=NOW() WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
// Ce preklopimo na crosstabe, means ali ttest resetiramo vse spremenljivke
elseif($what == 'type' && $value > 4){
$s = sisplet_query("UPDATE srv_custom_report SET $what='$value', spr1='', spr2='', time_edit=NOW() WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
// Ostali preklopi
else{
$s = sisplet_query("UPDATE srv_custom_report SET $what='$value', time_edit=NOW() WHERE ank_id='$this->ank_id' AND id='$element_id' AND profile='$this->creportProfile'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
$expanded = isset($_POST['expanded']) ? $_POST['expanded'] : 1;
$this->displayReportElement($element_id, $expanded);
}
if($_GET['a'] == 'copy_element'){
$sql = sisplet_query("SELECT * FROM srv_custom_report WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND id='$element_id' AND profile='$this->creportProfile'");
$row = mysqli_fetch_array($sql);
// najprej prestevilcimo elemente ki so za kopiranim
$sql2 = sisplet_query("UPDATE srv_custom_report SET vrstni_red=vrstni_red+1 WHERE ank_id='$this->ank_id' AND usr_id='$this->creportAuthor' AND vrstni_red>'$row[vrstni_red]' AND profile='$this->creportProfile'");
$vrstni_red = $row['vrstni_red'] + 1;
$sqlInsert = sisplet_query("INSERT INTO srv_custom_report (ank_id, usr_id, vrstni_red, type, sub_type, spr1, spr2, text, profile, time_edit) VALUES('$this->ank_id', '$this->creportAuthor', '$vrstni_red', '$row[type]', '$row[sub_type]', '$row[spr1]', '$row[spr2]', '$row[text]', '$row[profile]', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$this->displayReport();
}
// Sortiranje elementov
if($_GET['a'] == 'change_order'){
$sortable = $_POST['sortable'];
$exploded = explode('&', $sortable);
$i = 1;
foreach ($exploded AS $key) {
$key = str_replace('variabla_', '', $key);
$explode = explode('[]=', $key);
$sql = sisplet_query("UPDATE srv_custom_report SET vrstni_red = '$i', time_edit = NOW() WHERE id = '$explode[1]' AND profile='$this->creportProfile'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$i++;
}
}
// Alert pri dodajanju prvega
if($_GET['a'] == 'first_alert'){
echo $lang['srv_custom_report_first'];
/*Ozna�eni element (tabela/graf) se je prenesel v poro�ilo po meri, kjer lahko prilagajate prikaz in zaporedje elementov*/
echo ''.$lang['srv_custom_report_link'].'';
echo '
';
}
// Alert pri dodajanju vseh elementov istega tipa v report
if($_GET['a'] == 'all_elements_alert'){
$type = (isset($_POST['type'])) ? $_POST['type'] : 0;
echo '